nimoji
nimoji copied to clipboard
compile time
import nimoji
echo static ":wave:".emojize
output:
Error: cannot evaluate at compile time: emojiCodemap
it is a problem of string tables (but not of tables):
import tables, strtabs
const
next = {0: 1, 1:2}.toTable # ok
print = {0: "0", 1: "1"}.toTable # ok
parse = {"0": 0, "1": 1}.toTable # ok
read = {"0": "zero", "1": "one"}.toTable # ok
dict = {"zero": "0", "one": "1"}.newStringTable # fails
Error: invalid type for const: StringTableRef
it is in general due to the fact that ref types cannot be used at compile time (manual) and StringTable is implemented as ref type and not as object (while all other tables are object types with optional ref type).
see also https://github.com/nim-lang/Nim/issues/8521
a way to support this would be to replace StringTableRef with a Table[string, string] and make sure that checking for a key is done in a (full) case insensitive way.
POC: https://play.nim-lang.org/#ix=2znW
import tables, strutils
const
map = {"heart": "❤️", "spaghetti": "🍝" }.toTable
proc get(dict: Table[string, string], key: string): string =
dict[key.toLower.replace("_", "")]
const
heart = map.get("He_Art")
static:
echo heart