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

evaluator: Add map builtins has and del #45

Merged
merged 3 commits into from
Oct 26, 2022
Merged

evaluator: Add map builtins has and del #45

merged 3 commits into from
Oct 26, 2022

Conversation

juliaogris
Copy link
Member

@juliaogris juliaogris commented Oct 24, 2022

Add builtin function del for entry removal from map:

del {a: 1} "a" // {}

Add builtin function has for entry existence check in map:

has {a: 1} "a" // true

@github-actions
Copy link

github-actions bot commented Oct 24, 2022

firebase-deployment: https://evy-lang--45-68dhr1m4.web.app (20d51b5)

pkg/evaluator/builtin.go Outdated Show resolved Hide resolved
pkg/evaluator/builtin.go Show resolved Hide resolved
pkg/evaluator/evaluator_test.go Show resolved Hide resolved
pkg/evaluator/builtin.go Outdated Show resolved Hide resolved
pkg/evaluator/builtin.go Outdated Show resolved Hide resolved
@juliaogris juliaogris force-pushed the map-builtins branch 5 times, most recently from ae9dd4d to ac882ff Compare October 26, 2022 00:41
Refactor map of no type from EMPTY_MAP to GENERIC_MAP and similarly
refactor array of no type from EMPTY_ARRAY to GENERIC_ARRAY.

We are currently using empty maps `{}` and arrays `[]` of no type as
literals in expressions and assignments and give them a type in a
deferred manner: e.g. [1 2] + [] makes the second array an array of num
only when needed.

We also now allow parameters to be of type GENERC_MAP or GENERIC_ARRAY,
which can can only be used in builtin functions captured in the changes
to the function `assertArgTypes` in parser.go

In a follow up commit we are going to reuse this concept not only as
literal for delayed type binding but also to mark a parameter type
as "generic" map or array. This means a parameter hast to a be map, but
it could be a map of any, num or other types.

This will be useful for discovering invalid types for builtin functions
`has` and `del` when the first parameter passed is not a map.
Add builtin function `has` for entry existence check in map:

	has {a: 1} "a" // true
Add builtin function `del` for entry removal from map:

	del {a: 1} "a" // {}
Copy link
Contributor

@camh- camh- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍏

@juliaogris juliaogris merged commit 1b2d288 into master Oct 26, 2022
@juliaogris juliaogris deleted the map-builtins branch October 26, 2022 01:06
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

2 participants