jemc changed the topic of #ponylang to: Welcome! Please check out our Code of Conduct => https://github.com/ponylang/ponyc/blob/master/CODE_OF_CONDUCT.md | Public IRC logs are available => http://irclog.whitequark.org/ponylang | Please consider participating in our mailing lists => https://pony.groups.io/g/pony
mahsav has quit [Ping timeout: 256 seconds]
mahmudov has quit [Ping timeout: 240 seconds]
jemc has quit [Ping timeout: 240 seconds]
Praetonus has joined #ponylang
dougmacdoug has left #ponylang [#ponylang]
jwashton has joined #ponylang
jwashton has quit [Ping timeout: 240 seconds]
sarna has quit [Quit: Connection closed for inactivity]
nisanharamati has quit [Quit: Connection closed for inactivity]
milisarge has joined #ponylang
<SeanTAllen> i like that, thats a cool feature. i see rust implemented with a macro. i look forward to when we have macros in Pony.
mahmudov has joined #ponylang
jemc has joined #ponylang
Praetonus has quit [Ping timeout: 240 seconds]
mahmudov has quit [Ping timeout: 240 seconds]
Praetonus has joined #ponylang
mahmudov has joined #ponylang
silverjam_ has joined #ponylang
silverjam_ has quit [Read error: Connection reset by peer]
jhorwitz has joined #ponylang
<jhorwitz> Evening all, new to Pony and excited
mahtob has joined #ponylang
mahmudov has quit [Ping timeout: 248 seconds]
jhorwitz has quit [Ping timeout: 248 seconds]
<SeanTAllen> howdy
Praetonus has quit [Quit: Leaving]
jemc has quit [Ping timeout: 240 seconds]
jemc has joined #ponylang
gokr has joined #ponylang
jemc has quit [Ping timeout: 252 seconds]
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
vaninwagen has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
user10032 has joined #ponylang
khan has quit [Quit: khan]
codec1 has joined #ponylang
inoas has joined #ponylang
_andre has joined #ponylang
sarna has joined #ponylang
khan has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
mahtob has quit [Remote host closed the connection]
codec1 has quit [Quit: Leaving.]
codec1 has joined #ponylang
milisarge has quit [Ping timeout: 248 seconds]
user10032 has quit [Quit: Leaving]
milisarge has joined #ponylang
inoas has quit [Quit: inoas]
inoas has joined #ponylang
inoas has quit [Quit: inoas]
inoas has joined #ponylang
sarna has quit [Quit: Connection closed for inactivity]
user10032 has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
mahmudov has joined #ponylang
jemc has joined #ponylang
vaninwagen has quit [Ping timeout: 264 seconds]
dougmacdoug has joined #ponylang
dougmacdoug has quit [Remote host closed the connection]
dougmacdoug has joined #ponylang
jwashton has joined #ponylang
jwashton has quit [Remote host closed the connection]
jwashton has joined #ponylang
jwashton has quit [Remote host closed the connection]
jwashton_ has joined #ponylang
jwashton_ has quit [Remote host closed the connection]
jwashton has joined #ponylang
jwashton has quit [Ping timeout: 264 seconds]
jwashton has joined #ponylang
vaninwagen has joined #ponylang
jwashton has quit [Ping timeout: 268 seconds]
jwashton has joined #ponylang
jwashton has quit [Remote host closed the connection]
jwashton has joined #ponylang
foofighterbar has joined #ponylang
<foofighterbar> Heya. I just started learning Pony last night, want to make a little demo program for myself. Is there a way I can read input from stdin, char by char? (i.e., without waiting for a newline)
<foofighterbar> and also I'm curious on how to clear the console.
<foofighterbar> Using those 2 pieces, I want to make a little snake game or something.
<jwashton> I can't speak to clearing the screen. There may be a way to do that, or you may need to FFI out to ncurses or something.
<jwashton> But the examples from the repo helped me figure input out. https://github.com/ponylang/ponyc/tree/master/examples Checkout the Main actor for readline.
<jwashton> The basic idea is that you want to define a StdinNotify listener that you register to `env.input`. The apply method of the listener does get called on every character, so that gives you exactly what you need.
<jwashton> In the readline example either `ANSITerm` or `Readline` are swallowing the extra events, so you only see new data on the newline.
<jwashton> Also, here are the docs for StdinNotify: https://stdlib.ponylang.org/builtin-StdinNotify/#stdinnotify
<jwashton> Actually, here's the learning code I wrote for that. https://gist.github.com/Jwashton/1598a358556a1a9dee8b84dc7a929a4b
sarna has joined #ponylang
<sarna> does `if windows` only work with `use`?
codec1 has quit [Read error: Connection reset by peer]
foofighterbar has quit [Quit: Left.]
foofighterbar has joined #ponylang
gokr has left #ponylang [#ponylang]
inoas has quit [Quit: inoas]
jwashton has quit [Remote host closed the connection]
<jemc> sarna: for platform-specific expressions in imperative pony code, use `ifdef windows then ... else ... end`
<jemc> foofighterbar: I've not done something like what you're talking about myself, but here's someone who did: https://github.com/jtfmumm/acolyte/
<sarna> jemc: alright, thanks. do I need #s before ifdef and end?
<jemc> foofighterbar: so you may be able to learn some tricks from peeking through the codebase of that project
<foofighterbar> jemc jwashton I got it working
<jemc> sarna: no need for those - it's not the C-style of preprocessor syntax - it's parsed just like an `if` expression, except it's `ifdef`, and the condition is a compile-time condition rather than a runtime condition
<sarna> jemc: sweet! thank you :)
<foofighterbar> In case anyone is interested: https://pastebin.com/72uGrAcK
<foofighterbar> However, I'm trying to figure out how to get essentially an immutable snapshot of an array
<foofighterbar> I have an isolated Array[U8 val]
<foofighterbar> but I want to print it out with env.out.print
<foofighterbar> which takes an immutable (val) Array[U8]
<foofighterbar> Which I understand-- presumably out is an actor (right)? and is getting passed something to render, and so it can't be passed something isolated (or else it could change when the output actor is reading it)
<sarna> consume? 🤔
codec1 has joined #ponylang
<foofighterbar> I haven't gotten that far in the tutorial :) Just started learning last night. Will look into that
<sarna> it's later in the capabilities section foofighterbar
<sarna> idk how well it'd work with iso though
<sarna> personally, I'd probably just create a copy and print it
inoas has joined #ponylang
<foofighterbar> sarna very cool! It works well here.
<foofighterbar> let snapshot: Array[U8 val] val = consume data
<foofighterbar> _env.out.print(snapshot)
<foofighterbar> where data = Array[U8 val] iso
<foofighterbar> I'm guessing the Array type has some sort of interface that allows it to be projected to a read-only val? (shrug)
<foofighterbar> this is a really interesting system
<sarna> oh '^ ^ that's good then
<sarna> consume can like "downgrade" a reference capability
<foofighterbar> makes sense
<foofighterbar> although to be frank, the syntax seems a bit archaic to me-- idk why all the keywords are shortened. And prefix seems much more natural to me for the capabilities
<foofighterbar> i.e., "isolated U8" instead of "U8 iso"
<foofighterbar> or "immutable U8" instead of "U8 val"
<foofighterbar> but that's just my first-blush impression
<sarna> do you want 160 characters in one line :D
<sarna> that's how you get 160 characters in one line
<foofighterbar> Why not? :) It's not like monitors aren't wide enough for it these days. We're not using hyper low res terminals
<sarna> you'd be surprised
<foofighterbar> I think intuitive readability is worth a little wasted space. Although I get that it's a hot topic
<foofighterbar> but definitely jumped out to me when reading on the language last night
<sarna> it's just a trade-off, like everything :^) I think it's the right choice
<sarna> it's like `array[5]` vs `array.getValueAtIndex(5)` to me
<sarna> the first one is shorter, easier to type, and more readable
<jemc> foofighterbar: so it's a current shortcoming of the Array interface that we can't have a `clone` method that returns the cloned array as an `iso` or `val` - the issue is that doing so is only safe when the element type (U8 in this case) is `val` or `tag`, and we don't have a way right now to express that constraint in a generic type
<sarna> once you get used to it :)
<jemc> so the inconvenient workaround is: create an `iso` or `trn` array, push the values into it, and then `recover` that array
<foofighterbar> It's fair, I get there's no consensus on it. But it definitely made the language seem a lot less high level to me when I first saw it. I think there's a difference between syntactic sugar (like [] ) verses shortened keywords. A few chars can go a long way for more intuitive keywords.
<jemc> sorry, I mean `consume` the resulting array
<foofighterbar> That being said-- really cool language, I'm having fun playing with it
<jemc> I'll give an example
<foofighterbar> so sarna, why did consume work for me here? Did the compiler simply tell that the underlying array elements were vals?
<foofighterbar> my updated code: https://pastebin.com/fraXbzg8
<foofighterbar> or, jemc, not sarna-- sorry
<jemc> `let copy = recover trn Array[U8](original.size()) end; for x in original.values() do copy.push(x) end; some_method_that_requires_array_val(consume copy)`
<jemc> foofighterbar: it worked for you, but you lost your original mutable array - it was consumed in the process
<sarna> ^
<jemc> that is, it *became* the immutable array, rather than copying the buffer into a new immutable array
<sarna> it's called "destructive read" iirc
<jemc> destructive read is the equivalent that you use for fields, because you can't consume a field without putting something in its place
<jemc> which looks like this: `let old_value = my_field = new_value`
<foofighterbar> Yep, that makes sense. I was referring to when you said "so it's a current shortcoming of the Array interface that we can't have a `clone` method", but I was misunderstanding that-- I get what you mean now.
<foofighterbar> Yeah, that all makes sense. It's a really interesting system. At first I was confused why I couldn't pass an iso to the out.print method (/behavior?) but then it made sense
<foofighterbar> I guess cloning would require a deep copy for anything that's not a Val in the array
<foofighterbar> I should be doing my real work.. but meh. I got nerd sniped by this. Thanks for answering my questions, I appreciate it!
<foofighterbar> So right now, at the end of my main actor, I do a busy wait-- what's a better way to have my main actor hang around until I'd like to quit?
<foofighterbar> Can I actually have behaviors on my main actor, or does it end the program after "create" terminates?
<SeanTAllen> foofighterbar: you don't have to
<SeanTAllen> foofighterbar: pony will detect when its time to shutdown
<SeanTAllen> you dont have to busy wait in main
<SeanTAllen> pony looks for quiescence
<SeanTAllen> which is
<SeanTAllen> 1) there is no possibility of external input (actors registered for async-io), there's no messages waiting to be processed
<SeanTAllen> sorry that is two things
<foofighterbar> That's incredibly interesting.
<foofighterbar> So, I got clearscreen working. Almost at the point where I have a little program that allows a dot to wander around a matrix.
<foofighterbar> using the wasd input keys
<dougmacdoug> @foofighter using ncurses?
<foofighterbar> Nope
<foofighterbar> dougmacdoug _env.out.print("\ec\e[3J")
<foofighterbar> clears screen on linux
<foofighterbar> so not portable, but good enough for now
<foofighterbar> Question: So, I'm trying to allocate an array as a buffer, fill it with characters, and then print it-- I'm having some difficulty
<foofighterbar> What's the recommended pattern for that?
<SeanTAllen> so printing, it involves send to another actor.
<SeanTAllen> so here's a question
<SeanTAllen> do you need to keep that array after you print
<SeanTAllen> or is it, print and start a new buffer @foofighterbar ?
<foofighterbar> Nope, I don't need it after printing. I'm trying to consume it, but the types aren't working out
<foofighterbar> let buffer = Array[U8 val](1)
<foofighterbar> buffer.push('t')
<foofighterbar> let final: Array[U8 val] val = consume buffer
<foofighterbar>
<foofighterbar> _env.out.print(final)
<foofighterbar> I think I need buffer to be of type Array[U8 val] iso, right? But I can't make it an iso
<foofighterbar> the array constructor seems to return a ref
<SeanTAllen> what you probably want is an iso buffer and you want to do a destructive read
<foofighterbar> How do I get the iso buffer?
<foofighterbar> I tried this: let buffer: Array[U8 val] iso = Array[U8 val](1)
<SeanTAllen> here's some pointers...
<foofighterbar> but I get the compilation error: right side must be a subtype of left side
<SeanTAllen> ok so first link is the definition of one
<SeanTAllen> 2nd link is where its initialized
<foofighterbar> Ah, so I need recover here.
<SeanTAllen> 3rd is the destructive read
<SeanTAllen> the destructive read replaces to old buffer binding with a new one
<foofighterbar> This works: let buffer: Array[U8 val] iso = recover Array[U8 val](1) end
<SeanTAllen> and binds the old buffer to a new variable that could be sent off for printing
<SeanTAllen> ues
<foofighterbar> so essentially recover is a way of transforming ref -> iso, and the compiler checks the lexical scope to make sure that it is actually the only reference?
<SeanTAllen> or you can do `recover iso `
<SeanTAllen> to be specific
<SeanTAllen> recover is a safe area
<SeanTAllen> no outside references are allowed in
<foofighterbar> very cool
<SeanTAllen> sorry no mutable references from outside the cover
<SeanTAllen> so you can do whatever you want in there and return as a val or iso after treating as mutable because its safe
vaninwagen has quit [Ping timeout: 264 seconds]
_andre has quit [Quit: leaving]
mahmudov has quit [Ping timeout: 256 seconds]
<foofighterbar> Alright, got it working, if anyone wants to check it out: https://pastebin.com/71uMxdfN
vaninwagen has joined #ponylang
<dougmacdoug> V #any ! is not a subtype of V #any
<dougmacdoug> muhg
foofighterbar has quit [Ping timeout: 252 seconds]
foofighterbar has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
jwashton has joined #ponylang
jwashton has quit [Client Quit]
khan has joined #ponylang
<jemc> probably missing a `consume` or a `^` somewhere
foofighterbar has quit [Ping timeout: 268 seconds]
inoas has quit [Quit: inoas]
<dougmacdoug> changed to val->V and got it working
<sarna> hey, I have a file helpers.pony and I want to use stuff from it from main.pony. what do I need to do?
<sarna> `use helpers` doesn't work
<sarna> s/helpers/"helpers"
<vaninwagen> sarna if helpers.pony is right next to main.pony in the same folder they are both part of the same package and you can simply use the types/classes/actors defined therein
<SeanTAllen> where is helpers.pony located?
<sarna> oh! didn't know that vaninwagen, thanks
<vaninwagen> sarna but subdirectories need to be "used": use "subdirectory"
<sarna> vaninwagen: directories, I don't care about files?
<vaninwagen> if you have a directory "sub" in the same folder as your main.pony and want to use some pony classes defined in "sub/marine.pony" from your main.pony, then you need to "import" the stuff from the "sub" directory
<vaninwagen> use "sub" in your main.pony
<sarna> SeanTAllen: yes, but somehow I skipped over that part
<sarna> vaninwagen: thanks, that's neat
foofighterbar has joined #ponylang
mahmudov has joined #ponylang
codec1 has quit [Read error: Connection reset by peer]
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
vaninwagen has quit [Ping timeout: 240 seconds]
<foofighterbar> Is there a way to make it so an actor stops answering messages?
<SeanTAllen> no
<SeanTAllen> what's your use case? what are you looking to do foofighterbar ?
<foofighterbar> Right now I have a main actor that receives a quit signal ('q' from the keyboard), and I want to make it so it doesn't answer any messages after that-- however, in the time it takes to close the input stream, there are already other inputs queued up
<foofighterbar> so right now I just have a var boolean "_accepting", where I stop doing anything with input when I'm no longer accepting-- so while everything is closing
<SeanTAllen> yup
<SeanTAllen> that's what you'd want to do
<foofighterbar> Okay cool, I was just curious if there was some sort of sugar around it
<foofighterbar> like "be move(d: Direction) if _accepting =>"
<SeanTAllen> you have to drain your queue or quiescence won't be hit and pony won't shut down.
<foofighterbar> Makes sense-- in this case I'm just draining the queue by essentially piping the events to /dev/null
<foofighterbar> I'm going to try modifying this little toy game to make it a snake game, just added in a timer
<foofighterbar> Think it would be worthwhile to add to the examples section, if I make it somewhat polished? I like finding little games like this when trying to learn a language
<SeanTAllen> Definitely, open a PR and folks can give it a review.
<SeanTAllen> Cant say it will be accepted but examples are good.
user10032 has quit [Quit: Leaving]
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang