Matthias247 has quit [Read error: Connection reset by peer]
jemc has quit [Ping timeout: 260 seconds]
tm-exa_ has joined #ponylang
_andre has joined #ponylang
wizeman has joined #ponylang
anqur has joined #ponylang
<anqur>
Hi, I'm a Pony beginner but I'm reading the source of the libponyrt for learning the actor implementation. I got some questions about *scheduling* that why an `asio` instance starts with the thread register? And why thread registering uses an empty thread-local *this_scheduler*? What for? Hope that someone could help me with that. Thanks!
<zevlg>
hey guys, what is the best way in pony to read huge files in asynchronous way, doing bunch of file content processing in parallel ? is there any common pattern to "read huge file" ?
<zevlg>
it could be recursive behaviors for reading from file! nice
dougmacdoug has quit [Read error: Connection reset by peer]
aav_away_ is now known as aav
wizeman has quit [Ping timeout: 240 seconds]
omarkj has quit [Ping timeout: 258 seconds]
wizeman has joined #ponylang
omarkj has joined #ponylang
jtfmumm__ has quit [Ping timeout: 258 seconds]
emilbayes has quit [Ping timeout: 258 seconds]
jtfmumm__ has joined #ponylang
dougmacdoug has joined #ponylang
emilbayes has joined #ponylang
<SeanTAllen>
zevlg: the file library is currently synchronous. the pattern would be to have an actor that reads in the file and you can get data from that actor in some fashion.
<SeanTAllen>
anqur: each scheduler is a thread. for each CPU that the pony runtime has access to, it creates a scheduler thread to run actors usin that CPU.
<SeanTAllen>
so, the first step in setting up any scheduler is creating a thread for it to run on
<SeanTAllen>
you can think of the asio subsystem as a special form of scheduler that only handles async io events
<SeanTAllen>
there are command line options to pin schedulers to specific cpus and one for pinning the asio thread as well
<anqur>
Yes I noticed that option in the start.c and main.c files. So I can say that the asio could be handled by random CPU if pinasio is not specified, right?
<SeanTAllen>
i would say that it is unspecificied and liable to change
<anqur>
Oh thanks for answering me! I'm gonna read something about why when `library' specified and it would as well register a thread before creating the schedulers thread...I didn't read them through so I dare not to ask...but your answer is really helpful for my further reading! :D
<zevlg>
btw: is there something similar to `struct` to bind directly to C unions? Or what is the correct way to do it ?
jemc has joined #ponylang
<SeanTAllen>
zevlg: i havent done anything very serious with FFI so I'm not the correct person to answer that. Jemc would be a much better person to answer.
<zevlg>
jemc: hey, do you know any way in pony to bind directly to C union? something similiar to `struct` stuff
<jemc>
hm, I've never had to bind to a C union before, and not sure if there is an established pattern for it - can you paste the definition of the C union you want to bind to, and maybe I can help figure something out
<jemc>
zevlg: hm, I'm not sure, honestly - we should probably raise this for a broader discussion - can you file an issue ticket in the rfcs repo, as a "request for RFC", and we can discuss how we want to handle unions in structs
<jemc>
I suspect we should use some form of annotation, just as we do for packed structs, but it would need an RFC
<jemc>
if you wanted a short term hacky solution, you could write a little C shared library to be linked with your pony program that defines a simple C function that returns its argument, and you could use that for doing a C-style "cast" of one pony type to another
<jemc>
so basically in your case, you could define that union field as being of type `Pointer[None]` to represent the void pointer (which is the largest in the union), then use the C call hack to cast to `I32` or `U32` as needed.
<jemc>
but as I said, allowing unions to be defined in a first class way in Pony is what we really need
<zevlg>
yeah, a have some not so obvious unions as well to bind to
<jemc>
it would be good to give some of the not-so-obvious examples too in the issue ticket, so they can be considered when deciding if the proposed solution is general enough
aav has quit [Quit: Lost terminal]
amclain has joined #ponylang
graaff has joined #ponylang
aav has joined #ponylang
tm-exa_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
graaff has quit [Quit: Leaving]
anqur has quit [Quit: Connection closed for inactivity]
<aav>
can anyone explain why the following code fragment is invalid?
aedigix has quit [Remote host closed the connection]
aedigix has joined #ponylang
<jemc>
aav: you probably want `| let r': Union =>` on line 13
<jemc>
though as you probably already know, it's a rather useless match statement since you're matching for the type you already know it is
<jemc>
`| Union =>` is basically short for `if r == Union.create()`
<jemc>
which doesn't work, since you can't construct a union type
<jemc>
that is, you can't call a constructor on one, since you wouldn't know which one to call
<jemc>
`| Type1 =>` works for primitives, since `if r == Type1.create()` is a valid way to compare a value to a primitive
<aav>
and what if I want to say 'if r is Union then ....'?
<jemc>
but in general, for non-primitives you need to use `let`
<jemc>
aav: you basically want `match f1() | let r: Union => ... end`
<jemc>
that will give you a conditional block that runs if the return value of `f1` is of that union type, and it gives you access to the value under the name `r` within the block
<aav>
this is clear. so effectively it means that 'is' operator cannot be used for union types?
<aav>
same story with Tuple, but different error message
<jemc>
> so effectively it means that 'is' operator cannot be used for union types?
<jemc>
not true, but the issue is that the `is` operator doesn't do what you're thinking it does
<jemc>
the `is` operator will return true if the left side and the right side are the same *object* not the same *type*
<jemc>
so if I did something like `let a: Type1 = Type1; let a': Union = a`
<jemc>
then `a' is a` would return true
<jemc>
the two references have different types (`a'` is a `Union`, `a` is a `Type1`), but they refer to the same object (an instance of `Type1`)
<jemc>
of course, because `Type1` is a primitive, every single instance of it that I "create" in any thread will be the same object
<jemc>
so `a is Type1` will work for a primitive, because it translates to `a is Type1.create()`
<aav>
it means 'is' actually something like '==, but without type checking'?
<aav>
i can say 'if Type1 is Type2 ', but cannot say 'if Type1 == Type2 ...'
_andre has quit [Quit: leaving]
<aav>
jemc: thank you for the explanation
<jemc>
the best way to think about it is that `is` compares *identity*, and `==` checks *structural* equality (by delegating to the `eq` method of the class)
<jemc>
but yes, identity can be compared for references of two different types
<jemc>
the `==` operator could also do this, if the `eq` method implements
<jemc>
for example, nothing stops me from defining `fun eq(that: Type2): Bool => ...` on `Type1` (imagining for a moment that we're talking about classes, not primitives)
<jemc>
so the `==` operator can be used/abused to mean whatever you want it to mean, based on what you implement
<aav>
yes, i understand
<aav>
as a bottom line - the only way to check is the object is of some type is to match it with 'let ...' pattern
<aav>
without 'let...' it will try to create an instance, and match on value