From: Michael Bell
Subject: How to format a list? (newbie)
Date: 
Message-ID: <87wul070sn.fsf@belfry.cx>
I'm trying to learn about Common Lisp from a small emacs-lisp base.

If I have a list,  how do I use (format ...) to print it?

For example, I want to do something like:

(form-that-makes-mylist)
  .
  .
  .
(format nil "~2d ~2d " (mylist) )

Which fails because the format requires all the elements of list, not
the list itself.

I've played with multiple-value-*, values and some map* forms, but to
no avail.  I know I'm missing something basic - would you point it out
for me?

-- 
Michael Bell
Perth, Western Australia.

GnuPG fingerprint: E3E4 31C6 6FE6 B4F7 4279  5F48 D417 C044 ECD6 38AB

From: Geoffrey Summerhayes
Subject: Re: How to format a list? (newbie)
Date: 
Message-ID: <6VGW9.2356$W3.126581@news20.bellglobal.com>
"Michael Bell" <········@belfry.cx> wrote in message ···················@belfry.cx...
> I'm trying to learn about Common Lisp from a small emacs-lisp base.
>
> If I have a list,  how do I use (format ...) to print it?
>
> For example, I want to do something like:
>
> (form-that-makes-mylist)
>   .
>   .
>   .
> (format nil "~2d ~2d " (mylist) )
>
> Which fails because the format requires all the elements of list, not
> the list itself.
>
> I've played with multiple-value-*, values and some map* forms, but to
> no avail.  I know I'm missing something basic - would you point it out
> for me?
>

: (format nil "~{~2D~}" '(1 3 4 5))
" 1 3 4 5"

--
Geoff
From: Larry Clapp
Subject: Re: How to format a list? (newbie)
Date: 
Message-ID: <7eff0b.j27.ln@127.0.0.1>
In article <··············@belfry.cx>, Michael Bell wrote:
> I'm trying to learn about Common Lisp from a small emacs-lisp base.
> 
> If I have a list,  how do I use (format ...) to print it?
> 
> For example, I want to do something like:
> 
> (form-that-makes-mylist)
>   .
>   .
>   .
> (format nil "~2d ~2d " (mylist) )

First of all, you probably want (format t ...) if you actually
want the value printed.  (format nil ...) returns the value as a
string.

> Which fails because the format requires all the elements of
> list, not the list itself.
> 
> I've played with multiple-value-*, values and some map* forms,
> but to no avail.  I know I'm missing something basic - would
> you point it out for me?

(format t "~a~%" '(a b c)) prints (A B C).  Similarly,

    (let ((mylist '(a b c)))
      (format t "~a~%" mylist))

prints (A B C), too.

Does that clear up your problem, or did you have some other
issue?  The Common Lisp HyperSpec section on Formatted Output
might come in handy here:
http://www.lispworks.com/reference/HyperSpec/Body/22_c.htm.  On
the other hand, I don't know squat about emacs-lisp, so the
HyperSpec might not apply.

HTH.

-- Larry
From: Michael Bell
Subject: Re: How to format a list? (FOLLOWUP)
Date: 
Message-ID: <87vg0jd388.fsf_-_@belfry.cx>
Larry Clapp, et al, wrote several useful suggestions in response to my
query.

The solution I came up with myself was:

(apply #'(lambda (lst) (format "%2d:%02d" (car lst) (car (cdr lst)))) 
        my-list)

which works but doesn't appeal.

I am actually working within emacs, but also referring to clisp.  I've
down-loaded the HyperSpec but must confess that I haven't waded
through much of it:  I've been consulting Graham's "ANSI Common Lisp"
and Lamkins' Successful Lisp, along with the Elisp manual.

Thanks for responding to my basic queries.  I'm putting together a
simple script (program?  application??) to process my time-sheet;
I've re-written and re-formed it many times now but have been learning
heaps.

(I actually already have a solution in Python: so far Lisp is longer,
but more fun...)

-- 
Michael Bell
Perth, Western Australia.

GnuPG fingerprint: E3E4 31C6 6FE6 B4F7 4279  5F48 D417 C044 ECD6 38AB
From: Matthew Danish
Subject: Re: How to format a list? (FOLLOWUP)
Date: 
Message-ID: <20030120092603.A27240@lain.cheme.cmu.edu>
On Mon, Jan 20, 2003 at 08:18:21PM +0000, Michael Bell wrote:
> The solution I came up with myself was:
> 
> (apply #'(lambda (lst) (format "%2d:%02d" (car lst) (car (cdr lst)))) 
>         my-list)
> 
> which works but doesn't appeal.

I'm having trouble seeing how this could possibly work at all.  Even in
Emacs Lisp, the only way this could work is if the first (and only)
element of my-list was a list as well.

How about: (format t "%2d %2d" (first list) (second list)) ?

> I am actually working within emacs, but also referring to clisp.  I've
> down-loaded the HyperSpec but must confess that I haven't waded
> through much of it:  I've been consulting Graham's "ANSI Common Lisp"
> and Lamkins' Successful Lisp, along with the Elisp manual.

Mixing Emacs Lisp and Common Lisp sounds like a surefire recipe for
disaster.

> Thanks for responding to my basic queries.  I'm putting together a
> simple script (program?  application??) to process my time-sheet; I've
> re-written and re-formed it many times now but have been learning
> heaps.

Are you trying to parse a timesheet, or manage one?  I have some code
which does the latter, if you are interested.

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Michael Bell
Subject: Re: How to format a list? (FOLLOWUP)
Date: 
Message-ID: <87n0lvctlm.fsf@belfry.cx>
Matthew Danish <·······@andrew.cmu.edu> writes:

<good stuff>

 On Mon, Jan 20, 2003 at 08:18:21PM +0000, Michael Bell wrote:
> <other stuff>

> > I am actually working within emacs, but also referring to clisp.  I've
> > down-loaded the HyperSpec but must confess that I haven't waded
> > through much of it:  I've been consulting Graham's "ANSI Common Lisp"
> > and Lamkins' Successful Lisp, along with the Elisp manual.
> 
> Mixing Emacs Lisp and Common Lisp sounds like a surefire recipe for
> disaster.

I think that was lesson #1.  A week ago I was wondering how different
they could be;  now I have them partitioned as (dangerously similar
but) different languages.
 
> Are you trying to parse a timesheet, or manage one?  I have some code
> which does the latter, if you are interested.

I've been using the "records" package by  Ashvin Goel
(······@users.sourceforge.net) to keep track of work in xemacs, and
I'm adding a facility to email me my fortnightly time-sheet summary.
I've already bashed together a Python script to do it, but I've been
using it as an exercise to learn more about Lisp.

Is your code in Lisp?  If so, I'd be glad to see how you've done things.

-- 
Michael Bell
Perth, Western Australia.

GnuPG fingerprint: E3E4 31C6 6FE6 B4F7 4279  5F48 D417 C044 ECD6 38AB
From: synthespian
Subject: Re: How to format a list? (FOLLOWUP)
Date: 
Message-ID: <pan.2003.01.29.23.59.56.765556.29888@uol.com.br>
Em Mon, 20 Jan 2003 21:03:16 -0200, Michael Bell escreveu:

> Matthew Danish <·······@andrew.cmu.edu> writes:
> 
> <good stuff>
> 
>  On Mon, Jan 20, 2003 at 08:18:21PM +0000, Michael Bell wrote:
>> <other stuff>
> 
>> > I am actually working within emacs, but also referring to clisp. I've
>> > down-loaded the HyperSpec but must confess that I haven't waded
>> > through much of it:  I've been consulting Graham's "ANSI Common Lisp"
>> > and Lamkins' Successful Lisp, along with the Elisp manual.
>> 
>> Mixing Emacs Lisp and Common Lisp sounds like a surefire recipe for
>> disaster.
> 
> I think that was lesson #1.  A week ago I was wondering how different
> they could be;  now I have them partitioned as (dangerously similar but)
> different languages.
>
 Hi --

 You might want to look at the differences between the two Lisps (there
are quite a few, and imprtant ones too...):


 This URL covers the differneces:
 http://www.strw.leidenuniv.nl/cgi-bin/info2html?(cl)Top

 This one is about Common Lisp extensions to Emacs:
 http://www.lns.cornell.edu/public/COMP/info/cl/cl_1.html


 Cheers

 Henry
From: Frode Vatvedt Fjeld
Subject: Re: How to format a list? (newbie)
Date: 
Message-ID: <2hel78qpy5.fsf@vserver.cs.uit.no>
Michael Bell <········@belfry.cx> writes:

> (format nil "~2d ~2d " (mylist) )

It seems to me you want (apply #'format nil "~2d ~2d" mylist).

-- 
Frode Vatvedt Fjeld
From: Coby Beck
Subject: Re: How to format a list? (newbie)
Date: 
Message-ID: <b0g5vt$9as$1@otis.netspace.net.au>
"Michael Bell" <········@belfry.cx> wrote in message
···················@belfry.cx...
> I'm trying to learn about Common Lisp from a small emacs-lisp base.
>
> If I have a list,  how do I use (format ...) to print it?
>
> For example, I want to do something like:
>
> (form-that-makes-mylist)
>   .
>   .
>   .
> (format nil "~2d ~2d " (mylist) )

If you know the contents of you list (as is suggested by your two ~d
directives) you could use apply:
(apply #'format nil "~2d ~2d" my-list)
That has the advantage of being able to specify how each argument will be
formated but the disadvantage of having to match all of the format
directives:

CL-USER 4 > (let ((list (list 'a "Bee" 3 4.0)))
              (apply #'format t "~A~10T~S~20T~2,'0D~30T~,4F" list))
A         "Bee"     03        4.0000
NIL

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")