Re: Pretty-print question



Tamas <tkpapp@xxxxxxxxx> writes:

On Jan 17, 12:17 am, D Herring <dherr...@xxxxxxxxxxxxxxxxxxx> wrote:
I'm representing small directed graphs as 2D matrices.
(case (aref matrix x y)
(0 not connected)
(+1 x->y)
(-1 y->x))

This is convenient, but it doesn't print nicely...

#2A((0 1 1 1 0 0 0 0)
(-1 0 1 1 0 0 0 0)
(-1 -1 0 1 0 0 0 0)
(-1 -1 -1 0 0 0 0 0)
(0 0 0 0 0 1 0 0)
(0 0 0 0 -1 0 0 0)
(0 0 0 0 0 0 0 1)
(0 0 0 0 0 0 -1 0))

Is there a way to get lisp to print this with the columns lining up?
(portable/sbcl solutions preferred)

Its not hard to do this manually with format, but I was hoping for
something that would work transparently throughout a repl session.

In the meantime, I switched to using 0,1,2; but that seems less clean.

Thanks,
Daniel

Hi Daniel,

I don't quite understand the notation. The representation I have seen
for directed graphs works by putting a 1 in (aref matrix x y) if there
is a directed edge from x to y, otherwise 0. The y->x edge would be a
1 in (aref matrix y x), not a -1 in (aref matrix x y). So it is just
1s and 0s in the matrix. You seen to be duplicating information in
your matrix (the lower triangle is -1 times the upper one, mirrored on
the diagonal), which is something extra you have to keep consistent.

Indeed, the OP representation is strange.
How would he represent ({x,y},{(x,y),(y,x)}) ?

0 1
1 0

or

0 -1
-1 0

?

What would

0 -1
1 0

mean? ({x,y},{(x,y),(x,y)}) ???


Am I missing something?


--
__Pascal Bourguignon__
mailto:pascal.bourguignon@xxxxxxxxxx
http://www.anevia.com
.



Relevant Pages

  • Re: Pretty-print question
    ... Is there a way to get lisp to print this with the columns lining up? ... for directed graphs works by putting a 1 in (aref matrix x y) if there ... is a directed edge from x to y, ...
    (comp.lang.lisp)
  • Pretty-print question
    ... I'm representing small directed graphs as 2D matrices. ... (case (aref matrix x y) ... Its not hard to do this manually with format, but I was hoping for something that would work transparently throughout a repl session. ...
    (comp.lang.lisp)