简体   繁体   中英

“and” and tail recursion

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

For example, purpose, we have function foo 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)))))

是的, and是OK -你可以在阅读本标准

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM