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 gsm...@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
>
> 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
> * "Vladimir V. Zolotych" <gsm...@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
[kull...@ne.mediaone.net]
Don't Fear the Penguin!
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 gsm...@eurocom.od.ua
(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.