»ö« Welcome to Perl 6! | perl6.org/ | evalbot usage: 'p6: say 3;' or rakudo:, or /msg camelia p6: ... | irclog: irc.perl6.org or colabti.org/irclogger/irclogger_logs/perl6 | UTF-8 is our friend!
Set by moritz on 22 December 2015.
zengargoyle hrm. Supply.tap acts on each line as it arrives. Channel waits until the file is read in full. not sure i grok yet. :| 00:08
SmokeMachine Is there anything equivalente to Java’s hashCode for perl6? 03:13
araraloren m: say 1.WHICH 03:24
camelia Int|1
araraloren m: say 1.WHICH; my $a; say $a.WHICH; 03:25
camelia Int|1
Any|U16722968
araraloren SmokeMachine, do you mean this ?
SmokeMachine araraloren: a method that returns a Int depending of the content of the object 03:26
I mean a hash function... 03:27
araraloren I think hash has many kinds of implementation 03:28
SmokeMachine Yes, but default classes haven’t default hash functions? 03:28
araraloren What does that hash function for ? 03:29
I don't know well Java 03:30
Or SmokeMachine , what are you trying to do 03:31
SmokeMachine I wrote a a A/B test classifier in kotlin that I’m translating to perl6... part that uses the hashCode is something like this: val testGroup = groups[userIdentifier.hashCode % groups.size] // simplified version 03:33
araraloren It's like a group factory ? 03:35
SmokeMachine Sorry, I dodnt get what means “group factory”...
araraloren Oh 03:36
You want get a group of a particular user? 03:37
SmokeMachine The hashCode, for the same object will always return the same Int...
araraloren Identify by that `userIdentifier.hashCode` 03:38
SmokeMachine Yes
araraloren you wan store them in Hash
SmokeMachine The true conde used a test Id as a salt:
araraloren my %hash = userIdentifier => $group; and somewhere my $testGroup = %hash{userIdentifier}; 03:39
s/wan/can/
SmokeMachine val testGroup = groups[“$userIdentifier $testIdentifier”.hashCode % groups.size] 03:40
araraloren m: my %hash = 'A' => "Group A", B => "Group B"; say %hash{'A'}; say %hash<A>;
camelia Group A
Group A
araraloren m: class AG {}; class BG {}; my %hash = 'A' => AG.new, B => B.new; dd %hash{'A'}; dd %hash<B>; 03:41
camelia 5===SORRY!5=== Error while compiling <tmp>
Undeclared name:
B used at line 1
araraloren m: class AG {}; class BG {}; my %hash = 'A' => AG.new, B => BG.new; dd %hash{'A'}; dd %hash<B>;
camelia AG %hash = AG.new
BG %hash = BG.new
araraloren SmokeMachine, Is ^ help? 03:43
SmokeMachine No, that’s not what I want... I need to answer to the user what group it is participating on a specified a/b test and always give the same answer...
araraloren yeah, that Hash always given you same value when you given them same key 03:44
SmokeMachine I don’t what to record any data...
I just want a hash function... 03:45
araraloren Oh, But I recommend you do that in Perl 6 way
araraloren A hash function is no need 03:46
SmokeMachine This is what I want: en.m.wikipedia.org/wiki/Java_hashCode()
Yes, I need...
araraloren If you want a hash function, I think you have to write it yourself SmokeMachine 03:48
SmokeMachine We probably have a hash function for Str... it must be used on the Hash class... 03:49
timotimo m: set(1, 2, "foo", "bar").WHICH.say
camelia Set|F5FB15BD0FAD0FEA9366E0DF58948C292A378E77
timotimo :P
well, it's not an integer
araraloren As I say, Hash has a lot of implementation 03:50
SmokeMachine m: say 42.WHERE 03:52
camelia 140366095598312
araraloren This is a memory address, I think 03:53
SmokeMachine But it changes... :(
I know...
ugexe m: use nqp; say nqp::sha1("xxx")
camelia B60D121B438A380C343D5EC3C2037564B82FFEF3
SmokeMachine Getting better! 03:54
m: use nqp; say :16(nqp::sha1("xxx")) 03:55
camelia 1039327807276066319526960639699341474749786095347
SmokeMachine :)
SmokeMachine Any way to not use nqp? 03:55
timotimo there's modules that give you hash functions 03:56
SmokeMachine m: use nqp; say :16(nqp::sha1(class :: {}.new.WHICH)) 03:57
camelia 1148741742642494095844578821678109723607158773451
SmokeMachine m: use nqp; say :16(nqp::sha1(class :: {}.new.perl)) 03:58
camelia 36243988929059578703623939259804296396100285399
SmokeMachine WHICH in some classes uses the memory position, right?! 03:59
timotimo for mutable things it'll do something like that
i'm not sure if which uses objectid under the hood, i.e. whether the which changes when the gc moves the object 04:00
ugexe m: use nqp; sub ser($obj is copy) { my Mu $sh := nqp::list_s(); my $n = nqp::time_n(); my Mu $sc := nqp::createsc(nqp::unbox_s("$n")); nqp::setobjsc($obj,$sc); nqp::scsetobj($sc, 0, $obj); my $s = nqp::serialize($sc, $sh); my Mu $i := nqp::iterator($sh); while ($i) {my $s := nqp::shift($i)}; nqp::scdisclaim($sc); nqp::shift_s($sh); $n ~"\n"~nqp::p6box_s(nqp::join("\n", $sh))~"\n"~$s }; ser("foo".IO);
camelia ( no output )
ugexe m: use nqp; sub ser($obj is copy) { my Mu $sh := nqp::list_s(); my $n = nqp::time_n(); my Mu $sc := nqp::createsc(nqp::unbox_s("$n")); nqp::setobjsc($obj,$sc); nqp::scsetobj($sc, 0, $obj); my $s = nqp::serialize($sc, $sh); my Mu $i := nqp::iterator($sh); while ($i) {my $s := nqp::shift($i)}; nqp::scdisclaim($sc); nqp::shift_s($sh); $n ~"\n"~nqp::p6box_s(nqp::join("\n", $sh))~"\n"~$s }; ser("foo".IO).say;
camelia 1500177622.01373
531476C94944C40F030060AEB60539343668769B
gen/moar/CORE.setting
5E1B038AD8D0FE925C90549EA867F661F6FAAB44
<tmp>
/home/camelia
FAAAAEgAAAACAAAAWAAAAAAAAABYAAAAWAAAAAYAAACIAAAAwAAAAAAAAADAAAAAAAAAAMAAAADAAAAAAAAAAMAAAAAAAAAAAQAAA…
timotimo ugh, that's terrible :D :D 04:01
ugexe you used to be able to do a type of base64 encoding of objects like that 04:02
i wasnt expecting that output
araraloren SmokeMachine, can you show us some code kotlin 04:05
your code
SmokeMachine The important part was that I wrote... the real code is on my work’s computer... 04:06
araraloren And the Perl 6 code ? 04:07
Or
ugexe m: use nqp; sub ser($obj is copy) { my Mu $sh := nqp::list_s(); my $n = nqp::time_n(); my Mu $sc := nqp::createsc(nqp::unbox_s("$n")); nqp::setobjsc($obj,$sc); nqp::scsetobj($sc, 0, $obj); my $s = nqp::serialize($sc, $sh); my Mu $i := nqp::iterator($sh); while ($i) {my $s := nqp::shift($i)}; nqp::scdisclaim($sc); nqp::shift_s($sh); $s }; ser("foo").say; 04:08
camelia FAAAAEgAAAACAAAAWAAAAAAAAABYAAAAWAAAAAEAAABgAAAAcAAAAAAAAABwAAAAAAAAAHAAAABwAAAAAAAAAHAAAAAAAAAAAQAAAAIAAAADAAAABAAAAH4BEIAAAAAAAjAMACACMCAAIAEAAAAAAA==
faraco hello 04:09
SmokeMachine But I get the user identifier, concat with the test salt and get the hashCode for that... with this Int, I see if that user should be participating of that test, and if it should, what should be it’s group...
araraloren faraco, hi 04:22
Geth doc: 351f9007ce | (Zoffix Znet)++ | doc/Language/unicode_entry.pod6
Make xtest pass
04:23
araraloren :( 04:26
bioexpress hello, is `qx` a short notation of `q:x`? 07:01
timotimo yup 07:01
bioexpress Thx! 07:02
timotimo qqx also exists
bioexpress to interpolate variables
timotimo yup
Voldenet I've got a mild problem with postfix operators 10:51
m: sub postfix:<pa> { "pa_$^a" }; sub postfix:<a> { "a_$^a" }; sub postfix:<p> { "p_$^a" }; say "a"pa
camelia pa_a
Voldenet however
m: sub postfix:<pa> { "pa_$^a" }; sub postfix:<a> { "a_$^a" }; sub postfix:<p> { "p_$^a" }; say "a"p a
camelia 5===SORRY!5=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> 3}; sub postfix:<p> { "p_$^a" }; say "a"p7⏏5 a
expecting any of:
infix
infix stopper
postfix
statement end
Voldenet m: sub postfix:<pa> { "pa_$^a" }; sub postfix:<a> { "a_$^a" }; sub postfix:<p> { "p_$^a" }; say ("a"p)a
camelia a_p_a 10:52
Voldenet can I somehow force usage of specific operator in this context without parentheses?
hahainternet Voldenet: i seem to remember you can specify tightness/looseness, although i'm not certain 10:55
Voldenet: have you tried docs.perl6.org/language/functions....Precedence ? 10:56
timotimo you'll need a backslash there
Voldenet timotimo++, that what I was looking for
timotimo m: sub postfix:<pa> { "pa_$^a" }; sub postfix:<a> { "a_$^a" }; sub postfix:<p> { "p_$^a" }; "a"p\a
camelia ( no output )
timotimo m: sub postfix:<pa> { "pa_$^a" }; sub postfix:<a> { "a_$^a" }; sub postfix:<p> { "p_$^a" }; say "a"p\a
camelia a_p_a
Voldenet hahainternet: it wouldn't be bad, but I wouldn't want to destroy ++ in the process, because it's quite crucial operator to have working :P 10:57
hahainternet Voldenet: i guess i don't quite see what you're going for :) 10:58
Voldenet Oh right, I should be more specific in my examples
(I'm using postfix:<+>)
timotimo you could use postfix:<×> instead! 10:59
hahainternet ah, and you want to keep ++ with normal preference, but occasionally explicitly support the +
timotimo because there's no postfix:<××>
hahainternet yeah and × is not X
timotimo right, operators can be pulled into scopes lexically
in fact, you can only import operators lexically
timotimo well, except if you bind CALLER::('&infix:<+>') to my &infix:<+> in your sub or whatever 11:00
sjn o/ 14:18
pmurias \o 14:29
lucasb o/ 14:36
Voldenet \o 14:37
sjn found something weird again 14:39
it seems one can't access a .IO object on IntStr's 14:40
an*
(could be I'm not interpreting things correctly though) 14:41
lucasb m: say <100>.IO.perl 14:42
camelia IO::Path.new(IntStr.new(100, "100"), :SPEC(IO::Spec::Unix), :CWD("/home/camelia"))
sjn let's see if I can reproduce what I'm doing 14:43
pmurias sjn: are you still interested in sharing that TPC::EU room? 14:45
sjn pmurias: ah, sorry, I ended up in a sofa at one of the organizer's home 14:46
timotimo don't forget that IO-related things go through the restricted setting on camelia
sjn m: subset Existing of Str where { .IO ~~ :f }; my Existing $f = <0>; # gives the same error if there's a file named "0" in the current dir 14:47
camelia Must specify something as a path: did you mean '.' for the current directory?
in block <unit> at <tmp> line 1
sjn I got that error when using the same subset type as a parameter to MAIN(Existing $i) , and passing along "0" to $i from the command line 14:50
(with a filename "0" in the current dir)
sjn is unsure of how to reduce this to a minimal test for the bot here
here's my code (please touch a file named "0" in current dir before running): 14:53
perl6 -e 'subset Existing of Str where { .IO ~~ :f }; sub MAIN (Existing :$i) { ... }; ' -i=0
Voldenet m: say <0>.IO.perl
camelia Must specify something as a path: did you mean '.' for the current directory?
in block <unit> at <tmp> line 1
sjn yeah, that's a bug, isn't it? 14:55
m: say <1>.IO.perl
camelia IO::Path.new(IntStr.new(1, "1"), :SPEC(IO::Spec::Unix), :CWD("/home/camelia"))
Voldenet m: say <0 1>.map: { .IO.e } 14:58
camelia Must specify something as a path: did you mean '.' for the current directory?
in block <unit> at <tmp> line 1
Voldenet m: say <0 1>.map: { CATCH { .resume }; .IO.e }
camelia (False False)
Voldenet m: say <0 1>.map({ CATCH { .resume }; .IO }).map({ .e }) 14:59
camelia (False False)
sjn that one gives the correct (True False) output here. (I have a file name "0") 15:00
pmurias sjn: np 15:01
sjn pmurias: add yourself to the wiki, and mention that you have a room to share? 15:02
sjn has seen that work before
...assuming pmurias is still looking for a room mate 15:03
timotimo m: say so <0> 15:04
camelia False
timotimo m: say so "0"
camelia True
timotimo clearly a part of the IO constructor thinks "it's a Str and so Str is only False if the Str is empty" 15:05
i suggest we do a full audit of places that do that that could get tripped up by IntStr and similar
in fact, that's kind of a mean gotcha 15:08
or trap or what you want to call it
pmurias sjn: I'll try that 15:22
sjn timotimo: yeah, I was a bit surprised too 15:26
Geth doc: 188d98e6aa | (Zoffix Znet)++ (committed using GitHub Web editor) | doc/Language/traps.pod6
Add numericaly-zero allomorph's Bool to traps
16:22
timotimo that commit looks good 16:24
ugexe weird, i could have swore i fixed that bug like 2 years ago 16:26
timotimo oh? maybe lost during the IO rewrite? 16:27
ugexe i remember because CURI used to save distribution's meta data as filenames 0, 1, 2, etc 16:28
ugexe m: say IO::Path.new(".", :CWD(".")).dir eqv IO::Path.new(".", :CWD("")).dir; # wonder if CWD should be handling blank string, since `run "ls", :cwd("")` does not work the same as `run "ls", :cwd(".")` 17:00
camelia IO::Path is disallowed in restricted setting
in sub restricted at src/RESTRICTED.setting line 1
in method new at src/RESTRICTED.setting line 32
in block <unit> at <tmp> line 1
ugexe reason being that sometimes you want to do like `run "command", $path.relative, :cwd($path.CWD)` 17:02
especially since on windows you cant always pass the volume in as part of the absolute path as an argument, but you *can* set the CWD to whatever and use a relative path
nadim it there another way to push a list in a list than: @l.push: ( (1, 2,3), ) ; 21:18
samcv hi i cannot update zef 21:30
using latest rakudo
Cannot import symbol &zrun from Zef::Shell, because it already exists in this lexical scope
at /home/perl/new/site#sources/EEE22B32677EE6A3F8728D1902A4B45D3A74A68A (Zef::Service::Shell::unzip):2
------> use Zef::Shell⏏;
timotimo i thought push always pushes exactly one thing, so if you pass a list, you'll get a list pushed? 21:31
ah yes, you do have to make it actually a list though, so parens inside the parens
but only one set should be necessary