Last active
October 4, 2015 20:38
-
-
Save alcidesfp/2695774 to your computer and use it in GitHub Desktop.
Clase simple en Kawa
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
;; -*- coding:utf-8; mode:Scheme -*- | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(define-simple-class Person () | |
;; members | |
(name init: "" ) | |
(birth-year init: 0 ) | |
;; methods | |
((*init*) #!void) ;; default constructor | |
((*init* name: birth-year:) ;; constructor with params | |
(set! name name:) | |
(set! birth-year birth-year:)) | |
;; | |
((age) | |
(- 2012 birth-year))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(require 'srfi-64) | |
(test-begin "persona-test") | |
(define persona1 :: Person (Person)) | |
(test-eqv 0 persona1:birth-year) | |
(test-eqv "" persona1:name) | |
(set! persona1:name "Alcides") | |
(set! persona1:birth-year 1974) | |
(test-eqv 38 (persona1:age)) | |
(test-end) | |
;; | |
(newline) | |
(format #t "name: ~a~%" persona1:name) | |
(format #t "birth-year: ~a~%" persona1:birth-year) | |
(format #t "age: ~a~%" (persona1:age)) | |
(newline) | |
;; | |
(define persona2 :: Person (Person birth-year: 1984 name: "Persona2")) | |
(format #t "name: ~a~%" persona2:name) | |
(format #t "birth-year: ~a~%" persona2:birth-year) | |
(format #t "edad: ~a~%" (persona2:age)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment