help with macro characters

OpenLisp features, requests and ideas

help with macro characters

Postby lewis » Tue Oct 18, 2005 1:05 am

Christian Jullien,

I wonder if you could help me by answering a couple of
questions about your OpenLisp interpreter?

I have some Scheme code that I wanted to run under ISlisp
and I have already made it work under Common Lisp using
some macros. When I tried to do the same under ISlisp I
ran in to problems. Here are my questions.

I wish to modify the reader in order to use '#t'
and '#f' for true and false. In common lisp I used,
Code: Select all
;;;
(set-dispatch-macro-character #\# #\T
                              #'(lambda (stream subchar arg)
                                  t))

This works fine in Common Lisp but 'set-dispatch-macro-character'
is undefined in your ISlisp implementation.
So I tried instead to use 'set-macro-character' and used,

Code: Select all
;;;
(defvar default-dispatcher (get-macro-character #\#))
;
(defun bool-dispatcher (stream char)
          (case (preview-char stream)      ; ISlisp
;          (case (peek-char nil stream)      ; Clisp
              ((#\t #\T) (read-char stream) t)
              ((#\f #\F) (read-char stream) nil)
              (t      (funcall default-dispatcher stream char))))
;
(set-macro-character #\# #'bool-dispatcher)

Again this works fine in Common Lisp *but* apparently
'(get-macro-character #\#)' returns 'nil' in your ISlisp
whereas it should return the default dispatcher function
and so although '#t' and '#f' are OK, all other uses of '#' now fail.
Surely this is not correct since '#' is operating as a
macro character in, for example, '#\a and others.
How can I implement the desired behaviour using your
ISlisp interpreter?

Thanks for your help,

Stephen Lewis
lewis
 

Re: help with macro characters

Postby jullien » Tue Oct 18, 2005 5:39 am

lewis wrote: ... but 'set-dispatch-macro-character'
is undefined in your ISlisp implementation.


Yes, you're right. I'm afraid that '#' is hard wired as dispatch-macro-character in OpenLisp reader.

What about?
Code: Select all
(defglobal *scheme-rt* (copy-readtable nil))
(set-syntax-from-char #\# #\A *scheme-rt* *scheme-rt*)
(defglobal #t t)
(defglobal #nil nil)


Of course all # dispatch functions are lost.

To support your code, I have to add set-dispatch-macro character.
On what system are you running?

Christian
jullien
Site Admin
 
Posts: 30
Joined: Fri Nov 12, 2004 12:29 am

Postby Guest » Wed Oct 19, 2005 10:12 pm

Christien,

Thanks for your reply, unfortunately it does not help me enough to
get my code to work.

Re your posted fragment:

(defglobal *scheme-rt* (copy-readtable nil))
; makes a copy of *readtable*
(set-syntax-from-char #\# #\A *scheme-rt* *scheme-rt*)
; sets syntax-char '# in the copied table to syntax of 'A in copied table
; but this does not alter the current *readtable* unless you also intended
; to '(setf (dynamic *readtable*) *scheme-rt*)' otherwise following lines
; do not work...
(defglobal #t t)
(defglobal #nil nil)

But why make a copy? why not simply:

(set-syntax-from-char #\# #\A) ; sets current table from current table
(defglobal #t t)
(defglobal #nil nil)

Perhaps you were thinking of restoring the default table later?
However I find that:

(setf (dynamic *readtable*) (copy-readtable nil))

makes an empty *readtable* and not a _standard_ readtable as one might expect.
In particular macro characters \', \, and \@ go away. Surely standard
ISlisp should have those implemented?
Since the rest of my program uses most standard features of lisp
I need '#t *and* the default macro characters including \#, \`, \, and \,@.

I don't actually need you to implement (set-dispatch-macro-character ...)
although that would be good, all I need is a way to call the internal
function which processes the stream after \# is read, then I could call
it directly after I deal with '#t and '#f.
If the location of this function was returned by the call:

(get-macro-character #\#) ; which for some reason returns 'nil

as it is in Common Lisp then all would be well.

Stephen Lewis
Guest
 

Postby Guest » Wed Oct 19, 2005 10:24 pm

Christian,

I have access to your interpreter via 'sdf.org' but would like to
have a local copy.

I am running a fairly current version of Linux (2.6 kernel and gcc 3.3)
on a DEC Alpha Personal Workstation (PWS 500au).
I downloaded 'openlisp-8.1.0-Linux-alpha.tar.gz' and installed it.
It seems to link OK:

> ldd uxlisp
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x0000020000044000)
libdl.so.2.1 => /lib/libdl.so.2.1 (0x000002000006c000)
libm.so.6.1 => /lib/tls/libm.so.6.1 (0x0000020000080000)
libc.so.6.1 => /lib/tls/libc.so.6.1 (0x0000020000108000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x0000020000000000)
but when I try and run it I get an illegal instruction trap:

> ./uxlisp
Illegal instruction

Possibly because it was compiled for a different CPU? I have an EV56.
Since I have compiled Common Lisp and four flavors of Scheme I have
little doubt that it would compile on my machine but I do not have
access to the source code.

I also have a PowerPC G4 running YellowDogLinux 2.0 so I tried downloading
'openlisp-8.1.0-Linux-ppc.tar.gz' and installed it. Unfortunately
that does not link and I get this message:

> ldd ./uxlisp
/usr/local/openlisp-8.1.0/uxlisp: /lib/libc.so.6: version `GLIBC_2.3' not
found (required by /usr/local/openlisp-8.1.0/uxlisp)
libpthread.so.0 => /lib/libpthread.so.0 (0x0ffc9000)
libdl.so.2 => /lib/libdl.so.2 (0x0ffa6000)
libm.so.6 => /lib/libm.so.6 (0x0ff58000)
libc.so.6 => /lib/libc.so.6 (0x0fe13000)
/lib/ld.so.1 => /lib/ld.so.1 (0x30000000)

I have glibc 2.2 and again I feel sure it would compile but the binary
is not useful to me,

Stephen Lewis
(apologies for mis-spelling your name and my lousy formatting
on this bboard)
Guest
 

Postby jullien » Wed Oct 19, 2005 10:33 pm

Anonymous wrote:Christian,

I have access to your interpreter via 'sdf.org' but would like to
have a local copy.


Ask me by email
jullien
Site Admin
 
Posts: 30
Joined: Fri Nov 12, 2004 12:29 am


Return to Request

Who is online

Users browsing this forum: No registered users and 1 guest

cron