aboutsummaryrefslogtreecommitdiffstats
path: root/example/natargs_python_impl.md
blob: e80d09aa9181302d103bd88cc49672e021d65025 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
The arguments are stored as a trie using python dictonaries.  Each node
is a class consisting of two functions and a dict representing a subtree.

One function is a check on the length of the arguments, and the other
is the function executed on the list of arguments.

pseudocode
----------

```
def addargs(dict, h::[], chk, f):
	if dict[h] exists:
		throw exception
	dict[h].chk = chk
	dict[h].f = f
	dict[h].subtree = {}
def addargs(dict, h::t, chk, f):
	if dict[h] does not exist:
		dict[h].chk = None
		dict[h].f = None
	dict[h].subtree = addargs(dict[h].subtree, t, chk, f)

def execargs(dict, h::t):
	if dict[h] exists:
		f,args = execargs(dict[h].subtree, t)
		if f,args is None,None:
			if not dict[h].chk(t):
				return None,None
			return dict[h].f,t
		else:
			return f,args
	else:
		return None,None
```