This is a multi-part message in MIME format.
--------------1461AC448C8AD49986E84C0C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Happy New Year!
Please see the following
(let* ((n (/ (* 3600 200) 170))
(h (truncate n 3600))
(m (rem (truncate n 60) 60))
(s (truncate (rem n 60))))
(format t "~&~D:~D:~D~%" h m s))
this prints
1:10:35
Is it possible to make this fragment more clear ?
What is the right way to use only some values from those
returned by (values 1 2 3) ? E.g. second or first ?
Thanks!
--
Vladimir Zolotych ······@eurocom.od.ua
--------------1461AC448C8AD49986E84C0C
Content-Type: text/x-vcard; charset=us-ascii;
name="gsmith.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Vladimir V. Zolotych
Content-Disposition: attachment;
filename="gsmith.vcf"
begin:vcard
n:Zolotych;Valdimir V.
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
·····················@eurocom.od.ua
x-mozilla-cpt:;0
fn:Valdimir V. Zolotych
end:vcard
--------------1461AC448C8AD49986E84C0C--
* "Vladimir V. Zolotych" <······@eurocom.od.ua>
| (let* ((n (/ (* 3600 200) 170))
| (h (truncate n 3600))
| (m (rem (truncate n 60) 60))
| (s (truncate (rem n 60))))
| (format t "~&~D:~D:~D~%" h m s))
|
| this prints
| 1:10:35
(multiple-value-bind (mm ss) (floor (round (* 3600 200) 170) 60)
(multiple-value-bind (hh mm) (floor mm 60)
(format t "~2,'0D:~2,'0D:~2,'0D" hh mm ss)))
Note the use of round instead of / which produces an integer instead of a
rational number directly.
| Is it possible to make this fragment more clear?
Is the above more clear?
| What is the right way to use only some values from those
| returned by (values 1 2 3) ? E.g. second or first ?
If you need only one value, use nth-value. If you need more than one
value, any values you don't use are discarded, so you can use
multiple-value-bind or -setq to get the values you need.
#:Erik
--
Performance is the last refuge of the miserable programmer.
Erik Naggum <····@naggum.net> writes:
> * "Vladimir V. Zolotych" <······@eurocom.od.ua>
> | (let* ((n (/ (* 3600 200) 170))
> | (h (truncate n 3600))
> | (m (rem (truncate n 60) 60))
> | (s (truncate (rem n 60))))
> | (format t "~&~D:~D:~D~%" h m s))
> |
> | this prints
> | 1:10:35
>
> (multiple-value-bind (mm ss) (floor (round (* 3600 200) 170) 60)
> (multiple-value-bind (hh mm) (floor mm 60)
> (format t "~2,'0D:~2,'0D:~2,'0D" hh mm ss)))
>
> Note the use of round instead of / which produces an integer instead of a
> rational number directly.
i like the round idea.
> | Is it possible to make this fragment more clear?
>
> Is the above more clear?
if it's at all unclear, just _add a comment_. that's why we have
them.
;; this breaks the time into hours, minutes and seconds
;; and prints it in a human form like 1:10:35
;; note 24 clock
(multiple-value-bind (mm ss) (floor (round (* 3600 200) 170) 60)
(multiple-value-bind (hh mm) (floor mm 60)
(format t "~2,'0D:~2,'0D:~2,'0D" hh mm ss)))
--
J o h a n K u l l s t a m
[········@ne.mediaone.net]
Don't Fear the Penguin!
This is a multi-part message in MIME format.
--------------668B51906C00689E123B3D3D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Erik Naggum wrote:
> Is the above more clear?
Yes, undoubtedly.
Your version is much more Lisp.
I've asked wrongly. I should ask 'would you mind show me
the good Lisp style for...'.
Thanks.
--
Vladimir Zolotych ······@eurocom.od.ua
--------------668B51906C00689E123B3D3D
Content-Type: text/x-vcard; charset=us-ascii;
name="gsmith.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Vladimir V. Zolotych
Content-Disposition: attachment;
filename="gsmith.vcf"
begin:vcard
n:Zolotych;Valdimir V.
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
·····················@eurocom.od.ua
x-mozilla-cpt:;0
fn:Valdimir V. Zolotych
end:vcard
--------------668B51906C00689E123B3D3D--
"Vladimir V. Zolotych" <······@eurocom.od.ua> writes:
> (let* ((n (/ (* 3600 200) 170))
> (h (truncate n 3600))
> (m (rem (truncate n 60) 60))
> (s (truncate (rem n 60))))
> (format t "~&~D:~D:~D~%" h m s))
>
> this prints
> 1:10:35
>
> Is it possible to make this fragment more clear ?
How about the following?
(let* ((n (/ (* 3600 200) 170))
(h (truncate n 3600))
(m (truncate (rem n 3600) 60))
(s (truncate (rem n 60))))
(format t "~&~D:~D:~D~%" h m s))
That way the three expressions follow the same basic form.
> What is the right way to use only some values from those
> returned by (values 1 2 3) ? E.g. second or first ?
multiple-value-list or -bind?
(let ((dtime (multiple-value-list
(decode-universal-time
(truncate (/ (* 3600 200) 170)) 0))))
(format t "~&~D:~D:~D~%" (third dtime) (second dtime) (first dtime)))
(multiple-value-bind (s m h)
(decode-universal-time (truncate (/ (* 3600 200) 170)) 0)
(format t "~&~D:~D:~D~%" h m s))
--
// John Markus Bj�rndalen