What use are `case` bindings? (was: What use [...] sneak[...])

Michael P. empro2@REDACTED
Wed Aug 18 22:51:00 CEST 2021


On Wed, 18 Aug 2021 13:17:44 +0100
Karl Velicka <karolis.velicka@REDACTED> wrote:

> Thanks,

Thank _you_!
I have evidently but not obviously edited it to death.
I tried to be concise, but the info in the text deleted
was still in my mind and ... death edit.

Hope I didn't delete too quickly ... 8-(

All the fine explanations ...
"lost in time, like -- tears in the rain."

---------------

Being '(let)-y' is to mean that it all has its own scope,
like a `fun` has, from its recursion name,
through the pattern list of each clause,
and any guard sequences,
to the expression sequence in each clause.

Making `case` behave '(let)-y' would prevent it
from creating any bindings that exist beyond its `end`
or could not-match with a binding from before `case`.

The "legacy wall" means 'Cannot be changed,
because everyone has used it everywhere.'

F...ine! There is no "slot-machine" ...

Did `case` once behave like this?
put a variable getting bound in a pattern
outside the `case` only if the
variable occurred in the pattern of each clause?

I cannot find mention of such now.
The notes were a bit old;
trying to follow some netiquette
I try to have a thought of my own
before stealing other people's time with postings.

----------------

The only thing remaining a bit "sneaky",
is that I cannot find now any mention of
the bindings `case` can create; bindings
that live on beyond `end` and can collide
with non-matching bindings from before `case`.

So the question can be altered into:

What use are `case` bindings?

    "Strictly speaking, `case` is unnecessary.
     This is how filter would have been defined
     using pure pattern matching: [module functions]"

    -- Sec. 4.8, p. 68, _Programming_Erlang_Second_Edition_,
       by Joe Armstrong, edited by S. D. Pfalzer

What is unpure about `case` pattern matching?

When `case` is explained, there is little binding at all.
And with it looking like a function and

    "The return value of Body is
     the return value of the case expression."

    -- https://erlang.org/doc/reference_manual/expressions.html

people, like me, might think it was as '(let)-y' as a `fun` --
and use it that way, raising the last of the orginal questions:

What would one lose when "unpure" `case` scared
one into some

    Switch = ...,
    Result = (fun Case(...) when ... -> ...;
                  Case(...) when ... -> ...
              end)(Switch),
?

~M

--

The clever man acquires the knowledge of other clever men;
the sage can also learn from the fool.






More information about the erlang-questions mailing list