Hi Lutz:
Since I sent the previous, I find that the following:
Code: Select all
(define (Hash! l oname)
(new hash 'newhash)
(println "newhash = [" newhash:lst "]") ;; DEBUG newhash
(if l (set 'newhash:lst l))
(println "newhash = [" newhash:lst "]") ;; DEBUG newhash
(if oname (set 'newhash:object-name oname))
(println "newhash = [" newhash:object-name "]") ;; DEBUG newhash
newhash)
gives me results closer to what I'm looking for - at least with preliminary testing,
and the changes are consistent with your advice about not making
the variable local.
To clarify what I am after:
I'd like to be able to instantiate any number of "objects" which might be
multi-level associative lists. This is consistent with much that I now do in other languages
and consistent with RAD tools that I've developed for python and rebol
code generation.
Python has the feature of object intializers - so I'm trying to replicate that
here with the Hash! function. At a top level I might have something like this:
Code: Select all
(set 'lst '(
(id001 (name "Anne") (addr (country "USA") (city "New York")))
(id002 (name "Jean") (addr (country "France") (city "Paris")))
))
(set 'records (Hash! lst "records"))
;; here we have a default function
(define (hash:hash)
(let((res lst))
(dolist (i (args) (not res))
(set 'res (assoc i res)))))
;; and a function call like
(records 'id001 'addr 'country)
Such an instantiation might have a 'strict parameter that, if
set might result in an error thrown if for instance, a non-nil
search result - and such an error would
contain the name of the context ('context-name) and the name
of the instantiation ('object-name).
Are my intentions any clearer now? :-)
Thanks again
tim