What's better about Ruby than Python?

Andrew Dalke adalke at mindspring.com
Thu Aug 21 16:32:19 EDT 2003


Kenny Tilton:
> Can a Python first-class function close over a lexical variable and use
> that as a cache across multiple calls? That is another Lisp feature I am
> pressing into action.

My first example, before the correction by Alex, did that.  Idiomatic
Python prefers keeping state in a class rather than closures.

> Build it and they will come. Maybe if you used a macro-powered language
> and saw where macros improved code and they became second nature...

Maybe.  But look for previous posts of mine on c.l.py to see that
my previous attempts at learning Lisp have met dead ends.  I know
how it's supposed to work, but haven't been able to convert what
I see on a page into something in my head.

Same problem with I was studying algebra.  I just couldn't turn what
I saw on paper into something I could think about, while for analysis
I had no problem visualizing limits and epsilons.

> > The code caches the result of calling a given function, which could
> > compute 3 or could compute bessel functions or could compute
> > anything else.   I don't see how that's any different than what your
> > code does.
>
> Because I do not have to set anything up like you did with the class and
> the cache and the slot and the call to cacheCall. And if I did, a single
> form such as:
>
>     (defmemoized count (n) (* 2 n))
>
> ...would suffice. In my case I can even inline, since I am immediately
> dumping the outcome into an instance's slot where cooperating code
> (written by the defmodel macro) makes it work.

But I only need to define my class once, put it in a module, and
important it when needed for any code which needs it.

And while I can write code in-line (as with list comprehensions and
sets and other newer capabilities of Python), I can't read it.  My
mind likes thinking about little (espsilon sized?) chunks at time.
Hence, "Python fits my brain."

> But my hack gets used hundreds of times
> throughout a sizeable app. I dash them off inline without missing a
> beat, and when I change C? they all keep working.

"dash them off" means reimplementing it?

> The key thing about being there at compile
> time is that my code can write code for me, driven by the very small
> amount of code that varies from case to case. That makes my code more
> readable than yours, because you are cutting and pasting all that
> implementing cruft over and over again and the varying essence does not
> stand out so well.

Again, where's the cut&paste?  I define it one, put it in a
module, and reuse it anywhere appropriate.

BTW, I'm afraid I'm about at the end of my limits for this thread.
I'll only be able to do small followups.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list