From mark at purdue.edu Thu Jun 3 04:47:09 2010 From: mark at purdue.edu (Mark Senn) Date: Thu, 03 Jun 2010 07:47:09 -0400 Subject: [Purdue-pm] using Perl 6 Message-ID: <26294.1275565629@pier.ecn.purdue.edu> I istalled the latest Rakudo (Perl 6) on my home computer (Fedora 13 Linux) last night using the instructions in http://www.rakudo.org/how-to-get-rakudo: $ git clone git://github.com/rakudo/rakudo.git $ cd rakudo $ perl Configure.pl --gen-parrot $ make (forget if I did next command or not) $ make install Haven't found anything that is broken yet...just tried some simple stuff though. Thought you might be interested in following message. I found the discussion following the === while loop === heading interesting. -mark >Date: Thu, 3 Jun 2010 11:51:36 +0300 >From: Gabor Szabo >To: perl6 at szabgab.com >Subject: [Perl6 Tricks and Treats] Staring with Perl 6 > >==== Welcome back to the Perl 6 Tricks and Treats ==== > >My 12 year old son had several attempts to learn programming >already. He started to build a web application in Perl but >without the basics and without understand English he kept >getting stuck with simple things such as references and >5 dimensional hashes. > >A few days ago we decied to put him through my regular Perl 5 >training material that will let him learn the basics. He seems >to be mature enough now that he can find the joy in creating >even console based games. At least he might understand the >need to go a bit slower and not jump into a web application. > >I started to teach him Perl 5 and programming in general. >We decided on Perl 5 as that's what I know the most and >its a mature language so he will be able to continue to write >his web application. >In a few days we learned about scalars, basic I/O (print and ), >chomp, if conditions, strings and numbers, while loops, int, rand. >We already started to learn about reading and writing files. > >All this time I kept feeling that my training material does not fit >someone who does not have the basic concepts of a computer yet and >has no background in programming. Also there were all kinds of things >I had to explain that were just not clear. e.g. the need for chomp, >why to write the "or die" part of open() at all? > >The former I could manage by adjusting the lectures to his needs, >skipping slides that were not relevant and adding more explanations >where needed. I could not deal with the latter part, that are just >issues with Perl 5. > >Yesterday I decided that I stop the whole Perl 5 course and switch >over to teach him Perl 6. After all his main interest is to learn >programming and to build a game for himself and for his frinds. >It does not need to be production grade and by the time he reaches >the point that he wants this to be on a public server we will have >a much more mature Perl 6 implementation. > >This will also give me an opportunity to go over my training >material with the eyes of someone totally new to programming. > >==== Upcoming Courses ==== > >This year I am not running Perl 6 classes or any classes next >to the YAPCs but Damian Conway does: > >== Hands-on Perl 6 with Rakudo == > >? ?June 25 ?Registration via the YAPC::NA web site > >? ?http://yapc2010.com/yn2010/talk/2765 > >==== Getting Rakudo ==== > >In order to make life easier for my son I built Rakudo >for him follow the instructions on > >http://www.rakudo.org/how-to-get-rakudo > >I added the directory of rakudo to the PATH so it will be easy >for him to run perl6 from the comman line. > >BTW he is using Ubuntu 10.4 > > >==== Setting up Padre for Perl 6 ==== > >I also installed Padre from CPAN (using local::lib) >and installed the Padre::Plugin::Perl6 from CPAN. > >Once I launched Padre I went to Tools/Plug-in Manager and >enabled the Perl 6 plugin. > >Then I went to Tools/Preferences/File and colors >in File type: I selected Perl 6 and in Highlighter STD.pm >That will provide syntax highlighting for files with p6 extension. > >I also turned on View/Show Syntax check > >==== Perl 6 ?==== > >Let's start the code now: > >?use v6; ? ? ? ? ? ? ?# Even though this is not enforced when using >? ? ? ? ? ? ? ? ? ? ? # Rakudo better to declare the version of perl. >? ? ? ? ? ? ? ? ? ? ? # This will avoid lots of head scratching >? ? ? ? ? ? ? ? ? ? ? # when you run it with perl 5 by mistake. > >?say 42; ? ? ? ? ? ? ?# prints 42 and a newline >?say "hello world"; ? # prints hello world and a newline > > >This was the first time, after about 2 minues in Perl 6 that he said >"Oh that's simpler". > >Values need to be stored in boxes .... so the values of the boxes >can be changed later. Therefore the boxes are called "variables". >The scalar values such as numbers and strings can be stored in so called >scalar variables. > >?my $x = 42; ? ? ? ? ?# Scalar variables start with $ and include >? ? ? ? ? ? ? ? ? ? ? # letters and numbers and underscore. >? ? ? ? ? ? ? ? ? ? ? # They are declared using the "my" keyword. >?say $x; ? ? ? ? ? ? ?# They can be used just as regular scalar values. > >Earlier I already explained to him that this is different from math. >Here the = sign means assignment. So the previous statement means >put 42 in the box that is called $x. > >?my $name = prompt("type your name: "); > >? ? ? ? ? ? ? ? ? ? ? # This will print the string on the screen and then >? ? ? ? ? ? ? ? ? ? ? # wait for the user to type in some text and press enter. >? ? ? ? ? ? ? ? ? ? ? # This replaces the we had in perl 5. > >He asked where is chomp. There is no need for chomp here as prompt() >automatically removes the newlines. >"Oh nice", he said. > > >=== Conditionals === > >?if $age == 12 { >? ? ?say "he is 12"; >?} > >The if conditional does not need to have parentheses around it. >This looks strange to me but it he found it simpler. > >I had to point out here that we have ==, two equeal signs that mean >we are not assigning values but checking if they are equal or not. >I also had to explain about the difference between numerical == >and string 'eq'. I think this will need more explanation though. > > >else, and elseif are the same as in Perl 5 so you can write: > >?if $age < 12 { >? ? ?# young >?} else { >? ? ?# old >?} > >or you can write > >?if $age < 11 { >? ? ?# too young >?} elsif $age > 13 { >? ? ?# to old >?} else { >? ? ?# good >?} > > >Then I showed him the chained comparison possibilities: > >?if (11 <= $age <= 13) { >? ? ?say "Good, $age is in the range. We can play soccer."; >?} else { >? ? ?say "No partner for game"; >?} > >He loved that it is just like in math. > > >=== while loop === > >For English speakers it might be obvious what a while loop does >but others better translate the word for themselves and build a >real sentence with it. >In English it sound like this: > >While this is true do this. > >In perl 6 it looks like this: > >?while this is true { >? ? ?do this >?} > >and with a real example it looks like this: > >?my $num = 50; >?while $num >= 50 { >? ? ?$num = prompt("Please give a number smaller than 50: "); >?} > >Actually my son kept writing code like this: > >?my $num = prompt("Please give a number smaller than 50: "); >?while $num >= 50 { >? ? ?$num = prompt("Please give a number smaller than 50: "); >?} > >I am not 100% sure how to elminate that duplication in a way that >will make sense to him as well. He thinks about this as >"Ask the user. If the answer is incorrect, ask again." > >I would probably write this code: > >?my $num; >?while not defined $num or $num >= 50 { >? ? ?$num = prompt("Please give a number smaller than 50: "); >?} > >which translates to "While no correct value ask for a value". > >Maybe this would make more sense though: > >?my $num = prompt("Please give a number smaller than 50: ") >? ? ?while not defined $num or $num >= 50; > >Which is "Ask for a value as long as it is incorrect". > > >The "not defined $num" part still seems to be as unnecessary in >this case but that is currently required. > > >I asked on the #perl6 IRC channel for a more natural solution. >I got several suggestions in a few seconds. The one that seemed >to make sense the most to me was: > >?while (my $num = prompt("Please give a number smaller than 50: ")) >= 50 {} > >Here we need the extra parentheses around the assignment or the >= comparision >would take precedence. > > > >There was one thing that tripped us is that code like this: > >?while ($num >= 50){ >?} > >is incorrect. People who are used to write extensive spaces won't >fall in that trap but many beginners skip spaces in all kinds >of places. > >In this case you need to either add a space between the >closing parentheses and the ?opening curly or omit the parentheses at all. > >That's all for now. > > >=== Comments and Discussion === > >I am always open to comments and criticism >(just have a positive spin to it :-) >So if you find any issue with the examples, >please don't hesitate to let me know. > >If you'd like to ask question about Perl 6, >probably the best would be to sign up on the Perl 6 >users list by sending an e-mail to > >? ?perl6-users-subscribe at perl.org > >The archive of the perl6-users list is at: ? http://www.perl6.org/ > >The even better way is to join the #perl6 IRC channel on irc.freenode.net >If you have not used IRC yet, the easies way is to use the web based >IRC client of Freenode http://webchat.freenode.net/?channels=perl6 > >Previous issues of this newsletter can be found on > >? ?http://szabgab.com/perl6_tricks_and_treats.html > > >==== Copyright ==== > >Perl 6 Tricks and Treats and associated text is >Copyright 2009-2010 Gabor Szabo >The specific posts are Copyright the respective authors. >You may freely distribute this text so long as it is distributed >in full with this Copyright noticed attached. > >If you have any questions please don't hesitate to contact me: >Email: szabgab at gmail.com >Web: ? http://szabgab.com/ >_______________________________________________ >Perl6 mailing list >Perl6 at szabgab.com >http://mail.szabgab.com/mailman/listinfo/perl6 From westerman at purdue.edu Thu Jun 10 08:28:02 2010 From: westerman at purdue.edu (Rick Westerman) Date: Thu, 10 Jun 2010 11:28:02 -0400 Subject: [Purdue-pm] PM meeting this Tuesday, June 15th Message-ID: <4C110482.6060201@purdue.edu> Bizarrely I had the current meeting on the Monday the 21st from noon to 1:30 (I actually blame our scheduling person but really I should have caught the mistake earlier.) Anyway ... the meeting is now properly schedule on June 15th, 11:30 to 1:30 in WSLR 116. Social time from 11:30 to noon. Presentations from noon onward. No talks are currently scheduled but that does not seem to stop us from having an interesting last minute presentation. We do have several challenge problems out on the table. The most recent is from Joe and is summarized below. I had suggested that the fastest way to access the data was via an array. And indeed Mark sent out an elegant solution that used an array. I am not sure if we can do better than that. That is the solution is O(1) ignoring, as is typical, setup time. And space is O(x) where 'x' is the size of the array. However what if we have a very large and sparse array? And if we do wish to consider setup time plus minimizing memory space? Then what type of solution can be found? The other challenge problem on the table is Michael's from a couple of months ago. He presented a 'C'-based solution that is much speedier than his Perl-based ones. The overall challenge is to come up with (a) either a more speedy solution or (b) a fast Perl-based solution. The final challenge is one that I off-handedly mentioned: how to interactively present customer information on a web page. There are many different ways to do this and the challenge here is not to create the 'best' way but rather to show each other new techniques and perhaps to explore new techniques on our own in the safety of a non-critical application. In the June meeting I will present the API methods we can use to create our solutions. These solutions will be presented in July & August. -- Rick Westerman westerman at purdue.edu Bioinformatics specialist at the Genomics Facility. Phone: (765) 494-0505 FAX: (765) 496-7255 Department of Horticulture and Landscape Architecture 625 Agriculture Mall Drive West Lafayette, IN 47907-2010 Physically located in room S049, WSLR building From mark at ecn.purdue.edu Thu Jun 10 09:47:53 2010 From: mark at ecn.purdue.edu (Mark Senn) Date: Thu, 10 Jun 2010 12:47:53 -0400 Subject: [Purdue-pm] PM meeting this Tuesday, June 15th In-Reply-To: <4C110482.6060201@purdue.edu> References: <4C110482.6060201@purdue.edu> Message-ID: <29535.1276188473@pier.ecn.purdue.edu> Rick> We do have several challenge problems out on the table. The Rick> most recent is from Joe and is summarized below. I had Rick> suggested that the fastest way to access the data was via an Rick> array. And indeed Mark sent out an elegant [Perl 5 -mark] Rick> solution that used an array. I'll try to send a Perl 6 solution to the list before the next meeting. Rick> I am not sure if we can do Rick> better than that. That is the solution is O(1) ignoring, as is Rick> typical, setup time. And space is O(x) where 'x' is the size of Rick> the array. However what if we have a very large and sparse Rick> array? And if we do wish to consider setup time plus minimizing Rick> memory space? Then what type of solution can be found? Doing a Google search for perl sparse arrays gave around 20,900 results. I thought (next line over 80 chararacters) http://etutorials.org/Programming/Perl+tutorial/Chapter+4.+Arrays/Recipe+4.4+Implementing+a+Sparse+Array/ and http://stackoverflow.com/questions/863426/counting-array-elements-in-perl were helpful. (Mathematica---my second favorite programming language, has sparse arrays built-in.) Rick> And if we do wish to consider setup time plus minimizing Rick> memory space? Then what type of solution can be found? I don't want to consider it---too hypothetical in the context of the simple challenge problem. Use hashes for the 1D case. Maybe spin this off into a 2D or more challenge problem to better investigate setup time and minimizing memory space? -mark From mark at ecn.purdue.edu Fri Jun 11 22:17:08 2010 From: mark at ecn.purdue.edu (Mark Senn) Date: Sat, 12 Jun 2010 01:17:08 -0400 Subject: [Purdue-pm] fast table lookup of randomly associated items In-Reply-To: <4BF43C24.3090901@purdue.edu> References: <4BF43C24.3090901@purdue.edu> Message-ID: <7199.1276319828@pier.ecn.purdue.edu> > Say I have a table like the following: > > number Item > 1-5 A > 6 B > 7-12 C > 13-20 D > 21-25 E > 26-30 F > > Say I then have a random number generator that spits out a number from > 1-30. > > What is the fastest way to look up the item associated with that random > number? > > For more fun, say I want to store that table in a text file what is a > good way to represent that? > > I kicked around some ideas and the easiest solution I could come up with > is the following. I settled on JSON since it's a bit more portable than > most and I like its syntax better than YAML. > =================================== > > #!/usr/local/bin/perl > > use 5.010; > > use strict; > use warnings; > > use File::Slurp; > use JSON; > > my $table = q(table.json); > my $json_text = read_file( $table ) ; > my $data = from_json($json_text); > > my $number = int(rand(30)+1); > my $item = q(nothing); > foreach my $row ( @$data ) { > if ( $number > $row->[0] ){ > } > else { > $item = $row->[1]; > last; > } > } > > say qq($number associated with $item); > > exit(0); > > =================================== > table.json: > > [ > [5,"A"], > [6,"B"], > [12,"C"], > [20,"D"], > [25,"E"], > [30,"F"] > ] Perl 5 solution: #!/usr/bin/perl use Modern::Perl; my @table; while () { chomp; my ($range, $letter) = split /\s+/; ($range =~ /-/) or $range .= "-$range"; my ($min, $max) = split /-/, $range; @table[$min..$max] = ($letter) x ($max-$min+1); } my $number = int 1 + rand $#table; say "number $number is associated with $table[$number]"; __END__ 1-5 A 6 B 7-12 C 13-20 D 21-25 E 26-30 F Perl 6 solution: #!/home/mark/rakudo/perl6 # I couldn't get the following constructs to work in Rakudo on 2010-06-12 # # my $fh = open $fn, :r # err die "Can't open $fn for input: $!"; # # =begin DATA # ... # =end my @table; my @t = '1-5 A 6 B 7-12 C 13-20 D 21-25 E 26-30 F'.split(/\n/); for @t { my ($range, $letter) = $_.split(/\s+/); ($range ~~ m/\-/) or $range ~= "-$range"; my ($min, $max) = $range.split(/\-/); @table[$min..$max] = $letter xx $max-$min+1; } say @table[1..^+ at table].pick; -mark From mark at purdue.edu Fri Jun 18 04:21:31 2010 From: mark at purdue.edu (Mark Senn) Date: Fri, 18 Jun 2010 07:21:31 -0400 Subject: [Purdue-pm] June 2010 Perl 6 available Message-ID: <15018.1276860091@pier.ecn.purdue.edu> Purdue Perl Mongers, I've been using Rakudo Perl #29 (Perl 6) at home and am able to write complete programs with it. I plan to get #30 this weekend. -mark >Date: Fri, 18 Jun 2010 01:29:11 +0200 >Subject: Announce: Rakudo Perl 6 development release #30 ("Kiev") >From: =?ISO-8859-1?Q?Carl_M=E4sak?= >To: Perl6 , perl6-compiler at perl.org, > perl6-announce at perl.org, perl6-users > >On behalf of the Rakudo development team, I'm pleased to announce the >June 2010 development release of Rakudo Perl #30 "Kiev". Rakudo is an >implementation of Perl 6 on the Parrot Virtual Machine (see >). The tarball for the June 2010 release is >available from . > >Rakudo Perl follows a monthly release cycle, with each release named >after a Perl Mongers group. This release is named after the Perl >Mongers from the beautiful Ukrainian capital, Kiev. They recently >helped organize and participated in the Perl Mova + YAPC::Russia >conference, the ?????? (hackathon) of which was a particular success >for Rakudo. All those who joined the Rakudo hacking - from Kiev and >further afield - contributed spec tests as well as patches to Rakudo, >allowing various RT tickets to be closed, and making this month's >release better. ?????! > >Some of the specific changes and improvements occurring with this >release include: > >* Rakudo now uses immutable iterators internally, and generally hides >their existence from programmers. Many more things are now evaluated >lazily. > >* Backtraces no longer report routines from Parrot internals. This >used to be the case in the Rakudo alpha branch as well, but this time >they are also very pleasant to look at. > >* Match objects now act like real hashes and arrays. > >* Regexes can now interpolate variables. > >* Hash and array slicing has been improved. > >* The REPL shell now prints results, even when not explicitly asked to >print them, thus respecting the "P" part of "REPL". > >* Rakudo now passes 33,378 spectests. We estimate that there are about >39,900 tests in the test suite, so Rakudo passes about 83% of all >tests. > >For a more detailed list of changes see "docs/ChangeLog". > >The development team thanks all of our contributors and sponsors for >making Rakudo Perl possible, as well as those people who worked on >parrot, the Perl 6 test suite and the specification. > >The following people contributed to this release: >Patrick R. Michaud, Moritz Lenz, Jonathan Worthington, Solomon Foster, >Patrick Abi Salloum, Carl M?sak, Martin Berends, Will "Coke" Coleda, >Vyacheslav Matjukhin, snarkyboojum, sorear, smashz, Jimmy Zhuo, >Jonathan "Duke" Leto, Maxim Yemelyanov, St?phane Payrard, Gerd >Pokorra, cognominal, Bruce Keeler, ?var Arnfj?r? Bjarmason, >Shrivatsan, Hongwen Qiu, quester, Alexey Grebenschikov, Timothy Totten > >If you would like to contribute, see , >ask on the perl6-compiler at perl.org mailing list, or ask on IRC #perl6 >on freenode. > >The next release of Rakudo (#31) is scheduled for July 22, 2010. A >list of the other planned release dates and code names for 2010 is >available in the "docs/release_guide.pod" file. In general, Rakudo >development releases are scheduled to occur two days after each Parrot >monthly release. Parrot releases the third Tuesday of each month. > >Have fun! From gizmo at purdue.edu Fri Jun 18 06:51:09 2010 From: gizmo at purdue.edu (Joe Kline) Date: Fri, 18 Jun 2010 09:51:09 -0400 Subject: [Purdue-pm] YAPC::NA 2010 Message-ID: <4C1B79CD.1060206@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I think I forgot to mention I'll be at YAPC::NA next week. I'm still figuring out which talks I'll be going to so if you have one that sounds interesting to you let me know. joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkwbec0ACgkQb0mzA2gRTpmuNgCfYWiy2o4hW1L5syZ7fpXvj0g3 SScAnjYw3QplVQq8xHaH9Um8rO+6xnZ+ =BaGH -----END PGP SIGNATURE-----