Closed dougalm closed 1 year ago
(N.B. I'm not involved with the project nor a user of it, just observing out of interest.)
Is there a reason against considering the "usual mainstream" syntax, table[i][j][k]
or table[i,j,k]
?
If function calls were to also become f(x,y)
, there could be an interesting bit of symmetry, with both the type- and term-level syntaxes for tables resp. functions resembling each other while remaining distinct: A=>B
and a[b]
vs. A->B
and a(b)
.
@glaebhoerl , that's an excellent point. If we end up using f(x, y)
for function application I think it almost becomes a no-brainer to use table[i,j,k]
too.
(Just another external observer) Extending the above analogy, it would be interesting to see to what extent future syntax for array slicing and general function partial application could be unified:)
For fixing the first args: if table[i]
(for a three-dimensional table
) were to fix i
, that's analogous to the sort of partial application syntax #1240 seeks to disallow. But wanting to fix the first indices in particular is a much more natural assumption for (row major) arrays than for functions due to the memory ordering.
Underscore is just so common as a name character, though! But we could do step 3 right now :)
Done! #1250
Let's admit that we never should have stolen
.
for indexing. Its power is wasted as an ordinary infix operator. But how are we going to return it to its rightful role?We've had some entertaining proposals like using
's
for field lookup (as infoo's bar
) and more serious ones like trying to overload.
for both uses. That turns out to be tricky because when.
is used for field access the right-hand side is quoted/uninterpreted.But we finally have a plan. We'll do a three-way switcheroo like a hermit crab shell swap.
.
for field access, likefoo.bar
_
for table indexing, likexs_i
(think "subscript")-
for separating words in identifiers,kebab-case
. Hillel Wayne approves.One thing I like about this proposal is that the error messages if you mess it up in the obvious way will be pretty good:
_
to separate words in an identifier, writingdo_stuff
instead ofdo-stuff
, you'll get an error message aboutdo
andstuff
not being defined.x-y
when you meant "x minus y" but forgot the spaces, you'll get an error message aboutx-y
not being defined. Again, pretty clear that it's an unintended lex.To get a sense of how this would look, here's
takePicture
from the raytracer.Thoughts?