discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Convert from object to polygon/polyhedron.

A
adrian
Tue, Oct 4, 2016 12:02 AM

Hi all,

Is there a way to convert a 2D objects to a polygon format? Or a 3D object
to a polyhedron format?

To  be able to go that way, rather than make a polygon / polyhedron from
points and paths /faces would be awesome, as this would open up a whole new
set of abilities.

Thanks.

--
View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Hi all, Is there a way to convert a 2D objects to a polygon format? Or a 3D object to a polyhedron format? To be able to go that way, rather than make a polygon / polyhedron from points and paths /faces would be awesome, as this would open up a whole new set of abilities. Thanks. -- View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
Ronaldo
Tue, Oct 4, 2016 12:25 AM

Yes, there is but not with OpenSCAD language yet. A python code by Neon22
converts AMF files (possibly exported by OpenSCAD) to a text file in the
OpenSCAD polyhedron format. See this discussion:
http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-td18145.html#a18156
http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-td18145.html#a18156

--
View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Yes, there is but not with OpenSCAD language yet. A python code by Neon22 converts AMF files (possibly exported by OpenSCAD) to a text file in the OpenSCAD polyhedron format. See this discussion: http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-td18145.html#a18156 <http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-td18145.html#a18156> -- View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18523.html Sent from the OpenSCAD mailing list archive at Nabble.com.
MS
Mark Schafer
Tue, Oct 4, 2016 10:51 AM

also on thingiverse is an inkscape extension which exports vector
objects to openscad format directly:

Yes it would be nice if we could have lines as first class objects in
OpenSCAD but for now these tools might help you

On 10/4/2016 1:25 PM, Ronaldo wrote:

Yes, there is but not with OpenSCAD language yet. A python code by Neon22
converts AMF files (possibly exported by OpenSCAD) to a text file in the
OpenSCAD polyhedron format. See this discussion:
http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-td18145.html#a18156
http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-td18145.html#a18156

--
View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: 10/03/16

also on thingiverse is an inkscape extension which exports vector objects to openscad format directly: - http://www.thingiverse.com/thing:1065500 Yes it would be nice if we could have lines as first class objects in OpenSCAD but for now these tools might help you On 10/4/2016 1:25 PM, Ronaldo wrote: > Yes, there is but not with OpenSCAD language yet. A python code by Neon22 > converts AMF files (possibly exported by OpenSCAD) to a text file in the > OpenSCAD polyhedron format. See this discussion: > http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-td18145.html#a18156 > <http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-td18145.html#a18156> > > > > -- > View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18523.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > ----- > No virus found in this message. > Checked by AVG - www.avg.com > Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: 10/03/16 > >
PF
Peter Falke
Tue, Oct 4, 2016 12:42 PM

The reason there is no such thing is that OpenSCAD can not change/set the
variables (set any(!) variable) during  execution.
But the 2d primitives are eaily written by your self.
The 3D primitives are doable too, but a little harder.

2016-10-04 12:51 GMT+02:00 Mark Schafer mschafer@wireframe.biz:

also on thingiverse is an inkscape extension which exports vector objects
to openscad format directly:

Yes it would be nice if we could have lines as first class objects in
OpenSCAD but for now these tools might help you

On 10/4/2016 1:25 PM, Ronaldo wrote:

Yes, there is but not with OpenSCAD language yet. A python code by Neon22
converts AMF files (possibly exported by OpenSCAD) to a text file in the
OpenSCAD polyhedron format. See this discussion:
http://forum.openscad.org/Wrapping-text-around-a-complex-
geometry-td18145.html#a18156
<http://forum.openscad.org/Wrapping-text-around-a-complex-
geometry-td18145.html#a18156>

--
View this message in context: http://forum.openscad.org/Conv
ert-from-object-to-polygon-polyhedron-tp18522p18523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: 10/03/16

The reason there is no such thing is that OpenSCAD can not change/set the variables (set any(!) variable) during execution. But the 2d primitives are eaily written by your self. The 3D primitives are doable too, but a little harder. 2016-10-04 12:51 GMT+02:00 Mark Schafer <mschafer@wireframe.biz>: > also on thingiverse is an inkscape extension which exports vector objects > to openscad format directly: > - http://www.thingiverse.com/thing:1065500 > > Yes it would be nice if we could have lines as first class objects in > OpenSCAD but for now these tools might help you > > > > On 10/4/2016 1:25 PM, Ronaldo wrote: > >> Yes, there is but not with OpenSCAD language yet. A python code by Neon22 >> converts AMF files (possibly exported by OpenSCAD) to a text file in the >> OpenSCAD polyhedron format. See this discussion: >> http://forum.openscad.org/Wrapping-text-around-a-complex- >> geometry-td18145.html#a18156 >> <http://forum.openscad.org/Wrapping-text-around-a-complex- >> geometry-td18145.html#a18156> >> >> >> >> -- >> View this message in context: http://forum.openscad.org/Conv >> ert-from-object-to-polygon-polyhedron-tp18522p18523.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> ----- >> No virus found in this message. >> Checked by AVG - www.avg.com >> Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: 10/03/16 >> >> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
AH
Adrian H
Tue, Oct 4, 2016 1:09 PM

True that all variables are constants, but there could be an operator that
returns the points.  That wouldn't break that paradigm.  Something like:

_2d = points_edges()
intersection()
{
circle(1, $fn=20);
square(2);
}

_3d = points_faces()
intersection()
{
sphere(1, $fn=20);
cube(2);
}

Where:

