Hello,

2011/4/26 Joshua Ballanco <jballanc / gmail.com>:
> Regarding the consistency argument, as I understand Currying (or at least=
 the way that it is implemented in most other languages), the result of a P=
roc#curry call should be a chain of Proc's with arity 1 that return Proc's =
with arity 1 until all arguments have been satisfied. It would be nice if R=
uby behaved similarly.

How should Ruby handle *rest parameter?

  proc {|x, y, z, *rest| }.curry.(1).(2).(3).(4).(5)... ?


> For example, in OCaml (which auto-curries functions):

If you quote OCaml, you should note that Ocaml also provides
optional arguments.
Actually, OCaml handles optional arguments as Ruby does.
IOW, OCaml function also fires as soon as all the required
arguments are given:


  # let foo ?(a=3D"ichi") ?(b=3D"ni") ?(c=3D"san") () =3D
      print_endline (S(String.concat ", " [a; b; c]);;
  val foo : ?a:string -> ?b:string -> ?c:string -> unit -> unit =3D <fun>
  # foo ();;
  ichi, ni, san
  - : unit =3D ()
  # foo ~a:"first" ();;
  first, ni, san
  - : unit =3D ()
  # foo ~a:"first" ~b:"second" ();;
  first, second, san
  - : unit =3D ()
  # foo ~a:"first" ~b:"second" ~c:"third" ();;
  first, second, third
  - : unit =3D ()


There are some differences between OCaml and Ruby:

  - OCaml function requires at least one mandatory argument.
    (In this case, () is the only mandatory argument.)

  - Optional arguments always requires labels (=3D keywords).


I believe your concern (and #4601) will be solved by keyword
arguments.

  def foo(a:"ichi", b:"ni", c:"san")
    puts "#{ a }, #{ b }, #{ c }"
  end

  foo(b:"second")  #=3D> ichi, second, san

  method(:foo).curry.
    pass_option(a: "first").
    pass_option(b: "second").
    pass_option(c: "third").
    call()  #=3D> first, second, third

Unfortunately, a new method (Proc#pass_option) is needed
because Proc#call(key: val) passes a hash { key =3D> val } as
a normal argument, unless we accept the incompatibility.


The future of keyword arguments is promised by matz
[ruby-core:32131]:

> Keyword arguments will be available on 2.0.

--=20
Yusuke Endoh <mame / tsg.ne.jp>