Last active
January 3, 2016 06:39
-
-
Save addisaden/8424195 to your computer and use it in GitHub Desktop.
This is Lisp in Python: Checkout hy at http://docs.hylang.org/en/latest/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defclass Car [] | |
[[--init-- | |
(fn [self max-speed max-speedup] | |
(def self.speed 0) | |
(def self.max max-speed) | |
(def self.max-add max-speedup) | |
None)] | |
[gas | |
(fn [self speedup] | |
(do | |
(if (>= speedup self.max-add) | |
(+= self.speed self.max-add) | |
(+= self.speed self.speedup)) | |
(if (>= self.speed self.max) | |
(def self.speed self.max)) | |
self.speed))] | |
[break | |
(fn [self] | |
(do | |
(-= self.speed 30) | |
(if (< self.speed 0) (def self.speed 0)) | |
self.speed))] | |
[--str-- | |
(fn [self] | |
(.format "Das Auto fährt {} km/h schnell." self.speed))] | |
]) | |
(def auto (Car 200 50)) | |
(print auto) | |
(.gas auto 70) | |
(print auto) | |
(.break auto) | |
(print auto) | |
; Das Auto fährt 0 km/h schnell. | |
; Das Auto fährt 50 km/h schnell. | |
; Das Auto fährt 20 km/h schnell. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is Lisp in Python: Checkout hy