[Oc-pm] Meeting Notes

Pete Wilson peter.t.wilson at gmail.com
Fri May 25 14:47:03 PDT 2007


Hi all,

It is true that the only way to bind function arguments to lexically
scoped variables in Perl is to use the "=" operator.  But, I just used
assignment to bind function arguments to lexical variable.  No
changing a variables value in a given scope/environment once it is
set.

My rationalization for this actually comes from previous experience
with C++.  C++ uses the "=" operator for both assignment and
initialization.  For example, "int I = 0;" is considered an
initialization statement where as "I = 1;" is considered an assignment
statement.  This doesn't map 1 to 1 with what I did in perl.  I'm not
doing initialization I'm binding lexicaly scoped function arguments,
but all the assignments I do in my Y combinator implementation are to
variables immediately preceded by "my".

What I currently have is a derivation of the Y combinator using the
factorial function as an example recursive function.  The Perl file is
currently about 200 lines; although the final combinator it's self is
only 11 lines.   I'm currently tweaking it to make sure I understand
what I did.  I will try to post what I have in about half an hour.

-Pete

On 5/25/07, Ben Tilly <btilly at gmail.com> wrote:
> On 5/25/07, Mark D. Nagel <mnagel at willingminds.com> wrote:
> > Ben Tilly wrote:
> > > You can't really do the Y Combinator in Perl because one of the key
> > > points of the combinator is that you should not need any form of
> > > assignment, and Perl can't process function arguments without using
> > > assignment.
> >
> > I'm not familiar with all the details on this one, but is the problem
> > that when you use function arguments without assignment that they are
> > passed by reference?  Because I know you can process arguments without
> > assignment as long as they are not altered (unless that is the intent)
> > and you don't mind line noise :).
>
> Passed by reference is not the problem.  Dynamic scoping is.
>
> To make the Y Combinator work you need to use currying, and currying
> requires lexically scoped variables.  Currying is turning things like
>
>   F = function (i, j) {
>     ...
>   };
>   F(i,j);
>
> into things like
>
>   F = function (i) { return function (j) {
>     ...
>   }};
>   F(i)(j);
>
> but that only works if the anonymous function returned by the second
> version of F actually has i lexically scoped.
>
> Cheers,
> Ben
> _______________________________________________
> Oc-pm mailing list
> Oc-pm at pm.org
> http://mail.pm.org/mailman/listinfo/oc-pm
>


More information about the Oc-pm mailing list