1 /** This file is part of Shapes.
3 ** Shapes is free software: you can redistribute it and/or modify
4 ** it under the terms of the GNU General Public License as published by
5 ** the Free Software Foundation, either version 3 of the License, or
8 ** Shapes is distributed in the hope that it will be useful,
9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ** GNU General Public License for more details.
13 ** You should have received a copy of the GNU General Public License
14 ** along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 ** Copyright 2013 Henrik Tidefelt
19 /** This example is demonstrates a trick using functions to represent graphs.
21 ** The data of a node is made the result of a function of no arguments.
22 ** This makes it possible for nodes to have references to other nodes
23 ** with bindings in the current scope.
25 ** The ability to refer to bindings in this way is allowed in the
26 ** language to support the creation of mutually recursive functions.
30 ##lookin ..Shapes..Control
31 ##lookin ..Shapes..Data
35 a: \ → (> value: `A´ out_neighbors: [vector b] <)
36 b: \ → (> value: `B´ out_neighbors: [vector c d] <)
37 c: \ → (> value: `C´ out_neighbors: [vector a] <)
38 d: \ → (> value: `D´ out_neighbors: [vector] <)
43 /** Test the graph by traversing edges down to a given depth, and collect
46 traverse: \ node depth →
48 [[node].out_neighbors.foldl
49 \ p e → ( p + [traverse e depth-'1] )
50 ( ` ´ + [node].value )
55 IO..•stdout << [traverse [g '0] '7] << "{n}