Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
L
LINFO2335 - Assignement Project 2
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Nicolas Verbois
LINFO2335 - Assignement Project 2
Validations
d91ea09e
Valider
d91ea09e
rédigé
3 years ago
par
Nicolas Verbois
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Update step_4.rkt : adding comments and explanations
parent
0b9ea737
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
step_4.rkt
+54
-9
54 ajouts, 9 suppressions
step_4.rkt
avec
54 ajouts
et
9 suppressions
step_4.rkt
+
54
−
9
Voir le fichier @
d91ea09e
#
lang
r5rs
; Authors : Nicolas Verbois - 1366 1600
; Nicolas Rosar - 1443 1900
; Group F
; In this last step, we want to implement a way of executing the calls delegated to a method defined in the super class
; in the context of the child class. This will be done using what we have called a "self_ref" value inside each class.
; We have also created a new constructor procedure, that will handle the creation of any class instance, and will help
; the achieve this dynamic binding of self.
; The purpose of the self_ref value is linked to the special method named 'set-self! that we have added to each class.
; It binds self_ref to a given instance and then recursively calls the same 'set-self! method on the superclass to bind
; its self_ref to that same instance, solving the dynamic binding issue.
; For the object class, we don't need a recursive call to the super class in the set_self! method since it is the root
; of our inheritance hierarchy.
; Thus, in this case, we do not propagate the set_self! method and instead only dynamically bind the local self_ref value.
(
define
(
object
)
; #f is the default value before any binding
(
define
self_ref
#f
)
(
define
(
set-self!
ref
)
(
set!
self_ref
ref
))
(
define
(
gettype
)
'object
)
...
...
@@ -8,7 +26,8 @@
(
else
(
display
"Message not understood"
))))
self
)
; COLOR-POINT
; For the color-point class, since it is a child class of point, we need to propagate the set-self! call to the super class.
; Thus, we have an extra line in the definition of the set_self! procedure to propagate the dynamic binding upwards.
(
define
(
color-point
x
y
color
)
(
define
self_ref
#f
)
(
define
super
(
point
x
y
))
...
...
@@ -31,7 +50,7 @@
(
else
(
super
m
))))
self
)
;
POINT
;
For the point class, as it is a child class of object, we also need to propagate the set-self! call to the super class.
(
define
(
point
x
y
)
(
define
self_ref
#f
)
(
define
(
set-self!
ref
)
...
...
@@ -61,6 +80,7 @@
(
else
(
super
m
))))
self
)
(
define
(
send
p
m
.
args
)
(
if
(
procedure?
p
)
(
cond
...
...
@@ -73,6 +93,11 @@
)
; The new construtctor procedure.
; It has to take as parameters one object-class, as well as a variable numbler of
; class parameters.
; It will then create the new object, and initiate the dynamic binding of self through
; a 'set-self call.
(
define
(
new
object-class
.
class-args
)
(
let
((
temp
(
apply
object-class
class-args
)))
(
begin
...
...
@@ -82,10 +107,30 @@
)
)
(
eq?
color-point
point
)
(
define
cp
(
new
color-point
5
6
'red
)
)
(
send
cp
'type
)
; c o l o r - p o i n t
(
send
cp
'getx
)
; 5
(
send
cp
'gety
)
; 6
(
send
cp
'get-color
)
; red
(
send
cp
'info
)
; ( c o l o r - p o i n t 5 6 red )
; Sample code illustrating the execution of the step
; We can prove that the dynamic binding indeed worked with the followig piece of code.
; Indeed, with the current implementation, if the dynamic binding were not to work,
; then the 'info message sent to the color point would return something wrong.
; It is because the way we build the return value of the 'info message in the color-point
; class is done using informations retrieved by the parent class, and appending other informations
; to this : (append (send super 'info) ... )).
; Without dynamic binding, the parent point class would have no clue it is called by a color-point object,
; and thus return the information of a point and not a color-point.
(
define
cp
(
new
color-point
5
6
'red
))
(
display
(
send
cp
'type
))
; should display : color-point
(
newline
)
(
display
(
send
cp
'getx
))
; should display : 5
(
newline
)
(
display
(
send
cp
'gety
))
; should display : 6
(
newline
)
(
display
(
send
cp
'get-color
))
; should display : red
(
newline
)
(
display
(
send
cp
'info
))
; should display : (color-point 5 6 red)
(
newline
)
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter