Skip to content
Extraits de code Groupes Projets
Valider 2935d53d rédigé par Nicolas Verbois's avatar Nicolas Verbois
Parcourir les fichiers

Update step_0.rkt : adding comments and more tests

parent 8e4dd9f2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
#lang r5rs
; Authors : Nicolas Verbois - 1366 1600
; Nicolas Rosar - 1443 1900
; Group F
; This acts as the first step in building objects in Scheme
; The object, here a point, is defined as a dispacther returning values.
; We thus emulate a point class as a constructor function that creates
; an object through a dispacter function.
; A point will be defined as an object containing two coordinates, x and y.
; Once the object is created using the constructor, the dispacther will be
; able to respond to messages, concerning those two coordinates as well as
; characteristics of the point object, like the type of object, or printing
; a "string-like" representation using the "info" message.
; In case of a message that the dispatcher cannot handle, it will return a
; simple error message through a display.
(define (point x y)
(define (dispatch m)
......@@ -9,11 +26,38 @@
(else (display "ERROR"))))
dispatch)
; Sample code illustrating the execution of the step
; We start by trying to create a new point p
(define p (point 1 2))
(display (p 'getx))
(display (p 'getx)) ; should display : 1
(newline)
(display (p 'gety))
(display (p 'gety)) ; should display : 2
(newline)
(display (p 'type))
(display (p 'type)) ; should display : point
(newline)
(display (p 'info)) ; should display : (point 1 2)
(newline)
(display (p 'info))
(display '------------)
(newline)
; We then create a second point p
(define p2 (point 4 -1))
(display (p2 'getx)) ; should display : 4
(newline)
(display (p2 'gety)) ; should display : -1
(newline)
(display (p2 'type)) ; should display : point
(newline)
(display (p2 'info)) ; should display : (point 4 -1)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter