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

Sets supporting += for adding individual elements #3714

Open
vpax opened this issue May 1, 2024 · 1 comment
Open

Sets supporting += for adding individual elements #3714

vpax opened this issue May 1, 2024 · 1 comment
Labels
Area: Scripting Complexity: Modest A cup of tea and an evening (or two) with Zeek. Implementation: Core Implementation requires modification of the Zeek core Priority: Low Type: Enhancement

Comments

@vpax
Copy link
Contributor

vpax commented May 1, 2024

Currently if you have S1: set[count] and S2: set[count] you can use S1 += S2 to add the elements of S2 to S1. I find myself expecting that S1 += 5 ought to work too, equivalent to add S1[5].

This is clearly a minor syntactic issue, but I wanted to capture the notion.

@vpax vpax added Complexity: Modest A cup of tea and an evening (or two) with Zeek. Priority: Low Type: Enhancement Area: Scripting Implementation: Core Implementation requires modification of the Zeek core labels May 1, 2024
@bbannier
Copy link
Contributor

bbannier commented May 3, 2024

Since set's += currently means "set union" a workaround would be to construct a single element set for the RHS which is not a lot more typing, e.g.,

local s = set(1, 2, 3);
s += set(4);

+= also exists for table where it has the same semantics (append container).

vector is currently the only container which additionally supports += to mean add an element. This can be confusing, especially for containers over any where it becomes unclear whether we want to append a container or insert an element. IMO the append-element semantics for vector += are surprising and ideally we would not have it, and expanding this to more container types does not seem like a good idea to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Scripting Complexity: Modest A cup of tea and an evening (or two) with Zeek. Implementation: Core Implementation requires modification of the Zeek core Priority: Low Type: Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants