Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pretty printing sexps

865 views
Skip to first unread message

Jason Nielsen

unread,
Feb 8, 2009, 4:45:18 PM2/8/09
to
I have a program that is parsing input and emitting sexps (a subset of
common lisp). I can get this program to dump the output as one long
string of sexps but that isn't a format that makes it easy to see any
problems with my parser. Is there an easy way to pretty print lisp code
in this format (one big ass long string) into something readable? I was
thinking something along the lines of GNU indent for C.

Thanks,
Jason

jos...@corporate-world.lisp.de

unread,
Feb 8, 2009, 5:03:30 PM2/8/09
to

Common Lisp provides READ to read expressions from a stream.
PPRINT pretty prints expressions to a stream.

http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_pr.htm

Pascal Costanza

unread,
Feb 8, 2009, 5:04:44 PM2/8/09
to

What's wrong with pprint?


Pascal

--
ELS'09: http://www.european-lisp-symposium.org/
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/

Jason Nielsen

unread,
Feb 8, 2009, 6:26:56 PM2/8/09
to

On Sun, 8 Feb 2009, jos...@corporate-world.lisp.de wrote:
>
> Common Lisp provides READ to read expressions from a stream.
> PPRINT pretty prints expressions to a stream.
>
> http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_pr.htm
>

Thank you, the parser is in C so I wasn't thinking about the lisp side and
only wanted to pretty print the output in my editor (emacs) to have a look
see at the sexps it is emitting. However, I've got this working now using
streams and pprint... duh!

Cheers,
Jason

Xah Lee

unread,
Feb 9, 2009, 2:59:04 AM2/9/09
to

• A Simple Lisp Code Formatter
http://xahlee.org/emacs/lisp_formatter.html

just this month, i tried to “hire” Andy to do it. Here's the result:

http://www.emacswiki.org/emacs/ElispFormat

the code is 1k lines but it's rather in beta stage, and it is tested
on elisp only. (current status is “abandoned”.)

I was offering a cheap “thank you” money of $15 (USD) for the work.
But due to the problem of small amount and international money
transfer, it's not paid. Was offering $50 for a somewhat more robust
result, but right now things just hang there. (he wouldn't take paypal
($20 to withdraw for him), no friend i can pay to in US, and he's got
more important thing to do this than this small compensation)

If you would write to him, possibly he might pick it up. And if you
offer some small amount, combined with mine, there'd be more
incentive. (i can pay you, then you add your amount and pay him, so to
avoid 3rd party sucking off transaction fee. (a bank wire is $20 a
pop)) I'm sure if few more people join in, we can make the code
industrial strength that works on any lisp code.

In my opinion, a mechanical lisp formatter is extremely important.
(see the section “Automatic, Uniform, Universal, Source Code Display”
at http://xahlee.org/UnixResource_dir/writ/lisp_problems.html )

Common Lisp, and perhaps Scheme lisp, has some facility to read lisp
code, but the problem is that the compiler throws away comment.
Basically unusable for this purpose unless somewhat extensively
modified.

If you search back, in 2008 or 2007 there are at least 2 biggist
thread on this... someone actually posted a similar request and
announcement, that he did a half-assed job of it. In one of the
thread, Rainer also gave a common lisp “solution” using its reader
(which ditches comments).

(spent 10 min to google group seach but failed. Apparently google
search does not exactly search all texts in the post... because i know
the exact phrases used the post, yet search results nothing. For those
want to find the thread here's tips: i posted to the thread (using
xahlee gmail.com or xah xahlee.org), so did Rainer. The date is
sometimes in 2008, possibly 2007.
This article:
• A Simple Lisp Code Formatter http://xahlee.org/emacs/lisp_formatter.html
is a edited version from one of my post. Much texts there is verbatim.
A web search will probably return mirrored newsgroup sites of this
thread.
)

Xah
http://xahlee.org/


0 new messages