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

Disallow passing non-function values to an argument name ending in ~ #1289

Open
hanche opened this issue Apr 11, 2021 · 2 comments
Open

Disallow passing non-function values to an argument name ending in ~ #1289

hanche opened this issue Apr 11, 2021 · 2 comments

Comments

@hanche
Copy link
Contributor

hanche commented Apr 11, 2021

Consider this:

⬥ fn foo {|f~|  put hi-there; f 42 }
⬥ foo bar
⮕ hi-there
Exception: bad value: command must be callable or string containing slash, but is bar
Traceback:
  [tty 12], line 1:
    fn foo {|f~|  put hi-there; f 42 }
  [tty 14], line 1:
    foo bar

I think the error should happen earlier, i.e., when the function call results in assigning the string bar to the formal parameter f~. This for consistency with the prohibition on assigning non-functions to f~ using var or set, and because a function parameter named with a tilde at the end should clearly be expected to receive a function value.

Whether $nil is to be allowed or not, is orthogonal to this. But it should also be consistent with what happens with variables. See #1248.

Edited to conform to new function syntax.

@krader1961
Copy link
Contributor

I think the error should happen earlier, i.e., when the function call results in assigning the string bar to the formal parameter f~.

It's not quite that simple. Consider that a path containing a slash is valid; e.g., foo /bin/echo. So the rule should really be whether the argument can be resolved to a, possibly external, command -- not whether it is simply a string.

@hanche
Copy link
Contributor Author

hanche commented Jun 28, 2022

Hmm, that's an interesting point. I had forgotten, or possibly never learned, that var f = /bin/echo; $f 42 is legal.

On the other hand, var f~ = /bin/echo is not allowed. Perhaps it should be.

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

2 participants