[Openmcl-devel] macro-characters ? x:foo => (tag foo x)

Ron Garret ron at flownet.com
Sun Jul 29 09:04:28 PDT 2018


Ah.  That is indeed not possible with a regular macro because this syntax is fundamentally incompatible with the default Lisp reader.  So while it is possible to do this using the reader, if you do, you won’t be able to read standard Lisp any more.  So a better approach would be to either 1) design a better syntax or 2) write your own parser for this syntax.

Or you could just use the standard CL idiom for what it looks like you want to accomplish: (the tag expression)

rg

On Jul 29, 2018, at 4:25 AM, Taoufik Dachraoui <dachraoui.taoufik at gmail.com> wrote:

> this does not work because any expression can be tagged and not only symbols:
> 
> (+ x 1):foo  => (tag foo (+ x 1))
> 
> Also, how a macro can solve this? as soon as the reader sees x:foo it will complain that package x does not exist
> 
> Taoufik
> 
> On Sat, Jul 28, 2018 at 5:36 PM Ron Garret <ron at flownet.com> wrote:
> Yeah, doing this with a reader macro is a bad idea.  But you can do it with a regular macro via something like:
> 
> `(tag ,(intern (package-name (symbol-package the-symbol)) the-current-package) ,(intern (symbol-name (the-symbol)) the-current-package))
> 
> rg
> 
> On Jul 28, 2018, at 4:54 AM, Bill St. Clair <wws at clozure.com> wrote:
> 
>> As far as I know, you can’t do that. I would also recommend against redefining the package prefix separator.
>> 
>> On Sat, Jul 28, 2018 at 7:45 AM Taoufik Dachraoui <dachraoui.taoufik at gmail.com> wrote:
>> Hi,
>> 
>> I would like to be able to transform x:foo to (tag foo x)
>> 
>> if I define a macro-character for : how can I access the symbol 
>> read just before :
>> 
>> Example of usage:
>> 
>> (fn (x:foo) (+ x 1)) => (fn ((tag foo x)) (+ x 1))
>> ((fn (x:list) (car x)) body:list) => ((fn ((tag list x)) (car x)) (tag list body))
>> 
>> Thanks for your help
>> 
>> Taoufik
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> https://lists.clozure.com/mailman/listinfo/openmcl-devel
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> https://lists.clozure.com/mailman/listinfo/openmcl-devel
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20180729/5b9307b6/attachment.htm>


More information about the Openmcl-devel mailing list