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

Make the body of a user-defined function a fully-fledged scope #5075

Open
philrz opened this issue Mar 15, 2024 · 0 comments
Open

Make the body of a user-defined function a fully-fledged scope #5075

philrz opened this issue Mar 15, 2024 · 0 comments

Comments

@philrz
Copy link
Contributor

philrz commented Mar 15, 2024

tl;dr

In the Zed docs about statements several times we explain scopes as:

...the main scope at the start of a Zed program or a lateral scope defined by an over operator

However, there are valid reasons why a user might want to treat other ( )-enclosed code blocks (e.g, the body of a user-defined function) like scopes.

Details

Repro is with Zed commit f1be6a4.

#5073 has the background for the equivalent concept as relates to user-defined operators. It seems a similar enhancement might benefit user-defined functions as well. For example, this currently works:

$ cat circ.zed 
const pi = 3.14
func circ(r): (
  2 * pi * r
)

$ zq -version
Version: v1.14.0-17-gf1be6a4a

$ echo '10' | zq -I circ.zed 'circ(this)' -
62.800000000000004

But this does not:

$ cat circ-inner.zed 
func circ(r): (
  const pi = 3.14
  2 * pi * r
)

$ echo '10' | zq -I circ-inner.zed 'circ(this)' -
zq: error parsing Zed in circ-inner.zed at line 2, column 9:
  const pi = 3.14
    === ^ ===
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