Questions tagged [perl6]

2

votes
0

answer
11

Views

How to determine the absolute path name of the compilation unit of the caller?

According to p6doc 5to6-perlfunc: FILE Replaced by $?FILE which is slightly different from __FILE__ in that it is always an absolute path, rather than a relative one in the Perl 5 case. and according to p6doc CallFrame: With no arguments the callframe will give you frame information for the line cal...
Håkon Hægland
5

votes
0

answer
32

Views

Access JSON::Path numbers only key

What is the correct syntax to acces a json key that does only has numbers with Perl6 Module JSON::Path? I'm getting 'JSON path parse error at position 6' erros. I would like to access items->2018->name: use JSON::Path; my Str $json = 「 { 'items' : { 'old' : { 'name' : 'olditem' }, '2017' : { 'na...
Valle Lukas
15

votes
3

answer
1.6k

Views

How to check if a file is a text file?

Does Perl6 have something like the Perl5 -T file test to tell if a file is a text file?
sid_com
8

votes
1

answer
166

Views

Why don't all the shell processes in my promises (start blocks) run? (Is this a bug?)

I want to run multiple shell processes, but when I try to run more than 63, they hang. When I reduce max_threads in the thread pool to n, it hangs after running the nth shell command. As you can see in the code below, the problem is not in start blocks per se, but in start blocks that contain the sh...
5

votes
2

answer
140

Views

When I run a perl raku command line program a lib directory appears in the current working directory - how do I prevent this?

When I run a perl raku command-line program a lib directory (and precomp files) appear in the current working directory - how can I prevent/avoid this?
user2145475
8

votes
1

answer
123

Views

Blob.decode with replacement does not seem to work

This code: my $þor-blob = Blob.new('þor'.ords); $þor-blob.decode( 'ascii', :replacement('0'), :strict(False) ).say Fails with: Will not decode invalid ASCII (code point > 127 found)␤ And this one: my $euro = Blob.new('3€'.ords); $euro.decode( 'latin1', :replacement('euro') ).say Simply does n...
jjmerelo
7

votes
2

answer
79

Views

Errors with role “currying”

In the Perl 6 world, currying is an universal term indicating partial instantiation, and it's also used in the world of (parametrized) roles. However, it's not clear how to actually use it: role Zipi[::T] {}; class Zape does Zipi[::T] {} errors with No such symbol T; same if we use simply T when dec...
jjmerelo
9

votes
1

answer
79

Views

What is the difference between -I. and -Ilib in Perl6?

I have a local distribution laid out as follows: . ├── META6.json └── lib └── Foo.pm6 Both perl6 -I. -e 'use Foo;' and perl6 -Ilib -e 'use Foo;' compile and run, so which one should I use and why?
ugexe
2

votes
1

answer
26

Views

Reading file line by line in Perl6, how to do idiomatically?

I have a rudimentary script in Perl6 which runs very slowly, about 30x slower than the exact perl5 translation. CONTROL { when CX::Warn { note $_; exit 1; } } use fatal; role KeyRequired { method AT-KEY (\key) { die 'Key {key} not found' unless self.EXISTS-KEY(key); nextsame; } } for dir(test => /^n...
con
6

votes
1

answer
100

Views

defined-or “//” over multiple lines

Why are version 1,2 and 3 working, but version 4 fails with: Null regex not allowed when using // over multiple lines? #1 say Nil // try {'a'++} // 1; #2 say Nil // try {'a'++} // 2; #3 say Nil // 3; #Fails with: Null regex not allowed say Nil // try {'a'++} // 4;
Valle Lukas
6

votes
2

answer
127

Views

Are our variables dynamic?

This code will print out 'Duo' even though $var is not a dynamic variable with a * twigil: our $var='Duo'; sub sub1() { say $*var; } sub1(); #output is 'Duo' Adding a unit package ABC; at the start gives a compile time error 'Dynamic variable $*var not found': unit package ABC; our $var='Duo'; sub...
drclaw
7

votes
2

answer
194

Views

How to avoid importing default symbols when using a module?

I am going to use Hash::Merge as an example. Consider: use v6; use Hash::Merge; # [1, 2, 3], b => 'xxx', c => { ca => 1 }, e => 5; my %hash2 = a1 => [1, 5, 3], b => 'yyyy', c => { ca => 5, f => 'a' }, d => 4; my %res = merge-hash(%hash1, %hash2, :no-append-array); Suppose I do not want to pollute m...
Håkon Hægland
1

votes
1

answer
0

Views

Default definition of white space method ws in a grammar

According to the documentation the default definition of the ws method in a grammar is to match zero or more whitespace characters, as long as that point is not within a word: regex ws { \s* } What is the difference between this definition and the following: regex ws { \s+ } I wonder why the zero w...
Håkon Hægland
2

votes
0

answer
12

Views

Huge memory usage with circular pipeline

I've got a pipeline which executes a code block on a different thread at each stage. The result of a stage is sent/emitted via a Channel/Supplier. The next stage taps the the output of the previous. The last stage sends/emits to the first stage, and thus a circular pipeline runs continuously even f...
drclaw
5

votes
2

answer
97

Views

Is there a 'clamp' method/sub for ranges/Num etc in Perl6

Is there a 'clamp' or equivalent method or sub in Perl6? eg my $range= (1.0 .. 9.9) my $val=15.3; my $clamped=$range.clamp($val); # $clamped would be 9.9 $val= -1.3; $clamped=$range.clamp($val); # $clamped would be 1.0 Cheers
drclaw
10

votes
1

answer
142

Views

Why the performance difference in += vs +?

Debugging some code ended up testing the differences in the statements such as $counter=$counter + 1; vs $counter+=1; my $run=True; my $counter=0; my $sup=Supply.interval(1); my $tap= $sup.tap({ $run=$_ < 10; }); { while $run { #$counter+=1; $counter=$counter + 1; } $tap.close; say 'Iterations per s...
drclaw
7

votes
3

answer
84

Views

Sigilless variables, constants, bindings: when to choose what

So, from the documentation is almost clear what the three entities from the title are, but it is not very clear what their purpose is. Constants are common in many languages. You don't want to write 3.14 all over your code and that's why you define a constant PI that, by the nature of the thing it r...
pistacchio
1

votes
0

answer
4

Views

How to tell the difference between types of nqp iterators

In nqp, you can create an iterator on an nqp hash, or on an nqp list. I would like to be able to find out if a given nqp iterator is iterating over a hash or a list. Alas, I have not find a way to do that. They even seem to share the same name: use nqp; dd nqp::iterator(nqp::hash).^name; # BOOTI...
1

votes
1

answer
65

Views

Perl6 grammar and action error : “Cannot find method 'ann' on object of type NQPMu”

Okay, I am still having trouble with perl6 grammar and action. I want to find a pattern in a string, and as soon as it is is found, change the pattern according to action, and return the modified string. my $test = 'xx, 1-March-23, 23.feb.21, yy foo 12/january/2099 , zzz'; # want this result: xx, 0...
lisprogtor
1

votes
1

answer
103

Views

What's the build script for a module distribution?

I have test failures. I want to see the details and experiment and perhaps debug, so I unpack the module dist. Now I expect to find some analogue to Setup.hs, setup.py, Build.PL, Rakefile etc., but there are no executables. How do you manually build and test verbosely?
daxim
1

votes
1

answer
124

Views

Sorting with modified alphabet in Perl 6

I have to sort lists of strings using differently 'modified' alphabets. E.g. between letters 's' and 't' there are two additional letters ('s' with diacritics), so that this part of alphabet becomes: '... q r s ṣ š t u ...'. By default, sort will put first words beginning with letters without di...
Eugene Barsky
1

votes
1

answer
64

Views

Perl6: Picking a pair of coordinates

I was trying to find a way to print a random list of coordinates, without any duplicates, given a min and max value for both dimensions. Though I am having having a hard time understanding the 'X' and '>>' exactly does or means. Can anyone help explain this? my $a=3; my $b=3; for (^$a X ^$b)>>.Array...
Mikkel
6

votes
3

answer
156

Views

Creating a Maybe type in Perl 6

I have a lot of functions that can fail, but also have a return type defined in their signature. Since I like defining the types of variables whenever possible, I want to define a Maybe subset to use for this. What I came up with is this: subset Maybe is export of Mu where Mu | Failure; The problem...
Kaiepi
9

votes
1

answer
99

Views

Recursive regular expression in Perl 6?

I've been trying to figure out how to do a recursive regular expression in Perl 6. For a toy example, a balanced parentheses matcher, which would match ((())()) inside (((((())()). PCRE example: /\((?R)?\)/ Onigmo example: (?\(\g*\)) I thought this would do it: my regex paren { '(' ~ ')' * } or the...
Amadan
6

votes
1

answer
63

Views

Perl6 REPL print behaviour

When I execute the following statement in the Perl6 REPL: my $var = 1, 2, 3; it prints: (1 2 3) This seems curious to me, because $var is actually assigned a single integer (i.e. $var.WHAT returns (Int)), rather than a List of Ints. I take it that the reason that an Int is assigned is the higher pr...
ozzy
2

votes
1

answer
7

Views

Perl6 crashes, “left argument in overloaded package Perl6::Object”

I'm writing an excel xlsx spreadsheet with Perl6 and inline::Perl5. When I write a line like $file-location-ws.write($row, 2, $csv); Perl6 crashes with the cryptic error message Operation 'eq': no method found, left argument in overloaded package Perl6::Object, right argument has no overloaded...
con
7

votes
2

answer
118

Views

Map signature mismatch with Whatever? x vs X vs xx

The last line here results in a incorrect signature to the map call: my @array=[0,1,2]; say 'String Repetition'; say @array.map({($_ x 2)}); say @array.map: * x 2; say '\nCross product '; say @array.map({($_ X 2)}); say @array.map: * X 2; say '\nList Repetition'; say @array.map({$_ xx 2}); say @arra...
drclaw
0

votes
0

answer
7

Views

A Perl 6 Regex to match a Perl 6 delimited comment

Anyone have a Perl 6 regular expression that will match Perl 6 delimited comments? I would prefer something that's short rather than a full grammar, but I rule out nothing. As an example of what I am looking for, I want something that can parse the comments in here: #`{ foo {} bar } #`« woo woo »...
zostay
1

votes
3

answer
673

Views

How does opendir work in Perl 6?

Can someone tell me, why the 'opendir' doesn't work? #!/usr/bin/env perl6 use v6; my $file = 'Dokumente/test_file'; if ( my $fh = open $file, :r ) { for $fh.lines -> $line { say $line; } } else { say 'Could not open '$file''; } my $dir = 'Dokumente'; my $dh = opendir $dir err die 'Could not open $di...
sid_com
5

votes
2

answer
86

Views

Capturing a module output

Say we have this module: unit module outputs; say 'Loaded'; And we load it like this use v6; use lib '.'; require 'outputs.pm6'; That will print 'Loaded' when it's required. Say we want to capture the standard output of that loaded module. We can do that if it's an external process, but there does n...
jjmerelo
7

votes
2

answer
134

Views

Perl6: large gzipped files read line by line

I'm trying to read a gz file line by line in Perl6, however, I'm getting blocked: How to read gz file line by line in Perl6 however, this method, reading everything into :out uses far too much RAM to be usable except on very small files. I don't understand how to use Perl6's Compress::Zlib to get ev...
con
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
8

votes
3

answer
172

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

View additional questions