Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re (tilly) 1: Lisp is More Evaluatable

by hding (Chaplain)
on May 24, 2001 at 18:21 UTC ( [id://82913]=note: print w/replies, xml ) Need Help??


in reply to Re (tilly) 1: Lisp is More Evaluatable
in thread Lisp is More Evaluatable

It's really not bad style to write code with side effects (depending, I suppose, on your precise definition thereof). Of course, it's (usually) bad style to write code with random, unpredictable, or unclear side effects, just as in any language. But look in any well-regarded Lisp book like Norvig or one of Graham's and you'll see side effects, setfs, etc. It'd be hard to use CLOS, for example, without them. If one's intent is to use primarily the functional features of Lisp, then I guess I agree, but in practice, one uses the imperative and OO features just as much, it seems.

You're spot on about eval, though.

Oh, one other thing. For the code to do what (I guess) is actually desired, one needs to quote the form to be evaled:

(setq closure '(setq z (+ 2 2))) (eval closure) ;;; works

As originally written, both closure and z would be set to 4, and the eval form would simply eval 4 to get 4

Replies are listed 'Best First'.
Re (tilly) 3: Lisp is More Evaluatable
by tilly (Archbishop) on May 24, 2001 at 18:34 UTC
    Perhaps "bad style" is too strongly put.

    But it is certainly considered good style to avoid side-effects. And the advice of thinking of setq as having a penalty associated is straight from On Lisp by Graham. It is not a religious rule. But it is worth thinking about. In fact I think about it in Perl as well, though I am not as extreme because Perl cannot optimize tail recursion.

    As for the other point, perhaps I was unclearly verbose. But that is exactly what I was getting at with the phrase "...should no longer affect the value of z."

      Probably we more or less agree, but have different ways of expressing what we mean. Graham is good, but I think it's dangerous to rely too much on what he says. Just as an example, he seems to have a disdain for the loop macro that just isn't shared by the community at large, and if unduly under his influence one might neglect to use it even in situations where it's clearly the easiest and best solution. But (like Perl) there's room enough in Lisp for everyone, at least IMHO. :-)

      One should be careful about relying on tail recursion being optimized in Common Lisp, too. The spec doesn't require it (unlike Scheme which does). I think most implementations will do it under certain but not all circumstances. For example, in the one I use, you need to have debug set below 3 in the code to be compiled. I don't have a good enough sense of history to speculate whether this is because of or the cause of Common Lispers being a lot more willing to iterate than Schemers.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://82913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-07-17 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.