Re: pint: Elizabeth, sort list???
hello, > ==> sort({ | map { +$_ // $_ }, .split: /\d+/, :v }) ==> say() ok … so I'm lost but I'm not even curious to understand why (because of my lack of interest for the ==> operator :)) regards marc -- Marc Chantreux Pôle CESAR (Calcul et services avancés à la recherche) Université de Strasbourg 14 rue René Descartes, BP 80010, 67084 STRASBOURG CEDEX 03.68.85.60.79
Re: pint: Elizabeth, sort list???
hello, > How would you write that expression using the feed operator? I tried < afoo12 afoo2 > ==> {.sort: { | map { +$_ // $_ }, .split: /\d+/, :v }} ==> {map &say} and the error message is really interesting Only routine calls or variables that can '.append' may appear on either side of feed operators. on the other hand: I really don't understand why ==> even exists as method call syntax works well. < afoo12 afoo2 > .sort( { | map { +$_ // $_ }, .split: /\d+/, :v } ) .map(&say) what I would love instead is something closer than the haskell's $ operator with a very low priority so it could be possible to be parenthesis free. as example. I would like 1..10 ==> map * * 2 ==> say to be a joyful version of (1..10).map(* * 2).say regards -- Marc Chantreux Pôle CESAR (Calcul et services avancés à la recherche) Université de Strasbourg 14 rue René Descartes, BP 80010, 67084 STRASBOURG CEDEX 03.68.85.60.79
Re: pint: Elizabeth, sort list???
Hi rakoons, On Sun, Mar 03, 2024 at 01:22:45PM +0100, Elizabeth Mattijsen wrote: > Actually, the expression can be refined a bit: > > say .sort(*.split(/\d+/, :v).map({ (try .Int) // $_}).List) Which is gorgeous! thanks for that. I read the documentation which is clear about all the magic in action there. So I played a little with it and came with this sort .say for < afoo12 afoo2 abar12 abar9foo abar64foo abar64bang abar64bang4foo abar64bang4bar abar64bang5bar abar64foo abar64foo4foo abar64foo4bar abar64foo14bar abar64foo5bar afoo13 afoo4 >.sort: { | map { +$_ // $_ }, .split: /\d+/, :v } The ouput seems to be ok. regards, -- Marc Chantreux Pôle CESAR (Calcul et services avancés à la recherche) Université de Strasbourg 14 rue René Descartes, BP 80010, 67084 STRASBOURG CEDEX 03.68.85.60.79
Re: who call raku?
On Thu, Feb 08, 2024 at 02:25:00PM -0800, ToddAndMargo via perl6-users wrote: > Actually, I am looking for the name of the calling program: > Cobian, Task manager, deamon, etc.. linux centric anwser: raku -e 'say "/proc/{"/proc/$*PID/stat".IO.words[3]}/comm".IO.lines[0]' hth -- Marc Chantreux Pôle CESAR (Calcul et services avancés à la recherche) Université de Strasbourg 14 rue René Descartes, BP 80010, 67084 STRASBOURG CEDEX 03.68.85.60.79
Re: steps of a path
Hi Ralph, > Given that the broader picture is file/path related operations, it makes > sense to me you're mostly exploring use of `.parent` and `map`s etc. Actually what I really like the most from all your answers was the fact that I learned a lot not only about the langage but also some idoms. > Is that because it knows me, or has google started blessing Larry's > neologisms for the whole planet?!? ) Why not? new words happens all the time and those one are useful for programmers. -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: steps of a path
I love this one. I used uniq and run so the whole script can be run from raku (except the xargs ls avoid the ARG_MAX error) <<. raku -e 'run < ls -lUd >, unique map {(.IO, *.parent …^ "/")>>.Str.Slip}, lines' /var/log/messages /var/log/auth.log regards -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: steps of a path
Hi Ralph, > The `.Str.say` can be just `.put`. oh! got it. thanks :) > If not, can you see why I'm surprised -- why `m:g{ "/" <-[/]>+ }` > seems simpler to me than `m:ex{^ [:r "/" <-[/]>+]+? }`? I just played again with your solution and got the beauty of it. why made me realize I should take time between two post so I can have a fresh mindset for all of them! Actually: this is by far the simplest solution. Thanks. -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: steps of a path
hello William, On Sat, Sep 03, 2022 at 04:27:04PM -0700, William Michels wrote: > Hi Marc, There's also this conversation from March 2021 on the mailing list: > https://www.nntp.perl.org/group/perl.perl6.users/2021/03/msg9857.html > [Matthew's answer looks very interesting]. Interesting as it can provide a relative short solution with no advanced concept. I tried this line but got an immutability problem. I tried multiple work around with no success for the moment. <<. raku -e 'lines.IO.map: {repeat {.put} while not .=parent ~~ "/" }' /var/log/messages thank you -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: steps of a path
On Sat, Sep 03, 2022 at 09:50:08PM +0100, Ralph Mellor wrote: > > ( A B C ) to ((A) (A B) (A B C)) ? > [^1,^2,^3] I got that one and tried to generalize it with something more generic (using * to get the number of elements). thanks for helping -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: steps of a path
Hi Bruce and William, Ineed: I was looking for [\,] but your code removes the anoying empty string because of the leading / (which is awesome) so I mixed from both answers (<-[/]> is more robust than .alpha ) and added .Str to .say. finally I got: <<. raku -ne '.Str.say for m:ex /^ ["/" <-[/]>+:] **? 1..* /;' /var/log/messages ther is only one caracter I don't understand in this anwser so I considered removing it. bad idea: <<. raku -ne '.Str.say for m:ex /^ ["/" <-[/]>+ ] **? 1..* /;' /var/log/messages so I read about backtracking and found something I found a bit easier to get/memorize: the :r adverb. <<. raku -ne '.Str.say for m:ex{ ^ [ :r "/" <-[/]>+ ] **? 1..* }' /var/log/messages last but not least: **? 1..* is just +?. At this point, my prefered solution is: <<. raku -ne '.Str.say for m:ex{^ [:r "/" <-[/]>+]+? }' /var/log/messages and it is pretty good compared to the sed version: <<. sed -E ':b p; s:/[^/]+$::; t b' thank you very much to both of you: I learned a lot on this post. -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
steps of a path
hello people, I have this steps() function implemented this way in shell: steps() sed -r ':b p; s,/[^/]+$,,; t b' # demo: <<. steps | xargs ls -lUd /var/log/messages which shows -rw-r- 1 root adm 464304 Sep 3 19:03 /var/log/messages drwxr-xr-x 22 root root 4096 Sep 3 00:00 /var/log drwxr-xr-x 14 root root 4096 Jun 19 2021 /var for those who don't know sed that much, the perl equivalent is: steps() perl -lpe 'do {print} while s,/[^/]+$,,' I thought the raku one could be shorter but for now I'm stuck with a very long solution. my \path = [ "/var/log/messages" .split: "/" ]; .say for (^path).map( { path[0..$_].join: "/" } )[1..*]; I'm pretty sure I saw a very concise and elegant way to transform ( A B C ) to ((A) (A B) (A B C)) in the past but I'm enable to figure out how. Any help on that ? thanks by advance. -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: rotor in comb?
hello everyone and thanks Bruce and William for help, On Sat, Aug 27, 2022 at 01:25:32PM -0700, William Michels wrote: > ~$ raku -e '++(my %digraphs){$_} for slurp.lc.match(:global, :exhaustive, > /<[a..z]>**2/); .say for %digraphs.sort(-*.value);' richard3.txt I don't see a huge difference with the code Bruce posted previously. Did I miss something? On Sat, Aug 27, 2022 at 12:24:50PM -0500, Bruce Gray wrote: >> I do *not* think you can ("move the cursor backward in the comb >> regex"); See https://docs.raku.org/routine/comb : ... "returns a Seq >> of non-overlapping matches" ... I was diging in the regex syntax part of the doc but indeed: the comb part is clear, its name is too and I realize I was abusing it: match is the good thing to do. >> The "non-overlapping" nature is the problem. >> (Please let me know if this turns out to be incorrect!) If the cursor can be manipulated from the regex itself (:exhaustive is the thing I failed to find) but I try to be idiomatic so your answer fits! I noticed the usage of the hyperoperator » and wanted to know if we could take advantage if parallelism I found it a bit faster. It also shows that slurp.split('\n') is faster than lines by far (see below). Thanks again for helping me! slurp : 15.89s user 0.37s system 105% cpu 15.373 total slurp, split, race : 15.10s user 0.11s system 104% cpu 14.502 total line, race : 24.96s user 0.19s system 314% cpu 7.991 total set vi.macros vi.macros vi.macros vi.macros vi.macros \ vi.macros vi.macros vi.macros vi.macros vi.macros \ vi.macros vi.macros vi.macros vi.macros vi.macros \ vi.macros vi.macros vi.macros vi.macros vi.macros \ vi.macros vi.macros vi.macros vi.macros vi.macros \ vi.macros vi.macros vi.macros vi.macros vi.macros \ vi.macros vi.macros vi.macros vi.macros vi.macros \ vi.macros vi.macros vi.macros vi.macros vi.macros time raku -e 'slurp.lc.match(:exhaustive, /(<[a..z]> ** 2)/)».Str.Bag .sort({ -.value, ~.key })' "$@" time raku -e 'slurp.split("\n").map({ |map ~*, .lc.match(:exhaustive, /(<[a..z]> ** 2)/) }).flat.Bag.sort({-.value, .key})' "$@" time raku -e 'lines.race.map({ |map ~*, .lc.match(:exhaustive, /(<[a..z]> ** 2)/) }).flat.Bag.sort({-.value, .key})' "$@" raku -e ' lines.race.map({ |map ~*, .lc.match(:exhaustive, /(<[a..z]> ** 2)/) }).flat.Bag.sort({-.value, .key}).map: &say ' -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
rotor in comb?
hello people, Here is a little raku code to count all the digraphs from some text: my %digraphs = slurp.lc .comb(/<[a..z]>+/) .map( *.comb.rotor( 2 => -1, :!partial ).map: *.join ) .Bag; The first .comb match words then I map them to get digraphs but I think it is possible to move the cursor backward in the comb regex. I just don't know how. I'm trying to write something like: slurp.lc .comb(/ <[a..z]> ** 2 { --pos } /) .Bag; The perl version of it is: perl -lnE ' END { say "$_ = $digraph{$_}" for sort { $digraph{$b} <=> $digraph{$a} } keys %digraph } $_=lc; while (/([a-z]{2})/g) {++$digraph{$1}; --pos; } ' Any help is very welcome. regards, -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
questions about sigpipe
hello Rakoons, I found the sigpipe module [S13] while reading the Rakudo Weekly news[rwn] so Raku can handle SIGPIPE the way I think is the good one: raku -e 'loop { say "y"}' | sed 3q # some weird error raku -Msigpipe -e 'loop { say "y"}' | sed 3q # just works rwn: https://rakudoweekly.blog/2022/08/08/2022-32-2nd-conf/ S13: https://raku.land/zef:leont/sigpipe so now I have this 6 wrapper to make raku more unixish: 6() RAKUDO_ERROR_COLOR= raku -Msigpipe "$@" RAKUDO_ERROR_COLOR must be set because raku prints escape caracters in stderr by default, no matter if it is a tty. I never complained about it but I think of it as a bug. Also considered as a bug here was the default sigpipe handler raku -Msigpipe -e 'loop { say "y"}' | sed 3q Just works "as expected" and I don't know why Raku took so long to handle it this way. leont gave me the begin of the answer in the documentation of the module: «Raku's default sigpipe handling does the sensible things for networking applications, but entirely the wrong thing for CLI applications.» Can anyone give more detail about it? Thanks for any answer and regards, PS: sigpipe is also a nice example of usage for INIT and NativeCall. -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: something between run and qx() ?
Hi Liz! > sub prefix:<`>(*@a) { (run @a, :out).out.lines } Thanks for this example, I now can write things like .say for grep / '.txt' $ /, ` for ` { .say if / '.txt' $ / } which made me remember I wrote something similar (but not working) for the FOSDEM talk: sub prefix:<`>(|c) is tighter(&infix:<.>) { (run :out, c).out.lines } the `is tighter` thing was because I hoped I could write something like `.grep( / '.txt' $ / ).say Is is something to do to fix it ? Thanks everything you do on Raku! regards -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: something between run and qx() ?
hello Liz and thanks for helping, > I believe you could use App::Rak for that: > $ zef install App::Rak I'll test rak at some point but in this case, I can just write dpkg-query -f \${db-fsys:Files} -W gnuplot\* | raku -pe '.=trim; .say if .trim.IO.f' I asked the question about qx() and run because because I still have the "removing bash with raku" in mind and this is typically the kind of things where both tools comes with flaws. It would be nice to define a backtrick operator (like in rc) so we could write my @installed-files = grep *.IO.f, map *.trim, `< dpkg-query -f ${db-fsys:Files} -W gnuplot* >; insead of my @installed-files = grep *.IO.f, map *.trim, ( run :out, < dpkg-query -f ${db-fsys:Files} -W gnuplot* > ).out.lines; regards, -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: something between run and qx() ?
Hi Brian and thanks for your reply. > There is the 'x' adverb for Q -- I think qx is equivalent to Q:x exactly. that's why Q:x doesn't help as it still run sh -c to execute the command. regards, -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
something between run and qx() ?
hello people, I found myself choosing between raku -e ' (run :out, < dpkg-query -f ${db-fsys:Files} -W gnuplot* > ).out>>.lines>>.trim>>.grep(*.IO.f)>>.say' and raku -e ' qx< dpkg-query -f \${db-fsys:Files} -W gnuplot\* >.lines.trim>>.grep(*.IO.f)>>.say' I really love the qx syntax but * it runs an extra useless sh processus * I need to quote the shell symbols I read the Proc documentation and tried to see if there was another command or an adverb to the qx construction (something like :r for run). What I really would like to write is: raku -e ' qx:r< dpkg-query -f ${db-fsys:Files} -W gnuplot* >.lines>>.grep(*.IO.f)>>.say ' Any suggestion is welcome. Regards, -- Marc Chantreux Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: shorter way to set states in -n?
hello, > Is this a bug, or are my (our?) expectations wrong? I posted on the list precisely because the doc. wasn't enough to GTD so I can't reply your question :) regards -- Marc Chantreux Direction du numérique de l'Université de Strasbourg Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: shorter way to set states in -n?
Ralph, On Sat, Jul 02, 2022 at 08:27:19PM +0100, Ralph Mellor wrote: > Does this do what you want: > BEGIN my (@o, @f) = 0 xx 3; > @o.push: "ok"; > say @o; > seq 2|raku -ne ' BEGIN my (@o, @f) = 0 xx 3; @o.push: "ok"; say @o; ' works fine! thank you very much. -- Marc Chantreux Direction du numérique de l'Université de Strasbourg Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
shorter way to set states in -n?
hello rakoons, AFAIK about raku -n, I need 2 lines to setup a state with a default value seq 2| raku -ne ' state (@o, @f); BEGIN @o = 0 xx 3; @o.push: "ok"; say @o; ' but is there a shorter way ? regards, marc
Re: probably worth a bug report ?
Le Sun, Jan 02, 2022 at 12:32:46PM +0100, Elizabeth Mattijsen a écrit : > Maybe first explain why the error thanks for the explaination. especially > $ raku -e 'sub a(|c) { dd c }; a b => 42' > \(:b(42)) now my sub works the way I wanted: sub got (|c) { for c.hash.kv -> $rule ,$input { ok (my $r = Pugish.subparse: $input , :$rule ) , "match a $rule in: $input"; $r and return $r; } } got pair => 'obey the law'; > Again, it is all about *reading* the error message. > Is there room for improvement? There always is! I wrote this message mostly because the error message didn't help at all here but now i discovered and inspected the Capture, i realize the message was true but just left me clueless. Capture is a good way to understand what happened. > > Too few positionals passed; expected 1 argument but got 0 because c.list got is all ... many thanks for helping. marc
probably worth a bug report ?
hello rakoons, I got this error message Too few positionals passed; expected 1 argument but got 0 in sub xxx at - line 1 in block at - line 2 Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2021.09. Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d. Built on MoarVM version 2021.09. by running this: <<\-. raku; raku -v sub xxx ( Pair $test ) { $test.raku.say } xxx key => 'value'; and i think it's worth a bug: i don't know if xxx key => 'value' should parse but at least it deserve a less confusing message, don't you think ? regards marc
shell to raku
Le Fri, Dec 31, 2021 at 01:20:45PM +, Wesley Peng a écrit : > Replacing Bash scripts with Raku? That’s an interesting thing Well ... replacing bash is always a good thing but raku is not always the rhs of the substitution (could be dash/mksh/rc, make/mk, C, ...). raku is now my tool of choice when * manipulexity is important * performance is not The way i see the talk is: * show how to do simple things ($PATH vs $RAKULIB, ...) * show similarities (if you're confortable with feature X, then raku's Y will makes you happy) * show some pro and cons (Shell vs Raku) > Can Linux be shipped with Raku by default? apt install rakudo Is possible from the stable debian but i don't think it's a good idea to have it as part of the default install (in a sense that there should be nothing bigger than dash/busybox/toybox in the default install).
Last day for FOSDEM submission
hello people, I just discovered this this morning: https://www.reddit.com/r/rakulang/comments/rrcp4c/steal_these_ideas_for_raku_fosdem_talks/ I don't remember if there was a previous annoucement in this list but it's still possible to jump in. I just submitted one on "Replacing Bash scripts with Raku" * features and way of doing things i love from zsh * the raku way [1] * getting started with raku ecosystem (raku.land, zef, Ddt, fez, rakudoc, prove6, ...) gather/take=while read, Seq vs Pipes, ...) and ideas of modules 1: the raku way are things like *sh│ raku ───┼─ | │ Seq.map xargs -P │ .race while read │ gather/take At some point it could become an Intro section on the Raku documentation site. If a native/fluent english speaker want to take over it: i'll be more than happy to co-author the talk as well (i really feel like i'm a disaster as speaker). Regards marc
Re: the MAIN questions
hello Daniel, > > Did i just dreamed about it ? > You sort of dreamed it. damn! thanks for the red pill. > my $argfiles = IO::ArgFiles.new(@files || '-'); my perl history works against me there: i see @files.elems || '-' here :) thank you. > The other change I'd suggest for additional elegance (at least imo) is to put > the help text for each flag/option on the same line, either by putting it > after > with #= or by using an embedded comment. Here's the script with those > changes: well ... i'm visually impaired so i really try my code to fit in 72 cols. sub MAIN ( #| don't fix for real, just show the diff Bool :$diff=False , #| input files (stdin by default or with explicit '-')] *@files ) { would be my way of writing >sub MAIN ( >#|[don't fix for real, just show the diff] Bool :$diff=False, >#|[input files (stdin by default or with explicit '-')] *@files ) { >.&fixline.say for IO::ArgFiles.new(@files || '-').lines; >} > Hope that helps! definitely. always good to share ideas. regards marc
the MAIN questions
hello rakoons, I have a script named fixlines which is basically sub fixline (Str $line) { ... } say fixline $_ for lines; This is far enough for personal usage but i would like to release it so i need a decent -h to be implemented and basically should look like Usage: fixlines [--test] to do so, my say fixline $_ for lines; becomes sub MAIN ( #| don't fix for real, just show the diff Bool :$diff = False, #| input files (stdin by default or explicit '-' in the list) *@files ) { +@files or @files = ('-'); my $argfiles = IO::ArgFiles.new(@files); .&fixline.say for $argfiles.lines } This would be fair enough in any other langages but the whole thing looks unelegant in a raku code. So now I have 2 questions: * I'm pretty sure i saw something like :!$test to express Bool :$test = False. Did i just dreamed about it ? * more importantly, is the a better choice than +@files or @files = ('-'); my $argfiles = IO::ArgFiles.new(@files); .&fixline.say for $argfiles.lines I saw %*SUB-MAIN-OPTS in the documentation and was wondering if something like %*SUB-MAIN-OPTS= my @files; #= input files, stdin if none could be achievable by a module MAIN::UnixFilter i could put on Raku.land? Regards, marc
Re: is 'use v6' still a thing?
Dear Liz and Ralph, thanks for your anwsers. Le Tue, Dec 28, 2021 at 09:29:26PM +, Ralph Mellor a écrit : > > long time ago, there was this 'use v6' line ... Does it still make sense? > I think it depends. well. it's not that time consuming to add v6.d so reading your lines, i realized it's not worth to spare it. thank you. regards marc -- Marc Chantreux Direction du numérique de l'Université de Strasbourg Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
is 'use v6' still a thing?
hello people, long time ago, there was this 'use v6' line so perl should be v6 and still run v5.* things. I just took a look to https://raku.land/github:JJ/SDL2 and seen use v6; Does it still makes sense? Regards. -- Marc Chantreux Direction du numérique de l'Université de Strasbourg Pôle de Calcul et Services Avancés à la Recherche (CESAR) http://annuaire.unistra.fr/p/20200
Re: can't make from a S/// ?
hello William, > #old: > rule TOP {* %% \n } > token line { * %% ',' } > #new: > rule TOP {* } > token line { * %% ',' \n } ohhh ... indeed! when i fixed the code on Ralph's instructions, i finally was able to slurp a whole file and discovered a emtpy entry at the end of the flow so i realize that \n is actually a terminator, not a separator. > class CSV_as_table { > method TOP ($/) { make $/.map: *.made } > method line ($/) { make $/.map: *.made } > method col:sym ($/) { make ~$/ } > #method col:sym ($_) { .make: ~S:g/'""'/"/ } > method col:sym ($/) { make $/.subst(/'""'/, '"', :global) } > } nice :) but as i said earlier, i really prefer the short one. > been interesting nevertheless. Here's a related link to a one-liner that > uses Raku's Text::CSV module: > https://unix.stackexchange.com/a/670358/227738 This grammar really was an exercice. I also wrote a really simple csv2tsv in C which is really fast and was actually simpler to write. regards, marc
Re: can't make from a S/// ?
> On Sat, Nov 20, 2021 at 9:03 PM Marc Chantreux wrote: > > > > method col:sym ($/) { .make ~S:g/'""'/"/ } > > > That's not working for me. I'm on Moar (2021.06). > > works for me with: > > method col:sym ($_) { .make: ~S:g/'""'/"/ } > Yeah, you got it wrong the first time. To explicate, the key difference > is differently named parameters: ($/) vs ($_). Ohh ... sorry i didn't spot the problem because the relation between $_ and the use of .make was too obvious to me. thank you for noticing! regards marc
Re: can't make from a S/// ?
helllo William, > > Marc wrote: > > i'm inclined to think that this is easier to read: > > method col:sym ($/) { .make ~S:g/'""'/"/ } > That's not working for me. I'm on Moar (2021.06). works for me with: Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2021.09. Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d. Built on MoarVM version 2021.09. > This Is what I get back (first error below, note the "grammar CSV" line is > the first line of the script, and method col:sym is on line 20): the whole grammar and action is: grammar CSV { rule TOP {* } token line { * %% ',' \n } proto token col {*} token col:sym { <-[\n",]>* } token col:sym { '"' ~ '"' [<( [ '""' | <-[\n"]> ]* )>] } } class CSV_as_table { method TOP ($/) { make $/.map: *.made } method line ($/) { make $/.map: *.made } method col:sym ($/) { make ~$/ } method col:sym ($_) { .make: ~S:g/'""'/"/ } } regards marc
Raku and Datasciences
hello people, > I am still defending that we need a package for data > analysis/science/engineer (like the Perl5 PDL, Python Pandas or R > data.table) and an IDE for streaming programming like jupyter or rstudio. I'm still excited about this idea and my offer to test/feedback/document remains open. A first step should be to start with examples of pure Raku code. Once we are confident about the fact it's the state of art of the langage, we can merge it into https://github.com/Raku/examples/tree/master/categories I started it by using a turorial made by a colleage (in french, sorry) about "exploring facts about the titanic demography with python" https://www.youtube.com/watch?v=FNDWAybVPcc which is a good example: * simple grammar * simple data manipulations * interesting facts to work on simpler enough to explore Raku concepts and asking myself a lot of questions like "is it possible that a grammar can Supply objects or beging lazy". so could something inspired like that grammar grammar CSV { rule TOP { * } token line { * %% ',' \n } proto token col {*} token col:sym { <-[\n",]>* } token col:sym { '"' ~ '"' [<( [ '""' | <-[\n"]> ]* )>] } } which is basically used that way: my @data = CSV.parse( actions => CSV_as_table.new, "quoted.csv".IO.slurp ).made; my \col = %( $_ Z=> ^$_ with @data.shift.List ); be used this way to take avantage of lazyness: my @top5 = do { .use_headers; .head(5) } with onfly CSV, "quoted.csv".IO; # IO stops tor read at line 6 regards, marc
Re: can't make from a S/// ?
hello William, > method col:sym ($/) { make $/.subst(/'""'/, '"', :global).Str } which is just a longuest version of the line Ralph wrote. i'm inclined to think that this is easier to read: method col:sym ($/) { .make ~S:g/'""'/"/ } > The following line seems to work just fine, with-or-without the call to > .Str at the end both works but if you don't use ~ or .Str, a match is returned. I noticed after i replied to Ralph. Thanks for helping, regards
why not raku ?
hello, > I like ruby and perl so do I but raku is by far my prefered interpreted langage now. I don't raku that much and most of the time, i read the doc more than i actually write code but when it's writen, it's always elegant and concise the way i never seen before. > Maybe perl6 is still not production-ready? Perl6 is now raku. it depends: what do you mean by "production" and "ready"? start with some few non-critical usecases and you'll see raku is production ready enough for lot of things. > but why so few open source projects which were developed by perl6? wow ... interesting question. my cents on it: * raku shines on interpreted langages when people are moving to compiled langages * raku is that rich it's hard to get it in a first view * raku is still way too slow to be taken seriously by a large audience * js or python developpers are legions on the market now so everyone choose this as an argument * we need more packages on raku.land * i really think technologies are massively adopted when they are packaged in main linux distros because lot of people don't want to bother compiling an interpreter or adding extra repos to do it. regards, marc
Re: can't make from a S/// ?
hello Ralph, Thank you for the whole explaination and links. > method col:sym ($_) { .make: S:g/'""'/"/ } i dug around it but missed it! arggh ... > > am I right when i feel there is a way to do this > > substitution inside the grammar > As I've shown, yes. But it draws you into the `$/` dance. The way I read you is "no" as i can't reassign inside a grammar. what i was expecting is to hack the grammar itself. something like replacing token col:sym { '"' ~ '"' [ <( [ '""' | <-[\n"]> ]* )> ] } by something close to token col:sym { '"' ~ '"' [ <( [ '""' { $0 = '"' } | <-[\n"]> ]* )> ] } anyway: thanks for the detailed explaination. your solution is really elegant marc
Re: fixing the documentation
hello, Le Fri, Nov 19, 2021 at 07:12:13AM +0100, JJ Merelo a écrit : > Thanks a lot. well ... not sure who should thank someone here .. i meant: you spent so much more time on the raku ecosystem than i did ... thanks everyone.
can't make from a S/// ?
hello rakoons, I want to be able to parse this: CSV.parse( '162,1,2,"Watt, Mrs. James (Elizabeth ""Bessie"" Inglis Milne)",female,40,0,0,C.A. 33595,15.75,,S', actions => CSV_as_table.new, ).made.say; I wrote this simple Grammar and action grammar CSV { rule TOP {* %% \n } token line { * %% ',' } proto token col {*} token col:sym { <-[\n",]>* } token col:sym { '"' ~ '"' [ <( [ '""' | <-[\n"]> ]* )> ] } } class CSV_as_table { method TOP ($/) { make $/.map: *.made } method line ($/) { make $/.map: *.made } method col:sym ($/) { make ~$/ } method col:sym ($/) { make ~$/ } # method col:sym ($/) { make S:g/'""'/'"'/ with ~$/ } } And it *almost* work. the thing I try to do now is to replace the "" in quoted strings by a simple ". when I use method col:sym ($/) { make S:g/'""'/'"'/ with ~$/ } instead of method col:sym ($/) { make ~$/ } I get this error message: Cannot assign to a readonly variable or a value in method col:sym at whole.raku line 17 in regex col:sym at whole.raku line 7 in regex col at whole.raku line 5 in regex line at whole.raku line 4 in regex TOP at whole.raku line 3 in block at whole.raku line 30 I just don't understand why so i come with 2 questions (or 4): * how to fix it (and why isn't it working) ? * am I right when i feel there is a way to do this substitution inside the grammar (and is it a good idea) ? regards, marc
Re: fixing the documentation
Hello, > The best would be if you propose a PR or open an issue at > https://github.com/Raku/doc. Any help with the documentation would > most certainly be appreciated as people working on the docs project > are overloaded. Sorry I was late on this because I wasn't sure how to revamp the whole thing. so i just simplified the 5to6 page this way: https://github.com/Raku/doc/commit/cd32380ab4e1c5ad2017d60a31def9189b54c80f Simple changes are better anyway. thanks. marc
fixing the documentation
hello people, D526P: https://docs.raku.org/language/5to6-nutshell#index-entry-PERL6LIB-PERL6LIB DFIM : https://docs.raku.org/language/modules#Finding_installed_modules DLIB : https://docs.raku.org/programs/03-environment-variables#index-entry-RAKULIB This D526P is deprecated and some RAKULIB details are redundant with both DFIM and DLIB. I would like to propose a patch so: * the details of RAKULIB comes in DLIB * DFIM refers to DLIB * D526P refers to DFIM But D526P asserts something i read nowhere else: Note that C is more of a developer convenience in Raku (as opposed to the equivalent usage of C in Perl) and shouldn't be used by module consumers as it could be removed in the future. This is because Raku's module loading isn't directly compatible with operating system paths. Is it still true? if so, should this paragraph be in DFIM? regards, marc
[better solution] pairs of separators from a string
hello everyone, I made a mistake while replying to all of us so anwsers never reached your boxes. I'll summerize in one answer: Bill: > Is it just even/odd elements that you want to separate out? If so, maybe > .grep() is your friend here I don't think it is: 0, 2 ... * seems to be * closer to what i have in mind when i think about the problem (so i invoke readability there) * probably more efficient than (0..*).grep(* % 2) that * generate twice the number of required elements * need to filter the result Also, trying to play with this version: my ($a,$b) = .[0,2...*], .[1,3...*] with .comb; just don't work because the lists are squashed into scalar context in the process. So Brian and Fernando made my day with := and the unexpected power of the [] operator. my (@a,@b) := .comb[ [0,2...*], [1,3...*] ]; I really like how declarative it is. Also the use of := now seems obvious to me. Sigils still remains something strange to me desprite all your examples but i'll take some time. thanks everyone. marc
Re: pairs of separators from a string
hello William, > your string, or whether-or-not some might be nested within each other. You > show a lone ampersand ("&") at the beginning of your example, but other > strings may not be so simple. really sorry about this artefact from previous attempts :( > > $string.comb(/ ( <:Ps> ~ <:Pe> .?) /, :global).raku.say > ("()", "\{}", "[]").Seq those regexes i can't read for the moment is a good excuse to learn more about raku. i'll read them later and come back here if i have questions. thanks and regards. marc
[solved] pairs of separators from a string
hello Yary, > and my instinct is that "map" is adding a layer you don't need or want for > this issue, should just be sending the results of comb to a block. But I > can't quite get the syntax right (and docs.raku.org seems down at the > moment) With this and what i understood from Vladim, i tried this my ($a,$b) = "AaBbCcDd".comb.map: { .[0,2…*], .[1,3…*] }; say $a; it failed too. Also: the Vladim example of a direct call of the lambda seems intellectually closer to the problem to me. i realized that the perl map and for with scalars are work arounds. raku has with. so i tried: my ($a,$b) = .[0,2…*], .[1,3…*] with "AaBbCcDd".comb; say $a which is exactly the way i want to write things :) > I sent a variation of this as a potential question to Perl Weekly > Challenge, maybe it will get a bunch of answers in a few weeks! i'll be happy to read other answers. regards. marc
(sigils are awesome, they say ...) Re: pairs of separators from a string
thanks everyone for sharing, Vadim, my ($a, $b) = { @^a[0,2...Inf], @a[1,3...Inf] }.(q<(){}[]>.comb); say $a[0]; say $b[0] oh. i never see this direct call of a lambda before but it really makes sense! this is the answer i like the most. i rewrote it my way and this works my ($a, $b) = { .[0,2…∞], .[1,3…∞] }.(q.comb); it would be nice if this one will: my ($a, $b) = { .[0,2…∞], .[1,3…∞] }.: q.comb; But here is one of the reasons i'm still unconfortable with raku is the fact that sigils don't make sense anymore to me (in the contrary of perl were sigils means "i want a [$%@] from this"). so as i can't get grid of sigils in this case my (\a, \b) = { .[0,2…∞], .[1,3…∞] }.(q.comb); i need to choose a sigil. The way i understand sigils is "an optional type specifier". to me my $truc => my container 'truc' for anything you want my @truc => my container 'truc' for something that should mostly be understood as indexed my %truc => my container 'truc' for something that should mostly be understood as associative so of course i tried my (@a, @b) = { .[0,2…∞], .[1,3…∞] }.(q.comb); because i have two lists and two containers. this doesn't work. which means @ and $ combines with = to define how things are stored but i don't understand how for the moment. regards, marc
pairs of separators from a string
hello, i would like to get the list of opening (α) and closing (ω) separators from this string: &""''(){}[] too many years of perl made me think about this solution or something alike but it didn't work. my (\α,\ω) =| map { .[0,2…∞], .[1,3…∞] }, q&""''(){}[]&.comb; fixing this is important to me because it illustrate how bad i am to comprehend how raku flatten things. regards, marc
Re: Notes/Questions about Leon Timmermans's talk
Hello, > > sub foo ( Int $x ) { 0 if $x > 5 } > > sub hello {say "hello $^world"} > > if defined my $value = foo 45 { hello $value } >with foo 7 { say $^value } i feel really dumb right now as i just used with and didn't made the match in my head. > or if you want to trigger on *not* defined: >without foo 7 { say $^value } hoo ... my $x; without $x { note '$x is not set' } if not defined $x { note '$x is not set' } $x = 34; without $x { note 'is your raku broken?' } very nice! thank you for sharing! > You can use the » without fear if there aren't any side-effects. > Consider this: >class Foo { >my int $seen = 0; >method bar() { ++$seen } # side-effect >} … > Another thing to remember is the order in which they are executed: >("a".."z")».&say; … > Hope this explains :-) Both are clear and i AFAIR, i realize that your second example illustrate the error i made as i was writing stuff in $*STDOUT. thank you so much! marc
Notes/Questions about Leon Timmermans's talk
hello, I just saw this and it's very good https://www.youtube.com/watch?v=elalwvfmYgk The features he picked are indeed things i really like in raku and i learned some interesting details. Other details are still bugging me so i have some questions there: A. if x -> $y with // For exemple, given a function Foo sub foo ( Int $x ) { 42 if $x > 5 } this is awesome you can write if foo 7 -> $value { say $value } and even if foo 7 { say $^value } but is there a way (adverb?) to match if something is False but defined so given this sub foo ( Int $x ) { 0 if $x > 5 } i would write something else than sub foo ( Int $x ) { 0 if $x > 5 } sub hello {say "hello $^world"} if defined my $value = foo 45 { hello $value } B. » vs map Leon made this slide where i consider as equivalent @list».abs @list.map(*.abs) someone, some day, told me they are not and i shouldn't use » if i don't know what it means. I read the doc and came to the (incorrect?) conclusion that @list».abs is actually @list.map(*.abs).hyper which could have important overloads while creating an HyperSeq. should i reconsider the whole thing and use » without fear? regards, marc
df.column1 ... stealing from others could be counter-productive?
> > df.column1 ... return a list of values on this column > That thought should be a topic in its own right. what i really like in raku is that chance to not have all those fancy keywords just because langages lack of syntax so stealing from pandas, incanter, and others is a good idea only if we don't have some rakuness¹. to me and in this case: nothing compares @df[1;*]. ¹: obvious, idiomatic, powerful and elegant solution coming from the raku langage itself regards marc
Re: Baby steps to create a dataframe structure
hello, On Tue, Jul 21, 2020 at 10:56:22PM -0300, Aureliano Guedes wrote: > Then, a native call to R may be better cus bring us dataframe an a lot of > statistical functions natively without other R's package. coming from perl/shell and having to use pandas a little bit, my current perception of "datasciences for beginners" is * it's hard to find books about the way to reason about diving into a dataset: all the books are introductions to procedural python and R. * DF are just 2D matrix with a complex name. * PDL is about using native arrays instead of slow perl ones. * raku have bare metal structures like CArray and @array of int32 so ... > But the idea is to implement cooperatively those tools if you do that, i'll be a very suportive user (and casual contributor if i can). regards marc
Re: vim-raku roadmap
hello, > I think this got pulled into the Raku org so it didn't get lost - I > don't think anyone is "in charge" at the moment. I'll review the > existing PRs and apply them if possible. There was a public call to take over it some mounths ago. i haven't applied because i was affraid of the lack of time and competence (my level with raku is close to 0) and Sterling (aka https://github.com/zostay) kindly accepted to maintain it. Now that i write more raku code, it would save a lot of my time if we had at least ctags, cscope and 'goto file' working. I don't have much more time than i did, i just much more need vim to work as expected (and i think i know vim pretty well). so it would be really nice if we all join the effort at least by giving me some clues about * the best way to get the position (file, line and column) of the definitions of methods, variables and subs. * same questions for method/function calls about the 'goto file', i'll push a first version that try to find the source file of a module into * first $RAKULIB * then ~/.zef/store/*/*/lib i don't know if it's the best way to do it. regards. marc
vim-raku roadmap
hello rakuists, i want to work on raku-vim and saw that some PR from january aren't merged (https://github.com/Raku/vim-raku/pulls) so i would like to discuss about my roadmap with any interested people. my goals: * remove references to perl6 * remove mappings that shouldn't be in a public package and "conflicts" with digraphs anyway (https://github.com/Raku/vim-raku/blob/master/ftplugin/raku.vim#L76) * improve inex to work with installed modules * start working with open issues waiting for someone in charge to contact me, i'll go on improving my repo. regards marc
Re: variable as subroutine?
hello ToddAndMargo, > Can I declare a subroutine as a variable? just use the callable sigil (https://docs.perl6.org/type/Callable). those are 3 ways to write the same sub: sub foo ($x) { $x * $x } my &foo = -> $x { $x * $x } my &foo = * * *; regards, marc
rakudo.org outdated?
hello people, i read an annoncement for rakudo 2019.11 and the last github release confirms that. so i started to update the guix package before discovering that the rakudo.org page still points to 2019.03. is there a problem with the last version or os rakudo.org just outdated? regards. marc
Re: play with raku and autobiographical numbers
On Tue, Dec 31, 2019 at 03:16:50PM +0100, Tobias Boege wrote: > Here is my entry, having a Bag count the occurences of letters, > instead of the loop over @r you used. i'm not used to bags so i always forget it. i really love the your final code. thanks regards marc
play with raku and autobiographical numbers
hello, 2020 describes itself as it is composed by 2 0 0 1 2 2 0 3 perfect golf excuse! I have : sub is_autobiographic (\x) { my \s = x.Str; my @r = s.comb; my %appearance_of; %appearance_of{$_}++ for @r; x ~~ join '', (%appearance_of{$_}//0 for 0..^@r); } (^∞ ).race( :1batch,:10degree ).grep( &is_autobiographic ).head(10).map(*.say) anyone with something simpler? marc
(syntaxic choices) Re: split to walk into an HoH ?
> I don't think so; just a stylistic choice well ... i tested ===> once because i'll choose any syntax that can spare me parenthesis especially in raku because i feel they are in the wrong place (scheme makes parenthesis right). Raku behaves better than perl in this regard because say (f 12), "works"; when Perl expect a +(f 12). But i doesn't spare anything so are ok for me :) regards marc
Re: split to walk into an HoH ?
hello, > You could also use the feed operator is there a reason to do so? i see none. regards marc
Re: split to walk into an HoH ?
hello, > Hi Marc, I tried the first solution you posted and the "subheaders" > are returned out of order (e.g. "2,1,3" and not "1,2,3"): you're right but it doesn't matter in this usecase. > mbook:~ homedir$ cat p6_chunk_csv.p6 > lines.classify(*.split(",").head(2)).pairs.map: { > .say for .key, |.value.map({ "\t" ~ .key }); > } > mbook:~ homedir$ cat awk_test1.csv | perl6 p6_chunk_csv.p6 useless use of cat: as lines() works on $*ARGFILES, you can just write: perl6 p6_chunk_csv.p6 awk_test1.csv thanks for helping me regards marc
Re: split to walk into an HoH ?
hello, > FWIW, I would make %section an HoA, which would be a less compact > structure in memory, but allows more succinct manipulation, like so: > my %section = lines() > .map( *.split(",") ) > .classify( { .[0] }, :as{ .[1] } ); > for %section.sort { > say .key; > say "\t$_" for .value.sort.unique; > } then * no need of %section * no need to sort so it becames: fix () perl6 -e ' lines.map( *.split(",") ) .classify( { .[0] }, :as{ .[1] } ) .map: { say .key; say "\t$_" for .value.unique } ' even if the semicolon thing goes on scratching me, i'm really happy about this one! thanks a lot. regards marc
Re: split to walk into an HoH ?
hello Timo, > lines()>>.trim-leading.classify(*.split(",").head(2)); say to-json %foo' which led me to this solution: fix () perl6 -e ' lines.classify(*.split(",").head(2)).pairs.map: { .say for .key, |.value.map({ "\t" ~ .key }); } ' fix () perl6 -e ' lines\ .classify( *.split(",").head(2) ) .pairs .map: { .say for .key, |.value.map({ "\t" ~ .key }); } ' which is nice to read but hold much more data in memory. anyway: good point. regards marc
Re: split to walk into an HoH ?
hello Bruce, > The first key of each second level is missing, which differs from your sample > output above. > Have I corrupted your Awk code, or have I misunderstood something, or what? you just spotted a bug: the first subkey *is* indeed required. actually fixing the bug makes the awk version even shorter. fix () { awk -F, '{print $1" "$2}' | sort -u | awk -F" " ' seen != $1 { seen = $1; print $1 } { print "\t"$2 } ' } regards marc
Re: Fwd: split to walk into an HoH ?
On Fri, Nov 22, 2019 at 06:20:51AM -0800, William Michels via perl6-users wrote: > Hi Marc, I did a search for 'semicolon' on the following page and > found the interesting text below. Semicolons are used to create > multidimensional lists, maybe that's what's going on in your code? indeed! i tried with ";" but it wasn't that helpful. :) > PS I would presume some variation of 'next' would work where you're > using 'walkTheHash', but I don't really know for sure. Gianni gave the solution: my script became: fix () perl6 -e ' my %section; lines.map: {postcircumfix:<{; }>( %section, .split(",") ) = 1 }; %section.keys.map: { .say for $_ , |%section{$_}.keys.map: {"\t$_"} } ' it would be nice to have a shorter syntax to access to access to postcircumfix:<{; }> but still: it's awesome. regards marc
Re: split to walk into an HoH ?
> From a quick look through ``Perl6/Grammar.nqp`` and > ``Perl6/Actions.nqp``, I think that the semicolon is special-cased by > the compiler, so the slightly ugly way above (call the operator > directly) is probably the only way that works. *this* is the level of expertise i miss :) thanks for your reply. marc
Re: split to walk into an HoH ?
hello, On Fri, Nov 22, 2019 at 03:07:28PM +0100, Patrick Spek via perl6-users wrote: > Could you post some input and expected output? That would make it > easier for me (and perhaps others) to see what exactly you're trying to > accomplish, in practical terms. sorry ... i'm so confortable with awk i haven't though about some are not. i sincerely apologize. Basically i want to figure out what are the sections, subsections of of a CSV file: A,1,garbage . A,2,garbage . A,2,garbage . A,2,garbage . A,3,garbage . A,3,garbage . A,3,garbage . B,1,garbage . B,2,garbage . B,2,garbage . B,2,garbage . B,3,garbage . B,3,garbage . B,3,garbage . becomes A 1 2 3 B 1 2 3 regards, marc
split to walk into an HoH ?
hello people, removing shell scripts is a good way to learn raku and compare. today i want to replace this: fix () { awk -F, '{print $1" "$2}' | sort -u | awk -F" " '{ if (seen == $1) print "\t"$2; else { seen = $1; print $1 } }' } and i got this: fix () perl6 -e ' my %section; lines.map: { my ($s,$ss) = .split(","); %section{$s;$ss} = 1; } %section.keys.map: { .say for $_ , |%section{$_}.keys.map: {"\t$_"} } ' ";" to walk in the hoh is really awesome but i don't know even know from where i know it and what's the object underneath. it isn't listed in the list of operators (https://docs.perl6.org/language/operators). i would like to know because it would be nice to make this block my ($s,$ss) = .split(","); %section{$s;$ss} = 1; a one liner so i'm searching for something like %section{ .split(",").walkTheHash } = 1; any help will be warmly welcome. regards marc
Re: anything faster than say [+] lines?
hello, > should make it a bit faster, at the expense of *much* more memory > usage, as opposed to just. i was just reporting. perl6 isn't fast enough in this case to compare with other dynamic langages. > In any case, to get the same result, you could also do > > (0..10_000_00).sum.say > > which would come back instantaneously, regardless of the size of the > range. sure but the point of the stackoverflow question was to write a unix filter. seq 100 was just a simple and reproductible example. thanks a lot everyone for helping marc
Re: anything faster than say [+] lines?
hello, > though that works here, admittedly, my p6 is sort old > This is Rakudo version 2018.03 built on MoarVM version 2018.03 > implementing Perl 6.c. this lead me test it with the docker rakudo-star (2019.03). time docker run rakudo-star bash -c 'seq 1| perl6 -e ''slurp.split("\n")>>.Int.sum.say''' My error message desapeared but the response time of the script made by liz is more than one hour. regards marc
Re: anything faster than say [+] lines?
hello, > > > > nice ... but when x is ~ 75440 (not always), there is a problem > > > What is x here? > > sorry. x is the arg of seq (number of lines). > That never happens on my laptop well.. so it's a problem with my station. nevermind :) thanks again for helping marc
more unixish perl6?
hello, i don't know if it's useful to feedback on it but i would like to share about MAIN. this is a very nice thing to have it built-in so the quality of your scripts can be improved without effort ($*USAGE is very nice!) but here are some parts i feel i miss. * dealing with $*ARGFILES should be simpler (something like the closing @ in perl5 signatures) * a support of arguments cluster would be (both '-s -d +' and '-sd+' should be valid) * having something like auto-help that print $*USAGE on $*OUT multi sub MAIN ( Bool :h(:$help), +@rest ) { $*USAGE.say } aside: the perl6 error messages comes with escape caracters even if $*ERR isn't tty. this is unusual and makes things boring when you capture the error into an editor or a filter. i don't know if it can be useful in some cases. regards marc
Re: $*ARGFILES and MAIN
On Mon, Sep 23, 2019 at 11:34:14PM -0500, Brad Gilbert wrote: > You can create your own $*ARGFILES. > > sub MAIN ( +@ARGS ){ > my $*ARGFILES = IO::ArgFiles.new( @ARGS || $*IN ); > .say for lines; > } the way i understand https://docs.perl6.org/language/variables, my dynamic (my $*) variable is the raku way to have a local variable. i played around it and got: sub snitch { say join ',', $*ARGFILES.handles } sub MAIN ( $pattern, Bool :$H, Bool :$n, +@files ) { my $*ARGFILES = IO::ArgFiles.new(@files); snitch; } surprisingly compared to the rest of the code (especially when liz reviews it!) and when you consider (as i do) that raku will be used to write tons of filters. but hey! it works :) thank you very much for help. marc
Re: anything faster than say [+] lines?
hello Vittore, > Ok, I am 100% sure that, if people use it, eventually $*ARGFILES will > become as fast as $*IN. Because of people like Liz working on the project functions like slurp, lines, words already depends on $*ARGFILES (which is awesome, i think) so i have no doubt there will be attention there. > > nice ... but when x is ~ 75440 (not always), there is a problem > What is x here? sorry. x is the arg of seq (number of lines). regards marc
Re: anything faster than say [+] lines?
hello liz and Vittore, > bypassing $*ARGFILES.lines by using $*IN.lines, makes it faster for me than > using slurp $*ARGFILES is the correct FH to use when it comes to write unix filters (as it was in the other examples of the page). > > say lines.map(*.Int).sum i recently read that >> could help here so i tried seq 100 | time perl6 -e 'slurp.split("\n")>>.Int.sum.say' 5050 perl6 -e 'slurp.split("\n")>>.Int.sum.say' 0,21s user 0,03s system 155% cpu 0,151 total nice ... but when x is ~ 75440 (not always), there is a problem moar: src/unix/core.c:539: uv__close: Assertion `fd > STDERR_FILENO' failed. perl6 -e 'slurp.split("\n")>>.Int.sum.say' 0,30s user 0,05s system 135% cpu 0,254 total anyway: thanks for detailed and useful replies. marc
Re: $*ARGFILES and MAIN
hello, > > multi sub MAIN ( :$c ) { say [+] lines>>.chars } > Isn't that just `slurp.chars` ? correct :) > > multi sub MAIN ( :$w ) { say [+] lines.map: +*.words } > Isn't that just `+words` ? Aren't you awesome ? At least you're right: the doc says: multi sub words ( IO::Handle:D $fh = $*ARGFILES , $limit = Inf , :$close --> Seq:D) and it work like a charm. > You should **never** use >>. on anything that you expect the order of > execution to be the order of the input. `>>.` allows the compiler to > execute the code over multiple threads, so the `say` could be shown > out of order. wow ... thanks for pointing this. still can't mix MAIN and ARGFILES but learned. thank you very much. regards marc
$*ARGFILES and MAIN
hello people, short question: how to use $*ARGFILES in a MAIN function? context: as an exercice as well as demo, i reimplement unix filters (cat, grep, wc, join, paste, ...). Basic wc could be multi sub MAIN ( :$l ) { say +lines } multi sub MAIN ( :$c ) { say [+] lines>>.chars } multi sub MAIN ( :$w ) { say [+] lines.map: +*.words } now i want grep that can have both -H (head the line with the filename) and the -n (add the number of the line). my 'almost working' attempt was but it takes the flags as signatures. sub MAIN ( Str $pattern, :$H = False , :$n = False , *@rest ) { (IO::ArgFiles.new: @rest).lines>>.say } any help on it? extra note: i use the perl6 shipped with guix so: perl6 -v This is Rakudo version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d. regards marc
anything faster than say [+] lines?
hello, question: in raku, is there a faster solution than say [+] lines long story; here is a thread i would like to reply to https://stackoverflow.com/questions/450799/shell-command-to-sum-integers-one-per-line because: * the perl5 answer is fast compared to the other dynamic langages * the shortest solution is very interesting: even if you have an average level in dc (i think i have one), this is not that easy to read the answer (commented in the post) dc -f infile -e '[+z1
Re: flat a lazy gather ?
hello Bruce, > Short answer: Add `flat` before `lazy in line 19, and remove `.flat` from > line 21. Like so: > my @future_aams = > flat lazy gather for 2019..∞ { take .&aam_dates_of_year }; sure but i loose the ability to use @future_aams year by year. the best i i have here to keep both behaviors available is: sub flat_stream { lazy gather for @^list -> @l { take $_ for @l } } @future_aams.&flat_stream.head(1)>>.say; > Full answer coming when time allows. For such a small fix, it was > surprisingly effortful to figure out. > See https://docs.perl6.org/language/list#Itemization i'll read again and try to find by myself. thanks marc
flat a lazy gather ?
hello people, AÀM (Appel À Mousser) is the monthly social event of the Strasbourg(fr) LUG. the dates of those meetings are scheduled by an algorithm implemented in aam_dates_of_year (line 6). Now i would like to show 25 AAM dates staring from 2019-01. line 14 works fine but is too long. i really would have those dates be read as a simple list. i wrote the line 18 (so i tought ) but when i want to get the 2 next dates, i have the dates for the 2 next years. it seems .flat is ignored and i don't know why. any help on it ? regards, marc 1sub date_for (Date $d is copy, Int \dow) { 2 $d.=later(:1day) while $d.day-of-week != dow; 3 $d.later(:1week); 4} 5 6sub aam_dates_of_year ($year) { 7 ( for 1..12 { Date.new(:$year, :$^month, :1day) } ) 8 Z[&date_for] | (2..4) xx * 9} 10 11# works: 12# Date.today.year.&aam_dates_of_year[7].say; 13# (2019..2025)>>.&aam_dates_of_year.flat>>.say; 14# ( lazy gather for 2019..∞ { take .&aam_dates_of_year }).flat.head(2)>>.say; 15 16# more reusable ? 17 18my @future_aams = 19 lazy gather for 2019..∞ { take .&aam_dates_of_year }; 20 21@future_aams.flat.head(1)>>.say;
Re: [golf?] list of matches
hello Bruce; > # Elegant using the "cat-ears" range modifiers in Perl 6: > for 0 ..^ @players.end -> \i { > for i ^.. @players.end -> \j { > say @players[i,j].join(' vs '); > } > } > # See https://docs.perl6.org/type/Range i played around it and got: my @players = ; my @rounds = gather for ^@players -> \p { take @players[p,$_] for p^..^@players }; for @rounds -> ( $a, $b ) { "$a vs $b".say } > say .join(' vs ') for @players.combinations(2); > # See https://docs.perl6.org/routine/combinations i knew there will be something like that ... but didn't find it! thank you very much. regards marc
Re: documentation translation effort ?
hello, On Tue, Jul 09, 2019 at 11:28:29PM +0200, Laurent Rosenfeld via perl6-users wrote: > I have updated the Wikipedia page linked in Marc's message. @Marc: please > check it and let me know if you see any remaining issues. reading the fix, i realized i mixed up the errors of the linuxfr page and the wikipedia ones: of course, rakudo *is* the compiler targeting moarvm and jvm and written in NQP. for the rest: i'll take a look and fix the page if needed (i also have a wikipedia account). regards marc
Re: [golf?] list of matches
On Tue, Jul 09, 2019 at 11:44:07PM +0200, Laurent Rosenfeld via perl6-users wrote: > You might want to take a look at the cross ("X") operator, which takes two > or more lists as arguments and returns a list or all lists that can be > constructed combining the elements of each list (or, in other words, a > Cartesian product of the input lists). I used it in my first solution which was sub vs (@xs ( $head, *@tail ) ) { |($head X @tail), |(vs @tail if +@tail) } if i do @xs X @xs, i have +@xs unexpected elements so i have to filter the result: my @players = ; for @players X @players ==> grep({ [ne] |$_}) -> ( $a , $b ) { say "$a vs $b" } this is shorter but i my first solution doesn't need to be filtered. regards marc
[golf?] list of matches
hello people, i have a game where every opponent much play every other ones so i implemented vs to get a list of all the matches from a list of opponents. i'm pretty sure that there is a shorter/more beautiful solution than mine so i really would like to see. mine is sub vs (@xs ( $head, *@tail ) ) { |($head X @tail), |(vs @tail if +@tail) } my @rounds = .&vs; for @rounds -> ( $a, $b ) { say "$a vs $b" }; anyone want to share? regards, marc
Re: documentation translation effort ?
hello, > There have been some efforts to translate perl6intro; but as Laurent says, > we can hardly say the documentation is complete, so diverting resources to > translation is probably not such a good idea. yeah. when laurent spoke about a moving target, i gave a look at the doc repo and there almost everything moved in the last months. this is impressive. so i agreed with both of you: definitely not a good idea for the moment. regards marc
Re: documentation translation effort ?
hello Laurent, > the French Wikipedia page you refer to is not really wrong, but rather > terribly outdated and, therefore, no longer correct. I have a Wikipedia > account and can easily fix that page (using, if needed, the updated English > Wikipedia page on the same subject). The very first sentence state that rakudo is a compiler which, AFAIR, never was the case. i really want to double check other assertions of the article (for example: i don't think rakudo was developped as a part of the parrot project. instead, rakudo tried to target the parrot vm). > Translating the whole Perl 6/Raku documentation is a totally different > game. It's just too big (and it's a moving target), I won't undertake that. Having the official documentation translated could be a really good thing for the perl6 adoption in France so i think we have to think about it at some point. However, you're right when you say it's a moving target and it will slow down at some point. So maybe it's too early to start a translation project? regards marc
documentation translation effort ?
hello people, i just read this https://linuxfr.org/news/sortie-de-perl-5-30-0 in which the informations about perl6 are wrong. it points to https://fr.wikipedia.org/wiki/Rakudo_Perl which is wrong too and i was thinking that instead of writting wrong stuff on wrong sites, it would be nice to have a recap of the raku ecosystem (even the historical parts) directly in the perl6 site. but in french :) my broken english disqualify me to write the article itself but i obviously can translate it. which leads me to the translation effort: what if i want to translate the raku documentation? is there an official workflow? my own would be to get the hash of each file to be translated and start to translate it in another repo. regards, marc
Re: replace s///r ?
hello, On Tue, Jun 11, 2019 at 08:26:11AM -0500, Brad Gilbert wrote: > The /r modifier on s/// in Perl5 is S/// in Perl6. oops .. it was the section just after s/// :( thanks for pointing out. > Though you have to put it into a block lambda, otherwise it applies to > $_ before it gets a chance to be passed to map. this is very kind to let perl5 win sometimes :) regards marc
replace s///r ?
hello people, in perl5, i can print for map s/^/4/r, grep /^\d+$/, the perl6 version is a Seq, so much more memory friendly but i expected (and haven't found in the documentation) a short equivalent of s///r so the shorter i have is: $*ARGFILES . lines . grep( / ^ + $ / ) . map( *.subst(/^/," * ") ) . map(&other-things-to-do) . map(&say) when, of course, i want to replace . map( *.subst(/^/," * ") ) by something like . map( s:r/^/* / ) any idea? regards marc
Re: (update the doc?) Re: run with $*OUT?
hello, > Actually -- looks like it is there :-) though on the > Proc page, not the 'run' page -- too far from the expected lines. so maybe we should just add a link ? > I'm curious about whether you could rely > on a line being emitted right away -- e.g. > if there is some output-buffering of the > command well ... they told me that they torment implementers instead of users so i guess i can trust this code :) thanks, marc
(update the doc?) Re: run with $*OUT?
> Something like this? > my $p = run 'cat', '-n', :in, :out; > $p.in.say($_) for ; > $p.in.close; > say $p.out.slurp; *that* simple!!! perfect ... thanks a lot! this isn't obvious to guess that '-' means "you can connect the subprocess directly to the perl interpreter". i really think this example is worth to be added in the documentation. also, i guess that the way the example is written will cause some infinite iowait when we write a big enough amount of data to fill the buffer (i don't know if it's correct). so maybe this exemple should be added too? my $p = run 'cat', '-n', :in, :out; for { $p.in.say($_); say $p.out.lines(1)[0]; } $p.in.close; how about the attached patch? regards marc diff --git a/doc/Type/independent-routines.pod6 b/doc/Type/independent-routines.pod6 index 6142ebd3..f456b970 100644 --- a/doc/Type/independent-routines.pod6 +++ b/doc/Type/independent-routines.pod6 @@ -536,6 +536,30 @@ creating a kind of I: my $proc = run "ls", "-alt", :out($ls-alt-handle); # (The file will contain the output of the ls -alt command) +The standard input can be redirected as well so a bidirectional communication +can be establish with the run process. + +my $p = run 'cat', '-n', :in, :out; +for { $p.in.say($_) } +$p.in.close; +say $p.out.slurp; +# 1 i +# 2 bet +# 3 on +# 4 you +# 5 raku + +the last example isn't a good idea if you deal with a great amount of data so +you can also interact with the process line by line. + +my $p = run 'cat', '-n', :in, :out; +for { +$p.in.say($_); +say $p.out.lines(1)[0]; +} +$p.in.close; + + These argument are quite flexible and admit, for instance, handles to redirect them. See L and L for more details.
run with $*OUT?
hello people, French Perl Workshop is coming and would be a better event if *you* take part of it https://journeesperl.fr/jp2019/talks now the problem ... let's say i have a raku script to wrap mutt. in this script, i have * $body is the content of the body my message * $subject and $recipient are self explainatory from the shell, i call mutt those ways mutt -s $subject $recipient <<< $body mutt -s $subject $recipient <<. $body . i'm searching for the shortest/simplest way to do that in raku (meaning stay away from react/whenever for very basic usages) . so it seemed to me that `run` is a good candidate and expect filehandlers or filenames to setup the std. i tried some variations around my $p = run 'cat', '-n', in => $*OUT, :out; $*OUT.say for < i bet on you, raku >; $*ERR.say: $p.out.slurp; my $p = run 'cat', '-n', in => "/dev/stdout", :out; $*OUT.say for < i bet on you, raku >; $*ERR.say: $p.out.slurp; my $o2 = $*OUT.clone; my $p = run 'cat', '-n', in => $o2, :out; $o2.say for < i bet on you, raku >; $*ERR.say: $p.out.slurp; ... none of those made raku unhappy but none of them does the job. i'm on my way to use Proc::Async.new ... but before that, i would like to ask if there is a simpler solution. regards, marc
Announce: french perl workshop (Aka Journées Perl)
hello perl6 people, we hope there will be some events around the French Perl Worshop (aka journées perl) https://journeesperl.fr/jp2019/ there will be at least a "perl6 modules hackathon" (trying to contribute to the perl6 ecosystem). however i really would like to see a talk or a workshop about perl6. some ideas of topics that can be appreciated by the audience as well as trivial for some of you: * perl6 module path (and bytecoded version) * getting started with * zef and mi6 * Cro * NativeCall * Grammars so we'll be pleased to see you all and if you think you can give a talk: don't be shy and show us your perl6 :) regards marc
can't match unicode chars?
hello people, given the slides of my talk in the slides.vim format (https://github.com/eiro/slides.vim), i want some of them to be shown one bullet a slide. so when i have this input: › Renater et le libre Sympa FileSender the desired output is: › Renater et le libre Sympa › Renater et le libre FileSender and it seems gather is the perfect solution for that so i started to write it (any golfer magic or other feedback warmly welcome): @*ARGS.map: { gather { my @lines; for .IO.lines -> $l { if /'›'/ { @lines and take @lines; @lines = $l; } else { @lines.push($l); take @lines if /''/; } } } } this doesn't work as it seems that '›' and '' aren't matched. i tried both for .IO.lines -> $l { # following https://docs.perl6.org/routine/lines#class_IO::Path for .IO.lines(enc => 'utf8') -> $l { but none of them worked and i run out of idea to know what's going on. any idea or documentation point for me ? regards marc
Re: lats rakudo version from rakudobrew ?
hello, > This is one of the gotchas of rakudobrew. It determines the version from > the most recent release tag... but it uses git in default fetch mode, which > only pulls the most recent tag and never updates it, so your updates will > have the right commit hash but the wrong version from that point on. I > typically do 'git fetch --all' (but 'git fetch --tags' is likely good > enough for your use) in the three repos under ~/.rakudobrew/git_reference. > (You only need to do it once; git will keep it up to date itself once it > has been told that you want to track that.) i did it. i also removed all the repo and artefacts to start from scratch. yes i got a 2017.5. I have no more time to investigate so i fallback to my old script to make things work. thank you for helping -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln
Re: takeWhile ?
On Mon, Sep 11, 2017 at 10:16:50PM +0200, Timo Paulssen wrote: > the first expression uses ^ as a prefix operator on *, so it gives you > "a list of numbers 0 through * - 1" instead of "the number *" to compare > against *, so it's as if you had rounded the value up before comparing to 2. and now i got it :) thank you for this regards -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln
Re: takeWhile ?
On Mon, Sep 11, 2017 at 10:07:32PM +0200, Timo Paulssen wrote: > If I understand your problem correctly, you can simply use ...^ to leave > out the last element :) wow ... i tried it once but failed. and now i just spotted the error: i wrote (116, * * .6 ... ^ * < 2 ).say instead of (116, * * .6 ...^ * < 2 ).say the first expression is valid and i don't know what is does. the first expression is valid *and correct*. thank you! -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln
takeWhile ?
hello, doing maths with my kid, i just translated his spreadsheet with those lines of haskell: rebonds height loss = height : rebonds (height - height * loss) loss main = print $ takeWhile (> 2) $ rebonds 116 0.6 then i wanted to make it as short as possible in perl6, i'm almost there: (116, * * .6 ... * < 2 ).say but the first $_ < 2 remains in the list. the only one alternative i see is a gather/take loop but i really expect something shorter from perl6 :) any idea ? regards -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln
lats rakudo version from rakudobrew ?
hello people, since rakudo 2017.05, i ditched my own perl6 update/install script to use rakudobrew. as rakudo 2017.07 is out, i would like to update so i typed rakudo self-upgrade && rakudo build moar as written in the "Upgrading your Perl 6 implementation" section. it actually built stuff but at the end, perl6 -v still gives me 2017.05. any idea ? regards marc -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln
Re: lazy gather?
On Tue, Mar 14, 2017 at 03:16:40PM +0100, Andreas Mueller wrote: > > or in one line in REPL: > > ((1,1,*+* ... *).rotor(2=>-1).map:{[/] $_}) ... (*-*).abs < 1e-10 > > my \approx= fib.rotor(2 => -1).map: { .[1] ÷ .[0] }; both are awesome but i'll stick with the readable one :) thanks for help regards -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln
sympa hackathon: perl6 for the IM part ?
hello perl6 hackers, as some of you knows, there is a sympa hackathon in 3 weeks at Strasbourg. https://listes.renater.fr/sympa/arc/sympa-developpers/2017-02/msg0.html we talked about having an optionnal IM integration to the web UI using perl6. i'm really excited about it! if someone wants to help us, everyone is very welcome. just subcribe to this list: https://framalistes.org/sympa/info/sympa-20th-birthday-hackathon regards -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln
please apply to this CfP
hello people, Polyconf comes to Paris in 2017: https://eventil.com/events/polyconf-17/submissions/new and I would be really important to have a perl6 primer there. Any volonteer ? regards -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln
Re: lazy gather?
On Mon, Mar 13, 2017 at 08:33:05PM +0330, Siavash wrote: > I may be wrong, but I think the code should be: > my \golden= (1 + sqrt 5) ÷ 2; > my \fib = 1, 1, * + * ... ∞ ; > my \approx= gather for fib.rotor(2 => -1) { take .[1] ÷ .[0] }; > my \distances = approx.map: (golden - *).abs; > say distances[^1000]; excellent! i updated my perl6 and tested this code and it works well! thank you everyone. -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln