with-meta and concat

12 views
Skip to first unread message

jim

unread,
Feb 22, 2009, 4:07:43 PM2/22/09
to Clojure
In some old code, I did something like:

(with-meta (concat [1 3] [8 4])
{:tail true}))

which now fails. I believe it's because the result of concat is now
some kind of reference.

Does anyone have any advice on a workaround?

Jim

Chouser

unread,
Feb 22, 2009, 4:32:04 PM2/22/09
to clo...@googlegroups.com

LazySeq extends AFn, so you can't change the metadata once the object
exists. However, Seq's still accept meta-data, so:

(with-meta (seq (concat [1 3] [8 4]))
{:tail true})

--Chouser

jim

unread,
Feb 22, 2009, 4:40:46 PM2/22/09
to Clojure
Thanks! That was exactly what I needed to get my old code to pass my
unit tests. Now it's on to making changes to bring it up to date with
the new lazy stuff.

Jim

Christophe Grand

unread,
Feb 23, 2009, 4:21:05 AM2/23/09
to clo...@googlegroups.com
Chouser a écrit :

I'm not sure it's desirable to have metadata on seqs (it bit me while
transitionning to lazy) but I have thought of two ways to add withMeta
to a LazySeq:
* to have meta()/withMeta() to force evaluation of the inner seq (and it
begs the question to know whether (= (meta a) (meta (lazy-seq a)))
should be true),
* to have withMeta() to return some kind proxy on the LazySeq object
(cannot this approach also works for regular closures?).

BTW, speaking of regular closures, would it be possible to be able to
set "static" metadata?
eg:
(#^{:meta {:actual :metadata}} fn* [args] body)

(The fn macro could make this prettier.)

Christophe

--
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (en)


Rich Hickey

unread,
Feb 23, 2009, 7:37:29 AM2/23/09
to Clojure
The fact that LazySeqs are AFns is an implementation detail that might
change. I still have some perf tweaking to do. After that, we can look
at how best to support metadata.

Rich
Reply all
Reply to author
Forward
0 new messages