Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does command after if False produce an empty list in Perl 6 REPL?

Tags:

raku

If the condition of if is False, instead of empty output, REPL gives () (an empty List?)

> put 1 if True
1
> put 1 if False
()               # ← What is this?

What does () mean?

like image 539
Eugene Barsky Avatar asked Oct 02 '18 18:10

Eugene Barsky


1 Answers

All answers so far are excellent, explaining what's going on under the hood. But I'll try to answer your question directly.

If the condition of if is False, instead of empty output, REPL gives () (an empty List?)

The key to this is that you're working on the REPL. The REPL prints the output of a block if there's some; if there's no output, it prints whatever the expression returns. Let's then deal with your two options as blocks; what is inside the parentheses is what you would actually type in the REPL:

say (put 1 if True).^name # OUTPUT: «1␤Bool␤»

That's right. The REPL will see the output, 1, and print that. The block result, True in this case since that's what put returns, is dropped by the REPL. What happens in the second case?

say (put 1 if False).^name # OUTPUT: «Slip␤»

In this case, there's no output. The REPL would take (put 1 if False) as an expression, and prints () which, in this case, is a Slip. As indicated in @raiph answer, that's what if False {} returns, so that's what you get in your REPL.

like image 170
jjmerelo Avatar answered Nov 03 '22 16:11

jjmerelo