nicklockwood/Expression

variables with index

wildthink opened this issue · 10 comments

It would be great if we could support "myarray[1]" as a symbol. If you don't think its a good idea for the main branch could you offer a pointer to the best way to implement it anyway? :-)
thanks.

It’s definitely something I want to support. The main issue I’m wrestling with is whether to make the [ ] part of the identifier (as I have with dots and quotes) or to make it a separate operator.

Umm, making it an operator would be more swifty, corresponding to the subscript() method. Also, wouldn't being an operator be easier when the key (e.g. items[key]) might also be a symbol?

@wildthink yes, the problem is that you can't subscript a number, which is all that Expression currently knows how to deal with.

@wildthink I guess for your use case, you'd want the subscript to be part of the symbol, in the same way that functions currently work. So you'd have something like

.subscript(name, arity:)

That could work. It would mean you couldn't subscript the result of a function though, so you couldn't write an expression like:

foo(5)[6]

On a separate but related note, I'm interested in supporting identifiers like x' (being a variant of x). Its something inspired by TLA+ (https://en.wikipedia.org/wiki/TLA%2B). Maybe adding a new enum type? Any pointers into the code to effect this would be welcome :-).

@wildthink I don't think it's necessary to introduce a new enum type for that - it should just be possible for me to support symbols that include a trailing ', as it wouldn't be ambiguous with any other symbol. Would that work for you?

That would be great. I'm just trying to be sensitive to your overall goals but if I don't have to maintain my own fork, all the better. :-)
thanks.

@wildthink OK, both your feature requests are implemented in version 0.9.0 😊

Wow! Thanks a bunch.
How much do I owe you? :-)

This one’s on the house ;-)