There seems to be some inconsistencies in the argument syntax in the interpreter. I am using the latest Rakudo. Please see the following terminal output:
$ perl6
To exit type 'exit' or '^D'
> say: "foo"
foo
> say("foo")
foo
> say "foo"
===SORRY!=== Error while compiling:
Two terms in a row
------> say⏏ "foo"
expecting any of:
infix
infix stopper
statement end
statement modifier
statement modifier loop
>
$ perl6
To exit type 'exit' or '^D'
> say "foo"
foo
> say("foo")
foo
> say: "foo"
foo
> say "foo"
===SORRY!=== Error while compiling:
Two terms in a row
------> say⏏ "foo"
expecting any of:
infix
infix stopper
statement end
statement modifier
statement modifier loop
>
$
It seems that after you have used the ":
" or "()
" to supply the arguments, you cannot go back to use "", i.e., space, to supply arguments.
Or did I miss something?
Thanks !!!
lisprog
say: "foo"
That line does not call the say
subroutine.
Instead, it declares a statement label with the name say
, and then executes the statement "foo"
(which does nothing).
The only reason it printed "foo"
in your case, is because you entered it into the REPL, which automatically prints the value of the last statement of each line.
If you had used it in a normal program, it would have actually thrown the warning Useless use of constant string "foo" in sink context
.
say "foo" ===SORRY!=== Error while compiling: Two terms in a row ------> say⏏ "foo" expecting any of: infix infix stopper statement end statement modifier statement modifier loop
After you've declared the label, the symbol say
in this scope no longer refers to the built-in subroutine with that name but rather to your custom label, and it is a syntax error to use a label like that.
The error message should ideally explain that, though. I've submitted a Rakudo ticket for that.
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