discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Lua luau.

JB
Jordan Brown
Sat, Mar 20, 2021 10:41 PM

On 3/20/2021 3:32 PM, Torsten Paul wrote:

Most languages I'm aware of do provide both dictionaries
and objects/structs. The obvious difference is that the
dictionaries are much more limited but allow access via a
dynamically produced key where objects usually only allow
statically defined names for access (needing some kind of
runtime reflection to make it dynamic).

OpenSCAD is in a strange middle ground.

In one way, it's very dynamic.  It has no declarations and no
user-defined types.  It doesn't really have a way to say "this is what
an XXX structure looks like", outside the context of building a specific
instance of such a structure.

In another way, it's very static.  Values, once created, do not change. 
If you create a particular object/dictionary/structure with a particular
set of elements, that's exactly the set of elements and the set of
values that it will have for its entire life; you cannot add to it.

So far, it seems like those two combine to suggest that there's only one
abstraction needed - much as there's only one such abstraction in
JavaScript.

On 3/20/2021 3:32 PM, Torsten Paul wrote: > Most languages I'm aware of do provide both dictionaries > and objects/structs. The obvious difference is that the > dictionaries are much more limited but allow access via a > dynamically produced key where objects usually only allow > statically defined names for access (needing some kind of > runtime reflection to make it dynamic). OpenSCAD is in a strange middle ground. In one way, it's very dynamic.  It has no declarations and no user-defined types.  It doesn't really have a way to say "this is what an XXX structure looks like", outside the context of building a specific instance of such a structure. In another way, it's very static.  Values, once created, do not change.  If you create a particular object/dictionary/structure with a particular set of elements, that's exactly the set of elements and the set of values that it will have for its entire life; you cannot add to it. So far, it seems like those two combine to suggest that there's only one abstraction needed - much as there's only one such abstraction in JavaScript.
DM
Doug Moen
Sat, Mar 20, 2021 11:42 PM

Curv just has the one concept, which I call "records". You can use them for lots of different things. A record describes a set of named model parameters (which can be passed around as arguments to functions and modules). You can roll your own object-oriented programming by storing function values in record fields, and I use this idea a lot. OpenSCAD is a simple language; I don't think anything more complicated is needed.

So here's a design loosely based on Curv.

r = {a: 1, b: [0,0], c: "hello"} is a record value.

A field name can also be specified as a string literal, eg,
{"a": 1, "b": 2}
This is used if the field name contains special characters.

r.a or r["a"] selects field "a" and returns 1.

A record value is printed as a record literal.

That's all you need to get started.

Curv has a more sophisticated design, which I will partially describe.

{a: 1, b: 2, each r}
'each r' includes the record 'r' into the record under construction in the above example.
This has left-to-right override semantics.
If 'r' defines a field name 'a', then that overrides the earlier definition 'a: 1'.
So in this example, 'a: 1' acts as the default value of 'a' if not specified by 'r'.

In some contexts, a record behaves like a list of ["name",value] pairs.
This allows for dynamic construction and introspection of records.

  • within a record literal, 'each fieldlist' requires the list argument to contain ["name", value] pairs, which are converted to record fields.
  • within a list literal, 'each record' converts the record to a list of ["name",value] pairs.

With these extensions, here is a 'fields' function that converts a record to a list of field names.
function fields(r) = [for (f = [each r]) f[0]];
Now fields({a:1,b:2}) returns ["a","b"].

Even with the extensions, that's a fairly simple design that is quite powerful.

Doug Moen.

On Sat, Mar 20, 2021, at 6:41 PM, Jordan Brown wrote:

On 3/20/2021 3:32 PM, Torsten Paul wrote:

Most languages I'm aware of do provide both dictionaries

and objects/structs. The obvious difference is that the
dictionaries are much more limited but allow access via a
dynamically produced key where objects usually only allow
statically defined names for access (needing some kind of
runtime reflection to make it dynamic).

OpenSCAD is in a strange middle ground.

