• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisiond1d91819cde5866fc4aa5dd597bc9094e459594c (tree)
Time2018-07-18 02:35:11
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

TextJoyType and inscribe command.

I took the plunge and added the meta-command "inscribe" to the library.
This is, of course, a very dangerous and powerful command. Use it
wisely.

Change Summary

Incremental Difference

diff -r bed68cfd6319 -r d1d91819cde5 joy/library.py
--- a/joy/library.py Mon Jul 16 20:28:53 2018 -0700
+++ b/joy/library.py Tue Jul 17 10:35:11 2018 -0700
@@ -280,6 +280,24 @@
280280
281281
282282 @inscribe
283+@FunctionWrapper
284+def inscribe_(stack, expression, dictionary):
285+ '''
286+ Create a new Joy function definition in the Joy dictionary. A
287+ definition is given as a string with a name followed by a double
288+ equal sign then one or more Joy functions, the body. for example:
289+
290+ sqr == dup mul
291+
292+ If you want the definition to persist over restarts, enter it into
293+ the definitions.txt resource.
294+ '''
295+ definition, stack = stack
296+ DefinitionWrapper.add_def(definition, dictionary)
297+ return stack, expression, dictionary
298+
299+
300+@inscribe
283301 @SimpleFunctionWrapper
284302 def parse(stack):
285303 '''Parse the string on the stack to a Joy expression.'''
diff -r bed68cfd6319 -r d1d91819cde5 joy/utils/types.py
--- a/joy/utils/types.py Mon Jul 16 20:28:53 2018 -0700
+++ b/joy/utils/types.py Tue Jul 17 10:35:11 2018 -0700
@@ -63,6 +63,11 @@
6363 prefix = 'i'
6464
6565
66+class TextJoyType(FloatJoyType):
67+ accept = basestring
68+ prefix = 't'
69+
70+
6671 class StackJoyType(AnyJoyType):
6772
6873 accept = tuple
@@ -283,6 +288,7 @@
283288 S = s0, s1, s2, s3, s4, s5, s6, s7, s8, s9 = map(StackJoyType, _R)
284289 F = f0, f1, f2, f3, f4, f5, f6, f7, f8, f9 = map(FloatJoyType, _R)
285290 I = i0, i1, i2, i3, i4, i5, i6, i7, i8, i9 = map(IntJoyType, _R)
291+T = t0, t1, t2, t3, t4, t5, t6, t7, t8, t9 = map(TextJoyType, _R)
286292
287293
288294 def defs():
@@ -297,6 +303,7 @@
297303 dupd = __(a2, a1), __(a2, a2, a1)
298304 dupdd = __(a3, a2, a1), __(a3, a3, a2, a1)
299305 first = __((a1, s1),), __(a1,)
306+ inscribe = __(t1), __()
300307 over = __(a2, a1), __(a2, a1, a2)
301308 pop = __(a1), __()
302309 popd = __(a2, a1,), __(a1)
Show on old repository browser