(my-or temp nil) = 45
(my-or nil temp) = 45
-----------
first arg
should be 1: 1
-----------
first arg
second arg
should be 2: 2
At least its short (shorter then the if version)
returns the values correctly and doesnt drop variables..
But then again it uses (args) and it uses 'unless (which is an 'or).
PS: Dropin another quizzzzzzzzzz ;-)
Congrats newdep! That's a valid solution!
It is similar in principle to the one I came up with, but actually yours is better because it is much faster. In fact it's almost as fast as placing the macro in its own namespace. Send me a PM with your full name and email if you'd like a license to Espionage.
Here is the one I came up with, as you can see the principle of avoiding the evaluation is sortof the same, whereas you do it with 'unless', I did it with the exception mechanism. :-D
Yes, the 'unless' and 'or' are similar, but the 'or' solution as was presented was equivalent to doing this (and therefore not an acceptable solution):
I was mainly looking for something similar to what I had, which I feel your solution was, as it used the same principle of avoiding the extra evaluation that was in DrDave's code while avoiding variable capture as well.
I hope though that nobody actually writes their macros this way, as to an outsider it would be completely non-obvious why the extra hoop-jumping was taking place.
This just demonstrates the need for a define-smacro in newLISP.
Aha...I win finaly something here ;-)
Thanks for the price.. I dont have a Mac with OSX only
a MacClassic and an IMac.. But If you dont mind I would Like to store
you kind generosity for the "yearly newlisp Contest".. Where a winner
then also could get your nice software package.. (If thats oke with you, it would be a nice addon for the price shelf...)
Coming back to the Scheme example, I think its somehow unfair too what
Scheme does with GenSym. So personaly I prefer the newlisp (arg) way
of solving this. Where GenSym is a nice workaround its also not transparent for the function..
..I liked the quizzzz.. nice brain trainers these are...
newdep wrote:But If you dont mind I would Like to store
you kind generosity for the "yearly newlisp Contest".. Where a winner
then also could get your nice software package.. (If thats oke with you, it would be a nice addon for the price shelf...)
This solution uses a lambda to store the eval'ed first arg to the macro and defer evaluation of the second. It's not as fast as the solution presented by lutz, which has an execution time about 65% of mine, probably because mine entails an extra function call. But it does, at least, avoid the need for creating a new context just for one simple macro. This was a fun and surprisingly challenging problem. Thanks, itistoday!
So you used nested function call to transfer arguments in nested function so you do not have to use any variable at all. As (arg n) are always local, accidental overshadowing is impossible. Very interesting idea.
Kazimir Majorinc wrote:So you used nested function call to transfer arguments in nested function so you do not have to use any variable at all. As (arg n) are always local, accidental overshadowing is impossible. Very interesting idea.
Welcome to the forum.
Thanks! While this particular problem is unlikely to arise in any real-life work (after all, we have 'or), I think the basic underlying idea is potentially quite useful.
-- Christopher Suter
"The only reason for time is so that everything doesn't happen at once."
Albert Einstein
cgs1019 passes the user arguments to an inner function, with only the first argument evaluated. The inner function then decides if the second must be evaluated too. cgs1019 just uses the anonymous version of func. This is like doing:
ps: apropos "namespace jungle ;)": basic usage patterns of namespaces in newLISP are quite simple, like partitioning code into modules. Beyond that it gets more complicated and requires some manual studying to understand that namespaces in newLISP are not dynamic closures like in Scheme, but can be just as (and more) powerful when using them in their own way ;-)
cgs1019 wrote:This solution uses a lambda to store the eval'ed first arg to the macro and defer evaluation of the second. It's not as fast as the solution presented by lutz, which has an execution time about 65% of mine, probably because mine entails an extra function call. But it does, at least, avoid the need for creating a new context just for one simple macro. This was a fun and surprisingly challenging problem. Thanks, itistoday!
Your solution is beautiful Chris, I'd give you an Espionage license for it if I didn't know that you already had one. :-)
Last edited by itistoday on Thu Apr 09, 2009 8:06 pm, edited 1 time in total.