Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use .WHAT in examples to print the type info #1355

Closed
zoffixznet opened this issue Jun 1, 2017 · 6 comments
Closed

Don't use .WHAT in examples to print the type info #1355

zoffixznet opened this issue Jun 1, 2017 · 6 comments
Assignees
Labels
docs Documentation issue (primary issue type) xt Regarding current or new xt/ tests or the utils/

Comments

@zoffixznet
Copy link
Contributor

zoffixznet commented Jun 1, 2017

It's not quite the right tool for the job

Currently there's a ton of uses many of which shouldn't be using .WHAT:

zoffix@leliana/tmp/tmp.jxnsvMuh21 (master)$ grep -FR '.WHAT'
doc/Language/functions.pod6:multi mistake-proto($str, $number) { say $str.WHAT }
doc/Language/functions.pod6:   say $bar.WHAT; # OUTPUT: «(Bar)␤»
doc/Language/typesystem.pod6:    say $a.WHAT;
doc/Language/typesystem.pod6:identity between the object and its C<.WHAT> pseudo-method. Note that the
doc/Language/typesystem.pod6:    say so $a // $a === $a.WHAT;
doc/Language/typesystem.pod6:    say A.new.WHAT;    # OUTPUT: «(A)␤»
doc/Language/typesystem.pod6:    say $a.WHAT;     # OUTPUT: «(Names)␤»
doc/Language/typesystem.pod6:    say one.WHAT; # OUTPUT: «()␤»
doc/Language/typesystem.pod6:    say $e.WHAT;  # OUTPUT: «(Map)␤»
doc/Language/variables.pod6:    say @bar.WHAT;          # OUTPUT: «(Array)␤»
doc/Language/variables.pod6:    say $baz.WHAT;          # OUTPUT: «(List)␤»
doc/Language/faq.pod6:    say @a.WHAT;            # OUTPUT: «(Array)␤»
doc/Language/faq.pod6:    say $scalar.WHAT;       # OUTPUT: «(Array)␤»
doc/Language/exceptions.pod6:            say .WHAT.perl, do given .backtrace[0] { .file, .line, .subname }
doc/Language/classtut.pod6:    say $o.WHAT;
doc/Language/classtut.pod6:The C<.WHAT> method returns the type object associated with the object
doc/Language/classtut.pod6:know about, finding its type with C<.WHAT>, seeing a construction recipe for
doc/Language/containers.pod6:    say @a.WHAT;                # OUTPUT: «(List)␤»
doc/Language/5to6-nutshell.pod6:        say $query.WHAT;       # (Block)
doc/Language/objects.pod6:    my $int-type-obj = 1.WHAT;
doc/Language/objects.pod6:    if $x.WHAT B<L<===>> Int {
doc/Language/5to6-perlfunc.pod6:use C<$var.WHAT.perl>.  If you really want P5 ref
doc/Language/subscripts.pod6:    say $request.header.WHAT;  # OUTPUT: «(HTTP::Header)␤»
doc/Language/rb-nutshell.pod6:    $person.WHAT              # Perl 6, returns Person (class)
doc/Language/glossary.pod6:    say <42>.WHAT;     # OUTPUT: «(IntStr)␤»
doc/Language/glossary.pod6:    say <42.1e0>.WHAT; # OUTPUT: «(NumStr)␤»
doc/Language/glossary.pod6:    say <42.1>.WHAT;   # OUTPUT: «(RatStr)␤»
doc/Language/glossary.pod6:    say <42/1>.WHAT;   # OUTPUT: «(Rat)␤»
doc/Language/glossary.pod6:    say <42+0i>.WHAT;  # OUTPUT: «(Complex)␤»
doc/Language/glossary.pod6:    say < 42+0i >.WHAT;# OUTPUT: «(ComplexStr)␤»
doc/Language/glossary.pod6:    say < 42/1 >.WHAT; # OUTPUT: «(RatStr)␤»
doc/Language/mop.pod6:For example C<42.WHAT> returns the C<Int> type object.
doc/Type/ComplexStr.pod6:    my $f = <42+0i>; say $f.WHAT; # OUTPUT: «(ComplexStr)␤»
doc/Type/Pair.pod6:    say $manna.WHAT;
doc/Type/Pair.pod6:    say $manna.WHAT;
doc/Type/Pair.pod6:    say $p.pairs.WHAT; # OUTPUT: «(List)␤»
doc/Type/Pair.pod6:    say $p.WHAT;                                      # OUTPUT: «(List)␤»
doc/Type/Pair.pod6:    say $p.first.WHAT;                                # OUTPUT: «(Pair)␤»
doc/Type/Scalar.pod6:    $a.WHAT.say;     # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    $a.VAR.WHAT.say; # OUTPUT: «(Scalar)␤»
doc/Type/Scalar.pod6:    $b.WHAT.say;     # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    $b.VAR.WHAT.say; # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    @a[0].WHAT.say;            # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    @a[0].VAR.WHAT.say;        # OUTPUT: «(Scalar)␤»
doc/Type/Scalar.pod6:    [1, 2, 3][0].WHAT.say;     # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    [1, 2, 3][0].VAR.WHAT.say; # OUTPUT: «(Scalar)␤»
doc/Type/Scalar.pod6:    (1, 2, 3)[0].WHAT.say;     # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    (1, 2, 3)[0].VAR.WHAT.say; # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    c.WHAT.say;              # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    c.VAR.WHAT.say;          # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    d.WHAT.say;              # OUTPUT: «(Int)␤»
doc/Type/Scalar.pod6:    d.VAR.WHAT.say;          # OUTPUT: «(Scalar)␤»
doc/Type/Parameter.pod6:    sub b($x) { $x.WHAT.say }                   # does the same thing, but uglier.
doc/Type/Whatever.pod6:    say (1..*).WHAT;        # OUTPUT: «(Range)␤»
doc/Type/Whatever.pod6:    say (1..*-1).WHAT;      # OUTPUT: «(WhateverCode)␤»
doc/Type/IntStr.pod6:    my $f = <42>; say $f.WHAT; # OUTPUT: «(IntStr)␤»
doc/Type/Block.pod6:    say $block.WHAT;            # OUTPUT: «(Block)␤»
doc/Type/Sub.pod6:    say $s.WHAT;        # OUTPUT: «(Sub)␤»
doc/Type/Dateish.pod6:    say $dt.formatter.WHAT;           # OUTPUT: «(Callable)␤»
doc/Type/Dateish.pod6:    say $dt.formatter.WHAT;           # OUTPUT: «(Sub)␤»
doc/Type/Signature.pod6:    sub f(Int(Str) $want-int, Str() $want-str) { say $want-int.WHAT, $want-str.WHAT }
doc/Type/Signature.pod6:    sub foo(Date(Str) $d) { say $d.WHAT; say $d };
doc/Type/Signature.pod6:    sub a(Int $i, Str $s) { say $i.WHAT, $s.WHAT }
doc/Type/Signature.pod6:    sub b(|c) { say c.WHAT; a(|c) }
doc/Type/RatStr.pod6:    my $f = <42.1>; say $f.WHAT; # OUTPUT: «(RatStr)␤»
doc/Type/UInt.pod6:  say $u.WHAT;     # OUTPUT: «(Int)␤» - UInt is a subset, so the type is still Int.
doc/Type/UInt.pod6:  say $i.WHAT;     # OUTPUT: «(Int)␤»
doc/Type/Rat.pod6:    say approx-sqrt(2, 5).WHAT;     # OUTPUT: «(Rat)␤»
doc/Type/Rat.pod6:    say approx-sqrt(2, 10).WHAT;    # OUTPUT: «(Num)␤»
doc/Type/Regex.pod6:    say &R.WHAT; # OUTPUT: «(Regex)␤»
doc/Type/NumStr.pod6:    my $f = <42.1e0>; say $f.WHAT; # OUTPUT: «(NumStr)␤»
doc/Type/Hash.pod6:    say %h<a>.WHAT;             # OUTPUT: «(Pair)␤»
doc/Type/Hash.pod6:    say $h.WHAT;                # OUTPUT: «Hash␤»
doc/Type/Hash.pod6:        say $query.WHAT;       # OUTPUT: «Block␤»
doc/Type/Hash.pod6:say $query.WHAT;         # OUTPUT: «Hash␤»
doc/Type/Hash.pod6:say %query.WHAT;         # OUTPUT: «Hash␤»
doc/Type/Hash.pod6:        say $query.WHAT;     # OUTPUT: «Hash␤»
doc/Type/List.pod6:    say (1,2,3,4).WHAT;        # OUTPUT: «(List)␤»
doc/Type/List.pod6:    say (1,2,3,4).values.WHAT; # OUTPUT: «(Seq)␤»
doc/Type/List.pod6:    say ('hello', 1, 22/7, 42, 'world').map: { .WHAT.perl } # OUTPUT: «(Str Int Rat Int Str)␤»
doc/Type/Baggy.pod6:    say $h.WHAT;                                      # OUTPUT: «(Hash[Any,Any])␤»
doc/Type/Baggy.pod6:    say $sh.WHAT;                                     # OUTPUT: «(SetHash)␤»
doc/Type/Str.pod6:    say val("42").WHAT;    # OUTPUT: «(IntStr)␤»
doc/Type/Str.pod6:    say val("42e0").WHAT;  # OUTPUT: «(NumStr)␤»
doc/Type/Str.pod6:    say val("42.0").WHAT;  # OUTPUT: «(RatStr)␤»
doc/Type/Str.pod6:    say val("42+0i").WHAT; # OUTPUT: «(ComplexStr)␤»
zoffix@leliana/tmp/tmp.jxnsvMuh21 (master)$ 
@zoffixznet zoffixznet added the docs Documentation issue (primary issue type) label Jun 1, 2017
@JJ
Copy link
Contributor

JJ commented Jun 2, 2017 via email

@AlexDaniel
Copy link
Member

.^name ?

@zoffixznet
Copy link
Contributor Author

zoffixznet commented Jun 2, 2017

Any suggestion?

.^name ?

Yes, .^name it returns the full name of the target, as a string and not a type object, and can be used as a whatevercode too, and has a clearer meaning behind its name than both .WHAT and .WHO

@coke
Copy link
Collaborator

coke commented Jul 27, 2017

Here's a problem:

doc/Type/Whatever.pod6 would then change to:

say (1..*-1).^name;

which outputs

{ ... }

Not

WhateverCode, as .WHAT does.

How would you like to deal with this case?

@coke coke self-assigned this Jul 27, 2017
@coke coke added experimental xt Regarding current or new xt/ tests or the utils/ and removed experimental labels Jul 27, 2017
@coke
Copy link
Collaborator

coke commented Jul 27, 2017

I have a local modification to xt/examples-compilation.t that catches the use of .WHAT unless we've whitelisted the test with :ok-test

Just need feedback on what you want that one example to look like.

coke added a commit that referenced this issue Jul 27, 2017
@coke
Copy link
Collaborator

coke commented Jul 27, 2017

Chat points out that

((1..*-1)).^name

works. Using that, closing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type) xt Regarding current or new xt/ tests or the utils/
Projects
None yet
Development

No branches or pull requests

4 participants