ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
<irc_user> How would I get terminal rows/columns?
<FromGitter> <Blacksmoke16> idt theres a way to do that in the stdlib
<FromGitter> <Blacksmoke16> so would have to either like make some sys calls, bind to some c lib, or user a shard that provides it
<irc_user> Ah okay, thank you!
ur5us has quit [Ping timeout: 258 seconds]
typeof[panda] has joined #crystal-lang
typeof[panda] has quit [Quit: Client closed]
notzmv has quit [Ping timeout: 260 seconds]
<irc_user> Sorry but I just can't figure out how to run a process and get stdout. Is it not `output = = "tput", args = ["lines"], output = Process::Redirect::Pipe)`?
<FromGitter> <> I think the most simple way to do that is to just use backticks, like "output = `ls -l /`", like in Ruby. The $? variable can also be used to check that the process worked.
<irc_user> Wow.... well there goes an hour.......
<irc_user> Thank you very much
<FromGitter> <> Otherwise, you'd do something like: ⏎ ⏎ ```code paste, see link``` []
<irc_user> Haha I was about to ask that as well, thank you!
<FromGitter> <Blacksmoke16> you can also do like: ⏎ ⏎ ```io = ⏎ ⏎ "tput", ["lines"], output: io``` []
<FromGitter> <> If you want the lines/columns using a call to the C function `ioctl`, try this: ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <Blacksmoke16> there's also a block overload of `run` that exposes the output as it happens versus all at once
<irc_user> The backticks thing is pretty awesome. Crystal seems like it might even beat Python in some scripting use cases.
<FromGitter> <> The ioctl thing probably won't work outside of linux
<irc_user> I was trying to make a syscall to ioctl earlier but gave up because the docs said it would only work on Linux, but I'll save that snippet anyways as I'm sure it'll come in handy
<FromGitter> <> ☝️ Edit ( Otherwise, you'd do something like: ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <Blacksmoke16> if you just want to print it to the output of the parent process you can set `output: :inherit`
<irc_user> I'm coding game of life to try crystal out so I ended up doing: rows = `tput lines`.to_i; cols = `tput cols`.to_i; game = rows - 2, cols - 2
<FromGitter> <Blacksmoke16> are some CLI shards out there if that would help
<irc_user> Well I've got it up and running now so I'll probably look into those for the next project. This lang is awesome, I almost can't believe it's typed.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Blacksmoke16> it works out well, but ofc not without its cons
<irc_user> What would you say the main cons are, if you don't mind me asking?
<FromGitter> <Blacksmoke16> compile times, smaller ecosystem, and still maturing language features/platform support
<FromGitter> <Blacksmoke16> nothing really blocking, at least for majority of use cases
<irc_user> Ah, I see. Well the docs have had pretty much everything I've needed, apart from the terminal size thing which is probably a pretty niche use case. I did notice that the compile times are high, even for just a simple puts "hello world". But I mean, considering how much faster it is to write (so far), I'd say it seems to be a worthwhile tradeoff.
<irc_user> I wanted to give lisp/scheme a serious shot, and I think I still will, but this seems like it might be a better candidate to chase the snappy TUI text editior pipedream XD
<FromGitter> <Blacksmoke16> yea, just takes a bit of a diff workflow. write a bunch more before testing
<FromGitter> <Blacksmoke16> larger apps it can be dozen(s) seconds, in non-release mode too
<FromGitter> <Blacksmoke16> is some experimental interpreter support too, but still quite a bit of work to do on that
<irc_user> I'll keep that in mind, thanks. I'd like to think I'm good enough at coding now to do it in bigger chunks but my appending the same row to a matrix 10 times and wondering why all the columns kept coming out as identical for an hour makes me think otherwise haha.
<FromGitter> <> Yeeaahhhh... a release build of my unfinished port of Doom takes 21 minutes on my i9 ^_^; A debug build is only 5-6 seconds, though.
notzmv has joined #crystal-lang
<irc_user> That sounds like an awesome project
<irc_user> 21 minutes is quite steep too
ur5us has joined #crystal-lang
_ht has joined #crystal-lang
ur5us has quit [Ping timeout: 244 seconds]
pusewic|away__ has quit [Read error: Connection reset by peer]
pusewic|away__ has joined #crystal-lang
jmdaemon has quit [Ping timeout: 272 seconds]
<FromGitter> <grkek> Hi there
<FromGitter> <grkek> Haven't been here for a while
<FromGitter> <grkek> How are you?
<FromGitter> <> @grkek: hey, what's up?
Sankalp has quit [Ping timeout: 240 seconds]
Sankalp has joined #crystal-lang
Guest8745 has joined #crystal-lang
Guest8745 has quit [Ping timeout: 252 seconds]
Sankalp- has joined #crystal-lang
Sankalp has quit [Ping timeout: 276 seconds]
Sankalp- is now known as Sankalp
wwalker has quit [Remote host closed the connection]
<SamantazFox_> <Blacksmoke16> larger apps it can be dozen(s) seconds, in non-release mode too <- Minutes, even!
<FromGitter> <Blacksmoke16> indeed
<irc_user> Building strings with `+=` surprisingly appears to be really slow compared to node, is there a faster way to do it? Can provide example if that helps.
<FromGitter> <Blacksmoke16> id read that whole page
<irc_user> Will do, thank you
<irc_user> That's way faster, reality makes sense again. Thank you. Though, node is still only 30% slower, which is pretty crazy.
<FromGitter> <Blacksmoke16> 👍
jmdaemon has joined #crystal-lang
_ht has quit [Remote host closed the connection]
<FromGitter> <dorianmariefr> Hi, I'm new to Crystal, I'm trying to create a little DSL with "with ... yield" but I'm getting an error, anyone has any idea how to fix it? thanks
<FromGitter> <Blacksmoke16> should the 2nd file have been crystal code?
<FromGitter> <Blacksmoke16> or is there more to it?
<FromGitter> <dorianmariefr> Oops bad habit, I'm coming from ruby, it's all crystal
<FromGitter> <dorianmariefr> Doing this works, so I guess it's from passing the block to another method: ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <dorianmariefr> Not the best but I guess I will just do: ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <dorianmariefr> I'm pretty bad at crystal meta-programming, also tried to have specs with input/output array and couldn't make it
<FromGitter> <dorianmariefr> And `instance_eval` doesn't help, I will learn I guess :D
<FromGitter> <Blacksmoke16> `with ... yield` has some issues as well. prob be easier to just have a block arg
<FromGitter> <dorianmariefr> "be easier to just have a block arg", what do you mean? I already have &block
<FromGitter> <dorianmariefr> You mean `definition.instance_eval(&block)`?
<FromGitter> <Blacksmoke16> instead of ⏎ ⏎ ```language = Language.create do ⏎ root do ⏎ ⏎ end ⏎ end``` []
<FromGitter> <Blacksmoke16> do
<FromGitter> <Blacksmoke16> ```language = Language.create do ⏎ root do ⏎ ⏎ end ⏎ end``` []
<FromGitter> <Blacksmoke16> ```code paste, see link``` []
<FromGitter> <Blacksmoke16> via like `yield definition` or `yield language`
<FromGitter> <dorianmariefr> yeah I saw a PEG library did that, not a big fan, my rules are already hard to read :D
<FromGitter> <Blacksmoke16> another option is to take a step back and consider alternative options versus porting things 1:1
<FromGitter> <dorianmariefr> I was thinking I could also write with macros
<FromGitter> <dorianmariefr> It's the base of multiple languages I'm thinking of writing, so I want the DSL to be nice, very inspired by parslet in ruby I admit
<FromGitter> <Blacksmoke16> i think something else is going on
<FromGitter> <dorianmariefr> It's the first PEG I'm writing and the hard part is more into the parser itself, like building atoms, still unsure how to do that
<FromGitter> <Blacksmoke16> like does `Definition` actually have a `#any` method?
<FromGitter> <dorianmariefr>
<FromGitter> <dorianmariefr> It's the block passing that isn't working
<FromGitter> <Blacksmoke16> ⏎ ⏎ > The default receiver within a captured block can't be changed by using with ... yield. ⏎ ⏎ I take that to mean what you want to do just isnt possible []
<FromGitter> <> Adding a type seems to work
<FromGitter> <> Line 21
<FromGitter> <Blacksmoke16> there's no captured blocks in that example tho, so works just as good without it
<FromGitter> <> Oh whoops I copied the wrong code
<FromGitter> <dorianmariefr> but yeah @Blacksmoke16 I thought I add an "Original Idea™️" but actually it becomes clearer and clearer I'm just porting parslet to crystal :D
<FromGitter> <dorianmariefr> s/add/had
ur5us has joined #crystal-lang
<FromGitter> <Blacksmoke16> xD
ur5us has quit [Ping timeout: 255 seconds]