discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

what base language is used in OpenSCAD

K
ken@volksswitch.org
Thu, Apr 26, 2018 9:51 PM

I'd like to be able to convert a string to an integer in OpenSCAD.  For
example:

string = "11";

number = xxx(string);

echo(number);

. produces:  ECHO: 11

What is xxx()?  I have a suspicion that there are more functions available
in OpenSCAD than appear on the Cheat Sheet.  Functions that just come with
the language that OpenSCAD is built on.  Am I hallucinating or is there such
a language?

Ken

I'd like to be able to convert a string to an integer in OpenSCAD. For example: string = "11"; number = xxx(string); echo(number); . produces: ECHO: 11 What is xxx()? I have a suspicion that there are more functions available in OpenSCAD than appear on the Cheat Sheet. Functions that just come with the language that OpenSCAD is built on. Am I hallucinating or is there such a language? Ken
JB
Jordan Brown
Fri, Apr 27, 2018 12:59 AM

On 4/26/2018 2:51 PM, ken@volksswitch.org wrote:

I’d like to be able to convert a string to an integer in OpenSCAD. 
For example:

 

string = “11”;

number = xxx(string);

 

echo(number);

 

… produces:  ECHO: 11

 

What is xxx()?  I have a suspicion that there are more functions
available in OpenSCAD than appear on the Cheat Sheet.  Functions that
just come with the language that OpenSCAD is built on.  Am I
hallucinating or is there such a language?

I don't know anything about the internals, but based on what I've seen
of the externals... no, there isn't such a language; it's a completely
unique design.

And indeed some quick source inspection strongly suggests that what you
see is what you get.
https://github.com/openscad/openscad/blob/620ae8a8aa4ad6610aa3cdae8d1aedb828ed55cb/src/scadlexer.cpp#L14
https://github.com/openscad/openscad/blob/e99ec0ff4e89344da3c3709f381decc9fb95b9fd/src/func.cc#L939

On 4/26/2018 2:51 PM, ken@volksswitch.org wrote: > > I’d like to be able to convert a string to an integer in OpenSCAD.  > For example: > >   > > string = “11”; > > number = xxx(string); > >   > > echo(number); > >   > > … produces:  ECHO: 11 > >   > > What is xxx()?  I have a suspicion that there are more functions > available in OpenSCAD than appear on the Cheat Sheet.  Functions that > just come with the language that OpenSCAD is built on.  Am I > hallucinating or is there such a language? > I don't know anything about the internals, but based on what I've seen of the externals... no, there isn't such a language; it's a completely unique design. And indeed some quick source inspection strongly suggests that what you see is what you get. https://github.com/openscad/openscad/blob/620ae8a8aa4ad6610aa3cdae8d1aedb828ed55cb/src/scadlexer.cpp#L14 https://github.com/openscad/openscad/blob/e99ec0ff4e89344da3c3709f381decc9fb95b9fd/src/func.cc#L939
WF
William Ferry
Fri, Apr 27, 2018 1:38 AM

AFAIK, OpenSCAD isn't built on any other languages, it's its own unique language.  I mean it's written in C++, but the language parser is unique to OpenSCAD.

There are certainly libraries out there that include functions to do string to number conversions, for example relativity.scad (https://github.com/davidson16807/relativity.scad/blob/master, in "relativity.scad" see the "parse_int" function, it's also in the separate "strings.scad" file in the same repo).  - Will

On Apr 26, 2018, at 2:51 PM, ken@volksswitch.org wrote:

I’d like to be able to convert a string to an integer in OpenSCAD.  For example:

string = “11”;
number = xxx(string);

echo(number);

… produces:  ECHO: 11

What is xxx()?  I have a suspicion that there are more functions available in OpenSCAD than appear on the Cheat Sheet.  Functions that just come with the language that OpenSCAD is built on.  Am I hallucinating or is there such a language?

Ken


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

AFAIK, OpenSCAD isn't *built* on any other languages, it's its own unique language. I mean it's written in C++, but the language parser is unique to OpenSCAD. There are certainly libraries out there that include functions to do string to number conversions, for example relativity.scad (<https://github.com/davidson16807/relativity.scad/blob/master>, in "relativity.scad" see the "parse_int" function, it's also in the separate "strings.scad" file in the same repo). - Will > On Apr 26, 2018, at 2:51 PM, ken@volksswitch.org wrote: > > I’d like to be able to convert a string to an integer in OpenSCAD. For example: > > string = “11”; > number = xxx(string); > > echo(number); > > … produces: ECHO: 11 > > What is xxx()? I have a suspicion that there are more functions available in OpenSCAD than appear on the Cheat Sheet. Functions that just come with the language that OpenSCAD is built on. Am I hallucinating or is there such a language? > > Ken > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
M
MichaelAtOz
Fri, Apr 27, 2018 7:01 AM

khackbarth wrote

I'd like to be able to convert a string to an integer in OpenSCAD.  For
example:

string = "11";
number = xxx(string);
echo(number);

. produces:  ECHO: 11

In the production release there is no built-in for that.
There is a  WIP https://github.com/openscad/openscad/pull/1380  .

Here is a recursive function for this: hex-dec.scad
http://forum.openscad.org/file/t359/hex-dec.scad


Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

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

khackbarth wrote > I'd like to be able to convert a string to an integer in OpenSCAD. For > example: > > string = "11"; > number = xxx(string); > echo(number); > > > . produces: ECHO: 11 In the production release there is no built-in for that. There is a WIP <https://github.com/openscad/openscad/pull/1380> . Here is a recursive function for this: hex-dec.scad <http://forum.openscad.org/file/t359/hex-dec.scad> ----- Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- Sent from: http://forum.openscad.org/
T
Troberg
Fri, Apr 27, 2018 7:17 AM

As far as I can see, you can't convert string to number, not even implicitly.

Consider this small example:

a="1";
b="2";
c=a+b;
echo(c);

It will return undef.

I think you should look into customization instead.

http://www.openscad.org/news.html#20160714

It makes it very simple to make parameterized designs, I use it all the
time.

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

As far as I can see, you can't convert string to number, not even implicitly. Consider this small example: a="1"; b="2"; c=a+b; echo(c); It will return undef. I think you should look into customization instead. http://www.openscad.org/news.html#20160714 It makes it very simple to make parameterized designs, I use it all the time. -- Sent from: http://forum.openscad.org/
JB
Jordan Brown
Sat, Apr 28, 2018 12:12 AM

On 4/26/2018 2:51 PM, ken@volksswitch.org wrote:

I’d like to be able to convert a string to an integer in OpenSCAD. 
For example:

 

string = “11”;

number = xxx(string);

Here's what I come up with:

function atoi1(s, n) = n < 0 ? 0 : atoi1(s, n-1)*10 + search (s[n], "0123456789")[0];
function atoi(s) = atoi1(s, len(s)-1);
echo(atoi("123"));

It seems like it could be simplified a bit.

On 4/26/2018 2:51 PM, ken@volksswitch.org wrote: > > I’d like to be able to convert a string to an integer in OpenSCAD.  > For example: > >   > > string = “11”; > > number = xxx(string); > Here's what I come up with: function atoi1(s, n) = n < 0 ? 0 : atoi1(s, n-1)*10 + search (s[n], "0123456789")[0]; function atoi(s) = atoi1(s, len(s)-1); echo(atoi("123")); It seems like it could be simplified a bit.
K
ken@volksswitch.org
Sat, Apr 28, 2018 12:32 AM

Cool, thanks!

Ken

From: Jordan Brown [mailto:openscad@jordan.maileater.net]
Sent: Friday, April 27, 2018 6:12 PM
To: OpenSCAD general discussion; ken@volksswitch.org
Subject: Re: [OpenSCAD] what base language is used in OpenSCAD

On 4/26/2018 2:51 PM, ken@volksswitch.org wrote:

I'd like to be able to convert a string to an integer in OpenSCAD.  For
example:

string = "11";

number = xxx(string);

Here's what I come up with:

function atoi1(s, n) = n < 0 ? 0 : atoi1(s, n-1)*10 + search (s[n],
"0123456789")[0];
function atoi(s) = atoi1(s, len(s)-1);
echo(atoi("123"));

It seems like it could be simplified a bit.

Cool, thanks! Ken From: Jordan Brown [mailto:openscad@jordan.maileater.net] Sent: Friday, April 27, 2018 6:12 PM To: OpenSCAD general discussion; ken@volksswitch.org Subject: Re: [OpenSCAD] what base language is used in OpenSCAD On 4/26/2018 2:51 PM, ken@volksswitch.org wrote: I'd like to be able to convert a string to an integer in OpenSCAD. For example: string = "11"; number = xxx(string); Here's what I come up with: function atoi1(s, n) = n < 0 ? 0 : atoi1(s, n-1)*10 + search (s[n], "0123456789")[0]; function atoi(s) = atoi1(s, len(s)-1); echo(atoi("123")); It seems like it could be simplified a bit.