Re: Sequences other than list and vector
From: james anderson (james.anderson_at_setf.de)
Date: 11/26/03
- Next message: james anderson: "Re: CLOS and C++"
- Previous message: Lars Brinkhoff: "Re: CLOS and C++"
- In reply to: Lars Brinkhoff: "Re: Sequences other than list and vector"
- Next in thread: Erann Gat: "Re: Sequences other than list and vector"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 Nov 2003 14:13:55 +0100
Lars Brinkhoff wrote:
>
> ...
>
> I can't see anything about whether the result form should be inside or
> outside the implicit tagbody.
>
> --
> Lars Brinkhoff, Services for Unix, Linux, GCC, HTTP
> Brinkhoff Consulting http://www.brinkhoff.se/
Kent M Pitman wrote:
>
> "Steven E. Harris" <seharris@raytheon.com> writes:
>
> > tfb@famine.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
> >
> > > (defmacro dosequence ((var sequence &optional result) &body forms)
> > > `(block nil
> > > (map nil (lambda (,var) ,@forms) ,sequence)
> > > ,@(when result (list `(let ((,var nil)) ,result)))))
> >
> > Why does var have to be set to nil before evaluating the result form?
>
> What would you set it to? The form is to evaluate in the scope of var,
> if you're going to make it symmetric with, for example, DOLIST. From
> CLHS's DOLIST dictionary entry:
>
> The scope of the binding of var does not include the list-form,
> but the result-form is included.
>
> and the only other really obvious choice of a value is:
>
> (defmacro dosequence ((var sequence &optional result) &body forms)
> (let ((temp (gensym)))
> `(block nil
> (let ((,var nil))
> (map nil #'(lambda (,temp)
> (setq ,var ,temp)
> ,@forms)
> ,sequence)
+ (setf ,var nil)
> ,@(when result `(,result))))))
>
> I'm not sure I really like this better, since (ignoring even the issue of
> the presence of the SETQ) var is then bound to something relatively random.
> Making it a boring value like NIL discourages the use of it for any purpose,
> (since NIL already has a name if it's needed), and that's all to the good.
wouldn't this be preferred to the decimated bindings of the original example
in order to better parallel the behaviour of do &company? the spec does say
"the binding". the tagbody question remains, however, a riddle. i can imagine
ways to formulate expansions such that one could transfer into the body, but
i'm at a loss as to how to arrange that one could transfer into the "single
form" which constitutes the result form. which argues against an intention
that it be included in the tagbody.
(defmacro dosequence ((var sequence &optional result) &body forms)
(let ((end-p (gensym))
(fun (gensym)))
`(block nil
(flet ((,fun (,var ,end-p)
(tagbody
(when ,end-p (go ,end-p))
,@forms
(return-from ,fun nil)
,end-p
(return-from ,fun ,result))))
(map nil #'(lambda (element) (,fun element nil))
,sequence)
,@(when result `((,fun nil t)))))))
...
- Next message: james anderson: "Re: CLOS and C++"
- Previous message: Lars Brinkhoff: "Re: CLOS and C++"
- In reply to: Lars Brinkhoff: "Re: Sequences other than list and vector"
- Next in thread: Erann Gat: "Re: Sequences other than list and vector"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|