开发者

"and" and tail recursion

Can I build iterative process using recursive call in and statement?

For example, purpose, we have function fo开发者_JAVA技巧o that doesn't do anything. What kind of process it will create (iterative or recursion)?

(define (foo? bar) 
  (if (< bar 0) true (and (> 10 1) (foo? (- bar 1)))))


Yes, and is OK - you can read this in the standard.


For Lamberts sake, lets expand the syntax.

(define (foo? bar) 
  (if (< bar 0) 
      #t ; tail position, but no call
      (if (> 10 1) 
          (foo? (- bar 1)) ; tail position
          #f))) ; tail position, but no call
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