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

undeclared identifier 'f' if json is imported #28

Open
Vindaar opened this issue Jan 29, 2020 · 1 comment
Open

undeclared identifier 'f' if json is imported #28

Vindaar opened this issue Jan 29, 2020 · 1 comment

Comments

@Vindaar
Copy link
Owner

Vindaar commented Jan 29, 2020

When trying to build a formula with the f{} macro and importing json at the same time, we'll encounter:

Error: undeclared identifier: 'f'

For instance:

import ggplotnim
import json

let f = f{"Channel" == "Ch 0"}
echo f

This is due to the {} procs exported in json. This is confusing to me, since these are procs and our string / identifier input should never match their signature.

proc `{}`*(node: JsonNode, keys: varargs[string]): JsonNode
proc `{}`*(node: JsonNode, index: varargs[int]): JsonNode

I suppose this is because the implementation for the f{} macro is using the signature:

macro `{}`*(x: untyped{ident}, y: untyped): untyped

where the first arg x is required to be f and y is the actual content of the nnkCurly.

For now as a workaround I'll be adding a fn macro, which expects an nnkCurly argument:

macro `fn`*(x: untyped): untyped =
  let arg = if x.kind == nnkStmtList: x[0] else: x
  expectKind arg, nnkCurly
  ...

which can then be called via:

let f = fn {"Channel" == "Ch 0"} # note the required space!
let f2 = fn({"Channel" == "Ch 0"})
let f3 = fn:
  {"Channel" == "Ch 0"}

In this case the requirement for the curly brackets could of course be removed. I'm not sure which syntax I prefer. If anyone has ideas / an opinion, please let me know!

Vindaar added a commit that referenced this issue Jan 29, 2020
The default `f{}` macro does not work if `json` is imported :/ See
issue #28 for reference.
Vindaar added a commit that referenced this issue Jan 30, 2020
The default `f{}` macro does not work if `json` is imported :/ See
issue #28 for reference.
@Vindaar
Copy link
Owner Author

Vindaar commented Jan 30, 2020

While the related PR is merged, this issue will stay open for the time being, since the underlying issue is not fixed.

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

No branches or pull requests

1 participant