Re: how to define a local function



szergling wrote:

RANT

Common Lispers just like to show the classic delay and force macro, as
if delayed evaluation is a fait accompli. They usually quote some
variant of the 'On Lisp' example...

(defconstant unforced (gensym))
(defstruct delay forced closure)
(defmacro delay (expr)
(let ((self (gensym)))
`(let ((,self (make-delay :forced unforced)))
(setf (delay-closure ,self)
#'(lambda ()
(setf (delay-forced ,self) ,expr)))
,self)))
(defun force (x)
(if (delay-p x)
(if (eq (delay-forced x) unforced)
(funcall (delay-closure x))
(delay-forced x))
x))

It doesn't see to me that delay and force are too useful. They are typically just used to illustrate what macros can do. For practical purposes, I don't think they are very practical. ;) (Even R6RS Scheme drops them.)

But it is not quite enough, as there's a lot of work to do
still. Typically, one needs to go through all Common Lisp functions,
and rewrite them as *macros*. Otherwise, there's no way to delay
evaluation in standard funcall (so much for first class
functions).

No, going through all functions and turning them into delaying ones doesn't do the job. You need a distinction between what functions you consider to be primitives and what functions you want to be implicitly delaying. The "primitive" functions would be the implicitly forcing ones. (If no function implicitly forces delayed computation, your programs would never ever compute anything. ;)

Because that distinction is important, I think that in practice, it's more likely that people tend to use domain-specific variations of lazy evaluation.

BTW, it's a nice CLOS MOP exercise to come up with generic function classes for implicitly delaying and forcing generic functions.


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.



Relevant Pages

  • Re: how to define a local function
    ... I have not really gained much on top of reader macros, ... Common Lispers just like to show the classic delay and force macro, ... (if (delay-p x) ... Typically, one needs to go through all Common Lisp functions, ...
    (comp.lang.lisp)
  • Re: SCIP problem 3.5.* can`t pass Drscheme 2.9?
    ... (define (delay exp) ... But the problem comes,the function didnot delayed evaluation, ... As a data abstraction, streams are the ...
    (comp.lang.scheme)
  • Re: Staging Question
    ... Yes, I've noticed that we have a lot in common, Nick. ... Have you ever tried using time alignment to add delay to the RIGHT ... of TA because whenever I added delay to the left speakers I could never seem ... Everyone please feel free to technical "blah blah blah" me to death about ...
    (rec.audio.car)
  • Re: how to define a local function
    ... typically just used to illustrate what macros can do. ... If you want to delay arguments to a function, ... In Common Lisp, you have to use macros for that. ... what you can do with the CLOS MOP is to create a function class that delays its execution. ...
    (comp.lang.lisp)
  • Re: Firescrolling [Firefox 1.0]
    ... >can be hidden by common tasks... ... >Upgrade to Firefox 1.0.1 or disable javascript. ... Mozilla has apparently decided to delay, to the detriment of its users, the ... there ASAP via the auto-update feature. ...
    (NT-Bugtraq)