Re: Aha! moments



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;]

.



Relevant Pages

  • Aha! moments
    ... Here are a few things that triggered major Aha! ... moments for me, in no ... reading the source of cl-ppcre, ... bits on disk or on a wire or sometimes even in memory, and Lisp ...
    (comp.lang.lisp)
  • Re: Aha! moments
    ... What are some of the things that triggered your own Aha! ... sort of stuff delighted you when you discovered it? ... incremental programming with SLIME ...
    (comp.lang.lisp)
  • Re: Aha! moments
    ... What are some of the things that triggered your own Aha! ... functions and recompile on the spot while I was in the debugger. ... Also, discovering kill-sexp.. ...
    (comp.lang.lisp)
  • Re: Any advice on planning?
    ... which can be witty in ways that those ... boring old numbers aren't.... ... And which depend much more on Aha! ... moments and much less on ...
    (rec.arts.sf.composition)
  • Re: Aha! moments
    ... What advice would ... you give people who want to have more Aha! ... Rahul Jain ...
    (comp.lang.lisp)