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?
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: «1Bool»
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With