If one wanted to implemented some indexed data structure (e.g. defstruct),
wouldn't it be in the spirit of Arc to allow using such data structures
in the functional position? Example: (struct node name val)
(let n (make-node)
(= (node-name n) 'foo)
(prn (node-name n)) ; -> 'FOO
;; This won't work
(prn (n 'name)) ; -> Should also be 'FOO
;; This neither
(= (n 'val) 1))
The Tcl language has a 'unknown' command that can be redefined and is
called whenever the interpreter encounters something in the functional
position it does not know how to handle. If Arc had something similar,
one could handle the case of the node struct above: (let orig unknown
(def unknown (expr)
(if (and (alist expr) (isa (car expr) 'node))
(if (is (cadr expr) 'name) (node-name (car expr))
(is (cadr expr) 'val) (node-val (car expr))
(err "bad index"))
(orig expr))))
Of course, this would be have to be done in the macro expansion of
the (struct node ...) ...To allow using = on a place specified this way, would there have
to be an 'unknown=' procedure? Such a general mechanism like 'unknown' could of course be (mis)used for
other purposes, too ... |