1 ;; sch-prog-demo.el - Minimal example of scholiumific programming
3 ;; Copyright (C) 2013 Raymond S. Puzio
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU Affero General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU Affero General Public License for more details.
15 ;; You should have received a copy of the GNU Affero General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;; See http://arxana.net/foo-goo.jpg for a vital map.
24 (load-file "prelim.el")
25 (load-file "honey-redux.el")
28 (defun node-fun (node retrieve-code
32 (funcall retrieve-vars node
)
34 (cons (mapcar (quote (lambda (item)
36 (funcall retrieve-vars
(cadr item
))))
39 (apply (node-fun (\
, (cadr item
))
40 (quote (\
, retrieve-code
))
41 (quote (\
, retrieve-vars
))
42 (quote (\
, retrieve-link
)))
43 (\
, (cons (quote list
) var-list
))))))))
44 (funcall retrieve-link node
))
45 (funcall retrieve-code node
)))))
47 ;; Make a new scholium-based document.
49 (set-current-plexus (add-plexus))
51 ;; Put the main program in a node.
54 (add-nema (label2uid "ground")
60 ;; Put two subroutines in their own nodes.
63 (add-nema (label2uid "ground")
69 (add-nema (label2uid "ground")
74 ;; Make links from the main program to its subroutines. The text of
75 ;; the link states the name of the subroutine.
79 (label2uid "main-prog")
86 (label2uid "main-prog")
91 ;; Add nodes and links for the variables.
100 ;; Argument list of node 1 (points to "main-vars", which contains nil)
101 ;; In order words, List 1 doesn't have any unbound variables.
105 (label2uid "main-vars")
106 (label2uid "main-prog")
117 ;; Argument lists of node 2 and node 3
121 (label2uid "sub-vars")
122 (label2uid "sub-foo")
128 (label2uid "sub-vars")
129 (label2uid "sub-goo")
133 ; We provide functions to identify scholia of type
134 ;; var and sub and retrieve the appropriate data.
136 (defun get-dependencies (art)
138 (list (cadr (get-content x
))
143 (car (get-content y
))))
144 (get-forward-links art
))))
146 (defun get-vars (art)
151 (get-content (get-source x
)))
154 (equal 'var
(get-content y
)))
155 (get-backward-links art
))))))
157 ;; Here is the output they produce:
159 (get-dependencies (label2uid "main-prog"))
163 (get-vars (label2uid "sub-foo"))
167 ;; Using these functions, we evaluate our node. Remember that the code
168 ;; at node 1 is supposed to invoke foo and goo, which are found as
169 ;; scholia attached to node 2. As we see, it does this correctly.
172 (label2uid "main-prog")
178 ;; In case you're interested, here are the gory details of how
179 ;; node-fun wrapped up the code inside the node.
181 (node-fun (label2uid "main-prog")
187 (lambda nil
(flet ((goo (x) (apply (node-fun 4 (quote get-content
) (quote get-vars
) (quote get-dependencies
)) (list x
))) (foo (x) (apply (node-fun 3 (quote get-content
) (quote get-vars
) (quote get-dependencies
)) (list x
)))) (list (foo 5) (goo 6))))
191 (lambda nil
(flet ((goo (x) (apply (node-fun 3
194 (quote get-dependencies
))
196 (foo (x) (apply (node-fun 2
199 (quote get-dependencies
))
201 (list (foo 5) (goo 6))))
204 (node-fun (label2uid "sub-goo")
209 (lambda (x) (flet nil
(+ x
3)))
211 (get-content (label2uid "sub-goo")) => ((+ x
3))
212 (get-vars (label2uid "sub-goo")) => (x)
213 (get-dependencies (label2uid "sub-goo")) => nil