Skip to content

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

Draft
c42f wants to merge 1 commit into
mainfrom
c42f/string-format-syntax
Draft

Syntax experiment: String format syntax eg "$(x, digits=2)"#308
c42f wants to merge 1 commit into
mainfrom
c42f/string-format-syntax

Conversation

@c42f

@c42f c42f commented Jun 9, 2023

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

Can we use semicolons to start keyword arguments here?

@c42f

c42f commented Jun 10, 2023

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member

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

c42f commented Jun 10, 2023

Copy link
Copy Markdown
Member Author

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

andyferris commented Jun 14, 2023

Copy link
Copy Markdown
Member

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

c42f commented Jun 15, 2023

Copy link
Copy Markdown
Member Author

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

c42f commented Jul 23, 2024

Copy link
Copy Markdown
Member Author

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

See

JuliaLang/julia#54903

@c42f

c42f commented Nov 20, 2025

Copy link
Copy Markdown
Member Author

Note about moving this to base, if necessary

# git clone git@github.com:JuliaLang/julia julia_dir
# cd julia_dir

git remote add JuliaSyntax git@github.com:JuliaLang/JuliaSyntax.jl
git fetch JuliaSyntax
git checkout pr-for-Base/308
git rebase origin/master

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