Open Dry-Leaf opened 2 years ago
For context: this idea was born out of discussion, basically about how ugly Red becomes when one needs to access last items in a list.
Example:
change back back tail list 1 + pick tail list -2
in Red vs
list[-2] += 1
in Python
This area clearly needs some improvement, and this is one of the options for further consideration/development.
It's a clever idea, but raises questions. Is \x
a new kind of refinement!
? Is \1
the negation of /1
? Was \
avoided by Carl in Rebol's design because it's such a common escape char in other langs? For both that reason and reading paths, how confusing will it be, and will it lead to subtle errors?
For this particular wish and its syntax, my gut says No. For the general idea of some way to make last-item access clearer, that's a good idea. Let's list example use cases, think about incr, and brainstorm from there.
I see a disadvantage of \
being visually very similar to /
, could be difficult to read code properly.
negative index is relative to the head of a series, not its tail that works, but first you need to set the head at the tail
@Dry-Leaf Ah, yes. Forgot that. 😅
I’m strongly against it. How common is it to access paths from the end? Do we really need to waste one of the few remaining sigils on it? @greggirwin asks good questions, is it going to be a new type? And as negative indexes are relative to the head of the series, you need just to do list: tail list
to use them. It’s not that hard.
I’ll better save \
for something else.
Using black slashes to access items starting from the tail of a series.