PersistentStructMap Exception

15 views
Skip to first unread message

cearl

unread,
Nov 23, 2009, 9:29:57 AM11/23/09
to Clojure
Hi,
I'm getting a cast exception on trying to create a simple structure
and wondered if there was something obvious that I'm not doing. The
transcript below shows my version of java. Running on Mac Book Pro,
Snow Leopard 5.6.1


bash-3.2$ java -version
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219)
Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02-90, mixed mode)
bash-3.2$ java -cp clojure-1.0.0.jar clojure.lang.Repl
Clojure 1.0.0-
user=> (defstruct s1 :a :b)
#'user/s1
user=> (s1 1 2)
java.lang.ClassCastException: clojure.lang.PersistentStructMap$Def
cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0)


Thanks

ataggart

unread,
Nov 23, 2009, 3:07:30 PM11/23/09
to Clojure
That's not how you create a new struct instance.

http://clojure.org/data_structures#toc19

songoku

unread,
Nov 23, 2009, 9:00:12 PM11/23/09
to Clojure

> user=> (defstruct s1 :a :b)
> #'user/s1
> user=> (s1 1 2)

(struct s1 1 2) or (struct-map s1 :a 1 :b 2)
--> {:a 1, :b 2}

or:
(struct s1 1)
--> {:a 1, :b nil}

(struct-map s1 :b 2)
--> {:a nil, :b 2}
Reply all
Reply to author
Forward
0 new messages