discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Help combining bits into an object

HL
Hans L
Sat, Feb 3, 2018 7:20 PM

Let can be used inside a list comprehension, but it can also be its
own statement.  To be clear, in the code I posted above, I am not
using list comprehensions.

Documentation for the let statement exists on the wikibooks

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Let_Statement
"[Note: Requires version 2016.XX] (ie a development version)"

Hans

On Sat, Feb 3, 2018 at 11:52 AM, George Hartzell hartzell@alerce.com wrote:

It does not work in version version 2015.03-3, which is the stable
version installed via Homebrew Cask.

It does work in the dev release that I manually downloaded,
2017.12.23 (git 39823be1).

This usage seems to be a variant of the list comprehension form, it's
documented here without any caveats about what
release it will work in, although the top of that list comprehension
section states that it (list comprehensions in general?) requires
"2015.03".

There's a comment in this thread from 2016 that states
that let is only available in the dev releases.  It also states that
"the wiki" has been fixed.

Is there a doc bug in the User Manual?

g.


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

Let *can* be used inside a list comprehension, but it can also be its own statement. To be clear, in the code I posted above, I am not using list comprehensions. Documentation for the let statement exists on the wikibooks https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Let_Statement "[Note: Requires version 2016.XX] (ie a development version)" Hans On Sat, Feb 3, 2018 at 11:52 AM, George Hartzell <hartzell@alerce.com> wrote: > > It does not work in version `version 2015.03-3`, which is the stable > version installed via Homebrew Cask. > > It does work in the dev release that I manually downloaded, > `2017.12.23 (git 39823be1)`. > > This usage seems to be a variant of the list comprehension form, it's > documented [here][list-comp-let] without any caveats about what > release it will work in, although the top of that list comprehension > section states that it (list comprehensions in general?) requires > "2015.03". > > There's a comment in [this thread][let-thread] from 2016 that states > that `let` is only available in the dev releases. It also states that > "the wiki" has been fixed. > > Is there a doc bug in the User Manual? > > g. > > [let-thread]: http://forum.openscad.org/quot-Let-quot-deprecated-td17469.html > [list-comp-let]: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/List_Comprehensions#let > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
GH
George Hartzell
Sat, Feb 3, 2018 7:56 PM

Hans L writes:

Let can be used inside a list comprehension, but it can also be its
own statement.  To be clear, in the code I posted above, I am not
using list comprehensions.

Documentation for the let statement exists on the wikibooks

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Let_Statement
"[Note: Requires version 2016.XX] (ie a development version)"
[...]

What that documents is a form like so:

for (...) {
  let(...) {
    ...
  }
}

What confused me a bit was that in the code you provided for me, the
"for block" was simple enough that it didn't require braces:

for (i = [1:$children-1]) let($negative = true) {
  children(i);
}

This seems to function equivalently:

for (i = [1:$children-1]) {
  let($negative = true) {
    children(i);
  }
}

Is that correct?  If so, then I believe I understand the subtleties.

Thank you again!

g.

Hans L writes: > Let *can* be used inside a list comprehension, but it can also be its > own statement. To be clear, in the code I posted above, I am not > using list comprehensions. > > Documentation for the let statement exists on the wikibooks > > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Let_Statement > "[Note: Requires version 2016.XX] (ie a development version)" > [...] What that documents is a form like so: ```scad for (...) { let(...) { ... } } ``` What confused me a bit was that in the code you provided for me, the "for block" was simple enough that it didn't require braces: ```scad for (i = [1:$children-1]) let($negative = true) { children(i); } ``` This seems to function equivalently: ```scad for (i = [1:$children-1]) { let($negative = true) { children(i); } } ``` Is that correct? If so, then I believe I understand the subtleties. Thank you again! g.
HL
Hans L
Sat, Feb 3, 2018 8:21 PM

Yes, precisely.  Curly braces are only required when creating a
"block" around multiple statements.

If there is only a single statement under another, then the braces are
optional.
This is similar to the syntax found in most "c-style" languages
(though I don't consider OpenSCAD to be c-style, it does share some
simliarities such as this)

You could even do the whole loop with no braces in this case, if you
wanted.  It is a matter of preference:

for (i = [1:$children-1]) let($negative = true) children(i);

On Sat, Feb 3, 2018 at 1:56 PM, George Hartzell hartzell@alerce.com wrote:

Hans L writes:

Let can be used inside a list comprehension, but it can also be its
own statement.  To be clear, in the code I posted above, I am not
using list comprehensions.

Documentation for the let statement exists on the wikibooks

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Let_Statement
"[Note: Requires version 2016.XX] (ie a development version)"
[...]

What that documents is a form like so:

for (...) {
  let(...) {
    ...
  }
}

What confused me a bit was that in the code you provided for me, the
"for block" was simple enough that it didn't require braces:

for (i = [1:$children-1]) let($negative = true) {
  children(i);
}

This seems to function equivalently:

for (i = [1:$children-1]) {
  let($negative = true) {
    children(i);
  }
}

Is that correct?  If so, then I believe I understand the subtleties.

Thank you again!

g.


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

Yes, precisely. Curly braces are only *required* when creating a "block" around *multiple* statements. If there is only a single statement under another, then the braces are optional. This is similar to the syntax found in most "c-style" languages (though I don't consider OpenSCAD to be c-style, it does share some simliarities such as this) You could even do the whole loop with no braces in this case, if you wanted. It is a matter of preference: for (i = [1:$children-1]) let($negative = true) children(i); On Sat, Feb 3, 2018 at 1:56 PM, George Hartzell <hartzell@alerce.com> wrote: > Hans L writes: > > Let *can* be used inside a list comprehension, but it can also be its > > own statement. To be clear, in the code I posted above, I am not > > using list comprehensions. > > > > Documentation for the let statement exists on the wikibooks > > > > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Let_Statement > > "[Note: Requires version 2016.XX] (ie a development version)" > > [...] > > What that documents is a form like so: > > ```scad > for (...) { > let(...) { > ... > } > } > ``` > > What confused me a bit was that in the code you provided for me, the > "for block" was simple enough that it didn't require braces: > > ```scad > for (i = [1:$children-1]) let($negative = true) { > children(i); > } > ``` > > This seems to function equivalently: > > ```scad > for (i = [1:$children-1]) { > let($negative = true) { > children(i); > } > } > ``` > > Is that correct? If so, then I believe I understand the subtleties. > > Thank you again! > > g. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org