01:40 ACfromTX joined 02:57 avuserow left 03:18 lizmat left 03:59 avuserow joined 09:11 lizmat joined 13:47 habere-et-disper joined, habere-et-disper left 13:48 habere-et-disper joined
habere-et-disper Where is the documentation for Str.new ? 13:54
m: Int.^methods.map( *.name ).grep( 'new' ).say
m: Str.^methods.map( *.name ).grep( 'new' ).say
camelia (new)
()
habere-et-disper Is new missing from Str methods ?
antononcube Not missing, but private, is my conjecture. 13:58
librasteve err in docs.raku.org you can see that class Str is a Cool, Any, Mu from the type diagram docs.raku.org/type/Str#typegraphrelations
so it gets a new method from Mu (I guess) here docs.raku.org/type/Mu#method_new 13:59
you can go Str.^methods to get a list of all methods direct from the compiler
habere-et-disper Seems a little inconsistent to be able to do `Int.new(3)` but not `Str.new(3)` ? 14:00
m: Str.new( 3 ).say
camelia Default constructor for 'Str' only takes named arguments
in block <unit> at <tmp> line 1
habere-et-disper m: Str.new( value => 3 ).say 14:01
camelia 3
librasteve well there is a built in "incosistency" between Num literals which are bare and Str literals which require some kind of quoting and therefore involve the Q slang 14:06
(I don't know this history, but I am not sure there is much need for either Int.new or Str.new in real code thanks to all the literals, assignment, quoting, etc) 14:07
habere-et-disper I'm also a little perplexed by NaN... 14:16
m:  NaN.new(42).WHICH.say
camelia Num|42
habere-et-disper which I imagined was defined immutably as undefined and not a way to create a Num ?
librasteve you are calling .new on the class of the instance - like 1.new(42) dihwidt 14:21
habere-et-disper Weird that one can `.new` an instance but okay. 14:45
I thought though that Type.new was a different case and was calling the default constructor of the Type -- and so providing another way (TIMTOWTDI) to be more implicit in construction ?
librasteve The way I think about it is that raku is "turtles all the way down" - so Type classes are instances of something more fundamental (like Mu) and that all methods are defined on a class. So, in this case, .new is a method on class Mu and Int or Str are the instances of Mu on which the method is called. There is likely some flaw in this reasoning (I am not a student of the rakudo source), but hopefully that 14:52
provides a rationale that when 1 isa Int then the instance 1 (or NaN for Num) inherits the methods of the Type class all the way to Mu.
14:59 habere-et-disper left
ab5tract It may be a bit of an oversight that `NaN` has a new method that produces anything other than `NaN` 17:27
antononcube > [...] "turtles all the way down" Or raccoons, maybe. (They go up too.) 17:47
librasteve m: class C {has $.x}; my $c = C.new(:x(3)); say $c.x; my $o = $c.new(:x(4)); say $o.x; 17:59
Raku eval 3 4 18:00
librasteve I am not sure why the designers of raku decided that $c.new should be a shorthand for C.new - any answers welcome ... but since that's the design, then the behaviour of NaN.new, 1.new and so on is consistent. 18:03
SmokeMachine Any method, by default, works for :_ (that means it works for :D (defined objects) and :U (undefined objects)), unless it defines to use only one of them. If you want, you can create a new candidate to change that… 18:32
m: class C { has $.x; multi new(::?CLASS:U) { !!! } }; my C $c .= new: :4x; say $c.x; $c.new: :3x 18:35
camelia 4
SmokeMachine m: class C { has $.x; multi new(::?CLASS:U:) { !!! } }; my C $c .= new: :4x; say $c.x; $c.new: :3x 18:36
camelia ===SORRY!=== Error while compiling <tmp>
Can only use the : invocant marker in the signature for a method
at <tmp>:1
------> class C { has $.x; multi new(::?CLASS:U:<HERE>) { !!! } }; my C $c .= new: :4x; say $c
SmokeMachine 18:36 <SmokeMachine> m: class C { has $.x; multi new(C:U:) { !!! } }; my C $c .= new: :4x; say $c.x; $c.new: :3x 18:37
m: class C { has $.x; multi new(C:U:) { !!! } }; my C $c .= new: :4x; say $c.x; $c.new: :3x
camelia ===SORRY!=== Error while compiling <tmp>
Can only use the : invocant marker in the signature for a method
at <tmp>:1
------> class C { has $.x; multi new(C:U:<HERE>) { !!! } }; my C $c .= new: :4x; say $c
SmokeMachine m: class C { has $.x; multi method new(::?CLASS:U) { !!! } }; my C $c .= new: :4x; say $c.x; $c.new: :3x # I forgot the method keyword… 18:39
camelia 4
SmokeMachine And the : now… sorry
m: class C { has $.x; multi method new(::?CLASS:U:) { !!! } }; my C $c .= new: :4x; say $c.x; $c.new: :3x # I forgot the method keyword…
camelia Stub code executed
in method new at <tmp> line 1
in block <unit> at <tmp> line 1
librasteve I would hazard a guess that it's emergent behaviour since to get from Mu to something you need a .new as a method on the Mu class type and then to make a new Str you may was well have Str.new call the Mu.new parent. As mentioned above, all type classes are themselves instances of Mu so that means the default is that calling methods on an instance is a shortcut for calling them on the type class. QED 18:53
SmokeMachine All objects are instance of Mu… not only type objects (if I’m not mistaken) 19:11
And I don’t see them as shortcut… but, as I said, a method on a class can be set to run on an instance of that object (:D), on the type class only (:U) or both (:_), if nothing is set, it uses :_ as default (but the default can also be changed) 19:14
librasteve SmokeMachine: yes - thanks for correcting me ... on both points 21:27
22:40 lizmat left