Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Lisp

Idiom #243 Print list

Print the contents of the list or array a on the standard output.

(print a )
(defun plist (lst)
  (if (< (length lst) 20 )  
      (loop for elem in lst do (p elem))
      (let ((l (length lst )))
         (p (nth 0 lst )(nth 1 lst )(nth 2 lst )(nth 3 lst )
         "... (" l " in total)... "
         (nth (- l 4) lst )(nth (- l 3 ) lst )(nth (- l 2 ) lst )(nth (- l 1 ) lst ) )
      )))

(defun p (x &rest others)
  (cond ((listp x)( plist x   ))
        ((stringp x)(format t x  ))
        (T (write x)))
  (format t " ") 
  (if others (p others))

pretty-print a list, abbreviating the middle part if the list is too long.
(print a)

New implementation...