Are there any other languages that use assert like you propose? I can't
think of any where assert doesn't bring things to a full stop. I don't
think OpenSCAD should be the first.
On 3/16/19 1:58 PM, nop head wrote:
Perhaps assert should be changed to a warning and if you want it to
stop like an error then you select stop on first warning.
On Sat, 16 Mar 2019 at 17:59, adrianv <avm4@cornell.edu
mailto:avm4@cornell.edu> wrote:
tp3 wrote
Yes, like nophead wrote, you should not need that.
Here's a more detailed example:
function f(a, b) =
assert(a < 0, "wrong a") // assert input
assert(b > 0, "wrong b") // assert input
let (c = a + b) // derive a new value from input
assert(c != 0, "wrong c") // assert derived value
a * b; // calculate
This is a great solution to the problem. I don't like nophead's
solution
because it mingles the computation into the assert in a way that's
hard to
read, but this approach is clear. It didn't occur to me that
assert could
take children. (This isn't mentioned in the manual at all.) I do
wish
that let would allow a dangling comma on the last expression,
which would
make it easier to insert and delete assignments.
But regarding the other issue, I still think it would be nice if
there was a
way to generate warning and error messages from my code, without funny
business. It would be more clear to a user to see
ERROR: Value 'a' must be larger than zero in file tp, line 3
than
ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero"
failed in
file tp, line 3.
And of course there's no mechanism at all to generate a warning.
--
Sent from: http://forum.openscad.org/
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org <mailto: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
Well I suppose the alternative is to add a warning statement and function,
which duplicates all the same logic.
On Sat, 16 Mar 2019 at 19:15, Joe Francis joe@lostapathy.com wrote:
Are there any other languages that use assert like you propose? I can't
think of any where assert doesn't bring things to a full stop. I don't
think OpenSCAD should be the first.
On 3/16/19 1:58 PM, nop head wrote:
Perhaps assert should be changed to a warning and if you want it to stop
like an error then you select stop on first warning.
On Sat, 16 Mar 2019 at 17:59, adrianv avm4@cornell.edu wrote:
tp3 wrote
Yes, like nophead wrote, you should not need that.
Here's a more detailed example:
function f(a, b) =
assert(a < 0, "wrong a") // assert input
assert(b > 0, "wrong b") // assert input
let (c = a + b) // derive a new value from input
assert(c != 0, "wrong c") // assert derived value
a * b; // calculate
This is a great solution to the problem. I don't like nophead's solution
because it mingles the computation into the assert in a way that's hard to
read, but this approach is clear. It didn't occur to me that assert could
take children. (This isn't mentioned in the manual at all.) I do wish
that let would allow a dangling comma on the last expression, which would
make it easier to insert and delete assignments.
But regarding the other issue, I still think it would be nice if there
was a
way to generate warning and error messages from my code, without funny
business. It would be more clear to a user to see
ERROR: Value 'a' must be larger than zero in file tp, line 3
than
ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero" failed in
file tp, line 3.
And of course there's no mechanism at all to generate a warning.
--
Sent from: http://forum.openscad.org/
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
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
I think that makes a lot more sense.
If a library author needs a way to bail out if something is hopelessly
wrong, that capability shouldn't get taken away because a user
preference says "just treat asserts like warnings". Even if that
library author is just me from 6 months ago :).
I do this all the time to verify the relationship between parameters.
If something won't work, I want it to fail immediately rather than spend
a couple minutes rendering something that doesn't make any sense.
Putting together a warning() method like that should be doable in
userspace, too.
On 3/16/19 2:17 PM, nop head wrote:
Well I suppose the alternative is to add a warning statement and
function, which duplicates all the same logic.
On Sat, 16 Mar 2019 at 19:15, Joe Francis <joe@lostapathy.com
mailto:joe@lostapathy.com> wrote:
Are there any other languages that use assert like you propose? I
can't think of any where assert doesn't bring things to a full
stop. I don't think OpenSCAD should be the first.
On 3/16/19 1:58 PM, nop head wrote:
Perhaps assert should be changed to a warning and if you want it
to stop like an error then you select stop on first warning.
On Sat, 16 Mar 2019 at 17:59, adrianv <avm4@cornell.edu
<mailto:avm4@cornell.edu>> wrote:
tp3 wrote
Yes, like nophead wrote, you should not need that.
Here's a more detailed example:
function f(a, b) =
assert(a < 0, "wrong a") // assert input
assert(b > 0, "wrong b") // assert input
let (c = a + b) // derive a new value from input
assert(c != 0, "wrong c") // assert derived value
a * b; // calculate
This is a great solution to the problem. I don't like
nophead's solution
because it mingles the computation into the assert in a way
that's hard to
read, but this approach is clear. It didn't occur to me that
assert could
take children. (This isn't mentioned in the manual at all.)
I do wish
that let would allow a dangling comma on the last expression,
which would
make it easier to insert and delete assignments.
But regarding the other issue, I still think it would be nice
if there was a
way to generate warning and error messages from my code,
without funny
business. It would be more clear to a user to see
ERROR: Value 'a' must be larger than zero in file tp, line 3
than
ERROR: Assertion '(a>0)': "Value 'a' must be larger than
zero" failed in
file tp, line 3.
And of course there's no mechanism at all to generate a warning.
--
Sent from: http://forum.openscad.org/
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org>
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org>
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org <mailto: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
You can echo warnings in user space but I don't think they will stop on
first warning.
On Sat, 16 Mar 2019 at 19:27, Joe Francis joe@lostapathy.com wrote:
I think that makes a lot more sense.
If a library author needs a way to bail out if something is hopelessly
wrong, that capability shouldn't get taken away because a user preference
says "just treat asserts like warnings". Even if that library author is
just me from 6 months ago :).
I do this all the time to verify the relationship between parameters. If
something won't work, I want it to fail immediately rather than spend a
couple minutes rendering something that doesn't make any sense.
Putting together a warning() method like that should be doable in
userspace, too.
On 3/16/19 2:17 PM, nop head wrote:
Well I suppose the alternative is to add a warning statement and function,
which duplicates all the same logic.
On Sat, 16 Mar 2019 at 19:15, Joe Francis joe@lostapathy.com wrote:
Are there any other languages that use assert like you propose? I can't
think of any where assert doesn't bring things to a full stop. I don't
think OpenSCAD should be the first.
On 3/16/19 1:58 PM, nop head wrote:
Perhaps assert should be changed to a warning and if you want it to stop
like an error then you select stop on first warning.
On Sat, 16 Mar 2019 at 17:59, adrianv avm4@cornell.edu wrote:
tp3 wrote
Yes, like nophead wrote, you should not need that.
Here's a more detailed example:
function f(a, b) =
assert(a < 0, "wrong a") // assert input
assert(b > 0, "wrong b") // assert input
let (c = a + b) // derive a new value from input
assert(c != 0, "wrong c") // assert derived value
a * b; // calculate
This is a great solution to the problem. I don't like nophead's solution
because it mingles the computation into the assert in a way that's hard
to
read, but this approach is clear. It didn't occur to me that assert
could
take children. (This isn't mentioned in the manual at all.) I do wish
that let would allow a dangling comma on the last expression, which would
make it easier to insert and delete assignments.
But regarding the other issue, I still think it would be nice if there
was a
way to generate warning and error messages from my code, without funny
business. It would be more clear to a user to see
ERROR: Value 'a' must be larger than zero in file tp, line 3
than
ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero" failed in
file tp, line 3.
And of course there's no mechanism at all to generate a warning.
--
Sent from: http://forum.openscad.org/
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
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
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
nophead wrote
Perhaps assert should be changed to a warning and if you want it to stop
like an error then you select stop on first warning.
I don't think so. Some situations just call for warnings. And some are
errors. The first warning isn't an error.
I edited the manual to add the example of using assert in a function. I'm
not sure I correctly stated how assert works, though, so someone might want
to check. It looks like it returns the union of its children if you give
it children--is there any reason you'd ever want to do this? But is using
it in an expression context different?
Well I suppose the alternative is to add a warning statement and function,
which duplicates all the same logic.
I think it would be better to add an error statement that has a flag for
severity and which doesn't include all the extra verbiage, so you could
write
error(c<=0,"Must set c>0"); // Displays: ERROR: Must set c>0, in file
foo.scad, line 3
error(check_bounds(c),"c is close to zero",warning=true); // Displays:
WARNING: c is close to zero, in file foo.scad, line 25
Note there is no word "failed" and no assertion condition displayed on
output, and no extra quote characters. I have already found it necessary to
save condition results into variables so I don't put a long condition into
the assert because I don't want that complicated condition test to display
to the user.
lostapathy wrote
Putting together a warning() method like that should be doable in
userspace,
too.
You can't create warnings in userspace if there's no way to actually make a
real warning. You can just make yellow text. But it's not the same.
--
Sent from: http://forum.openscad.org/
In the Curv language, I have 4 operations called 'print', 'assert', 'warning' and 'error', and none of them can be replaced by the others.
'print' is like 'echo' in OpenSCAD.
'assert(condition)' aborts the program if condition is false, printing an error message and a stack trace.
'error(message)' aborts the program, printing the message and a stack trace. Unlike 'assert', you can use error in either a statement context or an expression context. That is, you can write 'x < 0 ? error("negative x") : f(x)'.
'warning(message)' prints the message followed by a stack trace, and the program keeps running.
So, based on this experience, I think it is useful to have separate 'warning' and 'error' operations.
Doug Moen.
On Sat, Mar 16, 2019, at 3:38 PM, adrianv wrote:
nophead wrote
Perhaps assert should be changed to a warning and if you want it to stop
like an error then you select stop on first warning.
I don't think so. Some situations just call for warnings. And some are
errors. The first warning isn't an error.
I edited the manual to add the example of using assert in a function. I'm
not sure I correctly stated how assert works, though, so someone might want
to check. It looks like it returns the union of its children if you give
it children--is there any reason you'd ever want to do this? But is using
it in an expression context different?
Well I suppose the alternative is to add a warning statement and function,
which duplicates all the same logic.
I think it would be better to add an error statement that has a flag for
severity and which doesn't include all the extra verbiage, so you could
write
error(c<=0,"Must set c>0"); // Displays: ERROR: Must set c>0, in file
foo.scad, line 3
error(check_bounds(c),"c is close to zero",warning=true); // Displays:
WARNING: c is close to zero, in file foo.scad, line 25
Note there is no word "failed" and no assertion condition displayed on
output, and no extra quote characters. I have already found it necessary to
save condition results into variables so I don't put a long condition into
the assert because I don't want that complicated condition test to display
to the user.
lostapathy wrote
Putting together a warning() method like that should be doable in
userspace,
too.
You can't create warnings in userspace if there's no way to actually make a
real warning. You can just make yellow text. But it's not the same.
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Having just written functions and modules to emulate error() and warning(), that only really output colored text, I agree that there should be builtins that stop compilation or trigger the warnings popup.
On Mar 16, 2019, at 1:54 PM, Doug Moen doug@moens.org wrote:
In the Curv language, I have 4 operations called 'print', 'assert', 'warning' and 'error', and none of them can be replaced by the others.
'print' is like 'echo' in OpenSCAD.
'assert(condition)' aborts the program if condition is false, printing an error message and a stack trace.
'error(message)' aborts the program, printing the message and a stack trace. Unlike 'assert', you can use error in either a statement context or an expression context. That is, you can write 'x < 0 ? error("negative x") : f(x)'.
'warning(message)' prints the message followed by a stack trace, and the program keeps running.
So, based on this experience, I think it is useful to have separate 'warning' and 'error' operations.
Doug Moen.
On Sat, Mar 16, 2019, at 3:38 PM, adrianv wrote:
nophead wrote
Perhaps assert should be changed to a warning and if you want it to stop
like an error then you select stop on first warning.
I don't think so. Some situations just call for warnings. And some are
errors. The first warning isn't an error.
I edited the manual to add the example of using assert in a function. I'm
not sure I correctly stated how assert works, though, so someone might want
to check. It looks like it returns the union of its children if you give
it children--is there any reason you'd ever want to do this? But is using
it in an expression context different?
Well I suppose the alternative is to add a warning statement and function,
which duplicates all the same logic.
I think it would be better to add an error statement that has a flag for
severity and which doesn't include all the extra verbiage, so you could
write
error(c<=0,"Must set c>0"); // Displays: ERROR: Must set c>0, in file
foo.scad, line 3
error(check_bounds(c),"c is close to zero",warning=true); // Displays:
WARNING: c is close to zero, in file foo.scad, line 25
Note there is no word "failed" and no assertion condition displayed on
output, and no extra quote characters. I have already found it necessary to
save condition results into variables so I don't put a long condition into
the assert because I don't want that complicated condition test to display
to the user.
lostapathy wrote
Putting together a warning() method like that should be doable in
userspace,
too.
You can't create warnings in userspace if there's no way to actually make a
real warning. You can just make yellow text. But it's not the same.
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
How would I write a modular code that checks for an error condition and
prints a message that I can use without dummy variables? Is this possible?
Could it be possible with a new error() function?
function do_something(x,y,mode) =
check_valid(mode,"mode", ["fast","slow","big","tall","purple"])
<function calculation>;
where check_valid checks() checks whether mode is on the list and if it's
not constructs a message like "Input 'mode' was set to <garbage>; it must be
one of 'fast', 'slow', 'big', 'tall', 'purple'") and calls assert() or
error().
I would rather avoid having to write a custom assert every time where I have
to repeat the list of options. But if I write a function, then it needs to
be part of an assignment, so then I need the dummy variable. Is there a way
around this?
--
Sent from: http://forum.openscad.org/
function do_something(x,y,mode) =
assert(check_valid(mode,"mode", ["fast","slow","big","tall","purple"]),
"bad mode")
<function calculation>;
On Mon, 25 Mar 2019 at 13:13, adrianv avm4@cornell.edu wrote:
How would I write a modular code that checks for an error condition and
prints a message that I can use without dummy variables? Is this
possible?
Could it be possible with a new error() function?
function do_something(x,y,mode) =
check_valid(mode,"mode", ["fast","slow","big","tall","purple"])
<function calculation>;
where check_valid checks() checks whether mode is on the list and if it's
not constructs a message like "Input 'mode' was set to <garbage>; it must
be
one of 'fast', 'slow', 'big', 'tall', 'purple'") and calls assert() or
error().
I would rather avoid having to write a custom assert every time where I
have
to repeat the list of options. But if I write a function, then it needs to
be part of an assignment, so then I need the dummy variable. Is there a
way
around this?
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
nophead wrote
function do_something(x,y,mode) =
assert(check_valid(mode,"mode",
["fast","slow","big","tall","purple"]),
"bad mode")
My initial reaction was that this doesn't solve the problem, since the
actual error message text says "bad mode" instead of actually giving the
informative content. But in fact it might actually be better than the
status quo if the check_valid function displays its error in red text so it
looks like part of the error message. I'd call it a hack, but a decent one.
--
Sent from: http://forum.openscad.org/