<div dir="auto"><div>The sort function&#39;s second argument must be a function. Below, I use an anonymous function but you could also define and declare it. Think of this second function as a map function which is applied to the vector you&#39;re sorting. </div><div dir="auto">Sorting is done in place, too. So you may want to add a copy() function to your definition of vo.<br><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div dir="auto">event zeek_init() {</div><div dir="auto">  local v: vector of interval = vector(1min,2min,1min,4min,6min,1min);</div><div dir="auto">  local vo : vector of interval = sort(copy(v), function(a: interval, b:</div><div dir="auto">interval): int {return a &gt; b ? 1 : -1;} );</div><div dir="auto">  for (i in vo) {</div><div dir="auto">    print vo[i];</div><div dir="auto">  }</div><div dir="auto">}</div><div dir="auto"><br></div><div dir="auto">-AK</div></div><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Sat, May 16, 2020, 13:03 Tomek Koziak &lt;<a href="mailto:ttomek.koziak@gmail.com">ttomek.koziak@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi All,</div><div>When I try to run the following code</div><div><div><br></div><div>event zeek_init()<br>        {<br>        local v: vector of interval = vector(1min,2min,1min,4min,6min,1min);<br>        local vo : vector of interval = sort(v);<br>            for (i in vo){<br>                    print vo[i];<br>            }       <br>        }<br></div></div></div><div><br></div><div>I get the expected output by as well I obtain the following error:</div><div>line 4: comparison function required for sort() with non-integral types (sort(v)) fatal error: errors occurred while initializing<br></div><div><br></div><div>I have followed the documentation. </div><div><a href="https://docs.zeek.org/en/current/scripts/base/bif/zeek.bif.zeek.html#sort" target="_blank" rel="noreferrer">https://docs.zeek.org/en/current/scripts/base/bif/zeek.bif.zeek.html#sort</a><br></div><div>But I quite don&#39;t understand the part about the comparison function as a second argument. What parameter should be placed as a second argument? <div><a href="https://docs.zeek.org/en/current/scripts/base/bif/zeek.bif.zeek.html#sort" target="_blank" rel="noreferrer"></a></div></div><div><br></div><div>Tomasz</div></div>
_______________________________________________<br>
Zeek mailing list<br>
<a href="mailto:zeek@zeek.org" target="_blank" rel="noreferrer">zeek@zeek.org</a><br>
<a href="http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/zeek" rel="noreferrer noreferrer" target="_blank">http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/zeek</a></blockquote></div></div></div>