Questions tagged [perl6]

4

votes
1

answer
37

Views

Perl6: getting array ref for Perl5 Module

I'm trying to write an Excel notebook in Perl6, using Excel::Writer::XLSX. I'm using Inline::Perl5 via use Excel::Writer::XLSX:from Specifically, I want to write a row like I did in Perl5: $worksheet -> write_row(0,0, \@line); but this gives error To pass an array, hash or sub to a function in Perl...
con
1

votes
1

answer
10

Views

invert needs a Pair?

The invert method for Lists should return the inverted sequence, or at least that's what the source seems to imply. However: say (1,3,2).invert fails with: (exit code 1) Type check failed in invert; expected Pair but got Int (1)␤ in block The documentation does not help, because it's LTA in thi...
jjmerelo
6

votes
1

answer
394

Views

Probable version skew in pre-compiled xxx

I'm installing a package onto a virtual machine(ubuntu18.04). Here are the instructions I used: apt-get install perl6 && \ git clone https://github.com/ugexe/zef.git && cd zef && perl6 -I. bin/zef install . && \ /usr/lib/perl6/site/bin/zef install Shell::Command && \ PYTHON_CONFIG=/usr/bin/python3-c...
lovetomato
7

votes
3

answer
144

Views

Perl6: variable number of arguments to function/subroutine

I want to be able to run a function with a variable number of parameters in Perl6, but after reading through https://docs.perl6.org/language/functions#Arguments I don't see how it can be done. I see numerous links for other languages, and a warning that "Questions with similar titles have frequently...
con
0

votes
0

answer
4

Views

perl6 How to make subrule/regex case-insensitive when used in match?

I am trying to match any keywords in a group. Keywords are in array @b. I am unable to make case-insensitive matches. I have done some testing, and the following script is an example: > my $line = "this is a test line"; this is a test line > my @b = < tes lin > ; [tes lin] > my regex a { || @b }; r...
lisprogtor
9

votes
3

answer
127

Views

How do I return from an anonymous recursive sub in perl6?

This does what I'd expect. fib(13) returns 233. sub fib(Int $a --> Int) { return 0 if $a == 0; return 1 if $a == 1; return fib($a -1) + fib($a -2); } my $square = -> $x { $x * 2 }; # this works with no return value my @list = .map( $square ); # returns [2 4 6 8 10 12 14 16 18] I tried implementing...
jmcneirney
6

votes
2

answer
117

Views

perl6: Cannot unbox 65536 bit wide bigint into native integer

I try some examples from Rosettacode and encounter an issue with the provided Ackermann example: When running it "unmodified" (I replaced the utf-8 variable names by latin-1 ones), I get (similar, but now copyable): $ perl6 t/ackermann.p6 65533 19729 digits starting with 2003529930406846464979072351...
Sno
7

votes
2

answer
62

Views

Simplify the invocation of a common method

I have a class like this: class Foo { method some-method(Str $name) { ... } } Simple usage: my $foo = Foo.new; $foo.some-method("peter"); Since the "some-method" will be called quite frequently, I'd like to do something to allow users to use it like below: $foo.peter; I know FALLBACK will do the jo...
lovetomato
8

votes
2

answer
84

Views

have perl6 invoke the right multi sub specialized by subtype(subset)

I have a type hierarchy constructed with perl6's subset command and some multi subs specialized on these type. How to give the highest precedence to the sub specialized by the most narrow subtype when multi dispatch happens? Here is the simplified code: #! /usr/bin/env perl6 use v6.c; proto check($v...
lovetomato
12

votes
4

answer
190

Views

How to make perl6 die on undefined values?

I am attempting to work with a hash in Perl6, but when I put some fake values into it (intentionally) like say %key; I get (Any) but I want the program to die in such occurrences, as Perl5 does, because this implies that important data is missing. For example, #!/usr/bin/env perl use strict; use wa...
con
3

votes
1

answer
33

Views

Perl6 NativeCall cannot locate symbol in native library

I have a module using NativeCall that works on both Linux and macOS, but not Windows. When I try to use the module on Windows I get lots of errors like: # Cannot locate symbol 'TinyTIFFReader_open' in native library 'tinytiff.dll' I use cmake for my C++ dependency on all three OS's. On Linux and mac...
ryn1x
1

votes
1

answer
89

Views

What does --> mean in Perl 6?

On Rossetta code, the Perl 6 code for Levenshtein distance, the subroutine signature contains Str $t --> Int. Is the --> an operator acting on $t or something else altogether?
1

votes
2

answer
91

Views

Why does panda fail to install my module when all tests pass locally?

I'm the author of Pod-Perl5 a Perl 6 module that parses Perl 5 pod. Until the release of Perl 6.c, this module installed fine with panda install Pod::Perl5. Now it fails with an extensive list of errors (excerpt is below, full output is here). All tests pass when running the test suite with: prove -...
David Farrell
1

votes
0

answer
14

Views

Can't precompile when using some external module

