GNU bug report logs - #45619
No warning when pcase-let is binding dynamic variable

Previous Next

Package: emacs;

Reported by: jixiuf <jixiuf <at> qq.com>

Date: Sun, 3 Jan 2021 09:05:01 UTC

Severity: normal

Found in version 28.0.50

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: jixiuf <jixiuf <at> qq.com>, 45619 <at> debbugs.gnu.org
Subject: bug#45619: 28.0.50; pcase-let on MacOS doesn't work
Date: Thu, 07 Jan 2021 10:19:46 -0500
>> Hmm... so-called "non-linear patterns".  We should emit a warning when the
>> same var is used twice in a pattern, indeed, to avoid surprises.
>
> Not sure if we speak about the same case.  I spoke about this: I caught
> myself trying something like that:
>
> (defvar thing-tag 'a-thing)
>
> (let ((my-thing (cons thing-tag '(thing-contents...))))
>   (pcase my-thing
>     (`(,thing-tag . ,contents) (do-something-with contents))))

Ah, indeed it's not the same thing as non-linear patterns.

An example of a non-linear pattern could be:

    (pcase foo
      (`(,a . ,a)
       (message "foo is a pair with car equal to cdr"))
      ...)

For your use case, you can write:

      (pcase my-thing
        (`(,(pred (equal thing-tag)) . ,contents) (do-something-with contents))))

> Something diametral to my previous suggestion, I don't know if it would
> be appropriate: You know scheme syntax rules and it's concept of
> hygiene?  Similarly in `pcase' we could silently transform any
> appearance of a SYMBOL with a fresh uninterned symbol.  While that would
> not change the behavior for the common use cases, it would be clear that
> bindings created by pcase would never interfere in any way with already
> existing bindings of any kind.

I know about macro hygiene, but what you describe is a mechanism
to get a particular semantics (a form a hygiene, typically), but I don't
understand what semantics you're trying to get.

Could you give some examples of problems you'd like to avoid this way?

> Being able to change the binding of a special variable sounds nice, but
> I think that could also happen by accident, right?

As I said, I think we should declare this is unsupported and try to emit
a warning what we detect such a thing (tho we should still support
corner cases like

    (pcase-let
        (((,foo . ,bar) (blabla))
         (default-directory (blibli)))
      ...)


        Stefan





This bug report was last modified 3 years and 112 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.