# syntax consistency question

**URL:** <https://community.zeek.org/t/syntax-consistency-question/1844>\
**Category:** Development\
**Tags:** development\
**Created:** [March 23, 2011, 2:26am UTC](https://community.zeek.org/t/syntax-consistency-question/1844 "2011-03-23T02:26:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [March 23, 2011, 2:26am UTC](https://community.zeek.org/t/syntax-consistency-question/1844/1 "2011-03-23T02:26:24Z")

</div>

set[string]  
and  
vector of string

Why do these have such differing syntaxes? I understand that internally vectors are really much more similar to tables than sets, but in usage they're more equivalent to an ordered set than a table (in my mind at least). If we add FIFO-type operations to vectors so that they're easier to work with, they would feel even more like ordered sets. For example, using a totally made up code snippet...

global stuff: vector[string] = vector();  
enqueue stuff["foo"];  
enqueue stuff["bar"];  
print |stuff|;  
&nbsp;&nbsp;==\> 2  
print dequeue stuff;  
&nbsp;&nbsp;==\> foo  
print dequeue stuff;  
&nbsp;&nbsp;==\> bar  
print |stuff|;  
&nbsp;&nbsp;==\> 0

Although it's essentially used as a FIFO here, it's still feels sort of set-y. BTW, this code or something like it working would be awesome. 🙂

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![Gregor\_Maier](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gregor\_Maier](https://community.zeek.org/u/Gregor_Maier)\
**Post date:** [March 25, 2011, 2:10am UTC](https://community.zeek.org/t/syntax-consistency-question/1844/2 "2011-03-25T02:10:32Z")

</div>

Yeah, I also discovered that vectors are kinda limited in their  
functionality. I think it would be great to have two different data  
types in Bro. Possibly both supporting the same.

\* array or vector (pretty much like the current vector type):  
&nbsp;&nbsp;+ O(1) random element access  
&nbsp;&nbsp;+ O(1) (armotized) adding to / removing from \*end\*  
&nbsp;&nbsp;+ O(n) adding to / removing from \*beginning\*  
&nbsp;&nbsp;+ grows (shrinks?) dynamically.

\* queue, deque (for FIFOs, stacks, etc)  
&nbsp;&nbsp;+ O(n) random element access  
&nbsp;&nbsp;+ O(1) adding/removing from \*either end\*

cu  
Gregor

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [March 27, 2011, 5:07pm UTC](https://community.zeek.org/t/syntax-consistency-question/1844/3 "2011-03-27T17:07:02Z")

</div>

Don't really like this syntax but also don't see another more  
intuitive operator. Could we just add more built-ins for vector  
operations like these? (e.g., vector\_dequeue(v)). As usual,  
type-safety would be a problem though.

Robin

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [March 27, 2011, 5:08pm UTC](https://community.zeek.org/t/syntax-consistency-question/1844/4 "2011-03-27T17:08:07Z")

</div>

Or more generally, lists. I agree, but adding that is a major task, I  
don't see that near-term. Perhaps for the 1.7 timeline?

Robin

---

<div class="post-metadata">

**Author:** ![Gregor\_Maier](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gregor\_Maier](https://community.zeek.org/u/Gregor_Maier)\
**Post date:** [March 27, 2011, 11:04pm UTC](https://community.zeek.org/t/syntax-consistency-question/1844/5 "2011-03-27T23:04:04Z")

</div>

sounds good to me

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [March 28, 2011, 2:15am UTC](https://community.zeek.org/t/syntax-consistency-question/1844/6 "2011-03-28T02:15:58Z")

</div>

Me too.

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [March 29, 2011, 12:49am UTC](https://community.zeek.org/t/syntax-consistency-question/1844/7 "2011-03-29T00:49:24Z")

</div>

Another vector wish list item: can we please make them zero-based? I  
propose to do that immediately while we're working on scripts anyway.

Robin

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [March 29, 2011, 1:00am UTC](https://community.zeek.org/t/syntax-consistency-question/1844/8 "2011-03-29T01:00:22Z")

</div>

Seems reasonable to me.

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![Gregor\_Maier](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Gregor\_Maier](https://community.zeek.org/u/Gregor_Maier)\
**Post date:** [March 30, 2011, 10:57pm UTC](https://community.zeek.org/t/syntax-consistency-question/1844/9 "2011-03-30T22:57:31Z")

</div>

IIRC, there's a #define that decides whether it's 0 or 1. (And yes, 0  
based seems great). IIRC, 0 might be used as a special value in C++ code  
but I'm not sure....

cu  
gregor

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [March 31, 2011, 3:45am UTC](https://community.zeek.org/t/syntax-consistency-question/1844/10 "2011-03-31T03:45:59Z")

</div>

Right, technically the change is trivial, I was mainly looking for a  
consensus. Seem we have one.

Robin

---

<div class="post-metadata">

**Author:** ![Vern](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/vern/32/630_2.png) [@Vern](https://community.zeek.org/u/Vern)\
**Post date:** [March 31, 2011, 4:00am UTC](https://community.zeek.org/t/syntax-consistency-question/1844/11 "2011-03-31T04:00:28Z")

</div>

> Right, technically the change is trivial, I was mainly looking for a  
> consensus. Seem we have one.

Well, depends on how you define consensus. I prefer indexing to start  
with 1. I think use of 0-basing is a holdover from C's too-low-level model  
equating arrays with pointers.

But given I'm the lone holdout, and vectors aren't something we've used  
much, I'm not going to fight hard. However, I can picture an attribute  
&base=1 or whatever to re-base particular vectors.

&nbsp;&nbsp;&nbsp;&nbsp;Vern

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [March 31, 2011, 4:09am UTC](https://community.zeek.org/t/syntax-consistency-question/1844/12 "2011-03-31T04:09:41Z")

</div>

> Well, depends on how you define consensus.

Defined as "hearing no objections so far". 🙂

> I prefer indexing to start with 1. I think use of 0-basing is a  
> holdover from C's too-low-level model equating arrays with pointers.

Maybe, but it's so common also with many other languages that I find  
it not worth the confusion that a different base causes.

> much, I'm not going to fight hard. However, I can picture an attribute  
> &base=1 or whatever to re-base particular vectors.

Oh, please not. That would be even worse because now one has to check  
everytime whether a vector has that attribute.

Robin

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:39pm UTC](https://community.zeek.org/t/syntax-consistency-question/1844/13 "2022-05-06T15:39:30Z")

</div>


