lisprogtor

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
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
1

votes
2

answer
27

views

How to use awk or other tools to rearranged fields if matched

I have a file from output of a lisp program: (john (a b c (grade 90 good))) (doe (e f (grade 80 fair) g h i j)) (mary ((grade 100 best)) (jane (x y (grade 95 better) z)) I want to move (grade number description) to right next to the name; e.g., (john (grade 90 good) (a b c)) (doe (grade 80 fair) (...
lisprogtor
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
1

answer
56

views

perl6 What is the best way to match any of a group of words?

I am trying to find a simple way to match any of a group of words. I have been using a for loop, but is there a simpler way? my @a=; my $x='a1234567'; say $x ~~ m/ @a.any /; It returns False. Is there a way to make it work? Thanks.
lisprogtor
5

votes
1

answer
87

views

perl6 How to use adverbs as variables?

I am trying to match a string either case-sensitive or case-insensitive. Is there a way to make the .match method take adverbs as variables? my $aString = 'foo bar baz'; my @anArray = ; my $anAdverb = :i; my $firstCheck = ($aString.match(/$anAdverb '@anArray[0]' /)).Bool; Using $anAdverb inside the...
lisprogtor
3

votes
3

answer
143

views

perl6 rakudo 2016.11 match tries to assign to read-only variable, why not in 2016.07?

I have the following method in an action class that worked well in Rakudo 2016.07, but I just installed 2016.11 and now the new Rakudo says my method tries to assign to read-only varible, and I just don't see the problem: method ptName ($/) { my $nameStr = $/.Str, my $lastName, my $firstName; my $...
lisprogtor
3

votes
1

answer
88

views

perl6 array assignment: pointer or copy?

In perl6, I want to assign an array to another array and have the resulting array be distinct entity, but it seems neither direct assignment nor cloning can do what I want. Is there a way to copy array over with one expression instead of writing a loop routine? To exit type 'exit' or '^D' > my @a= [...
lisprogtor
3

votes
1

answer
98

views

perl6 Any string port similar to Racket Scheme for reading data?

In Racket Scheme, there is a data structure called 'string port' and you can read data from it. Anything similar in perl6? For examples, I want to achieve these outcomes: my $a = '(1,2,3,4,5)'; # if you read from $a, you get a list that you can use; my $aList=readStringPort($a); say $aList.WHAT; # (...
lisprogtor
3

votes
2

answer
108

views

Special meaning of <> and anonymous arrays inside regex in Perl 6

Outside regex, behaves more or less like single quotes. My shallow understanding seems to tell me that, inside regex, allows evaluation and interpolation of codes: # Outside regex, acts like single quotes: > my $x = {'one'} > $x.WHAT (Str) # Inside regex, evaluates and interpolates: > my $b='on...
lisprogtor
3

votes
1

answer
89

views

perl6 Performance difference between @$aList and $aList

I have data structures that are very large and need to be assigned and passed around. I also need to get inside the list. Sometimes when a list is in a scalar container, $aList.elems will say 1 because there is only one element which is the list. To get inside the list, (@$aList).elems will give the...
lisprogtor
6

votes
2

answer
92

views

perl6 IO::Handle has no printf method, inconsistent with documentation, or I missed something?

I am trying to open a file for writing and use printf to do formatting, but documentation and reality do not seem to agree. Am I missing something? To exit type 'exit' or '^D' > my $fh=open 'test', :w; IO::Handle(opened, at octet 0) > $fh.printf: 'test'; No such method 'printf' for invocant of type...
lisprogtor
3

votes
1

answer
63

views

Using eof or end-of-input in ff match?

I have a huge data file in the following format: section 1 data 1 end section section n # n is a large number > 10000 data n end section The marker for the end of each section is the same, 'end section'. I need to frequently get a section and then another section to the end of the file. I do so in 2...
lisprogtor
2

votes
2

answer
136

views

perl6 How to match a character only under some conditions?

I have a file in the format: - foo bar - baz one two three - or four and another line - next job do this - and that and my grammar is grammar tasks { regex TOP { \n* + \n* } regex oneTask { ^^ \- ( )+ } regex oneSection { \N+ } # this is not quite working regex endSection { \n+ } } in the...
lisprogtor
2

votes
1

answer
122

views

perl6 Passing operators as arguments

I am trying to achieve some functionality similar to Scheme by defining and passing raw operators. In Scheme, you can (define x +) (x 1 2) and this operation will give you answer 3. In perl6, I somehow have to place the operator in another function in order to achieve the same: sub x($a) { $a * 2; }...
lisprogtor
3

votes
3

answer
111

views

perl6 Grammar action class method seems not inherited, named capture seems not made

I am trying to parse a csv file to do simple things: extract last name, ID, and birthday, and change format of birthday from m/d/yyyy to yyyymmdd. (1) I used named capture for birthdays, but it seems that named captures method are not called to make what I want. (2) Inheriting grammar action methods...
lisprogtor
4

votes
2

answer
157

views

perl6 Negating multiple words and permutations of their chars inside a regex

What is the best way to perform, inside a regex, negation of multiple words and permutations of chars that make up those words? For instance: I do not want 'zero dollar' 'roze dollar' 'eroz dollar' 'one dollar' 'noe dollar' 'oen dollar' but I do want 'thousand dollar' 'million dollar' 'trillion dol...
lisprogtor
4

votes
2

answer
144

views

perl6 How to get all lines that are not indented by x-width of spaces?

I have a very, very large text file that I am working on that has lines with various sizes of indentations. Those lines that are acceptable have 12-character-width of indentations, which are created by combination of tabs and spaces. Now I want to get all the lines that do not have 12-character-widt...
lisprogtor
3

votes
2

answer
90

views

perl6 how to get specific identity of promises?

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'...
lisprogtor
3

votes
3

answer
271

views

perl6 Is there a way to do editable prompt input?

In bash shell, if you hit up or down arrows, the shell will show you your previous or next command that you entered, and you can edit those commands to be new shell commands. In perl6, if you do my $name = prompt('Enter name: '); it will print 'Enter name: ' and then ask for input; is there a way t...
lisprogtor
2

votes
2

answer
152

views

Perl6: how to use <alpha> in user-defined character class or range?

I am trying to match any alphabetical characters and ',' or ';' and I am trying to use ' Alphabetic characters' according to the documentation https://docs.perl6.org/language/regexes . However, the compiler complains. What is the proper way to do it without using a..zA..Z ? say 'a,b,c;d,e;xyz...
lisprogtor
3

votes
1

answer
67

views

perl6 negating user-defined caracter class

I am trying to ignore all lines that has a quotation mark in it, somehow it is kind of onfusing: > my $y='\'\'''; \'\'' > so $y ~~ m/ $y ~~ m// (「\」 「\」) > $y ~~ m:g/ $y ~~ m/ the same as + /; 「no 」 > say 'no 'foo' quotes' ~~ / , i.e., escape \ and escape '. What did I misunderstand?...
lisprogtor
4

votes
1

answer
86

views

Why is perl6 regex ~~ trying to assign to immutable container?

I am trying to extract the first name in a regex, but ~~ seems to want to assign to an immutable container. Why so? What did I do wrong? my $test= ' 'DOE , JOHN' '; grammar findReplace { regex TOP { \s* \s* } regex ptName { } regex aName { \' .+? \' } } class rsAct { me...
lisprogtor
4

votes
1

answer
61

views

Why do Perl 6 state variable behave differently for different files?

I have 2 test files. In one file, I want to extract the middle section using a state variable as a switch, and in the other file, I want to use a state variable to hold the sum of numbers seen. File one: section 0; state 0; not needed = start section 1 = state 1; needed = end section 1 = section 2;...
lisprogtor
3

votes
2

answer
92

views

why can't perl6 just autovivify so that I don't have to use “my” all the time?

In per5, I can just use a variable, such as $foo or @bar without using 'my'. $foo=1; @bar=(1,2); In perl6, why do I have to use 'my' all the time? Otherwise compiler will say variable undeclared.Why can't perl6 just autovivify? print '{my @a=1,2,3;}\n'; # have to use 'my' to declare variable print '...
lisprogtor
4

votes
1

answer
83

views

perl6 Thread reading interference

I need to have multiple threads each read from the same socket or from $*IN; however, there seems to be error because each is trying to read from the same source (I think). What is the best way to resolve this problem? Thanks !! my $x = start { prompt('I am X: Enter x: '); } my $y = start { prompt('...
lisprogtor
3

votes
1

answer
66

views

perl6 grammar to do substitution

Ok, I am learning perl6 and I am trying to do something really simple: use grammar to change matched text according to the action object. But I failed and I don't know why. Please excuse me for such simple questions. I am not in the tech or programming industry. So, please be patient with me, okay?...
lisprogtor
3

votes
1

answer
53

views

perl6 How to re-open $*IN for input?

I have been trying to read characters from $*IN, including control characters. However, after Control-D has been entered, it seems that $*IN becomes non-functional. How can I re-open $*IN for reading? To exit type 'exit' or '^D' > my $x=$*IN.getc # entered 'e' e e > say ($x=$*IN.getc).or...
lisprogtor
3

votes
1

answer
82

views

perl6 How to do something at BEGIN and END of piped $*IN?

In awk, there are special patterns BEGIN and END that allow you to do something before and after the inputs are read. What is the equivalent functions in perl6? For instance: cat someFile | perl6 -ne '{do something before reading input} {do something else with input} {do something last after all in...
lisprogtor
5

votes
1

answer
75

views

perl6: how to specify multiple requirements for a parameter of a function?

I have a special function that takes a list, each member of the list must satisfy multiple requirements. How do I set this up in a perl6 function? sub specialFunc(List $x) {}; (1) $x is a list # easy, List $x, but what about the following: (2) each member of $x is numeric (3) each member of $x is po...
lisprogtor
5

votes
1

answer
171

views

perl6 Need help to understand more about proto regex/token/rule

The following code is taken from perl6 website tutorial, and I am trying to learn more about it before more experimentation: proto token command {*} token command:sym { } token command:sym { } token command:sym { } token command:sym { } Is the * in the first line a whatever-star? Can it be...
lisprogtor
1

votes
1

answer
110

views

perl6 Permutation match

I am still trying to work on permutation match, and I wonder if anyone has better way to do it. I want to match all patterns in an array in any order, i.e., match permutations of items (string or other objects) in an array. E.g., if array is (1,2,3), then it is true if a string contains 1 and 2 and...
lisprogtor
2

votes
2

answer
105

views

How do I access the captures within a match?

I am trying to parse a csv file, and I am trying to access names regex in proto regex in Perl6. It turns out to be Nil. What is the proper way to do it? grammar rsCSV { regex TOP { ( \s* \s* \, \s* )* } proto regex oneCSV {*} regex oneCSV:sym {
lisprogtor
7

votes
2

answer
179

views

perl6 Simultaneous substitutions with s///?

Is there a way to do simultaneous substitutions with s///? For instance, if I have a string with a number of 1s, 2s, 3s, etc, and I want to substitute 1 with 'tom', and 2 with 'mary', and 3, with 'jane', etc? my $a = '13231313231313231'; say $a ~~ s:g/1/tom/; say $a ~~ s:g/2/mary/; say $a ~~ s:g/3/j...
lisprogtor
4

votes
1

answer
70

views

perl6 Unable to initialize a state variable. Help needed

I want to use a one-liner to print a middle section of a file by using a state variable to indicate whether the current line is within the desired section of the file. But I am unable to initialize the state variable. Initialization is so simple, and I just cannot find what the problem is. Please he...
lisprogtor
2

votes
1

answer
150

views

Converting java object and method calls to Clojure codes

I was specifically trying to test Cjoures's claim that it can work with Java 'seamlessly'. In general, how do you translate Java code: object1.object2(some_args).object3.object4(some_other_args).object5.objectnth.method(arg‌​1, arg2, argn); to Clojure? Some of the objects in the chain maybe sta...
lisprogtor
14

votes
2

answer
214

views

perl6 grammar , not sure about some syntax in an example

I am still learning perl6, and I am reading the example on grammar from this page: http://examples.perl6.org/categories/parsers/SimpleStrings.html ; I have read the documentations on regex multiple times, but there are still some syntax that I don't understand; can anyone enlighten me? Thank you ver...
lisprogtor
2

votes
1

answer
46

views

perl6 what is the best way to enter multiple multi-line here-docs from $*IN

I need to enter multiple HERE-DOCs. My codes have 2 while loops. The inner loop is used to get the multi-line here-doc. But after I enter Control-D to complete one here-doc, then the inner while loop does not run again and the outer loop runs infinitely. What is the best way to fix it? while True {...
lisprogtor
5

votes
1

answer
109

views

perl6 Is using junctions in matching possible?

Is it possible to use junction to match any of the values in a junction? I want to match any of the values in an array. What is the proper way to do it? lisprog$ perl6 To exit type 'exit' or '^D' > my @a= [a b c] > any(@a) any(a, b, c) > my $x=any(@a) any(a, b, c) > my $y = 'a 1' a 1 > say $y ~~ m/...
lisprogtor
5

votes
1

answer
94

views

perl6 Catching non-fatal exceptions in autovivification

I am running analysis on about 10000 lines of numbers, and some of the lines give me errors: 'Use of uninitialized value of type Any in numeric context'. I am trying to catch this error to see which lines are causing the problem. However, the X::TypeCheck, and other X::* classes don't seem to do eff...
lisprogtor

View additional