1 ;; Demonstration of scholiumific programming
3 ;; Define the utility for running code.
5 (defun node-fun (node retrieve-code
9 (funcall retrieve-vars node
)
15 (funcall retrieve-vars
(cadr item
))))
18 (apply (node-fun (\
, (cadr item
))
19 (quote (\
, retrieve-code
))
20 (quote (\
, retrieve-vars
))
21 (quote (\
, retrieve-link
)))
22 (\
, (cons (quote list
) var-list
)))))))
23 (funcall retrieve-link node
))
24 (funcall retrieve-code node
)))))
26 ;; Make a new scholium-based document.
28 (set-current-plexus (add-plexus))
30 ;; Place the program in the document.
35 (2 "main-prog" 0 0 (list (foo 5) (goo 6)))
36 (3 "sub-foo" 0 0 (* x x
))
37 (4 "sub-goo" 0 0 (+ x
3))
38 (5 "link-foo" 2 3 sub foo
)
39 (6 "link-goo" 2 4 sub goo
)
41 (8 "main-args" 7 2 . var
)
43 (10 "foo-args" 9 3 . var
)
44 (11 "goo-args" 9 4 . var
)))
46 ; We provide functions to identify scholia of type
47 ;; var and sub and retrieve the appropriate data.
49 (defun get-dependencies (art)
51 (list (cadr (get-content x
))
56 (car (get-content y
))))
57 (get-forward-links art
))))
64 (get-content (get-source x
)))
67 (equal 'var
(get-content y
)))
68 (get-backward-links art
))))))
70 ;; Here is the output they produce:
72 (get-dependencies (label2uid "main-prog"))
76 (get-vars (label2uid "sub-foo"))
80 ;; Using these functions, we evaluate our node. Remember that the code
81 ;; at "main-prog" is supposed to invoke foo and goo, which are found as
82 ;; scholia attached to that node. As we see, it does this correctly.
85 (label2uid "main-prog")
91 ;; In case you're interested, here are the gory details of how
92 ;; node-fun wrapped up the code inside the node.
94 (node-fun (label2uid "main-prog")
101 ;; (lambda nil (flet ((goo (x) (apply (node-fun 4
102 ;; (quote get-content)
104 ;; (quote get-dependencies))
106 ;; (foo (x) (apply (node-fun 3
107 ;; (quote get-content)
109 ;; (quote get-dependencies))
111 ;; (list (foo 5) (goo 6))))
113 (node-fun (label2uid "sub-goo")
118 ;; (lambda (x) (flet nil (+ x 3)))
120 (get-content (label2uid "sub-goo")) ; => ((+ x 3))
121 (get-vars (label2uid "sub-goo")) ; => (x)
122 (get-dependencies (label2uid "sub-goo")) ; => nil