I'm trying to precompile external files to get their assets with this script: #!/usr/bin/env perl6 use v6; use nqp; my $precomp-store = CompUnit::PrecompilationStore::File.new(prefix => "/tmp".IO); our $precomp = CompUnit::PrecompilationRepository::Default.new(store => $precomp-store); my $file = "....
jjmerelo
0

votes
0

answer
7

Views

How does a triangular reduction on the comma operator know to make a list of all lists?

In Perl 6, doing a triangular reduction on the comma operator produces a list of lists, each of which adds one successive element from the input list: > [\,] 1..5 ((1) (1 2) (1 2 3) (1 2 3 4) (1 2 3 4 5)) Pretty nice! But recently I wondered just how it works the way it does. If op is an arbitrary...
Sean
4

votes
2

answer
63

Views

Extract tokens from grammar

I have been working through the Advent of Code problems in Perl6 this year and was attempting to use a grammar to parse the Day 3's input. Given input in this form: #1 @ 1,3: 4x4 and this grammar that I created: grammar Claim { token TOP { '#' \s* '@' \s* ':' \s* } token digits { + } token id {...
Hunter McMillen
3

votes
1

answer
52

Views

How to install only test dependencies with Zef

zef has a --deps-only flag for the install subcommand to install only the dependencies of a modules. zef install --deps-only . This installs all the modules referenced in the depends object in META6.json. Is there a similar flag to install all the modules in the test-depends object in META6.json?
Tyil
2

votes
0

answer
38

Views

How to use certfp with IRC::Client

I've used IRC::Client for a number of IRC bots so far, and I would like to use it for a new project too. However, this time I will need to have the bot authenticate using certfp. A search for "certfp" on the module's GitHub repository yields no results. Is it possible to configure IRC::Client with a...
Tyil
9

votes
0

answer
126

Views

Setting TCP flags with IO::Socket::Async

I'm writing a Telnet library, and one of the commands requires setting the URGENT flag on the TCP packet sent according to RFC854: The Synch is sent via the TCP send operation with the Urgent flag set and the DM as the last (or only) data octet. How can I do this?
Kaiepi
9

votes
0

answer
126

Views

Is there any way to list the functions and data structures available from the native interface in Perl 6?

Mainly with the objective of creating sensible examples, I'd like to know which data structures and rountes are available for use in the Perl6's native interface, as in class a-class is repr('CStruct') { has int $.whatever; } class another-class is repr('CPPStruct') { has int $.whateverelse; } sub...
jjmerelo
5

votes
1

answer
137

Views

Execute code block in nested regex only if the whole match succeeded in Perl 6

I would like a code block within a nested regex to be executed only if the whole pattern matches. Here's my test code. my regex left { | a { take "left: 'a' matched" } | aa { take "left: 'aa' matched" } } my regex right { b } my regex whole { ^ $ } my $string = 'aab'; my @left_history = gather $str...
Eugene Barsky
5

votes
1

answer
41

Views

Promise - start - await: output order

