On 25 February 2009, Adrian Cuthbertson  wrote:
> 
> Hmm, I get a stack overflow when trying that make macro.
> After using macroexpand-1...
> (with-meta (struct stuff 1 2) {:type (keyword (str *ns*) (name (quote 
> stuff)))})
> I still get the stack overflow.
> 
> I'm on svn 1307, jdk 1.5 mac osx.
> Any ideas?

Hmmm... On svn 1307, I get the same stack overflow. No issue on svn 1280. It's 
the keyword :type as metadata...but only when stringifying the value to output 
it.

(def x (with-meta [1 2] {:type "hi"})) ; define but don't print: works
(meta x) ; get metadata: works
(get x 1) ; get a value: works

(println x) ; stack overflow
(str x) ; stack overflow
(format "%s" x) ; stack overflow

If the keyword in the macro is changed to anything other than "type", there's 
no issue. 

(with-meta [] {:typeX "hi"}) ; no worries
(with-meta [] {:type "hi"})  ; stack overflow

String representation obviously uses :type now in a very particular way. I'm 
not sure where this happens though. Can anyone shed some light on the details?

-Jeff

> 
> On Thu, Feb 26, 2009 at 7:08 AM, Jeff Valk <jv-li...@tx.rr.com> wrote:
> >
> > How about appending type metadata automagically...
> >
> > (defstruct stuff :a :b)
> > (defmacro make
> >  "Creates a new instance of struct t and appends 'type' t as metadata"
> >  [t & vs]
> >  `(with-meta
> >    (struct ~t ~...@vs)
> >    {:type (keyword (str *ns*) (name '~t))}))
> >
> > user> (make stuff 1 2)
> > {:a 1, :b 2}
> >
> > user> (meta (make stuff 1 2))
> > {:type :user/stuff}
> >
> > -Jeff

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