4 ms·
I guess the alternative would be to define "apply" as a macro which evals the cons of its first argument and the other list of arguments...
by Patient0 14y ago
I guess the alternative would be to define "apply" as a macro which evals the cons of its first argument and the other list of arguments...
- akkartik 14y agoI addressed this approach at the top of the second link: http://arclanguage.org/item?id=15907 http://arclanguage.org/item?id=15907 Basically you'd have to: 1. eval the list 2. cons the macro to the list, eval to yield the macroexpansion 3. implicitly eval the macroexpansion -- but not eval the elements of the spliced in list because they've already been eval'd once. Step 3 throws a spanner in the works. So you might say, fine, let's quote all the elements of the spliced in list. And that'll seem to work for the previous example, but you'll eventually run into an example like this: (apply = '(x 3)) => (= 'x '3) => error: can't assign to (quote x) So you have to perform step 3 without actually inserting a literal quote. I gave up at this point.
- Patient0 14y agoAh I see. I've started implementing a Lisp interpreter in C# and I also was going along the path of making everything "first class" by using f-expressions where appropriate. So far my only actual f-expressions are "lambda" and "if" - everything else is bootstrapped as macros or functions. My "apply" currently expects a function but I was toying with making it "eval" the cons macro... but then "apply" has to become an f-expression instead of just a plain normal function which seemed inelegant so I left it as a function that requires a function. Reading your story... I think I'll leave it permanently side-stepped!! :-)
- akkartik 14y agoNice to meet ya! I've been working on a lisp as well: http://github.com/akkartik/wart#readme http://github.com/akkartik/wart#readme
- akkartik 14y agoBTW, in case you see this: I solved the problem for a large subset of macros. Details: http://arclanguage.org/item?id=16378 http://arclanguage.org/item?id=16378