Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative indexes, closes #274 #276

Merged
merged 1 commit into from
Aug 25, 2019
Merged

Negative indexes, closes #274 #276

merged 1 commit into from
Aug 25, 2019

Conversation

odino
Copy link
Collaborator

@odino odino commented Aug 25, 2019

This PR adds support for negative indexes in arrays / strings.

[1,2,3][-1] #3

There is one change that might alter existing ABS scripts, and that's
non-existing indexes, for strings, returning an empty string rather than
null.

I believe it's an ok thing to break as both will evaluate to false
when casted to boolean, and to check whether an index exists one can
simply:

  • check the length of the string (s.len())
  • check the boolean value of the index (!!s[idx])

both these examples do not break with these changes. I instead admit
that it would be weird to see code such as:

if s[idx] == null {
  ...
}

rather than

if !s[idx] {
  ...
}

So I guess this is a change that can go through, as it really shouldn't
impact much of the userbase.

@odino odino added this to the 1.8.x milestone Aug 25, 2019
This PR adds support for negative indexes in arrays / strings.

``` bash
[1,2,3][-1] #3
```

There is one change that might alter existing ABS scripts, and that's
non-existing indexes, for strings, returning an empty string rather than
`null`.

I believe it's an ok thing to break as both will evaluate to `false`
when casted to boolean, and to check whether an index exists one can
simply:

* check the length of the string (`s.len()`)
* check the boolean value of the index (`!!s[idx]`)

both these examples do not break with these changes. I instead admit
that it would be weird to see code such as:

``` bash
if s[idx] == null {
  ...
}
```

rather than

```
if !s[idx] {
  ...
}
```

So I guess this is a change that can go through, as it really shouldn't
impact much of the userbase.
@odino odino merged commit 6ef88ff into 1.8.x Aug 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant