Compare commits

..

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

  1. 14
      lib.py
  2. 3
      lib/aids.klambda
  3. 21
      lib/loop.klambda
  4. 3
      lib/string.klambda
  5. 6
      test.klambda

@ -2,6 +2,8 @@
# BET UR MAD BAKADESU HAHAHAHHAHAHAHAH # BET UR MAD BAKADESU HAHAHAHHAHAHAHAH
# t. cirno # t. cirno
def execute(program): def execute(program):
import traceback, copy import traceback, copy
def _execute(ctx, ids): def _execute(ctx, ids):
@ -56,14 +58,13 @@ def execute(program):
return ("lambda", (ctx[1], ctx[2])) return ("lambda", (ctx[1], ctx[2]))
elif ctx[0] == _ident("cond"): 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) if _truthy(_execute(ctx[1], lids)) else _execute(ctx[3], lids)
elif ctx[0][1] == "id":
return ctx[1] if len(ctx[1:]) == 1 else ctx[1:]
subs = _fixarr(list(map(lambda a: _execute(a, lids), ctx))) subs = _fixarr(list(map(lambda a: _execute(a, lids), ctx)))
if ctx[0][1][0] == "$": if ctx[0][1][0] == "$":
return subs return subs
elif ctx[0][1] == "id":
return subs[1] if len(subs[1:]) == 1 else subs[1:]
elif ctx[0] == _ident("miracle"): 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 if type(i) == type([]) else i[1]) for i in _fixarr(subs[3])]))
elif ctx[0] == _ident("def"): elif ctx[0] == _ident("def"):
@ -106,12 +107,11 @@ def execute(program):
return _execute(subs, lids) return _execute(subs, lids)
elif ctx[0][0] == "lambda": elif ctx[0][0] == "lambda":
prototype = ctx[0][1][1] prototype = ctx[0][1][1]
ephemeral_space = copy.copy(ids)
for idx, arg in enumerate(ctx[0][1][0]): for idx, arg in enumerate(ctx[0][1][0]):
ephemeral_space[arg] = ctx[1:][idx] prototype = _recursereplace(prototype, arg, ctx[1:][idx])
#prototype = _recursereplace(prototype, arg, ctx[1:][idx]) return _execute(prototype, lids)
return _execute(prototype, ephemeral_space)
else: else:
#print("base", ctx)
if type(ctx) == type([]): if type(ctx) == type([]):
return list( return list(
map(lambda a: _execute(a, lids), ctx) map(lambda a: _execute(a, lids), ctx)

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

@ -1,13 +1,8 @@
(def loop (lambda (max i statement) DEFINE:loop:(def loop (lambda (counter max)\
(all (all\
statement statement\
(cond (= i max) (cond (= counter max)\
false counter\
(loop max (- i 1) (id statement)))))) (loop (+ counter 1) max)))))\
(loop start end)\
(def each :start:end:statement
(lambda (it action)
(loop 0 (- (length it) 1)
(id all
(def item (at i it))
action))))

@ -1,3 +0,0 @@
(def str2lst (lambda (l)
(miracle
"__builtins__" "list" (l))))

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