all repos — min @ 4621824b3e58e6496b12d806eb8270fc06c423f3

A small but practical concatenative programming language.

Implemented sort operator.
h3rald h3rald@h3rald.com
Fri, 07 Oct 2016 19:46:45 +0200
commit

4621824b3e58e6496b12d806eb8270fc06c423f3

parent

b787fce00d8baf5d02c68edc7b113a0fafb6bc7e

3 files changed, 29 insertions(+), 3 deletions(-)

jump to
M lib/min_lang.nimlib/min_lang.nim

@@ -2,7 +2,8 @@ import

critbits, strutils, os, - json + json, + algorithm import ../core/consts, ../core/parser,

@@ -565,6 +566,26 @@ var check = i.pop

if check.isBool and check.boolVal == true: res.add e i.push res.newVal + + .symbol("sort") do (i: In): + var cmp, list: MinValue + i.reqTwoQuotations cmp, list + var i2 = i + var minCmp = proc(a, b: MinValue): int {.closure.}= + i2.push a + i2.push b + i2.unquote("<sort-cmp>", cmp) + let r = i2.pop + if r.isBool: + if 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 .symbol("linrec") do (i: In): var r2, r1, t, p: MinValue
M minim.vimminim.vim

@@ -10,7 +10,7 @@ endif

setl iskeyword+=?,$,+,*,/,%,=,>,<,&,-,',.,:,@,~,^,! -syntax keyword minimDefaultSymbol ! != $ & ' * + - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes and append apply ask at atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize case cd chmod choose clear-stack column-print concat confirm cons cp cpu crypto ctime datetime ddel debug debug? decode decrypt define delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dump-stack dup dupd echo encode encrypt env? eq eval even? exit fappend file? filename filter first float float? foreach fperms fread from-json fs fsize fstats ftype fwrite gets get-stack getenv gt gte hardlink hidden? i id ifte import include indent inspect int int? interpolate interval io join k keys length linrec load load-symbol logic lowercase ls ls-r lt lte map match md5 mkdir mod module mtime mv newline not noteq now num number? odd? or os password pop popd pred prepend print print! prompt puts puts! putenv q quit quotation? quote raise regex remove-symbol repeat replace rest rm rmdir run save-symbol scope scope? seal search select set-stack sha1 sha224 sha256 sha384 sha512 sigil sigils sip size sleep source split stored-symbols str string string? strip succ swap swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unit unquote uppercase values version which while with xor zap contains +syntax keyword minimDefaultSymbol ! != $ & ' * + - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes and append apply ask at atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize case cd chmod choose clear-stack column-print concat confirm cons cp cpu crypto ctime datetime ddel debug debug? decode decrypt define delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dump-stack dup dupd echo encode encrypt env? eq eval even? exit fappend file? filename filter first float float? foreach fperms fread from-json fs fsize fstats ftype fwrite gets get-stack getenv gt gte hardlink hidden? i id ifte import include indent inspect int int? interpolate interval io join k keys length linrec load load-symbol logic lowercase ls ls-r lt lte map match md5 mkdir mod module mtime mv newline not noteq now num number? odd? or os password pop popd pred prepend print print! prompt puts puts! putenv q quit quotation? quote raise regex remove-symbol repeat replace rest rm rmdir run save-symbol scope scope? seal search select set-stack sha1 sha224 sha256 sha384 sha512 sigil sigils sip size sleep sort source split stored-symbols str string string? strip succ swap swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unit unquote uppercase values version which while with xor zap contains syntax match minimDefaultSigil ;\<[:@'~!$%&$=<>^*]; contained
M tests/lang.mintests/lang.min

@@ -1,4 +1,5 @@

-'test include +'test load +'test import "lang" describe

@@ -167,6 +168,10 @@ ((3 <) (false))

((3 >) (true)) ) case ) assert + + ((3 4 7 2 4 6 5 6) '> sort (2 3 4 4 5 6 6 7) ==) assert + + ((3 4 7 2 4 6 5 6) '< sort (7 6 6 5 4 4 3 2) ==) assert report ; Tidy up