On 2019-12-07 22:43, William Michels via perl6-users wrote:
On Sat, Dec 7, 2019 at 9:36 PM ToddAndMargo via perl6-users
<perl6-us...@perl.org> wrote:
On 2019-12-07 18:30, Mark Senn wrote:
Corrected section
my %h = a => "x", b=>"r", c=>"z";
if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
DOES NOT exist
if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
exists
Hi.
The following code prints DOES NOT exist twice.
my %h = a => "x", b=>0, c=>"z";
if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
I changed the b=>"r" to b=>0. I think it is evaluating
the b element as a boolean---I think the exists adverb
needs to be used to check for existence.
-m
Hi Mark,
Oh bugger!
This is what I get:
$ perl6
To exit type 'exit' or '^D'
> my %h = a => "x", b=>"r", c=>"z";
{a => x, b => r, c => z}
> if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
DOES NOT exist
> if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
exists
Would someone else please run my code and see if
they can reproduce Mark's error?
Many thanks,
-T
Mark is correct. Changing values to 1 or 0 results in if/else
evaluating as a True/False:
mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
my %i = a => 1, b=> 0, c=> 1;
{a => 1, b => 0, c => 1}
if %i<a> { say "exists"; } else { say "DOES NOT exist"; }
exists
if %i<b> { say "exists"; } else { say "DOES NOT exist"; }
DOES NOT exist
if %i<d> { say "exists"; } else { say "DOES NOT exist"; }
DOES NOT exist
$*VM
moar (2019.07.1)
HTH, Bill.
Thank you.
Back to the drawing board. I think there is an adverb for this.