Carp/test/produces-output/function_members.carp
Erik Svedäng a873099640
chore: Move some examples to test/produces-output (#989)
* chore: Moved examples that work more as tests to folder 'test/produces-output'

* fix: Corrections to the release script

* fix: Correct filename on Windows

* fix: Move more files around

* fix: Remove check-malloc example

* fix: Apparently unicode example does not work

* chore: Move nested_lambdas.carp back to examples

* chore: Remove .DS_Store files

* fix: Bring back unicode test

* test: Make sure benchmark compile (had to remove mandelbrot and n-bodies)

* fix: Replacement implementation of clock_gettime on Windows

* chore: Trigger CI

* fix: Define CLOCK_REALTIME

Co-authored-by: Erik Svedang <erik@Eriks-iMac.local>
2020-11-23 06:30:43 +01:00

32 lines
807 B
Plaintext

(Project.no-echo)
(Debug.sanitize-addresses)
(Project.config "print-ast" true)
(deftype Enemy [hp Int
attack (Fn [Int] Int)])
(defn attack [attacker target]
(let [f @(Enemy.attack attacker)
new-hp (f @(Enemy.hp &target))]
(Enemy.set-hp target new-hp)))
(deftype SelfReferencer [hp Int
f (λ [SelfReferencer] SelfReferencer)])
(defn change-self [self]
(SelfReferencer.update-hp self &inc))
(deftype (GenericFuncMember a) [f (λ [a] a)])
(defn main []
(let-do [enemy (Enemy.init 100 dec)
hero (Enemy.init 100 dec)
selfer (SelfReferencer.init 100 change-self)
gen (GenericFuncMember.init Int.inc)
]
(println* &(attack &enemy hero))
(println* &(change-self selfer))
(println* &gen)
))