Chouser <[email protected]> writes:
> I haven't tried all the above, but I had a couple thoughts that might help:
>
> First, inside #=(), arguments aren't evaluated. They act as if quoted:
>
> #=(+ 1 (+ 2 4))
> ; ClassCastException clojure.lang.PersistentList cannot be cast to
> java.lang.Number clojure.lang.Numbers.add (Numbers.java:126)
>
> The list (+ 2 4) is passed as a list to the outer +, which fails
> because it's expecting a number not a list. So one alternative would
> be:
>
> #=(+ 1 #=(+ 2 4))
> ;=> 7
I'm unable to programmatically generate nested #=() forms. :-(
user> (str "#=" `(1 "#=" (+ 2 3)))
"#=(1 \"#=\" (clojure.core/+ 2 3))"
How would I do so?
> But please consider another alternative:
>
> (+ 1 (+ 2 4))
> ;=> 7
>
> That is, if you're going to be evaluating a large amount of code while
> reading your data back into memory, why not just go ahead and eval it
> instead of just reading it?
>
> (read-string "#=(+ 1 #=(+ 2 4))")
> vs.
> (eval (read-string "(+ 1 (+ 2 4))"))
I've tried spitting out forms without the #=, and that basically does
the trick for my objects.
"(de.uni-koblenz.funtg.core/vertex
(de.uni-koblenz.funtg.core/*serialization-bindings*
\"c06de1c7-f4ec0906-21cfbc86-28c31aa1\")
1)"
That can be loaded back with `load-string' or (eval (read-string ...))
[if the right graph is bound by *serialization-bindings*, of course].
However, my intent is to be able so seamlessly load and store any data
structure build upon clojure data structures mixed with vertices and
edges. The approach fails if I try to write/read something like that
#{1 2 (take 3 (vseq (rg)))}
where vseq is the lazy seq of a graph's vertices. Writing that results
in a string like
"#{1 2 ((vertex (*serialization-bindings* ...) 1)
(vertex (*serialization-bindings* ...) 2)
(vertex (*serialization-bindings* ...) 3))}"
and clearly when evaling, the result of the first vertex call [a vertex]
will be treated as a function, which it is not.
Reading a form with nested #= works just fine (namespace stripped for
brevity):
"#{1 2 (#=(vertex #=(*serialization-bindings*
\"c06de1c7-f4ec0906-21cfbc86-28c31aa1\") 1)
#=(vertex #=(*serialization-bindings*
\"c06de1c7-f4ec0906-21cfbc86-28c31aa1\") 2)
#=(vertex #=(*serialization-bindings*
\"c06de1c7-f4ec0906-21cfbc86-28c31aa1\") 3))}
So currently it seems to me that writing those nested #=() forms is the
most practical way. But I'm open for other suggestions as well.
Bye,
Tassilo
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en