From rpjday at crashcourse.ca Mon Jan 5 04:41:33 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Mon, 5 Jan 2009 07:41:33 -0500 (EST) Subject: [kw-pm] conditionals and the comma operator Message-ID: i'm sure i'm about to embarrass myself with how much i've forgotten my perl, but i'm reading a perl program and, early on, it sets default command line args thusly: ================================ my ($input,$vm_output,$rfs_output) = @ARGV; $vm_output = cwd . '/vmlinux', if (! defined ($vm_output) || $vm_output eq ''); $rfs_output = cwd . '/initramfs.cpio.gz', if (! defined ($rfs_output) || $rfs_output eq ''); ... ================================ i know what that early processing is meant to do -- assign default values to $vm_output and $rfs_output unless the user has specified those values on the command line. but how is that being done above? i vaguely recall that there was a perl idiom that involved the comma operator to do something like that, but i don't see how that's being done above. can someone refresh my memory? thanks. rday -- ======================================================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry: Have classroom, will lecture. http://crashcourse.ca Waterloo, Ontario, CANADA ======================================================================== From fulko.hew at gmail.com Mon Jan 5 05:04:28 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Mon, 5 Jan 2009 08:04:28 -0500 Subject: [kw-pm] conditionals and the comma operator In-Reply-To: References: Message-ID: <8204a4fe0901050504v6bc64bc7q183b588e83834ff1@mail.gmail.com> On Mon, Jan 5, 2009 at 7:41 AM, Robert P. J. Day wrote: > > i'm sure i'm about to embarrass myself with how much i've forgotten > my perl, but i'm reading a perl program and, early on, it sets default > command line args thusly: > > ================================ > my ($input,$vm_output,$rfs_output) = @ARGV; > > $vm_output = cwd . '/vmlinux', > if (! defined ($vm_output) || $vm_output eq ''); > $rfs_output = cwd . '/initramfs.cpio.gz', > if (! defined ($rfs_output) || $rfs_output eq ''); > ... > ================================ > > i know what that early processing is meant to do -- assign default > values to $vm_output and $rfs_output unless the user has specified > those values on the command line. but how is that being done above? > > i vaguely recall that there was a perl idiom that involved the comma > operator to do something like that, but i don't see how that's being > done above. can someone refresh my memory? thanks. I can't help on your comma question, but I'd say in the above case... that the comma is irrelevant . From rpjday at crashcourse.ca Mon Jan 5 06:39:16 2009 From: rpjday at crashcourse.ca (Robert P. J. Day) Date: Mon, 5 Jan 2009 09:39:16 -0500 (EST) Subject: [kw-pm] conditionals and the comma operator In-Reply-To: <8204a4fe0901050504v6bc64bc7q183b588e83834ff1@mail.gmail.com> References: <8204a4fe0901050504v6bc64bc7q183b588e83834ff1@mail.gmail.com> Message-ID: On Mon, 5 Jan 2009, Fulko Hew wrote: > On Mon, Jan 5, 2009 at 7:41 AM, Robert P. J. Day wrote: > > > > i'm sure i'm about to embarrass myself with how much i've forgotten > > my perl, but i'm reading a perl program and, early on, it sets default > > command line args thusly: > > > > ================================ > > my ($input,$vm_output,$rfs_output) = @ARGV; > > > > $vm_output = cwd . '/vmlinux', > > if (! defined ($vm_output) || $vm_output eq ''); > > $rfs_output = cwd . '/initramfs.cpio.gz', > > if (! defined ($rfs_output) || $rfs_output eq ''); > > ... > > ================================ > > > > i know what that early processing is meant to do -- assign default > > values to $vm_output and $rfs_output unless the user has specified > > those values on the command line. but how is that being done above? > > > > i vaguely recall that there was a perl idiom that involved the comma > > operator to do something like that, but i don't see how that's being > > done above. can someone refresh my memory? thanks. > > I can't help on your comma question, but I'd say in the above case... > that the comma is irrelevant ah, i remember the idiom that i was thinking of: $var = $var || new_value; as in (from my example above): $vm_output ||= cwd . '/vmlinux'; (the short form) isn't that the idiom? if the variable is set, it stays set to that value. if it's not set, it will be assigned the given value. am i remembering that right? rday -- ======================================================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry: Have classroom, will lecture. http://crashcourse.ca Waterloo, Ontario, CANADA ======================================================================== From ceeshek at gmail.com Mon Jan 5 08:56:25 2009 From: ceeshek at gmail.com (Cees Hek) Date: Mon, 5 Jan 2009 11:56:25 -0500 Subject: [kw-pm] conditionals and the comma operator In-Reply-To: References: <8204a4fe0901050504v6bc64bc7q183b588e83834ff1@mail.gmail.com> Message-ID: On Mon, Jan 5, 2009 at 9:39 AM, Robert P. J. Day wrote: > ah, i remember the idiom that i was thinking of: > > $var = $var || new_value; > > as in (from my example above): > > $vm_output ||= cwd . '/vmlinux'; (the short form) > > isn't that the idiom? if the variable is set, it stays set to that > value. if it's not set, it will be assigned the given value. am i > remembering that right? Hi Robert, That is a very common way of conditionally assigning a variable, but just make sure that 0 and "" are not valid values. $a = 0; $a ||= 1; That will set the value to 1, since 0 is a false value. perl 5.10 gives us a new conditional that takes this into consideration. The defined-or operator //. $a = 0; $a //= 1; It is equivalent to but much more concise than this: $a = 1 unless defined $a; Cheers, Cees From daniel at coder.com Fri Jan 9 15:21:18 2009 From: daniel at coder.com (Daniel R. Allen) Date: Fri, 9 Jan 2009 18:21:18 -0500 (EST) Subject: [kw-pm] No January Meeting Message-ID: January's kw-pm meeting isn't happening, because all our regular speakers are over-worked and under-compensated and striking and hungover. Also, we have fun stuff under wraps for February, which might include soldering and a special meeting day. More information forthcoming in the next few weeks. Meanwhile, if you have an idea for a talk you'd like to see, or a talk you'd like to give, please let us know (here or in the IRC channel, and optionally on the wiki; http://kw.pm.org/wiki/index.cgi?MeetingTopics ) -Daniel From abez at abez.ca Thu Jan 29 20:53:45 2009 From: abez at abez.ca (abez) Date: Thu, 29 Jan 2009 23:53:45 -0500 Subject: [kw-pm] The discussion about over-eager-evaluation Message-ID: <498287D9.9050803@abez.ca> xfsh and I were talking in the channel about this: Kinds of order of evaluation in programming languages: http://en.wikipedia.org/wiki/Eager_evaluation http://en.wikipedia.org/wiki/Lazy_evaluation They called "over-eager" evaluation "speculative evaluation" http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.48.8087 Abstract: In a parallel graph reduction system, speculative evaluation can increase parallelism by performing potentially useful computations before they are known to be necessary. Speculative computations may be coded explicitly in a program, or they may be scheduled implicitly by the reduction system as idle processors become available. A general approach to both kinds of speculation incurs a great deal of overhead that may outweigh the benefits of speculative evaluation for fine-grain speculative tasks. The basic principle of local speculation is to permanently bind all implicit speculative computations to the sparking processor. Should all local mandatory tasks become blocked, local speculation offers a lowcost alternative to task migration. Restricting speculation to the local processor simplifies the problems of speculative task management, and opens the door for fine-grain speculative tasks. Though there are fewer opportunities for local speculation than for more general speculation, local speculation can often make use of the same idle processor time that would normally trigger task migration. For distributed graph reduction systems, local speculation may prove to be a worthwhile, low-cost alternative to potentially expensive task migration. More possible papers on it: http://scholar.google.ca/scholar?q=Speculative+evaluation&hl=en&lr=&btnG=Search -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: