From: Jeff M.
Subject: Some macro character questions
Date: 
Message-ID: <cho0gr$6pe@odah37.prod.google.com>
Just wondering if anyone was able to help me construct a couple
character macros as a learning experience. I've tried each of these a
few times and can't seem to get anything to work right.

The first is a play off an older Lisp implementation I read about
(can't remember the name of the implementation, but I'm sure someone
here knows). It would be setting #\] to close all open lists:

(defun fac (n)
(if (<= n 1)
1
(* n (fac (1- n]

I don't know if this would be implementation-dependant. If so, I'm
using Lispworks. Any ideas would be appreciated on this one.

The other is a bit easier, and more of a test. I'd like to set #\[ to
begin a quoted list of symbols, so:

[a b c] => (a b c)

Instead of having to use '( ). There is no particular reason for this
other than to learn from doing it. I've made character macros for #/
... / (my regular expression macro reader) which works just fine, but
each of these involves using the reader to parse more instead of just
reading characters from the input stream.

With the list macro above, the closest I've come to is setting a macro
character for #\] to return a specific keyword like
:end-of-quoted-list. Then in the #\[ macro, just keep reading symbols
until :end-of-quoted-list is reached. I was hoping there would be a
more elegant solution.

Thanks for any help and advice. To be honest, I'd really appreciate
concepts and suggestions more than code, but anything is good ;)

Jeff

From: Peter Seibel
Subject: Re: Some macro character questions
Date: 
Message-ID: <m3acw0jpt4.fsf@javamonkey.com>
"Jeff M." <·······@gmail.com> writes:

> Just wondering if anyone was able to help me construct a couple
> character macros as a learning experience. I've tried each of these a
> few times and can't seem to get anything to work right.
>
> The first is a play off an older Lisp implementation I read about
> (can't remember the name of the implementation, but I'm sure someone
> here knows). It would be setting #\] to close all open lists:
>
> (defun fac (n)
> (if (<= n 1)
> 1
> (* n (fac (1- n]
>
> I don't know if this would be implementation-dependant. If so, I'm
> using Lispworks. Any ideas would be appreciated on this one.

Unless I'm missing something, to implement this you'll need to change
the reader macro associated with #\(. Which shouldn't be a problem but
I don't think there's anyway to do what you want just by defining a
reader macro for #\].

> The other is a bit easier, and more of a test. I'd like to set #\[
> to begin a quoted list of symbols, so:
>
> [a b c] => (a b c)
>
> Instead of having to use '( ). There is no particular reason for this
> other than to learn from doing it. I've made character macros for #/
> ... / (my regular expression macro reader) which works just fine, but
> each of these involves using the reader to parse more instead of just
> reading characters from the input stream.
>
> With the list macro above, the closest I've come to is setting a macro
> character for #\] to return a specific keyword like
> :end-of-quoted-list. Then in the #\[ macro, just keep reading symbols
> until :end-of-quoted-list is reached. I was hoping there would be a
> more elegant solution.

Do you know about READ-DELIMITED-LIST?

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Jeff
Subject: Re: Some macro character questions
Date: 
Message-ID: <V_M%c.160131$mD.57577@attbi_s02>
Peter Seibel wrote:

> "Jeff M." <·······@gmail.com> writes:
> 
> > The other is a bit easier, and more of a test. I'd like to set #\[
> > to begin a quoted list of symbols, so:
> > 
> > [a b c] => (a b c)
> > 
> 
> Do you know about READ-DELIMITED-LIST?
> 

Hehe, brilliant! Thank you very much.


-- 
Progress in computer technology is waiting for people to stop
re-inventing the wheel (often badly).
 - Dr. William Bland (comp.lang.lisp)
From: John Thingstad
Subject: Re: Some macro character questions
Date: 
Message-ID: <opsd05x0hfpqzri1@mjolner.upc.no>
On 8 Sep 2004 15:19:07 -0700, Jeff M. <·······@gmail.com> wrote:

Sounds to me like you could just use the emacs command C-]
(close-and-send-lisp) or (close-all-lisp)
which closes the parethesis for you.
(in ilisp not sure about SLIME)
Anyhow changing basic lisp syntax dosn't sound like a good idea.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Jeff
Subject: Re: Some macro character questions
Date: 
Message-ID: <4DM%c.160032$mD.28161@attbi_s02>
John Thingstad wrote:

> On 8 Sep 2004 15:19:07 -0700, Jeff M. <·······@gmail.com> wrote:
> 
> Sounds to me like you could just use the emacs command C-]
> (close-and-send-lisp) or (close-all-lisp)
> which closes the parethesis for you.
> (in ilisp not sure about SLIME)

I'm not using either, I'm using LispWorks for Win32 (stated in the
original post).

> Anyhow changing basic lisp syntax dosn't sound like a good idea.

Not to be rude, but this was precisely the kind of reply I was trying
to avoid getting. This is a *learning* exercise. For a more detailed
reason for why someone may actually want to do this, consider if I
needed to parse an existing file format that used [ ] and I wanted to
use the Lisp reader to do this?

Regardless, thank you for the reply.

Jeff
From: Pascal Costanza
Subject: Re: Some macro character questions
Date: 
Message-ID: <cho5ea$7mo$1@newsreader2.netcologne.de>
Jeff M. wrote:
> Just wondering if anyone was able to help me construct a couple
> character macros as a learning experience. I've tried each of these a
> few times and can't seem to get anything to work right.

CLtL2 has a number of examples that I have found very instructive. The 
only thing I have had to learn afterwards the hard way was that side 
effects inside a reader macro can really blow things up. ;)

Check out CLtL2 and see whether that helps you.

Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
From: Jeff
Subject: Re: Some macro character questions
Date: 
Message-ID: <F%M%c.60007$3l3.7124@attbi_s03>
Pascal Costanza wrote:

> 
> Jeff M. wrote:
> > Just wondering if anyone was able to help me construct a couple
> > character macros as a learning experience. I've tried each of these
> > a few times and can't seem to get anything to work right.
> 
> CLtL2 has a number of examples that I have found very instructive.
> The only thing I have had to learn afterwards the hard way was that
> side effects inside a reader macro can really blow things up. ;)
> 
> Check out CLtL2 and see whether that helps you.
> 

Thus far, most of my macro reader experience has been from the source
to Corman Lisp. I'll check out CLtL2, though, and see what I can find.
Thank you.

-- 
Progress in computer technology is waiting for people to stop
re-inventing the wheel (often badly).
 - Dr. William Bland (comp.lang.lisp)