;;; struct-lite
;; a very simple and fast structure system

;;AUTOLOAD: struct-lite:def
;;AUTODOC: struct-lite:def
;; (struct-lite:def structname fieldsnames...)
;;
;; struct-lite is a very simple and fast structure system
;; NOTE: this is obsolete: use defstruct instead.
;; ==> sets structname to a structlite which is a vector of the form:
;; #(Structure structname fieldsnames...)
;;
;; (struct-lite:make structlite fieldsvalue...)
;; ==> a new instance
;;
;; (struct-lite:get structlite fieldname)
;; ==> value or error
;;
;; (struct-lite:put structlite fieldname value)
;;
;; field can be an atom or a keyword, but cannot be mixed (usage in get 
;; must be the same as the declaration
;;
;; exemple:
;; ? (struct-lite:def Record name age adress)
;;  = [Structure Record name age adress]
;; ? (struct-lite:def Record :name :age :adress)
;;  = [Structure Record :name :age :adress]
;; ? (setq r (struct-lite:make Record "colas" 35 "Mougins"))
;;  = [Structure Record colas 35 Mougins]
;; ? (struct-lite:get r :adress)
;;  = Mougins
;; ? (struct-lite:get r 'adress)
;; Error: No field adress in [Structure Record colas 35 Mougins]
;; (error No field %0 in %1 field struct-lite)


(defunq struct-lite:def (struct-lite:def:struct-name 
    &rest struct-lite:def:fields
  )
  (set struct-lite:def:struct-name 
    (apply vector `(
	Structure
	,struct-lite:def:struct-name
	,@struct-lite:def:fields
))))

(defun struct-lite:make (struct-lite &rest fields)
  (apply vector `(Structure ,(getn struct-lite 1) ,@fields))
)

(defun struct-lite:get (struct-lite field &aux
    (pos (seekq (eval (get struct-lite 1)) field))
  )
  (if pos
    (get struct-lite pos)
    (error "No field %0 in %1" field struct-lite)
  )
)

(defun struct-lite:put (struct-lite field value &aux
    (pos (seekq (eval (get struct-lite 1)) field))
  )
  (if pos
    (put struct-lite pos value)
    (error "No field %0 in %1" field struct-lite)
  )
)
