From: John Thingstad
Subject: format hell?
Date: 
Message-ID: <op.usx18uehut4oq5@pandora>
(defun gimme-time ()
   (apply #'format nil
          "Time: ··@······@······@*~D ~
  ·······@* ~
  ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
  ··@* ~D/~D-~D"
          (multiple-value-list (decode-universal-time  
(get-universal-time)))))

CL-USER> (gimme-time)
"Time: 14:45:11 Date: Saturday 25/4-2009"

-----------------------
John Thingstad

From: Marco Antoniotti
Subject: Re: format hell?
Date: 
Message-ID: <fca8315e-7305-48f8-af1a-4b7721e1adf0@x31g2000prc.googlegroups.com>
On Apr 25, 3:25 pm, "John Thingstad" <·······@online.no> wrote:
> (defun gimme-time ()
>    (apply #'format nil
>           "Time: ··@······@······@*~D ~
>   ·······@* ~
>   ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
>   ··@* ~D/~D-~D"
>           (multiple-value-list (decode-universal-time  
> (get-universal-time)))))
>
> CL-USER> (gimme-time)
> "Time: 14:45:11 Date: Saturday 25/4-2009"
>

Just for fun... I ahve spent the last hour trying to figure out how to
make a http link from an image in MediaWiki....

Cheers
--
Marco
www.european-lisp-symposium.org
From: Tamas K Papp
Subject: Re: format hell?
Date: 
Message-ID: <75gpr3F188n3gU1@mid.individual.net>
On Sat, 25 Apr 2009 15:25:32 +0200, John Thingstad wrote:

> (defun gimme-time ()
>    (apply #'format nil
>           "Time: ··@······@······@*~D ~
>   ·······@* ~
>   ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
>   ··@* ~D/~D-~D"
>           (multiple-value-list (decode-universal-time
> (get-universal-time)))))
> 
> CL-USER> (gimme-time)
> "Time: 14:45:11 Date: Saturday 25/4-2009"

Why is this hell?  I think this is a neat application of a DSL
designed exactly for things like this.  I might have used
multiple-value-bind and reordered the arguments explicitly (I find
this more readable), but if you like ~* then it is fine.
      
Tamas
From: namekuseijin
Subject: Re: format hell?
Date: 
Message-ID: <gsvm4o$1adu$1@adenine.netfront.net>
John Thingstad wrote:
> 
> (defun gimme-time ()
>   (apply #'format nil
>          "Time: ··@······@······@*~D ~
>  ·······@* ~
>  ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
>  ··@* ~D/~D-~D"
>          (multiple-value-list (decode-universal-time 
> (get-universal-time)))))
> 
> CL-USER> (gimme-time)
> "Time: 14:45:11 Date: Saturday 25/4-2009"

Guess William James would be proud of the Perl inside CL. ;)
From: Kaz Kylheku
Subject: Re: format hell?
Date: 
Message-ID: <20090505193857.834@gmail.com>
On 2009-04-25, John Thingstad <·······@online.no> wrote:
>
> (defun gimme-time ()
>    (apply #'format nil
>           "Time: ··@······@······@*~D ~
>   ·······@* ~
>   ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
>   ··@* ~D/~D-~D"
>           (multiple-value-list (decode-universal-time  
> (get-universal-time)))))
>
> CL-USER> (gimme-time)
> "Time: 14:45:11 Date: Saturday 25/4-2009"

A while ago I came up with a macro called FORM which compiles an S-exp notation
to format strings.

The above would be written like this:

(defun gimme-time ()
   (apply #'format nil
          (form "Time: " 
                (go-nth 2) (d) 
                ":"
                (go-nth 1) (d)
                ":"
                (go-nth 0) (d)
                " Date: "
                (go-nth 6) (enum "Monday" "Tuesday" "Wednesday" "Thursday"
                                 "Friday" "Saturday" "Sunday")
                (go-nth 3) " " (d) "/" (d) "-" (d))
          (multiple-value-list (decode-universal-time  
(get-universal-time)))))

More verbose, but you have a shot at understanding it if you come back six
months later.

GIMME-TIME is a big unconventional; if some of the time numbers are single
digits, they don't get padded to zero. So one second past one minute past one
is Time: 1:1:1.  That could be taken care of as follows:

  (d :mincol 2 :padchar #\0)

Abstraction inversion city! Compile Lisp to a cryptic format string, which has
to be parsed again and turned into Lisp. :)
From: gugamilare
Subject: Re: format hell?
Date: 
Message-ID: <3d9bf2cb-5265-4984-9873-7d069379c8f2@d7g2000prl.googlegroups.com>
On 25 abr, 14:42, Kaz Kylheku <········@gmail.com> wrote:
> On 2009-04-25, John Thingstad <·······@online.no> wrote:
>
>
>
> > (defun gimme-time ()
> >    (apply #'format nil
> >           "Time: ··@······@······@*~D ~
> >   ·······@* ~
> >   ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
> >   ··@* ~D/~D-~D"
> >           (multiple-value-list (decode-universal-time  
> > (get-universal-time)))))
>
> > CL-USER> (gimme-time)
> > "Time: 14:45:11 Date: Saturday 25/4-2009"
>
> A while ago I came up with a macro called FORM which compiles an S-exp notation
> to format strings.
>
> The above would be written like this:
>
> (defun gimme-time ()
>    (apply #'format nil
>           (form "Time: "
>                 (go-nth 2) (d)
>                 ":"
>                 (go-nth 1) (d)
>                 ":"
>                 (go-nth 0) (d)
>                 " Date: "
>                 (go-nth 6) (enum "Monday" "Tuesday" "Wednesday" "Thursday"
>                                  "Friday" "Saturday" "Sunday")
>                 (go-nth 3) " " (d) "/" (d) "-" (d))
>           (multiple-value-list (decode-universal-time  
> (get-universal-time)))))

Sounds neat.

You could use multiple-value-call instead of apply.
>
> More verbose, but you have a shot at understanding it if you come back six
> months later.
>
> GIMME-TIME is a big unconventional; if some of the time numbers are single
> digits, they don't get padded to zero. So one second past one minute past one
> is Time: 1:1:1.  That could be taken care of as follows:
>
>   (d :mincol 2 :padchar #\0)
>
> Abstraction inversion city! Compile Lisp to a cryptic format string, which has
> to be parsed again and turned into Lisp. :)
From: Pascal J. Bourguignon
Subject: Re: format hell?
Date: 
Message-ID: <87ws98bm49.fsf@galatea.local>
Kaz Kylheku <········@gmail.com> writes:

> On 2009-04-25, John Thingstad <·······@online.no> wrote:
>>
>> (defun gimme-time ()
>>    (apply #'format nil
>>           "Time: ··@······@······@*~D ~
>>   ·······@* ~
>>   ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
>>   ··@* ~D/~D-~D"
>>           (multiple-value-list (decode-universal-time  
>> (get-universal-time)))))
>>
>> CL-USER> (gimme-time)
>> "Time: 14:45:11 Date: Saturday 25/4-2009"
>
> A while ago I came up with a macro called FORM which compiles an S-exp notation
> to format strings.
>
> The above would be written like this:
>
> (defun gimme-time ()
>    (apply #'format nil
>           (form "Time: " 
>                 (go-nth 2) (d) 
>                 ":"
>                 (go-nth 1) (d)
>                 ":"
>                 (go-nth 0) (d)
>                 " Date: "
>                 (go-nth 6) (enum "Monday" "Tuesday" "Wednesday" "Thursday"
>                                  "Friday" "Saturday" "Sunday")
>                 (go-nth 3) " " (d) "/" (d) "-" (d))
>           (multiple-value-list (decode-universal-time  
> (get-universal-time)))))
>
> More verbose, but you have a shot at understanding it if you come back six
> months later.
>
> GIMME-TIME is a big unconventional; if some of the time numbers are single
> digits, they don't get padded to zero. So one second past one minute past one
> is Time: 1:1:1.  That could be taken care of as follows:
>
>   (d :mincol 2 :padchar #\0)
>
> Abstraction inversion city! Compile Lisp to a cryptic format string, which has
> to be parsed again and turned into Lisp. :)

Why?

    22.3 Formatted Output

    format is useful for producing nicely formatted text, producing
    good-looking messages, and so on.  format can generate and return
    a string or output to destination.

    The control-string argument to format is actually a format
    control. That is, it can be either a  format string or a function,
    for example a function returned by the formatter macro.

    If it is a function, the function is called with the appropriate
    output stream as its first argument and the data arguments to
    format as its remaining arguments. The function should perform
    whatever output is necessary and return the unused tail of the
    arguments (if any).

You could generate a function instead of a string!

-- 
__Pascal Bourguignon__
From: John Thingstad
Subject: Re: format hell?
Date: 
Message-ID: <op.usyjhuo3ut4oq5@pandora>
På Sat, 25 Apr 2009 19:42:53 +0200, skrev Kaz Kylheku <········@gmail.com>:

> On 2009-04-25, John Thingstad <·······@online.no> wrote:
>>
>> (defun gimme-time ()
>>    (apply #'format nil
>>           "Time: ··@······@······@*~D ~
>>   ·······@* ~
>>   ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
>>   ··@* ~D/~D-~D"
>>           (multiple-value-list (decode-universal-time
>> (get-universal-time)))))
>>
>> CL-USER> (gimme-time)
>> "Time: 14:45:11 Date: Saturday 25/4-2009"
>
> A while ago I came up with a macro called FORM which compiles an S-exp  
> notation
> to format strings.
>
> The above would be written like this:
>
> (defun gimme-time ()
>    (apply #'format nil
>           (form "Time: "
>                 (go-nth 2) (d)
>                 ":"
>                 (go-nth 1) (d)
>                 ":"
>                 (go-nth 0) (d)
>                 " Date: "
>                 (go-nth 6) (enum "Monday" "Tuesday" "Wednesday"  
> "Thursday"
>                                  "Friday" "Saturday" "Sunday")
>                 (go-nth 3) " " (d) "/" (d) "-" (d))
>           (multiple-value-list (decode-universal-time
> (get-universal-time)))))
>
> More verbose, but you have a shot at understanding it if you come back  
> six
> months later.

Sweet! You couldn't give us the source for that?

>
> GIMME-TIME is a big unconventional; if some of the time numbers are  
> single
> digits, they don't get padded to zero. So one second past one minute  
> past one
> is Time: 1:1:1.  That could be taken care of as follows:
>
>   (d :mincol 2 :padchar #\0)
>

Right.. I ended with the ever more 'beutiful':

···@*~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~] ~
··@*~D/~D-~D ··@*~2,······@*~2,······@*~2,'0D"

(Cryptic enough to make a Perl head cry with delight!)

> Abstraction inversion city! Compile Lisp to a cryptic format string,  
> which has
> to be parsed again and turned into Lisp. :)

format can take a function as the third argument instead of a string as  
has been pointed out to me before.
Converting it directly is a bit more work but might just be worth it. (I  
wouldn't mind having a go at it..)

-----------------------
John Thingstad
From: Thomas A. Russ
Subject: Re: format hell?
Date: 
Message-ID: <ymi3abteu6r.fsf@blackcat.isi.edu>
"John Thingstad" <·······@online.no> writes:

> (defun gimme-time ()
>    (apply #'format nil
>           "Time: ··@······@······@*~D ~
>   ·······@* ~
>   ~[Monday~;Tuesday~;Wednesday~;Thursday~;Friday~;Saturday~;Sunday~]~
>   ··@* ~D/~D-~D"
>           (multiple-value-list (decode-universal-time
> (get-universal-time)))))
> 
> CL-USER> (gimme-time)
> "Time: 14:45:11 Date: Saturday 25/4-2009"

You only made it to heck.

You left out the

   ~2,'0D

part so that your minutes and seconds print with 2 digits, zero-filled.

-- 
Thomas A. Russ,  USC/Information Sciences Institute