guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gurus? Care to re-explain the absense of gh_set_x() for me?


From: Alex Shinn
Subject: Re: Gurus? Care to re-explain the absense of gh_set_x() for me?
Date: 14 Jul 2001 11:35:05 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.103

>>>>> "Ralf" == rm  <address@hidden> writes:

    Ralf> On Fri, Jul 13, 2001 at 03:11:35PM -0400, Alex Shinn wrote:
    >>  And considering the most common alternatives (C, Java), Perl
    >> is very close to Scheme.  Much closer than Python, which
    >> doesn't support proper lambda expressions, and until 2.0 didn't
    >> have closures.

    Ralf> Hmm, what do you consider "proper lambda" expressions? For
    Ralf> anyone interessted in python functional programming, have a
    Ralf> look at
    Ralf> http://www-106.ibm.com/developerworks/library/l-prog.html.

Well, the closures are certainly necessary for this.  Python 1.x only
had two scopes, local and global, which seriously limits the utility
of lambda expressions.  While this has been fixed in Python 2.0,
lambda expressions still have to consist of a single line (I guess a
result of the ambiguity that would arise if you had to indent a lambda
expression within another expression).  So you have to use Python
2.0's new list comprehensions (as shown in the link you gave), to
achieve any sort of non-trivial control flow in a lambda expression.
It can be difficult to express things this way, and tends to destroy
the nice formatting and readability of your Python code (where the
white-space as block structure suddenly has the opposite of it's
intended purpose).

Perl's lambda expressions, on the other hand, are identical to normal
Perl functions.  So wherever you have

  sub foo { ... }

you can also have[1]

  $foo = sub { ... }

Perl also gives you more control over the syntax of Perl itself,
letting you define functions to act on code blocks.  The code blocks
are passed to the function unevaluated, so this gives you a limited
type of special form.  Thus the standard Perl error handling expressed
with try/catch syntax is actually not a primitive but written in Perl
itself[2].  This is a very Schemey thing to do.

Finally, it may be useful[3] to dynamically generate functions that do
not fit a pre-defined lambda form.  This is not very hard in Scheme
(and in fact a simple macro may often do what you want), but in Perl
you need to construct and eval the string by hand.  I'm not saying
this is something you'd want to do all the time in Perl, but it's
certainly possible, and *much* more feasible than trying to do the
same in Python, where you actually have to take indentation into
consideration when constructing your function.


Footnotes: 
[1]  Unless foo is recursive, in which case you need the Y-combinator.

[2]  I think... it certainly could be.

[3]  We do this in the application I'm currently working on.


-- 
Alex Shinn <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]