From: Thomas Guettler
Subject: Print Function with several arguments
Date: 
Message-ID: <3D3D18D5.2070205@thomas-guettler.de>
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

From: Edi Weitz
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <87fzyakeaw.fsf@bird.agharta.de>
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>
From: Larry Kramer
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <3D3D5B2B.5FC1EAA1@cs.cmu.edu>
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
From: Thomas Guettler
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <3D3E5139.5010107@thomas-guettler.de>
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
From: Frode Vatvedt Fjeld
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <2hwurmx0s1.fsf@vserver.cs.uit.no>
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
From: Thomas Guettler
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <3D410054.6040708@thomas-guettler.de>
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
From: Jacek Generowicz
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <tyfvg72lw80.fsf@pcitapi22.cern.ch>
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.
From: Frode Vatvedt Fjeld
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <2hy9byamer.fsf@vserver.cs.uit.no>
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
From: Jacek Generowicz
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <tyfn0selsj3.fsf@pcitapi22.cern.ch>
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 ?
From: Frode Vatvedt Fjeld
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <2hu1mmahql.fsf@vserver.cs.uit.no>
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
From: Wolfhard Buß
Subject: Re: Print Function with several arguments
Date: 
Message-ID: <m3n0se92ud.fsf@buss-14250.user.cis.dfn.de>
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)