Hi!
I want to debug a lisp program by using print.
But print seems to accept only one item at once
(print "foo-variable:" foo-variable) does not work. At least not
with Allegro Common Lisp 3.0.2.
How could I do something like this?
Is there something like printf in C?
thomas
Thomas Guettler <···········@thomas-guettler.de> writes:
> Is there something like printf in C?
Even better:
<http://www.xanalys.com/software_tools/reference/HyperSpec/Body/22_c.htm>
Edi Weitz wrote:
>
> Thomas Guettler <···········@thomas-guettler.de> writes:
>
> > Is there something like printf in C?
>
> Even better:
>
> <http://www.xanalys.com/software_tools/reference/HyperSpec/Body/22_c.htm>
Before you get into print statements,
Even better: trace
Edi Weitz wrote:
> Thomas Guettler <···········@thomas-guettler.de> writes:
>
>
>>Is there something like printf in C?
>>
>
> Even better:
>
> <http://www.xanalys.com/software_tools/reference/HyperSpec/Body/22_c.htm>
>
Thank you very much! The HyperSpec is very good.
thomas
Thomas Guettler <···········@thomas-guettler.de> writes:
> Is there something like printf in C?
Yes, it's called format:
(format t "~&This is something: ~W~%" (do-something))
Also let me suggest that you'll learn much more and quicker if you
look up functions in the reference documentation rather than guessing
and/or asking about them here.
--
Frode Vatvedt Fjeld
Thomas Guettler wrote:
> Hi!
>
> I want to debug a lisp program by using print.
> But print seems to accept only one item at once
>
> (print "foo-variable:" foo-variable) does not work. At least not
> with Allegro Common Lisp 3.0.2.
>
> How could I do something like this?
(print (list "i:" i))
thomas
Thomas Guettler <···········@thomas-guettler.de> writes:
> Thomas Guettler wrote:
>
> > Hi!
> > I want to debug a lisp program by using print.
> > But print seems to accept only one item at once
> > (print "foo-variable:" foo-variable) does not work. At least not
> > with Allegro Common Lisp 3.0.2.
> > How could I do something like this?
>
> (print (list "i:" i))
Or you might want to define something like
(defmacro ?? (&rest symbols)
`(progn
,@(mapcar #'(lambda (s)
`(format t "~%~a: ~a" (symbol-name ',s) ,s))
symbols)))
... which you then use like this
(let ((a 1)
(b 2))
(?? a b))
A: 1
B: 2
NIL
If a real Lisp programmer would care to constructively criticize my
naivety in hacking together the above, I'd be grateful.
Jacek Generowicz <················@cern.ch> writes:
> (defmacro ?? (&rest symbols)
> `(progn
> ,@(mapcar #'(lambda (s)
> `(format t "~%~a: ~a" (symbol-name ',s) ,s))
> symbols)))
I don't see any reason to restrict this to forms that are symbols.
(defmacro ?? (&body forms)
(cons 'progn
(mapcar (lambda (form)
`(format t "~&~S: ~W~%" ',form ,form))
forms)))
You might want to make this return something useful, and take multiple
values into account too..
--
Frode Vatvedt Fjeld
Frode Vatvedt Fjeld <······@acm.org> writes:
> Jacek Generowicz <················@cern.ch> writes:
>
> > (defmacro ?? (&rest symbols)
> > `(progn
> > ,@(mapcar #'(lambda (s)
> > `(format t "~%~a: ~a" (symbol-name ',s) ,s))
> > symbols)))
>
> I don't see any reason to restrict this to forms that are symbols.
Good idea.
> (defmacro ?? (&body forms)
> (cons 'progn
> (mapcar (lambda (form)
> `(format t "~&~S: ~W~%" ',form ,form))
> forms)))
Thank you, that's prettier, and ... err ... yes, the symbol-name was
particularly pointless.
> You might want to make this return something useful,
(defmacro ?? (&body forms)
(append `(prog1 ,(car forms))
(mapcar (lambda (form)
`(format t "~&~S: ~W~%" ',form ,form))
forms)))
But you may not want any of the forms to be evaluated more than once
...
> and take multiple values into account too..
Before I re-invent the wheel, is there a way of calling whatever the
REPL uses to display multiple values ?
Jacek Generowicz <················@cern.ch> writes:
> But you may not want any of the forms to be evaluated more than once
I think this is an understatement. The first rule for macros with
sub-forms is to evaluate them in order and exactly once, unless some
control-structure like iteration or conditional branching is implied.
> Before I re-invent the wheel, is there a way of calling whatever the
> REPL uses to display multiple values ?
There are many REPLs, and what they all use I don't know, but format
in combination with m-v-call or m-v-list will do the job.
For example:
(multiple-value-call #'format t "Form ·········@{ ~W~}~%" <form>)
--
Frode Vatvedt Fjeld
Jacek Generowicz <················@cern.ch> writes:
> Before I re-invent the wheel, is there a way of calling whatever the
> REPL uses to display multiple values ?
You might iterate over a multiple-value-list.
--
"I believe in the horse. The automobile is a passing phenomenon."
-- Kaiser Wilhelm II. (1859-1941)