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

Syntax experiment: String format syntax eg "$(x, digits=2)" #308

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

c42f
Copy link
Member

@c42f c42f commented Jun 9, 2023

See JuliaLang/julia#18703

julia> JuliaSyntax.parsestmt(SyntaxNode, "\"prefix \$(1.0, digits=2) suffix\"")
line:col│ tree                                   │ file_name
   1:1  │[string]
   1:2"prefix "
   1:10 │  [format]
   1:111.0
   1:16 │    [=]
   1:16 │      digits
   1:232
   1:25" suffix"


julia> JuliaSyntax.parsestmt(Expr, "\"prefix \$(1.0, digits=2) suffix\"")
:("prefix $($(Expr(:format, 1.0, :(digits = 2)))) suffix")

CC @simonbyrne

@giordano
Copy link

Can we use semicolons to start keyword arguments here?

@c42f
Copy link
Member Author

c42f commented Jun 10, 2023

Can we use semicolons to start keyword arguments here?

Certainly! But is it a good idea to diverge from the syntax for keyword args supported everywhere else in the language?

@giordano
Copy link

But is it a good idea to diverge from the syntax for keyword args supported everywhere else in the language?

Uhm? Keyword arguments do start with semicolons in the language already, sadly that's optional and using commas can lead to not-so-fun-to-debug problems.

@c42f
Copy link
Member Author

c42f commented Jun 10, 2023

Keyword arguments do start with semicolons in the language already

Haha! I do know about this. And some other fiddly details of Julia's syntax ;-)

My point is, I think it'd be confusing not to support the comma notation, given that it's supported and extremely widely used for normal function calls. I think consistency is more important here than trying to fix problems which can't be fixed in the other more widely used syntax due to compat concerns.

@andyferris
Copy link
Member

andyferris commented Jun 14, 2023

I also kinda feel like semicolons might be good here, but it's not a super strong opinion. For one thing it wasn't obvious to me (before I checked) that "$(1,2)" isn't interpolating the tuple (1,2).

can't be fixed in the other more widely used syntax due to compat concerns

This isn't the right forum/issue - but I rather like the idea of having something like Rust's "editions" to make breaking syntax improvements over time (without needing e.g. Julia 2.0), hence I'd challenge what "can't" be done (eventually...).

@c42f
Copy link
Member Author

c42f commented Jun 15, 2023

I rather like the idea of having something like Rust's "editions" to make breaking syntax improvements over time (without needing e.g. Julia 2.0), hence I'd challenge what "can't" be done (eventually...).

I agree with this and I've been thinking a lot about it for a while :-) I don't know exactly how it should work yet but I've been wanting to write a julep on it :)

@c42f
Copy link
Member Author

c42f commented Jul 23, 2024

I rather like the idea of having something like Rust's "editions" to make breaking syntax improvements over time

See

JuliaLang/julia#54903

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

Successfully merging this pull request may close these issues.

3 participants