<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Actually, the 'as' operator is useful, since it appears that 'any' 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"><<a href="mailto:jsiwek@corelight.com" target="_blank">jsiwek@corelight.com</a>></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 'is' and<br>
'as' 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 <<a href="mailto:jmellander@lbl.gov">jmellander@lbl.gov</a>> wrote:<br>
><br>
> Thanks, Johanna - I think type_name() may suffice for the purposes I am envisioning.<br>
><br>
> On Thu, Aug 16, 2018 at 1:57 PM, Johanna Amann <<a href="mailto:johanna@icir.org">johanna@icir.org</a>> wrote:<br>
>><br>
>> Hi Jim,<br>
>><br>
>> On 16 Aug 2018, at 13:40, Jim Mellander wrote:<br>
>><br>
>>> It would be most convenient if the 'any' type could defer type checking<br>
>>> until runtime at the script level.<br>
>>><br>
>>> For instance, if both A & B are defined as type 'any', a compile time error<br>
>>><br>
>>> "illegal comparison (A < B)"<br>
>>><br>
>>> occurs upon encountering a bro statement<br>
>>><br>
>>> if (A < B) do_something();<br>
>>><br>
>>> even if the actual values stored in A & B at runtime are integral types for<br>
>>> which comparison makes sense.<br>
>><br>
>><br>
>> 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>
>><br>
>> However...<br>
>><br>
>>><br>
>>> If the decision could be made at runtime (which could then potentially<br>
>>> throw an error), a number of useful generic functions could be created at<br>
>>> the script level, rather than creating yet-another-bif. A useful<br>
>>> yet-another-bif would be 'typeof' to allow varying code paths based on the<br>
>>> type of value actually stored in 'any'.<br>
>><br>
>><br>
>> 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>
>><br>
>> Johanna<br>
><br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> bro-dev mailing list<br>
> <a href="mailto:bro-dev@bro.org">bro-dev@bro.org</a><br>
> <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>