Meikel Brandmeyer <m...@kotka.de> writes:

> you can return always a vector.
>
> (fn [] [true])
> (fn [] [true {:foo 12}])
>
> And then use destructuring on the return value.
>
> (let [[value annotations] (...)]
>   (when annotations
>     ..))

My first idea was to add metadata to the return value, but that doesn't
work for java types like Boolean.  As a workaround, you could let your
functions return

(defn foo []
  ;; calculate real-return-val
  (with-meta (constantly real-return-val)
    {:foo 1, :bar 2}))

Wrap that in a `annotated-return' macro and always use that in your
functions.  The cost is, that now `foo' returns a function returning the
result, so you have to call it using ((foo)) or (apply (foo))...

But at least you can then do

(let [f (foo)
      r (f)
      m (meta f)]
  ;; the result is r, the metadata is m
  )

Again, wrap that in some `annotated-call' macro, so that you can do

  (annotated-call foo [result meta]
    (do-stuff-with result meta))

Hm, but well, that's only a workaround.  Metadata could be so useful if
it was possible to attach it to anything, not only anything in clojure.
I myself once had the need to put metadata on java objects, but that
doesn't work either...

Bye,
Tassilo

-- 
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

Reply via email to