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

Passing an empty args list #13

Closed
bkamins opened this issue Jan 15, 2021 · 8 comments
Closed

Passing an empty args list #13

bkamins opened this issue Jan 15, 2021 · 8 comments

Comments

@bkamins
Copy link

bkamins commented Jan 15, 2021

This currently fails:

julia> @chain begin
       1
       sin()
       end
ERROR: LoadError: Can't prepend first arg to expression sin() that isn't a call.

It would be useful to have it as now you have to e.g. write:

julia> @chain begin
       [1,2]
       sin.(_)
       end
2-element Array{Float64,1}:
 0.8414709848078965
 0.9092974268256817

instead of just:

julia> @chain begin
       [1,2]
       sin.()
       end
ERROR: LoadError: Can't prepend first arg to expression sin.() that isn't a call.
@jkrumbiegel
Copy link
Owner

Oh interesting, I must have overlooked that case because when you have no arguments, you can also just write sin, and for the broadcasting version you can write @. sin as a special case. I'll look into it!

@bkamins
Copy link
Author

bkamins commented Jan 15, 2021

Another corner case:

julia> @chain 2 begin
       "$sin"
       end
ERROR: LoadError: Can't prepend first arg to expression "$(sin)" that isn't a call.

julia> @chain 2 begin
       "$(sin(_))"
       end
"0.9092974268256817"

@bkamins
Copy link
Author

bkamins commented Jan 15, 2021

@jkrumbiegel
Copy link
Owner

I've just fixed sin(), sin.() and somefunc.(arg2), thanks again for the heads-up!

But I don't think the string example makes sense, to be honest, or I'm misunderstanding. Your interpolated string syntax becomes equivalent to string(sin), so to splice in a first argument to that call would result in string(2, sin), so "2sin", not string(sin(2)). Your intent is very clear in the second example, even though you need four parentheses and an underscore, of course.. But it seems convoluted to add a case for "first function call within a string interpolation"

@bkamins
Copy link
Author

bkamins commented Jan 16, 2021

Thank you!

The point is that:

julia> "$sin"
"sin"

so the same should happen within @chain wrapped block I would assume. And now it errors.

@bkamins
Copy link
Author

bkamins commented Jan 16, 2021

But it is a corner case, so probably it can be left as is. I have not look at the expressions generated to check how easily such things could be fixed.

@jkrumbiegel
Copy link
Owner

yes it errors because @chain expects every line to have an underscore somewhere, or be a call of some kind that a first argument can be spliced into. "$sin" has no underscore but it's also not a call, so it doesn't make sense within a chain

@bkamins
Copy link
Author

bkamins commented Jan 16, 2021

OK - this makes sense as this works:

julia> @chain 2 begin
              "$_ $sin"
              end
"2 sin"

and this works:

julia> @chain 2 begin
              print("$sin")
              end
2sin

I was reading the error message incorrectly - I thought it referred to $sin while it refers to the whole string. Thank you for explaining.

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