-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to make an eval function? #11
Comments
Here's how I did it:
case P_EVAL:
va = checktype(ctx, evalarg(), FE_TPAIR);
res = eval(ctx, va, env, NULL);
break; You now have a functional (print "(eval '(+ 100 200)) =" (eval '(+ 100 200)))
(do
(let expr '(for x (list 1 2 3 4 5)
(print "x =" x)))
(print "(eval expr) =" (eval expr))) Keep in mind that fe doesn't support tail call optimization. This implementation of the |
Thanks for your solution! Any chance the original author (rxi) would include it in 'fe'? |
I realized this well after my last post, but I sort of over fitted my implementation to your example. You can simplify the case P_EVAL:
res = eval(ctx, EVAL_ARG(), env, NULL);
break; The prior version would only evaluate function application. This version will dynamically evaluate any legitimate s-expression. For example: (do
(let a 42)
(print "(eval 'a) =" (eval 'a))) Now works, evaluating the variable. Either version works, depending on your needs. Just thought I'd mention it. I don't want to speak for @rxi but I think the idea is that fe is so simple others can take it and mold it to their specific requirements. I've heavily customized fe for my use cases. @rxi If you like the idea of officially adding an |
@jeffpanici75 What is |
Thanks for fe -- a very nice tiny interpreter.
How could I make an
eval
function (or macro)? i.e. such that(= a '(+ 1 2))
(eval a)
=> 3I tried using
mac
andfn
but couldn't make it. Did I miss something obvious?The text was updated successfully, but these errors were encountered: