Hi,
One way to prevent the stack overflows is to wrap it in a lazy seq.
For example:
(defn remove-first [x coll]
(lazy-seq
(when (seq coll)
(let [[y & ys] coll]
(if (= target y)
ys
(cons y (remove-first x ys)))))))
On Saturday 24 July 2010 11:41:58 nickikt wrote:
> Hallo all,
>
> I'm working trough Essentials of Programming Languages. I'm trying to
> right a function like this one:
>
> (defn scheme-remove-first [syb lst]
> (if (empty? lst)
> '()
> (if (= (first lst) syb)
> (rest lst)
> (cons (first lst) (scheme-remove-first syb (rest lst))))))
>
> in a idiomatic clojure way (this is just a scheme to clojure 1:1
> version). I don't like that this function produces stack overflows.
>
> I tried some stuff but I it (almost) semantically correct working but
> I didn't like my code. Can anyone come up with a good version?
--
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