Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Is there a trick so macrolet can't refer to itself?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pascal Costanza  
View profile  
 More options Aug 18 2006, 8:58 am
Newsgroups: comp.lang.lisp
From: Pascal Costanza <p...@p-cos.net>
Date: Fri, 18 Aug 2006 14:58:38 +0200
Local: Fri, Aug 18 2006 8:58 am
Subject: Re: Is there a trick so macrolet can't refer to itself?

howard yeh wrote:
> (let ((foo 'bar))
>   (symbol-macrolet ((foo (list foo)))
>     foo))

> Leads to infinite regression. Is there a trick I can use so the above
> is equivalent to:

> (let ((foo 'bar))
>   (list foo))

No, essentially the outer 'foo must have a different name. You can use a
workaround, though:

(let ((-foo- 'bar)) ;; or some generated name
   (symbol-macrolet ((foo -foo-))
     ...
     (symbol-macrolet ((foo (list -foo-)))
       foo)))

> The reason for this is that I am modifying Henry Baker's parser as
> described in: http://home.pipeline.com/~hbaker1/Prag-Parse.html

> I want to be able to generate the same code, but depending on the
> surrounding macros, can behave differently.

> So a fragment like

> (and ...
>  (when (and (< index end)
>       (eql (char string index) ',x))
>   (incf index)
>   ...))

> Becomes

> (symbol-macrolet ((this (char string index)))
>   (macrolet ((end? () '(< index end))
>         (next () '(incf index)))
>     (and ...
>     (when (and (end?)
>                (eql this ',x))
>       (next))
>     ...)))

> If I want to parse sexp instead,

> (symbol-macrolet ((this (car index)))
>   (macrolet ((end? () '(null index))
>         (next () '(pop index)))
>     (and ...
>     (when (and (end?)
>                (eql this ',x))
>       (next))
>     ...)))

> Do you guys think this is a good use of abstraction? Or do macrolets
> obscure too much?

Two responses:

a) The problem above doesn't seem to occur here.

b) It's probably better to model this with functions or even with
generic functions because this would be easier to debug, and it's
unlikely that you get too much runtime overhead. In general, use macros
only when functional abstractions don't work, but only for syntactic
abstractions.

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/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.