Phase 6: slurp, spit, read-line, range 3-arg, repeat/cycle/iterate, interleave

Phase 6 Clojure Core Library now complete (except meta):
- T6.3: slurp (alias for file/read)
- T6.4: spit (alias for file/write)
- T6.5: read-line (stdin input)
- T6.6: range with 3 args (start, end, step)
- T6.7: repeat, cycle, iterate (eager implementations)
- T6.9: interleave
- Updated TASKS.md and ROADMAP.md
This commit is contained in:
2026-05-08 19:24:06 +03:00
parent 6dfc2a9308
commit 19ef69bf5b
4 changed files with 113 additions and 15 deletions
+28 -4
View File
@@ -109,6 +109,14 @@ proc runtimeName(op: string): string =
of "git/diff": "cljGitDiff"
of "git/log": "cljGitLog"
of "disj": "cljDisj"
of "slurp": "cljFileRead"
of "spit": "cljFileWrite"
of "read-line": "cljReadLine"
of "repeat": "cljRepeat"
of "cycle": "cljCycle"
of "iterate": "cljIterate"
of "interleave": "cljInterleave"
of "quot": "cljQuot"
else: ""
proc emitArgs(args: seq[CljVal]): string =
@@ -779,14 +787,30 @@ proc emitSpecialForm(items: seq[CljVal], indent: int): string =
return sp & "cljSet(@[" & emitExpr(arg, 0) & "])"
of "range":
if items.len < 1 or items.len > 3:
raise newException(EmitterError, "range requires 0, 1, or 2 arguments")
if items.len < 1 or items.len > 4:
raise newException(EmitterError, "range requires 0, 1, 2, or 3 arguments")
if items.len == 1:
return sp & "cljList(@[])"
elif items.len == 2:
return sp & "cljRange(" & emitExpr(items[1], 0) & ")"
else:
elif items.len == 3:
return sp & "cljRange(" & emitExpr(items[1], 0) & ", " & emitExpr(items[2], 0) & ")"
else:
return sp & "cljRange3(" & emitExpr(items[1], 0) & ", " & emitExpr(items[2], 0) & ", " & emitExpr(items[3], 0) & ")"
of "iterate":
if items.len != 4:
raise newException(EmitterError, "iterate requires 3 arguments (n, f, x)")
let fnArg = items[2]
let nArg = emitExpr(items[1], 0)
let xArg = emitExpr(items[3], 0)
if fnArg.kind == ckSymbol:
let rn = runtimeName(fnArg.symName)
if rn.len > 0:
return sp & "cljIterate(" & nArg & ", cljFn(proc(args: seq[CljVal]): CljVal = " & rn & "(args)), " & xArg & ")"
return sp & "cljIterate(" & nArg & ", cljFn(proc(args: seq[CljVal]): CljVal = " & mangleName(fnArg.symName) & "(args[0])), " & xArg & ")"
else:
return sp & "cljIterate(" & nArg & ", " & emitExpr(fnArg, 0) & ", " & xArg & ")"
else:
# ---- Nim interop: nim/module/function ----
@@ -882,7 +906,7 @@ proc emitSpecialForm(items: seq[CljVal], indent: int): string =
# Variadic functions take seq[CljVal]
let variadic = op in ["+", "-", "*", "/", "=", ">", "<", ">=", "<=", "not=",
"println", "prn", "print", "str", "pr-str",
"concat", "min", "max", "merge"]
"concat", "min", "max", "merge", "interleave"]
var call: string
if variadic and argParts.len > 0:
call = rn & "(@[" & argParts.join(", ") & "])"