Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile time #5

Open
pietroppeter opened this issue Sep 30, 2020 · 3 comments
Open

compile time #5

pietroppeter opened this issue Sep 30, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@pietroppeter
Copy link
Owner

import nimoji
echo static ":wave:".emojize

output:

Error: cannot evaluate at compile time: emojiCodemap
@pietroppeter pietroppeter added the enhancement New feature or request label Sep 30, 2020
@pietroppeter
Copy link
Owner Author

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

@pietroppeter
Copy link
Owner Author

pietroppeter commented Oct 1, 2020

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 nim-lang/Nim#8521

@pietroppeter
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant