discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

debug print in openscad functions

DM
doug moen
Fri, Jan 15, 2016 8:39 PM

Hi Torsten. In OpenSCAD2, because there is a single namespace (instead of
separate module/function namespaces), I need echo and echof to be separate
functions. They seem to require different interfaces, and I haven't found a
good way to unify them.

For OpenSCAD2, the syntax I designed for echof is:
echof(stuff, to, echo) result

The syntax is copied from module calls, and is convenient to use for the
same reasons.
For example,
echof("calling f(",x,")") f(x)
is syntactically similar to applying a transformation to some geometry, as
in
translate([10,0,0]) cube(10)

I just like the way that the debug output is visually separated from the
rest of the code in a function.

function sum(x, y) =
echof("sum(",x,",",y,")")
(x + y);

If you like this syntax, you'll need to add another production to the
expression grammar, which for now will only be used by echof. I can help,
since I've already got a working bison grammar for this.

On 15 January 2016 at 14:52, Torsten Paul Torsten.Paul@gmx.de wrote:

On 01/15/2016 08:40 PM, doug moen wrote:

Yes, I would like us to have echof.

Ok then, to make it easier to use, what about:

  • just call it echo() instead of echof()

  • have it declared like echo(result, ...)

    where it returns the value that is either the first positional
    argument or the argument named result (to match the argument
    behavior of module instantiations).

  • all arguments are printed as with the module echo()

  • if the function echo() is called with no argument, it will
    return undef.

ciao,
Torsten.


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

Hi Torsten. In OpenSCAD2, because there is a single namespace (instead of separate module/function namespaces), I need echo and echof to be separate functions. They seem to require different interfaces, and I haven't found a good way to unify them. For OpenSCAD2, the syntax I designed for echof is: echof(stuff, to, echo) result The syntax is copied from module calls, and is convenient to use for the same reasons. For example, echof("calling f(",x,")") f(x) is syntactically similar to applying a transformation to some geometry, as in translate([10,0,0]) cube(10) I just like the way that the debug output is visually separated from the rest of the code in a function. function sum(x, y) = echof("sum(",x,",",y,")") (x + y); If you like this syntax, you'll need to add another production to the expression grammar, which for now will only be used by echof. I can help, since I've already got a working bison grammar for this. On 15 January 2016 at 14:52, Torsten Paul <Torsten.Paul@gmx.de> wrote: > On 01/15/2016 08:40 PM, doug moen wrote: > > Yes, I would like us to have echof. > > > Ok then, to make it easier to use, what about: > > - just call it echo() instead of echof() > > - have it declared like echo(result, ...) > > where it returns the value that is either the first positional > argument or the argument named result (to match the argument > behavior of module instantiations). > > - all arguments are printed as with the module echo() > > - if the function echo() is called with no argument, it will > return undef. > > ciao, > Torsten. > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > >
TP
Torsten Paul
Fri, Jan 15, 2016 8:49 PM

On 01/15/2016 09:39 PM, doug moen wrote:

Hi Torsten. In OpenSCAD2, because there is a single namespace
(instead of separate module/function namespaces), I need echo
and echof to be separate functions. They seem to require
different interfaces, and I haven't found a good way to unify them.

Hmm, right, the result thingy would make it it harder to unify.
But we already have a case where the same name is used for both
cases: let().

So how about having it behave like let() (including the sequential
assignment) just with the additional side effect of printing the
values?

ciao,
Torsten.

On 01/15/2016 09:39 PM, doug moen wrote: > Hi Torsten. In OpenSCAD2, because there is a single namespace > (instead of separate module/function namespaces), I need echo > and echof to be separate functions. They seem to require > different interfaces, and I haven't found a good way to unify them. > Hmm, right, the result thingy would make it it harder to unify. But we already have a case where the same name is used for both cases: let(). So how about having it behave like let() (including the sequential assignment) just with the additional side effect of printing the values? ciao, Torsten.
M
MichaelAtOz
Fri, Jan 15, 2016 8:56 PM

doug.moen wrote

I just like the way that the debug output is visually separated from the
rest of the code in a function.

function sum(x, y) =
echof("sum(",x,",",y,")")
(x + y);

If you like this syntax, you'll need to add another production to the
expression grammar, which for now will only be used by echof. I can help,
since I've already got a working bison grammar for this.

Nooooooooooo. (I think)

echof() needs to be able to be placed anywhere in an expression.
Consider a complex recursion, it could be going wrong in any number of
"...?...:..."


Newly minted 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!

View this message in context: http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15715.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

doug.moen wrote > I just like the way that the debug output is visually separated from the > rest of the code in a function. > > function sum(x, y) = > echof("sum(",x,",",y,")") > (x + y); > > If you like this syntax, you'll need to add another production to the > expression grammar, which for now will only be used by echof. I can help, > since I've already got a working bison grammar for this. Nooooooooooo. (I think) echof() needs to be able to be placed anywhere in an expression. Consider a complex recursion, it could be going wrong in any number of "...?...:..." ----- Newly minted 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! -- View this message in context: http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15715.html Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Fri, Jan 15, 2016 9:05 PM

tp3 wrote

On 01/15/2016 08:40 PM, doug moen wrote:

Yes, I would like us to have echof.

Ok then, to make it easier to use, what about:

  • just call it echo() instead of echof()

  • have it declared like echo(result, ...)

    where it returns the value that is either the first positional
    argument or the argument named result (to match the argument
    behavior of module instantiations).

  • all arguments are printed as with the module echo()

  • if the function echo() is called with no argument, it will
    return undef.

How about calling the parameter 'return' as in return code.
I was about to argue for just returning zero, as originally proposed, but
I can see echof(return=[],"msg") & echof(return="","msg") being handy in
non-numeric functions.


Newly minted 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!

View this message in context: http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15716.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

tp3 wrote > On 01/15/2016 08:40 PM, doug moen wrote: >> Yes, I would like us to have echof. >> > Ok then, to make it easier to use, what about: > > - just call it echo() instead of echof() > > - have it declared like echo(result, ...) > > where it returns the value that is either the first positional > argument or the argument named result (to match the argument > behavior of module instantiations). > > - all arguments are printed as with the module echo() > > - if the function echo() is called with no argument, it will > return undef. How about calling the parameter 'return' as in return code. I was about to argue for just returning zero, as originally proposed, but I can see echof(return=[],"msg") & echof(return="","msg") being handy in non-numeric functions. ----- Newly minted 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! -- View this message in context: http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15716.html Sent from the OpenSCAD mailing list archive at Nabble.com.
DM
doug moen
Fri, Jan 15, 2016 9:07 PM

In OpenSCAD2, a call to echof is just an expression, and can therefore be
placed anywhere in an expression.

If you reduce it to the simplest case, then
echof(stuff,to,echo)(result)
is an expression with the same precedence as a function call, and can be
used in any context that a function call can be used. (There are also a
limited set of cases where the parentheses around (result) can be omitted,
but we can leave that out for now.)

Sorry to dump OpenSCAD2 syntax into this thread. My excuse is that Torsten
and Marius have previously expressed interest in integrating more of that
syntax into OpenSCAD.

On 15 January 2016 at 15:56, MichaelAtOz oz.at.michael@gmail.com wrote:

doug.moen wrote

I just like the way that the debug output is visually separated from the
rest of the code in a function.

function sum(x, y) =
echof("sum(",x,",",y,")")
(x + y);

If you like this syntax, you'll need to add another production to the
expression grammar, which for now will only be used by echof. I can help,
since I've already got a working bison grammar for this.

Nooooooooooo. (I think)

echof() needs to be able to be placed anywhere in an expression.
Consider a complex recursion, it could be going wrong in any number of
"...?...:..."


Newly minted 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!

View this message in context:
http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15715.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

In OpenSCAD2, a call to echof is just an expression, and can therefore be placed anywhere in an expression. If you reduce it to the simplest case, then echof(stuff,to,echo)(result) is an expression with the same precedence as a function call, and can be used in any context that a function call can be used. (There are also a limited set of cases where the parentheses around (result) can be omitted, but we can leave that out for now.) Sorry to dump OpenSCAD2 syntax into this thread. My excuse is that Torsten and Marius have previously expressed interest in integrating more of that syntax into OpenSCAD. On 15 January 2016 at 15:56, MichaelAtOz <oz.at.michael@gmail.com> wrote: > doug.moen wrote > > I just like the way that the debug output is visually separated from the > > rest of the code in a function. > > > > function sum(x, y) = > > echof("sum(",x,",",y,")") > > (x + y); > > > > If you like this syntax, you'll need to add another production to the > > expression grammar, which for now will only be used by echof. I can help, > > since I've already got a working bison grammar for this. > > Nooooooooooo. (I think) > > echof() needs to be able to be placed anywhere in an expression. > Consider a complex recursion, it could be going wrong in any number of > "...?...:..." > > > > > ----- > Newly minted 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! > -- > View this message in context: > http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15715.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
Fri, Jan 15, 2016 9:09 PM

On 01/15/2016 09:56 PM, MichaelAtOz wrote:

doug.moen wrote

function sum(x, y) =
echof("sum(",x,",",y,")")
(x + y);

Nooooooooooo. (I think)

echof() needs to be able to be placed anywhere in an expression.
Consider a complex recursion, it could be going wrong in any number of
"...?...:..."

If it would behave as let(), you can place it where you want.

E.g. what I had first thought:

function f(x) = echo(x = x, result = x > 0 ? f(x - 1) * 2 : 1);

would become

function f(x) = echo(x = x) x > 0 ? f(x - 1) * 2 : 1;

and print the "x = ..." part first and after the values that
are coming from the assignment, it would print (and also return)
the expression behind.

Also: function f(x, y) = echo() x * echo() y;
or: function(x, y) = echo(x = x, y = y) x * y;

ciao,
Torsten.

