[Terminology] What's the Ruby/OO name for this paradigm?

In my current project, one of the main paradigms is code such as in
the following example. I'm wondering if there's a Ruby/OO designation
for it so that I wouldn't have to always show some excerpt when
describing the project. It's sort of an inverse continuation passing
scheme (which, in itself, isn't exactly a prime OO term).

def three()
  return lambda { |s1, s2| puts s1 + s2 }
end

def two()
  return lambda { |s1| three().call(s1, 'world!') }
end

def one()
  return lambda { two().call('Hello ') }
end

one().call # "Hello world!"

Anything? Input on the style welcome, too, by the way: is this hard to
understand/unintuitive/there's a better way/etc.?

E

E S wrote:

In my current project, one of the main paradigms is code such as in
the following example. I'm wondering if there's a Ruby/OO designation

for it so that I wouldn't have to always show some excerpt when
describing the project. It's sort of an inverse continuation passing
scheme (which, in itself, isn't exactly a prime OO term).

def three()
  return lambda { |s1, s2| puts s1 + s2 }
end

def two()
  return lambda { |s1| three().call(s1, 'world!') }
end

def one()
  return lambda { two().call('Hello ') }
end

one().call # "Hello world!"

Anything? Input on the style welcome, too, by the way: is this hard

to

understand/unintuitive/there's a better way/etc.?

def three
lambda { |s1, s2| puts s1 + s2 }
end

def two
lambda { |s1| three[s1, 'world!'] }
end

def one
lambda { two['Hello '] }
end

one # "Hello world!"

But why do?

T

In my current project, one of the main paradigms is code such as in
the following example. I'm wondering if there's a Ruby/OO designation
for it so that I wouldn't have to always show some excerpt when
describing the project. It's sort of an inverse continuation passing
scheme (which, in itself, isn't exactly a prime OO term).

def three()
  return lambda { |s1, s2| puts s1 + s2 }
end

def two()
  return lambda { |s1| three().call(s1, 'world!') }
end

def one()
  return lambda { two().call('Hello ') }
end

one().call # "Hello world!"

Its called "Currying".

http://c2.com/cgi/wiki/Curry?CurryingSchonfinkelling

Not an OO term, but a functional programming term.

PGP.sig (186 Bytes)

···

On 02 Feb 2005, at 21:53, E S wrote:

Anything? Input on the style welcome, too, by the way: is this hard to
understand/unintuitive/there's a better way/etc.?

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Technically currying, but from the example it looks like the intent is
simply function wrapping.

e.g. we do this a lot at work:

one(args) {
  ensure thread safety;
  return two(args)
}

two(args) {
  ensure constraint satisfaction;
  return three(args)
}

three(args) {
  do the actual work;
  return the actual result;
}

Is that the same thing you're using it for?

martin

···

E S <eero.saynatkari@kolumbus.fi> wrote:

In my current project, one of the main paradigms is code such as in
the following example. I'm wondering if there's a Ruby/OO designation
for it so that I wouldn't have to always show some excerpt when
describing the project. It's sort of an inverse continuation passing
scheme (which, in itself, isn't exactly a prime OO term).

It is called "delayed evaluation". The pattern is that instead of having a
value of type A, you have a function taking no arguments whose return is
of type A. Some take this concept further, ensuring the function is only
actually called once, and the result is cached (Scheme has a macro called
DELAY for that). That's the kind of thing you'd do to have lazy semantics
in a non-lazy language.

Don't listen to those who might call this "currying". Currying means
decomposing the argument list like this:

  f = lambda{|a,b,c| a*b+c }
  p f[4,10,2]

  g = lambda{|a| lambda{|b| lambda{|c| a*b+c }}}
  p g[4][10][2]

here g is called the currying of f.

typewise, that's (A*B*C)->D becoming A->(B->(C->D)).

···

On Thu, 3 Feb 2005, E S wrote:

In my current project, one of the main paradigms is code such as in
the following example. I'm wondering if there's a Ruby/OO designation
for it so that I wouldn't have to always show some excerpt when
describing the project. It's sort of an inverse continuation passing
scheme (which, in itself, isn't exactly a prime OO term).

Anything? Input on the style welcome, too, by the way: is this hard to
understand/unintuitive/there's a better way/etc.?

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

e.g. we do this a lot at work:

one(args) {
  ensure thread safety;
  return two(args)
}

two(args) {
  ensure constraint satisfaction;
  return three(args)
}

three(args) {
  do the actual work;
  return the actual result;
}

Is that the same thing you're using it for?

Reminds me of decorators[1] except applied to functions instead of
objects. (Well.. OK... functions are objects... clss sense then...)

Douglas

[1]http://c2.com/cgi/wiki?DecoratorPattern