ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.32.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <oren> how to check for existence of a command line argument? i tried ARGV.length but it tells me length doesn't exist
<FromGitter> <Blacksmoke16> `ARGV.includes?`
<FromGitter> <ImAHopelessDev_gitlab> length doesn't exist
<FromGitter> <ImAHopelessDev_gitlab> what do you mean
<FromGitter> <oren> where do you see includes? https://crystal-lang.org/api/0.32.1/toplevel.html#ARGV
<FromGitter> <Blacksmoke16> `ARGV` is just an array of strings
<FromGitter> <ImAHopelessDev_gitlab> includes? works on array types, so won't show on ARGV docs
<FromGitter> <oren> ok. let me find it
<FromGitter> <oren> i think i need .size
<FromGitter> <oren> i need to check if arguments were passed or not
<FromGitter> <Blacksmoke16> `ARGV.empty?`
<FromGitter> <oren> interesting. works !
<FromGitter> <ImAHopelessDev_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e37675e58f02e34975cc197]
<FromGitter> <ImAHopelessDev_gitlab> doesn't crystal have a get_argv method or something, i remember writing one last year
<FromGitter> <ImAHopelessDev_gitlab> i remember seeing that
<FromGitter> <ImAHopelessDev_gitlab> how would we use it to get the value of `rofl`
<FromGitter> <ImAHopelessDev_gitlab> that api looks convoluted af
<FromGitter> <Blacksmoke16> `parser.on("--rofl", "Some Desc") { |rofl| pp rofl }`
<FromGitter> <ImAHopelessDev_gitlab> wtf
<FromGitter> <ImAHopelessDev_gitlab> LOL
<FromGitter> <Blacksmoke16> hm?
<alex``> the equivalent of ruby array.lazy.select(block).map(block) is just #each (without block) in crystal?
<FromGitter> <Blacksmoke16> yes, returns an iterator
<alex``> ruby #each does not that?
<FromGitter> <Blacksmoke16> well related to that so question, could do everything in `map` the do `compact!`
<alex``> I don't understand why #lazy was mentionned
<alex``> instead of just using #each
<alex``> oh
<alex``> > If no block is given, an Enumerator is returned.
<alex``> is there a reason why ruby #each doesn't return an iterator like crystal?
<alex``> when no block is specified
<FromGitter> <Blacksmoke16> idk
<FromGitter> <ImAHopelessDev_gitlab> i love how gitter dies in confusion parsing alex's name
<alex``> lol
<FromGitter> <ImAHopelessDev_gitlab> πŸ˜‚πŸ˜‚
<FromGitter> <ImAHopelessDev_gitlab> Everyone else: Watching the Superbowl ⏎ Me: Discussing ARGV on gitter
<FromGitter> <tenebrousedge> what's a superbowl?
<alex``> is there a way to specify the receiver when filtering a hash?
<FromGitter> <tenebrousedge> maybe. What are you trying to do?
<alex``> data.each.reject(&value.zero?)
<alex``> specifying the receiver for zero?
<alex``> being the value
<FromGitter> <tenebrousedge> `data.reject(&.last.zero?)`
<FromGitter> <tenebrousedge> keypairs are yielded as a tuple
<alex``> hm
<FromGitter> <tenebrousedge> huh, but what does `reject` yield?
<alex``> both |key, val|, |(key, val)|, |{key , val}| are valid then?
<FromGitter> <tenebrousedge> I don't think the last is valid
<alex``> tenebrousedge: data = { "days" => @span.days, "hours" => @span.hours, "minutes" => @span.minutes, "seconds" => @span.seconds }
<FromGitter> <tenebrousedge> you might have to do `each_pair.reject(&.last.zero?`
<alex``> why?
<alex``> ```
<alex``> data.each_pair.reject(&.last.zero?).map do |key, value|
<alex``> data << "#{value} #{key}"
<alex``> end.join(' ')
<alex``> ```
<FromGitter> <tenebrousedge> `join` takes a block
<alex``> without 'data <<'
<FromGitter> <tenebrousedge> `data.each.reject(&.last.zero?).join(&.join(' '))`
<FromGitter> <tenebrousedge> or wait, value first?
<FromGitter> <tenebrousedge> `data.each.reject(&.last.zero?).join(&.reverse.join(' '))`
<alex``> (does not compile)
<alex``> why join takes a block?
<FromGitter> <tenebrousedge> https://play.crystal-lang.org/#/r/8i1l
<FromGitter> <tenebrousedge> why not? it's useful
<alex``> oh
<alex``> join can be used for surrounding
<FromGitter> <tenebrousedge> it slices, it dices!
ur5us has quit [Ping timeout: 265 seconds]
<alex``> hm
<alex``> just though it could be nice to to_s supporting argument
<alex``> 10.to_s("(%s)")
<alex``> %d
<alex``> [1, 2, 3, 4, 5].join(", ") { |i| "(#{i})" }
<alex``> could be
<alex``> [1, 2, 3, 4, 5].join(", ", &.to_s("(#{i})"))
<FromGitter> <tenebrousedge> there's `"(%d)" % 10`
<FromGitter> <tenebrousedge> follows sprintf
<FromGitter> <tenebrousedge> ```formatstring = "(%d)" ⏎ (1..5).join(", ", &->formatstring.%(Int32))``` [https://gitter.im/crystal-lang/crystal?at=5e376fc8433e1d403990c398]
<alex``> data.each.reject(&.last.zero?).join(' ') do |key, value|
<alex``> "#{value} #{key}"
<alex``> end
<alex``> this join is really net
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<alex``> is there a way to extend printf format?
<FromGitter> <tenebrousedge> why?
<alex``> I want to add a sweet syntax to my chronic_date.to_s(format) to display the time span from now humanized
<FromGitter> <tenebrousedge> how is this not solved with sprintf?
<alex``> sprintf is extensible?
<FromGitter> <tenebrousedge> your format string can be arbitrarily complex. You can write your own `to_s` method, as well
<alex``> I just want to add my '%h' or something when calling .to_s(format)
<alex``> https://crystal-lang.org/api/0.32.1/Time.html#to_s(format:String):String-instance-method
<alex``> I don't see how to add our own format
<alex``> seems not possible
<FromGitter> <tenebrousedge> I'm not understanding why you see this as necessary
ur5us has joined #crystal-lang
<alex``> when doing data.to_s(format)
<alex``> I want to add this
<FromGitter> <Blacksmoke16> just provide an option for format? and call it a day
<alex``> human_duration = Chronic::Duration.new(Chronic::Time.new(data).from_now).humanize
<alex``> so I can do: echo 'tomorrow 10:20 am' | chronic '%F %{my_time_span_from_now_duration}'
<alex``> which display `YYYY-MM-DD remaining days remaining hours, etc.`
<alex``> that is why I want to add a format-like
<alex``> instead of an option
<alex``> the quick way I see is doing a gsub
<alex``> :X
_whitelogger has joined #crystal-lang
<alex``> yes but I lost control of the formatting
<alex``> (this command-line program is intended to work with editors)
<alex``> doing pipe on text
<alex``> selecting text and piping with the format as argument
<alex``> for replacing
<alex``> having extra remaining: is not intended
<alex``> but they require a lot of structure if I want to go on this path
<alex``> a time implementing to_s, format, formatter, parser..
<alex``> a lot a files xD
<alex``> x(
<alex``> reader is a scan reading a char and advancing in place on the string?
<alex``> char by char
<FromGitter> <watzon> Yep
<alex``> I facepalm for the complexity I'm going into just for adding my time format
<FromGitter> <Blacksmoke16> cant you just have the user provide a format and pass that to `.to_s`?
<FromGitter> <Blacksmoke16> like `--format '%f renaming {{seconds}}`
<alex``> {{seconds}} is built-in to_s?
<alex``> a week from sunday confused me indeed
<alex``> it looks out of the scope of my tool to do that in my source code directly
<alex``> gsub block replacement is nice for saving call in case of no match
<FromGitter> <Blacksmoke16> RIP my GPU
<FromGitter> <ImAHopelessDev_gitlab> @Blacksmoke16 what happened
<FromGitter> <Blacksmoke16> Heard a tsss and computer shut off
<FromGitter> <Blacksmoke16> Then smelled the smell you don't want to smell ha
<FromGitter> <tenebrousedge> D: you let the magic smoke out!
<FromGitter> <Blacksmoke16> Ikr?
* FromGitter * Blacksmoke16 renames my self bluesmoke
<FromGitter> <Blacksmoke16> Oh well
Dreamer3 has quit [Quit: Leaving...]
Dreamer3 has joined #crystal-lang
<alex``> xd
alex`` has quit [Quit: WeeChat 2.7]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
alex` has joined #crystal-lang
alexherbo2 has joined #crystal-lang
alex` is now known as Guest33331
Guest33331 has quit [Ping timeout: 268 seconds]
alexherbo2 has quit [Ping timeout: 268 seconds]
<FromGitter> <ImAHopelessDev_gitlab> so now you are using onboard graphics?
<FromGitter> <Blacksmoke16> For now yea
<FromGitter> <Blacksmoke16> Down to a peasently one monitor :p
ur5us has quit [Ping timeout: 260 seconds]
return0e has quit [Ping timeout: 265 seconds]
return0e has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> @Blacksmoke16 do you program in any other languages besides crystal
<FromGitter> <ImAHopelessDev_gitlab> So glad I got Notepad++'s format on save to work with Crystal. I feel like I'm 17 again coding. Good times
<FromGitter> <grkek> How does one make the hash accessible in multiple threads HM ?
_ht has joined #crystal-lang
_ht has quit [Quit: _ht]
alexherbo2 has joined #crystal-lang
Guest33331 has joined #crystal-lang
lunarkitty has quit [Ping timeout: 245 seconds]
lunarkitty has joined #crystal-lang
Dreamer3 has quit [Quit: Leaving...]
Guest33331 is now known as alex``
ur5us has joined #crystal-lang
<repo> with a mutex?
ur5us has quit [Ping timeout: 260 seconds]
<alex``> hi
<alex``> I'm trying to understand the crystal source code of time
<alex``> can you tell me if i'm correct?
<alex``> The entry-point of `time` to generate a time from a string is `parse(time_str, printf_pattern)`.
<alex``> It calls `time/format.cr`, which initializes with `printf_pattern` and call parse with `time_str`.
<alex``> The entry-point of `time.cr` to generate a string from a time is `to_s(printf_format)`.
<alex``> It calls `time/format.cr`, which initializes with `printf_pattern` and call the formatter with the time.
<alex``> The two classes (formatter and parser) encapsulate certain data for their stuff and use a common interface `visit` in `time/format/pattern.cr`, which is the actual parser.
<alex``> `visit` advance char by char in the pattern, when it encounters a recognized format, it calls methods by certain name, which are implemented by `formatter.cr` and `parser.cr`.
<alex``> for `parser` it means consumming the string it received when initializing, and set for example `@day` with the given string portion.
<alex``> for `formatter` it means pushing to the `io` it received when initializing, and print the correct date format with `time` is has when initializing.
<alex``> `format` is typically called with just the `time` format, but under the hood it build a string with a block and pass both `time` and the `str` io to the formatter.
masterdonx2 has quit [Ping timeout: 268 seconds]
MasterdonX has joined #crystal-lang
<FromGitter> <mavu> Current Mood: Writing c++. I wish I could use crystal to do embedded development. :(
<FromGitter> <confact> @mavu what is missing to use crystal for embedded?
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <mavu> Crystal is too big to be used on the sort of chips I use. I don't think the crystal compiler can or will ever target Atmel microcontrolers. or even something like an ESP32. (although the later might theoretically have enough memory i think)
<FromGitter> <straight-shoota> @mavu lvm target
<FromGitter> <Blacksmoke16> @ImAHopelessDev_gitlab yes
<FromGitter> <Blacksmoke16> for work
<FromGitter> <straight-shoota> @mavu The compiler itself could relatively easily target embedded chips, as long as there's an llvm backend available. The limiting factor is however the standard library. There have been attempts to build alternative stdlibs with much smaller footprint.
<FromGitter> <straight-shoota> So that could technically be an option for embedded systems.
<FromGitter> <straight-shoota> alex, your assessment of the time formatter architecture is correct
<FromGitter> <mavu> @straight-shoota Bigger chips are becoming more cheap, so in a couple of years this will probaboy be a non issue anyway. (i hope)
<FromGitter> <j8r> there will always be small limited chips
<FromGitter> <faustinoaq> @elorest Hi again, sorry I couldn't reply, I'm working at DELL EMC now, I'm kinda free from 7:00 P.M to 10:00 P.M. EST.BTW, I'm working on a DELL internal API using Amber πŸ’ͺ
<FromGitter> <j8r> economizing even $0.01 on billion chips results to 10 millions dollars saved
<FromGitter> <faustinoaq> @mavu I remember someone tried to port crystal to smt32, those chips are very powerful and pretty cheap, and I think it is possible. Also, I have an unfinished experiment about crystal on AVR chips like arduino and attiny, I'll try to finish it and share it with the crystal community πŸ˜„
<livcd> Is there anything (even just theoretical) way to solve the slow compile times at least for development process ?
<FromGitter> <j8r> livcd: shared libraries, in C. In Crystal it is very experimental
<livcd> dont really get it
<FromGitter> <j8r> for example, instead of using a Crystal shard, using a C library
<FromGitter> <j8r> or write you libraries in C
<FromGitter> <j8r> but this strips the point of Crystal then
<livcd> yeah
<FromGitter> <j8r> there are POC gists/issues about shared libraries in Crystal
<FromGitter> <j8r> there is also making the compiler multi-threaded
<FromGitter> <grkek> Is there something like
<FromGitter> <grkek> calling crystal compiled functions
<FromGitter> <grkek> from js ?
<FromGitter> <faustinoaq> @grkek Nim can do that, Crystal not yet, I think there is an open issue on github about Javascript and Crystal.
<FromGitter> <grkek> thank you
duane has quit [Ping timeout: 265 seconds]
<FromGitter> <faustinoaq> @grkek Also you can try Mint https://www.mint-lang.com/, this front-end language is built on crystal, so you can do interesting things with it, similar to react and vue.
<FromGitter> <j8r> anyone has experience with Mint? What's its pros/cons vs Svelte or Vue?
<FromGitter> <grkek> I've seen that
<FromGitter> <grkek> that is one of the most interesting things
<FromGitter> <grkek> ive came across so far
<FromGitter> <grkek> I really like the JSX approach to rendering
duane has joined #crystal-lang
duane has quit [Ping timeout: 252 seconds]
<FromGitter> <Blacksmoke16> @straight-shoota `docker run --rm -it -v $PWD:/app -w /app crystallang/crystal:0.32.1-alpine crystal build --release --static --no-debug --link-flags "$(pkg-config libxml-2.0 --libs --static)" src/oq_cli.cr` ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e383844f301780b83632e2a]
duane has joined #crystal-lang
hightower2 has joined #crystal-lang
<FromGitter> <straight-shoota> @Blacksmoke16 you're shelling out, calling `pkg-config` on the host, not in the container.
<FromGitter> <straight-shoota> Escaping the `$` it should work
<FromGitter> <tenebrousedge> just using single quotes should work
<FromGitter> <Blacksmoke16> oo good call, sec
<FromGitter> <Blacksmoke16> yea that seemed to do it
<FromGitter> <straight-shoota> I caught it immediately when trying to run the command in an environment where pkg-config isn't available
<FromGitter> <Blacksmoke16> πŸ‘ good stuff, this is deff a bit easier to manage than before
<FromGitter> <Blacksmoke16> now to try and figure out how to run a workflow to build the binary and add it to the releast on GH actions...
<alex``> is there a way to chain forwarding? between a method and a proc?
<alex``> puts object.join(options.separator, &->Chronic::Time.new(Time)&formatter)
<FromGitter> <tenebrousedge> not in Crystal
<FromGitter> <tenebrousedge> well
<FromGitter> <tenebrousedge> you could maybe make a partial
<FromGitter> <tenebrousedge> but I don't think that's what you're after
<alex``> what is a partial?
<FromGitter> <tenebrousedge> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e385f0aea9ba00b84ac795c]
<FromGitter> <Blacksmoke16> burn the witch
<FromGitter> <tenebrousedge> @Blacksmoke16 are GPUs witches?
<FromGitter> <Blacksmoke16> 😒 dont remind me
<alex``> partial = curry?
<FromGitter> <tenebrousedge> yes
<alex``> is there a way to rename the object in case when?
<FromGitter> <Blacksmoke16> hm?
<alex``> to a more meaningful name
<alex``> case object
<alex``> when Time -> call it time
<alex``> when Range(Time, Time) -> call it time range
<FromGitter> <tenebrousedge> `when (a = othername)` maybe
<FromGitter> <tenebrousedge> `when (a = othername && condition)`
<FromGitter> <tenebrousedge> but I would probably try to avoid such things
<alex``> yes
<alex``> it's less readable
_ht has joined #crystal-lang
<alex``> when Chronic::Range
<alex``> range = object
<alex``> I do this currently, just after the wen
<alex``> when*
<alex``> maybe there is another approach
<alex``> that using case/when
<FromGitter> <Blacksmoke16> not really, sounds like it would be a pita
<alex``> it looks good to you?
<alex``> I forgot the `puts text` L11-12
<FromGitter> <Blacksmoke16> ah ok, yea probably fine
<alex``> initially I was doing `text = case object` and print the return text after the block, but since I added the "Should sleep?" I cannot organize my code that way
<FromGitter> <tenebrousedge> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e3865b3ea9ba00b84ac8e90]
<FromGitter> <tenebrousedge> assuming that `object` is a string
<FromGitter> <tenebrousedge> or no, it's a time, isn't it?
<FromGitter> <tenebrousedge> sheesh
<FromGitter> <636f7374> Do you like to write Crystal code without parentheses?
<FromGitter> <tenebrousedge> personally? not particularly
<FromGitter> <636f7374> parentheses: `sleep(time.from_now)` -> `sleep time.from_now`.
<FromGitter> <tenebrousedge> quite
<FromGitter> <636f7374> I like it, this is the advantage of Crystal / Ruby. (Compared to Rust).
<FromGitter> <636f7374> πŸ™‚
<FromGitter> <tenebrousedge> it's nice that it's an option. It helps with code golf sometimes
<FromGitter> <636f7374> πŸ˜€
<FromGitter> <Daniel-Worrall> I use parentheses when there's ambiguity, if the parameters call methods or if it calls another method (can fall under ambiguity)
<FromGitter> <tenebrousedge> I wrote a Lisp in Crystal so that I can use parentheses with my parentheses in my parentheses o_____o
<FromGitter> <636f7374> Lisp is good, Clojure is better。 :)
erdnaxeli has quit [*.net *.split]
alexherbo28 has joined #crystal-lang
alex`` has quit [Ping timeout: 265 seconds]
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo28 is now known as alexherbo2
<FromGitter> <watzon> Well clojure is a lisp, so...
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Remote host closed the connection]
alex`` has joined #crystal-lang
ur5us has joined #crystal-lang
erdnaxeli has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
erdnaxeli has quit [*.net *.split]
duane has joined #crystal-lang
erdnaxeli has joined #crystal-lang
<FromGitter> <wontruefree> We are hosting Vitalii Elenhaupt a Fullstack Software Developer and Crystal enthusiast. A high level architecture of the Ameba linter, the role of built-in Crystal’s Lexer and AST parser and future plans/challenges to make Ameba better. chicagocrystal.org/events/dfpqmrybcdbjb/
_ht has quit [Remote host closed the connection]
<FromGitter> <rurounijones_gitlab> @lbarasti Thanks: I have zero experience with LLVM so, while I am sure there are tools out there, I have no idea what they would be nor how to use em, any recommendations would be appreciated!
Human_G33k has joined #crystal-lang
duane has quit [Ping timeout: 265 seconds]
HumanG33k has quit [Ping timeout: 260 seconds]
ur5us has quit [Ping timeout: 265 seconds]