Compare commits

..

No commits in common. 'db801bd8187a92a0e6ca81cec60e56a366f089b9' and '35ec0ece22ad1032f9f74284b0f1a06a40205937' have entirely different histories.

  1. 46
      lib.py
  2. 3
      lib/aids.klambda
  3. 2
      lib/booleans.klambda
  4. 15
      lib/kokoro.klambda
  5. 8
      lib/lists.klambda
  6. 8
      lib/loop.klambda
  7. 4
      test.klambda

@ -6,9 +6,10 @@
def execute(program):
import traceback, copy
def _execute(ctx, ids):
def _execute(ctx, ids, fns):
import sys, functools
lids = copy.copy(ids)
lfns = copy.copy(fns)
def _ident(name):
return ("identifier", name)
def _destr(t):
@ -54,19 +55,20 @@ def execute(program):
#print("abba", ctx, subs)
if ctx[0] == _ident("lambda"):
return ("lambda", (ctx[1], ctx[2]))
if ctx[0] == _ident("defun"):
fns[ctx[1]] = ctx[2]
return fns[ctx[1]]
elif ctx[0] == _ident("cond"):
return _execute(ctx[2], lids) if _truthy(_execute(ctx[1], lids)) else _execute(ctx[3], lids)
return _execute(ctx[2], lids, lfns) if _truthy(_execute(ctx[1], lids, lfns)) else _execute(ctx[3], lids, lfns)
subs = _fixarr(list(map(lambda a: _execute(a, lids), ctx)))
subs = _fixarr(list(map(lambda a: _execute(a, lids, lfns), ctx)))
if ctx[0][1][0] == "$":
return subs
elif ctx[0][1] == "id":
return subs[1] if len(subs[1:]) == 1 else subs[1:]
elif ctx[0] == _ident("miracle"):
return _box(eval(_destr(subs[1]))[_destr(subs[2])](*[(i if type(i) == type([]) else i[1]) for i in _fixarr(subs[3])]))
return _box(eval(_destr(subs[1]))[_destr(subs[2])](*[i[1] for i in _fixarr(subs[3])]))
elif ctx[0] == _ident("def"):
ids[ctx[1]] = subs[2]
return ids[ctx[1]]
@ -81,7 +83,7 @@ def execute(program):
elif ctx[0] == _ident("%"):
return (subs[1][0], subs[1][1]%subs[2][1])
elif ctx[0] == _ident("!"):
return ("number", 0.0 if _truthy(subs[1]) else 1.0)
return ("number", 0.0 if subs[1] else 1.0)
elif ctx[0] == _ident("=="):
return ("number", 1.0 if subs[1] == subs[2] else 0.0)
elif ctx[0] == _ident("="):
@ -93,37 +95,41 @@ def execute(program):
elif ctx[0] == _ident("conv"):
return (subs[1][1], float(subs[2][1]) if subs[1][1] == "number" else str(subs[2][1]))
elif ctx[0] == _ident("all"):
ret = _execute(subs[1], lids)
ret = _execute(subs[1], lids, lfns)
for statement in subs[2:]:
ret = _execute(statement, lids)
ret = _execute(statement, lids, lfns)
return ret
elif ctx[0] == _ident("at"):
return subs[2][int(subs[1][1])]
elif ctx[0] == _ident("insert"):
subs[3].insert(int(subs[1][1]), subs[2])
return subs[3]
elif ctx[0] in fns:
#print(subs)
prototype = fns[ctx[0]]
for idx, arg in enumerate(subs[1:]):
idx += 1
prototype = _recursereplace(prototype, ("identifier", f"${idx}"), arg)
#print(f"${idx}", prototype)
#print(prototype)
return _execute(prototype, lids, lfns)
else:
#print(f"{subs[0]} is not a valid function")
return _execute(subs, lids)
elif ctx[0][0] == "lambda":
prototype = ctx[0][1][1]
for idx, arg in enumerate(ctx[0][1][0]):
prototype = _recursereplace(prototype, arg, ctx[1:][idx])
return _execute(prototype, lids)
return subs
else:
#print("base", ctx)
if type(ctx) == type([]):
return list(
map(lambda a: _execute(a, lids), ctx)
map(lambda a: _execute(a, lids, lfns), ctx)
)
return ctx
idspace = {}
funcspace = {}
for strand in program:
try: _execute(strand, idspace)
try: _execute(strand, idspace, funcspace)
# _execute(strand)
except Exception as e:
print("failed in", strand, "with", e)
_execute(strand, idspace)
_execute(strand, idspace, funcspace)
#input()

@ -3,5 +3,4 @@
INCLUDE:./loop.klambda
INCLUDE:./lists.klambda
INCLUDE:./kokoro.klambda
INCLUDE:./booleans.klambda
INCLUDE:./kokoro.klambda

@ -1,2 +0,0 @@
(def true 1)
(def false 1)

@ -1,11 +1,10 @@
(def spit (lambda (cunny)
(miracle
"__builtins__" "print" (id cunny))))
(def input (lambda ()
(defun spit
(miracle
"__builtins__" "input" (""))))
(def thesis (lambda ()
"__builtins__" "print" (id $1)))
(defun input
(miracle
"__builtins__" "input" ("")))
(defun thesis
(spit
("this language belongs to makise kurisu. there are many like it, but this one is hers."))))
("this language belongs to makise kurisu. there are many like it, but this one is hers.")))
DEFINE:<3:(thesis)

@ -1,6 +1,6 @@
(def length (lambda (cunny)
(defun length
(miracle
"__builtins__" "len" (cunny))))
"__builtins__" "len" ((id $1))))
(def append (lambda (item, victim)
(insert (length victim) item victim)))
(defun append
(insert (length $2) $1 $2))

@ -1,8 +1,8 @@
DEFINE:loop:(def loop (lambda (counter max)\
DEFINE:loop:(defun loop\
(all\
statement\
(cond (= counter max)\
counter\
(loop (+ counter 1) max)))))\
(cond (= $1 $2)\
$1\
(loop (+ $1 1) $2))))\
(loop start end)\
:start:end:statement

@ -15,9 +15,9 @@ INCLUDE:./lib/aids.klambda
"adult (hag)"
"not adult (uoh)"))
loop:0:100:(spit (cond (% counter 15) (cond (% counter 5) (cond (% counter 3) counter "fizz") "buzz") "fizzbuzz"))
loop:0:100:(spit (cond (% $1 15) (cond (% $1 5) (cond (% $1 3) $1 "fizz") "buzz") "fizzbuzz"))
(def moeblob ("moe" "moe~" "kyun!!"))
loop:0:(- (length moeblob) 1):(spit (at counter moeblob))
loop:0:(length moeblob):(spit (at $1 moeblob))
(thesis)
Loading…
Cancel
Save