For Programmers: Free Programming Magazines  


Home > Archive > Scheme > August 2007 > I'm turning into one heck of a lisper (was: Computationally arrive at index of list-r









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author I'm turning into one heck of a lisper (was: Computationally arrive at index of list-r
Joel J. Adamson

2007-08-16, 10:15 pm

Pascal Bourguignon <pjb@informatimago.com> writes:

> Anand Hariharan <mailto.anand.hariharan@gmail.com> writes:
>
> But you can do similarly in scheme with named lets:
>
> (let loop ((max (ceiling (expt (length (part:entities)) (/ 1 3))))
> (r 0)

[snip]
> And I'd bet there's half an implementation of the Common Lisp LOOP
> macro in scheme somewhere...


Pascal, reading your code (and much more of any kind of Lisp) makes a
lot more sense now:

Last night I'm sittin' there thinking "How do I multiply each element
of this list by 2...I know there's a procedure called map..." and
tried it a bunch of times just using

(map * 2 '(insert your favorite list here))

Which of course makes no sense, but then I realized the second
argument must be a procedure: so I *wrote a procedure* and stuck it in
there.

(map (lambda (x) (* 2 x)) '(8 6 7 5 3 0 9))

A-ha! I finally realized that lambda is really a SYMBOL! A symbolic
representation of a procedure -- yet again lexical scoping only makes
sense here since the symbols must have meaning *as symbols*. This is
about my twelfth light-bulb moment in studying Scheme, I'm well on my
way to completing my "afternoon of study."

[now, is there a simpler way to do the multiplication above? This
makes so much sense to my mathematical mind that it feels really
friggin' simple already, even though it would have looked complicated
to me 24 hours ago]

Joel

--
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA 02114
(617) 643-1432
(303) 880-3109

"It can be interesting to study ancient philosophy, but more as a kind
of accident report than to teach you anything useful."
--Paul Graham
http://www.paulgraham.com/raq.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com