Re: eval use ?
- From: M Jared Finder <jared@xxxxxxxxxxx>
- Date: Sun, 26 Feb 2006 23:19:41 -0800
Majorinc wrote:
In article <1140929811.970351.270010
@e56g2000cwe.googlegroups.com>, amit_h123@xxxxxxxxxxx says...
hello,
i am just tryin to learn lisp from robert wilensky's common lispcraft.
But i am all stuck at the eval function use ..can somebody help me out
what does exactly eval is used for specially can you give me some
examples of complex code where it is being use.. coz its like i can get
the simpler examples but not gettin it utility for complex thinkgs
where it can be used..
Just two examples from my practice - imagine that you write screen saver, and you want to write program that calculate and draw some cute 3d objects on the base of random ... formula. Now, the problem - how to represent formulas? The simplest answer is to represent them as expressions in the programming language and evaluate as needed.
This would be much better done using functions, not eval. Represent each formula as a function, and use funcall to evaluate.
Or, second example - imagine that you want to write program that process Boolean formulas. How will you represent that formula? It is best to represent them as Lisp expression and in that case, from time to time, it will be very handy to simply EVALuate such formula.
Unless you are expecting to symbolicly manipulate the formulas, it would again be better to represent each as a function.
I can describe few other problems from top of my mind. Of course, all this can be done without EVAL, hey, everything can be done in C. Just data structures and algorithms one develop with time start to look like interpreter.
Not only can they both be done without eval, they can be done much clearer, faster, and more naturally without eval. Eval is very very rarely useful; it's mainly useful for recreating your own REPL. Other cases are better off using macros or closures, both of which more cleanly integrate with the rest of Lisp.
-- MJF
.
- Follow-Ups:
- Re: eval use ?
- From: Majorinc , Kazimir
- Re: eval use ?
- References:
- eval use ?
- From: newbie
- Re: eval use ?
- From: Majorinc , Kazimir
- eval use ?
- Prev by Date: Re: eval use ?
- Next by Date: Re: lisp idiom for processing each line in a file?
- Previous by thread: Re: eval use ?
- Next by thread: Re: eval use ?
- Index(es):
Relevant Pages
|