|This message can be seen as a follow-up to the "Macro expansion/evaluation problem" thread (http://www.arclanguage.org/item?id=10205). In short: I want to make 'each have an "anonymous form", where I could say:|
But currently I can't do it (because I'm weak, but nothing is impossible ;-)). I thought the root of all my problems were the 'if behaviour in Arc, but its behaviour is actually quite normal (i.e: like in Common Lisp, but I stay persuaded it should be more "lazy" or something ;-P). So CatDancer said I better try to implement a 'defined operator, that could tell, at macro-expansion time if a variable is defined or not.
arc> (each '(1 2 3) (pr _)) ; use the _ symbol, like in anonymous 1-param fns
So, I followed his wise advice, and I've implemented something which works, but well, it's a dirty hack and it is insufficient anyway.
Big picture: when 'ac sees an sexpr beginning by 'defined, it returns the function 'ac-defined. Later, in ac-mac-call, if the result of the application of the args to the macro is a procedure (it is 'ac-defined), it is called with the macro args & env for parameters.
arc> (mac isdef (x) (defined x))
#3(tagged mac #<procedure: isdef>)
arc> (isdef a)
arc> (let a 1 (isdef a))
arc> (isdef (+ 2 1))
arc> (isdef (+ 2 a))
arc> (= a 42)
arc> (isdef (+ 2 a))
arc> (defined a) ; could only be used in macro
I'll post the patch in a comment.
However, as I said, it is imperfect. Big, big problem is... it doesn't work with 'if. Since 'if quasiquotes the test:
and in the 'defined case, ,(ac ...) returns #<procedure:ac-defined> which is obviously true.
`(if (not (ar-false? ,(ac (car args) env)))
So, I tried to also hack 'if :-D, but I will turn insane if I continue for now!
It's like with 'ac-mac-call, 'if should now be aware of this new (strange) kind of object.
I try to make 'if returning a closure when the test is 'ac-defined (or any procedure? actually ; could be the start of a way to do some kind of lazy evaluation), but... this leads to a lot of environment/arguments problems, because they vary between "compile" and runtime.
So here I am for the moment, resting from looking at Arc guts, and asking for any advice/ideas/suggestions a person interested in the subject would have :-)