- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Open
Labels
parserLanguage parsing and surface syntaxLanguage parsing and surface syntax
Description
a:::b
is valid Julia syntax:
julia> Meta.show_sexpr(Meta.parse("a:::b"))
(:(::), :a, (:quote, #QuoteNode
:b
))
but is not semantically valid code.
Could :::
be parsed as an operator instead? Like this:
julia> Meta.show_sexpr(Meta.parse("a:::b"))
(:(:::), :a, :b)
StefanKarpinski, MasonProtter and serenity4
Metadata
Metadata
Assignees
Labels
parserLanguage parsing and surface syntaxLanguage parsing and surface syntax
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
StefanKarpinski commentedon Jun 3, 2025
Seems good to me. Very technically breaking as
a:::b
does already parse, but it parses as(a)::(:b)
which is useless, so very doubtful this would actually break anything.adienes commentedon Jun 3, 2025
time to wake up, a new equality operator just dropped
quinnj commentedon Jun 3, 2025
We've talked about having
x as T
syntax before which would doconvert(T, x)
, that was my immediate though seeing this syntax. i.e. we'd havex::T
for assertion andx:::T
for conversion. But maybe those are too visually similar to be helpful when perusing code 🤷StefanKarpinski commentedon Jun 4, 2025
The proposal isn't to give it a definition, just to parse it as an operator. But yes, that's s possibility.
LilithHafner commentedon Jul 3, 2025
If we do want to give it a definition and export it from Base we should ideally do that in the same release as we make it an operator; lest packages give it conflicting meanings.
JeffBezanson commentedon Jul 3, 2025
@iuliadmtru Do you have an example in mind of how you might use it? That would be helpful to assess the value of this.
DilumAluthge commentedon Jul 3, 2025
For this specific example, I think that
x::T
andx:::T
are too visually similar and would be confusing.iuliadmtru commentedon Jul 3, 2025
I have been using it for a syntax matching mechanism in Argus.jl to represent pattern variables restricted by syntax classes:
This is a pattern that matches an assignment.
x
and_
are pattern variables (the latter is anonymous) andidentifier
andexpr
are syntax classes. I wanted something that is different from::
but close enough to it to suggest similar semantics.LilithHafner commentedon Jul 3, 2025
Triage is fine with this if someone wants to implement and it's not too much complexity. We'd just make it an operator with some precedence, we wouldn't define a meaning.
martinholters commentedon Jul 4, 2025
A language-level use-case for
:::
I could imagine is like a stricter::
, such thatx:::T
ensures thattypeof(x) == T
or similar. This could make sense for dispatch, like so:Not sure how useful this would be and whether it would be imaginable to fit this into the subtyping/dispatch mechanism in the foreseeable future, but I wanted to float the idea before we make the syntax available and regret later on.