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

Daniel Weinreb dlw at itasoftware.com
Wed Sep 22 15:12:31 UTC 2010



Scott McKay wrote:
> 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.
>   

Yes, I was just about to hit reply and say all these things,
but Scott got there first.

I'll add that if you can make the tiny subset have no
side effects, there are lots of good properties of
that.

And if you can make it declarative, that has big
advantages, although that might provide not
enough power, depending on what you're planning
to use this for.

-- Dan

> 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.  :-)
>
>
> _______________________________________________
> pro mailing list
> pro at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/pro
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/pro/attachments/20100922/c1cf2906/attachment.html>


More information about the pro mailing list