# New Ticket Created by  "Carl Mäsak" 
# Please include the string:  [perl #112596]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=112596 >


<grondilu> p6: .say for map &sprintf.assuming("%x"), ^16;
<p6eval> ..rakudo b64c1e: OUTPUT«This type cannot unbox to a native
integer [...]
<grondilu> this used to work fine :(
<moritz> when? and in which compiler?
<grondilu> I don't know exactly.  Something like this was in my Digest module.
<moritz> I'm a bit surprised it ever worked
<moritz> because sprintf has a signature of ($format, *@args)
<grondilu> so?
<grondilu> "%x" is a format, isn'it?
<moritz> yes, but what remains after the .assuming is applied is a
signature of (*@args)
<moritz> and .map is sensitive to the arity of the block it operates on
<masak> so .map slurps all of the ^16
<grondilu> I don't give a block I give a function
<moritz> grondilu: s/block/callable/ then
<moritz> well, it's the same as  sprintf("%x', ^16)
<moritz> which should complain about excess arguments
<grondilu> hang on
<moritz> r: say sprintf('%x', ^16)
<p6eval> rakudo b64c1e: OUTPUT«0␤»
<masak> huh.
<moritz> it seems to just ignore all the other arguments
<moritz> the format tells it to print only one number
<moritz> so that's all it does
<masak> right.
<masak> there really should be a check there.
<masak> for too-many as well as too-few.
<moritz> masak: yes, but we can't do that with our current factoring
<moritz> grondilu: assuming just returns a callable with one argument curried
<moritz> now this should work:
<moritz> r: sub a($a, $b) { sprintf $a, $b }; .say for map
&a.assuming('%x'), ^16
<p6eval> rakudo b64c1e: OUTPUT«This type cannot unbox to a native integer [...]
<grondilu> ah
<grondilu> There IS something wrong, isn't there?
<moritz> r:  .say for map -> *@a { @a } , ^16
<p6eval> rakudo b64c1e: OUTPUT«This type cannot unbox to a native integer [...]
<moritz> grondilu: yes, there's something wrong
* masak submits rakudobug
<moritz> grondilu: and I believe I know what
<moritz> it's getting Inf as the parameter count
<moritz> and tries to unbox that as an integer
<grondilu> Are you going to add this in the test suite to avoid
degradation in future?
<grondilu> Because really: it used to work.
<moritz> yes, but it relied on a bug
<moritz> I know how and why it used to work
<grondilu> ok
<moritz> but when we fix this bug, it won't work the way you want it to work
<grondilu> :(
<grondilu> why not??
<moritz> because the arity of the callable that you pass to .map
decides how many arguments maps passes to the callable
<moritz> and your takes as many arguments as it wants
<moritz> but let me propose
<moritz> r: .say for map *.fmt('%x'), ^16
<p6eval> rakudo b64c1e: OUTPUT«0␤1␤2␤3␤4␤5␤6␤7␤8␤9␤a␤b␤c␤d␤e␤f␤»
<grondilu> oh that's nice
<moritz> that works, will continue to work, and is even shorter :-)
<grondilu> thanks!
<grondilu> I totally forgot about the fmt method
* grondilu happily edits his Digest module :)

Reply via email to