in reply to Re^2: RFC: Destructuring Assignment (aka Unpacking aka Type Patterns) in pure Perl
in thread RFC: Destructuring Assignment (aka Unpacking aka Type Patterns) in pure Perl

Sort of like your slice, but you also can provide default values if things are missing. E.g. if arg_map didn't have anything at the key :foo the variable foo would get be the string "foo missing".

(let [{:keys [foo bar] :or {foo "foo missing"}} arg_map] ;; ... )

You'd prossibly need something like my $foo = exists $arg_map{foo} ? $arg_map{foo} : "foo missing" and you'd need to do each variable separately. (I've not messed with clojure in long enough that I'm probably explaining this poorly, to boot . . .)

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^4: RFC: Destructuring Assignment (aka Unpacking aka Type Patterns) in pure Perl
by LanX (Saint) on Jul 04, 2020 at 10:35 UTC
    Individual defaults are no problem.

    set my $var= DEFAULT

    does it already.

    If there is no prior value, it will be undef because of my .

    If you need a dedicated Missing different from undef I could return an error object.

    Implementation is no problem, I'd need to think about the best API.

    There might also be the case of reused variables - like in a loop - were you skipped the my, but don't want to default to the prior value but undef.

    set $var

    Again only a question of designing a intuitive API/Syntax and testing use cases.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) my defaults to undef