Professional Web Applications Themes

why can't I use $3somevar for global variable in ruby 1.8.0? - Ruby

Hi, I'm new to Ruby programming and I just upgraded from 1.6.8 to 1.8.0 preview3. I noticed that I can no longer define global variables like $3somevar (an example of the error I get is attached below). Ruby 1.8 seems to complain about the 3 following the $ where it was perfectly fine with it in 1.6.8. Is there a reason for this? Thanks. Regards, Donglai ------------------------------------------------------------ %ruby example.rb example.rb:1: warning: useless use of a variable in void context example.rb:1: syntax error $3somevar = "whatever" ^...

  1. #1

    Default why can't I use $3somevar for global variable in ruby 1.8.0?

    Hi, I'm new to Ruby programming and I just upgraded from 1.6.8 to 1.8.0
    preview3. I noticed that I can no longer define global variables like
    $3somevar (an example of the error I get is attached below). Ruby 1.8
    seems to complain about the 3 following the $ where it was perfectly
    fine with it in 1.6.8. Is there a reason for this? Thanks.

    Regards,
    Donglai

    ------------------------------------------------------------
    %ruby example.rb
    example.rb:1: warning: useless use of a variable in void context
    example.rb:1: syntax error
    $3somevar = "whatever"
    ^


    Donglai Gong Guest

  2. #2

    Default Re: why can't I use $3somevar for global variable in ruby 1.8.0?

    Hi,

    Daniel Carrera <dcarreramath.umd.edu> writes:
    > dcarrera ~ $ ruby -v
    > ruby 1.8.0 (2002-12-24) [sparc-solaris2.8]
    > dcarrera ~ $ irb
    > >> $3somevar = "whatever"
    > => "whatever"
    >
    >
    > What's the problem?
    Your ruby is too old.

    ChangeLog says:

    Tue Apr 8 11:49:31 2003 Yukihiro Matsumoto <matzruby-lang.org>

    (snip)

    * p.y (yylex): disallow global variables like "$1ve".
    [ruby-core:00945]

    --
    eban

    WATANABE Hirofumi Guest

  3. #3

    Default Re: why can't I use $3somevar for global variable in ruby 1.8.0?

    There must be a reason why $1ve is disallowed in 1.8.0 but I can't
    imagine why. Anyone knows the reason behind this change?

    Donglai

    On Friday, Jun 27, 2003, at 00:23 US/Eastern, WATANABE Hirofumi wrote:
    > Hi,
    >
    > Daniel Carrera <dcarreramath.umd.edu> writes:
    >
    >> dcarrera ~ $ ruby -v
    >> ruby 1.8.0 (2002-12-24) [sparc-solaris2.8]
    >> dcarrera ~ $ irb
    >>>> $3somevar = "whatever"
    >> => "whatever"
    >>
    >>
    >> What's the problem?
    >
    > Your ruby is too old.
    >
    > ChangeLog says:
    >
    > Tue Apr 8 11:49:31 2003 Yukihiro Matsumoto <matzruby-lang.org>
    >
    > (snip)
    >
    > * p.y (yylex): disallow global variables like "$1ve".
    > [ruby-core:00945]
    >
    > --
    > eban
    >

    Donglai Gong Guest

  4. #4

    Default Re: why can't I use $3somevar for global variable in ruby 1.8.0?

    Hi,

    Donglai Gong <donglaiMIT.EDU> writes:

    > There must be a reason why $1ve is disallowed in 1.8.0 but I can't
    > imagine why. Anyone knows the reason behind this change?
    [ruby-core:00945]
    [ruby-core:00949]

    --
    eban



    WATANABE Hirofumi Guest

  5. #5

    Default Re: why can't I use $3somevar for global variable in ruby 1.8.0?


    "WATANABE Hirofumi" <ebanos.rim.or.jp> schrieb im Newsbeitrag
    news:4518-Fri27Jun2003134257+0900-ebanos.rim.or.jp...
    > Hi,
    >
    > Donglai Gong <donglaiMIT.EDU> writes:
    >
    >
    > > There must be a reason why $1ve is disallowed in 1.8.0 but I can't
    > > imagine why. Anyone knows the reason behind this change?
    In most programming languages identifiers may not start with a digit.
    Same for Ruby. You can't do class 3Foo; end either. Simply get used to
    not start identifiers with numbers. The change just makes identifiers for
    global variables consistent with other identifiers.

    In Ruby there's the additional point that $1, $2 etc. are used for holding
    the contents of regexp sub pattern matches.

    robert

    Robert Klemme Guest

  6. #6

    Default Re: why can't I use $3somevar for global variable in ruby 1.8.0?

    ----- Original Message -----
    From: "Robert Klemme" <bob.newsgmx.net>
    Newsgroups: comp.lang.ruby
    To: "ruby-talk ML" <ruby-talkruby-lang.org>
    Sent: Friday, June 27, 2003 3:03 AM
    Subject: Re: why can't I use $3somevar for global variable in ruby 1.8.0?

    >
    > "WATANABE Hirofumi" <ebanos.rim.or.jp> schrieb im Newsbeitrag
    > news:4518-Fri27Jun2003134257+0900-ebanos.rim.or.jp...
    > > Hi,
    > >
    > > Donglai Gong <donglaiMIT.EDU> writes:
    > >
    > >
    > > > There must be a reason why $1ve is disallowed in 1.8.0 but I can't
    > > > imagine why. Anyone knows the reason behind this change?
    >
    > In most programming languages identifiers may not start with a digit.
    > Same for Ruby. You can't do class 3Foo; end either. Simply get used to
    > not start identifiers with numbers. The change just makes identifiers for
    > global variables consistent with other identifiers.
    But $3var doesn't start with a 3; it starts with a $.

    This is historical Ruby behavior, but it seems to be
    changing; I now see that 3var is also disallowed. (I
    don't *think* it was in the past.)
    > In Ruby there's the additional point that $1, $2 etc. are used for holding
    > the contents of regexp sub pattern matches.
    This is probably related to the change. I don't read
    ruby-core, so I can't say for sure.

    Hal

    --
    Hal Fulton
    [email]hal9000hypermetrics.com[/email]



    Hal E. Fulton Guest

  7. #7

    Default Re: why can't I use $3somevar for global variable in ruby 1.8.0?

    On Mon, Jun 30, 2003 at 06:35:58PM +0900, Robert Klemme wrote:
    > > But $3var doesn't start with a 3; it starts with a $.
    >
    > Hmm, you can call me picky, but I'd say it does start with a digit.
    > Here's why: I regards the "$" not the first character of the identifier
    > but a namespace tag for the global variables namespace. Similarly there
    > is "" as tag for the namespace "variables of the current instance".
    The character definitely _is_ part of the name. For example, try doing
    instance_variable_get on :foo instead of :foo

    Regards,

    Brian.

    Brian Candler Guest

Similar Threads

  1. global variable
    By Ben in forum PHP Development
    Replies: 2
    Last Post: May 19th, 10:00 PM
  2. global variable problem
    By david taylor in forum Macromedia Director Basics
    Replies: 1
    Last Post: November 14th, 01:59 PM
  3. [Ruby] GUI toolkit supporting Global IME?
    By Walter Cazzola in forum Ruby
    Replies: 0
    Last Post: October 10th, 10:17 AM
  4. Global variable and tempo
    By Ned in forum Macromedia Director Lingo
    Replies: 0
    Last Post: September 23rd, 08:54 PM
  5. Replies: 0
    Last Post: July 17th, 09:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139