Moved seq to global.
h3rald h3rald@h3rald.com
Sat, 03 Aug 2024 14:09:23 +0200
9 files changed,
488 insertions(+),
509 deletions(-)
M
minpkg/core/stdlib.nim
→
minpkg/core/stdlib.nim
@@ -13,7 +13,6 @@
import ../lib/[min_global, min_stack, - min_seq, min_dict, min_time, min_sys,@@ -39,7 +38,6 @@ if not MINRC.fileExists:
MINRC.writeFile("") i.global_module i.stack_module - i.seq_module i.dict_module i.time_module i.sys_module
M
minpkg/lib/min_global.nim
→
minpkg/lib/min_global.nim
@@ -1,7 +1,6 @@
import std/[critbits, strutils, - sequtils, json, parseopt, algorithm,@@ -10,6 +9,9 @@ streams,
random, bitops, macros, + tables, + sequtils, + sets, uri, nre, os,@@ -2037,6 +2039,402 @@ i.pushSym("interpolate")
def.symbol("=%") do (i: In): i.pushSym("apply-interpolate") + + # Sequence operations + + def.symbol("intersection") do (i: In): + let vals = i.expect("quot", "quot") + let q1 = sets.toHashSet(vals[0].qVal) + let q2 = sets.toHashSet(vals[1].qVal) + i.push items(sets.intersection(q2, q1)).toSeq.newVal + + def.symbol("union") do (i: In): + let vals = i.expect("quot", "quot") + let q1 = sets.toHashSet(vals[0].qVal) + let q2 = sets.toHashSet(vals[1].qVal) + i.push sets.items(sets.union(q2, q1)).toSeq.newVal + + def.symbol("difference") do (i: In): + let vals = i.expect("quot", "quot") + let q1 = sets.toHashSet(vals[0].qVal) + let q2 = sets.toHashSet(vals[1].qVal) + i.push sets.items(sets.difference(q2, q1)).toSeq.newVal + + def.symbol("symmetric-difference") do (i: In): + let vals = i.expect("quot", "quot") + let q1 = sets.toHashSet(vals[0].qVal) + let q2 = sets.toHashSet(vals[1].qVal) + i.push sets.items(sets.symmetricDifference(q2, q1)).toSeq.newVal + + def.symbol("concat") do (i: In): + let vals = i.expect("quot", "quot") + let q1 = vals[0] + let q2 = vals[1] + let q = q2.qVal & q1.qVal + i.push q.newVal + + def.symbol("first") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + if q.qVal.len == 0: + raiseOutOfBounds("Quotation is empty") + i.push q.qVal[0] + + def.symbol("last") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + if q.qVal.len == 0: + raiseOutOfBounds("Quotation is empty") + i.push q.qVal[q.qVal.len - 1] + + def.symbol("rest") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + if q.qVal.len == 0: + raiseOutOfBounds("Quotation is empty") + i.push q.qVal[1..q.qVal.len-1].newVal + + def.symbol("append") do (i: In): + let vals = i.expect("quot", "a") + let q = vals[0] + let v = vals[1] + i.push newVal(q.qVal & v) + + def.symbol("prepend") do (i: In): + let vals = i.expect("quot", "a") + let q = vals[0] + let v = vals[1] + i.push newVal(v & q.qVal) + + def.symbol("get") do (i: In): + let vals = i.expect("int", "quot") + let index = vals[0] + let q = vals[1] + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + i.push q.qVal[ix.int] + + def.symbol("get-raw") do (i: In): + let vals = i.expect("int", "quot") + let index = vals[0] + let q = vals[1] + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + let v = q.qVal[ix.int] + var rv = newDict(i.scope) + rv.objType = "rawval" + i.dset(rv, "type", v.typeName.newVal) + i.dset(rv, "val", v) + i.dset(rv, "str", newVal($v)) + i.push rv + + def.symbol("set") do (i: In): + let vals = i.expect("int", "a", "quot") + let index = vals[0] + let val = vals[1] + var q = newVal(vals[2].qVal) + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + q.qVal[ix.int] = val + i.push q + + def.symbol("set-sym") do (i: In): + let vals = i.expect("int", "'sym", "quot") + let index = vals[0] + let val = newSym(vals[1].getString) + var q = newVal(vals[2].qVal) + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + q.qVal[ix.int] = val + i.push q + + def.symbol("remove") do (i: In): + let vals = i.expect("int", "quot") + let index = vals[0] + let q = vals[1] + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + var res = newSeq[MinValue](0) + for x in 0..q.qVal.len-1: + if x == ix: + continue + res.add q.qVal[x] + i.push res.newVal + + def.symbol("insert") do (i: In): + let vals = i.expect("int", "a", "quot") + let index = vals[0] + let val = vals[1] + let q = vals[2] + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + var res = newSeq[MinValue](0) + for x in 0..q.qVal.len-1: + if x == ix: + res.add val + res.add q.qVal[x] + i.push res.newVal + + def.symbol("size") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + i.push q.qVal.len.newVal + + def.symbol("in?") do (i: In): + let vals = i.expect("a", "quot") + let v = vals[0] + let q = vals[1] + i.push q.qVal.contains(v).newVal + + def.symbol("map") do (i: In): + let vals = i.expect("quot", "quot") + var prog = vals[0] + let list = vals[1] + var res = newSeq[MinValue](0) + for litem in list.qVal: + i.push litem + i.dequote(prog) + res.add i.pop + i.push res.newVal + + def.symbol("quote-map") do (i: In): + let vals = i.expect("quot") + let list = vals[0] + var res = newSeq[MinValue](0) + for litem in list.qVal: + res.add @[litem].newVal + i.push res.newVal + + def.symbol("reverse") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + var res = newSeq[MinValue](0) + for c in countdown(q.qVal.len-1, 0): + res.add q.qVal[c] + i.push res.newVal + + def.symbol("filter") do (i: In): + let vals = i.expect("quot", "quot") + var filter = vals[0] + let list = vals[1] + var res = newSeq[MinValue](0) + for e in list.qVal: + i.push e + i.dequote(filter) + var check = i.pop + if check.isBool and check.boolVal == true: + res.add e + i.push res.newVal + + def.symbol("reject") do (i: In): + let vals = i.expect("quot", "quot") + var filter = vals[0] + let list = vals[1] + var res = newSeq[MinValue](0) + for e in list.qVal: + i.push e + i.dequote(filter) + var check = i.pop + if check.isBool and check.boolVal == false: + res.add e + i.push res.newVal + + def.symbol("any?") do (i: In): + let vals = i.expect("quot", "quot") + var filter = vals[0] + let list = vals[1] + var res = false.newVal + for e in list.qVal: + i.push e + i.dequote(filter) + var check = i.pop + if check.isBool and check.boolVal == true: + res = true.newVal + break + i.push res + + def.symbol("one?") do (i: In): + let vals = i.expect("quot", "quot") + var filter = vals[0] + let list = vals[1] + var res = false.newVal + for e in list.qVal: + i.push e + i.dequote(filter) + var check = i.pop + if check.isBool and check.boolVal == true: + if res == true.newVal: + res = false.newVal + break + res = true.newVal + i.push res + + def.symbol("all?") do (i: In): + let vals = i.expect("quot", "quot") + var filter = vals[0] + let list = vals[1] + var res = true.newVal + for e in list.qVal: + i.push e + i.dequote(filter) + var check = i.pop + if check.isBool and check.boolVal == false: + res = false.newVal + break + i.push res + + def.symbol("sort") do (i: In): + let vals = i.expect("quot", "quot") + var cmp = vals[0] + let list = vals[1] + var i2 = i + var minCmp = proc(a, b: MinValue): int {.closure.} = + i2.push a + i2.push b + i2.dequote(cmp) + let r = i2.pop + if r.isBool: + if r.isBool and r.boolVal == true: + return 1 + else: + return -1 + else: + raiseInvalid("Predicate quotation must return a boolean value") + var qList = list.qVal + sort[MinValue](qList, minCmp) + i.push qList.newVal + + def.symbol("shorten") do (i: In): + let vals = i.expect("int", "quot") + let n = vals[0] + let q = vals[1] + if n.intVal > q.qVal.len: + raiseInvalid("Quotation is too short") + i.push q.qVal[0..n.intVal.int-1].newVal + + def.symbol("take") do (i: In): + let vals = i.expect("int", "quot") + let n = vals[0] + let q = vals[1] + var nint = n.intVal + if nint > q.qVal.len: + nint = q.qVal.len + i.push q.qVal[0..nint-1].newVal + + def.symbol("drop") do (i: In): + let vals = i.expect("int", "quot") + let n = vals[0] + let q = vals[1] + var nint = n.intVal + if nint > q.qVal.len: + nint = q.qVal.len + i.push q.qVal[nint..q.qVal.len-1].newVal + + def.symbol("find") do (i: In): + let vals = i.expect("quot", "quot") + var test = vals[0] + let s = vals[1] + var result: MinValue + var res = -1 + var c = 0 + for el in s.qVal: + i.push el + i.dequote test + result = i.pop + if result.isBool and result.boolVal == true: + res = c + break + c.inc + i.push res.newVal + + def.symbol("reduce") do (i: In): + let vals = i.expect("quot", "a", "quot") + var q = vals[0] + var acc = vals[1] + let s = vals[2] + for el in s.qVal: + i.push acc + i.push el + i.dequote q + acc = i.pop + i.push acc + + def.symbol("map-reduce") do (i: In): + let vals = i.expect("quot", "quot", "quot") + var red = vals[0] + var map = vals[1] + let s = vals[2] + if s.qVal.len == 0: + raiseInvalid("Quotation must have at least one element") + i.push s.qVal[0] + i.dequote map + var acc = i.pop + for ix in 1..s.qVal.len-1: + i.push s.qVal[ix] + i.dequote map + i.push acc + i.dequote red + acc = i.pop + i.push acc + + def.symbol("partition") do (i: In): + let vals = i.expect("quot", "quot") + var test = vals[0] + var s = vals[1] + var tseq = newSeq[MinValue](0) + var fseq = newSeq[MinValue](0) + for el in s.qVal: + i.push el + i.dequote test + let res = i.pop + if res.isBool and res.boolVal == true: + tseq.add el + else: + fseq.add el + i.push tseq.newVal + i.push fseq.newVal + + def.symbol("slice") do (i: In): + let vals = i.expect("int", "int", "quot") + let finish = vals[0] + let start = vals[1] + let q = vals[2] + let st = start.intVal + let fn = finish.intVal + if st < 0 or fn > q.qVal.len-1: + raiseOutOfBounds("Index out of bounds") + elif fn < st: + raiseInvalid("End index must be greater than start index") + let rng = q.qVal[st.int..fn.int] + i.push rng.newVal + + def.symbol("harvest") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + var res = newSeq[MinValue](0) + for el in q.qVal: + if el.isQuotation and el.qVal.len == 0: + continue + res.add el + i.push res.newVal + + def.symbol("flatten") do (i: In): + let vals = i.expect("quot") + let q = vals[0] + var res = newSeq[MinValue](0) + for el in q.qVal: + if el.isQuotation: + for el2 in el.qVal: + res.add el2 + else: + res.add el + i.push res.newVal # Sigils
D
minpkg/lib/min_seq.nim
@@ -1,410 +0,0 @@
-import - std/[tables, - algorithm, - sets, - sequtils] -import - ../core/parser, - ../core/value, - ../core/interpreter, - ../core/utils - -proc seq_module*(i: In) = - - let def = i.define() - - def.symbol("intersection") do (i: In): - let vals = i.expect("quot", "quot") - let q1 = toHashSet(vals[0].qVal) - let q2 = toHashSet(vals[1].qVal) - i.push toSeq(items(q2.intersection(q1))).newVal - - def.symbol("union") do (i: In): - let vals = i.expect("quot", "quot") - let q1 = toHashSet(vals[0].qVal) - let q2 = toHashSet(vals[1].qVal) - i.push toSeq(items(q2.union(q1))).newVal - - def.symbol("difference") do (i: In): - let vals = i.expect("quot", "quot") - let q1 = toHashSet(vals[0].qVal) - let q2 = toHashSet(vals[1].qVal) - i.push toSeq(items(q2.difference(q1))).newVal - - def.symbol("symmetric-difference") do (i: In): - let vals = i.expect("quot", "quot") - let q1 = toHashSet(vals[0].qVal) - let q2 = toHashSet(vals[1].qVal) - i.push toSeq(items(q2.symmetricDifference(q1))).newVal - - def.symbol("concat") do (i: In): - let vals = i.expect("quot", "quot") - let q1 = vals[0] - let q2 = vals[1] - let q = q2.qVal & q1.qVal - i.push q.newVal - - def.symbol("first") do (i: In): - let vals = i.expect("quot") - let q = vals[0] - if q.qVal.len == 0: - raiseOutOfBounds("Quotation is empty") - i.push q.qVal[0] - - def.symbol("last") do (i: In): - let vals = i.expect("quot") - let q = vals[0] - if q.qVal.len == 0: - raiseOutOfBounds("Quotation is empty") - i.push q.qVal[q.qVal.len - 1] - - def.symbol("rest") do (i: In): - let vals = i.expect("quot") - let q = vals[0] - if q.qVal.len == 0: - raiseOutOfBounds("Quotation is empty") - i.push q.qVal[1..q.qVal.len-1].newVal - - def.symbol("append") do (i: In): - let vals = i.expect("quot", "a") - let q = vals[0] - let v = vals[1] - i.push newVal(q.qVal & v) - - def.symbol("prepend") do (i: In): - let vals = i.expect("quot", "a") - let q = vals[0] - let v = vals[1] - i.push newVal(v & q.qVal) - - def.symbol("get") do (i: In): - let vals = i.expect("int", "quot") - let index = vals[0] - let q = vals[1] - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - i.push q.qVal[ix.int] - - def.symbol("get-raw") do (i: In): - let vals = i.expect("int", "quot") - let index = vals[0] - let q = vals[1] - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - let v = q.qVal[ix.int] - var rv = newDict(i.scope) - rv.objType = "rawval" - i.dset(rv, "type", v.typeName.newVal) - i.dset(rv, "val", v) - i.dset(rv, "str", newVal($v)) - i.push rv - - def.symbol("set") do (i: In): - let vals = i.expect("int", "a", "quot") - let index = vals[0] - let val = vals[1] - var q = newVal(vals[2].qVal) - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - q.qVal[ix.int] = val - i.push q - - def.symbol("set-sym") do (i: In): - let vals = i.expect("int", "'sym", "quot") - let index = vals[0] - let val = newSym(vals[1].getString) - var q = newVal(vals[2].qVal) - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - q.qVal[ix.int] = val - i.push q - - def.symbol("remove") do (i: In): - let vals = i.expect("int", "quot") - let index = vals[0] - let q = vals[1] - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - var res = newSeq[MinValue](0) - for x in 0..q.qVal.len-1: - if x == ix: - continue - res.add q.qVal[x] - i.push res.newVal - - def.symbol("insert") do (i: In): - let vals = i.expect("int", "a", "quot") - let index = vals[0] - let val = vals[1] - let q = vals[2] - let ix = index.intVal - if q.qVal.len < ix or ix < 0: - raiseOutOfBounds("Index out of bounds") - var res = newSeq[MinValue](0) - for x in 0..q.qVal.len-1: - if x == ix: - res.add val - res.add q.qVal[x] - i.push res.newVal - - def.symbol("size") do (i: In): - let vals = i.expect("quot") - let q = vals[0] - i.push q.qVal.len.newVal - - def.symbol("in?") do (i: In): - let vals = i.expect("a", "quot") - let v = vals[0] - let q = vals[1] - i.push q.qVal.contains(v).newVal - - def.symbol("map") do (i: In): - let vals = i.expect("quot", "quot") - var prog = vals[0] - let list = vals[1] - var res = newSeq[MinValue](0) - for litem in list.qVal: - i.push litem - i.dequote(prog) - res.add i.pop - i.push res.newVal - - def.symbol("quote-map") do (i: In): - let vals = i.expect("quot") - let list = vals[0] - var res = newSeq[MinValue](0) - for litem in list.qVal: - res.add @[litem].newVal - i.push res.newVal - - def.symbol("reverse") do (i: In): - let vals = i.expect("quot") - let q = vals[0] - var res = newSeq[MinValue](0) - for c in countdown(q.qVal.len-1, 0): - res.add q.qVal[c] - i.push res.newVal - - def.symbol("filter") do (i: In): - let vals = i.expect("quot", "quot") - var filter = vals[0] - let list = vals[1] - var res = newSeq[MinValue](0) - for e in list.qVal: - i.push e - i.dequote(filter) - var check = i.pop - if check.isBool and check.boolVal == true: - res.add e - i.push res.newVal - - def.symbol("reject") do (i: In): - let vals = i.expect("quot", "quot") - var filter = vals[0] - let list = vals[1] - var res = newSeq[MinValue](0) - for e in list.qVal: - i.push e - i.dequote(filter) - var check = i.pop - if check.isBool and check.boolVal == false: - res.add e - i.push res.newVal - - def.symbol("any?") do (i: In): - let vals = i.expect("quot", "quot") - var filter = vals[0] - let list = vals[1] - var res = false.newVal - for e in list.qVal: - i.push e - i.dequote(filter) - var check = i.pop - if check.isBool and check.boolVal == true: - res = true.newVal - break - i.push res - - def.symbol("one?") do (i: In): - let vals = i.expect("quot", "quot") - var filter = vals[0] - let list = vals[1] - var res = false.newVal - for e in list.qVal: - i.push e - i.dequote(filter) - var check = i.pop - if check.isBool and check.boolVal == true: - if res == true.newVal: - res = false.newVal - break - res = true.newVal - i.push res - - def.symbol("all?") do (i: In): - let vals = i.expect("quot", "quot") - var filter = vals[0] - let list = vals[1] - var res = true.newVal - for e in list.qVal: - i.push e - i.dequote(filter) - var check = i.pop - if check.isBool and check.boolVal == false: - res = false.newVal - break - i.push res - - def.symbol("sort") do (i: In): - let vals = i.expect("quot", "quot") - var cmp = vals[0] - let list = vals[1] - var i2 = i - var minCmp = proc(a, b: MinValue): int {.closure.} = - i2.push a - i2.push b - i2.dequote(cmp) - let r = i2.pop - if r.isBool: - if r.isBool and r.boolVal == true: - return 1 - else: - return -1 - else: - raiseInvalid("Predicate quotation must return a boolean value") - var qList = list.qVal - sort[MinValue](qList, minCmp) - i.push qList.newVal - - def.symbol("shorten") do (i: In): - let vals = i.expect("int", "quot") - let n = vals[0] - let q = vals[1] - if n.intVal > q.qVal.len: - raiseInvalid("Quotation is too short") - i.push q.qVal[0..n.intVal.int-1].newVal - - def.symbol("take") do (i: In): - let vals = i.expect("int", "quot") - let n = vals[0] - let q = vals[1] - var nint = n.intVal - if nint > q.qVal.len: - nint = q.qVal.len - i.push q.qVal[0..nint-1].newVal - - def.symbol("drop") do (i: In): - let vals = i.expect("int", "quot") - let n = vals[0] - let q = vals[1] - var nint = n.intVal - if nint > q.qVal.len: - nint = q.qVal.len - i.push q.qVal[nint..q.qVal.len-1].newVal - - def.symbol("find") do (i: In): - let vals = i.expect("quot", "quot") - var test = vals[0] - let s = vals[1] - var result: MinValue - var res = -1 - var c = 0 - for el in s.qVal: - i.push el - i.dequote test - result = i.pop - if result.isBool and result.boolVal == true: - res = c - break - c.inc - i.push res.newVal - - def.symbol("reduce") do (i: In): - let vals = i.expect("quot", "a", "quot") - var q = vals[0] - var acc = vals[1] - let s = vals[2] - for el in s.qVal: - i.push acc - i.push el - i.dequote q - acc = i.pop - i.push acc - - def.symbol("map-reduce") do (i: In): - let vals = i.expect("quot", "quot", "quot") - var red = vals[0] - var map = vals[1] - let s = vals[2] - if s.qVal.len == 0: - raiseInvalid("Quotation must have at least one element") - i.push s.qVal[0] - i.dequote map - var acc = i.pop - for ix in 1..s.qVal.len-1: - i.push s.qVal[ix] - i.dequote map - i.push acc - i.dequote red - acc = i.pop - i.push acc - - def.symbol("partition") do (i: In): - let vals = i.expect("quot", "quot") - var test = vals[0] - var s = vals[1] - var tseq = newSeq[MinValue](0) - var fseq = newSeq[MinValue](0) - for el in s.qVal: - i.push el - i.dequote test - let res = i.pop - if res.isBool and res.boolVal == true: - tseq.add el - else: - fseq.add el - i.push tseq.newVal - i.push fseq.newVal - - def.symbol("slice") do (i: In): - let vals = i.expect("int", "int", "quot") - let finish = vals[0] - let start = vals[1] - let q = vals[2] - let st = start.intVal - let fn = finish.intVal - if st < 0 or fn > q.qVal.len-1: - raiseOutOfBounds("Index out of bounds") - elif fn < st: - raiseInvalid("End index must be greater than start index") - let rng = q.qVal[st.int..fn.int] - i.push rng.newVal - - def.symbol("harvest") do (i: In): - let vals = i.expect("quot") - let q = vals[0] - var res = newSeq[MinValue](0) - for el in q.qVal: - if el.isQuotation and el.qVal.len == 0: - continue - res.add el - i.push res.newVal - - def.symbol("flatten") do (i: In): - let vals = i.expect("quot") - let q = vals[0] - var res = newSeq[MinValue](0) - for el in q.qVal: - if el.isQuotation: - for el2 in el.qVal: - res.add el2 - else: - res.add el - i.push res.newVal - - def.finalize("seq")
M
next-release.md
→
next-release.md
@@ -3,6 +3,7 @@
- All symbols defined in the **num** module have been moved to the **global** module. - All symbols defined in the **logic** module have been moved to the **global** module. - All symbols defined in the **str** module have been moved to the **global** module. +- All symbols defined in the **seq** module have been moved to the **global** module. ### New Features
M
prelude.min
→
prelude.min
@@ -1,6 +1,5 @@
; Imports 'stack import -'seq import 'dict import 'time import 'io import
M
site/contents/learn-extending.md
→
site/contents/learn-extending.md
@@ -42,7 +42,6 @@ ; Imports
'io import 'sys import 'stack import -'seq import 'dict import 'time import 'fs import
M
tests/all.min
→
tests/all.min
@@ -15,7 +15,6 @@ 'fs load
'io load 'global load 'math load -'seq load 'stack load 'sys load 'time load
M
tests/global.min
→
tests/global.min
@@ -719,6 +719,94 @@ ("0x00FF0000" dup from-hex to-hex ==) test.assert
("0o00007473" dup from-oct to-oct ==) test.assert ("123" dup from-dec to-dec ==) test.assert + ;; Sequence operations + + ((1 2) (3 4) concat (1 2 3 4) ==) test.assert + + ((1 2 3) first 1 ==) test.assert + + ((1 2 3) last 3 ==) test.assert + + ((1 2 3) rest (2 3) ==) test.assert + + (4 (1 2 3) append (1 2 3 4) ==) test.assert + + (0 (1 2 3) prepend (0 1 2 3) ==) test.assert + + ((1 2 3 4) 2 get 3 ==) test.assert + + ((a b c) 1 get-raw "type" dget "sym" ==) test.assert + + ((1 2 3 4) 222 2 set (1 2 222 4) ==) test.assert + + ((1 2 3) "test" 1 set-sym (1 test 3) ==) test.assert + + ((1 2 3 4) 2 remove (1 2 4) ==) test.assert + + ((1 2 3 4) 333 2 insert (1 2 333 3 4) ==) test.assert + + ((1 2 3) size 3 ==) test.assert + + ((1 2 3 4) 5 in? false ==) test.assert + + ((1 2 3 4) 2 in?) test.assert + + ((1 2 3 4) (2 +) map (3 4 5 6) ==) test.assert + + ((5 4 3 2 1) reverse (1 2 3 4 5) ==) test.assert + + ((3 4 7 2 4 6 5 6) '> sort (2 3 4 4 5 6 6 7) ==) test.assert + + ((3 4 7 2 4 6 5 6) '< sort (7 6 6 5 4 4 3 2) ==) test.assert + + ((1 2 3 4 5) 3 shorten (1 2 3) ==) test.assert + + ((1 2 3 4 5) 3 take (1 2 3) ==) test.assert + + ((1 2 3 4 5) 6 take (1 2 3 4 5) ==) test.assert + + ((1 2 3 4 5) 3 drop (4 5) ==) test.assert + + ((1 2 3 4 5) 6 drop () ==) test.assert + + ((1 2 3 4 5) (2 >) find 2 ==) test.assert + + ((1 2 3 4 5) 1 (*) reduce 120 ==) test.assert + + ((1 3 5) (dup *) (+) map-reduce 35 ==) test.assert + + ((1 2 3 4 5 6) (odd?) partition get-stack ((1 3 5) (2 4 6)) ==) test.assert + + ((1 2 3 4 5 6) (odd?) reject (2 4 6) ==) test.assert + + ((1 2 3 4 5 6) 2 4 slice (3 4 5) ==) test.assert + + ((2 3 () 4 (3 4) () () "test") harvest (2 3 4 (3 4) "test") ==) test.assert + + ((1 2 3 (4 5 6) 7 (8 9)) flatten (1 2 3 4 5 6 7 8 9) ==) test.assert + + ((2 3 + 4 *) quote-map ('+ ==) find 2 ==) test.assert + + ((2 4 6 8) 'even? all?) test.assert + + ((2 4 3 6 8) 'even? all? not) test.assert + + ((1 2 3 4) 'odd? one? not) test.assert + + ((1 2 4) 'odd? one?) test.assert + + ((1 2 3 4) 'odd? any?) test.assert + + ((2 4 6 8) 'odd? any? not) test.assert + + ((1 2 "test") ("test" "a" true 1) intersection (1 "test") ==) test.assert + + ((1 2 "test") ("test" "a" true 1) union (true 1 "test" "a" 2) ==) test.assert + + ((1 2 "test") ("test" "a" true 1) difference (2) ==) test.assert + + ((1 2 "test") ("test" "a" true 1) symmetric-difference (true "a" 2) ==) test.assert + test.report ;; Tidy up clear-stack
D
tests/seq.min
@@ -1,93 +0,0 @@
-'min-test require :test -;;; - -"seq" test.describe - - ((1 2) (3 4) concat (1 2 3 4) ==) test.assert - - ((1 2 3) first 1 ==) test.assert - - ((1 2 3) last 3 ==) test.assert - - ((1 2 3) rest (2 3) ==) test.assert - - (4 (1 2 3) append (1 2 3 4) ==) test.assert - - (0 (1 2 3) prepend (0 1 2 3) ==) test.assert - - ((1 2 3 4) 2 get 3 ==) test.assert - - ((a b c) 1 get-raw "type" dget "sym" ==) test.assert - - ((1 2 3 4) 222 2 set (1 2 222 4) ==) test.assert - - ((1 2 3) "test" 1 set-sym (1 test 3) ==) test.assert - - ((1 2 3 4) 2 remove (1 2 4) ==) test.assert - - ((1 2 3 4) 333 2 insert (1 2 333 3 4) ==) test.assert - - ((1 2 3) size 3 ==) test.assert - - ((1 2 3 4) 5 in? false ==) test.assert - - ((1 2 3 4) 2 in?) test.assert - - ((1 2 3 4) (2 +) map (3 4 5 6) ==) test.assert - - ((5 4 3 2 1) reverse (1 2 3 4 5) ==) test.assert - - ((3 4 7 2 4 6 5 6) '> sort (2 3 4 4 5 6 6 7) ==) test.assert - - ((3 4 7 2 4 6 5 6) '< sort (7 6 6 5 4 4 3 2) ==) test.assert - - ((1 2 3 4 5) 3 shorten (1 2 3) ==) test.assert - - ((1 2 3 4 5) 3 take (1 2 3) ==) test.assert - - ((1 2 3 4 5) 6 take (1 2 3 4 5) ==) test.assert - - ((1 2 3 4 5) 3 drop (4 5) ==) test.assert - - ((1 2 3 4 5) 6 drop () ==) test.assert - - ((1 2 3 4 5) (2 >) find 2 ==) test.assert - - ((1 2 3 4 5) 1 (*) reduce 120 ==) test.assert - - ((1 3 5) (dup *) (+) map-reduce 35 ==) test.assert - - ((1 2 3 4 5 6) (odd?) partition get-stack ((1 3 5) (2 4 6)) ==) test.assert - - ((1 2 3 4 5 6) (odd?) reject (2 4 6) ==) test.assert - - ((1 2 3 4 5 6) 2 4 slice (3 4 5) ==) test.assert - - ((2 3 () 4 (3 4) () () "test") harvest (2 3 4 (3 4) "test") ==) test.assert - - ((1 2 3 (4 5 6) 7 (8 9)) flatten (1 2 3 4 5 6 7 8 9) ==) test.assert - - ((2 3 + 4 *) quote-map ('+ ==) find 2 ==) test.assert - - ((2 4 6 8) 'even? all?) test.assert - - ((2 4 3 6 8) 'even? all? not) test.assert - - ((1 2 3 4) 'odd? one? not) test.assert - - ((1 2 4) 'odd? one?) test.assert - - ((1 2 3 4) 'odd? any?) test.assert - - ((2 4 6 8) 'odd? any? not) test.assert - - ((1 2 "test") ("test" "a" true 1) intersection (1 "test") ==) test.assert - - ((1 2 "test") ("test" "a" true 1) union (true 1 "test" "a" 2) ==) test.assert - - ((1 2 "test") ("test" "a" true 1) difference (2) ==) test.assert - - ((1 2 "test") ("test" "a" true 1) symmetric-difference (true "a" 2) ==) test.assert - - test.report - clear-stack