Re: "wrong number of args" with nested map

2010-04-19 Thread Peter Salvi
Also the function
  (defn foo [map1 map2] (map map2 (keys map1)))
seems to be a bit more clear.

Peter

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Multimethods & derive

2009-06-08 Thread Peter Salvi

On Jun 8, 3:51 pm, Konrad Hinsen  wrote:

> See also my patch that creates such a universal root type [...]

Nice! That's exactly what I was thinking about

Peter

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Multimethods & derive

2009-06-07 Thread Peter Salvi

Hi,

I would like to use multimethods by dispatching on keys of the
variables (maps)
in a way that I sometimes have constraints on only some of the
arguments.

In common lisp I would say

(defgeneric foo (a b))
(defmethod foo ((a bar) b) ...)
(defmethod foo (a (b baz)) ...)
(defmethod foo ((a bar) (b baz)) ...)

This would mean that I have also defined methods for calls when (for
example)
`a' is an instance of `bar' and `b' of anything but `baz'. How can I
achieve
something like this with multimethods?

I could define a relationship like

(derive :bar :anything)
(derive :baz :anything)

and then do

(defmulti foo (fn [a b] [(:somekey1 a) (:somekey2 b)]))

with

(defmethod foo [:bar :anything] [a b] ...)
(defmethod foo [:anything :baz] [a b] ...)
(defmethod foo [:bar :baz] [a b] ...)

This seems to do the trick... but is this really the way to do it?

If it is, it would be very useful to have something that is the
ancestor of
everything (like T in common lisp).

Thanks,

Peter

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---