Skip to content

Instantly share code, notes, and snippets.

@alcidesfp
Last active October 4, 2015 20:38
Show Gist options
  • Save alcidesfp/2695774 to your computer and use it in GitHub Desktop.
Save alcidesfp/2695774 to your computer and use it in GitHub Desktop.
Clase simple en Kawa
;; -*- 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