Re: Aha! moments
- From: "K.S.Sreeram" <kssreeram@xxxxxxxxx>
- Date: 27 Sep 2006 18:04:22 -0700
Zach Beane wrote:
What are some of the things that triggered your own Aha! moments? What
sort of stuff delighted you when you discovered it? What advice would
you give people who want to have more Aha! moments?
I guess "code is data" is the most basic lisp aha! But its implications
continue to be sources for many more such aha moments.
For instance, in most other programming languages, new abstractions are
built by writing code on /top/ of existing abstractions. But in lisp,
its possible to build new abstractions by writing code *beneath*
existing code.
Here's an example (in scheme):
(define (square x) (* x x))
(define (power x n)
(cond ((= n 0) 1)
((odd? n) (* x (power x (- n 1))))
(else (square (power x (/ n 2))))))
This is a simple function which raises x to the integer power n, with a
minimum number of multiplications. (let ((x 5)) (power x 3)) returns
125.
Now its possible to make the same piece of code return optimized
symbolic output by just writing a new implementation of '*' !
(power 'x 3) -> (* x (* x x))
See the original article by Darius Bacon for the details:
http://cybertiggyr.com/gene/peval/peval.cgi
[sreeram;]
.
- References:
- Aha! moments
- From: Zach Beane
- Aha! moments
- Prev by Date: Deploying application with SBCL, ASDF
- Next by Date: Re: (read-from-string "#.(values) 42")
- Previous by thread: Re: Aha! moments
- Next by thread: Re: Aha! moments
- Index(es):
Relevant Pages
|