perl6

how to pass a class method as argument to another method of the class in perl 6

我们两清 提交于 2019-12-13 00:58:55
问题 I have a script like the below. Intent is to have different filter methods to filter a list. Here is the code. 2 3 class list_filter { 4 has @.my_list = (1..20); 5 6 method filter($l) { return True; } 7 8 # filter method 9 method filter_lt_10($l) { 10 if ($l > 10) { return False; } 11 return True; 12 } 13 14 # filter method 15 method filter_gt_10($l) { 16 if ($l < 10) { return False; } 17 return True; 18 } 19 20 # expecting a list of (1..10) to be the output here 21 method get_filtered_list

Making a junction out of an array with string values in Perl 6

你说的曾经没有我的故事 提交于 2019-12-12 13:07:37
问题 Here's what I'm trying to do. It should be very simple, but I can't figure out how to do it correctly. > my @search_keys = <bb cc dd> [bb cc dd] > my $search_junc = @search_keys.join('|') bb|cc|dd > "bb" eq $search_junc False 回答1: my @search_keys = <bb cc dd>; say "bb" eq any(@search_keys); # any(True, False, False) say so "bb" eq any(@search_keys); # True The | syntax is merely sugar for calling the any() function. Just like & is syntactic sugar for the all() function. They both return

Is there still a race condition? [closed]

不想你离开。 提交于 2019-12-12 12:14:08
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago . this is the current state of my little unimportant async experiment. Can you spot any races or leaks? Common critique is also welcome. class GameObject { has Int $.id; has Int $.x is rw; has Int $.y is rw; has $.game; has Int $.speed; #the higher the faster multi method start(

Why do I get 'divide by zero` errors when I try to run my script with Rakudo?

筅森魡賤 提交于 2019-12-12 11:47:35
问题 I just built Rakudo and Parrot so that I could play with it and get started on learning Perl 6. I downloaded the Perl 6 book and happily typed in the first demo program (the tennis tournament example). When I try to run the program, I get an error: Divide by zero current instr.: '' pc -1 ((unknown file):-1) I have my perl6 binary in the build directory. I added a scripts directory under the rakudo build directory: rakudo |- perl6 \- scripts |- perlbook_02.01 \- scores If I try to run even a

Updating a program in a CompUnit::PrecompilationStore?

一个人想着一个人 提交于 2019-12-12 10:47:53
问题 I am working with documents compiled by Rakudo Perl and the documents can get updated. I store the documents in a CompUnit::PrecompilationStore::File How do I change an older version for a newer one? The following program produces the same output, as if the newer version is not stored in CompUnit. What am I doing wrong? use v6.c; use nqp; 'cache'.IO.unlink if 'cache'.IO ~~ e; my $precomp-store = CompUnit::PrecompilationStore::File.new(prefix=>'cache'.IO); my $precomp = CompUnit:

Perl6 equivalent of Perl's 'store' or 'use Storable'

爱⌒轻易说出口 提交于 2019-12-12 10:34:41
问题 I am attempting to write a hash, which is written very slowly, into a data file, but am unsure about how Perl6 does this in comparison to Perl5. This is a similar question Storing intermediate data in a file in Perl 6 but I don't see how I can use anything written there, specifically messagepack. I'd like to see the Perl6 equivalent of my %hash = ( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4); use Storable; store \%hash, 'hash.pldata'; and then read with my $hashref = retrieve('hash.pldata'); my

How can I compile perl6 file to exe

元气小坏坏 提交于 2019-12-12 09:34:34
问题 I am playing with perl6 version which built on MoarVM on windows. I created some perl6 file and want to compile it to exe. I tried the following: perl6 --target=MAST r.pl>r Now I want to compile the r to executable I found this link which talk about how to that using Parrot but I am using MoarVM target: http://perlgeek.de/blog-en/perl-6/my-first-executable.writeback my question how can i compile MoarvVM targeted file to windows executable ? 回答1: Unfortunately, the answer is to target JVM and

perl6 how to get specific identity of promises?

落花浮王杯 提交于 2019-12-10 16:42:14
问题 I am trying to code 3 echo servers running in promises, but I want to know which promise is doing the echoing. Is there a way to do that? no strict; for 0 .. 2 -> $index { @result[$index] = start { $myID = $index; say "======> $myID\n"; my $rsSocket = IO::Socket::INET.new: localhost => 'localhost', localport => 1234 + $index, listen => 1; while $rsSocket.accept -> $rsConnection { say "Promise $myID accepted connection"; while $rsConnection.recv -> $stuff { say "promise $myID Echoing $stuff";

Useless use of hash composer, or cannot modify an immutable hash?

旧时模样 提交于 2019-12-10 15:36:34
问题 This code: constant %what = { doesn't => 'change' }; %what = { will => "change" } Should say something along the lines of "Cannot modify an immutable hash". However, it says: Potential difficulties: Useless use of hash composer on right side of hash assignment; did you mean := instead? Positionals have pretty much the same problem, but the error is different. In this case it's about cannot modify an immutable, but an Str: constant @what = <does not change>; @what = <does change> # Cannot

Passing an inlined CArray in a CStruct to a shared library using NativeCall

删除回忆录丶 提交于 2019-12-10 14:53:17
问题 This is a follow-up question to " How to declare native array of fixed size in Perl 6? ". In that question it was discussed how to incorporate an array of a fixed size into a CStruct . In this answer it was suggested to use HAS to inline a CArray in the CStruct . When I tested this idea, I ran into some strange behavior that could not be resolved in the comments section below the question, so I decided to write it up as a new question. Here is is my C test library code: slib.c : #include