From: Jason Nielsen
Subject: Pretty printing sexps
Date: 
Message-ID: <alpine.DEB.2.00.0902081637580.15954@octopus>
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

From: ······@corporate-world.lisp.de
Subject: Re: Pretty printing sexps
Date: 
Message-ID: <69dc1470-fbbe-4176-b7db-da2563a1993e@e18g2000yqo.googlegroups.com>
On 8 Feb., 22:45, Jason Nielsen <····@math.carleton.ca> wrote:
> 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

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
From: Jason Nielsen
Subject: Re: Pretty printing sexps
Date: 
Message-ID: <Pine.LNX.4.64.0902081822560.11916@juno.math.carleton.ca>
On Sun, 8 Feb 2009, ······@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
From: Pascal Costanza
Subject: Re: Pretty printing sexps
Date: 
Message-ID: <6v937sFikncuU1@mid.individual.net>
Jason Nielsen wrote:
> 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.

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/
From: Xah Lee
Subject: Re: Pretty printing sexps
Date: 
Message-ID: <3e2f5524-6662-455a-b97c-681cb815b1fb@a12g2000pro.googlegroups.com>
On Feb 8, 1:45 pm, Jason Nielsen <····@math.carleton.ca> wrote:
> 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

• 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/

☄