Log in

No account? Create an account
Lindsey Kuper [entries|archive|friends|userinfo]
Lindsey Kuper

[ website | composition.al ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

I'm a little rusty. [Nov. 4th, 2007|04:54 am]
Lindsey Kuper

Just now, I very nearly emailed Mr. Stone to ask, "Can you think of any way to put a recursively defined function in a let-expression in Scheme? Gosh, it would be so magical if something like that were possible! Gee whiz!"

Good thing I looked it up. letrec. Duh.

I've been usin' Perl for too long, my friends.


[User Picture]From: jes5199
2007-11-04 05:53 pm (UTC)
is that a Y Combinator?
(Reply) (Thread)
From: (Anonymous)
2007-11-04 09:06 pm (UTC)
You bet!

(Actually, it's a 'fancy' Y-combinator that also allows for mutual recursion, but I think Scheme optimises it down to a regular Y-comb if it sees you're just doing single recursion.)
(Reply) (Parent) (Thread)
[User Picture]From: lindseykuper
2007-11-05 07:02 am (UTC)

I've been trying for two hours to figure out how to answer this question, and I still don't know how. But I managed to write sum in terms of the Y-combinator:

; Namelessly add 2 + 2
(((lambda (X)
    ((lambda (proc)
       (X (lambda (arg) ((proc proc) arg))))
     (lambda (proc)
       (X (lambda (arg) ((proc proc) arg)))))) (lambda (func)
                                                 (lambda (ls)
                                                   (if (null? ls)
                                                       (+ (car ls) (func (cdr ls))))))) '(2 2))

Hoo-ah. I, uh, don't think I'm going to attempt to unsugar the code that's using the letrec. (I can't show it to you yet. It's a secret.)

(Reply) (Parent) (Thread)
[User Picture]From: the_flea_king
2007-11-05 12:33 am (UTC)
Does he not like to be called Dr. Stone?
(Reply) (Thread)
[User Picture]From: lindseykuper
2007-11-05 12:40 am (UTC)
I got into the habit of calling the CS professors "Mr." and "Ms." because they've been listed as such on the departmental website for as long as I can remember.
(Reply) (Parent) (Thread)