all repos — min @ 3bec33c4d30ad8329f44972afac0bb342a314866

A small but practical concatenative programming language.

Added ord, chr, dtype
h3rald h3rald@h3rald.com
Wed, 17 Jun 2020 11:02:28 +0200
commit

3bec33c4d30ad8329f44972afac0bb342a314866

parent

1d555258128e0345415220db952e1a3957215af3

M lib/min_dict.nimlib/min_dict.nim

@@ -64,6 +64,10 @@ if d.dhas(k):

i.dset(res, k, i.dget(d, k)) i.push res + def.symbol("dtype") do (i: In): + let vals = i.expect("dict") + i.push vals[0].objType.newVal + def.sigil("?") do (i: In): i.push("dhas?".newSym)
M lib/min_str.nimlib/min_str.nim

@@ -74,6 +74,19 @@ let vals = i.expect("'sym")

let s = vals[0] i.push s.getString.capitalizeAscii.newVal + def.symbol("ord") do (i: In): + let vals = i.expect("'sym") + let s = vals[0] + if s.getString.len != 1: + raiseInvalid("Symbol ord requires a string containing a single character.") + i.push s.getString[0].ord.newVal + + def.symbol("chr") do (i: In): + let vals = i.expect("int") + let n = vals[0] + let c = n.intVal.chr + i.push ($c).newVal + def.symbol("titleize") do (i: In): let vals = i.expect("'sym") let s = vals[0]
M site/contents/_defs_.mdsite/contents/_defs_.md

@@ -10,7 +10,6 @@ {{4 => [<sub>4</sub>](class:kwd)}}

{{e => [dict:error](class:kwd)}} {{tinfo => [dict:timeinfo](class:kwd)}} {{d => [dict](class:kwd)}} -{{m => [module](class:kwd)}} {{d1 => [dict<sub>1</sub>](class:kwd)}} {{d2 => [dict<sub>2</sub>](class:kwd)}} {{flt => [float](class:kwd)}}
M site/contents/reference-dict.mdsite/contents/reference-dict.md

@@ -47,5 +47,8 @@

{#op||dset||{{d}} {{any}} {{sl}}||{{d}}|| Sets the value of the {{sl}} of {{d1}} to {{any}}, and returns the modified dictionary {{d}}. #} +{#op||dtype||{{d}}||{{s}}|| +Returns a string set to the type of {{d}} (empty if the dictionary has no type). #} + {#op||dvalues||{{d}}||({{a0p}})|| Returns a quotation containing all the values of dictionary {{d}}. #}
M site/contents/reference-lang.mdsite/contents/reference-lang.md

@@ -249,8 +249,8 @@

{#op||remove-symbol||{{sl}}||{{null}}|| Removes the symbol {{sl}} from the [.min\_symbols](class:file) file. #} -{#op||ROOT||{{null}}||{{q}}|| -Returns an empty quotation holding a reference to the [ROOT](class:kwd) scope. +{#op||ROOT||{{null}}||{{d}}|| +Returns a module holding a reference to the [ROOT](class:kwd) scope. > > %tip% > > Tip

@@ -261,8 +261,8 @@

{#op||save-symbol||{{sl}}||{{null}}|| Saves the contents of symbol {{sl}} to the [.min\_symbols](class:file) file. #} -{#op||scope||{{null}}||({{m}})|| -> Returns a module {{m}} corresponding to the current scope. +{#op||scope||{{null}}||{{d}}|| +> Returns a dictionary {{d}} holding a reference to the current scope. > > This can be useful to save a reference to a given execution scope to access later on. >

@@ -401,7 +401,7 @@

> > %sidebar% > > Example > > -> > This operator is useful to define symbols on the [ROOT](class:kwd) scope or a parent scope. For example min's prelude includes the following code used to import certain modules only if min was not compiled in lite mode: +> > This operator is useful to define symbols on the [ROOT](class:kwd) scope or another scope. For example min's prelude includes the following code used to import certain modules only if min was not compiled in lite mode: > > > > 'lite? ( > > (
M site/contents/reference-str.mdsite/contents/reference-str.md

@@ -11,6 +11,9 @@

{#op||capitalize||{{sl}}||{{s}}|| Returns a copy of {{sl}} with the first character capitalized.#} +{#op||chr||{{i}}||{{s}}|| +Returns the single character {{s}} obtained by interpreting {{i}} as an ASCII code.#} + {#op||indent||{{sl}} {{i}}||{{s}}|| Returns {{s}} containing {{sl}} indented with {{i}} spaces.#}

@@ -50,6 +53,9 @@ > > %tip%

> > Tip > > > > {{s2}} can be a {{sgregex}}-compatible regular expression.#} + +{#op||chr||{{s}}||{{i}}|| +Returns the ASCII code {{i}} corresponding to the single character {{s}}.#} {#op||repeat||{{sl}} {{i}}||{{s}}|| Returns {{s}} containing {{sl}} repeated {{i}} times.#}