<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Actually, the &#39;as&#39; operator is useful, since it appears that &#39;any&#39; can currently only be cast into a string otherwise....<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 16, 2018 at 2:58 PM, Jon Siwek <span dir="ltr">&lt;<a href="mailto:jsiwek@corelight.com" target="_blank">jsiwek@corelight.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the master branch, there are also type checking/casting &#39;is&#39; and<br>
&#39;as&#39; operators [1] and type-based switch statement [2] that may be be<br>
useful.<br>
<br>
- Jon<br>
<br>
[1] <a href="https://www.bro.org/sphinx-git/script-reference/operators.html" rel="noreferrer" target="_blank">https://www.bro.org/sphinx-<wbr>git/script-reference/<wbr>operators.html</a><br>
[2] <a href="https://www.bro.org/sphinx-git/script-reference/statements.html#keyword-switch" rel="noreferrer" target="_blank">https://www.bro.org/sphinx-<wbr>git/script-reference/<wbr>statements.html#keyword-switch</a><br>
<div><div class="h5"><br>
On Thu, Aug 16, 2018 at 4:24 PM Jim Mellander &lt;<a href="mailto:jmellander@lbl.gov">jmellander@lbl.gov</a>&gt; wrote:<br>
&gt;<br>
&gt; Thanks, Johanna - I think type_name() may suffice for the purposes I am envisioning.<br>
&gt;<br>
&gt; On Thu, Aug 16, 2018 at 1:57 PM, Johanna Amann &lt;<a href="mailto:johanna@icir.org">johanna@icir.org</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi Jim,<br>
&gt;&gt;<br>
&gt;&gt; On 16 Aug 2018, at 13:40, Jim Mellander wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; It would be most convenient if the &#39;any&#39; type could defer type checking<br>
&gt;&gt;&gt; until runtime at the script level.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; For instance, if both A &amp; B are defined as type &#39;any&#39;, a compile time error<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &quot;illegal comparison (A &lt; B)&quot;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; occurs upon encountering a bro statement<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; if (A &lt; B) do_something();<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; even if the actual values stored in A &amp; B at runtime are integral types for<br>
&gt;&gt;&gt; which comparison makes sense.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; I think this is a bit hard to do with how things are set up at the moment internally - and it also does make type-checking at startup less possible-helpful.<br>
&gt;&gt;<br>
&gt;&gt; However...<br>
&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; If the decision could be made at runtime (which could then potentially<br>
&gt;&gt;&gt; throw an error), a number of useful generic functions could be created at<br>
&gt;&gt;&gt; the script level, rather than creating yet-another-bif.  A useful<br>
&gt;&gt;&gt; yet-another-bif would be &#39;typeof&#39; to allow varying code paths based on the<br>
&gt;&gt;&gt; type of value actually stored in &#39;any&#39;.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; This already exists and I think you can actually use it to write code like that; you just have to cast your any-type to the correct type first. The function you want is type_name; it is e.g. used in base/utils/json.bro.<br>
&gt;&gt;<br>
&gt;&gt; Johanna<br>
&gt;<br>
&gt;<br>
</div></div>&gt; ______________________________<wbr>_________________<br>
&gt; bro-dev mailing list<br>
&gt; <a href="mailto:bro-dev@bro.org">bro-dev@bro.org</a><br>
&gt; <a href="http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev" rel="noreferrer" target="_blank">http://mailman.icsi.berkeley.<wbr>edu/mailman/listinfo/bro-dev</a><br>
</blockquote></div><br></div>