Re: Question: Tokenizing CDATA attribute values

Subject: Re: Question: Tokenizing CDATA attribute values
From: Paul Prescod <papresco@xxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 16 Jun 1997 14:40:28 -0400
W. Eliot Kimber wrote:
> Thanks for the functions--I'll put them to use right away.
> 
> While we're on the subject, can someone provide (or point me to) a brief
> tutorial on the distinction between a simple define, "let" procedures, and
> "lambda" procedures?  

Not much. It is mostly syntactic sugar. 

define is global, and there happens to be a nice short-cut syntax:

(define (doit) (foo))

is defined in the standard to be the same as

(define doit (lambda () (foo)))

So define isn't really a special procedure definition tool, and lambda
is hiding right under the covers.

The "named let" that David used is also defined in terms of "ordinary"
(lambda) procedures:

"Some implementations of Scheme permit a variant on the syntax of let
called "named" let which provides a more general looping construct than
do, and may also be used to express recursions. 
Named let has the same syntax and semantics as ordinary let except that
"variable" is bound within "body" to a procedure whose formal arguments
are the bound variables and whose body is "body". Thus the execution of
"body" may be repeated by invoking the procedure named by "variable". 

(let loop ((numbers '(3 -2 1 6 -5))
           (nonneg '())
           (neg '()))
  (cond ((null? numbers) (list nonneg neg))
        ((>= (car numbers) 0)
         (loop (cdr numbers)
               (cons (car numbers) nonneg)
               neg))
        ((< (car numbers) 0)
         (loop (cdr numbers)
               nonneg
               (cons (car numbers) neg))))) 
  Þ  ((6 1 3) (-5 -2))
"

This may sound very complex but it is really just a way of making
recursion look like iteration. The variables bound at the top get new
values from the function calls at the bottom. It is analgous to
assigning to them. When you get to the "bottom" of the recursion, you
return the accumulated value.

 Paul Prescod

 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread