Professional Web Applications Themes

ruby fixnums - Ruby

Hello! As I have understood Ruby fixnums are passed by value and you can grab the value as an integer like: VALUE foo; int i = (int) (foo >> 1); Is there any way to get an explicit reference of the value of the fixnum in C, without allocating new space, or using a new integer pointer? I.e. what &RFLOAT(foo)->value does. Regards, -- University of Athens I bet the human brain Physics Department is a kludge --Marvin Minsky...

  1. #1

    Default ruby fixnums

    Hello!

    As I have understood Ruby fixnums are passed by value and
    you can grab the value as an integer like:

    VALUE foo;
    int i = (int) (foo >> 1);

    Is there any way to get an explicit reference of the
    value of the fixnum in C, without allocating new space, or using
    a new integer pointer?

    I.e. what &RFLOAT(foo)->value does.

    Regards,
    --
    University of Athens I bet the human brain
    Physics Department is a kludge --Marvin Minsky




    Elias Guest

  2. #2

    Default Re: ruby fixnums

    Elias Athanasopoulos wrote:
     

    Well, you have to understand that the internal representation for Fixnum
    values is different from most other objects in Ruby. If you create two
    different Float objects with the same value, i.e.

    x = 5.0
    y = 5.0

    then they are really two different objects, i.e.

    x.id != y.id

    but when you "create" two different Fixnum objects with the same value:

    x = 5
    y = 5

    then they are references to the *same* object:

    x.id == y.id is True

    So the short answer is no, there's no way to change the value of a
    Fixnum object like you could with a Float, even from C code. A Fixnum is
    what it is.
    Lyle Guest

  3. #3

    Default Re: ruby fixnums

    On Wed, Feb 11, 2004 at 01:15:03AM +0900, Lyle Johnson wrote: 

    Thanks for the detailed reply.

    Regards,
    --
    University of Athens I bet the human brain
    Physics Department is a kludge --Marvin Minsky




    Elias Guest

Similar Threads

  1. Replies: 0
    Last Post: November 1st, 05:21 PM
  2. Replies: 1
    Last Post: October 29th, 07:52 PM
  3. ruby-talk: 80813 (Rite/Ruby2.0 & Ruby vs OCaml)
    By Steven Lumos in forum Ruby
    Replies: 0
    Last Post: October 9th, 10:21 PM
  4. RubyConf, Ruby Central, Ruby Garden temporary outage
    By dblack@superlink.net in forum Ruby
    Replies: 1
    Last Post: September 10th, 03:46 PM
  5. [ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge
    By guillaume.pierronnet@ratp.fr in forum Ruby
    Replies: 0
    Last Post: August 31st, 11:57 PM

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