From: ahoward Date: 2003-01-28T10:19:26+09:00 Subject: Re: Parsing: x = y || raise "error" On Tue, 28 Jan 2003, Gavin Sinclair wrote: > I more or less commonly use the following idiom (taken from recent > code): > > dir = ARGV.shift || raise "Require directory argument" > > Then I find that it fails: > > /home/gavin/bin/ckcr:3: parse error > /home/gavin/bin/ckcr:3: warning: useless use of a literal in void context > > This fixes it: > > dir = ARGV.shift || raise("Require directory argument") > > Can anyone explain why the parentheses are required? Not a critical > error or anything. I've just always wanted to know but been afraid to > ask. || binds more tightly that (). so dir = ARGV.shift || raise "Require directory argument" is like saying dir = (ARGV.shift || raise) "Require directory argument" you could say dir = ARGV.shift or raise "Require directory argument" but that is like (dir = ARGV.shift) or raise "Require directory argument" because = binds more tightly that 'or' personally i like dir = (ARGV.shift or raise "Require directory argument") because it is visually clear that dir will be 'one of the things in the parens' and it allows poetry mode methods and plain text booleans. -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================