_2d=[ [point0, point1, ...], [ [edge0, ...], [edge1, ...], ...];
_3d=[ [point0, point1, ...], [ [face0, ...], [face1, ...], ...];

On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke <
stempeldergeschichte@googlemail.com> wrote:

The reason there is no such thing is that OpenSCAD can not change/set the
variables (set any(!) variable) during  execution.
But the 2d primitives are eaily written by your self.
The 3D primitives are doable too, but a little harder.

2016-10-04 12:51 GMT+02:00 Mark Schafer mschafer@wireframe.biz:

also on thingiverse is an inkscape extension which exports vector objects
to openscad format directly:

Yes it would be nice if we could have lines as first class objects in
OpenSCAD but for now these tools might help you

On 10/4/2016 1:25 PM, Ronaldo wrote:

Yes, there is but not with OpenSCAD language yet. A python code by Neon22
converts AMF files (possibly exported by OpenSCAD) to a text file in the
OpenSCAD polyhedron format. See this discussion:
http://forum.openscad.org/Wrapping-text-around-a-complex-geo
metry-td18145.html#a18156
<http://forum.openscad.org/Wrapping-text-around-a-complex-ge
ometry-td18145.html#a18156>

--
View this message in context: http://forum.openscad.org/Conv
ert-from-object-to-polygon-polyhedron-tp18522p18523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date:
10/03/16

True that all variables are constants, but there could be an operator that returns the points. That wouldn't break that paradigm. Something like: _2d = points_edges() intersection() { circle(1, $fn=20); square(2); } _3d = points_faces() intersection() { sphere(1, $fn=20); cube(2); } Where: _2d=[ [point0, point1, ...], [ [edge0, ...], [edge1, ...], ...]; _3d=[ [point0, point1, ...], [ [face0, ...], [face1, ...], ...]; On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke < stempeldergeschichte@googlemail.com> wrote: > The reason there is no such thing is that OpenSCAD can not change/set the > variables (set any(!) variable) during execution. > But the 2d primitives are eaily written by your self. > The 3D primitives are doable too, but a little harder. > > 2016-10-04 12:51 GMT+02:00 Mark Schafer <mschafer@wireframe.biz>: > >> also on thingiverse is an inkscape extension which exports vector objects >> to openscad format directly: >> - http://www.thingiverse.com/thing:1065500 >> >> Yes it would be nice if we could have lines as first class objects in >> OpenSCAD but for now these tools might help you >> >> >> >> On 10/4/2016 1:25 PM, Ronaldo wrote: >> >>> Yes, there is but not with OpenSCAD language yet. A python code by Neon22 >>> converts AMF files (possibly exported by OpenSCAD) to a text file in the >>> OpenSCAD polyhedron format. See this discussion: >>> http://forum.openscad.org/Wrapping-text-around-a-complex-geo >>> metry-td18145.html#a18156 >>> <http://forum.openscad.org/Wrapping-text-around-a-complex-ge >>> ometry-td18145.html#a18156> >>> >>> >>> >>> -- >>> View this message in context: http://forum.openscad.org/Conv >>> ert-from-object-to-polygon-polyhedron-tp18522p18523.html >>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >>> >>> ----- >>> No virus found in this message. >>> Checked by AVG - www.avg.com >>> Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: >>> 10/03/16 >>> >>> >>> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
AH
Adrian H
Tue, Oct 4, 2016 1:32 PM

Oh, and further to this, yes, one can write the primitives and the
operators, but that would be reinventing the wheel, and would definitely be
slower.  Especially with things like hull() and minkowski().

The information is available, it just needs to be made available.

Thinking about this further, the operators that I described are actually a
module to function crossover, which doesn't currently exist in OpenSCAD,
but perhaps it could possibly be doable?  Maybe by some incremental build
process?

As I understand it, it currently builds by:

  1. calculate all variables/functions
  2. calculate all operations/modules.
  3. show result on screen result

What I would be suggesting is to iterate over the first 2 steps, executing
each iteration, child node first, up to such crossover points until
everything is calculated, and then do step 3.

Yes, that would be a significant change to the paradigm, but doable?

On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke <
stempeldergeschichte@googlemail.com> wrote:

The reason there is no such thing is that OpenSCAD can not change/set the
variables (set any(!) variable) during  execution.
But the 2d primitives are eaily written by your self.
The 3D primitives are doable too, but a little harder.

2016-10-04 12:51 GMT+02:00 Mark Schafer mschafer@wireframe.biz:

also on thingiverse is an inkscape extension which exports vector objects
to openscad format directly:

Yes it would be nice if we could have lines as first class objects in
OpenSCAD but for now these tools might help you

On 10/4/2016 1:25 PM, Ronaldo wrote:

Yes, there is but not with OpenSCAD language yet. A python code by Neon22
converts AMF files (possibly exported by OpenSCAD) to a text file in the
OpenSCAD polyhedron format. See this discussion:
http://forum.openscad.org/Wrapping-text-around-a-complex-geo
metry-td18145.html#a18156
<http://forum.openscad.org/Wrapping-text-around-a-complex-ge
ometry-td18145.html#a18156>

--
View this message in context: http://forum.openscad.org/Conv
ert-from-object-to-polygon-polyhedron-tp18522p18523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date:
10/03/16

Oh, and further to this, yes, one can write the primitives and the operators, but that would be reinventing the wheel, and would definitely be slower. Especially with things like hull() and minkowski(). The information is available, it just needs to be made available. Thinking about this further, the operators that I described are actually a module to function crossover, which doesn't currently exist in OpenSCAD, but perhaps it could possibly be doable? Maybe by some incremental build process? As I understand it, it currently builds by: 1. calculate all variables/functions 2. calculate all operations/modules. 3. show result on screen result What I would be suggesting is to iterate over the first 2 steps, executing each iteration, child node first, up to such crossover points until everything is calculated, and then do step 3. Yes, that would be a significant change to the paradigm, but doable? On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke < stempeldergeschichte@googlemail.com> wrote: > The reason there is no such thing is that OpenSCAD can not change/set the > variables (set any(!) variable) during execution. > But the 2d primitives are eaily written by your self. > The 3D primitives are doable too, but a little harder. > > 2016-10-04 12:51 GMT+02:00 Mark Schafer <mschafer@wireframe.biz>: > >> also on thingiverse is an inkscape extension which exports vector objects >> to openscad format directly: >> - http://www.thingiverse.com/thing:1065500 >> >> Yes it would be nice if we could have lines as first class objects in >> OpenSCAD but for now these tools might help you >> >> >> >> On 10/4/2016 1:25 PM, Ronaldo wrote: >> >>> Yes, there is but not with OpenSCAD language yet. A python code by Neon22 >>> converts AMF files (possibly exported by OpenSCAD) to a text file in the >>> OpenSCAD polyhedron format. See this discussion: >>> http://forum.openscad.org/Wrapping-text-around-a-complex-geo >>> metry-td18145.html#a18156 >>> <http://forum.openscad.org/Wrapping-text-around-a-complex-ge >>> ometry-td18145.html#a18156> >>> >>> >>> >>> -- >>> View this message in context: http://forum.openscad.org/Conv >>> ert-from-object-to-polygon-polyhedron-tp18522p18523.html >>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >>> >>> ----- >>> No virus found in this message. >>> Checked by AVG - www.avg.com >>> Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: >>> 10/03/16 >>> >>> >>> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
NH
nop head
Tue, Oct 4, 2016 1:59 PM

The problem is that with F5 preview the geometry is never calculated. It is
straight from variables to pixels, so the information is never there unless
you use render().

On 4 October 2016 at 14:32, Adrian H adrianh.bsc@gmail.com wrote:

Oh, and further to this, yes, one can write the primitives and the
operators, but that would be reinventing the wheel, and would definitely be
slower.  Especially with things like hull() and minkowski().

The information is available, it just needs to be made available.

Thinking about this further, the operators that I described are actually a
module to function crossover, which doesn't currently exist in OpenSCAD,
but perhaps it could possibly be doable?  Maybe by some incremental build
process?

As I understand it, it currently builds by:

1. calculate all variables/functions
2. calculate all operations/modules.
3. show result on screen result

What I would be suggesting is to iterate over the first 2 steps, executing
each iteration, child node first, up to such crossover points until
everything is calculated, and then do step 3.

Yes, that would be a significant change to the paradigm, but doable?

On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke <stempeldergeschichte@
googlemail.com> wrote:

The reason there is no such thing is that OpenSCAD can not change/set
the variables (set any(!) variable) during  execution.
But the 2d primitives are eaily written by your self.
The 3D primitives are doable too, but a little harder.

2016-10-04 12:51 GMT+02:00 Mark Schafer mschafer@wireframe.biz:

also on thingiverse is an inkscape extension which exports vector
objects to openscad format directly:

Yes it would be nice if we could have lines as first class objects in
OpenSCAD but for now these tools might help you

On 10/4/2016 1:25 PM, Ronaldo wrote:

Yes, there is but not with OpenSCAD language yet. A python code by
Neon22
converts AMF files (possibly exported by OpenSCAD) to a text file in the
OpenSCAD polyhedron format. See this discussion:
http://forum.openscad.org/Wrapping-text-around-a-complex-geo
metry-td18145.html#a18156
<http://forum.openscad.org/Wrapping-text-around-a-complex-ge
ometry-td18145.html#a18156>

--
View this message in context: http://forum.openscad.org/Conv
ert-from-object-to-polygon-polyhedron-tp18522p18523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date:
10/03/16

The problem is that with F5 preview the geometry is never calculated. It is straight from variables to pixels, so the information is never there unless you use render(). On 4 October 2016 at 14:32, Adrian H <adrianh.bsc@gmail.com> wrote: > Oh, and further to this, yes, one can write the primitives and the > operators, but that would be reinventing the wheel, and would definitely be > slower. Especially with things like hull() and minkowski(). > > The information is available, it just needs to be made available. > > Thinking about this further, the operators that I described are actually a > module to function crossover, which doesn't currently exist in OpenSCAD, > but perhaps it could possibly be doable? Maybe by some incremental build > process? > > As I understand it, it currently builds by: > > 1. calculate all variables/functions > 2. calculate all operations/modules. > 3. show result on screen result > > What I would be suggesting is to iterate over the first 2 steps, executing > each iteration, child node first, up to such crossover points until > everything is calculated, and then do step 3. > > Yes, that would be a significant change to the paradigm, but doable? > > > On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke <stempeldergeschichte@ > googlemail.com> wrote: > >> The reason there is no such thing is that OpenSCAD can not change/set >> the variables (set any(!) variable) during execution. >> But the 2d primitives are eaily written by your self. >> The 3D primitives are doable too, but a little harder. >> >> 2016-10-04 12:51 GMT+02:00 Mark Schafer <mschafer@wireframe.biz>: >> >>> also on thingiverse is an inkscape extension which exports vector >>> objects to openscad format directly: >>> - http://www.thingiverse.com/thing:1065500 >>> >>> Yes it would be nice if we could have lines as first class objects in >>> OpenSCAD but for now these tools might help you >>> >>> >>> >>> On 10/4/2016 1:25 PM, Ronaldo wrote: >>> >>>> Yes, there is but not with OpenSCAD language yet. A python code by >>>> Neon22 >>>> converts AMF files (possibly exported by OpenSCAD) to a text file in the >>>> OpenSCAD polyhedron format. See this discussion: >>>> http://forum.openscad.org/Wrapping-text-around-a-complex-geo >>>> metry-td18145.html#a18156 >>>> <http://forum.openscad.org/Wrapping-text-around-a-complex-ge >>>> ometry-td18145.html#a18156> >>>> >>>> >>>> >>>> -- >>>> View this message in context: http://forum.openscad.org/Conv >>>> ert-from-object-to-polygon-polyhedron-tp18522p18523.html >>>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> Discuss@lists.openscad.org >>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>> >>>> >>>> ----- >>>> No virus found in this message. >>>> Checked by AVG - www.avg.com >>>> Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: >>>> 10/03/16 >>>> >>>> >>>> >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
AH
Adrian H
Thu, Oct 6, 2016 12:07 AM

Oh, that's unfortunate.  But, can not the same idea apply to the preview?
It still has to have points to be able to show the preview, doesn't it?
On Oct 4, 2016 10:00 AM, "nop head" nop.head@gmail.com wrote:

The problem is that with F5 preview the geometry is never calculated. It
is straight from variables to pixels, so the information is never there
unless you use render().

On 4 October 2016 at 14:32, Adrian H adrianh.bsc@gmail.com wrote:

Oh, and further to this, yes, one can write the primitives and the
operators, but that would be reinventing the wheel, and would definitely be
slower.  Especially with things like hull() and minkowski().

The information is available, it just needs to be made available.

Thinking about this further, the operators that I described are actually
a module to function crossover, which doesn't currently exist in OpenSCAD,
but perhaps it could possibly be doable?  Maybe by some incremental build
process?

As I understand it, it currently builds by:

1. calculate all variables/functions
2. calculate all operations/modules.
3. show result on screen result

What I would be suggesting is to iterate over the first 2 steps,
executing each iteration, child node first, up to such crossover points
until everything is calculated, and then do step 3.

Yes, that would be a significant change to the paradigm, but doable?

On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke <
stempeldergeschichte@googlemail.com> wrote:

The reason there is no such thing is that OpenSCAD can not change/set
the variables (set any(!) variable) during  execution.
But the 2d primitives are eaily written by your self.
The 3D primitives are doable too, but a little harder.

2016-10-04 12:51 GMT+02:00 Mark Schafer mschafer@wireframe.biz:

also on thingiverse is an inkscape extension which exports vector
objects to openscad format directly:

Yes it would be nice if we could have lines as first class objects in
OpenSCAD but for now these tools might help you

On 10/4/2016 1:25 PM, Ronaldo wrote:

Yes, there is but not with OpenSCAD language yet. A python code by
Neon22
converts AMF files (possibly exported by OpenSCAD) to a text file in
the
OpenSCAD polyhedron format. See this discussion:
http://forum.openscad.org/Wrapping-text-around-a-complex-geo
metry-td18145.html#a18156
<http://forum.openscad.org/Wrapping-text-around-a-complex-ge
ometry-td18145.html#a18156>

--
View this message in context: http://forum.openscad.org/Conv
ert-from-object-to-polygon-polyhedron-tp18522p18523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date:
10/03/16

Oh, that's unfortunate. But, can not the same idea apply to the preview? It still has to have points to be able to show the preview, doesn't it? On Oct 4, 2016 10:00 AM, "nop head" <nop.head@gmail.com> wrote: > The problem is that with F5 preview the geometry is never calculated. It > is straight from variables to pixels, so the information is never there > unless you use render(). > > On 4 October 2016 at 14:32, Adrian H <adrianh.bsc@gmail.com> wrote: > >> Oh, and further to this, yes, one can write the primitives and the >> operators, but that would be reinventing the wheel, and would definitely be >> slower. Especially with things like hull() and minkowski(). >> >> The information is available, it just needs to be made available. >> >> Thinking about this further, the operators that I described are actually >> a module to function crossover, which doesn't currently exist in OpenSCAD, >> but perhaps it could possibly be doable? Maybe by some incremental build >> process? >> >> As I understand it, it currently builds by: >> >> 1. calculate all variables/functions >> 2. calculate all operations/modules. >> 3. show result on screen result >> >> What I would be suggesting is to iterate over the first 2 steps, >> executing each iteration, child node first, up to such crossover points >> until everything is calculated, and then do step 3. >> >> Yes, that would be a significant change to the paradigm, but doable? >> >> >> On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke < >> stempeldergeschichte@googlemail.com> wrote: >> >>> The reason there is no such thing is that OpenSCAD can not change/set >>> the variables (set any(!) variable) during execution. >>> But the 2d primitives are eaily written by your self. >>> The 3D primitives are doable too, but a little harder. >>> >>> 2016-10-04 12:51 GMT+02:00 Mark Schafer <mschafer@wireframe.biz>: >>> >>>> also on thingiverse is an inkscape extension which exports vector >>>> objects to openscad format directly: >>>> - http://www.thingiverse.com/thing:1065500 >>>> >>>> Yes it would be nice if we could have lines as first class objects in >>>> OpenSCAD but for now these tools might help you >>>> >>>> >>>> >>>> On 10/4/2016 1:25 PM, Ronaldo wrote: >>>> >>>>> Yes, there is but not with OpenSCAD language yet. A python code by >>>>> Neon22 >>>>> converts AMF files (possibly exported by OpenSCAD) to a text file in >>>>> the >>>>> OpenSCAD polyhedron format. See this discussion: >>>>> http://forum.openscad.org/Wrapping-text-around-a-complex-geo >>>>> metry-td18145.html#a18156 >>>>> <http://forum.openscad.org/Wrapping-text-around-a-complex-ge >>>>> ometry-td18145.html#a18156> >>>>> >>>>> >>>>> >>>>> -- >>>>> View this message in context: http://forum.openscad.org/Conv >>>>> ert-from-object-to-polygon-polyhedron-tp18522p18523.html >>>>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>>>> >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> Discuss@lists.openscad.org >>>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>>> >>>>> >>>>> ----- >>>>> No virus found in this message. >>>>> Checked by AVG - www.avg.com >>>>> Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: >>>>> 10/03/16 >>>>> >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> Discuss@lists.openscad.org >>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>> >>> >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >>> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
RP
Ronaldo Persiano
Thu, Oct 6, 2016 12:26 AM

Preview doesn't compute boolean operations points. Try preview cube(10);
rotate(15) sphere(10,$fn=12); with Show edges on. You will see no edges at
the intersection line.

2016-10-05 21:07 GMT-03:00 Adrian H adrianh.bsc@gmail.com:

Oh, that's unfortunate.  But, can not the same idea apply to the preview?
It still has to have points to be able to show the preview, doesn't it?
On Oct 4, 2016 10:00 AM, "nop head" nop.head@gmail.com wrote:

The problem is that with F5 preview the geometry is never calculated. It
is straight from variables to pixels, so the information is never there
unless you use render().

On 4 October 2016 at 14:32, Adrian H adrianh.bsc@gmail.com wrote:

Oh, and further to this, yes, one can write the primitives and the
operators, but that would be reinventing the wheel, and would definitely be
slower.  Especially with things like hull() and minkowski().

The information is available, it just needs to be made available.

Thinking about this further, the operators that I described are actually
a module to function crossover, which doesn't currently exist in OpenSCAD,
but perhaps it could possibly be doable?  Maybe by some incremental build
process?

As I understand it, it currently builds by:

1. calculate all variables/functions
2. calculate all operations/modules.
3. show result on screen result

What I would be suggesting is to iterate over the first 2 steps,
executing each iteration, child node first, up to such crossover points
until everything is calculated, and then do step 3.

Yes, that would be a significant change to the paradigm, but doable?

On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke <
stempeldergeschichte@googlemail.com> wrote:

The reason there is no such thing is that OpenSCAD can not change/set
the variables (set any(!) variable) during  execution.
But the 2d primitives are eaily written by your self.
The 3D primitives are doable too, but a little harder.

2016-10-04 12:51 GMT+02:00 Mark Schafer mschafer@wireframe.biz:

also on thingiverse is an inkscape extension which exports vector
objects to openscad format directly:

Yes it would be nice if we could have lines as first class objects in
OpenSCAD but for now these tools might help you

On 10/4/2016 1:25 PM, Ronaldo wrote:

Yes, there is but not with OpenSCAD language yet. A python code by
Neon22
converts AMF files (possibly exported by OpenSCAD) to a text file in
the
OpenSCAD polyhedron format. See this discussion:
http://forum.openscad.org/Wrapping-text-around-a-complex-geo
metry-td18145.html#a18156
<http://forum.openscad.org/Wrapping-text-around-a-complex-ge
ometry-td18145.html#a18156>

--
View this message in context: http://forum.openscad.org/Conv
ert-from-object-to-polygon-polyhedron-tp18522p18523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date:
10/03/16

Preview doesn't compute boolean operations points. Try preview cube(10); rotate(15) sphere(10,$fn=12); with Show edges on. You will see no edges at the intersection line. 2016-10-05 21:07 GMT-03:00 Adrian H <adrianh.bsc@gmail.com>: > Oh, that's unfortunate. But, can not the same idea apply to the preview? > It still has to have points to be able to show the preview, doesn't it? > On Oct 4, 2016 10:00 AM, "nop head" <nop.head@gmail.com> wrote: > >> The problem is that with F5 preview the geometry is never calculated. It >> is straight from variables to pixels, so the information is never there >> unless you use render(). >> >> On 4 October 2016 at 14:32, Adrian H <adrianh.bsc@gmail.com> wrote: >> >>> Oh, and further to this, yes, one can write the primitives and the >>> operators, but that would be reinventing the wheel, and would definitely be >>> slower. Especially with things like hull() and minkowski(). >>> >>> The information is available, it just needs to be made available. >>> >>> Thinking about this further, the operators that I described are actually >>> a module to function crossover, which doesn't currently exist in OpenSCAD, >>> but perhaps it could possibly be doable? Maybe by some incremental build >>> process? >>> >>> As I understand it, it currently builds by: >>> >>> 1. calculate all variables/functions >>> 2. calculate all operations/modules. >>> 3. show result on screen result >>> >>> What I would be suggesting is to iterate over the first 2 steps, >>> executing each iteration, child node first, up to such crossover points >>> until everything is calculated, and then do step 3. >>> >>> Yes, that would be a significant change to the paradigm, but doable? >>> >>> >>> On Tue, Oct 4, 2016 at 8:42 AM, Peter Falke < >>> stempeldergeschichte@googlemail.com> wrote: >>> >>>> The reason there is no such thing is that OpenSCAD can not change/set >>>> the variables (set any(!) variable) during execution. >>>> But the 2d primitives are eaily written by your self. >>>> The 3D primitives are doable too, but a little harder. >>>> >>>> 2016-10-04 12:51 GMT+02:00 Mark Schafer <mschafer@wireframe.biz>: >>>> >>>>> also on thingiverse is an inkscape extension which exports vector >>>>> objects to openscad format directly: >>>>> - http://www.thingiverse.com/thing:1065500 >>>>> >>>>> Yes it would be nice if we could have lines as first class objects in >>>>> OpenSCAD but for now these tools might help you >>>>> >>>>> >>>>> >>>>> On 10/4/2016 1:25 PM, Ronaldo wrote: >>>>> >>>>>> Yes, there is but not with OpenSCAD language yet. A python code by >>>>>> Neon22 >>>>>> converts AMF files (possibly exported by OpenSCAD) to a text file in >>>>>> the >>>>>> OpenSCAD polyhedron format. See this discussion: >>>>>> http://forum.openscad.org/Wrapping-text-around-a-complex-geo >>>>>> metry-td18145.html#a18156 >>>>>> <http://forum.openscad.org/Wrapping-text-around-a-complex-ge >>>>>> ometry-td18145.html#a18156> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> View this message in context: http://forum.openscad.org/Conv >>>>>> ert-from-object-to-polygon-polyhedron-tp18522p18523.html >>>>>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>>>>> >>>>>> _______________________________________________ >>>>>> OpenSCAD mailing list >>>>>> Discuss@lists.openscad.org >>>>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>>>> >>>>>> >>>>>> ----- >>>>>> No virus found in this message. >>>>>> Checked by AVG - www.avg.com >>>>>> Version: 2016.0.7797 / Virus Database: 4656/13139 - Release Date: >>>>>> 10/03/16 >>>>>> >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> Discuss@lists.openscad.org >>>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>>> >>>> >>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> Discuss@lists.openscad.org >>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>> >>>> >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >>> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
O
otto
Thu, Oct 6, 2016 1:11 AM

I have written a library for my work with and for openscad that does
affine transforms.  I use it to generate a module that will rotate
about the line through any two points in space given the two points.  It
simplifies a number of operations if you can wrap your brain around
the affine transform.

Code and test examples are at:

https://github.com/ottojas/openscad-affine

I would appreciate any testing comments etc.

I just created the library and realized I havn't (yet) included the
license for you to do whatever you want with it.  I will do that now.

Thanks for any help
Otto

I have written a library for my work with and for openscad that does affine transforms. I use it to generate a module that will rotate about the line through any two points in space given the two points. It simplifies a number of operations if you can wrap your brain around the affine transform. Code and test examples are at: https://github.com/ottojas/openscad-affine I would appreciate any testing comments etc. I just created the library and realized I havn't (yet) included the license for you to do whatever you want with it. I will do that now. Thanks for any help Otto
O
otto
Thu, Oct 6, 2016 1:41 AM

GPL license now with the code.

On Wed, 5 Oct 2016 18:11:39 -0700
otto otto@123phase.com wrote:

I have written a library for my work with and for openscad that does
affine transforms.  I use it to generate a module that will rotate
about the line through any two points in space given the two points.
It simplifies a number of operations if you can wrap your brain around
the affine transform.

Code and test examples are at:

https://github.com/ottojas/openscad-affine

I would appreciate any testing comments etc.

I just created the library and realized I havn't (yet) included the
license for you to do whatever you want with it.  I will do that now.

Thanks for any help
Otto


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

GPL license now with the code. On Wed, 5 Oct 2016 18:11:39 -0700 otto <otto@123phase.com> wrote: > I have written a library for my work with and for openscad that does > affine transforms. I use it to generate a module that will rotate > about the line through any two points in space given the two points. > It simplifies a number of operations if you can wrap your brain around > the affine transform. > > Code and test examples are at: > > https://github.com/ottojas/openscad-affine > > I would appreciate any testing comments etc. > > I just created the library and realized I havn't (yet) included the > license for you to do whatever you want with it. I will do that now. > > Thanks for any help > Otto > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
O
otto
Mon, Oct 10, 2016 8:53 AM

I have hacked the openscad source code to support function indirection.

Here is a sample of how it works.  Function is decorated with the "@"
character when it is created and when it is used, but not when it is
passed to another function.

//Preferred usage//
function @xsq(x) = x*x;
function @recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = "div3";
echo(map(indirect,vec2));

Output is:

ECHO: [1, 4, 9]
ECHO: [0.01, 0.49]
ECHO: [1, 0.5, 0.333333]
ECHO: [10, 1.42857]
ECHO: [0.0333333, 0.233333]

Everything is contained in the github repositor:
https://github.com/ottojas/openscad-affine

There is a pdf file there with some sample 3D and 2D output.  In order
to get this capability you need to add about 30 lines of code in
changes to five files in the source directory.  These are relatively
stable files and you may get away with simply copying them from the
ojasSources directory.

This is very much a work in progress.  Comments, questions, flames,
laughter, mockery etc. all welcome.  If anyone tests this please let me
know what your experience is.  Everything is gnu public license as is
the source code for openscad.

Regards
Otto

I have hacked the openscad source code to support function indirection. Here is a sample of how it works. Function is decorated with the "@" character when it is created and when it is used, but not when it is passed to another function. //Preferred usage// function @xsq(x) = x*x; function @recip(x)=1/x; vec1=[1,2,3]; vec2=[.1,.7]; function map(func,vec) = [for (i=vec) @func(i)]; echo(map(xsq,vec1)); echo(map(xsq,vec2)); echo(map(recip,vec1)); echo(map(recip,vec2)); //Other crazy usage// function div3(x)=x/3; indirect = "div3"; echo(map(indirect,vec2)); Output is: ECHO: [1, 4, 9] ECHO: [0.01, 0.49] ECHO: [1, 0.5, 0.333333] ECHO: [10, 1.42857] ECHO: [0.0333333, 0.233333] Everything is contained in the github repositor: https://github.com/ottojas/openscad-affine There is a pdf file there with some sample 3D and 2D output. In order to get this capability you need to add about 30 lines of code in changes to five files in the source directory. These are relatively stable files and you may get away with simply copying them from the ojasSources directory. This is very much a work in progress. Comments, questions, flames, laughter, mockery etc. all welcome. If anyone tests this please let me know what your experience is. Everything is gnu public license as is the source code for openscad. Regards Otto
NH
nop head
Mon, Oct 10, 2016 9:06 AM

You don't seem to use the @ sign in the places I would expect. I don't see
a need for them in the function definition as any function should be
passable as an argument. I would expect them to be needed where a function
is called from a string, so:

function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("xsq",vec1));
echo(map"("xsq",vec2));
echo(map("recip",vec1));
echo(map("recip",vec2));

The @ sign could also be used to make a function literal instead of passing
string but that is a bigger change to the language. Simply adding @ to take
a string and look up function seems like a simple mod. Creating a new
variable type that is a function would have much bigger implications
because it could be used in any expression. Keeping the name as a string
allows all sorts of tricks by concatenating suffixes, etc.

On 10 October 2016 at 09:53, otto otto@123phase.com wrote:

I have hacked the openscad source code to support function indirection.

Here is a sample of how it works.  Function is decorated with the "@"
character when it is created and when it is used, but not when it is
passed to another function.

//Preferred usage//
function @xsq(x) = x*x;
function @recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = "div3";
echo(map(indirect,vec2));

Output is:

ECHO: [1, 4, 9]
ECHO: [0.01, 0.49]
ECHO: [1, 0.5, 0.333333]
ECHO: [10, 1.42857]
ECHO: [0.0333333, 0.233333]

Everything is contained in the github repositor:
https://github.com/ottojas/openscad-affine

There is a pdf file there with some sample 3D and 2D output.  In order
to get this capability you need to add about 30 lines of code in
changes to five files in the source directory.  These are relatively
stable files and you may get away with simply copying them from the
ojasSources directory.

This is very much a work in progress.  Comments, questions, flames,
laughter, mockery etc. all welcome.  If anyone tests this please let me
know what your experience is.  Everything is gnu public license as is
the source code for openscad.

Regards
Otto


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

You don't seem to use the @ sign in the places I would expect. I don't see a need for them in the function definition as any function should be passable as an argument. I would expect them to be needed where a function is called from a string, so: function xsq(x) = x*x; function recip(x)=1/x; vec1=[1,2,3]; vec2=[.1,.7]; function map(func,vec) = [for (i=vec) @func(i)]; echo(map("xsq",vec1)); echo(map"("xsq",vec2)); echo(map("recip",vec1)); echo(map("recip",vec2)); The @ sign could also be used to make a function literal instead of passing string but that is a bigger change to the language. Simply adding @ to take a string and look up function seems like a simple mod. Creating a new variable type that is a function would have much bigger implications because it could be used in any expression. Keeping the name as a string allows all sorts of tricks by concatenating suffixes, etc. On 10 October 2016 at 09:53, otto <otto@123phase.com> wrote: > I have hacked the openscad source code to support function indirection. > > Here is a sample of how it works. Function is decorated with the "@" > character when it is created and when it is used, but not when it is > passed to another function. > > //Preferred usage// > function @xsq(x) = x*x; > function @recip(x)=1/x; > vec1=[1,2,3]; > vec2=[.1,.7]; > > function map(func,vec) = [for (i=vec) @func(i)]; > echo(map(xsq,vec1)); > echo(map(xsq,vec2)); > echo(map(recip,vec1)); > echo(map(recip,vec2)); > > //Other crazy usage// > function div3(x)=x/3; > indirect = "div3"; > echo(map(indirect,vec2)); > > Output is: > > ECHO: [1, 4, 9] > ECHO: [0.01, 0.49] > ECHO: [1, 0.5, 0.333333] > ECHO: [10, 1.42857] > ECHO: [0.0333333, 0.233333] > > > Everything is contained in the github repositor: > https://github.com/ottojas/openscad-affine > > There is a pdf file there with some sample 3D and 2D output. In order > to get this capability you need to add about 30 lines of code in > changes to five files in the source directory. These are relatively > stable files and you may get away with simply copying them from the > ojasSources directory. > > This is very much a work in progress. Comments, questions, flames, > laughter, mockery etc. all welcome. If anyone tests this please let me > know what your experience is. Everything is gnu public license as is > the source code for openscad. > > Regards > Otto > > > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
O
otto
Mon, Oct 10, 2016 9:19 AM

On Mon, 10 Oct 2016 10:06:50 +0100
nop head nop.head@gmail.com wrote:

The goal was to get what I wanted easily.  The changes are small and
the code seems quite stable.

In declaring a function with the @ decoration.

As in function @xsq(x) = x*x
xsq is an ID token and the variable xsq is given a unique function name
as its contents.  The name is a digit followed by a period.  You can
see it by echoing xsq.

You can then pass xsq around and then dereference it with @.  Because we
use openscads well designed and consistent parsing/compiling environment
to do all the work, this is fast.  As designed I hadn't really
anticipated the side effect that any function can be passed as its token
name, and dereferenced later.  The great thing about this is that the
compiler resolves functions by there string name and all I needed to do
was detect the decorator in the parser and then do one level of
indirection.  The nice thing is it is safe, it doesn't break other code
and it requires only small changes to the source code and it works
now.  Please test the code in the repository if you are inclined or
have the time.

Regards
Otto

You don't seem to use the @ sign in the places I would expect. I
don't see a need for them in the function definition as any function
should be passable as an argument. I would expect them to be needed
where a function is called from a string, so:

function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("xsq",vec1));
echo(map"("xsq",vec2));
echo(map("recip",vec1));
echo(map("recip",vec2));

The @ sign could also be used to make a function literal instead of
passing string but that is a bigger change to the language. Simply
adding @ to take a string and look up function seems like a simple
mod. Creating a new variable type that is a function would have much
bigger implications because it could be used in any expression.
Keeping the name as a string allows all sorts of tricks by
concatenating suffixes, etc.

On 10 October 2016 at 09:53, otto otto@123phase.com wrote:

I have hacked the openscad source code to support function
indirection.

Here is a sample of how it works.  Function is decorated with the
"@" character when it is created and when it is used, but not when
it is passed to another function.

//Preferred usage//
function @xsq(x) = x*x;
function @recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = "div3";
echo(map(indirect,vec2));

Output is:

ECHO: [1, 4, 9]
ECHO: [0.01, 0.49]
ECHO: [1, 0.5, 0.333333]
ECHO: [10, 1.42857]
ECHO: [0.0333333, 0.233333]

Everything is contained in the github repositor:
https://github.com/ottojas/openscad-affine

There is a pdf file there with some sample 3D and 2D output.  In
order to get this capability you need to add about 30 lines of code
in changes to five files in the source directory.  These are
relatively stable files and you may get away with simply copying
them from the ojasSources directory.

This is very much a work in progress.  Comments, questions, flames,
laughter, mockery etc. all welcome.  If anyone tests this please
let me know what your experience is.  Everything is gnu public
license as is the source code for openscad.

Regards
Otto


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

On Mon, 10 Oct 2016 10:06:50 +0100 nop head <nop.head@gmail.com> wrote: The goal was to get what I wanted easily. The changes are small and the code seems quite stable. In declaring a function with the @ decoration. As in function @xsq(x) = x*x xsq is an ID token and the variable xsq is given a unique function name as its contents. The name is a digit followed by a period. You can see it by echoing xsq. You can then pass xsq around and then dereference it with @. Because we use openscads well designed and consistent parsing/compiling environment to do all the work, this is fast. As designed I hadn't really anticipated the side effect that any function can be passed as its token name, and dereferenced later. The great thing about this is that the compiler resolves functions by there string name and all I needed to do was detect the decorator in the parser and then do one level of indirection. The nice thing is it is safe, it doesn't break other code and it requires only small changes to the source code and it works now. Please test the code in the repository if you are inclined or have the time. Regards Otto > You don't seem to use the @ sign in the places I would expect. I > don't see a need for them in the function definition as any function > should be passable as an argument. I would expect them to be needed > where a function is called from a string, so: > > function xsq(x) = x*x; > function recip(x)=1/x; > vec1=[1,2,3]; > vec2=[.1,.7]; > > function map(func,vec) = [for (i=vec) @func(i)]; > echo(map("xsq",vec1)); > echo(map"("xsq",vec2)); > echo(map("recip",vec1)); > echo(map("recip",vec2)); > > The @ sign could also be used to make a function literal instead of > passing string but that is a bigger change to the language. Simply > adding @ to take a string and look up function seems like a simple > mod. Creating a new variable type that is a function would have much > bigger implications because it could be used in any expression. > Keeping the name as a string allows all sorts of tricks by > concatenating suffixes, etc. > > > > On 10 October 2016 at 09:53, otto <otto@123phase.com> wrote: > > > I have hacked the openscad source code to support function > > indirection. > > > > Here is a sample of how it works. Function is decorated with the > > "@" character when it is created and when it is used, but not when > > it is passed to another function. > > > > //Preferred usage// > > function @xsq(x) = x*x; > > function @recip(x)=1/x; > > vec1=[1,2,3]; > > vec2=[.1,.7]; > > > > function map(func,vec) = [for (i=vec) @func(i)]; > > echo(map(xsq,vec1)); > > echo(map(xsq,vec2)); > > echo(map(recip,vec1)); > > echo(map(recip,vec2)); > > > > //Other crazy usage// > > function div3(x)=x/3; > > indirect = "div3"; > > echo(map(indirect,vec2)); > > > > Output is: > > > > ECHO: [1, 4, 9] > > ECHO: [0.01, 0.49] > > ECHO: [1, 0.5, 0.333333] > > ECHO: [10, 1.42857] > > ECHO: [0.0333333, 0.233333] > > > > > > Everything is contained in the github repositor: > > https://github.com/ottojas/openscad-affine > > > > There is a pdf file there with some sample 3D and 2D output. In > > order to get this capability you need to add about 30 lines of code > > in changes to five files in the source directory. These are > > relatively stable files and you may get away with simply copying > > them from the ojasSources directory. > > > > This is very much a work in progress. Comments, questions, flames, > > laughter, mockery etc. all welcome. If anyone tests this please > > let me know what your experience is. Everything is gnu public > > license as is the source code for openscad. > > > > Regards > > Otto > > > > > > > > > > > > _______________________________________________ > > OpenSCAD mailing list > > Discuss@lists.openscad.org > > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
NH
nop head
Mon, Oct 10, 2016 9:44 AM

So @xsq becomes both a name mangled function and a variable holding its
name? That seems like a bit of a kludge to me.

Defining functions normally and passing them with @name would allow the
compiler to check it was a valid function name without having to have
specially decorated functions. They could be passed as string equal to
their name and then calling @func() could work with any string that equals
a function name. Seems less kludgey to me. You only have one type of
function rather than ones that have to be called normally and ones that
need to be called with @.

On 10 October 2016 at 10:19, otto otto@123phase.com wrote:

On Mon, 10 Oct 2016 10:06:50 +0100
nop head nop.head@gmail.com wrote:

The goal was to get what I wanted easily.  The changes are small and
the code seems quite stable.

In declaring a function with the @ decoration.

As in function @xsq(x) = x*x
xsq is an ID token and the variable xsq is given a unique function name
as its contents.  The name is a digit followed by a period.  You can
see it by echoing xsq.

You can then pass xsq around and then dereference it with @.  Because we
use openscads well designed and consistent parsing/compiling environment
to do all the work, this is fast.  As designed I hadn't really
anticipated the side effect that any function can be passed as its token
name, and dereferenced later.  The great thing about this is that the
compiler resolves functions by there string name and all I needed to do
was detect the decorator in the parser and then do one level of
indirection.  The nice thing is it is safe, it doesn't break other code
and it requires only small changes to the source code and it works
now.  Please test the code in the repository if you are inclined or
have the time.

Regards
Otto

You don't seem to use the @ sign in the places I would expect. I
don't see a need for them in the function definition as any function
should be passable as an argument. I would expect them to be needed
where a function is called from a string, so:

function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("xsq",vec1));
echo(map"("xsq",vec2));
echo(map("recip",vec1));
echo(map("recip",vec2));

The @ sign could also be used to make a function literal instead of
passing string but that is a bigger change to the language. Simply
adding @ to take a string and look up function seems like a simple
mod. Creating a new variable type that is a function would have much
bigger implications because it could be used in any expression.
Keeping the name as a string allows all sorts of tricks by
concatenating suffixes, etc.

On 10 October 2016 at 09:53, otto otto@123phase.com wrote:

I have hacked the openscad source code to support function
indirection.

Here is a sample of how it works.  Function is decorated with the
"@" character when it is created and when it is used, but not when
it is passed to another function.

//Preferred usage//
function @xsq(x) = x*x;
function @recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = "div3";
echo(map(indirect,vec2));

Output is:

ECHO: [1, 4, 9]
ECHO: [0.01, 0.49]
ECHO: [1, 0.5, 0.333333]
ECHO: [10, 1.42857]
ECHO: [0.0333333, 0.233333]

Everything is contained in the github repositor:
https://github.com/ottojas/openscad-affine

There is a pdf file there with some sample 3D and 2D output.  In
order to get this capability you need to add about 30 lines of code
in changes to five files in the source directory.  These are
relatively stable files and you may get away with simply copying
them from the ojasSources directory.

This is very much a work in progress.  Comments, questions, flames,
laughter, mockery etc. all welcome.  If anyone tests this please
let me know what your experience is.  Everything is gnu public
license as is the source code for openscad.

Regards
Otto


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

So @xsq becomes both a name mangled function and a variable holding its name? That seems like a bit of a kludge to me. Defining functions normally and passing them with @name would allow the compiler to check it was a valid function name without having to have specially decorated functions. They could be passed as string equal to their name and then calling @func() could work with any string that equals a function name. Seems less kludgey to me. You only have one type of function rather than ones that have to be called normally and ones that need to be called with @. On 10 October 2016 at 10:19, otto <otto@123phase.com> wrote: > On Mon, 10 Oct 2016 10:06:50 +0100 > nop head <nop.head@gmail.com> wrote: > > The goal was to get what I wanted easily. The changes are small and > the code seems quite stable. > > In declaring a function with the @ decoration. > > As in function @xsq(x) = x*x > xsq is an ID token and the variable xsq is given a unique function name > as its contents. The name is a digit followed by a period. You can > see it by echoing xsq. > > You can then pass xsq around and then dereference it with @. Because we > use openscads well designed and consistent parsing/compiling environment > to do all the work, this is fast. As designed I hadn't really > anticipated the side effect that any function can be passed as its token > name, and dereferenced later. The great thing about this is that the > compiler resolves functions by there string name and all I needed to do > was detect the decorator in the parser and then do one level of > indirection. The nice thing is it is safe, it doesn't break other code > and it requires only small changes to the source code and it works > now. Please test the code in the repository if you are inclined or > have the time. > > > Regards > Otto > > > > You don't seem to use the @ sign in the places I would expect. I > > don't see a need for them in the function definition as any function > > should be passable as an argument. I would expect them to be needed > > where a function is called from a string, so: > > > > function xsq(x) = x*x; > > function recip(x)=1/x; > > vec1=[1,2,3]; > > vec2=[.1,.7]; > > > > function map(func,vec) = [for (i=vec) @func(i)]; > > echo(map("xsq",vec1)); > > echo(map"("xsq",vec2)); > > echo(map("recip",vec1)); > > echo(map("recip",vec2)); > > > > The @ sign could also be used to make a function literal instead of > > passing string but that is a bigger change to the language. Simply > > adding @ to take a string and look up function seems like a simple > > mod. Creating a new variable type that is a function would have much > > bigger implications because it could be used in any expression. > > Keeping the name as a string allows all sorts of tricks by > > concatenating suffixes, etc. > > > > > > > > On 10 October 2016 at 09:53, otto <otto@123phase.com> wrote: > > > > > I have hacked the openscad source code to support function > > > indirection. > > > > > > Here is a sample of how it works. Function is decorated with the > > > "@" character when it is created and when it is used, but not when > > > it is passed to another function. > > > > > > //Preferred usage// > > > function @xsq(x) = x*x; > > > function @recip(x)=1/x; > > > vec1=[1,2,3]; > > > vec2=[.1,.7]; > > > > > > function map(func,vec) = [for (i=vec) @func(i)]; > > > echo(map(xsq,vec1)); > > > echo(map(xsq,vec2)); > > > echo(map(recip,vec1)); > > > echo(map(recip,vec2)); > > > > > > //Other crazy usage// > > > function div3(x)=x/3; > > > indirect = "div3"; > > > echo(map(indirect,vec2)); > > > > > > Output is: > > > > > > ECHO: [1, 4, 9] > > > ECHO: [0.01, 0.49] > > > ECHO: [1, 0.5, 0.333333] > > > ECHO: [10, 1.42857] > > > ECHO: [0.0333333, 0.233333] > > > > > > > > > Everything is contained in the github repositor: > > > https://github.com/ottojas/openscad-affine > > > > > > There is a pdf file there with some sample 3D and 2D output. In > > > order to get this capability you need to add about 30 lines of code > > > in changes to five files in the source directory. These are > > > relatively stable files and you may get away with simply copying > > > them from the ojasSources directory. > > > > > > This is very much a work in progress. Comments, questions, flames, > > > laughter, mockery etc. all welcome. If anyone tests this please > > > let me know what your experience is. Everything is gnu public > > > license as is the source code for openscad. > > > > > > Regards > > > Otto > > > > > > > > > > > > > > > > > > _______________________________________________ > > > OpenSCAD mailing list > > > Discuss@lists.openscad.org > > > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
O
otto
Mon, Oct 10, 2016 5:13 PM

On Mon, 10 Oct 2016 10:44:13 +0100
nop head nop.head@gmail.com wrote:

So @xsq becomes both a name mangled function and a variable holding
its name? That seems like a bit of a kludge to me.

Well its like this, you can pass a function with the name of the
function in quotes.

function div3(x)=x/3;
vec = [1,2,3];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("div3",vec));

And it works:

Compiling design (CSG Tree generation)...
ECHO: [0.333333, 0.666667, 1]

Using the construct funcion @xyz .., gives you a way to create a
function and have the compiler generate a name for the function and put
it in a variable for you. "@" used in other contexts is simply a
dereferencing operator.  It does require that the name following the
"@" is a variable name known by the compiler and not an expression
returning a string.  "@concat("d","iv3")" will not work.

A syntax that would work nicely (but requires more hacking on my part)
would be to create true anonymous functions with syntax such as follows.

Abandon the "function @...",
shorten it to "@(<argument list>,<function,def>)"
Which returns the created name of the function.  This would allow for
a more anonymous lambda like usage.

Map could then be invoked, map(@(x,x/3),[1,2,3]), which is more compact
and would get the right behavior.

Thanks for the questions and idea.  You are helping me think it
through.  Please try current code.  I think I will try to program
this capability next week. I am going on a trip this week.

BTW what is best way to pass on this code in github.

Regards
Otto

Defining functions normally and passing them with @name would allow
the compiler to check it was a valid function name without having to
have specially decorated functions. They could be passed as string
equal to their name and then calling @func() could work with any
string that equals a function name. Seems less kludgey to me. You
only have one type of function rather than ones that have to be
called normally and ones that need to be called with @.

On 10 October 2016 at 10:19, otto otto@123phase.com wrote:

On Mon, 10 Oct 2016 10:06:50 +0100
nop head nop.head@gmail.com wrote:

The goal was to get what I wanted easily.  The changes are small and
the code seems quite stable.

In declaring a function with the @ decoration.

As in function @xsq(x) = x*x
xsq is an ID token and the variable xsq is given a unique function
name as its contents.  The name is a digit followed by a period.
You can see it by echoing xsq.

You can then pass xsq around and then dereference it with @.
Because we use openscads well designed and consistent
parsing/compiling environment to do all the work, this is fast.  As
designed I hadn't really anticipated the side effect that any
function can be passed as its token name, and dereferenced later.
The great thing about this is that the compiler resolves functions
by there string name and all I needed to do was detect the
decorator in the parser and then do one level of indirection.  The
nice thing is it is safe, it doesn't break other code and it
requires only small changes to the source code and it works now.
Please test the code in the repository if you are inclined or have
the time.

Regards
Otto

You don't seem to use the @ sign in the places I would expect. I
don't see a need for them in the function definition as any
function should be passable as an argument. I would expect them
to be needed where a function is called from a string, so:

function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("xsq",vec1));
echo(map"("xsq",vec2));
echo(map("recip",vec1));
echo(map("recip",vec2));

The @ sign could also be used to make a function literal instead
of passing string but that is a bigger change to the language.
Simply adding @ to take a string and look up function seems like
a simple mod. Creating a new variable type that is a function
would have much bigger implications because it could be used in
any expression. Keeping the name as a string allows all sorts of
tricks by concatenating suffixes, etc.

On 10 October 2016 at 09:53, otto otto@123phase.com wrote:

I have hacked the openscad source code to support function
indirection.

Here is a sample of how it works.  Function is decorated with
the "@" character when it is created and when it is used, but
not when it is passed to another function.

//Preferred usage//
function @xsq(x) = x*x;
function @recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = "div3";
echo(map(indirect,vec2));

Output is:

ECHO: [1, 4, 9]
ECHO: [0.01, 0.49]
ECHO: [1, 0.5, 0.333333]
ECHO: [10, 1.42857]
ECHO: [0.0333333, 0.233333]

Everything is contained in the github repositor:
https://github.com/ottojas/openscad-affine

There is a pdf file there with some sample 3D and 2D output.  In
order to get this capability you need to add about 30 lines of
code in changes to five files in the source directory.  These
are relatively stable files and you may get away with simply
copying them from the ojasSources directory.

This is very much a work in progress.  Comments, questions,
flames, laughter, mockery etc. all welcome.  If anyone tests
this please let me know what your experience is.  Everything is
gnu public license as is the source code for openscad.

Regards
Otto


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

On Mon, 10 Oct 2016 10:44:13 +0100 nop head <nop.head@gmail.com> wrote: > So @xsq becomes both a name mangled function and a variable holding > its name? That seems like a bit of a kludge to me. Well its like this, you can pass a function with the name of the function in quotes. function div3(x)=x/3; vec = [1,2,3]; function map(func,vec) = [for (i=vec) @func(i)]; echo(map("div3",vec)); And it works: Compiling design (CSG Tree generation)... ECHO: [0.333333, 0.666667, 1] Using the construct funcion @xyz .., gives you a way to create a function and have the compiler generate a name for the function and put it in a variable for you. "@" used in other contexts is simply a dereferencing operator. It does require that the name following the "@" is a variable name known by the compiler and not an expression returning a string. "@concat("d","iv3")" will not work. A syntax that would work nicely (but requires more hacking on my part) would be to create true anonymous functions with syntax such as follows. Abandon the "function @...", shorten it to "@(<argument list>,<function,def>)" Which returns the created name of the function. This would allow for a more anonymous lambda like usage. Map could then be invoked, map(@(x,x/3),[1,2,3]), which is more compact and would get the right behavior. Thanks for the questions and idea. You are helping me think it through. Please try current code. I think I will try to program this capability next week. I am going on a trip this week. BTW what is best way to pass on this code in github. Regards Otto > > Defining functions normally and passing them with @name would allow > the compiler to check it was a valid function name without having to > have specially decorated functions. They could be passed as string > equal to their name and then calling @func() could work with any > string that equals a function name. Seems less kludgey to me. You > only have one type of function rather than ones that have to be > called normally and ones that need to be called with @. > > On 10 October 2016 at 10:19, otto <otto@123phase.com> wrote: > > > On Mon, 10 Oct 2016 10:06:50 +0100 > > nop head <nop.head@gmail.com> wrote: > > > > The goal was to get what I wanted easily. The changes are small and > > the code seems quite stable. > > > > In declaring a function with the @ decoration. > > > > As in function @xsq(x) = x*x > > xsq is an ID token and the variable xsq is given a unique function > > name as its contents. The name is a digit followed by a period. > > You can see it by echoing xsq. > > > > You can then pass xsq around and then dereference it with @. > > Because we use openscads well designed and consistent > > parsing/compiling environment to do all the work, this is fast. As > > designed I hadn't really anticipated the side effect that any > > function can be passed as its token name, and dereferenced later. > > The great thing about this is that the compiler resolves functions > > by there string name and all I needed to do was detect the > > decorator in the parser and then do one level of indirection. The > > nice thing is it is safe, it doesn't break other code and it > > requires only small changes to the source code and it works now. > > Please test the code in the repository if you are inclined or have > > the time. > > > > > > Regards > > Otto > > > > > > > You don't seem to use the @ sign in the places I would expect. I > > > don't see a need for them in the function definition as any > > > function should be passable as an argument. I would expect them > > > to be needed where a function is called from a string, so: > > > > > > function xsq(x) = x*x; > > > function recip(x)=1/x; > > > vec1=[1,2,3]; > > > vec2=[.1,.7]; > > > > > > function map(func,vec) = [for (i=vec) @func(i)]; > > > echo(map("xsq",vec1)); > > > echo(map"("xsq",vec2)); > > > echo(map("recip",vec1)); > > > echo(map("recip",vec2)); > > > > > > The @ sign could also be used to make a function literal instead > > > of passing string but that is a bigger change to the language. > > > Simply adding @ to take a string and look up function seems like > > > a simple mod. Creating a new variable type that is a function > > > would have much bigger implications because it could be used in > > > any expression. Keeping the name as a string allows all sorts of > > > tricks by concatenating suffixes, etc. > > > > > > > > > > > > On 10 October 2016 at 09:53, otto <otto@123phase.com> wrote: > > > > > > > I have hacked the openscad source code to support function > > > > indirection. > > > > > > > > Here is a sample of how it works. Function is decorated with > > > > the "@" character when it is created and when it is used, but > > > > not when it is passed to another function. > > > > > > > > //Preferred usage// > > > > function @xsq(x) = x*x; > > > > function @recip(x)=1/x; > > > > vec1=[1,2,3]; > > > > vec2=[.1,.7]; > > > > > > > > function map(func,vec) = [for (i=vec) @func(i)]; > > > > echo(map(xsq,vec1)); > > > > echo(map(xsq,vec2)); > > > > echo(map(recip,vec1)); > > > > echo(map(recip,vec2)); > > > > > > > > //Other crazy usage// > > > > function div3(x)=x/3; > > > > indirect = "div3"; > > > > echo(map(indirect,vec2)); > > > > > > > > Output is: > > > > > > > > ECHO: [1, 4, 9] > > > > ECHO: [0.01, 0.49] > > > > ECHO: [1, 0.5, 0.333333] > > > > ECHO: [10, 1.42857] > > > > ECHO: [0.0333333, 0.233333] > > > > > > > > > > > > Everything is contained in the github repositor: > > > > https://github.com/ottojas/openscad-affine > > > > > > > > There is a pdf file there with some sample 3D and 2D output. In > > > > order to get this capability you need to add about 30 lines of > > > > code in changes to five files in the source directory. These > > > > are relatively stable files and you may get away with simply > > > > copying them from the ojasSources directory. > > > > > > > > This is very much a work in progress. Comments, questions, > > > > flames, laughter, mockery etc. all welcome. If anyone tests > > > > this please let me know what your experience is. Everything is > > > > gnu public license as is the source code for openscad. > > > > > > > > Regards > > > > Otto > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > OpenSCAD mailing list > > > > Discuss@lists.openscad.org > > > > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > > > > > > > > _______________________________________________ > > OpenSCAD mailing list > > Discuss@lists.openscad.org > > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
B
Bananapeel
Mon, Oct 10, 2016 7:15 PM

I don't know why this thread is inside the thread "Convert from object to
polygon/polyhedron." Anyways, regarding passing functions as arguments:

IMO, there's just one "proper" syntax for this. And that is, that the name
without () acts as a variable, and () means call. And function becomes just
another type, like string and int. This means functions and variables must
occupy the same namespace. This syntax can also work for modules, however,
this means variables, functions and modules all share the same namespace,
which currently isn't the case.

Using () on a variable that isn't of type function or module would give a
runtime error.

Example:

//Preferred usage//
function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1, 2, 3];
vec2=[0.1, 0.7];

function map(func,vec) = [for (i=vec) func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = div3;
echo(map(indirect,vec2));

--
View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18659.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I don't know why this thread is inside the thread "Convert from object to polygon/polyhedron." Anyways, regarding passing functions as arguments: IMO, there's just one "proper" syntax for this. And that is, that the name without () acts as a variable, and () means call. And function becomes just another type, like string and int. This means functions and variables must occupy the same namespace. This syntax can also work for modules, however, this means variables, functions and modules all share the same namespace, which currently isn't the case. Using () on a variable that isn't of type function or module would give a runtime error. Example: //Preferred usage// function xsq(x) = x*x; function recip(x)=1/x; vec1=[1, 2, 3]; vec2=[0.1, 0.7]; function map(func,vec) = [for (i=vec) func(i)]; echo(map(xsq,vec1)); echo(map(xsq,vec2)); echo(map(recip,vec1)); echo(map(recip,vec2)); //Other crazy usage// function div3(x)=x/3; indirect = div3; echo(map(indirect,vec2)); -- View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18659.html Sent from the OpenSCAD mailing list archive at Nabble.com.
A
adrian
Mon, Oct 10, 2016 8:50 PM

Bananapeel wrote

I don't know why this thread is inside the thread "Convert from object to
polygon/polyhedron."

Yes, I feel that my thread got hijacked somehow.

Bananapeel wrote

IMO, there's just one "proper" syntax for this. And that is, that the name
without () acts as a variable, and () means call. And function becomes
just another type, like string and int. This means functions and variables
must occupy the same namespace. This syntax can also work for modules,
however, this means variables, functions and modules all share the same
namespace, which currently isn't the case.

Using () on a variable that isn't of type function or module would give a
runtime error.

Yes, this sounds somewhat reasonable, but these namespaces don't have to
collide.  They can still be (and really should remain) separate, as changing
this could break a lot of scripts.  One can gain access to the function
namespace using that @ sign (or some other sign.  I assume that & wasn't
used for simplicity):

It would also be nice to have proper lambdas:

This syntax would introduce being able to create true lambdas on the fly,
instead of always having to name them and access the function namespace.

--
View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18662.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Bananapeel wrote > I don't know why this thread is inside the thread "Convert from object to > polygon/polyhedron." Yes, I feel that my thread got hijacked somehow. Bananapeel wrote > IMO, there's just one "proper" syntax for this. And that is, that the name > without () acts as a variable, and () means call. And function becomes > just another type, like string and int. This means functions and variables > must occupy the same namespace. This syntax can also work for modules, > however, this means variables, functions and modules all share the same > namespace, which currently isn't the case. > > Using () on a variable that isn't of type function or module would give a > runtime error. Yes, this sounds somewhat reasonable, but these namespaces don't have to collide. They can still be (and really should remain) separate, as changing this could break a lot of scripts. One can gain access to the function namespace using that @ sign (or some other sign. I assume that & wasn't used for simplicity): It would also be nice to have proper lambdas: This syntax would introduce being able to create true lambdas on the fly, instead of always having to name them and access the function namespace. -- View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18662.html Sent from the OpenSCAD mailing list archive at Nabble.com.
O
otto
Mon, Oct 10, 2016 9:15 PM

Let me summarize current situation:

The following work in my current code:

function map(func,vec) = [for (i=vec) @func(i)];
function @xsq(x) = x*x;
function recip(x)=1/x;
box = "recip";

vec1=[1, 2, 3];
map(box,vec);
map(xsq,vec);

Objections have been:

  1. First version using "function @xsq(x)" seems kludgy.
  2. One suggestion was the following syntax:

function recip(x)=1/x;
vec1=[1, 2, 3];
function map(func,vec) = [for (i=vec) func(i)];

which seems intuitive.
3. (my own objections)  None of these allow for lambda like syntax.

I have a particular problem with my own current code and all
suggestions.  They fail to implement lambda. Suggestion 2 is
essentially the same way that python deals with indirection, Python
provides two methods of creating a function. One method uses a def
statement and the other uses the Lambda construct. They are equivalent
and dereferencing is automatic.

I believe I can get the lambda behavior relatively easily in the current
system. To add lambda syntax I will implement it as:

@(<argumentlist>:<functionDefintion>)

which I think is easier to read than (from python):

lambda <argumentlist>:<functionDefintion>

Either implementation is possible and if enough people request one over
the other, I am willing to implement either.  The first is much simpler
to add for me with my current shallow knowledge of how the code works
and really requires very small changes.

The following would then work:

vec1=[1, 2, 3];
function map(func,vec) = [for (i=vec) @func(i)];
recip = @(x:1/x);
map(recip,vec); //this would work as before
map(@(x,x*x),vec); //this would be using @ as lambda.

I actually believe that the dereferencing of a variable name using "@"
makes the code clearer and easier to maintain and we lose nothing in
terms of capabilities.

If anyone wants to hack the code themselves to obtain any behavior, I
am happy to help point out where in the code changes can be made.
Currently there are only about 30 lines of code that have been added. In
addition, there are some problems currently in my code that could use
some work. I will post these in openscad-affine when I have time.
Collaboration on this is desirable. Incidentally I need these changes
for my work.  The modules in paraSolids are essential for me and need
the function indirection capabilities to work.

For examples of pretty picture please see: ParaSolidExamples.pdf
which is among the files at https://github.com/ottojas/openscad-affine

The repo needs some re-arrangement but I think everything is there..

Thoughts?

I would really like it if someone would test the code I have written.
I am almost exclusively on debian based linux systems.  Debian, Ubuntu
and mint.  I would be happy to build a binary for one of these if that
is what someone willing to test would like.  I am definitely going to
implement the second syntax when i have time (next week at earliest),
that is the "@(<argument list>:<function definition>)" syntax for an
anonymous function.

If requested, I will fork the complete source code setup so you can
compile on any system.  Is that a good idea??

Regards
Otto

On Mon, 10 Oct 2016 12:15:31 -0700 (MST)
Bananapeel lunatica.xiaoyu@gmail.com wrote:

I don't know why this thread is inside the thread "Convert from
object to polygon/polyhedron." Anyways, regarding passing functions
as arguments:

IMO, there's just one "proper" syntax for this. And that is, that the
name without () acts as a variable, and () means call. And function
becomes just another type, like string and int. This means functions
and variables must occupy the same namespace. This syntax can also
work for modules, however, this means variables, functions and
modules all share the same namespace, which currently isn't the case.

Using () on a variable that isn't of type function or module would
give a runtime error.

Example:

//Preferred usage//
function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1, 2, 3];
vec2=[0.1, 0.7];

function map(func,vec) = [for (i=vec) func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = div3;
echo(map(indirect,vec2));

--
View this message in context:
http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18659.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Let me summarize current situation: The following work in my current code: function map(func,vec) = [for (i=vec) @func(i)]; function @xsq(x) = x*x; function recip(x)=1/x; box = "recip"; vec1=[1, 2, 3]; map(box,vec); map(xsq,vec); Objections have been: 1. First version using "function @xsq(x)" seems kludgy. 2. One suggestion was the following syntax: > function recip(x)=1/x; > vec1=[1, 2, 3]; > function map(func,vec) = [for (i=vec) func(i)]; which seems intuitive. 3. (my own objections) None of these allow for lambda like syntax. I have a particular problem with my own current code and all suggestions. They fail to implement lambda. Suggestion 2 is essentially the same way that python deals with indirection, Python provides two methods of creating a function. One method uses a def statement and the other uses the Lambda construct. They are equivalent and dereferencing is automatic. I believe I can get the lambda behavior relatively easily in the current system. To add lambda syntax I will implement it as: @(<argumentlist>:<functionDefintion>) which I think is easier to read than (from python): lambda <argumentlist>:<functionDefintion> Either implementation is possible and if enough people request one over the other, I am willing to implement either. The first is much simpler to add for me with my current shallow knowledge of how the code works and really requires very small changes. The following would then work: vec1=[1, 2, 3]; function map(func,vec) = [for (i=vec) @func(i)]; recip = @(x:1/x); map(recip,vec); //this would work as before map(@(x,x*x),vec); //this would be using @ as lambda. I actually believe that the dereferencing of a variable name using "@" makes the code clearer and easier to maintain and we lose nothing in terms of capabilities. If anyone wants to hack the code themselves to obtain any behavior, I am happy to help point out where in the code changes can be made. Currently there are only about 30 lines of code that have been added. In addition, there are some problems currently in my code that could use some work. I will post these in openscad-affine when I have time. Collaboration on this is desirable. Incidentally I need these changes for my work. The modules in paraSolids are essential for me and need the function indirection capabilities to work. For examples of pretty picture please see: ParaSolidExamples.pdf which is among the files at https://github.com/ottojas/openscad-affine The repo needs some re-arrangement but I think everything is there.. Thoughts? I would really like it if someone would test the code I have written. I am almost exclusively on debian based linux systems. Debian, Ubuntu and mint. I would be happy to build a binary for one of these if that is what someone willing to test would like. I am definitely going to implement the second syntax when i have time (next week at earliest), that is the "@(<argument list>:<function definition>)" syntax for an anonymous function. If requested, I will fork the complete source code setup so you can compile on any system. Is that a good idea?? Regards Otto On Mon, 10 Oct 2016 12:15:31 -0700 (MST) Bananapeel <lunatica.xiaoyu@gmail.com> wrote: > I don't know why this thread is inside the thread "Convert from > object to polygon/polyhedron." Anyways, regarding passing functions > as arguments: > > IMO, there's just one "proper" syntax for this. And that is, that the > name without () acts as a variable, and () means call. And function > becomes just another type, like string and int. This means functions > and variables must occupy the same namespace. This syntax can also > work for modules, however, this means variables, functions and > modules all share the same namespace, which currently isn't the case. > > Using () on a variable that isn't of type function or module would > give a runtime error. > > Example: > > //Preferred usage// > function xsq(x) = x*x; > function recip(x)=1/x; > vec1=[1, 2, 3]; > vec2=[0.1, 0.7]; > > function map(func,vec) = [for (i=vec) func(i)]; > echo(map(xsq,vec1)); > echo(map(xsq,vec2)); > echo(map(recip,vec1)); > echo(map(recip,vec2)); > > //Other crazy usage// > function div3(x)=x/3; > indirect = div3; > echo(map(indirect,vec2)); > > > > > -- > View this message in context: > http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18659.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
TP
Torsten Paul
Mon, Oct 10, 2016 9:23 PM

On 10/10/2016 11:15 PM, otto wrote:

Either implementation is possible and if enough people
request one over the other, I am willing to implement
either.  The first is much simpler to add for me with
my current shallow knowledge of how the code works and
really requires very small changes.

Did you see the work Doug did?

https://github.com/doug-moen/openscad2

It's proposing a way to a more powerful language while still
trying to be as compatible as possible.

It would be ideal if we could get the feature aligned with
those efforts. I think it would be a nice thing to get for
current OpenSCAD already.

ciao,
Torsten.

On 10/10/2016 11:15 PM, otto wrote: > Either implementation is possible and if enough people > request one over the other, I am willing to implement > either. The first is much simpler to add for me with > my current shallow knowledge of how the code works and > really requires very small changes. > Did you see the work Doug did? https://github.com/doug-moen/openscad2 It's proposing a way to a more powerful language while still trying to be as compatible as possible. It would be ideal if we could get the feature aligned with those efforts. I think it would be a nice thing to get for current OpenSCAD already. ciao, Torsten.
CA
Carsten Arnholm
Mon, Oct 10, 2016 9:23 PM

On 10. okt. 2016 19:13, otto wrote:

On Mon, 10 Oct 2016 10:44:13 +0100
nop head nop.head@gmail.com wrote:

So @xsq becomes both a name mangled function and a variable holding
its name? That seems like a bit of a kludge to me.

Well its like this, you can pass a function with the name of the
function in quotes.

function div3(x)=x/3;
vec = [1,2,3];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("div3",vec));

And it works:

Compiling design (CSG Tree generation)...
ECHO: [0.333333, 0.666667, 1]

Sometimes I wonder why OpenSCAD reinvents standard language features of
existing languages... below are some thoughts intended as inspiration.
Your example code is applied to AngelScript, a language I use for 3d
modelling:

funcdef double FUNC(double x);
double div3(double x) { return x/3; }
void map(FUNC @func, double[] @vec)
{ for(uint i=0; i<vec.size(); i++) { vec[i]=func(vec[i]); }  }

void main()
{
double[] vec = { 1,2,3 };
map(div3,vec);
for(uint i=0; i<vec.size(); i++) print(vec[i]+' ');
}

output is the expected:
0.333333 0.666667 1

First, a function signature 'FUNC' is defined, i.e. one taking and
returning a double. Second, an actual function 'div3' with a signature
compatible with FUNC is defined. Third, the 'map' function where the
'func' parameter is passed 'by handle' using @ resembles your code
(alternate syntax "FUNC@ func" also ok). The array 'vec' also passed 'by
handle' so the caller sees the modified 'vec' after calling 'map'

If I had tried to call map using another function, e.g.
double divn(double x, int n) { return x/n; }
it would generate an error because 'divn' is incompatible with the FUNC
signature. It is not clear from your example what happens if you did a
similar mistake.

Just take this comment as food for thought & inspiration.

Regards
Carsten Arnholm

On 10. okt. 2016 19:13, otto wrote: > On Mon, 10 Oct 2016 10:44:13 +0100 > nop head <nop.head@gmail.com> wrote: > >> So @xsq becomes both a name mangled function and a variable holding >> its name? That seems like a bit of a kludge to me. > > Well its like this, you can pass a function with the name of the > function in quotes. > > function div3(x)=x/3; > vec = [1,2,3]; > > function map(func,vec) = [for (i=vec) @func(i)]; > echo(map("div3",vec)); > > And it works: > > Compiling design (CSG Tree generation)... > ECHO: [0.333333, 0.666667, 1] Sometimes I wonder why OpenSCAD reinvents standard language features of existing languages... below are some thoughts intended as inspiration. Your example code is applied to AngelScript, a language I use for 3d modelling: funcdef double FUNC(double x); double div3(double x) { return x/3; } void map(FUNC @func, double[] @vec) { for(uint i=0; i<vec.size(); i++) { vec[i]=func(vec[i]); } } void main() { double[] vec = { 1,2,3 }; map(div3,vec); for(uint i=0; i<vec.size(); i++) print(vec[i]+' '); } output is the expected: 0.333333 0.666667 1 First, a function signature 'FUNC' is defined, i.e. one taking and returning a double. Second, an actual function 'div3' with a signature compatible with FUNC is defined. Third, the 'map' function where the 'func' parameter is passed 'by handle' using @ resembles your code (alternate syntax "FUNC@ func" also ok). The array 'vec' also passed 'by handle' so the caller sees the modified 'vec' after calling 'map' If I had tried to call map using another function, e.g. double divn(double x, int n) { return x/n; } it would generate an error because 'divn' is incompatible with the FUNC signature. It is not clear from your example what happens if you did a similar mistake. Just take this comment as food for thought & inspiration. Regards Carsten Arnholm
O
otto
Mon, Oct 10, 2016 9:46 PM

Thanks for reference.  I am new here, found openscad as an ideal
platform for what I wanted to do.  Found some limits and decided to
hack the code.  I am concerned that I may be duplicating others work.
I will read these documents.

I am trying to make the code more powerful and maintain compatibility.
This was intended to meet my own personal needs but I see it as a
possibility for the whole community.

Best Regards
Otto

On Mon, 10 Oct 2016 23:23:28 +0200
Torsten Paul Torsten.Paul@gmx.de wrote:

On 10/10/2016 11:15 PM, otto wrote:

Either implementation is possible and if enough people
request one over the other, I am willing to implement
either.  The first is much simpler to add for me with
my current shallow knowledge of how the code works and
really requires very small changes.

Did you see the work Doug did?

https://github.com/doug-moen/openscad2

It's proposing a way to a more powerful language while still
trying to be as compatible as possible.

It would be ideal if we could get the feature aligned with
those efforts. I think it would be a nice thing to get for
current OpenSCAD already.

ciao,
Torsten.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Thanks for reference. I am new here, found openscad as an ideal platform for what I wanted to do. Found some limits and decided to hack the code. I am concerned that I may be duplicating others work. I will read these documents. I am trying to make the code more powerful and maintain compatibility. This was intended to meet my own personal needs but I see it as a possibility for the whole community. Best Regards Otto On Mon, 10 Oct 2016 23:23:28 +0200 Torsten Paul <Torsten.Paul@gmx.de> wrote: > On 10/10/2016 11:15 PM, otto wrote: > > Either implementation is possible and if enough people > > request one over the other, I am willing to implement > > either. The first is much simpler to add for me with > > my current shallow knowledge of how the code works and > > really requires very small changes. > > > Did you see the work Doug did? > > https://github.com/doug-moen/openscad2 > > It's proposing a way to a more powerful language while still > trying to be as compatible as possible. > > It would be ideal if we could get the feature aligned with > those efforts. I think it would be a nice thing to get for > current OpenSCAD already. > > ciao, > Torsten. > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
O
otto
Mon, Oct 10, 2016 9:57 PM

That is very similar to what I have implemented and what I am
proposing.  I am not familiar with AngelScript.  It looks like in
AngelScript you declare that the argument "func" takes a function.  The
C/C++ like syntax of AngelScript doesn't really (IMHO) fit well with the
untyped and functional nature of OpenScad, but it is interesting to see
another language using @ as an indirection indicator, although it
appears (in AngelScript) in the argument list as a declaration of type
instead of in the body as a declaration of indirection at call time.

Is it possible for AngelScript to implement a function anonymously?
It doesn't look like it from the posted code.

Regards
Otto

On Mon, 10 Oct 2016 23:23:53 +0200
Carsten Arnholm arnholm@arnholm.org wrote:

On 10. okt. 2016 19:13, otto wrote:

On Mon, 10 Oct 2016 10:44:13 +0100
nop head nop.head@gmail.com wrote:

So @xsq becomes both a name mangled function and a variable holding
its name? That seems like a bit of a kludge to me.

Well its like this, you can pass a function with the name of the
function in quotes.

function div3(x)=x/3;
vec = [1,2,3];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("div3",vec));

And it works:

Compiling design (CSG Tree generation)...
ECHO: [0.333333, 0.666667, 1]

Sometimes I wonder why OpenSCAD reinvents standard language features
of existing languages... below are some thoughts intended as
inspiration. Your example code is applied to AngelScript, a language
I use for 3d modelling:

funcdef double FUNC(double x);
double div3(double x) { return x/3; }
void map(FUNC @func, double[] @vec)
{ for(uint i=0; i<vec.size(); i++) { vec[i]=func(vec[i]); }  }

void main()
{
double[] vec = { 1,2,3 };
map(div3,vec);
for(uint i=0; i<vec.size(); i++) print(vec[i]+' ');
}

output is the expected:
0.333333 0.666667 1

First, a function signature 'FUNC' is defined, i.e. one taking and
returning a double. Second, an actual function 'div3' with a
signature compatible with FUNC is defined. Third, the 'map' function
where the 'func' parameter is passed 'by handle' using @ resembles
your code (alternate syntax "FUNC@ func" also ok). The array 'vec'
also passed 'by handle' so the caller sees the modified 'vec' after
calling 'map'

If I had tried to call map using another function, e.g.
double divn(double x, int n) { return x/n; }
it would generate an error because 'divn' is incompatible with the
FUNC signature. It is not clear from your example what happens if you
did a similar mistake.

Just take this comment as food for thought & inspiration.

Regards
Carsten Arnholm


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

That is very similar to what I have implemented and what I am proposing. I am not familiar with AngelScript. It looks like in AngelScript you declare that the argument "func" takes a function. The C/C++ like syntax of AngelScript doesn't really (IMHO) fit well with the untyped and functional nature of OpenScad, but it is interesting to see another language using @ as an indirection indicator, although it appears (in AngelScript) in the argument list as a declaration of type instead of in the body as a declaration of indirection at call time. Is it possible for AngelScript to implement a function anonymously? It doesn't look like it from the posted code. Regards Otto On Mon, 10 Oct 2016 23:23:53 +0200 Carsten Arnholm <arnholm@arnholm.org> wrote: > On 10. okt. 2016 19:13, otto wrote: > > On Mon, 10 Oct 2016 10:44:13 +0100 > > nop head <nop.head@gmail.com> wrote: > > > >> So @xsq becomes both a name mangled function and a variable holding > >> its name? That seems like a bit of a kludge to me. > > > > Well its like this, you can pass a function with the name of the > > function in quotes. > > > > function div3(x)=x/3; > > vec = [1,2,3]; > > > > function map(func,vec) = [for (i=vec) @func(i)]; > > echo(map("div3",vec)); > > > > And it works: > > > > Compiling design (CSG Tree generation)... > > ECHO: [0.333333, 0.666667, 1] > > > Sometimes I wonder why OpenSCAD reinvents standard language features > of existing languages... below are some thoughts intended as > inspiration. Your example code is applied to AngelScript, a language > I use for 3d modelling: > > funcdef double FUNC(double x); > double div3(double x) { return x/3; } > void map(FUNC @func, double[] @vec) > { for(uint i=0; i<vec.size(); i++) { vec[i]=func(vec[i]); } } > > void main() > { > double[] vec = { 1,2,3 }; > map(div3,vec); > for(uint i=0; i<vec.size(); i++) print(vec[i]+' '); > } > > > output is the expected: > 0.333333 0.666667 1 > > First, a function signature 'FUNC' is defined, i.e. one taking and > returning a double. Second, an actual function 'div3' with a > signature compatible with FUNC is defined. Third, the 'map' function > where the 'func' parameter is passed 'by handle' using @ resembles > your code (alternate syntax "FUNC@ func" also ok). The array 'vec' > also passed 'by handle' so the caller sees the modified 'vec' after > calling 'map' > > If I had tried to call map using another function, e.g. > double divn(double x, int n) { return x/n; } > it would generate an error because 'divn' is incompatible with the > FUNC signature. It is not clear from your example what happens if you > did a similar mistake. > > Just take this comment as food for thought & inspiration. > > Regards > Carsten Arnholm > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
TP
Torsten Paul
Mon, Oct 10, 2016 10:36 PM

On 10/10/2016 11:46 PM, otto wrote:

Thanks for reference.  I am new here, found openscad
as an ideal platform for what I wanted to do.  Found
some limits and decided to hack the code.  I am concerned
that I may be duplicating others work. I will read
these documents.

Awesome, that's exactly how I got involved, I really
missed an easy way to add text to a model :-).

I am trying to make the code more powerful and maintain
compatibility. This was intended to meet my own personal
needs but I see it as a possibility for the whole community.

There are very likely a number of things from the OpenSCAD2
proposal (and also other ideas) that could be added to the
current state without too much issues. But please don't be
discouraged if it takes some time as language changes are
always a bit tricky. Once something is out, it's very hard
to change.

ciao,
Torsten.

On 10/10/2016 11:46 PM, otto wrote: > Thanks for reference. I am new here, found openscad > as an ideal platform for what I wanted to do. Found > some limits and decided to hack the code. I am concerned > that I may be duplicating others work. I will read > these documents. > Awesome, that's exactly how I got involved, I really missed an easy way to add text to a model :-). > I am trying to make the code more powerful and maintain > compatibility. This was intended to meet my own personal > needs but I see it as a possibility for the whole community. > There are very likely a number of things from the OpenSCAD2 proposal (and also other ideas) that could be added to the current state without too much issues. But please don't be discouraged if it takes some time as language changes are always a bit tricky. Once something is out, it's very hard to change. ciao, Torsten.
A
arnholm (at) arnholm.org
Tue, Oct 11, 2016 8:20 AM

On 2016-10-10 23:57, otto wrote:

That is very similar to what I have implemented and what I am
proposing.  I am not familiar with AngelScript.  It looks like in
AngelScript you declare that the argument "func" takes a function.

Yes, funcdef declares a pointer to function type. If FUNC is defined by
'funcdef', you can declare a variable of type FUNC as a pointer to
function, and assign it:  FUNC@ some_func = div3;

The
C/C++ like syntax of AngelScript doesn't really (IMHO) fit well with
the
untyped and functional nature of OpenScad,

That may be true, but as you say these things are a matter of opinion.
The strong typing in AngelScript is in my opinion an advantage (there
are other advantages as well).

but it is interesting to see
another language using @ as an indirection indicator, although it
appears (in AngelScript) in the argument list as a declaration of type
instead of in the body as a declaration of indirection at call time.

True. I guess in untyped languages that's the only option you have.

Is it possible for AngelScript to implement a function anonymously?
It doesn't look like it from the posted code.

Yes, indeed it is possible. See quick example at
http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_anonfunc.html

Regards
Carsten Arnholm

On 2016-10-10 23:57, otto wrote: > That is very similar to what I have implemented and what I am > proposing. I am not familiar with AngelScript. It looks like in > AngelScript you declare that the argument "func" takes a function. Yes, funcdef declares a pointer to function type. If FUNC is defined by 'funcdef', you can declare a variable of type FUNC as a pointer to function, and assign it: FUNC@ some_func = div3; > The > C/C++ like syntax of AngelScript doesn't really (IMHO) fit well with > the > untyped and functional nature of OpenScad, That may be true, but as you say these things are a matter of opinion. The strong typing in AngelScript is in my opinion an advantage (there are other advantages as well). > but it is interesting to see > another language using @ as an indirection indicator, although it > appears (in AngelScript) in the argument list as a declaration of type > instead of in the body as a declaration of indirection at call time. True. I guess in untyped languages that's the only option you have. > Is it possible for AngelScript to implement a function anonymously? > It doesn't look like it from the posted code. Yes, indeed it is possible. See quick example at http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_anonfunc.html Regards Carsten Arnholm
DM
doug moen
Thu, Oct 13, 2016 5:27 PM

I've been doing some prototyping work, and after some experiments, my
favourite syntax for anonymous functions is
(x, y) -> x + y

This syntax is naturally nestable, so it's easy to write a "curried"
function like this:
x -> y -> x + y
[In my prototype, the parentheses around a parameter list are optional if
the entire parameter list consists of just a single identifier.]

Otto's "map" example would be written
map(x->x/3, [1,2,3])

On 10 October 2016 at 13:13, otto otto@123phase.com wrote:

On Mon, 10 Oct 2016 10:44:13 +0100
nop head nop.head@gmail.com wrote:

So @xsq becomes both a name mangled function and a variable holding
its name? That seems like a bit of a kludge to me.

Well its like this, you can pass a function with the name of the
function in quotes.

function div3(x)=x/3;
vec = [1,2,3];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("div3",vec));

