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

Macros: quasiquoting + dot or bracket syntax: dot and brackets are ignored #7726

Closed
mratsim opened this issue Apr 29, 2018 · 5 comments · Fixed by #17426
Closed

Macros: quasiquoting + dot or bracket syntax: dot and brackets are ignored #7726

mratsim opened this issue Apr 29, 2018 · 5 comments · Fixed by #17426

Comments

@mratsim
Copy link
Collaborator

mratsim commented Apr 29, 2018

The quasiquoting interpolation ignores dot call/fields. Test case:

import macros

macro foo(): untyped =
  let a = @[1, 2, 3, 4, 5]
  result = quote do:
    `a.len`


macro foo2(): untyped =
  let a = @[1, 2, 3, 4, 5]
  let len = a.len
  result = quote do:
    `len`

echo foo() # Outputs @[1, 2, 3, 4, 5] instead of 5
echo foo2() # Outputs 5
@mratsim mratsim changed the title Macros: quasiquoting + dot syntax: dot is ignored Macros: quasiquoting + dot or bracket syntax: dot and brackets are ignored Jun 19, 2018
@mratsim
Copy link
Collaborator Author

mratsim commented Jun 19, 2018

Brackets are also ignored:

import macros

macro foo(): untyped =
  let a = @[1, 2, 3, 4, 5]
  result = quote do:
    `a.len`


macro foo2(): untyped =
  let a = @[1, 2, 3, 4, 5]
  let len = a.len
  result = quote do:
    `len`

macro foo3(): untyped =
  let a = @[1, 2, 3, 4, 5]
  let len = a.len
  result = quote do:
    `a[2]`

echo foo()  # Outputs @[1, 2, 3, 4, 5] instead of 5
echo foo2() # Outputs 5
echo foo3() # Outputs @[1, 2, 3, 4, 5] instead of 3

@dom96
Copy link
Contributor

dom96 commented Jun 19, 2018

Yeah, and idents aren't handled correctly. I have to write let foo = newIdentNode("foo") all over my code and then use it inside my quote. It's super messy.

@krux02
Copy link
Contributor

krux02 commented Jul 23, 2019

Yes, the backticks on expressions should, when not supported, at least come with a sane error message.

@dom96 sorry, this is a very late reply, but your comment is on an entirely different issue. And I am aware of it.

@3gx
Copy link

3gx commented Jan 4, 2020

is the fix in works? Ability to call functions in unquote parts help to keep code clean, like in scheme/racket, for instance, the following doesn't compile:

import macros
macro fun(): untyped =
  let a = @[1, 2, 3, 4, 5]
  result = quote do:
    `len(a)`
echo fun

@krux02
Copy link
Contributor

krux02 commented Jan 5, 2020

there is this branch from me: #11823

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

Successfully merging a pull request may close this issue.

5 participants