Ruby concepts

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

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

"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

    robert

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.

···

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?

The first three concepts aren't particularly Ruby-ish, they're more
closely attached to functional-programming languages such as Haskell,
CaML, Lambda, etc. However the central feature of those is called
"closure" and you do them in Ruby using proc{} or lambda{} or other. C++
doesn't support those "nested functions". However I think the STL uses C++
classtemplates to wrap single functions in a way that type-decls of C++
can begin to look like functional-programming (that's de hack!).

The latter, reflection, could be thought of just RTTI boosted to the
"max". Actually it doesn't give you so much more in Ruby because all
methods are silent as to the types of arguments they take and what they
give back. However you can at least query classes and walk through
class-hierarchies using ordinary while-loops and recursion, and get a list
of method-defs for each class. You can also do runtime modifications.

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)

···

On Wed, 2 Feb 2005, Joe Van Dyk 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?

_____________________________________________________________________
Mathieu Bouchard -=- Montréal QC Canada -=- http://artengine.ca/matju

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.

···

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)

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.