From: LeonardoBizzoni Date: Wed, 3 Jan 2024 11:13:45 +0000 (+0100) Subject: Iniziato a fare i metodi X-Git-Url: http://git.leonardobizzoni.com/?a=commitdiff_plain;h=21bf5b308bc05d8496f757d206cfdee45266b1d4;p=ObjectOriented-Prolog-Lisp Iniziato a fare i metodi Manca ancora la sostituzione dei vari `this` ma la definizione del "metodo" c'è. Credo sia necessario trovare un modo per permettere l'esistenza di 2+ funzioni con lo stesso nome perchè ora quando un figlio estende un metodo del padre questo viene eliminato e le istanza del padre sono fottute. --- diff --git a/Lisp/README.org b/Lisp/README.org index 37430e9..f7ced47 100644 --- a/Lisp/README.org +++ b/Lisp/README.org @@ -125,6 +125,7 @@ (error "Il primo argomento della lista di methods ~S" "deve essere il simbolo 'methods'"))) + (create-methods classname (cdr methods)) (type-check-fields (cdr fields)) (inherit (list :classname classname :type 'class @@ -192,6 +193,20 @@ (field-name-exists name (rest fields))))) #+end_src +*** Creazione di metodi +#+begin_src lisp :tangle ool.lisp +(defun create-methods (classname methods) + (mapcar + (lambda (method) + (eval (list* 'defun + (first method) + (append '(inst) (second method)) + (append '((unless (is-instance inst) + (error "~A non è un'istanza" inst))) + (cddr method))))) + methods)) +#+end_src + ** Creazione di un'istanza #+begin_src lisp :tangle ool.lisp (defun create-instance (listclass new-fields) diff --git a/Lisp/ool.lisp b/Lisp/ool.lisp index 71e780f..4eba3f8 100644 --- a/Lisp/ool.lisp +++ b/Lisp/ool.lisp @@ -63,6 +63,7 @@ (error "Il primo argomento della lista di methods ~S" "deve essere il simbolo 'methods'"))) + (create-methods classname (cdr methods)) (type-check-fields (cdr fields)) (inherit (list :classname classname :type 'class @@ -120,6 +121,17 @@ (or (equal name (first (first fields))) (field-name-exists name (rest fields))))) +(defun create-methods (classname methods) + (mapcar + (lambda (method) + (eval (list* 'defun + (first method) + (append '(inst) (second method)) + (append '((unless (is-instance inst) + (error "~A non è un'istanza" inst))) + (cddr method))))) + methods)) + (defun create-instance (listclass new-fields) ;; Se c'è almeno un field da cambiare ;; il cui nome non è una proprietà della classe