Problems with &form (in an effort to make serializable functions)

50 views
Skip to first unread message

nathanmarz

unread,
Apr 17, 2012, 8:34:55 PM4/17/12
to Clojure
So I've been hacking for the past day on making serializable functions
for Clojure (building off the work of @technomancy in his serializable-
fn repo).

I'm running into a nasty problem though, and I really don't understand
what's going on. One of the things I'm doing in my code (
https://github.com/nathanmarz/serializable-fn/blob/master/src/clj/serializable/fn.clj
) is trying to capture the source code whenever someone uses the
replacement serializable.fn/fn macro. I'm using &form to do this.

However, *sometimes*, the form when serialized contains a bunch of
subforms missing. The subforms are replaced with a "#" character. To
serialize I'm just calling pr-str on the form.

The way the behavior is reproduced is odd as well. If I run the
Cascalog tests (in this branch:
https://github.com/nathanmarz/serializable-fn/blob/master/src/clj/serializable/fn.clj),
everything works fine until one of the last test suites,
cascalog.predicate-test, where I get this behavior (causing
deserialization errors). However, if I run just that test suite (lein2
test cascalog.predicate-test) it passes. It only fails if I run the
whole test suite, and it always fails the exact same way. So
whatever's causing this behavior is not random but consistent.

Does anyone know what could be causing this behavior and how to fix it?

nathanmarz

unread,
Apr 17, 2012, 9:07:52 PM4/17/12
to Clojure
OK, I dug into the Clojure source and found a way to solve my issue.
If I wrap the pr-str in (binding [*print-dup* true] (pr-str form)) it
works.


On Apr 17, 5:34 pm, nathanmarz <nathan.m...@gmail.com> wrote:
> So I've been hacking for the past day on making serializable functions
> for Clojure (building off the work of @technomancy in his serializable-
> fn repo).
>
> I'm running into a nasty problem though, and I really don't understand
> what's going on. One of the things I'm doing in my code (https://github.com/nathanmarz/serializable-fn/blob/master/src/clj/ser...
> ) is trying to capture the source code whenever someone uses the
> replacement serializable.fn/fn macro. I'm using &form to do this.
>
> However, *sometimes*, the form when serialized contains a bunch of
> subforms missing. The subforms are replaced with a "#" character. To
> serialize I'm just calling pr-str on the form.
>
> The way the behavior is reproduced is odd as well. If I run the
> Cascalog tests (in this branch:https://github.com/nathanmarz/serializable-fn/blob/master/src/clj/ser...),

Caspar Hasenclever

unread,
Apr 17, 2012, 9:10:32 PM4/17/12
to clo...@googlegroups.com
The # appears when *print-level* is exceeded
in pr/pr-str, just as you get "..." when *print-lengtht*
is exceeded:

(pr-str {:foo {:bar {:baz 3}}})
=> "{:foo {:bar {:baz 3}}}"

(set! *print-level* 2)
=> 2

(pr-str {:foo {:bar {:baz 3}}})
=> "{:foo {:bar #}}"

Could it be that a preceding test sets *print-level*? Just a wild guess.

Cheers,

Caspar
Reply all
Reply to author
Forward
0 new messages