[pro] The Best Examples of "Code is Data"

Scott McKay swm at itasoftware.com
Tue Sep 14 17:15:49 UTC 2010


On Sep 14, 2010, at 1:07 PM, Kazimir Majorinc wrote:

> On 8.9.2010 0:08, Daniel Weinreb wrote:
> 
>> There is an old saying: if you are using "eval", you are
>> doing it wrong. So far I have yet to find any significant
>> exceptions to this rule.
> 
> Look at this:
> 
>   The program generates propositional formulas S1, S2, ... using
>   some experimental algorithm. S1, ..., Sn are needed for generation of
>   Sn+1, as typical in deductive systems. The formulas contain logical
>   constants and already defined operators. The hypothesis is:
>   all generated propositional expressions are true.
> 
>   The problem: write the function that tests that hypothesis for
>   any generated formula. Optimization is not needed. Simpler is better.
> 
> I'd use eval instead of defining any new function, as the simplest and
> the most natural solution. What would others do? If you'd use eval as
> well, do you think it is important or rare, maybe even 'artificial'
> example.
> 


This is a place you could use 'eval', but...
 - It depends on what the propositions contain.
   If it's a tiny subset of Lisp (like 'and', 'or', 'not'),
   a custom evaluator might be nicer.
 - A custom evaluator might be faster, too, especially if you're
   doing this in the context of some sort of SAT-solver where you've
   got lots of propositions, and you might want caching, etc.

In the many years I've been using Lisp, I've used eval so few times,
and one of the times was in a debugger where I wanted to evaluate
Lisp forms.  :-)





More information about the pro mailing list