Paulo Mendes
Paulo Mendes

Reputation: 728

Avoiding echos in Clozure lisp (noob)

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.

Upvotes: 1

Views: 87

Answers (2)

m-n
m-n

Reputation: 1446

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*

Upvotes: 7

Rainer Joswig
Rainer Joswig

Reputation: 139251

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.

Upvotes: 7

Related Questions