From mark at purdue.edu Mon Mar 11 05:56:03 2019 From: mark at purdue.edu (Mark Senn) Date: Mon, 11 Mar 2019 08:56:03 -0400 Subject: [Purdue-pm] Perl 6 One-Liners Message-ID: <20618.1552308963@pier.ecn.purdue.edu> There is a "Perl 6 One-Liners" presentation by Andrew Shitov on the web at https://www.slideshare.net/andy.sh/perl6-oneliners I recommend it. My advice---puzzle out the easy stuff, if something looks hard skip it until you have more experience with Perl 6. William F. Buckley Jr. knew lots of English words and could use the most appropriate tool (word) for a task. He wasn't afraid to use sharp tools among not-so-sharp company. Perl 6 has many more tools than Perl 5 and is joy to use. The new operators are arranged into groups that make sense and can be combined in---in my opinion---natural ways. I urge you to learn the new vocabulary but not abuse it by trying to be too clever. Programming involves typing and thinking, Perl 6 allows me to do less of each. I well-written Perl 6 programs much easier to read than Perl 5. -mark From mark at purdue.edu Mon Mar 11 06:10:53 2019 From: mark at purdue.edu (Mark Senn) Date: Mon, 11 Mar 2019 09:10:53 -0400 Subject: [Purdue-pm] "Perl 6 One-Liners" with corrections and additions Message-ID: <24360.1552309853@pier.ecn.purdue.edu> There is a "Perl 6 One-Liners" presentation by Andrew Shitov on the web at https://www.slideshare.net/andy.sh/perl6-oneliners I recommend it. My advice---puzzle out the easy stuff, if something looks hard skip it until you have more experience with Perl 6. William F. Buckley Jr. knew lots of English words and could use the most appropriate tool (word) for a task. He wasn't afraid to use sharp tools among not-so-sharp company. Perl 6 has many more tools than Perl 5 and is a joy to use. The new operators are arranged into groups that make sense and can be combined in---in my opinion---very natural ways. I urge you to learn the new vocabulary but not abuse it by trying to be too clever. Programming involves typing and thinking, Perl 6 allows me to do less of each. I find well-written Perl 6 programs much easier to read than Perl 5. In my opinion, it doesn't make sense to write "down" to the lowest common denominator. It's faster, cheaper, and more fun to use sharper tools. -mark From mark at purdue.edu Thu Mar 21 19:06:15 2019 From: mark at purdue.edu (Mark Senn) Date: Thu, 21 Mar 2019 22:06:15 -0400 Subject: [Purdue-pm] Perl 6 sets Message-ID: <26835.1553220375@pier.ecn.purdue.edu> Purdue Perl Mongers, Thought you might be interested in the following Perl 6 program. If your problem domain is sets, Perl 6 supports those very naturally, including the Unicode math symbols for union, intersection, and set difference. There are non-Unicode versions of the symbols if you don't like Unicode. -mark # Read files 'a', 'b', 'c', and 'd' and print the unique lines that # are in 'a' or 'b', and aren't in both 'c' and 'd'. use v6; # Define a sub so we don't need to write # my $a = 'a'.IO.lines.Set; # my $b = 'b'.IO.lines.Set; # [...] # Read all lines in $filename, make a set, and return the set. sub readset($filename) { return $filename.IO.lines.Set; } my $a = readset 'a'; my $b = readset 'b'; my $c = readset 'c'; my $d = readset 'd'; # SYMBOL DESCRIPTION UNICODE CODEPOINT # ? intersection U+2229 # ? set difference U+2216 # ? union U+222A # # Using my 'a', 'b', 'c', and 'd' test files gives # $a is (a b c) # $b is (c d e) # $c is (c d) # $d is (c e) # ($a ? $b) is (a b c d e) # ($c ? $d) is (c) # ($a ? $b) ? ($c ? $d) is (a b d e) (($a ? $b) ? ($c ? $d)).keys.sort.say; # Or, if you don't like to use Unicode characters: (($a (|) $b) (-) ($c (&) $d)).keys.sort.say; From mark at purdue.edu Fri Mar 29 07:11:09 2019 From: mark at purdue.edu (Mark Senn) Date: Fri, 29 Mar 2019 10:11:09 -0400 Subject: [Purdue-pm] Personal electronics recycling event Message-ID: <4324.1553868669@pier.ecn.purdue.edu> at Purdue from 10am to 2pm on Saturday, March 30, 2019. See https://www.purdue.edu/newsroom/releases/2019/Q1/personal-electronics-recycling-event-being-held-saturday-on-campus.html for more information -mark From mark at purdue.edu Sun Mar 31 22:45:21 2019 From: mark at purdue.edu (Mark Senn) Date: Mon, 01 Apr 2019 01:45:21 -0400 Subject: [Purdue-pm] Perl Weekly Challenge Message-ID: <4264.1554097521@pier.ecn.purdue.edu> The Perl Weekly Challenge problem web site is at https://perlweeklychallenge.org The deadline for submitting answers to the first challenge has passed so I can send out my answer now. I do these challenges in Perl 6. It's a much better language than Perl 5. The solution I sent in is attached. Perl 6 has many new features compared to Perl 5. I think I may be able to write a much clearer answer to the second challenge using one of the new features. -mark -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: answer.email URL: From mark at purdue.edu Fri Mar 8 17:06:41 2019 From: mark at purdue.edu (Mark Senn) Date: Sat, 09 Mar 2019 01:06:41 -0000 Subject: [Purdue-pm] Perl 6 hyper and reduction operators, etc. Message-ID: <48702.1552093589@pier.ecn.purdue.edu> Purdue Perl Mongers, Thought you might be interested in the Perl 6 program below. See https://perl6.org/ for more information on Perl 6 (not to be confused with Perl 5). It shows how to o defining your own infix command (+ is a normal infix command) o do custom usage messages---automatic usage messages are done by default o do grep commands in parallel using .race o use hyper operators o use reduction operations o etc. I'm working on a one page printed on both sides example of how to use the free LaTeX typesetting system. So far the following is planned (this document will have narrow margins and not much white space): automatically produced bibliographies chemical diagrams chemical symbols computer program listings defining LaTeX commands, in particular to make it easy to typeset the first two verses of Supercalifragilisticexpialidocious doing SI and etc. units properly (meters, seconds, etc.) electrical circuits embedding video files in PDF files embedding you tube videos in PDF files Feynman diagrams figures graphics including 2D and 3D graphs using the handicapped friendly Cividis color map math (including weird fonts and symbols from many branches of math) microtype typograhy improvements music pictures tables The purpose of this document is to grab people's attention and try to get them interested in using LaTeX for their thesis or dissertation. Let me know if there is anything you'd like to see demostrated. Mark Senn, Senior Software Engineer, Engineering Computer Network, Purdue University # # factor 2019-03-08 Mark Senn http://engineering.purdue.edu/~mark # # Factor the positive integer given on the command line. # # If the MAIN subroutine signature doesn't match usage print # this custom error message. sub USAGE { say "Usage: {$*PROGRAM-NAME} unsigned_composite_number"; } # Set the MAIN subroutine signature so $N must be a positive # integer that is is a composite number---not a prime. sub MAIN (UInt $N where $N > 0 && !($N.is-prime)) { # METHOD 1: divide by each prime, one at a time. # From # http://www.jnthn.net/papers/2018-conc-par-8-ways.pdf # starting at page 39 (for example, ^3 is a (0,1,2) list: # Sequential runs in 17.2s # say ^100000.grep(*.is-prime) .elems # Parallel runs in 5.3s # say ^100000.race.grep(*.is-prime) .elems # Make a list of primes that are in the range of 2 to floor(sqrt($n)). # I LOVE the way Perl 6 code reads well from left to right. my @p = (2..$N.sqrt).race.grep(*.is-prime); my $n = $N; # While the number hasn't been factored. while ($n != 1 && !($n.is-prime)) { # Try dividing it by all computed primes. for @p -> $p { # Is the number evenly divisible by the current prime? while $n %% $p { say $p; $n div= $p; } } } # For the number 6, for example, we factor out a 2 above # and there is a 3 left. If there is 1 don't print it, # if there is one remaining prime factor then print it. ($n == 1) or say $n; say "-----"; # METHOD 2: divide by all primes in parallel. We can # use hyper operators and reduction operators to make # the notation nicer. # # From https://docs.perl6.org/language/operators#Hyper_operators: # Hyper operators include ? and ?, with their ASCII variants # << and >>. They apply a given operator enclosed (or preceded # or followed, in the case of unary operators) by ? and/or ? # to one or two lists, returning the resulting list, with the # pointy part of ? or ? aimed at the shorter list. Single # elements are turned to a list, so they can be used too. # [...] # Also, methods can be called in an out of order, concurrent # fashion. The resulting list is in order. Note that all hyper # operators are candidates for autothreading and will cause # tears if the methods have side effects. The optimizer has # full reign over hyper operators, which is the reason that # they cannot be defined by the user. $n = $N; # Define a new operator called mt (make triple). The $n # (nummber) and $p (prime) in the sub's signature are # local to this subroutine. Given $n and $p we return a # (multiplier, multiplacand, count) triple. Equivalent # code for expression below is # If ($n mod $p == 0) { # return ($p, 1, 1); # } else { # return (1, 1, 0); # } # Offhand I don't know how to turn ordinary subs into hyper # operators---that's why I made this an infix operator. sub infix:(UInt $n, UInt $p) { ($n %% $p) ?? ($p,1,1) !! (1,1,0); } # Initialize the @totalcount array. my @totalcount = 0 xx @p; # Divide $n by each prime. # For $n = 2 x 3 x 5 x 7 = 210, this gave # (1, 1, 1, 1, 0, 0). # For $n = 2^2 x 3 x 5 x 7 = 420, this gave # (1, 1, 1, 1, 0, 0, 0, 0) # not # (2, 1, 1, 1, 0, 0, 0, 0) # To get all the factors we need to divide $n by # the product of all multipliers and multiplacands # and do another pass. while (True) { # One should be able to do # my @triple = $n >>mt<< @p; # and/or # my @triple = ($n) >>mt<< @p; # because, as stated above, "Single elements are turned to # a list, so they can be used too.". This didn't work using # the April 2018 version on Perl 6. Make a list of $n's the # length of @p. my @n = $n xx @p; my @triple = @n >>mt<< @p; # Use some temporary variables to make things more clear. my @multiplier = @triple[*; 0]; my @multiplicand = @triple[*; 1]; my @count = @triple[*; 2]; # If we don't have any primes exit the loop. # ([+] @count == 0) and last; # Depending on the hardware we're running on, doing a # bit-wise or over all the counts may be faster. ([+|] @count) or last; @totalcount >>+=<< @count; $n div= [*] (@multiplier >>*<< @multiplicand); } for (0..^@p) -> $i { for (^@totalcount[$i]) { say "{@p[$i]}"; } } ($n > 1) and say $n; }