1. 22
pkg.go.dev
1. 14

Russ Cox published a series of videos on how to solve Advent Of Code 2021 using this language (ivy): https://www.youtube.com/user/rscgolang/videos

2. 2

As a special but important case, note that 1/3, with no intervening spaces, is a single rational number, not the expression 1 divided by 3. This can affect precedence: 3/64 is 2 while 3 / 64 is 1/8 since the spacing turns the / into a division operator. Use parentheses or spaces to disambiguate: 3/(64) or 3 /64.

This seems… really bad. Lexer behavior is based on values? Why is 1/3 special but 1/5 isn’t? Is 1.0/3.0 covered? The language has first class rationals, why is this necessary?

1. 2

Why do you think it depends on values? It says both 1/3 and 3/6 have the property, so why would you believe 1/5 does not?

1. 1

It appears I misread, still seems kinda weird though, why have that? (Also markdown removing the asterisks in my post isn’t helping)

1. 4

Maybe that’s Pike’s background as physicist acting up :-). Having looked at similar formulae throughout my university years, reading 1/2 * m * v^2 as (1/2) * m * v^2 feels pretty natural to me, too – it’s very close to how you’d write it (\frac{1}{2} mv^2) if we weren’t stuck with 1970s terminals in 2022.

It’s also extraordinarily useful to have rational number support in calculators (but note that I don’t know if Ivy does these things specifically). For example it makes checking your results so much easier, because it preserves easily-checked proportions. There are various quantities that you expect to vary in a particular way – for example, to decrease linearly with, or with the square or cube of, the distance from a particular point. So if you know the value of that quantity at L=2 um, you expect a nice, round value at L = 4 um or L = 20 um. But if the length gets lost in the floating point rounding error, you don’t get those nice results, and depending on context, you often lose the ability to tell if two pages of thick integrals you really don’t feel like checking are right just by checking a few points in a table. There are also various “special” well-known values of otherwise complicated-looking functions – for example, you expect various special “nice” values for I and V at specific points on a transmission line because various ugly coefficients (sometimes irrational) cancel each other out. If you plug that in a purely numerical system, they get lost in floating-point errors and you don’t easily recognize them anymore.

FWIW, there’s a whole series of tricks that you learn as an engineering/physics/chemistry/whatever undergrad to use these things more efficiently, ranging from doing part of the computation on paper to get some of the uglier coefficients out to cleverly computing things in a slightly different order on your calculator to goad it into rounding values just right (RPN calculators can make that a little easier FWIW).

1. 1

Absolutely, my gripe isn’t with rationals as first class numbers, I really like that, my gripe is with the whitespace semantics, in ‘n/m’ the / has different precidence than in ‘n / m’.

1. 1

I realise that, I think my wall of text said too much about why rational numbers are cool and not enough about the spacing: after having written the kind of formulae I suspect Pike wrote in his undergrad years, too, having n/m treated differently than n / m makes total sense to me, and I find it a really neat idea. I’m pretty sure I’d hate it if any of the general-purpose languages I work with would have that, but I really like it in a desktop calculator.

That’s obviously super subjective and I realise it’s heresy :-D.

2. 3

As a special but important case, note that 1/3, with no intervening spaces, is a single rational number, not the expression 1 divided by 3. This can affect precedence: 3/6*4 is 2 while 3 / 6*4 is 1/8 since the spacing turns the / into a division operator. Use parentheses or spaces to disambiguate: 3/(6*4) or 3 /6*4.

3. 2

1e5 is different from 1 e 5. For languages in the algol (c, pascal) syntax lineage, is it commonly illegal to have two terms in sequence. Not so in others, however. In apl, pertinently, 1e5 is a single number, while 1 e 5 invokes function e with arguments 1 and 5 (or, perhaps, passes 1 to the adverb e and invokes the derived function on 5; or, even, in dialects with stranding, might be a 3-element array comprising 1, e, and 5). In ml derivatives, ‘f 1e5’ invokes f with the single argument 1e5; ‘f 1 e 5’ invokes f with the three arguments 1, e, and 5 (modulo currying). In lisp, the situation is almost exactly the same as in TFA: ‘3/4’ reads as a ratio, but ‘3 / 4’ reads as the integer 3, the symbol /, and the integer 4.

That said, I do find the rule to be in somewhat poor taste (if not inconsistent in that respect with other choices made by the dialect), and prefer j’s notation, cf ‘3r4’.

markdown removing the asterisks

You may escape them using \.

3. 2

That would make a nice episode for ArrayCast maybe