2008-09-29 01:40:58 -04:00
|
|
|
#!/usr/bin/env ikarus --r6rs-script
|
|
|
|
|
|
|
|
(import (ikarus) (objc))
|
|
|
|
|
|
|
|
(define-framework Cocoa)
|
|
|
|
(define-class NSObject)
|
|
|
|
|
|
|
|
(define IKFact
|
|
|
|
(create-class "IKFact" NSObject '() #f))
|
|
|
|
|
|
|
|
(class-add-class-method IKFact 'fact: 'int '(class selector int)
|
|
|
|
(trace-lambda fact (self sel n)
|
|
|
|
(if (zero? n)
|
|
|
|
1
|
|
|
|
(* n [$ self fact: (sub1 n)]))))
|
|
|
|
|
2008-10-06 01:19:27 -04:00
|
|
|
(class-add-class-method IKFact 'fact:ac: 'int '(class selector int int)
|
|
|
|
(trace-lambda fact (self sel n ac)
|
|
|
|
(if (zero? n)
|
|
|
|
ac
|
|
|
|
[$ self fact: (sub1 n) ac: (* n ac)])))
|
|
|
|
|
2008-09-29 01:40:58 -04:00
|
|
|
(printf "(fact 5) = ~s\n" [$ IKFact fact: 5])
|
2008-10-06 01:19:27 -04:00
|
|
|
|
|
|
|
(printf "(fact 5) = ~s\n" [$ IKFact fact: 5 ac: 1])
|
|
|
|
|