[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby concepts

Joe Van Dyk

2/1/2005 6:43:00 PM

I understand C++ programming concepts (i.e. Classes, generics, etc). pretty well

However, I always feel a little lost about stuff that you don't do
(easily) in C++, like first class functions, partials, currying,
reflection, etc.

Can someone recommend some resources for better understanding of these
weird concepts?

Thanks,
Joe


6 Answers

Assaph Mehr

2/1/2005 9:42:00 PM

0

If you have enough time, try "Structure and Interpretation of Computer
Programs":
http://mitpress.mit...
(One of these days I plan to actually finish it :-)

Robert Klemme

2/1/2005 11:17:00 PM

0


"Joe Van Dyk" <joevandyk@gmail.com> schrieb im Newsbeitrag
news:c715e640502011035724846c@mail.gmail.com...
>I understand C++ programming concepts (i.e. Classes, generics, etc). pretty
>well
>
> However, I always feel a little lost about stuff that you don't do
> (easily) in C++, like first class functions, partials, currying,
> reflection, etc.
>
> Can someone recommend some resources for better understanding of these
> weird concepts?

Hmm, there is a Wiki page about this
http://www.rubygarden.org/ruby?Func...

robert

Dido Sevilla

2/2/2005 5:31:00 PM

0

On Wed, 2 Feb 2005 03:43:11 +0900, Joe Van Dyk <joevandyk@gmail.com> wrote:
> I understand C++ programming concepts (i.e. Classes, generics, etc). pretty well
>
> However, I always feel a little lost about stuff that you don't do
> (easily) in C++, like first class functions, partials, currying,
> reflection, etc.
>
> Can someone recommend some resources for better understanding of these
> weird concepts?

Simple explanations:

Reflection -- The ability to perform introspection on an object
instance to determine what methods, fields, and so forth it has at
run-time. Java can do this, as can Ruby. This isn't even a strange
functional programming property.

First class functions -- This is a property of languages in that a
function may be used as though it were most other types of values,
e.g. you can pass a function as a parameter to another function
(higher-order functions or HOF's), store functions inside variables,
make functions that return other functions as their return value and
so on and so forth. C has first class functions: look at the qsort
standard library function. You pass qsort a function used to compare
elements in the array you want to sort. I believe the same is also
true of C++ by extension.

Partial Evaluation/Currying -- Say we had some function f(x, y, z)
with three arguments. If we left the arguments x and y fixed to some
constant values, say 1 and 2, we could construct another function of
one variable g(z) = f(1, 2, z). Currying or partial evaluation is the
process of doing this. If you ever took a course in the theory of
computation, you'll recognize this as a direct application of S.C.
Kleene's S-m-n theorem, so in theory any language that has first class
functions can define a currying HOF that takes a function of m+n
arguments, constant values for m arguments, and return a function of n
arguments that computes the original input function with m variables
fixed. Some languages (like Standard ML or OCaml) make this process
trivial because it is inherent in their syntax, and some languages
with first-class functions make it inordinately difficult to do in its
fullest generality because of their syntax (I can't think of how to do
it in C, for instance). Ruby falls somewhere in the middle, as the
Wiki link Mr. Klemme points out shows.


Mathieu Bouchard

2/5/2005 7:16:00 PM

0

Kent Sibilev

2/5/2005 10:01:00 PM

0

On Feb 5, 2005, at 2:16 PM, Mathieu Bouchard wrote:

> However, Ruby's reflection is missing a few things, that are present in
> languages like Tcl/Python (examining lists of local variables) or
> Scheme/Lisp/Tcl (accessing source code at runtime, as nested lists;
> easy
> manipulation of source code)
>

Hm, I'm not sure about local variables though. The last time I checked:

$ irb
irb(main):001:0> a,b = 1,2
=> [1, 2]
irb(main):002:0> local_variables.grep(/^[^_]/) do |n|
irb(main):003:1* puts "#{n} = #{eval n}"; n
irb(main):004:1> end
a = 1
b = 2
=> ["a", "b"]
irb(main):005:0>

Cheers
Kent.


Cheers,
Kent.



Yukihiro Matsumoto

2/6/2005 1:11:00 AM

0

Hi,

In message "Re: Ruby concepts"
on Sun, 6 Feb 2005 04:16:11 +0900, Mathieu Bouchard <matju@sympatico.ca> writes:

|However, Ruby's reflection is missing a few things, that are present in
|languages like Tcl/Python (examining lists of local variables) or
|Scheme/Lisp/Tcl (accessing source code at runtime, as nested lists; easy
|manipulation of source code)

I think you mean something more than "local_variables" method.

matz.