raku

Returning a 'raw' scalar container from AT-POS method (rather than a Proxy instance) in a class that 'does' Positional?

老子叫甜甜 提交于 2021-01-26 07:56:32
问题 I'm attempting to implement a class that 'does' Positional that also allows me to update its values by assigning to the result returned by the AT-POS method. Eventually, I was able to concoct the following class that works as intended: class Test does Positional { has $.slot_1 is rw = 12; has $.slot_2 is rw = 24; method AT-POS(\position) { my $t = self; return-rw Proxy.new: FETCH => method () { position % 2 ?? $t.slot_1 !! $t.slot_2 }, STORE => method ($v) { if position % 2 { $t.slot_1 = $v }

Assignment to a List Container Confusion

人走茶凉 提交于 2021-01-26 03:51:57
问题 I may be suffering from brain fade, but according to the docs regarding Items and List assignment (https://docs.raku.org/language/variables#Item_and_list_assignment ), Assignment to a List container (list-context) always triggers list assignment. However that seems to conflict with what I get from the code (here reproduced in the raku repl).. > my %syns-by-name = %(Bq => ["Bq", "becquerel", "becquerels"], C => ["C", "coulomb", "coulombs"],) {Bq => [Bq becquerel becquerels], C => [C coulomb

The performance penalties for types/constraints in Raku?

倾然丶 夕夏残阳落幕 提交于 2021-01-21 06:12:30
问题 In contrast with Perl 5, Raku introduced gradual typing. The landscape of gradually typed object-oriented languages is rich and includes: Typed Racket, C#, StrongScript, Reticulated Python. It's said that "optional gradual type-checking at no additional runtime cost" on the Raku official website. As far as I know, some gradual typing language (like Typed Racket and Reticulated Python) suffered from the serious performance issue due to strategy of enforcing type system soundness. On the other

Raku regex: Inconsistent longest token matching

若如初见. 提交于 2021-01-02 05:02:34
问题 Raku's regexes are expected to match longest token. And in fact, this behaviour is seen in this code: raku -e "'AA' ~~ m/A {say 1}|AA {say 2}/" # 2 However, when the text is in a variable, it does not seem to work in the same way: raku -e "my $a = 'A'; my $b = 'AA'; 'AA' ~~ m/$a {say 1}|$b {say 2}/" # 1 Why they work in a different way? Is there a way to use variables and still match the longest token? 回答1: There are two things at work here. The first is the meaning of "longest token". When

Passing an array of structures to a Perl 6 NativeCall function

一个人想着一个人 提交于 2020-12-08 07:06:21
问题 I'm trying to use NativeCall to interact with some C functions. I have a simple C struct, and a function that wants an array of them. struct foo { int x; char *s; }; struct foo foo_array[3]; foo_array[0].x = 12; foo_array[0].s = "foo"; foo_array[1].x = 27; foo_array[1].s = "bar"; foo_array[2].x = -1; void somefunc(foo_array); I've tried a bunch of ways, but can't seem to get it quite right. class foo is repr('CStruct') { has int32 $.x; has Str $.s }; sub somefunc(CArray[foo]) is native { * }

Passing an array of structures to a Perl 6 NativeCall function

一个人想着一个人 提交于 2020-12-08 07:05:27
问题 I'm trying to use NativeCall to interact with some C functions. I have a simple C struct, and a function that wants an array of them. struct foo { int x; char *s; }; struct foo foo_array[3]; foo_array[0].x = 12; foo_array[0].s = "foo"; foo_array[1].x = 27; foo_array[1].s = "bar"; foo_array[2].x = -1; void somefunc(foo_array); I've tried a bunch of ways, but can't seem to get it quite right. class foo is repr('CStruct') { has int32 $.x; has Str $.s }; sub somefunc(CArray[foo]) is native { * }