Lisp symbols without package bindings -
i've been working on project. should able numerical , symbolic computing. stuck on 1 problem , don't know how resolve it. specific , short, let's in package
(in-package #:brand-new-package) where have symbol database
(defvar var-symbol-database (make-hash-table :test #'equal)) reading , setting functions
(defun var-symbol (name) (get-hash name var-symbol-database)) (defun set-var-symbol (name value) (setf (get-hash name var-symbol-database) value)) (set-var-symbol 'temperature 300) ;k (set-var-symbol 'f 200) ;hz (set-var-symbol 'k 1.3806504e-23) ;j k^-1 and in file (but same package) try evaluate equation
(eval '(+ 2 (var-symbol 'f))) it won't work. problem particular reason value of key in hash table is.
brand-new-package::f i though solve problem defining function this
(set-var-symbol 1 '(var-symbol 'f)) ;hz but interpreted as
(brand-new-package::var-symbol brand-new-package::f) the problem program can create many different symbols. compute electronic circuit equations. program first inspect device objects capacitors, resistors , so. create circuit tablo mna.
during many new symbols representing node voltages , currents created
(v1, v2, v3, i1, i2). i needed method hold count , names of variables presented in equation. because passed symbolic derivator ie (diff '(* (+ 40 v1) u2 ...) 'v1)) came idea, maybe wrong, make them reachable index define them list
'(v 1) '(v 2) '(v 3). to make them evaluable added begining var-variable funcall. list becomed
'(var-variable v 1) '(var-variable v 2) '(var-variable v 3) but have written, system changes
'(brand-new-package::var-variable brand-new-package::v 1) '(brand-new-package::var-variable brand-new-package::v 2) '(brand-new-package::var-variable brand-new-package::v 3) how allow users acces these variables typing (var-symbol 'v 1). can imagine 1 way. instead of symbols use strings , export function (var-symbol). work way
'(var-variable "v" 1) but little bit confusing.
what state "problem" expected. common lisp notation brand-new-package::var-symbol signifies symbol var-symbol in package brand-new-package, current package @ time symbol read lisp.
Comments
Post a Comment