On Feb 19, 2:39 pm, Phil Hagelberg wrote:
> linh writes:
> > # ruby code
> > def foo(x, y)
> > x + y
> > end
>
> > def bar
> > [1, 2]
> > end
>
> > foo(*bar) # this is fine, the result will be 3
> > foo(bar) # this is not ok, will raise exception
>
> > bar returns an array of size 2, but foo
linh writes:
> # ruby code
> def foo(x, y)
> x + y
> end
>
> def bar
> [1, 2]
> end
>
> foo(*bar) # this is fine, the result will be 3
> foo(bar) # this is not ok, will raise exception
>
> bar returns an array of size 2, but foo expects 2 parameters not an
> array.
In Clojure, this would lo
On Thu, Feb 19, 2009 at 4:28 PM, linh wrote:
>
> hi,
> how can i do this in clojure?
>
> # ruby code
> def foo(x, y)
> x + y
> end
(defn foo [x y] (+ x y))
> def bar
> [1, 2]
> end
(def bar [1 2])
> foo(*bar) # this is fine, the result will be 3
(apply foo bar)
> foo(bar) # this is not ok