And it works:

Compiling design (CSG Tree generation)...
ECHO: [0.333333, 0.666667, 1]

Using the construct funcion @xyz .., gives you a way to create a
function and have the compiler generate a name for the function and put
it in a variable for you. "@" used in other contexts is simply a
dereferencing operator.  It does require that the name following the
"@" is a variable name known by the compiler and not an expression
returning a string.  "@concat("d","iv3")" will not work.

A syntax that would work nicely (but requires more hacking on my part)
would be to create true anonymous functions with syntax such as follows.

Abandon the "function @...",
shorten it to "@(<argument list>,<function,def>)"
Which returns the created name of the function.  This would allow for
a more anonymous lambda like usage.

Map could then be invoked, map(@(x,x/3),[1,2,3]), which is more compact
and would get the right behavior.

Thanks for the questions and idea.  You are helping me think it
through.  Please try current code.  I think I will try to program
this capability next week. I am going on a trip this week.

BTW what is best way to pass on this code in github.

Regards
Otto

Defining functions normally and passing them with @name would allow
the compiler to check it was a valid function name without having to
have specially decorated functions. They could be passed as string
equal to their name and then calling @func() could work with any
string that equals a function name. Seems less kludgey to me. You
only have one type of function rather than ones that have to be
called normally and ones that need to be called with @.

