Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > ABS |ruby|

Reply
Thread Tools

ABS |ruby|

 
 
Alex Combas
Guest
Posts: n/a
 
      01-13-2006
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/


 
Reply With Quote
 
 
 
 
Christer Nilsson
Guest
Posts: n/a
 
      01-13-2006
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/.


 
Reply With Quote
 
 
 
 
ATOM
Guest
Posts: n/a
 
      01-13-2006
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/


 
Reply With Quote
 
Adriano Ferreira
Guest
Posts: n/a
 
      01-13-2006
On 1/13/06, Alex Combas <(E-Mail Removed)> 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:

[ | 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 () were replaced by the delimited block of names (| x |) and
voil=E0.

Regards,
Adriano.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
f2c's abs conflicts with <complex> abs Klaas Vantournhout C++ 3 10-31-2006 10:07 PM
ABS Stealth Computer Case @ A True Review Silverstrand Front Page News 0 12-01-2005 01:23 AM
Math.abs markelmel@yahoo.com Java 37 11-14-2005 03:45 PM
C++ abs() function Aaron Gallimore C++ 5 02-24-2004 06:13 PM
g++ 3.2.X: undefined reference to `abs(int)' Daniel Heiserer C++ 2 09-23-2003 10:58 AM



Advertisments