>>> "'Alexander Kogtenkov' via Eiffel Users" <
eiffel...@googlegroups.com>
schrieb am 08.04.2021 um 10:03 in Nachricht
<
1617868989...@f301.i.mail.ru>:
> You are talking about "currying". Routine classes are using tuples to pass
> arguments to feature calls. As a result, direct currying is impossible (as,
I
> guess, you figured out by trial and error). A wrapper (as pointed out in
> another reply) can be used instead.
>
> Let’s look at an example. Suppose, 3 local variables are declared and
> initialized as follows:
>
> local
> x: PROCEDURE [STRING, STRING]
> y, z: PROCEDURE [STRING]
> do
> x := agent (a, b: STRING) do print (a + b + "%N") end
> y := currying.close_1 (x, "a")
> z := currying.close_2 (x, "b")
>
> The desired effect of the subsequent calls
>
> x ("a", "b")
> y ("y")
> z ("z")
>
> is the following output:
>
> ab
> ay
> zb
Sorry I couldn't resist doing it in Perl:
DB<1> $x = sub($$) { print "$_[0]$_[1]\n" }
DB<2> $y = sub($) { $x->("a", $_[0]) }
DB<3> $z = sub($) { $x->($_[0], "b") }
DB<4> $x->("a", "b")
ab
DB<5> $y->("y")
ay
DB<6> $z->("z")
zb
I think Perl's closures are much more elegant.
Regards,
Ulrich
https://groups.google.com/d/msgid/eiffel-users/1617868989.443136361%40f301.i.
>
mail.ru.