-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[WIP] new brackets: angle, Brack, Brace #8892
Conversation
Nice! I wouldn't get greedy trying to add |
I guess not, considering this PR would already more than double the brackets available... I notice that Travis CI is failing on osx, though on my local mac it passed the test. |
I'm working on the OSX issue. It's because there has been some path breakage due to a new GCC version being released. |
Cool, I'm not a fan of the concatenated |
Fair enough, though the way |
Thank you @staticfloat for the heads up. I'm a bit nervous since this is my first time touching such a core component of Julia. A little more color on the current "implementation": I'm kind of ok with using the existing @jakebolewski I'm okay with renaming them to whatever, presumably after we have some good idea how we are going to use them. |
On the sub-topic of scarce resources: presumably there'd be a little land-grab on using those brackets, so I may as well start this first! So, I'd like to reserve |
Most likely all of these should be lowered to calls of certain standard names. The first argument ( |
Wait until algebraists and differential geometrists get their hands on them... I'm not taking chances. |
Good idea, but... the \langle and \rangle is not very visually distinguishable from parens. I had to read your table several times before realising that |
@elextr, of course, none of these are set in stone. Here are some alternatives:
What do you think? |
Agree 2039 is kinda small, 276e is distinguishable from parens, but 29fc didn't render (on current release Linux Mint default).
Note that C++ is just about to drop trigraphs to support all of ASCII IIUC :) As a next generation language Julia probably should just go Unicode without ASCII alternatives, only beware of characters that are hard to distinguish thats all. Even in your pdf the \lparen and \langle need more than a quick glance to distinguish.
As has been suggested elsewhere, Julia font anyone? It would be guaranteed to contain good renderings for all codepoints used in Julia and packages (well packages that contribute glyphs anyway). |
What about dingbats '\U276e' |
Updated above. Looks better to me. |
What are we? APL? At least we don't need to ship a keyboard. |
The rendering may be very different depending on the font, so there's little point in discussing this in general. I'd say a font in which you cannot easily distinguish parentheses from angle brackets has a bug and should be improved. The good news is that it can be done for open source fonts. Using dingbats instead of the mathematically correct Unicode character isn't great, it means the result will be different than what you'd get e.g. in LaTex and will lead to confusion. |
I'm taking a more pragmatic view on this. There isn't a "mathematically correct unicode character". If the poor first-time user, with a suboptimal font set, encounters a un-renderable or confusable bracket, that is not a very good first impression. |
Actually, this starts to feel like something we should enlist broader input from julia-users mailing list. wdyt? |
Playing with mock code with the brackets a bit, here is a draft of their potential use
I'm already annoyed with the Angle being confused with the small angle brackets. I think we should just collapse them. |
Actually, there are. In principle, Unicode distinguishes between characters (with semantic meanings) and glyphs (their visual representation), and so differentiates things like ⋅ U+22C5 (dot operator) and · U+00B7 (middle dot) . The standard glyph chart (pdf) explicitly states "(22C5) • preferred to 00B7 · for denotation of |
@jiahao is quite right. Unicode includes characters for their meaning, not their appearance. There are many pairs of characters that are likely to look the same in most fonts. |
"\\rangle" => "⟩", #U27e9 | ||
"\\lAngle" => "⟪", #U27ea | ||
"\\rAngle" => "⟫", #U27eb | ||
"\\ldangle" => "❮", #U276e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is \ldangle
actual LaTeX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. it's just a shorthand for "dingbat-angle"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think we should not have those.
I probably wasn't very precise in presenting my view. The closest analogy is that @elextr 's concern of the appearance of Besides, what should a angular bracket correctly mean anyway, mathematically? I don't know. We are giving them meaning here. I think we should focus on enriching the expressive power of Julia while making them readable (by human). Pretty-printing can be monkey-patched when non-standard angular bracket characters are encountered. |
What you're describing sounds like defining your own Unicode canonical equivalence for angle brackets (see UAX 15). You can have multiple Unicode code points all be treated the same as angle brackets because of visual ambiguity. Nonetheless, Unicode does have very specific code points for angle brackets (U+3008 and U+3009), and we should respect that, even if fonts don't. "Get a better font" is a perfectly valid solution. |
Granted, it's not too helpful that Unicode has U+2329, U+3008, and U+27E8 just for left angle bracket, never mind the extra dingbats and whatnot. For years, programmers have been picking fonts based on the distinguishability of 0 and O, and i, I, l, and 1. |
|
ref: JuliaStrings/utf8proc#11 - possible use case for canonicalizing brackets |
@jiahao thanks for the pointer. It's nicer to deal with unicode normalization issues for julia code in one place. |
@JeffBezanson, @jakebolewski I wonder if it's better just to transform all the new brackets into |
Ok, we are further along where the code can actually be used. import Base: Brace_call, Brace_enclose
Base.Brace_call( s::Any, x::Int ) = (s,x)
Base.Brace_enclose( x::Int ) = (x,)
@assert sin{| 1 |} == (:sin,1)
@assert f{T}{| 1 |} == ( :(f{T}), 1 )
sin{| 1.0 |} # ERROR
@assert {| 1 |} == (1,)
{| 1.0 |} # ERROR So a module can specialize these brackets for its own use by extending the |
What's with the extra quoting in the parser? If these are going to be macros (which I'm not sure they should be) then that's totally redundant, since macros always see the argument expressions anyway. If they're not going to be macros, then the extra quoting is just crazy. |
@JeffBezanson That's fair. I'm learning the rope as I go. How does it look? |
Another related issue: #8599 |
Here is a status update on this PR
|
I've been waiting to see where this goes, and it seems like its converging to something. Also, does anyone else read |
Yes, and the "use a better font" argument is a furphy that might apply to those developing Julia or using it intensively, but it doesn't apply to casual code readers on github or elsewhere. Julia should not require a special font to read the code.
Now that you mention it, yes. |
I think in the likely use case it'd be @IainNZ, @elextr We could remove/ban \langle and \rangle |
The thing is, and I think this is getting at a more fundamental objective I have, is: do we have anything like it in this language or the 95% of popular languages? I'm trying to think of things that are double-punctuation:
I just feel like |
Yes, let's have some data points. From Haskell, there are
Ok, Haskell may not be even in the 95% of popular languages, but it's certainly not a "bad idea language". Just saying. |
@tonyhffong the ⟪⟫ is fine, its visually distinct from everything else. Just the single ⟨ is font dependent to distinguish it from ( and therefore should not be used by a sensible language like Julia. BTW to emphasise, other than ⟨ more brackets is a good thing :) Haskell is trying to take Perl's mantle of "every sequence of punctuation is valid code" :) But |
@tonyhffong I still don't like it, or the whole idea in general, but I don't think anything other than amazing example that you can't do any other way is going to sway me. Luckily, its not me you need to sway :D |
@IainNZ lol. okay. Well, let's see. I guess the train of thought I followed is like this:
|
Their latex symbols are \lAngle,\lBrack,\lBrace ( the closing ones should be obvious). Brack and Brace has ASCII equivalent of [| |] and {| |} They map to : * With prefix expression: `@call_Angle, @call_Brack, @call_Brace` * Without prefix: `@enclose_Angle, @enclose_Brack, @enclose_Brace` The further lowering of @call_Brace is different from others to allow for the need to look at the prefix symbolically, instead of its dereferenced value.
Another update on this PR:
The remaining issues are:
|
FWIW, I'm not a fan of this. I think it adds too much visual and functional ambiguity without - as yet - a clearly-articulated motivation or usage guidance. "wait, which bracket is implemented for this type; ok now what does it do?!?" -- multiplied by 4,000+ packages in a few years. |
okay, let's shelf this PR. Carry on. |
Changes Unknown when pulling 0c72c01 on tonyhffong:master into * on JuliaLang:master*. |
Relevant issue: #7128
I propose adding a number of unicode and composite brackets. In the table below, I include the new LaTeX shortcuts for these new brackets and how they will be parsed. As it stands now, these brackets can be used inside macros, but they have no meaning in proper Julia (yet). I have also given myself the creative license to equate
[| |]
to⟦ ⟧
and{| |}
to⦃ ⦄
. I think they make input more pleasant, and visually their similarity is compelling.The motivation is that we seem to struggle with using only three bracket types (), [], {} for a large number of language features.
\langle, \rangle,\lAngle, \rAngle⟨⟩
⟪⟫
is canonical,❮❯
,❰❱
, acceptable❮a,b❯
->Expr(:angle,:a,:b)
@enclose_Angle(:a,:b)
foo❮a❯
->Expr(:anglecall,:foo,:a)
@call_Angle(:foo, :a)
⟦⟧
⦃⦄
Notes and discussion points:
❮❯
, and canonical LaTeX angle bracket⟨⟩
are interchangeable to generate the same AST, although they must be matched exactly. The parser would not match❮
with⟩
. By the same token, the parser would not match[|
with⟧
, etc.|: :|
being a bracket possibility as well. However, I notice that colon is used inside multiple contexts (range, symbol, quote, indexing wildcard) so there is also risk of surprise.