Lisp HUG Maillist Archive

reader macro function -> constituant character

Hello,

What would be the definition of a reader macro function for 
character that just returns the character as a normal constituant 
character? In the example below, I want '{abc to still evaluate to {ABC


CL-USER 10 > (get-macro-character #\{)
NIL
NIL

CL-USER 11 > '{abc
{ABC

CL-USER 12 > (set-macro-character #\{ (lambda (stream char) char))
T

CL-USER 13 > '{
#\{

CL-USER 14 > abc

Error: The variable ABC is unbound.



Francis


Re: reader macro function -> constituant character

Unable to parse email body. Email id is 6988

Re: reader macro function -> constituant character

Francis Leboutte wrote:

> What would be the definition of a reader macro function for
> character that just returns the character as a normal constituant
> character? In the example below, I want '{abc to still evaluate to {ABC
>
>
> CL-USER 10 > (get-macro-character #\{)
> NIL
> NIL
>
> CL-USER 11 > '{abc
> {ABC
>
> CL-USER 12 > (set-macro-character #\{ (lambda (stream char) char))
> T

I think that adding a call to SET-SYNTAX-FROM-CHAR, e.g.

   (set-syntax-from-char #\{ #\A)

should do what you need.


Arthur Lemmens


Re: reader macro function -> constituant character

Le 25/09/2007 11:10, Nick Levine écrivait :
>    What would be the definition of a reader macro function for
>    character that just returns the character as a normal constituant
>    character? In the example below, I want '{abc to still evaluate to
>    {ABC
>
>Careful. I don't think you really mean "evaluate". "Read as", maybe?

This is what I mean:
USER 8 > '{ab
{ab
USER 9 > '{
{

>So ignoring (which you shouldn't) what happens if the #\{ is not
>followed by a symbol, or how you'd get to a symbol not visible in
>*package*, consider:
>
>(lambda (stream char) (intern (format nil "~c~a" char (read stream t nil t))))

This looks promising. But see my next post.
Thanks,
Francis


>- nick
>
>
>    CL-USER 10 > (get-macro-character #\{)
>    NIL
>    NIL
>
>    CL-USER 11 > '{abc
>    {ABC
>
>    CL-USER 12 > (set-macro-character #\{ (lambda (stream char) char))
>    T
>
>    CL-USER 13 > '{
>    #\{
>
>    CL-USER 14 > abc
>
>    Error: The variable ABC is unbound.
>
>
>
>    Francis


Re: reader macro function -> constituant character

Le 25/09/2007 11:20, Arthur Lemmens écrivait :
>Francis Leboutte wrote:
>
> > What would be the definition of a reader macro function for
> > character that just returns the character as a normal constituant
> > character? In the example below, I want '{abc to still evaluate to {ABC
> >
> >
> > CL-USER 10 > (get-macro-character #\{)
> > NIL
> > NIL
> >
> > CL-USER 11 > '{abc
> > {ABC
> >
> > CL-USER 12 > (set-macro-character #\{ (lambda (stream char) char))
> > T
>
>I think that adding a call to SET-SYNTAX-FROM-CHAR, e.g.
>
>    (set-syntax-from-char #\{ #\A)
>
>should do what you need.

I want to write something a bit more dynamic like this:

(set-macro-character
        #\{
        (lambda (stream char)
          (cond (*rm-fun (funcall *rm-fun stream char))
                (T
                 ;; takes char as a constituant character
                 ...
                 ))))


In a Lisp implementation where a constituant 
character would have a reader macro function, the answer would be simple:

(set-macro-character
        #\{
        (lambda (stream char)
          (cond (*rm-fun (funcall *rm-fun stream char))
                (T
                 (funcall (get-macro-character #\a) stream char)
                 ))))


Francis

>Arthur Lemmens


Updated at: 2020-12-10 08:45 UTC