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

Scalar index access #401

Merged
merged 9 commits into from
Jan 13, 2022
Merged

Scalar index access #401

merged 9 commits into from
Jan 13, 2022

Conversation

alari
Copy link
Member

@alari alari commented Jan 13, 2022

Fixes #329

To use non-literal indices, the new brackets syntax is introduced:

opt: []string

-- Take an element of an array, or 0 element
opt!

-- Take the sixth element
opt!5 

-- the same as opt!
opt[0]

-- the same as opt!5
opt[5]

-- get by index
func get(idx: i16) -> string:
   <- opt[idx]

-- Can use any proper value getter as an argument
get(opt!)

data Complex:
  field: []i16

func other(c: Complex) -> string
  x <- get(c.field!55)
  <- x

@alari alari self-assigned this Jan 13, 2022
@alari alari added enhancement New feature or request sugar Remove boilerplate syntax Syntax additions & changes labels Jan 13, 2022
@alari alari marked this pull request as ready for review January 13, 2022 10:06
@alari alari requested a review from DieMyst January 13, 2022 10:06
@alari alari added this to the 0.5.3 milestone Jan 13, 2022
@alari alari merged commit 5a8a702 into main Jan 13, 2022
@alari alari deleted the scalar-index-access branch January 13, 2022 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sugar Remove boilerplate syntax Syntax additions & changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow constants usage in ! operator
1 participant