Avoiding echos in Clozure lisp (noob)

87 views Asked by At

I'm getting my feet wet with lisp and came across an (I think) unusual problem. I'd like to create very long lists; ie, something like (setf *mat* (make-list 1000000)), but without having Nil printed out a million times on the screen.

The best I came up with is...

(let () (setf *mat* (make-list 1000000)) (length *mat*))

(or some other short but useless function at the end of the closure)

...but I suspect there is a better solution to avoid these sesquipedalian printouts. Any input is appreciated. Btw, I'm using Clozure v1.10 under Windows 7.

2

There are 2 answers

0
Rainer Joswig On BEST ANSWER

Usually one would call (values) at the end.

Common Lisp has a way to deal with long output at the printer level:

Welcome to Clozure Common Lisp Version 1.9-dev-r15612M-trunk  (DarwinX8664)!
? *print-length*
NIL
? (setf *print-length* 100)
100
? (make-list 1000000)
(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL
 NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL
 NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL
 NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL
 NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL
 NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL
 NIL NIL NIL NIL ...)

*print-length* here is the variable which controls it.

0
m-n On

An alternative to setting *print-length* is to use defparameter instead of setf on the repl. defparameter returns the symbol instead of the value:

(defparameter *mat* (make-list 10000))
-> *mat*