What is the meaning of (Any) in Raku - specifically the ()?

前端 未结 3 679
孤独总比滥情好
孤独总比滥情好 2021-01-17 12:44

Here is an experiment with Raku:

> my $x
(Any)
> my $y=1
1
> my @a=[1, 2]
[1 2]
> my %h=a=>\'b\'
{a => b}
> say \"nil\" unless $x
nil
         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 13:22

    When you use the REPL, the result of the expression is shown using say. The say function calls the .gist function on the expression.

    Any is a type-object. Type-objects have a .gist method that puts the parentheses around them.

    The put function is almost the same as the say function, but it calls the .Str function on the expression. And that produces a warning, because you cannot really stringify a type object. Observe the difference:

    $ raku -e 'say Any'
    (Any)
    
    # raku -e 'put Any'
    Use of uninitialized value of type Any in string context.
    Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
      in block  at -e line 1
    

    See Classes and Objects, Type System, Type Objects for more information.

提交回复
热议问题