Support additional brackets

question

#1

Is it possible to support extra braces? Like, convert ⟨a, b⟩ to angle(a, b), ⌊x⌋ to floor(Int, x), and ⌈x⌉ to ceil(Int, x).

If the change is not difficult, I can make a pr :stuck_out_tongue:


#2

It’s certainly possible, and there was a draft PR at one point, but the implementation didn’t get a consensus at that time for various reasons: https://github.com/JuliaLang/julia/issues/7128


#3

There were too much things in that pr. I want to modify it into a simpler version. Just convert ⟨⟩, ⌊⌋ and ⌈⌉ into function calls.

Here is the plan:

  • f⟨bla, blah⟩ is not considered because I only want brackets.
  • ⟦ ⟧ is not implemented because it has the potential to support f⟦bla, blah⟧.
  • ❮❯ and ⟪⟫ are not implemented because I cannot find their LaTeX names.
  • ⟨⟩, ⌊⌋ and ⌈⌉ are not translated into macro calls for simplicity.

link to pr: https://github.com/JuliaLang/julia/pull/8892


#4

While you’re at it, is it completely impossible to have |x| as abs(x)?


#5

| is bitwise or


#6

You could have ‖x‖ for norm(x), which gives abs(x) for scalars, where is U+2016 (\Vert).


#7

(for julia 0.7?)


#8

I definitely agree it would be really nice to have more brackets.


#9

Welcome to cryptic Julia!! I was never impressed by using unicode in Julia, nothing is more readable than plain text. If I say alpha, why should I write α? It just adds to line noise. See how people criticize this on Quora, for example. IMHO, angle(a, b) is way more readable than ⟨a, b⟩.


#10

I absolutely, emphatically disagree with this. If this were true, math and physics papers would be entirely in plain text. They evolved to look the way they do in order to be readable.

So, 5 characters is less line noise than 1 character?


#11

Thankfully, Julia doesn’t force you to use unicode.

I say “tee”, but write “t”, what’s the difference?


#12

Math and physics papers are written like this because we, humans, understand the following formula at a glance:

\zeta = \frac{\left|\ln\left(\frac{P_0}{100}\right)\right|}{\sqrt{\pi^2+\ln^2\left(\frac{P_0}{100}\right)}}

If a whole formula like this can be parsed and executed correctly, that’s a dream!

To write α, you actually need 7 strokes \alpha+tab instead of 5, and on a low resolution screen one may find α not very distinct from a. Besides, we don’t expect people to hold a PhD in Mathematics to decipher our code (think about weird symbols sometimes used in math). Julia deserves a universal place as a general purpose language, and not only a language for mathematicians and the like. Of course you can choose your own style and no one forces you otherwise, but IMHO, this is not the recommended style of writing code.


#13

I see your point, but consider that only a fraction of the variables in any chunk of code are going to be αs. Most of them will always be your good old as and xs… What’s freaking awesome is that the part of the code that represents actual formulas can be coded exactly like that. That surly makes it more readable.


#14

Ok, so isn’t it nice to be able to do

ζ = abs(log(P₀/100))/√(π^2 + log(P₀/100)^2)

Are you really arguing that this is a perfectly understandable formula, but that you’d be better off using all ASCII for the code? Is it hard to get this to parse correctly?

If that really bothers you so much that you don’t find it worth it, than don’t do it. (By the way, on many editors you don’t need the tab, so it’s only 6 strokes in addition to the usual space.)

I pray that it doesn’t require a PhD in mathematics to read a Greek letter. If that’s the case, we’re going to be in very big trouble indeed.

Anyway, this is getting quite off point. Having a few extra delimiters, while they probably shouldn’t be abused, might really common in handy in some cases where you need to repeat a function very often. I agree that, for example, it might be dangerous to have tons of different variations on \langle brackets, because it may be hard to distinguish them, but picking the most common ones and going with them seems like a safe approach.


#15

Its still 5 strokes. \alp hold tab.


#16

Okay, pr submitted. https://github.com/JuliaLang/julia/pull/27697


#17

It’s basically a symbolic jargon, which also evolves in specialized fields to make things easier to express within the field, but which do the opposite outside of that targeted audience.

One only has to look at how the same operator can be used for entirely different things in math papers vs. physics papers vs. engineering to see how many times using those operators can be problematic when there is any overlap in the audiences.


#18

I will play around the bra and kets (ref A Qubit DSL?) a little bit to see if it is feasible.


#19

What I see as good point for Julia! :slight_smile: (to be able to work better in specialized fields)

Using words instead of symbols would bring same confusion, wouldn’t it?


#20

When somebody from outside a particular field sees a symbol which means something specific in that field, how easy is it for them to discover the meaning?
It’s not easy to Google some funny Unicode character or sequence, or to get help at the REPL.

If I see inner_product(a, b), I’d have a good idea what that means, but with some obscure symbol?

While there is some overlap with words, I think it’s less than with some of the symbols.