develooper Front page | perl.perl6.users | Postings from September 2021

Different behavior for strings and strings in variables withmulti-dispatch using a subset

Thread Next
From:
Joseph Brenner
Date:
September 23, 2021 00:49
Subject:
Different behavior for strings and strings in variables withmulti-dispatch using a subset
Message ID:
CAFfgvXVVRd=dU030+Y5n-i-ZQOROn=cfxvrOpa49=9p-Ktj2gw@mail.gmail.com
In this code I'm using multi-dispatch with a subset type that
makes string values special: "wuhn", "tew" and "thuree".

    use Test;

    multi sub whats_my_type (Str $item) {
        return "This is a Str: $item";
    }

    subset GoofyNum of Str where { $_ eq any( 'wuhn', 'tew', 'thuree' ) };
    multi sub whats_my_type (GoofyNum $item) {
        return "This is a GoofyNum string: $item";
    }

    {
        my ($ret, $arg);
        $ret =  whats_my_type('two');
        like $ret, /<< Str >>/, "quoted string argument of 'two' is Str";

        $ret = whats_my_type('tew');
        like $ret,  /<< GoofyNum >>/, "quoted string argument of
'wuhn' is 'goofy'";

        $arg = "one";
        $ret = whats_my_type( $arg );
        like $ret, /<< Str >>/, "string in var argument of '$arg' is Str";

        $arg = "whun";
        $ret = whats_my_type( $arg );
        like $ret, /<< GoofyNum >>/, "string in var argument of 'wuhn'
is 'goofy'";
    }


I would think all four of these tests should pass, instead I see
the last one failing: for some reason there's a difference in the
case of a simple quoted string, and a string inside a variable.

Any comments?


raku --version
Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2020.10.
Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.
Built on MoarVM version 2020.10.

uname -a
Linux fandango 4.9.0-8-686 #1 SMP Debian 4.9.144-3 (2019-02-02) i686 GNU/Linux

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About