On Mon, Nov 24, 2008 at 5:27 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> I believe I have fixed all of my stack-space issues except for this
> one annoying function (rewritten from the original since the
> multimethod wasn't buying me much):
>
> (defn flatten [x]
>  (let [type (:type x)]
>    (cond (or (= type :NIL) (= type :TEXT))
>          x
>          (= type :CONCAT)
>          (doc-concat (flatten (:doc1 x))
>                      (flatten (:doc2 x)))
>          (= type :NEST)
>          (doc-nest (:level x)
>                    (flatten (:doc x)))
>          (= type :LINE)
>          (doc-text " ")
>          (= type :UNION)
>          (recur (:doc1 x)))))
>
> Any ideas?

One option: You could use a seq instead of all the various structs.
This would allow you to remove all the doc-foo helper functions.
Instead of calling those helpers, in most cases you could simply build
a vector [:NIL] instead of (doc-nil), [:TEXT " "] instead of (doc-text
" ").  That way, when you need to recurse, you could use a lazy
expression like (lazy-cat [:concat] [(flatten (:doc1 x))] [(flatten
(:doc2 x))])
This would of course require you to change everywhere that currently
expects a struct with a :type to instead use (first x) for the type
and the rest of the seq as args.

Is your current version visible anywhere?  Perhaps a more holistic
look would reveal some other options.

--Chouser

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to