Chapter 17 - pg 358 Display an aditional character on output

27 views
Skip to first unread message

francisco carlos

unread,
Jul 4, 2012, 12:51:51 AM7/4/12
to Land of Lisp
I coded the following code: (test.lisp)

(defun print-tag (name alst closingp)
(princ #\<)
(when closingp
(princ #\/))
(princ (string-downcase name))
(mapc (lambda (att)
(format t " ~a=\"~a\"" (string-downcase (car att)) (cdr att)))
alst)
(princ '#\>))

But I noted a following output:

CL-USER> (load (compile-file "test.lisp"))

etc ...etc

; /home/lisper/test.lisp.fasl written
; compilation finished in 0:00:14.730
T

CL-USER> (print-tag 'mytag '((color . blue) (height . 9)) nil)
<mytag color="BLUE" height="9">
#\>

*note* The last line has string "#\>" uneexpected... what is happenng?

Suggestions?
Sinceraly, Carlos

lisper

unread,
Jul 4, 2012, 1:48:51 AM7/4/12
to land-o...@googlegroups.com

More an example:
CL-USER> (with-open-file (*standard-output* "lixo.txt"
                        :direction :output
                        :if-exists :supersede)
       (print-tag 'my-tag '((color . blue ) (height . 9)) nil))
#\>
Why the  caracter #\>  was printed in REPL???
Suggestions?
Sinceraly, Carlos


 

Sequiturian

unread,
Nov 6, 2012, 12:52:41 PM11/6/12
to land-o...@googlegroups.com
 lisper wrote:
I coded the following code:  (test.lisp)

(defun print-tag (name alst closingp)
  (princ #\<)
  (when closingp
    (princ #\/))
  (princ (string-downcase name))
  (mapc (lambda (att)
        (format t " ~a=\"~a\"" (string-downcase (car att)) (cdr att)))
      alst)
 (princ '#\>))

But I noted a following output:

CL-USER> (load (compile-file "test.lisp"))
 
*snip*

CL-USER> (print-tag 'mytag '((color . blue) (height . 9)) nil)
<mytag color="BLUE" height="9">
#\>

*note* The last line has string "#\>" uneexpected... what is happenng?

Suggestions?
Sinceraly, Carlos

Carlos,
The Lisp REPL always prints out the result of the last expression entered, if any. Since, (princ #\>) was the last body statement in your print-tags function, that is the result of print-tag (what was printed) - it's like an implicit progn. The rest of the printed text you see are just side-effects. Enter (princ 'hello) on a line and notice that is prints twice. Once was the side-effect and the other is the result from REPL.
 
 Hope that makes sense.

LL
Reply all
Reply to author
Forward
0 new messages