You can prevent stack consumption by using trampoline for tail-recursive 
calls to a different arity, and recur for same arity, something like:

(defn find-comment-in-line
    ([s] (when (pos? (count s))
      (if-let [cs (seq (comment-s? s))]
         ;; yes, a comment symbol found, 
         ;; just return the remainder of a string
          (subs s (count (first cs))) 

         ;; no, lets check for an opening quote
          (if-let [qs (seq (quote-s? s))] 

              ;; yes, an opening quote found, 
              ;; now go look for an end quote
              (trampoline find-comment-in-line (subs s 1) qs) 

              ;; no, just some other symbol found, 
              ;; check for the rest
              (recur (subs s 1)))))) 

     ([s q] (when (pos? (count s))
     ;; lets check if it is a quote 
     (if-let [qs (seq (quote-s? s))] 

         ;; is it a closing quote?
         (if (= qs q) 
           ;; yes, lets check for the rest
           (trampoline find-comment-in-line (subs s 1)) 

           ;; no, just ignore the symbol, 
           ;;continue looking for a closing quote
           (recur (subs s 1) q)))))) 


On Tuesday, April 19, 2016 at 11:18:40 AM UTC-4, andmed wrote:
>
> Thank you. That the point. If "recur" binds to fn, why it can not know the 
> binding point as the function method based on the number of arguments 
> passed to it? I mean it is clear that Clojure can't do that, but I can see 
> no reason why it could or should not if we choose to implement such 
> syntactic nicety as recur in a function
>

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to