Show HN: Plain Document Status
thoughts.h3rald.com2 ポイント投稿者 h3rald0 コメント
args
(compiled?)
(0)
(1)
if get int
(dup 0 ==) (1 +)
(dup 1 -) (*) linrec
puts
Note how I am getting the first or second argument from the command line depending if I am running the program through the interpreter (min factorial.min 5) or as a stand-alone executable (./factorial 5). min -c factorial.min
...the following Nim code gets generated. As you can see, it's mostly just pushing items on the stack :) import min
MINCOMPILED = true
var i = newMinInterpreter("factorial.min")
i.stdLib()
### factorial.min (main)
i.push MinValue(kind: minSymbol, symVal: "args", column: 4, line: 1, filename: "factorial.min")
var q1 = newSeq[MinValue](0)
q1.add MinValue(kind: minSymbol, symVal: "compiled?", column: 10, line: 2, filename: "factorial.min")
i.push MinValue(kind: minQuotation, qVal: q1)
var q2 = newSeq[MinValue](0)
q2.add MinValue(kind: minInt, intVal: 0)
i.push MinValue(kind: minQuotation, qVal: q2)
var q3 = newSeq[MinValue](0)
q3.add MinValue(kind: minInt, intVal: 1)
i.push MinValue(kind: minQuotation, qVal: q3)
i.push MinValue(kind: minSymbol, symVal: "if", column: 2, line: 5, filename: "factorial.min")
i.push MinValue(kind: minSymbol, symVal: "get", column: 6, line: 5, filename: "factorial.min")
i.push MinValue(kind: minSymbol, symVal: "int", column: 10, line: 5, filename: "factorial.min")
var q4 = newSeq[MinValue](0)
q4.add MinValue(kind: minSymbol, symVal: "dup", column: 4, line: 6, filename: "factorial.min")
q4.add MinValue(kind: minInt, intVal: 0)
q4.add MinValue(kind: minSymbol, symVal: "==", column: 9, line: 6, filename: "factorial.min")
i.push MinValue(kind: minQuotation, qVal: q4)
var q5 = newSeq[MinValue](0)
q5.add MinValue(kind: minInt, intVal: 1)
q5.add MinValue(kind: minSymbol, symVal: "+", column: 15, line: 6, filename: "factorial.min")
i.push MinValue(kind: minQuotation, qVal: q5)
var q6 = newSeq[MinValue](0)
q6.add MinValue(kind: minSymbol, symVal: "dup", column: 4, line: 7, filename: "factorial.min")
q6.add MinValue(kind: minInt, intVal: 1)
q6.add MinValue(kind: minSymbol, symVal: "-", column: 8, line: 7, filename: "factorial.min")
i.push MinValue(kind: minQuotation%, qVal: q6)
var q7 = newSeq[MinValue](0)
q7.add MinValue(kind: minSymbol, symVal: "*", column: 12, line: 7, filename: "factorial.min")
i.push MinValue(kind: minQuotation, qVal: q7)
i.push MinValue(kind: minSymbol, symVal: "linrec", column: 20, line: 7, filename: "factorial.min")
i.push MinValue(kind: minSymbol, symVal: "puts", column: 4, line: 8, filename: "factorial.min") . ls-r
(mtime now 3600 - >)
filter
Can you guess what it does? You might, but what about this: . ls-r :files
((mtime > (now - 3600)) ><) =changed-in-last-hour
@files #changed-in-last-hour filter
Now ok, I went insane with sigils and weird operators but:
- creating variables helps
- using infix notation via the infix-dequote (><) operator makes expressions much more readable proc createIndex*(store: Datastore, indexId, field: string) =
let query = sql("CREATE INDEX json_index_$1 ON documents(json_extract(data, ?) COLLATE NOCASE) WHERE json_valid(data)" % [indexId])
store.begin()
store.db.exec(query, field)
store.commit()
Basically, SQLite supports indexes in arbitrary expressions and so you can use it in conjunction with json_extract. In this case, field is an arbitrary json path.
min does not have a C FLI essentially because it has a "Nim FLI". It is really easy to add new symbols to the language using a Nim API (which is also used internally to define all symbols of the language).
See https://min-lang.org/learn-extending/ for more info. Maybe I should generate some Nim docs for the public API though... but it's really easy to use, and you can check the lib folder of the repo for examples: https://github.com/h3rald/min/tree/master/minpkg/lib