This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
Dr.Doom i need to genrate binary numbers from 0 to lenght of the array 00:01
nemokosch including the length as well, or only the valid indices? 00:15
Dr.Doom not including the length 01:41
nemokosch m: my @values = <godzilla mothera whateva>; @values.keys.say 01:53
Raku eval (0 1 2)
nemokosch you can retrieve the keys of the array, that's also an option
m: my @values = <godzilla mothera whateva>; @values.keys.map(*.base: 2).say 01:54
Raku eval (0 1 10)
03:33 hythm joined 05:41 hythm left
Dr.Doom m:say ^9 <= <-1 0 1 -1 0 1 2 3 4 5>; 11:30
how is this evaluating to true ?
^9 is not a sub set of that other array 11:31
m: say ^9 <= <-1 0 1 -1 0 1 2 3 4 5>; 11:32
Raku eval True
nemokosch <= is not about arrays 11:34
or better said, sets
it's about numbers
m: (^9).Numeric.say; <-1 0 1 -1 0 1 2 3 4 5>.Numeric.say; 11:35
Raku eval 9 10
nemokosch I don't know why it was a good idea to allow listy things to be coerced into numbers as the number of elements they have 11:36
but in any case, a numeric operation is going on here
the principle is that most operations are dedicated to a purpose - in the light of this, it would be a design bug to overload <= in a way that doesn't relate to numbers 11:37
11:40 teatwo joined 11:43 teatime left
Dr.Doom i wanted to check if range 0..9 is a sub set of the other array 11:53
nemokosch docs.raku.org/routine/%28%26lt%3B%...0%E2%8A%86 11:55
12:04 teatwo left, teatwo joined 12:05 teatwo left, teatwo joined
Dr.Doom i am a bit confused isnt this the same as what i did ? 12:16
@nemokosch
nemokosch nope, you did <= 12:18
the parens are a part of the operator 12:19
or if you fancy unicode, you can just outright write ⊆ for the set operation
m: say ^9 ⊆ <-1 0 1 -1 0 1 2 3 4 5>;
Raku eval False
nemokosch AND ≤ for the numeric operation
m: say ^9 ≤ <-1 0 1 -1 0 1 2 3 4 5>; 12:20
Raku eval True
Dr.Doom aren't <= and ⊆ interchable ? 12:30
ab5tract_ Dr.Doom not at all. one is a numeric comparison and the other is a set operator 14:55
'<=' ne '(<=)'
despite the fact that Raku does do some type conversions for you (most notably Int <-> Str), we try to keep our operators specific to the types that should be using them: `!=` for numeric, `ne` for string, etc. 14:58
so the set-ish version of `<=` is `(<=)`
fun fact, under this philosophy we used to have an entire duplication of the set operators but dedicated to bags/mixes 14:59
so there was an additional `+(<-)` I think it was
`+(<=)`, rather 15:00
Luckily I managed to convince enough people that sets/bags/mixes are more like ints/nums/rats, and thus should share a single set of operators and gently auto-promote to the relevant type when necessary 15:01
ie, `$set (-) $bag` used to coerce `$bag` to a Set because there was a baggy version of `(-)` when you wanted baggy semantics. Nowadays, `$set` is coerced to a Bag and a Bag is returned. Similar to how you can add 2 + 2.5 and then get a Rat holding 4.5 15:04
15:35 Tirifto left 15:37 Tirifto joined
rcmlz I have a question regarding "Binary Methods". Behavior should be specialized depending on the dynamic types of both arguments. Assume I have a Shape class that knows how derive the intersection of any Shapes. Assume I have a Rectangle class, that is extra clever and knows how to intersect Rectangles efficiently. raku # Shape ∩ Shape -> Shape # Shape ∩ Rectangle -> Shape # Rectangle ∩ Shape -> Shape # 17:20
Rectangle ∩ Rectangle -> Rectangle class Shape { #| Universal Shape ∩ Shape --> Shape method intersect(Shape $s --> Shape){ return Shape.new } } class Rectangle is Shape { #| Specialized Rectangle ∩ Rectangle --> Rectangle multi intersect(Rectangle $s --> Rectangle){ return Rectangle.new } } class Client { has @.pairs-of-shapes; method intersect-all {
gather { for @!pairs-of-shapes -> ($s1, $s2) { take $s1.intersect($s2) } } } } use Test; my @arr of Shape = Shape.new(ID => 1), Rectangle.new(ID => 2); my @pos = (@arr X @arr); is-deeply Client.new(pairs-of-shapes => @pos).intersect-all, (Shape.new, Shape.new, Shape.new, Rectangle.new); <pre> # Failed test # expected: $(Shape.new, Shape.new, Shape.new,
Rectangle.new) # got: $(Shape.new, Shape.new, Shape.new, Shape.new) </pre> Is there a Rakoon-way of making this work? I was fiddeling around with roles, red about delegation, but could not make that work. Any hints?
ab5tract_ rcmlz: can you share in a gist or some other pastebin? 17:22
rcmlz yes, just a sec
ab5tract_ thx
rcmlz gist.github.com/rcmlz/7d0d8f7e8c61...f26e7f87e5 17:24
ab5tract_ rcmlz: thanks! Looking at it, I’m not sure why it isn’t working tbh :( 17:26
rcmlz The lecturer of "Concepts of Object Oriented Programming" told us recently that only a few research languages solved this problem - all "normal" languages need to use e.g. Visitor-Pattern. 17:29
MasterDuke does Shape's `intersect` need to be a multi?
rcmlz Then Rectangle can not handle Shapes anymore 17:31
nemokosch > dd @arr[1].intersect(@arr[1]); # Shape.new 17:32
ab5tract_ Hmm, well if I take the multi off the Rectangle candidate
nemokosch this is enough to have it wrong
ab5tract_ Wait, it appears to work for me if I add multi to the intersect definition in Shape 17:34
nemokosch what do you mean?
I changed method intersect to multi intersect and now @arr[1].intersect(@arr[1]) downright doesn't find the method which is just wrong from all angles I can look 17:35
ab5tract_ It requires two changes: `method intersect(Shape $shape —> Shape)` becomes `multi method intesect(Shape $shape —> Shape)`
nemokosch yes, that one broke it completely 17:36
ab5tract_ And `multi intersect(Rectangle $rec —> Rectangle)` becomes `multi method intersect(Rectangle $rec —> Rectangle)`
TIL that a bare `multi` compiles
nemokosch TIL a bare multi doesn't DWIM in classes 17:37
ab5tract_ After those changes, the tests passes
*test
nemokosch maybe it wasn't such a good idea to allow multi if it gets inferred to multi sub even in a class...
ab5tract_ nemokosch: no argument here! 17:38
nemokosch by the way, even a bare base method intersect in Shape doesn't seem to break anything
not sure what the difference would be
ab5tract_ Oh, nice! 17:39
rcmlz multi method- I red docs.raku.org/language/objects now a few times, also Chapter 8 of Perl 6 Deep Dive - and did not understood thta this is possible. Thank you.
nemokosch gonna check for "regressions"
rcmlz Thank you all for the quick help. Nice! 17:40
nemokosch okay, multi actually is required for the mixed case
rcmlz "regressions" is not in docs.raku.org/language/objects - but "multi method" is and I still could not relate it to my problem :-( 17:42
nemokosch no, regressions as in regression testing 17:43
I don't know if anybody really knows how dispatching works in Raku, which in itself should be very alarming 17:45
but it's clear as water that the object and the parameters would influence it
so "multi method" is clearly related
rcmlz My takeaway is: no need for complex patterns - use multi method and all is fine! ;-) 17:46
nemokosch multiple dispatch resolution of subroutines and method resolution are two different things, that's for sure 17:49
and based on that, I would assume that in a "multi method" situation, method resolution takes priority and then the narrowed-down candidates "fight" in the multiple dispatch resolution step over the given arguments 17:50
but this is all just speculative
one could test that out by pushing the Shape.intersect(Rectangle) and Rectangle.intersect(Shape) cases 17:51
apparently there is some detection of ambiguity so if you have a separate Rectangle - Shape and Shape - Rectangle case, it will be an error for Rectangle - Rectangle 18:00
rcmlz How can you include in Shape a Shape x Rectange and in Rectangle a Rectangle x Shape method? Circular reference, need Shape to be declared in order to declare Rectangle and vice versa. 18:28
Anyhow, on the slide it states: - Some research languages allow method calls to be bound based on the dynamic type of several arguments - Examples: CLU, Cecil, Fortress, MultiJava So I guess someone could add Raku too ... 18:54
I just told the lecturer what I just learned, and that he might want to add Raku as Non-Research-Language that has this feature - also mention PRE and POST phaser, which is very important to formal verification folks ... let's see ... 19:30
ab5tract_ Nice! 20:11
rcmlz: I’m not sure if I’m understanding 100% correctly, but you can always declare the existence of a class without defining it 20:12
class Shape {…}; class Rectangle is Shape { #definition of Rectangle }; class Shape { #definition of Shape } 20:13
lakmatiol Julia is probably an easier example, as the entire language is built around dynamic multiple dispatch 20:14
ab5tract_ rcmlz: One day I might finally wire up some wrapping around PRE and POST such that it feels more like how Eiffel does it, in hopes of making the formal verification folks happy 20:17
.ohnowendigo Eiffel doesn't have a good rep in the formal verification community 20:49
nemokosch I haven't actually used Eiffel but it looked to me that it's like Ada 20:58
in which case I can understand it's not very acknowledged among the math folks
Ada is strict like a lawyer, not strict in the math sense
.ohnowendigo Oh SPARK has a good reputation in formal methods, great tool. Eiffel just kept advertising itself as FM but only really got a checker in the 2010's. 21:12
nemokosch vanilla Ada is not quite SPARK though 😛 21:13
.ohnowendigo Also the inventor has this infuriating habit of refusing to use any standard lingo, instead making up his own jargon and trying to force everybody else ot use it
And he trademarked "design by contract"
nemokosch that's a bizarre move 21:14
especially when it really seems Ada at the very least laid down the principles earlier
quite possibly other languages as well
23:20 jgaz joined, jgaz left 23:24 jgaz joined 23:40 teatwo left, teatwo joined 23:43 teatwo left, teatwo joined