Is the order of the values returned by await always relative to the input order? my @aoa = ( qw, qw, qw, qw, qw, qw, qw, qw, qw, ); my @portions = ( ( 0, 2 ), ( 3, 5 ), ( 6, 8 ) ); my @promise; for @portions -> $range { @promise.push: start { do for $range[0] .. $range[1] -> $row { do for ^@aoa.[$ro...
sid_com
3

votes
1

answer
500

Views

An array of array variable in Perl 6

How can I declare and create a variable of type "array of array" in Perl 6? In the Perl's 6 documentation there's nothing about that. Theoretically, I can do this @@var1 but that doesn't work.
アレックス
3

votes
2

answer
101

Views

How do I `say` and `print` into a buffer?

In Perl 6 the Str type is immutable, so it seems reasonable to use a mutable buffer instead of concatenating a lot of strings. Next, I like being able to use the same API regardless if my function is writing to stdout, file or to an in-memory buffer. In Perl, I can create an in-memory file like so m...
user7610
3

votes
1

answer
89

Views

How to store a reference to parent object in perl6 (conversion from perl5)

I'm trying to create a Perl 6 client interface to an RPC server, with the class hierarchy matching the server URLs. e.g. # for url path: /account/login # client code: $client.account.login; For this to work, the 'child' object (account) needs to store a reference to its parent object (client). This...
fireartist
1

votes
1

answer
99

Views

Trying to use threads as demonstrated on Perl6.org

I saved my $thread = Thread.start({ for 1 .. 10 -> $v { say $v }}); from https://docs.perl6.org/language/concurrency#Threads into a file and ran perl6 file.pl but get error Undeclared name: Thread used ... Any ideas how to fix the problem? (The documentation doesn't mention using any packages.) [E...
Apshir
12

votes
1

answer
144

Views

Perl6 IO::Socket::Async truncates data

I'm rewriting my P5 socket server in P6 using IO::Socket::Async, but the data received got truncated 1 character at the end and that 1 character is received on the next connection. Someone from Perl6 Facebook group (Jonathan Worthington) pointed that this might be due to the nature of strings and by...
Zarul Zakuan
5

votes
2

answer
102

Views

* quantifier in Perl 6

This seems to be something very basic that I don't understand here. Why doesn't "babc" match / a * / ? > "abc" ~~ / a / 「a」 > "abc" ~~ / a * / 「a」 > "babc" ~~ / a * / 「」 # WHY? > "babc" ~~ / a + / 「a」
Eugene Barsky
7

votes
2

answer
148

Views

What is the syntax for deleting an array element if you don't know its index?

You can use the adverb :delete in Perl 6 to delete an array element if you know its index: my @letters = ; @letters[0]:delete; say @letters # OUTPUT: «[(Any) b c]␤» However, you can't do that if you don't know the index: my @letters = ; $_:delete if $elem eq 'a' for @letters #ERROR! → Variable...
jjmerelo
4

votes
1

answer
68

Views

Where is “require” defined?

I have been looking in Rakudo source for the implementation of require, first out of curiosity and second because I wanted to know if it was returning something. I looked up sub require and it returned this hit, which actually seems to be the source for require, but it's called sub REQUIRE_IMPORT. I...
jjmerelo
5

votes
2

answer
58

Views

Perl 6 $*ARGFILES.handles in binary mode?

I'm trying out $*ARGFILES.handles and it seems that it opens the files in binary mode. I'm writing a zip-merge program, that prints one line from each file until there are no more lines to read. #! /usr/bin/env perl6 my @handles = $*ARGFILES.handles; # say $_.encoding for @handles; while @handles {...
Arne Sommer
18

votes
4

answer
1.7k

Views

Is there a working CPAN/CPAN6 like project for Perl 6?

I'm playing around with Rakudo Perl 6 lately and was searching for a project similar to CPAN. I found CPAN 6, but I think there is no Perl 6 code yet. So I'm looking for some alternative that does not necessarily aim to be a long term solution, but is capable of maintaining modules and is written...
matthias krull
1

votes
0

answer
5

Views

Obtaining the Pod of a module without explicitly exporting it

The documentation in Perl 6 programs, using the Pod 6 DSL, are actually parsed as part of the code; this makes that documentation available, inside the program, as the $=pod variable. However, I'd like to have access to that variable in order to process it from, say, tests. In this example I wrote f...
jjmerelo
19

votes
2

answer
1.2k

Views

How many ways are there to describe the Fibonacci sequence in Perl 6?

I've been looking at the various ways of constructing lazy lists in Perl 6 and I would like to collect all of the concise ways of describing the Fibonacci sequence. I will start this off with the three from masak's journal: my @fibs := (0, 1, -> $a, $b { $a + $b } ... *); my @fibs := (0, 1, { $^a +...
Eric Strom
4

votes
1

answer
195

Views

Will writing module in NQP (Not Quite Perl) speed up perl6 program?

NQP was mainly designed to bootstrap the perl6 language, but I'm thinking whether it is possible to use it as optimization. I know that rakudo is not perfectly optimized yet, but I'm looking for a long term approach. Perl6 has some low level data types and some compiler and backend level ideas that...
teodozjan
4

votes
2

answer
166

Views

Can you loop a Perl 6 block that's in a variable?

I keep wanting to do something like this: my $block := { state $n = 0; say $n++; last if $n > 3; }; loop $block; Or even: $block.loop; I'm not expecting that this is possible but it would sure be cool if it was. How would I find out where a particular routine comes from? $ perl6 To exit type 'exit'...
brian d foy
4

votes
1

answer
131

Views

Perl 6 function argument syntax in the interpreter (REPL)

There seems to be some inconsistencies in the argument syntax in the interpreter. I am using the latest Rakudo. Please see the following terminal output: $ perl6 To exit type 'exit' or '^D' > say: "foo" foo > say("foo") foo > say "foo" ===SORRY!=== Error while compiling: Two terms in a row ------> s...
lisprogtor
5

votes
2

answer
115

Views

:ex and :ov adverbs with Perl 6 named captures

I don't fully understand, why the results are different here. Does :ov apply only to , so having found the longest match it wouldn't do anything else? my regex left { a | ab } my regex right { bc | c } "abc" ~~ m:ex/ {put $, '|', $}/; # 'ab|c' and 'a|bc' say '---'; "abc" ~~ m:ov/ {put $, '|', $}/...
Eugene Barsky
6

votes
1

answer
229

Views

A constructor with only 1 argument in Perl 6

I want to override new so that my class can be created only by passing one argument to the constructor, no more and no fewer. class MyClass { has $.var1; method new($var1) { return MyClass.new(var1 => $var1); } } my $my_class1 = MyClass.new(33); say $my_class1.var1; The error is: Too few positionals...
6

votes
1

answer
122

Views

How do I pass an arbitrary list of arguments on the command line in Perl 6?

I know how to pass single and named arguments on the command line to a Perl 6 script, but how do I pass an arbitrary list of arguments? For example, script.pl6 fileA.txt fileB.txt and then run it with script.pl6 fileC.txt fileD.txt .. fileZ.txt
CyberSkull

View additional questions