Re: Next Generation of Language
- From: rem642b@xxxxxxxxx (Robert Maas, see http://tinyurl.com/uh3t)
- Date: Fri, 09 Nov 2007 16:52:25 -0800
From: wv9...@xxxxxxxxx
I don't think there is anything more anti parallelism like Lisp. Lisp
is recursive, a function has to basically wait for another instance of
itself to finish before continuing. Where is the parallelism?
OK, consider the most trivial recursive-definition example, factorial:
I you use non-branching recursion merely to emulate iteration,
that's stupid, requiring tail-recursion optimization to avoid stack
overflow. But if you divide-and-conquer, the parallelism is obvious:
(defun lo+hi-product (lo hi)
"Computes product lo * (lo+1) * (lo+2) ... up to but not including hi"
(if (>= (+ 1 lo) hi)
lo
(let ((mid (ceiling (+ lo hi) 2)))
(* (lo+hi-product lo mid)
(lo+hi-product mid hi)))))
;(lo+hi-product 2 3) ==> 2
;(lo+hi-product 1 6) ==> 120
;Caveat: The above code works correctly only when lo is an integer.
;A slight change in the logic would be needed to handle products such
; as 1.3 * 2.3 * 3.3 * 4.3 etc., left as exercise to newbies/students.
(defun factorial (n)
(lo+hi-product 1 (+ 1 n)))
;(factorial 5) ==> 120
In general, recursive algorithms are more divide-and-conquer rather
than emulation of iteration. IMO It's unfortunate that the
really-iterative definition of factorial is usually given as the
first example of "recursion" in schools.
<mathCliche>In general, it helps to solve a more general problem
than the one given. The more general problem is often actually
easier to understand than the given special case.</mathCliche>
In this case, generalizing 1*2*3*... to LO*(LO+1)*(LO+2)*...
make it more obvious how to divide-and-conquer.
.
- Prev by Date: Re: We are happy to announce: our first Lisp production system went online
- Next by Date: Starting up Slime
- Previous by thread: Re: Next Generation of Language
- Next by thread: Re: Next Generation of Language
- Index(es):
Relevant Pages
|