On 01/15/2016 09:56 PM, MichaelAtOz wrote: > doug.moen wrote >> function sum(x, y) = >> echof("sum(",x,",",y,")") >> (x + y); >> > Nooooooooooo. (I think) > > echof() needs to be able to be placed anywhere in an expression. > Consider a complex recursion, it could be going wrong in any number of > "...?...:..." > If it would behave as let(), you can place it where you want. E.g. what I had first thought: function f(x) = echo(x = x, result = x > 0 ? f(x - 1) * 2 : 1); would become function f(x) = echo(x = x) x > 0 ? f(x - 1) * 2 : 1; and print the "x = ..." part first and after the values that are coming from the assignment, it would print (and also return) the expression behind. Also: function f(x, y) = echo() x * echo() y; or: function(x, y) = echo(x = x, y = y) x * y; ciao, Torsten.
M
MichaelAtOz
Fri, Jan 15, 2016 10:25 PM

tp3 wrote

and print the "x = ..." part first and after the values that
are coming from the assignment, it would print (and also return)
the expression behind.

Also: function f(x, y) = echo() x * echo() y;
or: function(x, y) = echo(x = x, y = y) x * y;

Are you suggesting the assignment actually works as per let()?
That changes it from a simple none side-effect (except console) debug
statement, to a functional part of the language.


Newly minted 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!

View this message in context: http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15719.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

tp3 wrote > and print the "x = ..." part first and after the values that > are coming from the assignment, it would print (and also return) > the expression behind. > > Also: function f(x, y) = echo() x * echo() y; > or: function(x, y) = echo(x = x, y = y) x * y; Are you suggesting the assignment actually works as per let()? That changes it from a simple none side-effect (except console) debug statement, to a functional part of the language. ----- Newly minted 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! -- View this message in context: http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15719.html Sent from the OpenSCAD mailing list archive at Nabble.com.
TP
Torsten Paul
Fri, Jan 15, 2016 10:54 PM

On 01/15/2016 11:25 PM, MichaelAtOz wrote:

tp3 wrote

and print the "x = ..." part first and after the values that
are coming from the assignment, it would print (and also return)
the expression behind.

Also: function f(x, y) = echo() x * echo() y;
or: function(x, y) = echo(x = x, y = y) x * y;

Are you suggesting the assignment actually works as per let()?
That changes it from a simple none side-effect (except console) debug
statement, to a functional part of the language.

I'd prefer something that makes it easier to move to the
OpenSCAD2 syntax later and does not have funny names like
echof().

If it's not possible to find a sensible way to have that
with echo(), it might even be something completely new for
both cases which leaves behind the current echo() eventually.

ciao,
Torsten.

On 01/15/2016 11:25 PM, MichaelAtOz wrote: > tp3 wrote >> and print the "x = ..." part first and after the values that >> are coming from the assignment, it would print (and also return) >> the expression behind. >> >> Also: function f(x, y) = echo() x * echo() y; >> or: function(x, y) = echo(x = x, y = y) x * y; > > Are you suggesting the assignment actually works as per let()? > That changes it from a simple none side-effect (except console) debug > statement, to a functional part of the language. > I'd prefer something that makes it easier to move to the OpenSCAD2 syntax later and does not have funny names like echof(). If it's not possible to find a sensible way to have that with echo(), it might even be something completely new for both cases which leaves behind the current echo() eventually. ciao, Torsten.
M
MichaelAtOz
Sat, Jan 16, 2016 12:55 AM

Could consider plain dumb echof() or echo() [as a function] short term and
immediately deprecate it, while working on debug() [or whatever the grand
OpenSCAD2 solution will be].

Could call it _echo() or something if you don't like funny names...


Newly minted 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!

View this message in context: http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15724.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Could consider plain dumb echof() or echo() [as a function] short term and immediately deprecate it, while working on debug() [or whatever the grand OpenSCAD2 solution will be]. Could call it _echo() or something if you don't like funny names... ----- Newly minted 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! -- View this message in context: http://forum.openscad.org/debug-print-in-openscad-functions-tp15683p15724.html Sent from the OpenSCAD mailing list archive at Nabble.com.
TP
Torsten Paul
Sat, Jan 16, 2016 1:05 AM

On 01/16/2016 01:55 AM, MichaelAtOz wrote:

Could consider plain dumb echof() or echo() [as a function] short term and
immediately deprecate it, while working on debug() [or whatever the grand
OpenSCAD2 solution will be].

Could call it _echo() or something if you don't like funny names...

In case a "temporary" solution is ok, then it can be just echo().
If that's fine with Marius, I'd have an updated pull request ready
based on the older existing echof() pull request...

ciao,
Torsten.

On 01/16/2016 01:55 AM, MichaelAtOz wrote: > Could consider plain dumb echof() or echo() [as a function] short term and > immediately deprecate it, while working on debug() [or whatever the grand > OpenSCAD2 solution will be]. > > Could call it _echo() or something if you don't like funny names... > In case a "temporary" solution is ok, then it can be just echo(). If that's fine with Marius, I'd have an updated pull request ready based on the older existing echof() pull request... ciao, Torsten.