-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnewcl.lisp
98 lines (83 loc) · 3.61 KB
/
newcl.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;;;-*-Mode:LISP; Package:NEWCL; Base:10; Syntax:Common-lisp -*-
;;; This is the file newcl.lisp
;;; Revisions of September 27, 1991 by desRivieres@parc.xerox.com:
;;; - add clause to make print-unreadable-object work for AKCL
;;; - standardize on uppercase names in setf-function-symbol
(in-package 'newcl :use '(lisp))
(shadow '(defun fmakunbound fboundp))
(export '(fdefinition defun fmakunbound fboundp print-unreadable-object))
;;; New macros to support function names like (setf foo).
(lisp:defun setf-function-symbol (function-specifier)
(if (consp function-specifier)
(let ((print-name (format nil "~:@(~A~)" function-specifier)))
(intern print-name
(symbol-package (cadr function-specifier))))
function-specifier))
(lisp:defun fboundp (function-specifier)
(if (consp function-specifier)
(lisp:fboundp (setf-function-symbol function-specifier))
(lisp:fboundp function-specifier)))
(lisp:defun fdefinition (function-specifier)
(if (consp function-specifier)
(lisp:symbol-function (setf-function-symbol function-specifier))
(lisp:symbol-function function-specifier)))
(lisp:defun fmakunbound (function-specifier)
(if (consp function-specifier)
(lisp:fmakunbound (setf-function-symbol function-specifier))
(lisp:fmakunbound function-specifier)))
(defsetf fdefinition (function-specifier) (new-value)
`(set-fdefinition ,new-value ,function-specifier))
(lisp:defun set-fdefinition (new-value function-specifier)
(if (consp function-specifier)
(progn
(setf (symbol-function (setf-function-symbol function-specifier))
new-value)
(eval `(defsetf ,(cadr function-specifier)
(&rest all-args)
(new-value)
`(,',(setf-function-symbol function-specifier)
,new-value
,@all-args))))
(setf (symbol-function function-specifier) new-value)))
(defmacro defun (name formals &body body)
(cond ((symbolp name)
`(lisp:defun ,name ,formals ,@body))
((and (consp name) (eq (car name) 'setf))
`(progn
(lisp:defun ,(setf-function-symbol name) ,formals ,@body)
(defsetf ,(cadr name) ,(cdr formals) (,(car formals))
(list ',(setf-function-symbol name) ,@formals))))))
#| Minimal tests:
(macroexpand '(defun (setf foo) (nv x y) (+ x y)))
(defun (setf baz) (new-value arg)
(format t "setting value of ~A to ~A" arg new-value))
(macroexpand '(setf (baz (+ 2 2)) (* 3 3)))
|#
;;;
;;; print-unreadable-object
;;;
;;; print-unreadable-object is the standard way in the new Common Lisp
;;; to generate #< > around objects that can't be read back in. The option
;;; (:identity t) causes the inclusion of a representation of the object's
;;; identity, typically some sort of machine-dependent storage address.
(defmacro print-unreadable-object
((object stream &key type identity) &body body)
`(let ((.stream. ,stream)
(.object. ,object))
(format .stream. "#<")
,(when type
'(format .stream. "~S" (type-of .object.)))
,(when (and type (or body identity))
'(format .stream. " "))
,@body
,(when (and identity body)
'(format .stream. " "))
,(when identity
#+Genera '(format .stream. "~O" (si:%pointer .object.))
#+Lucid '(format .stream. "~O" (sys:%pointer .object.))
#+Excl '(format .stream. "~O" (excl::pointer-to-fixnum .object.))
#+:coral '(format .stream. "~O" (ccl::%ptr-to-int .object.))
#+kcl '(format .stream. "~O" (si:address .object.))
)
(format .stream. ">")
nil))