multiple-value-bind discard first value
Asked Answered
B

2

10

In my code below , I only want r.

(let* ((frac  (multiple-value-bind (f r)  (floor amt  100) r)))
..use frac..)

I get compilation warnings saying unused variable f.

Is there an idiomatic way of writing this?

Blackfoot answered 26/4, 2014 at 23:52 Comment(3)
What's the intent of the code you have there?Septuplicate
A warning isn't necessarily an error so it should work. It's nice that the compiler warns since it could be a bug.Annulus
Some implementations allow *, **, *** etc as names that indicate an unused variable.Starknaked
G
14

declare ignore is generally useful in this context, here:

(multiple-value-bind (_ frac)  (floor amt 100)
  (declare (ignore _))
  ; use frac)
Gregoriagregorian answered 27/4, 2014 at 7:47 Comment(0)
A
8

NTH-VALUE allows you to choose one of a form's return values. This will behave like your snippet:

(let* ((frac (nth-value 1 (floor amt 100))))
  ...)
Atwekk answered 27/4, 2014 at 4:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.