Article View: comp.lang.lisp.x
Article #316defstruct for xlisp 2.0
From: R Hamilton
Date: Thu, 23 May 1991 14:00
Date: Thu, 23 May 1991 14:00
50 lines
2071 bytes
2071 bytes
I hacked this up to run some lisp code on a PC with Xlisp (V2.0)).
It gives most of defstruct (allows slot defaults in defstruct but no
initialising :keywords in make-structname). I'm no lisp guru and the
code which quotes commas does look a bit iffy (certainly doesnt work in
LUCID!), but it's small and does at least work in xlisp so perhaps
somebody else may find it useful too.
;;; partial defstruct for Xlisp
;;; Robert Hamilton (rjha@uk.ac.ed.ee)
;
;;; doesnt support :keword initialisation in make-structname but allows
;;; defaults in defstruct
;;; uses an array to store the structure
;;; Xlisp only
;;;
(defmacro incf (x) `(setf ,x (+ 1 ,x))) ;need incf
(defmacro defstruct (name &rest parms &aux (counter -1) var)
(setq var (quote ,pppxyz)) ; diddles backquote on xlisp
;; make/eval a list of access macros suitable for setf like:
;; (defmacro name-slot1 (structname) `(aref ,structname slot-number))
(mapcar #'(lambda (x) (eval `(defmacro
,(intern (strcat ; slot-name
(string (car name)) "-"
(if (atom x) (string x)
(string (car x)))))
(pppxyz) ;structure arg
`(aref ,var ,(incf counter)))))
parms)
;; return the make-struct for evaluation
`(defun
,(intern (strcat
(string 'make-) (string (car name))))
()
(prog (template result )
(setq template (quote ,parms))
(setq result (make-array (length template)))
(dotimes (i (length template))
(if (listp (nth i template))
(setf (aref result i)
(cadr (nth i template)))))
(return result))))
Robert Hamilton
Dept of Elect. Engin.
Kings Buildings,
University of Edinburgh
JANET: rjha@uk.ac.ed.ee
Technical Details
Message-ID:
<10488@castle.ed.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!ukc!edcastle!rjhaShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!ukc!edcastle!rjha From: rjha@castle.ed.ac.uk (R Hamilton) Newsgroups: comp.lang.lisp.x Subject: defstruct for xlisp 2.0 Message-ID: <10488@castle.ed.ac.uk> Date: 23 May 91 14:00:49 GMT Organization: Edinburgh University Lines: 50