raku

Perl6: load functions into other namespace

一世执手 提交于 2019-12-23 08:53:07
问题 I want to use Perl6 Modules to group some functions, i often use. Because this functions are all loosely coupled, I don't like to add them in a class. I like the idea of use , where you can select, which functions should be imported, but I don't like it, that the functions, which are imported are then stored in the global namespace. For example if I have a file my_util.pm6 : #content of my_util.pm6 unit module my_util; our sub greet($who) is export(:greet) { say $who; } sub greet2($who) is

perl6 IO::Socket::Async server dies with the exception: connection reset by peer

痞子三分冷 提交于 2019-12-23 08:47:54
问题 Here is the echo server code: #!/usr/bin/env perl6 my $port = 3333 ; say "listen port $port" ; react { my $ids = 0 ; whenever IO::Socket::Async.listen('0.0.0.0', $port ) -> $conn { my $id = $ids++ ; $conn.print( "$id: hello\n") ; whenever $conn.Supply.lines -> $line { say "$id: $line" ; $conn.print( "$id : $line\n") ; } } } here is the client code: #!/usr/bin/env perl6 my $port = 3333 ; my $conn = await IO::Socket::Async.connect('localhost', $port ); $conn.print: "{time}\n"; #$conn.Supply.tap

How to define fixed-length strings in a Perl6 NativeCall struct?

天大地大妈咪最大 提交于 2019-12-23 08:37:36
问题 I have a third-party C library that defines a struct similar to: struct myStruct { int a; int b; char str1[32]; char str2[32]; }; And a function that takes a pointer to this struct and populates it. I need my Perl6 native call to provide that struct, and then read the results. So far I've got the struct defined in Perl6 as: class myStruct is repr('CStruct') { has int32 $.a; has int32 $.b; has Str $.str1; # Option A: This won't work as Perl won't know what length to allocate has CArray[uint8]

Can Perl 6 sort or compare based on collations?

别说谁变了你拦得住时间么 提交于 2019-12-23 07:50:02
问题 The cmp operator works on code numbers, or at least that's what I think it does because the docs aren't explicit on that and don't mention any localization stuff. Can I make it sort by other collations? I know I tell sort how to compare, but I figure it must be in there already (somewhere). 回答1: Collation is available as an experimental feature: my @list = <a ö ä Ä o ø>; say @list.sort; # (a o Ä ä ö ø) use experimental :collation; say @list.collate; # (a ä Ä o ö ø) $*COLLATION.set(:tertiary

Why does the Perl 6 sequence 'A' … 'AA' have only one element?

不问归期 提交于 2019-12-23 07:33:03
问题 Today I noticed that the sequence 'A' ... 'AA' contains only one element: > 'A' ... 'AA' (A) I thought it would contain 27: the alphabet plus the final AA . If I explicitly provide a generator, it does: > 'A', *.succ ... 'AA' (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA) The docs say that the default generator is either *.succ or *.pred depending on how the end points compare. But: > 'A' cmp 'AA' Less So it seems I should be getting the *.succ generator by default. I'm definitely

Why does the Perl 6 sequence 'A' … 'AA' have only one element?

这一生的挚爱 提交于 2019-12-23 07:32:04
问题 Today I noticed that the sequence 'A' ... 'AA' contains only one element: > 'A' ... 'AA' (A) I thought it would contain 27: the alphabet plus the final AA . If I explicitly provide a generator, it does: > 'A', *.succ ... 'AA' (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA) The docs say that the default generator is either *.succ or *.pred depending on how the end points compare. But: > 'A' cmp 'AA' Less So it seems I should be getting the *.succ generator by default. I'm definitely

How to declare native array of fixed size in Perl 6?

*爱你&永不变心* 提交于 2019-12-23 07:31:09
问题 I'm am trying to declare the following C struct in Perl 6: struct myStruct { int A[2]; //<---NEED to declare this int B; int C; }; My problem is that I don't know how to declare the int A[2]; part using the built in NativeCall api. So for what I have is: class myStruct is repr('CStruct') { has CArray[int32] $.A; has int32 $.B; has int32 $.C; }; However, I know that the has CArray[int32] $.A; part is wrong as it does not declare a part in my struct that takes up ONLY 2 int32 sizes. 回答1: Update

Use “perl6” command with Git Bash on windows

眉间皱痕 提交于 2019-12-23 07:26:31
问题 Using Windows, I installed Rakudo Star and Git and ensured that C:\rakudo\bin and C:\rakudo\share\perl6\site\bin are in my Path environment variable. Now, typing perl6 inside Git Bash afterwards gives the command not found error, while the command does work inside powershell and cmd . Typing echo $PATH inside Git Bash confirms again that the folders above are in my path variable here as well. How can I get the perl6 command working inside Git Bash? Note: Using moar (moar.exe) which resides in

What's the difference between Perl 6's DEFINITE and defined methods?

烂漫一生 提交于 2019-12-23 07:08:46
问题 Type objects are always undefined, but I've seen some tests that use .defined and some that use .DEFINITE . Is there any case where those might be different? I tend to think that any method that's all uppercase isn't for everyday work and would prefer .defined for this task. my $class = IntStr; put '-' x 20; # False put $class.DEFINITE; put $class.defined; put '-' x 20; # False $class = Nil; put $class.DEFINITE; put $class.defined; put '-' x 20; # True $class = ''; put $class.DEFINITE; put

How does Perl 6 evaluate truthiness?

假装没事ソ 提交于 2019-12-23 06:48:04
问题 In reading about Perl 6, I see a feature being trumpeted about, where you no longer have to do: return "0 but true"; ...but can instead do: return 0 but True; If that's the case, how does truth work in Perl 6? In Perl 5, it was pretty simple: 0, "", and undef are false, everything else is true. What are the rules in Perl 6 when it comes to boolean context? 回答1: Perl 6 evaluates truth now by asking the object a question instead of looking at its value. The value is not the object. It's