This will give you a list of contexts:
Code: Select all
(filter context? (map eval (symbols 'MAIN)))
In your code you probably mean:
Code: Select all
(context 'MY_CONTEXT)
(set 'items '())
(define (create_item this_item)
(new ITEM this_item)
(set 'this_item (eval this_item))
;;Item Title
(set 'this_item:title "some title")
;;Item Author
(set 'this_item:author "some author")
;;Item Date
(set 'this_item:item_date "some date")
;;Item Body
(set 'this_item:content "foo body")
;;Item Link/URL
(set 'this_item:link "some URL")
(push this_tem items)
)
(context 'MAIN)
;; now you could do:
(MY_CONTEXT:create_item 'TEST-1)
(MY_CONTEXT:create_item 'TEST-2)
MY_CONTEXT:items => (TEST-2 TEST-1)
; from inside MY_CONTEXT you would do:
(create_item 'MAIN:TEST-1)
(create_item 'MAIN:TEST-1)
; because context symbols always belong to MAIN
This is the critical statement:
(set 'this_item (eval this_item))
Because you want to acces the context which is inside this_item but 'this_item' contains the symbol 'TEST-1 (which will contan the context TEST-1). So with 'eval' you have to peel off one layer.
In the last statment I use 'push', because 'cons' is non-destructive and would not change the list.
Lutz