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 "bootstart.el")
26 (defun filter (pred stuff
)
28 (dolist (item stuff
(reverse ans
))
29 (if (funcall pred item
)
30 (setq ans
(cons item ans
))
33 ;; Make a new scholium-based document.
38 (setq article-list
(gen-gnd))
40 ;; Put the main program in a node.
49 ;; Put two subroutines in their own nodes.
62 ;; Make links from the main program to its subroutines. The text of
63 ;; the link states the name of the subroutine.
65 (ins-nod 1 '(sub foo
) 2)
68 (ins-nod 1 '(sub goo
) 3)
71 ;; Add nodes and links for the variables.
78 ;; Argument list of node 1 (points to node 6, which contains nil)
79 ;; In order words, List 1 doesn't have any unbound variables.
88 ;; Argument listS of node 2 and node 3
95 ; We provide functions to identify scholia of type
96 ;; var and sub and retrieve the appropriate data.
98 (defun get-dependencies (art)
100 (list (cadr (get-txt x
))
108 (defun get-vars (art)
113 (get-txt (get-src x
)))
116 (equal 'var
(get-txt y
)))
119 ;; Here is the output they produce:
129 ;; Using these functions, we evaluate our node. Remember that the code
130 ;; at node 1 is supposed to invoke foo and goo, which are found as
131 ;; scholia attached to node 2. As we see, it does this correctly.
139 ;; In case you're interested, here are the gory details of how
140 ;; node-fun wrapped up the code inside the node.
147 (lambda nil
(flet ((goo (x) (apply (node-fun 3
150 (quote get-dependencies
))
152 (foo (x) (apply (node-fun 2
155 (quote get-dependencies
))
157 (list (foo 5) (goo 6))))
165 (lambda (x) (flet nil
(+ x
3)))
167 (get-txt 3) => ((+ x
3))
169 (get-dependencies 3) => nil
173 (set-txt 6 '(y)) => (y)
179 => (lambda (y) (flet ((goo (x) (apply (node-fun 3 (quote get-txt
) (quote get-vars
) (quote get-dependencies
)) (list x
)))
180 (foo (x) (apply (node-fun 2 (quote get-txt
) (quote get-vars
) (quote get-dependencies
)) (list x
))))
181 (list (foo 5) (goo 6))))
183 (get-txt 1) => ((list (foo 5) (goo 6)))
184 (set-txt 1 '((list (foo 5) (goo y
))))((list (foo 5) (goo y
)))
190 (defun joe-function (y)
191 (flet ((goo (x) (apply (node-fun 3 (quote get-txt
) (quote get-vars
) (quote get-dependencies
)) (list x
)))
192 (foo (x) (apply (node-fun 2 (quote get-txt
) (quote get-vars
) (quote get-dependencies
)) (list x
))))
193 (list (foo 5) (goo y
))))
195 (joe-function 16)(25 19)