Souphead wrote:
I have seen your postings on pixels.us though I try to post on only one site. Let me ask a few questions.
- Functions can have multiple statements? The example above has only one.
Yes, you can have multiple statements, just as any expression. By the way, the example above has already two statements (there is a ';' delimitor if you look at it closely). Just put your multiple statements between parentheses, and you're done with it.
Quote:
- Are variables local or global in scope inside the function?
In fact, there is no 'scope' for the function. It's more a
macro than as function to be honest. When the expression parser find a function call like 'foo(1,2,3)', it just replaces 'foo()' by its definition with the argument substituted into it. Nothing more.
I think this is good enough and do not slow down the expression parser too much. You have to take care of possible side effects of course, like :
foo(x) = x + x;
z=0;
foo(++z)
This example returns 4, as 'foo(++z)' is replaced by '(++z) + (++z)' equivalent to '++z;++z;z+z' i.e. 4.
As these are macros rather than regular functions, it also avoids recursive calls. I know this is a limitation, but this is how it works for now.
Maybe in the future, I'll find an easy way to do the calls as regular functions, but if I do that, I'm sure this will be slower to execute
(I'll need to copy the functions arguments in a stack). I don't really see the advantages of having regular functions rather than macros right now
(except for recursive calls).
Quote:
-Function definitions happen before usage (ie above it in the code) but after the init(), right?
They can appear anywhere before they are used. Defining a function takes some time during the expression compilation, but nothing during the evaluation. I guess that writing them in the 'init()' section could be a good practice
Also, a function that has been already defined can be re-defined in another place (just like a macro), with a different signature.
Quote:
- Any view yet on the overhead?
Yes, that's the point. As I know this math parser is a JIT compiler, I've made a lot of efforts to reduce the overhead.
If you don't use custom functions at all, it costs nothing. Otherwise, it takes just a slight amount of time during the
expression compilation, nothing more during the evaluation itself (as they are macros, they don't have an existence
by themselves in the compiled bytecode).
Quote:
I haven't got too far with adding them in to Droste (real like has got in the way) but I'll get onto it soon. If nothing else this should significantly reduce the number of lines of code.
Do you need (as apposed to want) some feedback before fully releasing 1.6.9? Also, any view of when 1.6.9 is being released? If you don't want to go public on it, I understand.
Yes, I'd be interested by any feedback on the new math parser features. I'm trying to do some tests here, but I'm sure I'll miss a lot of weird configurations which may crash the math parser. Feel free to play with it.
I'll try to release new 'pre-release' packages this afternoon (GMT+1). If everything goes well, I'll try to release 1.6.9 maybe in one or two weeks
(I have to write some more docs also before releasing).
Quote:
I have a few other thoughts on features - these are much smaller and maybe they are already there, somewhere.
Inside a "Do" loop, is there a way to CONTINUE (go directly to the test condition) or immediately BREAK from the loop?
For that, I'd use something like this :
x = 10;
dowhile(
...; # Do things here.
do_I_continue?0: # Equivalent to a 'continue'
..., # Do non-continue things here (end with a comma)
--x>0
)
and same for the break:
x = 10;
dowhile(
...; # Do things here.
do_I_break?x=0: # Equivalent to a 'break'
..., # Do non-break things here (end with a comma)
--x>0
)
Quote:
Is there any direct handling of multiple choice logic either by an "elseif" or a switch-like control block? Nested 'if' blocks always work but they soon becomes unclear.
Same here, the ternary operator allows to write things, that, when correcty indented, really look like a '-if...-elif...-else...-endif' bloc:
is_test1?
do_test1_stuff:
is_test2 ?
do_test2_stuff:
is_test3 ?
do_test3_stuff:
do_else_stuff