-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-slot.lisp
62 lines (61 loc) · 1.51 KB
/
get-slot.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
;controlla che la lista fornita rispetti la specifica (rappresenti un
; metodo)
(defun methodp (value)
(and (listp value) (> (length value) 2) (eq 'method (first value)))
)
;a ogni chiamata di metodo trasforma la rappresentazione relativa
;(method () ())
;in una lambda e la applica
(defun call_method (this nome args)
(let
(
(arglist (cons 'this
(second(gethash nome (cdr (get-class-spec (cdr this)))))))
(corpofunz (prognizza
(rest (rest (gethash nome
(cdr (get-class-spec (cdr this))))))))
)
(apply (eval (list 'lambda arglist corpofunz))
(cons this args))
)
)
;prende una lista di sexp sperando che siano chiamate di funzione e
;le fa diventare gli argomenti di una chiamata a progn
(defun prognizza (operazioni)
(cons 'progn operazioni)
)
;imposta
(defun set-slot (classe campo valore)
(let ((tabella
(if (methodp valore)
(cdr classe)
(car classe)
)
))
(progn
(if (not (has_member tabella campo))
(setf (gethash '__names__ tabella)
(cons campo (gethash '__names__ tabella))
)
)
;in ogni caso:
(setf (gethash campo tabella) valore)
;se è un metodo serve esportare la funzione
(if (methodp valore)
(process-method campo valore)
)
)
)
)
;installa un metodo.
(defun process-method (method-name metod-spec)
(setf (fdefinition method-name)
(lambda (this &rest args)
(call_method this method-name args)
)
)
)
;restituisce un attributo di istanza (non funziona sui metodi)
(defun get-slot (istanza nome)
(gethash nome (car istanza))
)