ABS |ruby|

Discussion in 'Ruby' started by Alex Combas, Jan 13, 2006.

  1. Alex Combas

    Alex Combas Guest

    Quick question,

    In math the absolute value is typically
    the double pipe:
    |x| =3D 27

    This reminds me stuff like:
    Stuff.each { |x| puts 'hello '+x }

    Are these two related in any way?
    I dont really see why they would be related but thought it was an
    interesting coincidense nonetheless.

    --
    Alex Combas
    http://noodlejunkie.blogspot.com/
     
    Alex Combas, Jan 13, 2006
    #1
    1. Advertising

  2. Alex Combas wrote:
    >
    > In math the absolute value is typically
    > the double pipe:
    > |x| = 27
    >
    > This reminds me stuff like:
    > Stuff.each { |x| puts 'hello '+x }
    >
    > Are these two related in any way?


    No, this is just syntactic sugar. It's a placeholder for the iteration
    variable. abs is a method in Numeric.

    Christer

    --
    Posted via http://www.ruby-forum.com/.
     
    Christer Nilsson, Jan 13, 2006
    #2
    1. Advertising

  3. Alex Combas

    ATOM Guest

    In math we also have the set-notation like:
    A = { a | a > 0 }
    which means something like: A is set of elements,
    greater then 0... and so on. This could also
    be read similar to block-syntax. We get a set of elements
    on which we perform some operations (like map+lambda
    call in funcional languages, anonymous function +
    set of elements).
    regards.

    Alex Combas wrote:
    > Quick question,
    >
    > In math the absolute value is typically
    > the double pipe:
    > |x| = 27
    >
    > This reminds me stuff like:
    > Stuff.each { |x| 'h puts ello '+x }
    >
    > Are these two related in any way?
    > I dont really see why they would be related but thought it was an
    > interesting coincidense nonetheless.
    >
    > --
    > Alex Combas
    > http://noodlejunkie.blogspot.com/
     
    ATOM, Jan 13, 2006
    #3
  4. On 1/13/06, Alex Combas <> wrote:
    > In math the absolute value is typically
    > the double pipe:
    > |x| =3D 27
    >
    > This reminds me stuff like:
    > Stuff.each { |x| puts 'hello '+x }
    >
    > Are these two related in any way?


    IIRC, the block syntax in Ruby is reminiscent to Smalltalk syntax,
    which used blocks like this:

    [ :x | Transcript show: 'hello ', x ] "the equivalent of Ruby
    block { |x| puts 'hello '+x }"

    and used | vars | to declare some temporary variables in a piece of code.

    | x y |
    ^ x + y

    Square brackets are not square anymore (as they are used in Ruby for
    indexing purposes - C inheritance). The odd variable names with
    markers :)x) were replaced by the delimited block of names (| x |) and
    voil=E0.

    Regards,
    Adriano.
     
    Adriano Ferreira, Jan 13, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Math.abs

    , Nov 9, 2005, in forum: Java
    Replies:
    37
    Views:
    14,750
    Oliver Wong
    Nov 14, 2005
  2. Daniel Heiserer
    Replies:
    2
    Views:
    799
    Chris Dams
    Sep 23, 2003
  3. Aaron Gallimore

    C++ abs() function

    Aaron Gallimore, Feb 24, 2004, in forum: C++
    Replies:
    5
    Views:
    96,899
    Rob Williscroft
    Feb 24, 2004
  4. Steven T. Hatton
    Replies:
    4
    Views:
    3,991
    Rob Williscroft
    Dec 5, 2004
  5. Klaas Vantournhout

    f2c's abs conflicts with <complex> abs

    Klaas Vantournhout, Oct 31, 2006, in forum: C++
    Replies:
    3
    Views:
    402
    Victor Bazarov
    Oct 31, 2006
Loading...

Share This Page