However talk has symbols which end in ':' and behave like a
keyword -> evaluate to themeselves.
Can anyone suggest a quick method of allowing this to be
read in? CL thinks the lhs of the colon refers to a package....
I've read the documentation on readtables and macro-dispatch
but couldnt get it working.
i.e I have code which looks like
(define-cpp-function ...... super: ......)
^^^^^^
it is these keywords which cause the problem?
Any suggestions appreciated...
Thanks
Jon
ouch. been there, suffered that.
| Can anyone suggest a quick method of allowing this to be read in? CL
| thinks the lhs of the colon refers to a package....
quick? maybe. dirty? oh, yes. :)
first, you make #\: a terminating macro character that returns a unique
symbol, instead of being a constituent character that causes the symbol
reader to attempt to absorb it only to barf on you. second, you advise
READ to hack a returned list to convert a symbol followed by the special
colon marker into a keyword and then skip the colon marker. (I forget
why we have to advise EXCL::READ1 instead of CL:READ.)
(defvar *ilog-readtable* (copy-readtable nil)
"Readtable modified to read keywords that _end_ in colon.")
(defvar *colon* (list #\:)
"Special colon marker to replace final colon in symbols read.")
(defun colon-reader (stream character)
"Replace all read colons with the special colon marker. Undone later."
(declare (ignore stream character))
*colon*)
(set-macro-character #\: 'colon-reader nil *ilog-readtable*)
(defadvice excl::read1 (ilog-fixup :after)
"Undo the damage done by COLON-READER and intern keywords properly."
(when (and (eq *readtable* *ilog-readtable*)
(listp (first values)))
(loop for tail on (first values)
when (and (symbolp (first tail)) (eq *colon* (second tail)))
do (setf (first tail) (intern (symbol-name (first tail))
*keyword-package*)
(second tail) nil
(cdr tail) (cddr tail))
when (eq *colon* (first tail))
do (error "Colon reader needs more work."))))
you can now do stuff like
(let ((*readtable* *ilog-readtable*))
(read-from-string "(define-cpp-function whatever super: t fumble: yes)"))
=> (define-cpp-function whatever :super t :fumble yes)
voilà, as the Ilog Talk people would probably say.
CAVEAT: this was sufficient for reading DSSSL, and may not be sufficient
for anything else. use at your own risk.
#:Erik
--
http://www.naggum.no/spam.html is about my spam protection scheme and how
to guarantee that you reach me. in brief: if you reply to a news article
of mine, be sure to include an In-Reply-To or References header with the
message-ID of that message in it. otherwise, you need to read that page.
>
> Hi
> I am trying to load some ilog talk code into acl4.3; to borrow
> from talks automatic FFI generator.
>
> However talk has symbols which end in ':' and behave like a
> keyword -> evaluate to themeselves.
...
> (define-cpp-function ...... super: ......)
> ^^^^^^
> it is these keywords which cause the problem?
>
> Any suggestions appreciated...
Do a regular expression string replacement on the source files before
trying to load them in?
In Emacs it might look something like this (for names that contain only
letters, numbers and "-":
M-X replace-regexp
\([-a-zA-Z0-9]*\):\B
:\1
Example:
(define-cpp-function ... super: boo sub:
oops)
Gets transformed into:
(define-cpp-function ... :super boo :sub
oops)
--
Thomas A. Russ, USC/Information Sciences Institute t...@isi.edu