On 10 October 2016 at 10:19, otto otto@123phase.com wrote:

On Mon, 10 Oct 2016 10:06:50 +0100
nop head nop.head@gmail.com wrote:

The goal was to get what I wanted easily.  The changes are small and
the code seems quite stable.

In declaring a function with the @ decoration.

As in function @xsq(x) = x*x
xsq is an ID token and the variable xsq is given a unique function
name as its contents.  The name is a digit followed by a period.
You can see it by echoing xsq.

You can then pass xsq around and then dereference it with @.
Because we use openscads well designed and consistent
parsing/compiling environment to do all the work, this is fast.  As
designed I hadn't really anticipated the side effect that any
function can be passed as its token name, and dereferenced later.
The great thing about this is that the compiler resolves functions
by there string name and all I needed to do was detect the
decorator in the parser and then do one level of indirection.  The
nice thing is it is safe, it doesn't break other code and it
requires only small changes to the source code and it works now.
Please test the code in the repository if you are inclined or have
the time.

Regards
Otto

You don't seem to use the @ sign in the places I would expect. I
don't see a need for them in the function definition as any
function should be passable as an argument. I would expect them
to be needed where a function is called from a string, so:

function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map("xsq",vec1));
echo(map"("xsq",vec2));
echo(map("recip",vec1));
echo(map("recip",vec2));

The @ sign could also be used to make a function literal instead
of passing string but that is a bigger change to the language.
Simply adding @ to take a string and look up function seems like
a simple mod. Creating a new variable type that is a function
would have much bigger implications because it could be used in
any expression. Keeping the name as a string allows all sorts of
tricks by concatenating suffixes, etc.

On 10 October 2016 at 09:53, otto otto@123phase.com wrote:

I have hacked the openscad source code to support function
indirection.

Here is a sample of how it works.  Function is decorated with
the "@" character when it is created and when it is used, but
not when it is passed to another function.

//Preferred usage//
function @xsq(x) = x*x;
function @recip(x)=1/x;
vec1=[1,2,3];
vec2=[.1,.7];

function map(func,vec) = [for (i=vec) @func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = "div3";
echo(map(indirect,vec2));

Output is:

ECHO: [1, 4, 9]
ECHO: [0.01, 0.49]
ECHO: [1, 0.5, 0.333333]
ECHO: [10, 1.42857]
ECHO: [0.0333333, 0.233333]

Everything is contained in the github repositor:
https://github.com/ottojas/openscad-affine

There is a pdf file there with some sample 3D and 2D output.  In
order to get this capability you need to add about 30 lines of
code in changes to five files in the source directory.  These
are relatively stable files and you may get away with simply
copying them from the ojasSources directory.

This is very much a work in progress.  Comments, questions,
flames, laughter, mockery etc. all welcome.  If anyone tests
this please let me know what your experience is.  Everything is
gnu public license as is the source code for openscad.

Regards
Otto


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_

lists.openscad.org

I've been doing some prototyping work, and after some experiments, my favourite syntax for anonymous functions is (x, y) -> x + y This syntax is naturally nestable, so it's easy to write a "curried" function like this: x -> y -> x + y [In my prototype, the parentheses around a parameter list are optional if the entire parameter list consists of just a single identifier.] Otto's "map" example would be written map(x->x/3, [1,2,3]) On 10 October 2016 at 13:13, otto <otto@123phase.com> wrote: > On Mon, 10 Oct 2016 10:44:13 +0100 > nop head <nop.head@gmail.com> wrote: > > > So @xsq becomes both a name mangled function and a variable holding > > its name? That seems like a bit of a kludge to me. > > Well its like this, you can pass a function with the name of the > function in quotes. > > function div3(x)=x/3; > vec = [1,2,3]; > > function map(func,vec) = [for (i=vec) @func(i)]; > echo(map("div3",vec)); > > And it works: > > Compiling design (CSG Tree generation)... > ECHO: [0.333333, 0.666667, 1] > > Using the construct funcion @xyz .., gives you a way to create a > function and have the compiler generate a name for the function and put > it in a variable for you. "@" used in other contexts is simply a > dereferencing operator. It does require that the name following the > "@" is a variable name known by the compiler and not an expression > returning a string. "@concat("d","iv3")" will not work. > > A syntax that would work nicely (but requires more hacking on my part) > would be to create true anonymous functions with syntax such as follows. > > Abandon the "function @...", > shorten it to "@(<argument list>,<function,def>)" > Which returns the created name of the function. This would allow for > a more anonymous lambda like usage. > > Map could then be invoked, map(@(x,x/3),[1,2,3]), which is more compact > and would get the right behavior. > > Thanks for the questions and idea. You are helping me think it > through. Please try current code. I think I will try to program > this capability next week. I am going on a trip this week. > > BTW what is best way to pass on this code in github. > > Regards > Otto > > > > > > > > > > Defining functions normally and passing them with @name would allow > > the compiler to check it was a valid function name without having to > > have specially decorated functions. They could be passed as string > > equal to their name and then calling @func() could work with any > > string that equals a function name. Seems less kludgey to me. You > > only have one type of function rather than ones that have to be > > called normally and ones that need to be called with @. > > > > On 10 October 2016 at 10:19, otto <otto@123phase.com> wrote: > > > > > On Mon, 10 Oct 2016 10:06:50 +0100 > > > nop head <nop.head@gmail.com> wrote: > > > > > > The goal was to get what I wanted easily. The changes are small and > > > the code seems quite stable. > > > > > > In declaring a function with the @ decoration. > > > > > > As in function @xsq(x) = x*x > > > xsq is an ID token and the variable xsq is given a unique function > > > name as its contents. The name is a digit followed by a period. > > > You can see it by echoing xsq. > > > > > > You can then pass xsq around and then dereference it with @. > > > Because we use openscads well designed and consistent > > > parsing/compiling environment to do all the work, this is fast. As > > > designed I hadn't really anticipated the side effect that any > > > function can be passed as its token name, and dereferenced later. > > > The great thing about this is that the compiler resolves functions > > > by there string name and all I needed to do was detect the > > > decorator in the parser and then do one level of indirection. The > > > nice thing is it is safe, it doesn't break other code and it > > > requires only small changes to the source code and it works now. > > > Please test the code in the repository if you are inclined or have > > > the time. > > > > > > > > > Regards > > > Otto > > > > > > > > > > You don't seem to use the @ sign in the places I would expect. I > > > > don't see a need for them in the function definition as any > > > > function should be passable as an argument. I would expect them > > > > to be needed where a function is called from a string, so: > > > > > > > > function xsq(x) = x*x; > > > > function recip(x)=1/x; > > > > vec1=[1,2,3]; > > > > vec2=[.1,.7]; > > > > > > > > function map(func,vec) = [for (i=vec) @func(i)]; > > > > echo(map("xsq",vec1)); > > > > echo(map"("xsq",vec2)); > > > > echo(map("recip",vec1)); > > > > echo(map("recip",vec2)); > > > > > > > > The @ sign could also be used to make a function literal instead > > > > of passing string but that is a bigger change to the language. > > > > Simply adding @ to take a string and look up function seems like > > > > a simple mod. Creating a new variable type that is a function > > > > would have much bigger implications because it could be used in > > > > any expression. Keeping the name as a string allows all sorts of > > > > tricks by concatenating suffixes, etc. > > > > > > > > > > > > > > > > On 10 October 2016 at 09:53, otto <otto@123phase.com> wrote: > > > > > > > > > I have hacked the openscad source code to support function > > > > > indirection. > > > > > > > > > > Here is a sample of how it works. Function is decorated with > > > > > the "@" character when it is created and when it is used, but > > > > > not when it is passed to another function. > > > > > > > > > > //Preferred usage// > > > > > function @xsq(x) = x*x; > > > > > function @recip(x)=1/x; > > > > > vec1=[1,2,3]; > > > > > vec2=[.1,.7]; > > > > > > > > > > function map(func,vec) = [for (i=vec) @func(i)]; > > > > > echo(map(xsq,vec1)); > > > > > echo(map(xsq,vec2)); > > > > > echo(map(recip,vec1)); > > > > > echo(map(recip,vec2)); > > > > > > > > > > //Other crazy usage// > > > > > function div3(x)=x/3; > > > > > indirect = "div3"; > > > > > echo(map(indirect,vec2)); > > > > > > > > > > Output is: > > > > > > > > > > ECHO: [1, 4, 9] > > > > > ECHO: [0.01, 0.49] > > > > > ECHO: [1, 0.5, 0.333333] > > > > > ECHO: [10, 1.42857] > > > > > ECHO: [0.0333333, 0.233333] > > > > > > > > > > > > > > > Everything is contained in the github repositor: > > > > > https://github.com/ottojas/openscad-affine > > > > > > > > > > There is a pdf file there with some sample 3D and 2D output. In > > > > > order to get this capability you need to add about 30 lines of > > > > > code in changes to five files in the source directory. These > > > > > are relatively stable files and you may get away with simply > > > > > copying them from the ojasSources directory. > > > > > > > > > > This is very much a work in progress. Comments, questions, > > > > > flames, laughter, mockery etc. all welcome. If anyone tests > > > > > this please let me know what your experience is. Everything is > > > > > gnu public license as is the source code for openscad. > > > > > > > > > > Regards > > > > > Otto > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > OpenSCAD mailing list > > > > > Discuss@lists.openscad.org > > > > > http://lists.openscad.org/mailman/listinfo/discuss_ > lists.openscad.org > > > > > > > > > > > > > > _______________________________________________ > > > OpenSCAD mailing list > > > Discuss@lists.openscad.org > > > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > >
DM
doug moen
Fri, Oct 14, 2016 1:46 PM

Bananapeel wrote:

IMO, there's just one "proper" syntax for this. And that is, that the name
without () acts as a variable, and () means call. And function becomes just
another type, like string and int. This means functions and variables must
occupy the same namespace. This syntax can also work for modules, however,
this means variables, functions and modules all share the same namespace,
which currently isn't the case.

I agree with this.

If we implement function values without uniting the namespaces, we have to
use ugly, nonstandard syntax for things like: calling a function stored in
a variable, or passing a named function as an argument. This leads to
complicated rules and ugly syntax, worse than function calls in any modern
programming language. And that's not in the spirit of OpenSCAD, which aims
to be simpler than a general purpose programming language.

Thought experiment: what happens if we change OpenSCAD to use 1 namespace
in the next release? Answer: we'd break some existing code, and that
happens in two ways:

  1. If you define a function and a variable with the same name X, in the
    same scope, then the code no longer works. We should report an error
    (duplicate definition of X).
  2. Currently, a variable defined in an inner scope cannot  shadow a
    variable defined in an outer scope, and vice versa. Once we unify the
    namespaces, the scoping rules change, and this sort of shadowing will
    occur. And this could be a silent error?

So maybe we should make this change in two phases, first deprecating the 3
namespaces, then uniting them in a subsequent release?

  1. In release N, we'll deprecate the 3 namespaces. You'll get a warning
    for duplicate definitions in the same scope, and a warning for objects with
    different kinds but the same name shadowing each other in nested scopes.
  2. In release N+1, these warnings turn into errors. We won't silently
    change the meaning of old code: instead, we'll detect the old incompatible
    code, report an error and force you to fix it. In this release, we can also
    make functions into first class values, and introduce a syntax for
    anonymous functions. Although the namespaces are now unified, modules won't
    necessarily be first class values (that's harder to do, and I won't discuss
    the details here).

Even with the deprecation release, this is a disruptive change that breaks
existing code. It's more work, but we could mitigate the problem by
providing an upgrade tool that automatically renames objects to avoid
conflicts. (For example, the tool could append a V, F or M to the names of
variables, functions and modules that conflict with one another.) If the
upgrade tool is painless enough to use, maybe we don't need the deprecation
phase?

This is the simplest path I can think of that leads to function values with
a unified namespace. The backwards compatibility scheme I described in the
OpenSCAD2 proposal is much harder to implement.

Doug Moen.

On 10 October 2016 at 15:15, Bananapeel lunatica.xiaoyu@gmail.com wrote:

I don't know why this thread is inside the thread "Convert from object to
polygon/polyhedron." Anyways, regarding passing functions as arguments:

IMO, there's just one "proper" syntax for this. And that is, that the name
without () acts as a variable, and () means call. And function becomes just
another type, like string and int. This means functions and variables must
occupy the same namespace. This syntax can also work for modules, however,
this means variables, functions and modules all share the same namespace,
which currently isn't the case.

Using () on a variable that isn't of type function or module would give a
runtime error.

Example:

//Preferred usage//
function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1, 2, 3];
vec2=[0.1, 0.7];

function map(func,vec) = [for (i=vec) func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = div3;
echo(map(indirect,vec2));

--
View this message in context: http://forum.openscad.org/
Convert-from-object-to-polygon-polyhedron-tp18522p18659.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Bananapeel wrote: > IMO, there's just one "proper" syntax for this. And that is, that the name > without () acts as a variable, and () means call. And function becomes just > another type, like string and int. This means functions and variables must > occupy the same namespace. This syntax can also work for modules, however, > this means variables, functions and modules all share the same namespace, > which currently isn't the case. > I agree with this. If we implement function values without uniting the namespaces, we have to use ugly, nonstandard syntax for things like: calling a function stored in a variable, or passing a named function as an argument. This leads to complicated rules and ugly syntax, worse than function calls in any modern programming language. And that's not in the spirit of OpenSCAD, which aims to be simpler than a general purpose programming language. Thought experiment: what happens if we change OpenSCAD to use 1 namespace in the next release? Answer: we'd break some existing code, and that happens in two ways: 1. If you define a function and a variable with the same name X, in the same scope, then the code no longer works. We should report an error (duplicate definition of X). 2. Currently, a variable defined in an inner scope cannot shadow a variable defined in an outer scope, and vice versa. Once we unify the namespaces, the scoping rules change, and this sort of shadowing will occur. And this could be a silent error? So maybe we should make this change in two phases, first deprecating the 3 namespaces, then uniting them in a subsequent release? 1. In release N, we'll deprecate the 3 namespaces. You'll get a warning for duplicate definitions in the same scope, and a warning for objects with different kinds but the same name shadowing each other in nested scopes. 2. In release N+1, these warnings turn into errors. We won't silently change the meaning of old code: instead, we'll detect the old incompatible code, report an error and force you to fix it. In this release, we can also make functions into first class values, and introduce a syntax for anonymous functions. Although the namespaces are now unified, modules won't necessarily be first class values (that's harder to do, and I won't discuss the details here). Even with the deprecation release, this is a disruptive change that breaks existing code. It's more work, but we could mitigate the problem by providing an upgrade tool that automatically renames objects to avoid conflicts. (For example, the tool could append a V, F or M to the names of variables, functions and modules that conflict with one another.) If the upgrade tool is painless enough to use, maybe we don't need the deprecation phase? This is the simplest path I can think of that leads to function values with a unified namespace. The backwards compatibility scheme I described in the OpenSCAD2 proposal is much harder to implement. Doug Moen. On 10 October 2016 at 15:15, Bananapeel <lunatica.xiaoyu@gmail.com> wrote: > I don't know why this thread is inside the thread "Convert from object to > polygon/polyhedron." Anyways, regarding passing functions as arguments: > > IMO, there's just one "proper" syntax for this. And that is, that the name > without () acts as a variable, and () means call. And function becomes just > another type, like string and int. This means functions and variables must > occupy the same namespace. This syntax can also work for modules, however, > this means variables, functions and modules all share the same namespace, > which currently isn't the case. > > Using () on a variable that isn't of type function or module would give a > runtime error. > > Example: > > //Preferred usage// > function xsq(x) = x*x; > function recip(x)=1/x; > vec1=[1, 2, 3]; > vec2=[0.1, 0.7]; > > function map(func,vec) = [for (i=vec) func(i)]; > echo(map(xsq,vec1)); > echo(map(xsq,vec2)); > echo(map(recip,vec1)); > echo(map(recip,vec2)); > > //Other crazy usage// > function div3(x)=x/3; > indirect = div3; > echo(map(indirect,vec2)); > > > > > -- > View this message in context: http://forum.openscad.org/ > Convert-from-object-to-polygon-polyhedron-tp18522p18659.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > >
MS
Mark Schafer
Fri, Oct 14, 2016 10:07 PM

Does this mean we will have to use unique names for everything ?

On 10/15/2016 2:46 AM, doug moen wrote:

Bananapeel wrote:

IMO, there's just one "proper" syntax for this. And that is, that the name
without () acts as a variable, and () means call. And function becomes just
another type, like string and int. This means functions and variables must
occupy the same namespace. This syntax can also work for modules, however,
this means variables, functions and modules all share the same namespace,
which currently isn't the case.

I agree with this.

If we implement function values without uniting the namespaces, we have to use ugly, nonstandard syntax for things like: calling a function stored in a variable, or passing a named function as an argument. This leads to complicated rules and ugly syntax, worse than function calls in any modern programming language. And that's not in the spirit of OpenSCAD, which aims to be simpler than a general purpose programming language.

Thought experiment: what happens if we change OpenSCAD to use 1 namespace in the next release? Answer: we'd break some existing code, and that happens in two ways:

  1. If you define a function and a variable with the same name X, in the same scope, then the code no longer works. We should report an error (duplicate definition of X).
  2. Currently, a variable defined in an inner scope cannot shadow a variable defined in an outer scope, and vice versa. Once we unify the namespaces, the scoping rules change, and this sort of shadowing will occur. And this could be a silent error?

So maybe we should make this change in two phases, first deprecating the 3 namespaces, then uniting them in a subsequent release?

  1. In release N, we'll deprecate the 3 namespaces. You'll get a warning for duplicate definitions in the same scope, and a warning for objects with different kinds but the same name shadowing each other in nested scopes.
  2. In release N+1, these warnings turn into errors. We won't silently change the meaning of old code: instead, we'll detect the old incompatible code, report an error and force you to fix it. In this release, we can also make functions into first class values, and introduce a syntax for anonymous functions. Although the namespaces are now unified, modules won't necessarily be first class values (that's harder to do, and I won't discuss the details here).

Even with the deprecation release, this is a disruptive change that breaks existing code. It's more work, but we could mitigate the problem by providing an upgrade tool that automatically renames objects to avoid conflicts. (For example, the tool could append a V, F or M to the names of variables, functions and modules that conflict with one another.) If the upgrade tool is painless enough to use, maybe we don't need the deprecation phase?

This is the simplest path I can think of that leads to function values with a unified namespace. The backwards compatibility scheme I described in the OpenSCAD2 proposal is much harder to implement.

Doug Moen.

On 10 October 2016 at 15:15, Bananapeel <lunatica.xiaoyu@gmail.com> wrote:

I don't know why this thread is inside the thread "Convert from object to
polygon/polyhedron." Anyways, regarding passing functions as arguments:

IMO, there's just one "proper" syntax for this. And that is, that the name
without () acts as a variable, and () means call. And function becomes just
another type, like string and int. This means functions and variables must
occupy the same namespace. This syntax can also work for modules, however,
this means variables, functions and modules all share the same namespace,
which currently isn't the case.

Using () on a variable that isn't of type function or module would give a
runtime error.

Example:

//Preferred usage//
function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1, 2, 3];
vec2=[0.1, 0.7];

function map(func,vec) = [for (i=vec) func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = div3;
echo(map(indirect,vec2));

--
View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18659.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Discuss@lists.openscad.org">Discuss@lists.openscad.org</a>
<a class="moz-txt-link-freetext" href="http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org">http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org</a>

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4664/13206 - Release Date: 10/13/16

NH
nop head
Fri, Oct 14, 2016 10:21 PM

Breaks all my code as I use lots of single names for both a variable, a
function that exports it and module that it relates to. I find it handy not
to make up three names for one subject. It is obvious which one is
referenced from the context.

If there is a breaking change to OpenScad I will stick with the version I
have now forever as it does everything I need. Same as Python 2, never used
3 as I need to change all my print statements to functions. Please make
such big changes in OpenScad2.

On 14 October 2016 at 23:07, Mark Schafer mschafer@wireframe.biz wrote:

Does this mean we will have to use unique names for everything ?

On 10/15/2016 2:46 AM, doug moen wrote:

Bananapeel wrote:

IMO, there's just one "proper" syntax for this. And that is, that the name
without () acts as a variable, and () means call. And function becomes
just
another type, like string and int. This means functions and variables must
occupy the same namespace. This syntax can also work for modules, however,
this means variables, functions and modules all share the same namespace,
which currently isn't the case.

I agree with this.

If we implement function values without uniting the namespaces, we have to
use ugly, nonstandard syntax for things like: calling a function stored in
a variable, or passing a named function as an argument. This leads to
complicated rules and ugly syntax, worse than function calls in any modern
programming language. And that's not in the spirit of OpenSCAD, which aims
to be simpler than a general purpose programming language.

Thought experiment: what happens if we change OpenSCAD to use 1 namespace
in the next release? Answer: we'd break some existing code, and that
happens in two ways:

1. If you define a function and a variable with the same name X, in
the same scope, then the code no longer works. We should report an error
(duplicate definition of X).
2. Currently, a variable defined in an inner scope cannot  shadow a
variable defined in an outer scope, and vice versa. Once we unify the
namespaces, the scoping rules change, and this sort of shadowing will
occur. And this could be a silent error?

So maybe we should make this change in two phases, first deprecating the 3
namespaces, then uniting them in a subsequent release?

1. In release N, we'll deprecate the 3 namespaces. You'll get a
warning for duplicate definitions in the same scope, and a warning for
objects with different kinds but the same name shadowing each other in
nested scopes.
2. In release N+1, these warnings turn into errors. We won't silently
change the meaning of old code: instead, we'll detect the old incompatible
code, report an error and force you to fix it. In this release, we can also
make functions into first class values, and introduce a syntax for
anonymous functions. Although the namespaces are now unified, modules won't
necessarily be first class values (that's harder to do, and I won't discuss
the details here).

Even with the deprecation release, this is a disruptive change that breaks
existing code. It's more work, but we could mitigate the problem by
providing an upgrade tool that automatically renames objects to avoid
conflicts. (For example, the tool could append a V, F or M to the names of
variables, functions and modules that conflict with one another.) If the
upgrade tool is painless enough to use, maybe we don't need the deprecation
phase?

This is the simplest path I can think of that leads to function values
with a unified namespace. The backwards compatibility scheme I described in
the OpenSCAD2 proposal is much harder to implement.

Doug Moen.

On 10 October 2016 at 15:15, Bananapeel lunatica.xiaoyu@gmail.com wrote:

I don't know why this thread is inside the thread "Convert from object to
polygon/polyhedron." Anyways, regarding passing functions as arguments:

IMO, there's just one "proper" syntax for this. And that is, that the name
without () acts as a variable, and () means call. And function becomes
just
another type, like string and int. This means functions and variables must
occupy the same namespace. This syntax can also work for modules, however,
this means variables, functions and modules all share the same namespace,
which currently isn't the case.

Using () on a variable that isn't of type function or module would give a
runtime error.

Example:

//Preferred usage//
function xsq(x) = x*x;
function recip(x)=1/x;
vec1=[1, 2, 3];
vec2=[0.1, 0.7];

function map(func,vec) = [for (i=vec) func(i)];
echo(map(xsq,vec1));
echo(map(xsq,vec2));
echo(map(recip,vec1));
echo(map(recip,vec2));

//Other crazy usage//
function div3(x)=x/3;
indirect = div3;
echo(map(indirect,vec2));

--
View this message in context: http://forum.openscad.org/Conv
ert-from-object-to-polygon-polyhedron-tp18522p18659.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing listDiscuss@lists.openscad.orghttp://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7797 / Virus Database: 4664/13206 - Release Date: 10/13/16


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Breaks all my code as I use lots of single names for both a variable, a function that exports it and module that it relates to. I find it handy not to make up three names for one subject. It is obvious which one is referenced from the context. If there is a breaking change to OpenScad I will stick with the version I have now forever as it does everything I need. Same as Python 2, never used 3 as I need to change all my print statements to functions. Please make such big changes in OpenScad2. On 14 October 2016 at 23:07, Mark Schafer <mschafer@wireframe.biz> wrote: > Does this mean we will have to use unique names for everything ? > > On 10/15/2016 2:46 AM, doug moen wrote: > > Bananapeel wrote: > >> IMO, there's just one "proper" syntax for this. And that is, that the name >> without () acts as a variable, and () means call. And function becomes >> just >> another type, like string and int. This means functions and variables must >> occupy the same namespace. This syntax can also work for modules, however, >> this means variables, functions and modules all share the same namespace, >> which currently isn't the case. >> > > I agree with this. > > If we implement function values without uniting the namespaces, we have to > use ugly, nonstandard syntax for things like: calling a function stored in > a variable, or passing a named function as an argument. This leads to > complicated rules and ugly syntax, worse than function calls in any modern > programming language. And that's not in the spirit of OpenSCAD, which aims > to be simpler than a general purpose programming language. > > Thought experiment: what happens if we change OpenSCAD to use 1 namespace > in the next release? Answer: we'd break some existing code, and that > happens in two ways: > > 1. If you define a function and a variable with the same name X, in > the same scope, then the code no longer works. We should report an error > (duplicate definition of X). > 2. Currently, a variable defined in an inner scope cannot shadow a > variable defined in an outer scope, and vice versa. Once we unify the > namespaces, the scoping rules change, and this sort of shadowing will > occur. And this could be a silent error? > > So maybe we should make this change in two phases, first deprecating the 3 > namespaces, then uniting them in a subsequent release? > > 1. In release N, we'll deprecate the 3 namespaces. You'll get a > warning for duplicate definitions in the same scope, and a warning for > objects with different kinds but the same name shadowing each other in > nested scopes. > 2. In release N+1, these warnings turn into errors. We won't silently > change the meaning of old code: instead, we'll detect the old incompatible > code, report an error and force you to fix it. In this release, we can also > make functions into first class values, and introduce a syntax for > anonymous functions. Although the namespaces are now unified, modules won't > necessarily be first class values (that's harder to do, and I won't discuss > the details here). > > Even with the deprecation release, this is a disruptive change that breaks > existing code. It's more work, but we could mitigate the problem by > providing an upgrade tool that automatically renames objects to avoid > conflicts. (For example, the tool could append a V, F or M to the names of > variables, functions and modules that conflict with one another.) If the > upgrade tool is painless enough to use, maybe we don't need the deprecation > phase? > > This is the simplest path I can think of that leads to function values > with a unified namespace. The backwards compatibility scheme I described in > the OpenSCAD2 proposal is much harder to implement. > > Doug Moen. > > On 10 October 2016 at 15:15, Bananapeel <lunatica.xiaoyu@gmail.com> wrote: > >> I don't know why this thread is inside the thread "Convert from object to >> polygon/polyhedron." Anyways, regarding passing functions as arguments: >> >> IMO, there's just one "proper" syntax for this. And that is, that the name >> without () acts as a variable, and () means call. And function becomes >> just >> another type, like string and int. This means functions and variables must >> occupy the same namespace. This syntax can also work for modules, however, >> this means variables, functions and modules all share the same namespace, >> which currently isn't the case. >> >> Using () on a variable that isn't of type function or module would give a >> runtime error. >> >> Example: >> >> //Preferred usage// >> function xsq(x) = x*x; >> function recip(x)=1/x; >> vec1=[1, 2, 3]; >> vec2=[0.1, 0.7]; >> >> function map(func,vec) = [for (i=vec) func(i)]; >> echo(map(xsq,vec1)); >> echo(map(xsq,vec2)); >> echo(map(recip,vec1)); >> echo(map(recip,vec2)); >> >> //Other crazy usage// >> function div3(x)=x/3; >> indirect = div3; >> echo(map(indirect,vec2)); >> >> >> >> >> -- >> View this message in context: http://forum.openscad.org/Conv >> ert-from-object-to-polygon-polyhedron-tp18522p18659.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> > > > _______________________________________________ > OpenSCAD mailing listDiscuss@lists.openscad.orghttp://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > > No virus found in this message. > Checked by AVG - www.avg.com > Version: 2016.0.7797 / Virus Database: 4664/13206 - Release Date: 10/13/16 > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
P
Parkinbot
Fri, Oct 14, 2016 10:58 PM

nophead wrote

Breaks all my code as I use lots of single names for both a variable, a
function that exports it and module that it relates to. I find it handy
not
to make up three names for one subject. It is obvious which one is
referenced from the context.

nice: :

a = 10;
a();
module a(){
a = a;
echo(a);
echo(a());
a();
function a() = 20;

module a(){
a = a;
echo(a);
echo(a());
function a() = 20;
}
}

--
View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18714.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

nophead wrote > Breaks all my code as I use lots of single names for both a variable, a > function that exports it and module that it relates to. I find it handy > not > to make up three names for one subject. It is obvious which one is > referenced from the context. nice: : > a = 10; > a(); > module a(){ > a = a; > echo(a); > echo(a()); > a(); > function a() = 20; > > module a(){ > a = a; > echo(a); > echo(a()); > function a() = 20; > } > } -- View this message in context: http://forum.openscad.org/Convert-from-object-to-polygon-polyhedron-tp18522p18714.html Sent from the OpenSCAD mailing list archive at Nabble.com.