Created
October 4, 2012 09:52
-
-
Save kosh04/3832633 to your computer and use it in GitHub Desktop.
FOOPでメンバ変数に名前を付ける #newlisp
This file contains 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
;; FOOP in newLISP | |
;; * How find parent context? | |
(new Class 'Animal) | |
(new Animal 'Snake) (define Snake:super Animal) | |
(new Animal 'Horse) (define Horse:super Animal) | |
(context Animal) | |
;; constructor | |
; (define (Animal:Animal name) | |
; (list (context) name)) | |
;; * use macro module. enabled (setf (@var) val) | |
; (module "macro.lsp") | |
; (macro (@name) (self 1)) | |
(define (@name) (self 1)) | |
(define (move meters) | |
(println (@name) " moved " meters "m.") | |
true) | |
(context Snake) | |
(define (move) | |
(print "Slithering...") | |
(super:move 5)) | |
(context Horse) | |
(define (move) | |
(print "Galloping...") | |
(super:move 45)) | |
(context MAIN) | |
(setq sam (Snake "Sammy the Python") | |
tom (Horse "Tommy the Palomino")) | |
(:move sam) | |
(:move tom) | |
(exit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment