go ("int",_) = Just $ PDBS $ call "int" []
go ("pycall",_) = Just $ PDBS $ call "pycall" []
+ go ("range",_) = Just $ PDBS $ call "range" []
+
go ("in",2) = Just $ PDBS $ call "in_list" []
go ("<=",2) = Just $ PDBS $ infixOp "<="
for i, line in enumerate(block.split('\n')):
if (line.startswith('|') or i == 0) and reading:
if line.startswith('|'):
- line = line[1:]
+ line = ' ' + line[1:]
cmd.append(line)
else:
reading = False
functor/arity, `fn`. Returns the arguments of term as a tuple of intern idxs
and constants (possibly an empty tuple).
"""
-
- if fn == "true/0" :
-# assert item is True
- assert bool(item)
+ if fn == "true/0":
+ assert item is true
return
- if fn == "false/0" :
-# assert item is False
- assert not bool(item)
+ if fn == "false/0":
+ assert item is false
return
assert isinstance(item, Term)
assert item.fn == fn
# """
# ip()
-# def do_debug(self, line):
-# """
-# Development tool. Used for view Dyna's intermediate representations.
-# """
-# import debug
-# with file(dotdynadir / 'repl-debug-line.dyna', 'wb') as f:
-# f.write(line)
-# debug.main(f.name)
+ def do_debug(self, line):
+ """
+ Development tool. Used for view Dyna's intermediate representations.
+ """
+ import debug
+ with file(dotdynadir / 'repl-debug-line.dyna', 'wb') as f:
+ f.write(line)
+ debug.main(f.name)
# def do_run(self, filename):
# """
def uniform(a=0, b=1):
return _random() * (b - a) + a
+
+_range = range
+def range(*x):
+ return todyna(_range(*x))
+
def split(s, delim='\s+'):
return todynalist(re.split(delim, s))
> % a strange way to get back sentences as lists
| sentence(S, I) =
| T is b(tree(S)),
-| I in pycall("range", 0, numwords(T)),
+| I in range(0, numwords(T)),
| word(I, T).
|
| slen(S) max= _ is sentence(S, I), I.
-> :- dispos &cons(&,&).
-| :- dispos &nil.
-|
-| % binary rules
+> % binary rules
| rewrite(X, Y, Z) :=
| rules_tsv(Linenum, Cost, X, R),
| [Y, Z] is split(R, "\\s+"),
| phrase(S,X,I,K) += phrase(S,Y,I,J) + phrase(S,Z,J,K) + rewrite(X,Y,Z).
| phrase(S,W,I,I+1) += W is token(S,I), 0.
|
-| sentence_length(S) max= token(S,I), I+1.
+| sentence_length(S) max= _ is token(S,I), I+1.
| goal(S) += phrase(S, "ROOT", 0, sentence_length(S)).