Re: eval use ?



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
.



Relevant Pages

  • Re: Whats the best language to learn...
    ... consider the merits of the typical implementations. ... on processors designed to run Lisp and Lisp OSes. ... level programming language such as Lisp. ... lisp, java, ruby, etc. ...
    (comp.programming)
  • Re: The PL design space is not that simple (was: Re: Alternatives 4)
    ... solution, including a programming language. ... Implicit in the fact that a newsgroup specific to Lisp ... I don't believe that the PL design space is that simple. ...
    (comp.lang.lisp)
  • Re: Would logo count as an introduction to lisp?
    ... so much of computerdom is not theoretical. ... > on the theoretical niceties of any particular programming language. ... > So what I'm saying is: is studying Lisp / Scheme worthwhile? ... I learnt enough statistics to get by ...
    (comp.lang.lisp)
  • Re: SMLs patterns
    ... >> like macros in Lisp. ... I personally have very little use for interactivity when I ... I don't have a use for a Ferrari. ... I see the programming language Lisp more like a Mercedes-Benz Unimog. ...
    (comp.lang.functional)
  • Re: Whats the best language to learn...
    ... Common Lisp as a industry strong programming language. ... compete effectively in most respects with more mainstream languages (C, C++, ... you said that you didn't consider it a "general purpose language". ...
    (comp.programming)