In one way, it's very dynamic.  It has no declarations and no user-defined types.  It doesn't really have a way to say "this is what an XXX structure looks like", outside the context of building a specific instance of such a structure.

In another way, it's very static.  Values, once created, do not change.  If you create a particular object/dictionary/structure with a particular set of elements, that's exactly the set of elements and the set of values that it will have for its entire life; you cannot add to it.

So far, it seems like those two combine to suggest that there's only one abstraction needed - much as there's only one such abstraction in JavaScript.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org mailto:discuss-leave%40lists.openscad.org

Curv just has the one concept, which I call "records". You can use them for lots of different things. A record describes a set of named model parameters (which can be passed around as arguments to functions and modules). You can roll your own object-oriented programming by storing function values in record fields, and I use this idea a lot. OpenSCAD is a simple language; I don't think anything more complicated is needed. So here's a design loosely based on Curv. r = {a: 1, b: [0,0], c: "hello"} is a record value. A field name can also be specified as a string literal, eg, {"a": 1, "b": 2} This is used if the field name contains special characters. r.a or r["a"] selects field "a" and returns 1. A record value is printed as a record literal. That's all you need to get started. Curv has a more sophisticated design, which I will partially describe. {a: 1, b: 2, each r} 'each r' includes the record 'r' into the record under construction in the above example. This has left-to-right override semantics. If 'r' defines a field name 'a', then that overrides the earlier definition 'a: 1'. So in this example, 'a: 1' acts as the default value of 'a' if not specified by 'r'. In some contexts, a record behaves like a list of ["name",value] pairs. This allows for dynamic construction and introspection of records. * within a record literal, 'each fieldlist' requires the list argument to contain ["name", value] pairs, which are converted to record fields. * within a list literal, 'each record' converts the record to a list of ["name",value] pairs. With these extensions, here is a 'fields' function that converts a record to a list of field names. function fields(r) = [for (f = [each r]) f[0]]; Now fields({a:1,b:2}) returns ["a","b"]. Even with the extensions, that's a fairly simple design that is quite powerful. Doug Moen. On Sat, Mar 20, 2021, at 6:41 PM, Jordan Brown wrote: > On 3/20/2021 3:32 PM, Torsten Paul wrote: >> Most languages I'm aware of do provide both dictionaries and objects/structs. The obvious difference is that the dictionaries are much more limited but allow access via a dynamically produced key where objects usually only allow statically defined names for access (needing some kind of runtime reflection to make it dynamic). >> > > OpenSCAD is in a strange middle ground. > > In one way, it's very dynamic. It has no declarations and no user-defined types. It doesn't really have a way to say "this is what an XXX structure looks like", outside the context of building a specific instance of such a structure. > > In another way, it's very static. Values, once created, do not change. If you create a particular object/dictionary/structure with a particular set of elements, that's exactly the set of elements and the set of values that it will have for its entire life; you cannot add to it. > > So far, it seems like those two combine to suggest that there's only one abstraction needed - much as there's only one such abstraction in JavaScript. > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave%40lists.openscad.org> >
N
NateTG
Sun, Mar 21, 2021 12:26 AM

I've got the impression that function literals are pretty powerful in terms
of the ability to set up things like data structures.  I would really like
some kind of syntax sugar or "function swizzling" or whatever you want to
call it so that instantiation (I think that's the right word) is a little
nicer.

For example, if

were equivalent to

I'm not sure how heavy function calls or function literals are in OpenSCAD,
but I'm a little dubious about adding language features for something that
can (at least mostly) already be done without them.

--
Sent from: http://forum.openscad.org/

I've got the impression that function literals are pretty powerful in terms of the ability to set up things like data structures. I would really like some kind of syntax sugar or "function swizzling" or whatever you want to call it so that instantiation (I think that's the right word) is a little nicer. For example, if were equivalent to I'm not sure how heavy function calls or function literals are in OpenSCAD, but I'm a little dubious about adding language features for something that can (at least mostly) already be done without them. -- Sent from: http://forum.openscad.org/
CF
Carsten Fuchs
Sun, Mar 21, 2021 7:28 AM

Am 20.03.21 um 23:41 schrieb Jordan Brown:

So far, it seems like those two combine to suggest that there's only one abstraction needed - much as there's only one such abstraction in JavaScript.

Lua too has only a single, simple and very powerful abstraction: tables, which are implemented so that they can act as lists, dicts and structs.
Please see http://www.lua.org/pil/2.5.html

Honestly, I'm a bit surprised by the vehemence to reinvent the wheel in OpenSCAD while at the same time claiming it is a waste of time to even consider alternatives. Lua is complete, very well thought out, proven and made for embedding in projects like OpenSCAD: If time is expensive, it would be way more effective to spend it with integrating Lua rather than adding features to a language that will remain hard-to-use even with a dozen more features implemented.

Best regards,
Carsten

Am 20.03.21 um 23:41 schrieb Jordan Brown: > So far, it seems like those two combine to suggest that there's only one abstraction needed - much as there's only one such abstraction in JavaScript. Lua too has only a single, simple and very powerful abstraction: tables, which are implemented so that they can act as lists, dicts and structs. Please see http://www.lua.org/pil/2.5.html Honestly, I'm a bit surprised by the vehemence to reinvent the wheel in OpenSCAD while at the same time claiming it is a waste of time to even consider alternatives. Lua is complete, very well thought out, proven and *made* for embedding in projects like OpenSCAD: If time is expensive, it would be way more effective to spend it with integrating Lua rather than adding features to a language that will remain hard-to-use even with a dozen more features implemented. Best regards, Carsten
WF
William F. Adams
Mon, Mar 22, 2021 9:18 PM

Did anyone mention/suggest/bring up:
https://github.com/thechillcode/Lua_CAD
in this discussion?
William

Did anyone mention/suggest/bring up: https://github.com/thechillcode/Lua_CAD in this discussion? William
CF
Carsten Fuchs
Tue, Mar 23, 2021 6:23 AM

Am 22.03.21 um 22:18 schrieb William F. Adams via Discuss:

Did anyone mention/suggest/bring up:

https://github.com/thechillcode/Lua_CAD

This seems to be as dead as most other related projects. I guess projects need active developers and a vivid community to thrive.

https://github.com/CadQuery/cadquery looks very interesting though! Installation is still a bit difficult, but they're working on improving that.

Best regards,
Carsten

Am 22.03.21 um 22:18 schrieb William F. Adams via Discuss: > Did anyone mention/suggest/bring up: > > https://github.com/thechillcode/Lua_CAD This seems to be as dead as most other related projects. I guess projects need active developers and a vivid community to thrive. https://github.com/CadQuery/cadquery looks very interesting though! Installation is still a bit difficult, but they're working on improving that. Best regards, Carsten
WF
William F. Adams
Tue, Mar 23, 2021 3:45 PM

Carsten Fuchs wrote:

Am 22.03.21 um 22:18 schrieb William F. Adams via Discuss:

Did anyone mention/suggest/bring up:

https://github.com/thechillcode/Lua_CAD

This seems to be as dead as most other related projects. I guess projects need active developers and a vivid community to thrive.

That's a shame, yes, a program needs users.

https://github.com/CadQuery/cadquery looks very interesting though! Installation is still a bit difficult, but they're working on improving that.

With a bit of help I managed to get that installed, and agree it's one of the most promising of alternatives.
Things I miss in using it:
 - BlockSCAD - easy solutions found w/ a 'net search
William

Carsten Fuchs wrote: Am 22.03.21 um 22:18 schrieb William F. Adams via Discuss: >> Did anyone mention/suggest/bring up: >> >> https://github.com/thechillcode/Lua_CAD >This seems to be as dead as most other related projects. I guess projects need active developers and a vivid community to thrive. That's a shame, yes, a program needs users. >https://github.com/CadQuery/cadquery looks very interesting though! Installation is still a bit difficult, but they're working on improving that. With a bit of help I managed to get that installed, and agree it's one of the most promising of alternatives. Things I miss in using it:  - BlockSCAD - easy solutions found w/ a 'net search William