Antireader macros

Discussion of Common Lisp
Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Antireader macros

Post by Goheeca » Wed Sep 12, 2012 8:11 am

It's user's arbitrariness (like *print-circle* etc.).
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

JamesF
Posts: 98
Joined: Thu Jul 10, 2008 7:14 pm

Re: Antireader macros

Post by JamesF » Thu Sep 13, 2012 1:01 am

Just spinning my wheels here, what about defining a type or class that's instantiated when the reader encounters curly-braces, possibly a subclass/subtype of list, and specialising print-object on that type/class?

Note: this is based on exactly zero fact-checking, combined with a sketchy grasp of CL's type system.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Antireader macros

Post by Goheeca » Thu Sep 13, 2012 6:07 am

sylwester wrote:A) only curlies in place of parenthesis everywhere?
B) mixed curlies and parenthsis?
A) - I don't mind that I'm going to lose information during a reading part.
JamesF wrote:Just spinning my wheels here, what about defining a type or class that's instantiated when the reader encounters curly-braces, possibly a subclass/subtype of list, and specialising print-object on that type/class?
The reader macro is more generic actually it's for differently written lists, no special structure, so I would say that doesn't fit.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Antireader macros

Post by Goheeca » Sat Sep 15, 2012 3:34 am

So I'm probably blind and possibly set-pprint-dispatch will be sufficient.
Here is a simple solution for my factitious problem, although it deals bad with a syntactic sugar like quote, quasiquote, unquote, etc.

Code: Select all

(set-pprint-dispatch '(cons t t)
                     #'(lambda (s input) (format s "{~{~s~^ ~}}" input)))
// I wonder you haven't kicked me to read the documentation properly.
And now I'll see how good is it for cl-2dsynax.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Kohath
Posts: 61
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia
Contact:

Re: Antireader macros

Post by Kohath » Tue Sep 18, 2012 11:40 pm

Good pickup - I just found 22.2.1.4 Pretty Print Dispatch Tables. Interestingly, I've never seen anyone use it (although that's not saying much :mrgreen:). Nice!

Post Reply