Bug? (1.8.0)

Ruby 1.8.0 on win32:

1: ruby -e ‘p “#abc#def#”.gsub(/#$/, " ")’
-e:1: unterminated string meets end of file
-e:1: syntax error

2: ruby -e ‘p “#abc#def#”.gsub(/#/, " ")’
" abc def "

3: ruby -e ‘p “#abc#def#”.gsub(/#$/, " ")’
"#abc#def "

What’s wrong with the first one? I expected the first one to
behave like the third one.

gegroet,
Erik V.

Erik Veenstra wrote:

Ruby 1.8.0 on win32:

1: ruby -e ‘p “#abc#def#”.gsub(/#$/, " ")’
-e:1: unterminated string meets end of file
-e:1: syntax error

2: ruby -e ‘p “#abc#def#”.gsub(/#/, " ")’
" abc def "

3: ruby -e ‘p “#abc#def#”.gsub(/#$/, " ")’
"#abc#def "

What’s wrong with the first one? I expected the first one to
behave like the third one.

That’s interesting and syntactically subtle.

Here are the facts the explain this:

  1. Regexes can have interpolated values just like strings
  2. When an expression is a single name and that name starts
    with a special symbol like @, @@, or $, the braces can
    be omitted
  3. $/ is one of the ugly special variables
  4. So #$/ is interpreted as inserting the value of $/ into
    the regex
  5. The regex then consumes the rest of the line
  6. The interpreter apparently does not distinguish between
    strings and regular expressions when reporting that
    something is unterminated.

If there is a bug at all, it is #6 (misleading error message).

Hal

That’s interesting and syntactically subtle.

Here are the facts the explain this:

  1. Regexes can have interpolated values just like strings
  2. When an expression is a single name and that name starts
    with a special symbol like @, @@, or $, the braces can
    be omitted
  3. $/ is one of the ugly special variables
  4. So #$/ is interpreted as inserting the value of $/ into
    the regex
  5. The regex then consumes the rest of the line
  6. The interpreter apparently does not distinguish between
    strings and regular expressions when reporting that
    something is unterminated.

I’m not sure I followed that. Can you explain to me how 1-6 explain
this?:

p “#$”
SyntaxError: compile error
(irb):22: unterminated string meets end of file
from (irb):22

···


Daniel Carrera, Math PhD student at UMD. PGP KeyID: 9AF77A88
.-“~~~”-.
/ O O \ ATTENTION ALL PASCAL USERS:
: s :
\ _/ / To commemorate the anniversary of Blaise Pascal’s
`-.
_.-’ birth (today) all your programs will run at half speed.

Wow, I’d’ve never gotten that one, and I’m usually pretty good at
catching stuff like that.

I don’t think I’d call it a bug, but to my eyes, #2 seems like a
design “whodathunkit”. Mind you, I’m really quite against poetry
mode and a lot of other seemingly “magic” things the interpreter does
(if I want interpolation in a string, I’ll tell it so, in this case).

···

— Hal Fulton hal9000@hypermetrics.com wrote:

Erik Veenstra wrote:

Ruby 1.8.0 on win32:

1: ruby -e ‘p “#abc#def#”.gsub(/#$/, " ")’
-e:1: unterminated string meets end of file
-e:1: syntax error

2: ruby -e ‘p “#abc#def#”.gsub(/#/, " ")’
" abc def "

3: ruby -e ‘p “#abc#def#”.gsub(/#$/, " ")’
"#abc#def "

What’s wrong with the first one? I expected the first one to
behave like the third one.

That’s interesting and syntactically subtle.

Here are the facts the explain this:

  1. Regexes can have interpolated values just like strings
  2. When an expression is a single name and that name starts
    with a special symbol like @, @@, or $, the braces can
    be omitted
  3. $/ is one of the ugly special variables
  4. So #$/ is interpreted as inserting the value of $/ into
    the regex
  5. The regex then consumes the rest of the line
  6. The interpreter apparently does not distinguish between
    strings and regular expressions when reporting that
    something is unterminated.

If there is a bug at all, it is #6 (misleading error message).


Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Daniel Carrera wrote:

That’s interesting and syntactically subtle.

Here are the facts the explain this:

  1. Regexes can have interpolated values just like strings
  2. When an expression is a single name and that name starts
    with a special symbol like @, @@, or $, the braces can
    be omitted
  3. $/ is one of the ugly special variables
  4. So #$/ is interpreted as inserting the value of $/ into
    the regex
  5. The regex then consumes the rest of the line
  6. The interpreter apparently does not distinguish between
    strings and regular expressions when reporting that
    something is unterminated.

I’m not sure I followed that. Can you explain to me how 1-6 explain
this?:

p “#$”

SyntaxError: compile error
(irb):22: unterminated string meets end of file
from (irb):22

Isn’t $" also a special variable?

Hal

p “#$”

SyntaxError: compile error
(irb):22: unterminated string meets end of file
from (irb):22

Isn’t $" also a special variable?

Okay, I would suggest the following behaviour would make most sense:

p “#$” => ‘#$’
p “#{$”}" => contents of $"

Thoughts?

···


Daniel Carrera, Math PhD student at UMD. PGP KeyID: 9AF77A88
.-“~~~”-.
/ O O \ ATTENTION ALL PASCAL USERS:
: s :
\ _/ / To commemorate the anniversary of Blaise Pascal’s
`-.
_.-’ birth (today) all your programs will run at half speed.

Daniel Carrera wrote:

p “#$”

SyntaxError: compile error
(irb):22: unterminated string meets end of file
from (irb):22

Isn’t $" also a special variable?

Okay, I would suggest the following behaviour would make most sense:

p “#$” => ‘#$’
p “#{$”}" => contents of $"

Thoughts?

I’d rather just see the ugly variables go away.
The Ruby Way intentionally avoided their use. There are a few
in there, but most are in code contributed by others.

Rather than change the parser, I’d suggest that the nuby should
be aware that #$ will interpolate a global variable if the rest
of the variable name is valid.

I’ve been playing in irb and this is making my head hurt.

Personally I’d say: If you want a literal #$, then either escape
the $ or use a non-interpolating string.

Hal

Rene van Bevern wrote:

can “The Ruby Way” be found online, like the pickaxe?

Sure, here’s one link:

I think you may have a free subscription to safari.oreilly.com for 14
days and get an electronic copy from there. You may need to pay after
that time, anyway…

···

il Sat, 30 Aug 2003 11:53:58 +0200, Rene van Bevern rvb@rvb.dyndns.org ha scritto::

can “The Ruby Way” be found online, like the pickaxe? (although i have
the pickaxe in “bookform”).

Lyle Johnson wrote:

Rene van Bevern wrote:

can “The Ruby Way” be found online, like the pickaxe?

Sure, here’s one link:

http://www.amazon.com/exec/obidos/ASIN/0672320835/102-1067493-2732943

:slight_smile: No, surely he means the full text.

The Ruby Way is not open-sourced, so there’s no
free electronic copy.

I’ve heard that safari.net has it – downloadable
for a fee of some kind.

Hal

:slight_smile: No, surely he means the full text.

right :wink: … and i refuse to buy at amazon.

I’ve heard that safari.net has it – downloadable
for a fee of some kind.

downloading for a fee? … no thanks, then i will just buy your book on
paper ;> … i prefer paperbooks, although they are not grep-able
i have just read the sample pages … looks good :wink:

Rene
···

On Sun, 31 Aug 2003 02:27:14 +0900, Hal Fulton hal9000@hypermetrics.com wrote: