[Bro] appending to a vector

Siwek, Jonathan Luke jsiwek at illinois.edu
Wed Jun 19 15:00:20 PDT 2013


On Jun 19, 2013, at 11:14 AM, David Mandelberg <david at mandelberg.org> wrote:

> What's the recommended way to append to a vector? The documentation 
> says vectors are like tables, so I tried the below code, but it gives 
> some errors.
> 
> const foo: vector of double = vector() &redef;
> 
> redef foo += {
>     [|foo|] = 42.0
> };

Appending to a vector can't currently be done w/ redef, but I don't think it would be difficult to implement if you want to add a ticket to the tracker.

> Maybe there's a better way to do what I want without vectors. I have a 
> somewhat complex record type and I want to store multiple records of 
> that type in a container of some sort. I want to be able to iterate over 
> the container, but I don't care about order (vector) or uniqueness 
> (set). When I tried using sets, I got the error below, so I switched to 
> vectors.
> 
> internal error: over-ran key in CompositeHash::RecoverVals
> Aborted


Can you give an example script that reproduces that (create a bug/ticket for it) ?

> I thought normal assignment to a const variable was supposed to fail. Isn't that a bug?


I agree that it shouldn't be allowed, but just to explain how it's currently working:  the const applies to the variable, not the value bound it.  So you can't assign further values to the const variable, but its value may still be mutable depending on its type.

- Jon



More information about the Bro mailing list