apricot-lang / apricot

Clojure-like Lisp on Rubinius
94 stars 7 forks source link

Arity-overloaded fns could be more efficient #38

Closed solson closed 9 years ago

solson commented 11 years ago

Take the function map for example:

(defn map
  ([f coll]
   (.map coll | f))
  ([f coll & colls]
   (.map (.zip coll & colls) | #(apply f %))))

Here's the top bit of its decoded assembly:

0000:  passed_arg                 2
0002:  goto_if_true               27
0004:  passed_arg                 1
0006:  goto_if_true               8
0008:  push_local                 1    # coll
0010:  push_local                 0    # f

The point is that Rubinius allows users to pass only 2 or 3 arguments to map, so if that passed_arg 2 check (checking for the 3rd argument) fails, we know for sure 2 arguments were passed and we don't need to check with passed_arg 1. This current code works but does pointless extra work.

I'm sure there are other cases like this I haven't considered.

canweriotnow commented 11 years ago

Related: what is the state of multimethods in Apricot? Could dispatch-on-arity be a thing?

Sorry, just getting my feet wet and coming from a background of MRI + JVM Clojure :smile:

solson commented 11 years ago

There's currently no support for Clojure-style multimethods. What exactly do you mean by dispatch-on-arity (as opposed to the already implemented arity-overloaded fns)?

canweriotnow commented 11 years ago

Using multimethods to emulate Java overloading based on args/arg arity... I don't even like using multimethods that way in Clojure (usually just dispatch on a fn like class), just curious about the state of multimethods in Apricot. Thanks.

Jason Lewis

vox 410.428.0253 twitter @canweriotnow blog http://decomplecting.org else http://about.me/jason.lewis

On Wed, Dec 4, 2013 at 8:42 PM, Scott Olson notifications@github.comwrote:

There's currently no support for Clojure-style multimethods. What exactly do you mean by dispatch-on-arity?

— Reply to this email directly or view it on GitHubhttps://github.com/apricot-lang/apricot/issues/38#issuecomment-29864628 .

solson commented 9 years ago

I'm closing this since Apricot is effectively abandoned, but I'm open to pull requests if anyone is interested.