thowe | The Raku docs seem to indicate that blocks do, in fact, return "The last statement". Though it does say they are "transparent to return " whatever that means. | 00:01 | |
Did this behavior change since the book was written? | 00:02 | ||
Nemokosch | it would be good to see what it says exactly | 00:08 | |
thowe | "A subroutine can return a value (a Block can’t)." | 00:09 | |
pizza.deschutesdigital.com:9088/fil...tSJglDwQxn | 00:10 | ||
dammit | |||
http:/file/1/BBx04PmCM4CVw955 | |||
SmokeMachine | m: sub a($should-return) { my $b = { return “returned” if $should-return; “b” }; say $b; “last value” }; a True; a False | ||
camelia | -> ;; $_? is raw = OUTER::<$_> { #`(Block|43082528) ... } -> ;; $_? is raw = OUTER::<$_> { #`(Block|43083104) ... } |
||
thowe | the helll | ||
http:/file/1/sjP0pUAQgRA2LFgF | 00:11 | ||
SmokeMachine | 00:10 <SmokeMachine> m: sub a($should-return) { my $b = { return “returned” if $should-return; “b” }.(); say $b; “last value” }; a True; a False | ||
m: sub a($should-return) { my $b = { return “returned” if $should-return; “b” }.(); say $b; “last value” }; a True; a False | |||
camelia | b | ||
SmokeMachine | m: sub a($should-return) { my $b = { return “returned” if $should-return; “b” }.(); say $b; “last value” }; say a True; say a False | 00:12 | |
camelia | returned b last value |
||
thowe | apparently convos won't let me paste in the next couple sentences, but the way I use put in the example is what it says can only be done with a sub... "Previously the blocks handled output" | ||
I can only assume Brian De Foy was very confused, or blocks are different now? | 00:13 | ||
SmokeMachine | thowe: transparent to return: 👆 | ||
Nemokosch | I don't think this helps a lot | 00:14 | |
does this mean that `return` inside a block still belongs to the sub? | |||
SmokeMachine | Calling return from a block inside a sub will return the sub and not the block | ||
thowe | in the code example I pasted, I do "put $maxofthree($n1, $n2, $n3);" put is printing the returned value of the block. The following examples and text in the book explain that one must use a sub to be able to do that. | 00:15 | |
SmokeMachine | Nemokosch#9980: yes | ||
You must use a sub to be able to use the return keyword | 00:16 | ||
Nemokosch | $maxofthree works for me btw | ||
SmokeMachine | m: { return 42 } | 00:17 | |
camelia | Attempt to return outside of any Routine in block <unit> at <tmp> line 1 |
||
thowe | Transparent to return is not explained there. He says that previous examples in the book showed the block handling the output. However I look back and they don't all do so. I think this is a result of bad editing or something. | ||
SmokeMachine | A block being transparent to return mean that if you call return from inside a block, it will return from the outside sub and not from the block | 00:18 | |
Nemokosch | SmokeMachine has explained what transparent to return means and I think it makes sense | ||
just like the block of an if statement is "transparent to break/continue", a raku block is "transparent to return" | |||
thowe | OK, thanks for that. but that is not the issue that is confusing me in the book. | 00:19 | |
"tranparent to return" is clearly not what is being discussed in the book. I think I point that out clearly above. | 00:20 | ||
SmokeMachine | I haven’t read the book, but isn’t it explaining that you can’t use return on the block itself? Like this: | ||
thowe | No. | ||
SmokeMachine | m: { return 42 } | ||
camelia | Attempt to return outside of any Routine in block <unit> at <tmp> line 1 |
||
Nemokosch | then I'm afraid you also aren't explaining well enough 😅 | 00:21 | |
anyways, what you posted works just fine for me | |||
m: my $maxofthree := { ($^a, $^b, $^c).max } put $maxofthree(4,5,2) | |||
thowe | It is saying that the block would have to have the put statement in it instead of being able to do what I do in my code example I pasted. It works fine for me too. I didn't say it didn't work. | ||
But the book is saying it wouldn't work... It says I would need a sub to do that. I'm saying the book is wrong. | 00:22 | ||
Nemokosch | okay, missing semicolon... | 00:23 | |
m: my $maxofthree := { ($^a, $^b, $^c).max }; put $maxofthree(4,5,2) | |||
we don't have the book so we can't check that 🤷♂️ | |||
thowe | a screenshot would be fair use, right? | ||
Nemokosch | I think so but don't bother, it was uploaded somewhere and I looked it up | 00:25 | |
my first impression is that the author doesn't really know/pay attention to the fact that implicit returns exist | 00:27 | ||
and hence mistakenly concludes from the "transparency of return" that blocks can't return a value | |||
I see no behavior that contradicts the current status quo | |||
the only thing I can imagine is that implicit returns didn't exist at that time but I wouldn't know that as a newbie to the language | 00:28 | ||
moreover | 00:29 | ||
```perl | |||
my $subroutine := sub { | |||
return do if now.Int %% 2 { 'Even' } | |||
else { 'Odd' } | |||
}; | |||
put $subroutine(); | |||
``` | |||
this already contradicts this narrative | |||
thowe | Yes, you are describing exactly my thoughts. | ||
Nemokosch | the guy doesn't seem to be trying to use implicit returns with pointy blocks | ||
thowe | but if you go back, the block examples given also contradict this. I think the return transparency thing was previously misunderstood by him, and then he went back and made changes, but never fixed the text. | 00:30 | |
anyway, at least the third big error I have found in the book. Starting to annoy me. | 00:31 | ||
Nemokosch | ```perl | ||
my $block := -> Numeric $b, Numeric $a { $a / $b }; | |||
put $block( 1, 2 ); | |||
``` | |||
this for one is a good way of "return" from a pointy block | 00:33 | ||
SmokeMachine | In that case I would prefer like this: | 00:34 | |
my &block := -> Numeric $b, Numeric $a { $a / $b }; say block 1, 2 | 00:35 | ||
m: my &block := -> Numeric $b, Numeric $a { $a / $b }; say block 1, 2 | |||
camelia | 2 | ||
thowe | What learning materials are others using? | 00:38 | |
Nemokosch | I mean, indeed, & is the right sigil for something meant to be called all along | 00:47 | |
I was taking the example from the book | |||
thowe: I basically just use the docs and lurk around on the discord server, in case I have a question or someone posts something clever 🙂 | 00:48 | ||
stevied | I got this: | 05:06 | |
``` | |||
multi apps(Str $dir) is export(:MANDATORY) { apps [$dir] } | |||
multi apps(Str @dirs?) is export(:MANDATORY) { | |||
``` | |||
I call it with this: `@apps = apps @path` | |||
i get this error: | |||
``` | |||
Cannot resolve caller apps(Array:D); none of these signatures match: | |||
(Str $dir) | |||
(Str @dirs?) | |||
``` | |||
how do I fix this? | |||
the @path has a string in it. | 05:07 | ||
so I'm not sure why it doesn't match the signature | 05:11 | ||
oh, I guess at @path has to be typed as Str. hmmm. | 05:15 | ||
MasterDuke | how to use typed arrays is a common trap in raku | 08:24 | |
m: my Str @a = <a b c>; dd @a | 08:25 | ||
camelia | Array[Str @a = Array[Str].new("a", "b", "c") | ||
MasterDuke | but | ||
m: sub foo(Str @a) { dd @a }; foo(<a b c>) | |||
camelia | Type check failed in binding to parameter '@a'; expected Positional[Str] but got List (("a", "b", "c")) in sub foo at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
MasterDuke | and | ||
m: my Str @a := <a b c>; dd @a | |||
camelia | Type check failed in binding; expected Positional[Str] but got List (("a", "b", "c")) in block <unit> at <tmp> line 1 |
||
MasterDuke | the `<a b c>` is not something that's explicitly been typed to only contains Strs, it just happens to do so. in the first assignment example i showed, it works because assignment does copying, it kind of creates a typed array and then copied each individual element into it, and they all fit the type | 08:28 | |
but the binding example (and that's how the sub argument passing is done) doesn't do that copying, and the types don't match | 08:29 | ||
m: sub foo(@a where @a.all ~~ Str) { dd @a }; foo(<a b c>) | 08:30 | ||
camelia | ("a", "b", "c") | ||
MasterDuke | in that case the sub just wants any kind of array, as long as every element is a Str | 08:31 | |
m: sub foo(@a where @a.all ~~ Str) { dd @a }; foo(("a", "b", "c", 3)) | 08:32 | ||
camelia | Constraint type check failed in binding to parameter '@a'; expected anonymous constraint to be met but got List (("a", "b", "c", 3)) in sub foo at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
MasterDuke | m: sub foo(Str @a) { dd @a }; foo(Array[Str]("a", "b", "c")) | 08:35 | |
camelia | Array[Str].new("a", "b", "c") | ||
10:20
discord-raku-bot left,
discord-raku-bot joined
|
|||
stevied | I'm going through book at arnesom.github.io/Beginning-v1.00.pdf | 13:18 | |
has this code example: `my Int %$hash; say %hash.of; # -> (Int)` | |||
why does it have %$hash? the book offers no explanation. I'm thinking it's a typo as the book is full of other errors. | |||
Nemokosch | I also think so... %$hash does exist as a kind of conversion but not as a variable on its own | 13:49 | |
from what I know | |||
and it surely won't work like that example | |||
maybe the other way around | |||
15:29
discord-raku-bot left,
[Coke] left,
Manifest0 left,
MasterDuke left,
camelia left,
SmokeMachine left,
mjgardner left,
gfldex left,
thowe left,
sivoais left,
TempIRCLogger left,
tbrowder left,
Util_ left,
codesections left,
guifa left,
samebchase left,
qorg11 left,
lizmat left
15:32
codesections joined,
Util_ joined,
tbrowder joined,
camelia joined,
SmokeMachine joined,
MasterDuke joined,
Manifest0 joined,
[Coke] joined,
discord-raku-bot joined,
guifa joined,
samebchase joined,
mjgardner joined,
TempIRCLogger joined
15:33
qorg11 joined,
lizmat joined,
gfldex joined,
thowe joined,
sivoais joined
|
|||
lizmat | I think Arne Sommer would appreciate PR's for errors that you find | 15:43 | |
16:20
discord-raku-bot left
|
|||
thowe | I didn't know about that pdf... I'll check that out | 16:21 | |
16:21
discord-raku-bot joined,
getimiskon joined
|
|||
thowe | raku people sure do like Docker... | 16:26 | |
Re: Beginning Raku by Sommer: I had seen that but thought it was a print book. I'll def check out. | 16:29 | ||
lizmat | thowe: I think that's really to get around the fact that Raku isn't in that many standard Linux distributions (yet) | 16:30 | |
thowe | ah. I find rakubrew a treat | 16:34 | |
but then I am used to perlbrew | |||
I rememeber the Ruby equiv being less friendly | |||
Nemokosch | rakubrew is nice | 16:35 | |
16:37
discord-raku-bot left
16:38
discord-raku-bot joined
|
|||
stevied | Looking at: docs.raku.org/language/mop | 22:29 | |
it's got this sample code: | 22:31 | ||
``` | |||
my $arr = [1, 2]; | |||
say $arr.^name; # OUTPUT: «Array» | |||
``` | |||
but REPL shows: | |||
``` | |||
say $arr.^name | |||
Array | |||
``` | |||
any reason why? | |||
Nemokosch | hey, what's the difference? | 22:41 | |
stevied | the funny symbols around Array are in docs, not in REPL | 22:46 | |
I keep seeing those funny symbols and have no idea what they are | 22:47 | ||
23:04
getimiskon left
|
|||
MasterDuke | french quotes i believe | 23:10 |