Re: [Bro-Dev] [Proposal] Language extensions for better Broker support

2016-12-06 Thread Matthias Vallentin
> >   Alternative to even providing “type(v)”, you could have a “v is T”
> 
> I like that. That avoids the question of storing types altogether.

I think we can cover all type-based dispatching with "is" and "switch."
In fact, I see "x is T" as syntactic sugar for:

function is(x: any) {
switch(x)  {
  default:
return false;
  case T:
return true;
}
}

> > It might even be useful to try and spec out the co-routine support now
> > and see how this specific use-case fits in with that.
> 
> Need to think about that, would clearly be nice if we could pave the
> way for that already. 

+1

> Full enumeration doesn't seem possible, that would mean all possible
> types, no?

Yeah, not in a distributed systems, at least. I think I was coming from
C++ here where dispatching on type-safe unions requires complete
enumeration of all overloads. In Bro, we don't need that because we
cannot know the complete list of types a priori.

> Are we requiring "default" for the standard switch statement? If so, I
> agree it makes sense to do the same here (otherwise, not so sure,
> because of consistency).

Sounds good to me.

> > if ( type(v) == string )
> 
> I believe you misread this: "string" *is* a type.

Ah, now that makes sense!

> >  - Uplevelling, why do we need type() in the first place? Can't we just
> >overload the switch statement to work on types as well? Or do you
> >have other use cases in mind?
> 
> My main other use case was offering if-style comparision as well for
> types (see previous point). But if we do "is" for that, we indeed
> wouldn't need the type() anymore.

Good, I like "is" better than a type function because of readability.

> But explicitly specifying one each time takes away some of the
> simplicity.
>
> On the other hand, with a default timeout we'd probably need to throw
> runtime errors instead of returning something, and Bro isn't good with
> tons of runtime errors (which could happen here).

How is a timeout different from a failed computation due to a different
reason (e.g., connection failure, store backend error)? I think we need
to consider errors as possible outcomes of *any* asynchronous operation.
More generally, we need well-defined semantics for composing
asynchronous computations. For example, what do we do here?

# f :: T -> U
# g :: T
local x = async f(async g())?

One solution: if g fails, x should contain g's error---while f will
never execute. But in the common case of success, the user just wants to
work with x as an instance of T, e.g., when T = count:

count y = 42;
print x + y; # use x as type count

If x holds an error, then Bro would raise a runtime error in the
addition operator. Would that make sense?

Matthias
___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev


Re: [Bro-Dev] Package manager meta data

2016-12-06 Thread Robin Sommer


On Tue, Nov 29, 2016 at 17:42 +, you wrote:

> The metadata changes discussed in this thread are now in bro-pkg 0.8

I've tried this out now, it's all working great, thanks! I just
noticed one tiny little thing, for which I filed a ticket:
https://bro-tracker.atlassian.net/browse/BIT-1766

Robin

-- 
Robin Sommer * ICSI/LBNL * ro...@icir.org * www.icir.org/robin
___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev


Re: [Bro-Dev] [Proposal] Language extensions for better Broker support

2016-12-06 Thread Siwek, Jon

> On Dec 4, 2016, at 2:40 PM, Robin Sommer  wrote:
> 
> "(v as T)$foobar” vs "as(v)$foobar”.

Could just do some time trials to see which one people can type faster.  
There’s online typing speed tests that let you enter the test’s text.  I 
consistently typed "(v as T)$foobar” faster.

>> Is there a reason "type(v)” can’t be stored?
> 
> Mind elaborating how you would expect to use that?

Was thinking I’d end up doing something like (more a personal habit/style 
thing):

local t = type(v);

if ( t == count )
…
else if ( t == int )
...

But this example came to mind only because the draft didn’t have “v is T”.  
Point seems moot now.

> seems the existing switch could just infer that it's maching types by
> looking at case values: if they are types, it'd use "is" for
> comparision.

+1

>>  - In the switch statement, I would require that a user either provide
>>a default case or fully enumerates all cases. Otherwise it's too
>>easy to cause harder-to-debug run-time errors.
> 
> Are we requiring "default" for the standard switch statement? If so, I
> agree it makes sense to do the same here (otherwise, not so sure,
> because of consistency).

The “default" case is optional.  If it were required, I wouldn’t feel safer — 
maybe I don’t frequently make/see mistakes related to that and/or don’t find 
them hard to debug.

More often I’ve seen forgotten “break” at the end of a cases causing 
unintentional fallthroughs, but Bro does require explicit “break” or 
“fallthrough” statement to end cases.

- Jon

___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev