[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

ignoring the same argument multiple times in destructuring-bind

Jim Newton

5/20/2016 9:07:00 AM

SBCL warns me that _IGNORE is defined but never used. However, it looks to me like I've declared it as ignore. Is this an sbcl bug, or do I really need to use 7 different variables _ignore1, _ignore2 etc, and marked all 6 as ignore in the declaration?

(destructuring-bind (_ignore _ignore ; let arglist
(_ignore _ignore ; typecase var
_ignore ; case1
_ignore ; case2
(type3 &rest _ignore ))) expanded
(declare (ignore _ignore))
type3)
9 Answers

Elias Mårtenson

5/20/2016 11:27:00 AM

0

On Friday, 20 May 2016 17:06:43 UTC+8, Jim Newton wrote:
> SBCL warns me that _IGNORE is defined but never used. However, it looks to me like I've declared it as ignore. Is this an sbcl bug, or do I really need to use 7 different variables _ignore1, _ignore2 etc, and marked all 6 as ignore in the declaration?
>
> (destructuring-bind (_ignore _ignore ; let arglist
> (_ignore _ignore ; typecase var
> _ignore ; case1
> _ignore ; case2
> (type3 &rest _ignore ))) expanded
> (declare (ignore _ignore))
> type3)

You can always use a macro to do this for you. One way is to use OPTIMA:

(optima:multiple-value-match (values 1 2 3)
((_ _ v) (print v)))

Prints:

3

Marco Antoniotti

5/20/2016 1:49:00 PM

0

On Friday, May 20, 2016 at 1:27:28 PM UTC+2, Elias Mårtenson wrote:
> On Friday, 20 May 2016 17:06:43 UTC+8, Jim Newton wrote:
> > SBCL warns me that _IGNORE is defined but never used. However, it looks to me like I've declared it as ignore. Is this an sbcl bug, or do I really need to use 7 different variables _ignore1, _ignore2 etc, and marked all 6 as ignore in the declaration?
> >
> > (destructuring-bind (_ignore _ignore ; let arglist
> > (_ignore _ignore ; typecase var
> > _ignore ; case1
> > _ignore ; case2
> > (type3 &rest _ignore ))) expanded
> > (declare (ignore _ignore))
> > type3)
>
> You can always use a macro to do this for you. One way is to use OPTIMA:
>
> (optima:multiple-value-match (values 1 2 3)
> ((_ _ v) (print v)))
>
> Prints:
>
> 3

Or, shameless plug, you can use something customizable like CL-UNIFICATION.

Cheers
--
MA

taruss

5/20/2016 4:56:00 PM

0

On Friday, May 20, 2016 at 2:06:43 AM UTC-7, Jim Newton wrote:
> SBCL warns me that _IGNORE is defined but never used. However, it looks to me like I've declared it as ignore. Is this an sbcl bug, or do I really need to use 7 different variables _ignore1, _ignore2 etc, and marked all 6 as ignore in the declaration?
>
> (destructuring-bind (_ignore _ignore ; let arglist
> (_ignore _ignore ; typecase var
> _ignore ; case1
> _ignore ; case2
> (type3 &rest _ignore ))) expanded
> (declare (ignore _ignore))
> type3)

You probably have a more complicated real use-case, but for this simple example, I might be tempted to do something more specialized such as

(let ((type3 (first (fifth expanded)))) ...)

or better yet:

(let ((type3 (get-nth-typecase-type 2 expanded))) ...)

(defun get-nth-typecase-type (n typecase-form)
(assert (eq (first typecase-form) 'typecase))
(first (nth n (cddr typecase-form))))

If you need to bind more than one variable, then one of the other matching
suggestions would be better.

Kaz Kylheku

5/20/2016 6:09:00 PM

0

On 2016-05-20, Jim Newton <jimka.issy@gmail.com> wrote:
> SBCL warns me that _IGNORE is defined but never used. However, it
> looks to me like I've declared it as ignore. Is this an sbcl bug, or
> do I really need to use 7 different variables _ignore1, _ignore2 etc,
> and marked all 6 as ignore in the declaration?
>
> (destructuring-bind (_ignore _ignore ; let arglist
> (_ignore _ignore ; typecase var
> _ignore ; case1
> _ignore ; case2
> (type3 &rest _ignore ))) expanded
> (declare (ignore _ignore))
> type3)


There is something glaring here, namely that you're using the same
symbol _ignore multiple times in the same binding construct.

This violates 3.1.1 Introduction to Environments:

"A single name can simultaneously have more than one associated
binding per environment, but can have only one associated binding per
namespace."

The spec is mum about this issue everywhere else.

A parallel binding construct which repeats a variable is ambiguous.
What should this yield?

(let ((a 1) (a 2)) a)

So even if that above requirement in 3.1.1 weren't stated, we could not
be confident that this has a well-defined behavior.

Lisp implementations tend not to be consistent in diagnosing this,
unfortunately.

This issue could be somehow linked to the unexpected error
message. Replace all the ignored places in the template with
unique symbols, declare-ignore all of them and try again with
conforming code.

Barry Margolin

5/20/2016 10:43:00 PM

0

In article <f7609236-5b46-4d5d-af44-db7803c018b5@googlegroups.com>,
Jim Newton <jimka.issy@gmail.com> wrote:

> SBCL warns me that _IGNORE is defined but never used. However, it looks to
> me like I've declared it as ignore. Is this an sbcl bug, or do I really need
> to use 7 different variables _ignore1, _ignore2 etc, and marked all 6 as
> ignore in the declaration?
>
> (destructuring-bind (_ignore _ignore ; let arglist
> (_ignore _ignore ; typecase var
> _ignore ; case1
> _ignore ; case2
> (type3 &rest _ignore ))) expanded
> (declare (ignore _ignore))
> type3)

CLtL says that you can use NIL in a destructuring lambda list to
indicate a place that shouldn't be assigned to a variable. But I can't
find this in CLHS.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

taruss

5/20/2016 11:29:00 PM

0

On Friday, May 20, 2016 at 3:43:33 PM UTC-7, Barry Margolin wrote:
>
> CLtL says that you can use NIL in a destructuring lambda list to
> indicate a place that shouldn't be assigned to a variable. But I can't
> find this in CLHS.

I don't think it made it into the CL spec.
AFAIK it only works inside the LOOP macro.

Destructuring-bind uses the lambda-list syntax and that doesn't allow NIL as a
variable name. But it would be nice if it did.


rpw3

5/22/2016 10:20:00 AM

0

<taruss@google.com> wrote:
+---------------
| Barry Margolin wrote:
| > CLtL says that you can use NIL in a destructuring lambda list to
| > indicate a place that shouldn't be assigned to a variable. But I
| > can't find this in CLHS.
|
| I don't think it made it into the CL spec.
| AFAIK it only works inside the LOOP macro.
+---------------

It does work in LOOP in at least CMUCL & CCL:

(loop for (a b nil c nil nil d e) = '(1 2 3 4 5 6 7 8 9)
return (list a b c d e nil nil))
==>
(1 2 4 7 8 NIL NIL)


-Rob

-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw...
San Mateo, CA 94403

Alberto Riva

5/22/2016 4:37:00 PM

0

On 05/22/2016 06:19 AM, Rob Warnock wrote:
> <taruss@google.com> wrote:
> +---------------
> | Barry Margolin wrote:
> | > CLtL says that you can use NIL in a destructuring lambda list to
> | > indicate a place that shouldn't be assigned to a variable. But I
> | > can't find this in CLHS.
> |
> | I don't think it made it into the CL spec.
> | AFAIK it only works inside the LOOP macro.
> +---------------
>
> It does work in LOOP in at least CMUCL & CCL:
>
> (loop for (a b nil c nil nil d e) = '(1 2 3 4 5 6 7 8 9)
> return (list a b c d e nil nil))
> ==>
> (1 2 4 7 8 NIL NIL)

And also in Allegro CL and CLISP.

Alberto


Jim Newton

5/23/2016 8:09:00 AM

0

I was under the impression that nil in a destructuring lambda list
matches ONLY the empty list, as it is an empty list of variable names.

Although it would be great if destructuring-bind had a notation for specifying
variables to omit binding. t (or any constant symbol other than nil) would be
a good candidate.

On the other hand I think the warning from SBCL is wrong, but it sounds like
nobody agrees with my opinion.