Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

12:31:23

5 views
Skip to first unread message

Vladimir V. Zolotych

unread,
Dec 31, 2000, 6:45:45 AM12/31/00
to
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 gsm...@eurocom.od.ua

gsmith.vcf

jo...@cs.uit.no

unread,
Dec 31, 2000, 10:11:46 AM12/31/00
to
"Vladimir V. Zolotych" <gsm...@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

Johan Kullstam

unread,
Dec 31, 2000, 11:19:39 AM12/31/00
to
Erik Naggum <er...@naggum.net> writes:

> * "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!

Vladimir V. Zolotych

unread,
Jan 1, 2001, 11:47:02 AM1/1/01
to
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 gsm...@eurocom.od.ua

gsmith.vcf

Erik Naggum

unread,
Dec 31, 2000, 9:28:19 AM12/31/00
to
* "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.

| 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.

0 new messages