From gizmo at purdue.edu Mon Mar 2 13:23:29 2009 From: gizmo at purdue.edu (Joe Kline) Date: Mon, 02 Mar 2009 16:23:29 -0500 Subject: [Purdue-pm] perl6 rpn calculator Message-ID: <49AC4E51.8040904@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 That's some dense code. http://use.perl.org/~pmichaud/journal/38580 joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org iD8DBQFJrE5Qb0mzA2gRTpkRAh2kAJwKH7Tgm40iJVIv96hhJzbiR5Z5UQCbBzF+ MO38AbkzR8imDjeRlzIkkEE= =RcZW -----END PGP SIGNATURE----- From gribskov at purdue.edu Wed Mar 4 05:40:51 2009 From: gribskov at purdue.edu (Michael Gribskov) Date: Wed, 04 Mar 2009 08:40:51 -0500 Subject: [Purdue-pm] perl6 rpn calculator In-Reply-To: <49AC4E51.8040904@purdue.edu> References: <49AC4E51.8040904@purdue.edu> Message-ID: <49AE84E3.50300@purdue.edu> A good example of why shorter isn't the same as better. the original version, while still somewhat cryptic, at least makes it explicit that the operation work on the stack, and where the operands are obtained. IMO the original is much better (more maintainable) Joe Kline wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > That's some dense code. > > http://use.perl.org/~pmichaud/journal/38580 > > joe > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.5 (GNU/Linux) > Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org > > iD8DBQFJrE5Qb0mzA2gRTpkRAh2kAJwKH7Tgm40iJVIv96hhJzbiR5Z5UQCbBzF+ > MO38AbkzR8imDjeRlzIkkEE= > =RcZW > -----END PGP SIGNATURE----- > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > http://mail.pm.org/mailman/listinfo/purdue-pm > -- Michael Gribskov - gribskov at purdue.edu Professor of Biological Sciences and Computer Science Purdue University Lilly Hall of Life Sciences 915 W. State Street West Lafayette IN 47907-2054 voice: 765.494.6933 fax: 765.496-1189 email: gribskov at purdue.edu Calendar: http://www.google.com/calendar/embed?src=gribskov%40purdue.edu&ctz=America/New_York From westerman at purdue.edu Fri Mar 13 12:16:16 2009 From: westerman at purdue.edu (Rick Westerman) Date: Fri, 13 Mar 2009 15:16:16 -0400 Subject: [Purdue-pm] Spring break -- shall we have a meeting? Message-ID: <49BAB100.2000503@purdue.edu> I know that it is short notice but (a) we don't have any speakers --- well, I could come up with something but it will not be perl related and (b) it is spring break -- not that the break really affects the non-students. But perhaps we should cancel the March meeting. Anyone in favor of having the meeting. And be forewarned that by voting in favor of the meeting then I'll expect you to come with a talk. :-) -- Rick From gizmo at purdue.edu Fri Mar 13 12:29:32 2009 From: gizmo at purdue.edu (Joe Kline) Date: Fri, 13 Mar 2009 15:29:32 -0400 Subject: [Purdue-pm] Spring break -- shall we have a meeting? In-Reply-To: <49BAB100.2000503@purdue.edu> References: <49BAB100.2000503@purdue.edu> Message-ID: <49BAB41C.4010103@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I'd be more inclined to have a meeting than not. If need be I could make something up to talk about...probably perl related. joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org iD8DBQFJurQbb0mzA2gRTpkRAq/kAJ9fkF/1a3M8AbNwcES8WFVSb1RN+QCfWSDT 5ni1qLxxy/lPFiRfI+tUXlQ= =iczB -----END PGP SIGNATURE----- From jacoby at purdue.edu Fri Mar 13 12:33:02 2009 From: jacoby at purdue.edu (Dave Jacoby) Date: Fri, 13 Mar 2009 15:33:02 -0400 Subject: [Purdue-pm] [Fwd: Re: Spring break -- shall we have a meeting?] Message-ID: <49BAB4EE.4020507@purdue.edu> Because I sent it wrong.... (I've only been doing email for 20 years. You think I'd have a handle on it by now.) -- Dave Jacoby Address: WSLR S049 Genomics Core Programmer Mail: jacoby at purdue.edu Purdue University Jabber: jacoby at jabber.org Phone: hah! -------------- next part -------------- An embedded message was scrubbed... From: Dave Jacoby Subject: Re: [Purdue-pm] Spring break -- shall we have a meeting? Date: Fri, 13 Mar 2009 15:21:35 -0400 Size: 1298 URL: From westerman at purdue.edu Fri Mar 13 12:35:03 2009 From: westerman at purdue.edu (Rick Westerman) Date: Fri, 13 Mar 2009 15:35:03 -0400 Subject: [Purdue-pm] Mar meeting is a go. In-Reply-To: <49BAB41C.4010103@purdue.edu> References: <49BAB100.2000503@purdue.edu> <49BAB41C.4010103@purdue.edu> Message-ID: <49BAB567.4000705@purdue.edu> OK, Joe is going to give a talk. Dave is going to give a talk. I'll give a talk. So the March meeting is a go. This does not prevent the rest of you of popping up with a talk. Otherwise we will have a rather light meeting. See you Tuesday! -- 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 Fri Mar 13 13:09:07 2009 From: mark at ecn.purdue.edu (Mark Senn) Date: Fri, 13 Mar 2009 16:09:07 -0400 Subject: [Purdue-pm] Mar meeting is a go. In-Reply-To: <49BAB567.4000705@purdue.edu> References: <49BAB100.2000503@purdue.edu> <49BAB41C.4010103@purdue.edu> <49BAB567.4000705@purdue.edu> Message-ID: <1365.1236974947@pier.ecn.purdue.edu> If we don't have enough content I'll give a talk about a project I'm working on: controlling a LEGO Mindstorms NXT robot car over the Internet...this will be a project that I'll be doing stepwise improvements on for the rest of the calendar year or so To those of you with Purdue Perl Mongers book please bring them to the meeting if you are done with them...don't forgot to work on your book review if you laid you'd do one -mark From mark at purdue.edu Fri Mar 20 07:00:01 2009 From: mark at purdue.edu (Mark Senn) Date: Fri, 20 Mar 2009 10:00:01 -0400 Subject: [Purdue-pm] Parrot 1.0.0 released, Perl 6 Message-ID: <29997.1237557601@pier.ecn.purdue.edu> Purdue Perl Mongers mailing list, >From http://www.parrot.org/: Parrot is a virtual machine designed to efficiently compile and execute bytecode for dynamic languages. Parrot currently hosts a variety of language implementations in various stages of completion, including Tcl, Javascript, Ruby, Lua, Scheme, PHP, Python, Perl 6, APL, and a .NET bytecode translator. Parrot 1.0.0 "Haru Tatsu" Released! Maybe web browsers will eventually contain Parrot virtual machines. >From http://rakudo.org/: Rakudo Perl 6, or just Rakudo, is an implementation of the Perl 6 specification that will run on the Parrot virtual machine. Perl 6 is a programming language standard. Unlike previous versions of Perl, it will have multiple implementations. >From http://rakudo.org/how-to-get-rakudo: Because Rakudo is under rapid development, we generally recommend downloading Rakudo directly from github and building from there: $ git clone git://github.com/rakudo/rakudo.git Rakudo is under development. It "feels" like Perl 5 but has many improvements. Rakudo is experimental and incomplete ---do not get it thinking that you'll be able to use it for production programs. Go to http://mail.szabgab.com/mailman/listinfo/perl6 to sign up for the perl 6 Tricks and Treats newsletter. A sample message is below. See http://pm.purdue.org for information on the Purdue Perl Mongers Perl users group. Mark Senn, Purdue Perl Mongers >Date: Fri, 20 Mar 2009 11:17:24 +0200 From: Gabor Szabo >To: perl6 at szabgab.com >Subject: [Perl6 Tricks and Treats] Looping over a list of values one at a > time, two at a time and more >Sender: perl6-bounces at szabgab.com >X-PerlMx-Virus-Scanned: Yes >X-ECN-MailServer-VirusScanned: by amavisd-new >X-ECN-MailServer-Origination: mailhub245.itcs.purdue.edu [128.210.5.245] >X-ECN-MailServer-SpamScanAdvice: DoNotScan > >==== Welcome back to the Perl 6 Tricks and Treats ==== > >? ?The list does not have an archive, past issues can be >? ?found on my web site: > >? ?http://szabgab.com/perl6.html > >? ?Before the upcoming events and the actual content let >? ?me congratulate the Parrot development team on the release >? ?of Parrot 1.0. > >? ?Having a declared stable releases is a huge psychological >? ?milestone. I think now we'll be able to see many more people >? ?starting to take Parrot seriously. This will make a positive >? ?effect on Perl 6 and Rakudo as well. > >? ?As for myself, I should get back to try to improve the >? ?Parrot plugin of Padre so people who write code for Parrot >? ?could use it as their IDE. > > >==== Upcoming Events ==== > >== Nordic Perl Workshop in Oslo, Norway == > >? ?16-17 April. ?It will have lots of Perl 6 content. > >? ?http://www.perlworkshop.no/npw2009/talks > >? ?Register on the web site. > >== Hands-on Perl 6 Training in Oslo, Norway == > >? 18 April. Free but registration required. > >? http://szabgab.com/blog/2009/03/1235863222.html > >? If you are interested in participating in this course >? please contact me by e-mail. > >== Perl 6 Hackathon in Oslo, Norway == > >? ?18-20 April, Free > >? ?http://www.perlfoundation.org/perl6/index.cgi?oslo_perl_6_hackaton_2009 > >? ?If you are interested, please sign up on the wiki. > >== Test Automation Training in ?Oslo, Norway == > >? ?21-24 April, Corporate rate, Using Perl 5 and PHP > >? ?http://szabgab.com/blog/2009/01/1232302278.html > >? ?If you are interested in participating in this course >? ?please contact me by e-mail. > >== YAPC::NA Pittsburgh, USA == > >? ?22-24 June > >? ?http://yapc10.org/ > >? ?Register on the web site. > > >== YAPC::EU Lisbon, Portugal == > >? ?3-5 August > >? ?http://yapceurope2009.org/ye2009/ > >? ?Register on the web site. > >==== Looping over a list of values one at a time, two at a time and more ==== > > >In Perl 6 the standard way to iterate over the elements of >a list or an array is by using the "for" statement. >A simple version of it looks like this: > > >? ?use v6; > >? ?my @fellows = ; >? ?for @fellows -> $name { >? ? ? ?say $name; >? ?} > >This will print out the three values one under the other. > >As an explanation syntax: > >@fellows is an array with 3 elements in it. > >The loop variable ($name) in the above case is automatically >declared in the loop so one does not need to declare it using "my" >and it is still not global. It is scoped to the block of the loop. > >== Looping over keys of a hash == > >The same way we can loop over keys of a hash - after >fetching them using the "keys" function. > >? ?use v6; > >? ?my %phone = ( >? ? ? ?"Foo" => 123, >? ? ? ?"Bar" => 456, >? ?); > >? ?for keys %phone -> $name { >? ? ? ?say "$name {%phone{$name}}"; >? ?} > >The declaration of hashes in Perl 6 is similar to that in >Perl 5 but when access individual elements in the hash it >now keeps the % prefix. Thus the value of the key "Foo" will >be ?%phone{"Foo"}. Similarly if $name contains "Foo" we can >use the %phone{$name} expression to get back the relevant value. > >As mentioned earlier the string interpolation of hashes requires >curly braces around the statement. > > >== Loop over every two elements in a list == > >So what if we have an array of pairs of values and >and we would like to go over all the pairs. >We could do that by assigning the array to a hash >and then going over the keys just in the next example: > >? ?use v6; > >? ?my @phones = ; >? ?my %temp = @phones; >? ?for %temp.keys -> $name { >? ? ? ?say "$name {%temp{$name}}"; >? ?} > >Not only is the use of the temporary hash disturbing but it >actually looses the original order of the pairs. >Sometime the order is important. > > >The nice thing about the for loop in Perl 6 is that it also allows >the looping over groups of values. So in or case we can go over >every two elements preserving the order: > >? ?use v6; > >? ?my @phones = ; >? ?for @phones -> $name, $number { >? ? ? ?say "$name ?$number"; >? ?} > >== Going over elements of a hash == > >If you'd like to go over all the pairs in a hash >you can use "for": > >? ?use v6; > >? ?my %phone = ( >? ? ? ?"Foo" => 123, >? ? ? ?"Bar" => 456, >? ?); > >? ?for %phone -> $key, $value { >? ? ? ?say "$key $value"; >? ?} > >That still does not indicate any specific order >(similarly to "each" in Perl 5) but now both the key >and the value are in simple scalars. > > >== Looping over any number of elements == > > >You can also iterate over any number of elements: > >Let's say we just extracted the results of the Spanish Liga football >games from the soccer website http://soccernet.espn.go.com/ . >Those come in groups of 4 values: > >home team, >score of home team >score of guest team >guest team > > >? ?use v6; > >? ?my @scores = < >? ? ? ?Valencia ?1 1 Recreativo_Huelva >? ? ? ?Athletic_Bilbao 2 5 Real_Madrid >? ? ? ?Malaga ? ? ? ? ?2 ?2 ? ?Sevilla_FC >? ? ? ?Sporting_Gijon ?3 2 Deportivo_La_Coruna >? ? ? ?Valladolid ? ? ?1 ?0 ? ?Getafe >? ? ? ?Real_Betis ? ? ?0 ?0 ? ?Osasuna >? ? ? ?Racing_Santander ? ? ? ?5 ?0 ? ?Numancia >? ? ? ?Espanyol ? ? ? ?3 ?3 ? ?Mallorca >? ? ? ?Atletico_Madrid ? ? ? ? 3 ?2 ? ?Villarreal >? ? ? ?Almeria ? ? ? ? 0 ?2 ? ?Barcelona >? ?>; > >We can loop over the values using a for statement with >4 scalar variables: > >? ?for @scores -> $home, $home_score, $guest_score, $guest { >? ? ? ?say "$home $guest $home_score : $guest_score"; >? ?} > >== Missing values == > >One should ask the question what happens if the list runs out of >values in the middle, of a multi-value iteration? That is, >what happens to the follow loop? > >? ?use v6; > >? ?for (1, 2, 3, 4, 5) -> $x, $y { >? ? ? ?say "$x $y"; >? ?} > >In this case Rakudo throws an exception when it finds out it >does not have enough values for the last iteration. It will look >like this, (with a bunch of trace information afterwards). > >? ?1 2 >? ?3 4 >? ?StopIteration > > >In order to avoid the exception we could tell the loop that the second and >subsequent values are optional by adding a question mark after the variable > >? ?use v6; > >? ?for (1, 2, 3, 4, 5) -> $x, $y? { >? ? ? ? ? ?say "$x $y"; >? ?} > >Unfortunately as of today this latter construct does not work yet. >So if you have some tuits, this might be a good thing to add. > >== Iterating over more than one array in parallel == > >In the last example I'd like to show a totally different case. >What if you have two (or more) array you'd like to combine somehow? >How can you go over the elements of two arrays in parallel? > >? ?use v6; > >? ?my @chars ? = ; >? ?my @numbers = <1 2 3>; > >? ?for @chars Z @numbers -> $letter, $number { >? ? ? ?say "$letter $number"; >? ?} > >The Z infix operator version of the zip function allows >the parallel use of two lists. > >Or that of more: > >? ?use v6; > >? ?my @operator ?= <+ - *>; >? ?my @left ? ? ?= <1 2 3>; >? ?my @right ? ? = <7 8 9>; > >? ?for @left Z @operator Z @right -> $a, $o, $b { >? ? ? ?say "$a $o $b"; >? ?} > > >== Other Resource == > >For further details on the "for" statement and the zip >function you can take a look at the specification >S04-control.pod >http://svn.pugscode.org/pugs/docs/Perl6/Spec/S04-control.pod > > >==== Getting Perl 6 ==== > >I am using and recommending the Rakudo implementation >of ?Perl 6 that runs on top of the Parrot Virtual Machine. > >See the up-to-date instructions on how to get them >on the Rakudo web site: > >http://rakudo.org/how-to-get-rakudo > >That's it 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/ > >Previous issues of this newsletter can be found on >http://szabgab.com/perl6.html > >==== Copyright ==== > >Perl 6 Tricks and Treats and associated text is >Copyright 2009 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 >Phone: +972-54-4624648 >_______________________________________________ >Perl6 mailing list >Perl6 at szabgab.com >http://mail.szabgab.com/mailman/listinfo/perl6