From mark at purdue.edu Sun Oct 13 17:22:52 2019 From: mark at purdue.edu (Mark Senn) Date: Sun, 13 Oct 2019 20:22:52 -0400 Subject: [Purdue-pm] Perl 6, use "," instead of "!" for command history Message-ID: <25285.1571012572@pier.ecn.purdue.edu> Purdue Perl Mongers, Engineering Computer Network staff, Below is my Perl 6 solution to the Perl Weekly Challenge - 029, task #1. The Perl 6 programming language is Perl 5 totally redesigned and rewritten from the ground up. If you don't have any Perl 5 or Perl 6 experience this may not make much sense to you. There is also an "ASIDE: BASH SHELL HISTORY EXPANSION" section below. If you type "!" followed by a number or by a string to redo a command you did earlier on Linux, and would like to know how to use "," instead of "!" because it is easier to type, see below. # # Perl Weekly Challenge - 029 # Task #1 # # Mark Senn, http://engineering.purdue.edu/~mark # October 13, 2019 # # From # https://perlweeklychallenge.org/blog/perl-weekly-challenge-029#task-1 # Write a script to demonstrate brace expansion. For example, # script would take command line argument # Perl {Daily,Weekly,Monthly,Yearly} Challenge # and should expand it and print like below: # Perl Daily Challenge # Perl Weekly Challenge # Perl Monthly Challenge # Perl Yearly Challenge # # ASIDE: HELP WANTED WITH PERL 6 CUSTOM SYNTAX # This works: # my @x = (, ); # @x.map({.join(':').say}); # I'd like for this to work so I don't need to type as much: # @x.{.join(':').say}; # If you know how to do it please send me the answer at the email # address in # https://engineering.purdue.edu/~mark/ # Thank you. # # ASIDE: BASH SHELL HISTORY EXPANSION # If you use ! followed by a command number to rerun that command # or a string to rerun tha last command that started with that # string and would like to change that to ',' because that is easier # to type keep reading this ASIDE. # I use ',' instead of '!' for my Bash shell history expansion # character because I use shell history expansion often and ',' # is easier to type than '!'. Because of that I'd need to type # Perl {Daily\,Weekly\,Monthly\,Yearly} Challenge # on the command line to do the challenge. (I have things set # up so that is the default input if no arguements are on the # command line for this program, too.) # From # http://web.mit.edu/gnu/doc/html/features_4.html # histchars # Up to three characters which control history expansion, # quick substitution, and tokenization (see section History # Interaction). The first character is the # history-expansion-char, that is, the character which # signifies the start of a history expansion, normally # `!'. The second character is the character which signifies # `quick substitution' when seen as the first character on a # line, normally `^'. The optional third character is the # character which signifies the remainder of the line is a # comment, when found as the first character of a word, # usually `#'. The history comment character causes history # substitution to be skipped for the remaining words on the # line. It does not necessarily cause the shell parser to # treat the rest of the line as a comment. # To change my Bash shell history characters from '!^#' to ',^#' # I put # histchars=',^#' # in my .bashrc file. Other shells use histchars also---check # the documentation for your shell if you are interested. # # Run using Perl v6.d; use v6.d; sub MAIN(*@arg); { # If no command line arguments are given use these defaults. # I couldn't figure out how to do this on the "sub MAIN" line # without getting a "Cannot put default on slurpy parameter @arg" # error. (@arg.elems) or @arg = 'Perl', '{Daily,Weekly,Monthly,Yearly}', 'Challenge'; # Convert the @arg array to a @term array. The next paragraph # of code explains this in detail. my @term = (); for @arg { # If $_ starts with '{' and ends with '}' # set $0 to what's between the braces. if /^^ \{ (.*?) \} $$/ { # Split $0 on commas and push the that array # on @term as a single element. push @term, $0.split(','); } else { # Push the scalar $_ on @term. push @term, $_; } } # At this point, if no command line arguments are set # $term[0] is 'Perl' # $term[1] is ('Daily', 'Weekly', 'Monthly', 'Yearly') # $term[2] is 'Challenge' # $term[0] X $term[1] X @term[2] would give a list of # ('Perl', 'Daily', 'Challenge') # ('Perl', 'Weekly', 'Challenge') # ('Perl', 'Monthly', 'Challenge') # ('Perl', 'Yearly', 'Challenge') # If the program is called with a different number of # arguments there will be a different number of @term # elements set. The reduction operator '[X]' puts a 'X' # between each element of @term. After the '([X] @term).' # any of the following can be used to do what we want: # # Convert * to type Str and print it. # map(*.Str.say); # # Convert * to type Stringy and print it. # map(*.Stringy.say); # # Convert * to string and print it. # map((~*).say); # # Put a space between each element of $_ and print it. # map({join(' ',$_).say}); # # Put a space between each element of $_ and print it. # map({$_.join(' ').say}); # # Put a space between each element of $_ and print it. # # If a method is going to operate on $_ you don't need to # # specify '$_'. # map({.join(' ').say}); # I like the following line the best. ([X] @term).map({.join(' ').say}); } From mark at purdue.edu Wed Oct 16 10:50:14 2019 From: mark at purdue.edu (Mark Senn) Date: Wed, 16 Oct 2019 13:50:14 -0400 Subject: [Purdue-pm] Perl 6 renamed to Rakudo Message-ID: <2500.1571248214@pier.ecn.purdue.edu> There isn't what I'd call an official announcement out yet but it appears that "Perl 6" will be renamed to "Raku" and "Perl 5" will be renamed to "Perl version 5" or something similar. Announcements have already been on many international tech sites. I think it is getting to the point that not doing this change would be prohibitively difficult. I got a free "Using Raku" book earlier today from https://raku.online/2019/10/13/using-raku-the-free-book/ That book is suitable for beginners. It was reported that Larry Wall, the creator of Perl, would like the upcoming PerlCon in Cypress to be renamed RakuCon. Again, I can find a high enough quality source to cite for this. I like Raku much better than Perl. More power, flexibility, etc. Perl uses @x and $x[0]. Raku uses @x and @x[0]. -mark From mark at purdue.edu Sun Oct 20 16:31:05 2019 From: mark at purdue.edu (Mark Senn) Date: Sun, 20 Oct 2019 19:31:05 -0400 Subject: [Purdue-pm] Purdue Weekly Challenge solutions Message-ID: <1201.1571614265@pier.ecn.purdue.edu> Perl 5 is the Perl that has been distributed for decades. Perl 6 is a new language with the language syntax totally redesigned and Perl 6 was totally rewritten from scratch. Perl 5 has been renamed to Perl and Perl 6 has been renamed to Raku. Perl Weekly Challenge 030 Raku solutions for tasks #1 and #2 are below. The solution for task 2 has a solution written in Wolfram Language (Mathematica is a technical computing environment inside which one can write Wolfram Language code.) # # Perl Weekly Challenge - 030 # Task #1 # # Mark Senn, http://engineering.purdue.edu/~mark # October 19, 2019 # # From # https://perlweeklychallenge.org/blog/perl-weekly-challenge-030#task-1 # Write a script to list dates for Sunday Christmas # between 2019 and 2100. For example, 25 Dec 2022 is Sunday. # # Perl 6 is in the process of being renamed Raku. # Run using Raku v6.d; use v6.d; sub MAIN() { for (2019..2100) -> $year { (Date.new(day =>25, month=>12, year=>$year).day-of-week == 7) and say "25 Dec $year"; } } # The program printed: # 25 Dec 2022 # 25 Dec 2033 # 25 Dec 2039 # 25 Dec 2044 # 25 Dec 2050 # 25 Dec 2061 # 25 Dec 2067 # 25 Dec 2072 # 25 Dec 2078 # 25 Dec 2089 # 25 Dec 2095 # # Perl Weekly Challenge - 030 # Task #2 # # Mark Senn, http://engineering.purdue.edu/~mark # October 19, 2019 # # From # https://perlweeklychallenge.org/blog/perl-weekly-challenge-030#task-2 # Write a script to print all possible series of 3 positive numbers, # where in each series at least one of the number is even and sum of # the three numbers is always 12. For example, 3,4,5. # # The sum of any three odd positive numbers will always be odd. So, # any three positive numbers that add to 12 must have at least one # even number. The task can be restated as # Write a script to print all possible series of 3 positive numbers # where the sum of the numbers is 12. For example, 3,4,5. # # THIS WOLFRAM LANGUAGE (FORMERLY KNOWN AS MATHEMATICA) PROGRAM CAN BE USED # TO SOLVE THIS PROGRAM: # s = Solve[i+j+k == 12 && i>0 && j>0 && k>0, {i,j,k}, Integers]; # # For [t=1, t<=Length[s], t++, # Print[i/.s[[t,1]], ",", j/.s[[t,2]], ",", k/.s[[t,3]]]; # ]; # # Perl 6 is in the process of being renamed Raku. # Run using Raku v6.d; use v6.d; sub MAIN() { for (1..10) -> $i { for (1..10) -> $j { for (1..10) -> $k { ($i + $j + $k == 12) and say "$i,$j,$k"; } } } # Optimize so we don't need to examine as many numbers. for (1..10) -> $i { for (1..12-$i-1) -> $j { for (12-$i-$j..10) -> $k { ($i + $j + $k == 12) and say "$i,$j,$k"; } } } } # For each example, the program printed: # 1,1,10 # 1,2,9 # 1,3,8 # 1,4,7 # 1,5,6 # 1,6,5 # 1,7,4 # 1,8,3 # 1,9,2 # 1,10,1 # 2,1,9 # 2,2,8 # 2,3,7 # 2,4,6 # 2,5,5 # 2,6,4 # 2,7,3 # 2,8,2 # 2,9,1 # 3,1,8 # 3,2,7 # 3,3,6 # 3,4,5 # 3,5,4 # 3,6,3 # 3,7,2 # 3,8,1 # 4,1,7 # 4,2,6 # 4,3,5 # 4,4,4 # 4,5,3 # 4,6,2 # 4,7,1 # 5,1,6 # 5,2,5 # 5,3,4 # 5,4,3 # 5,5,2 # 5,6,1 # 6,1,5 # 6,2,4 # 6,3,3 # 6,4,2 # 6,5,1 # 7,1,4 # 7,2,3 # 7,3,2 # 7,4,1 # 8,1,3 # 8,2,2 # 8,3,1 # 9,1,2 # 9,2,1 # 10,1,1 -mark From mark at purdue.edu Mon Oct 21 10:35:47 2019 From: mark at purdue.edu (Mark Senn) Date: Mon, 21 Oct 2019 13:35:47 -0400 Subject: [Purdue-pm] free _Raku One-Liners_ book Message-ID: <46183.1571679347@pier.ecn.purdue.edu> A free _Raku One-Liners_ book is available from https://deeptext.media/i/raku-oneliners/RakuOneLiners.pdf -mark