[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

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

e

2/3/2005 5:53:00 AM

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



5 Answers

Trans

2/3/2005 6:22:00 AM

0


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

Eric Hodel

2/3/2005 7:20:00 AM

0

On 02 Feb 2005, at 21:53, 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!"

Its called "Currying".

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

Not an OO term, but a functional programming term.

> 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://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Martin DeMello

2/3/2005 8:25:00 AM

0

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).

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

Douglas Livingstone

2/3/2005 11:17:00 PM

0

> 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?Decora...


Mathieu Bouchard

2/4/2005 9:27:00 AM

0