jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.28.0 | 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> <dscottboggs_gitlab> you can do `command --cmd a --cmd b --cmd c` with OptionParser
<FromGitter> <dscottboggs_gitlab> like ⏎ ⏎ ```parser.on "--cmd" do |val| ⏎ values << val ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5cf5b4a982c2dc79a54761e8]
<FromGitter> <Blacksmoke16> :0
<FromGitter> <Blacksmoke16> TIL
DTZUZO has quit [Ping timeout: 272 seconds]
wymillerlinux has joined #crystal-lang
<alex``> what does this error mean? file.puts modification_command.to_s % { "1" => shell_escape(in), "2" => shell_escape(out) }
<alex``> Syntax error in src/batch.cr:58: expecting variable or instance variable after out
<FromGitter> <dscottboggs_gitlab> out is a keyword
<FromGitter> <dscottboggs_gitlab> it's used in lib definitions
<alex``> oh :o
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
<alex``> thanks
<alex``> is there a more elegant way to
<alex``> on a loop:
<alex``> if i == o
<alex``> if cmd_same
<alex``> cmd_same ...
<alex``> I have a loop, test input and output, and for each passed test, I check after that if the command is defined..
<alex``> but I know already out of the loop if the command is defined or not
<alex``> if would like to better express without `if cmd_same` check
<alex``> with a single check I could do if (cmd_same) ... range.each, but I have multiple check in the loop, if input == output, if output.empty?, else
<FromGitter> <dscottboggs_gitlab> could you provide a code example? It's kinda hard to read the examples you're posting through IRC
<FromGitter> <dscottboggs_gitlab> I don't really understand the question yet
<alex``> dscottboggs_gitlab I find the `if commands[name]` checks ugly
<alex``> would like to avoid if in the loop
<FromGitter> <dscottboggs_gitlab> aah
<alex``> as I already know, out of the loop if the command is defined or not
<FromGitter> <dscottboggs_gitlab> oh, no nevermind my idea doesn't work in this case
<FromGitter> <dscottboggs_gitlab> hm
<alex``> with a single command, it would be easy
<alex``> if command
<alex``> for-loop
<alex``> but with multiple commands if more tedious
<FromGitter> <dscottboggs_gitlab> you could have `file.puts commands.fetch("remain", some_default) % { "1" => shell_escap in }`
<FromGitter> <dscottboggs_gitlab> or, along the same lines, `file.puts (commands["remain"] || some_default) % { "1" => shell_escap in }`
<alex``> it would still populate the file
<alex``> dscottboggs_gitlab maybe there is no way?
<FromGitter> <dscottboggs_gitlab> yeah... I think your best bet is ⏎ ⏎ ```if remain = commands["remain"] ⏎ file.puts remain % { "1" => shell_escape in } ⏎ els....``` [https://gitter.im/crystal-lang/crystal?at=5cf5c4d3702b7e5e762560ae]
<alex``> you would do the same way as I?
<FromGitter> <dscottboggs_gitlab> I would do it that ^^ way, but it's functionally the same as your exampel
<FromGitter> <dscottboggs_gitlab> it's certainly one of the more cumbersome examples of null safety
<alex``> how do you deal with optionals flags?
<alex``> commands["remain"] = nil
<FromGitter> <dscottboggs_gitlab> there's also ⏎ ⏎ ```commands["remain"].try do |remain| ⏎ file.puts remain % .... ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5cf5c547bf4cbd167c27c422]
<alex``> file.puts commands["remain"].to_s % { "1" => shell_escape(in) }
<alex``> I have to do
<alex``> commands["remain"].to_s
<alex``> to cast to string
<FromGitter> <dscottboggs_gitlab> not in my examples, because it's reassigned to a new variable whose type is `String` as opposed to `String?`
<alex``> oh
<alex``> I find your first solution more readable than the .try approach
<FromGitter> <dscottboggs_gitlab> which doesn't give you a performance hit because that happens in the compiled assembly anyway
<FromGitter> <dscottboggs_gitlab> I agree, the first example is how I usually do it
<FromGitter> <dscottboggs_gitlab> I usually only use `.try` when I'm calling a single method on a value, i.e. `maybe_nil.try &.method || default`
<FromGitter> <pynixwang> how to use a go lib in crystal?
<FromGitter> <dscottboggs_gitlab> not possible. They're very easy to translate though.
<FromGitter> <Blacksmoke16> id be surprised if you can?
<FromGitter> <pynixwang> not possible?
<FromGitter> <Blacksmoke16> cant be done
<alex``> I want to set an initial input, using `input = if` statement, BUT in case of reading from stdin, I have to do an additional work (reopening tty), so I end up with `input = [] of String; if ... input = ...; else input = ...; additional-work`
<FromGitter> <dscottboggs_gitlab> When I made crystal-darksky (https://github.com/dscottboggs/crystal-darksky), I copy-pasted large chunks of the golang (https://github.com/mlbright/darksky) implementation into Atom, and then used the split-cursor mode to edit all the lines at once. One could also do a simple regex replacement for large chunks of go source code to translate it to crystal structs
<alex``> there is no functional way to assign `variable = if` ?
<alex``> with extra-work in an if-else clause
<FromGitter> <dscottboggs_gitlab> > not possible? ⏎ ⏎ No, seriously. The only way that we are able to bind to C code is because C has a standardized binary representation. Golang does not have this, and large chunks of its standard library are implemented in inline assembly. There is absolutely no way to bind go libraries to *any* other language.
<FromGitter> <dscottboggs_gitlab> There is one library which generates C++ bindings, and it does so by generating a C file which calls the C++ functions, then binding to the C header.
<alex``> here is the snippets
<alex``> can the else clause be simplified?
<alex``> I want to avoid `value =`
<alex``> but if I put `STDIN.each_line.to_a` at the end, I cannot read stdin anymore..
<alex``> as I do `STDIN.reopen tty`
<alex``> is it a bug, Dir.glob("*") shows hidden files?
<alex``> https://crystal-lang.org/api/0.28.0/Dir.html#glob%28%2Apatterns%2Cmatch_hidden%3Dfalse%29%3AArray%28String%29-class-method
<FromGitter> <Blacksmoke16> should be fixed in next version
woodruffw has joined #crystal-lang
<alex``> is there a way to type options?
<FromGitter> <Blacksmoke16> hm?
<alex``> options = {} of Symbol => String | Bool | Nil
<FromGitter> <Blacksmoke16> well yea, you just did
<FromGitter> <Blacksmoke16> limited types it can be to symbol keys with value of either string bool or nil
<alex``> options[:confirm] = true
<alex``> options[:modify] = nil
<alex``> but options[:modify] is String | Bool | Nil
<alex``> I want to be String?
<alex``> and confirm Bool
<FromGitter> <Blacksmoke16> use a struct
<FromGitter> <Blacksmoke16> Options.new true, nil
<FromGitter> <Blacksmoke16> a hash's type is going to be a union of all possible types
<alex``> you mean
<alex``> instead of options[name]
<FromGitter> <Blacksmoke16> `record Options, confirm : Bool, modify : String?`
<alex``> confirm = Options.new(true, nil)
<FromGitter> <Blacksmoke16> yes
<FromGitter> <Blacksmoke16> well kinda
<alex``> oh
<FromGitter> <Blacksmoke16> juse use a struct to hold your values, then it can be typed correctly, and have methods
<alex``> what is `record`?
<FromGitter> <dscottboggs_gitlab> it's a shortcut for defining structs
<FromGitter> <dscottboggs_gitlab> kinda unnecessary IMO
<FromGitter> <Blacksmoke16> it defines a struct with an initalizer and getters
<FromGitter> <Blacksmoke16> :0
<FromGitter> <dscottboggs_gitlab> like I don't get why ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ because that's basically all it does (or as you said it only provides getters so not even that. [https://gitter.im/crystal-lang/crystal?at=5cf5d009faac64393436fe7e]
<FromGitter> <Blacksmoke16> much cleaner
<FromGitter> <dscottboggs_gitlab> like, I'm a fan of shortcuts but that seems like too much of a tradeoff of abstraction for conciseness
<FromGitter> <Blacksmoke16> and structs are usually meant for immutable data, so it just that
<FromGitter> <Blacksmoke16> i.e. not supplying properties by default
<FromGitter> <dscottboggs_gitlab> I don't get why you think that structs are usually immutable
<FromGitter> <mistergibson> I've JUST picked up my Crystal Programming book --> I'm stoked
<FromGitter> <dscottboggs_gitlab> Oh cool, a real paper book?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf5d07cbf4cbd167c2800fc]
<FromGitter> <dscottboggs_gitlab> fair enough
<FromGitter> <Blacksmoke16> mhm
woodruffw has quit [Read error: Connection reset by peer]
woodruffw has joined #crystal-lang
<FromGitter> <mistergibson> ebook --> I live in the cheap seats of life :/
<FromGitter> <dscottboggs_gitlab> fair enough.
<FromGitter> <dscottboggs_gitlab> I started learning Crystal by reading https://crystal-lang.org/reference/, mostly front-to-back.
<FromGitter> <mistergibson> I developed an app framework in Ruby, I'm keen on porting it to Crystal
<FromGitter> <mistergibson> good one
<FromGitter> <dscottboggs_gitlab> What kinda app?
<FromGitter> <mistergibson> anything really
<FromGitter> <mistergibson> it is a framework to make apps
<FromGitter> <mistergibson> alpha still -- but a labor of love to be sure
<FromGitter> <dscottboggs_gitlab> hm? Like...desktop, mobile, or web?
<FromGitter> <mistergibson> it started out desktop, but I made a modded version for Padrino for web apps
<FromGitter> <mistergibson> All but the gui done on the desktop version
<FromGitter> <mistergibson> but with Crystal -- wow, I get excited pondering the possibilities
<alex``> what did I do wrong
<FromGitter> <Blacksmoke16> `can't define struct inside def`
<FromGitter> <Blacksmoke16> prob used `record` within a def
<alex``> arguments have all to be specified with Options.new too?
<FromGitter> <Blacksmoke16> unless you give them defaults yes
<alex``> they are immutable by default with `record`, only getter are defined
<alex``> you have a reference to `record` to help me understand?
<FromGitter> <Blacksmoke16> correct
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.28.0/toplevel.html#record(name,*properties)-macro
<alex``> you know if it's explained if the reference/ doc
<alex``> ?
<FromGitter> <Blacksmoke16> `record` is just a shortcut to creating a struct
<alex``> may be a dump question, but named argument don’t work with @var in the constructor?
<FromGitter> <Blacksmoke16> Example?
<alex``> I committed a typo
<FromGitter> <Blacksmoke16> Rgr
<alex``> ok, so I tried to type confirm, and realized options can’t be bool @_@
<alex``> the value --confirm=value, value can’t be parsed to bool
<FromGitter> <Blacksmoke16> Cast as a book?
<FromGitter> <Blacksmoke16> Book
<FromGitter> <Blacksmoke16> Bool
<FromGitter> <Blacksmoke16> Sigh
<alex``> I used another approach: parser.on("--no-confirm", "no confirm") { options.confirm = false }
<FromGitter> <Blacksmoke16> Like !!confirm?
<FromGitter> <Blacksmoke16> False for nil, true for everything else
<alex``> I would liked to --confirm true | --confirm false, and doing { |value| options.confirm = value } directly
<alex``> with options.confirm being a Bool
<FromGitter> <Blacksmoke16> Value == "true"?
<alex``> well, I have to handle value == "true" or value == "false" or trigger error
<alex``> http://whatisthor.com has good typing
<alex``> for list, key=value pairs, etc.
<FromGitter> <Blacksmoke16> `options.confirm = {"true", "false"}.includes? value ? value == "true" : raise "Invalid value for confirm"`
<FromGitter> <Blacksmoke16> something like that maybe/
<FromGitter> <Blacksmoke16> anyway, imma get to bed o/
blassin has quit [Ping timeout: 246 seconds]
chemist69 has quit [Ping timeout: 252 seconds]
chemist69 has joined #crystal-lang
blassin has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Ping timeout: 256 seconds]
laaron has joined #crystal-lang
<FromGitter> <watzon> How exciting, and annoying
<FromGitter> <watzon> You're supposed to be able to pass blocks around right?
<FromGitter> <watzon> Kinda like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf5fe396fc5846bab5b531a]
Raimondi has quit [Read error: Connection reset by peer]
yxhuvud has joined #crystal-lang
DTZUZO has joined #crystal-lang
ashirase has quit [Ping timeout: 248 seconds]
ashirase has joined #crystal-lang
ua has quit [Ping timeout: 252 seconds]
ua has joined #crystal-lang
<FromGitter> <raymanoz> hi peeps
<FromGitter> <raymanoz> simple question
hightower2 has joined #crystal-lang
<FromGitter> <raymanoz> how do I negate a Bool ?
<FromGitter> <mavu> ! true
<FromGitter> <raymanoz> ! doesn't seem to be working for me (outside an if)
<FromGitter> <mavu> Aww, I was happy there was a question I could answer :)
<FromGitter> <raymanoz> `list.count(!&.empty?)` gives ` unterminated call`
<FromGitter> <watzon> You can't do that haha
<FromGitter> <watzon> You'd have to do the full block
<FromGitter> <raymanoz> ok......
<FromGitter> <raymanoz> ah--ok
<FromGitter> <watzon> `list.count { |l| !l.empty? }`
<FromGitter> <raymanoz> yep, got it
<FromGitter> <raymanoz> thx
<FromGitter> <watzon> No problem
<FromGitter> <raymanoz> :D
<FromGitter> <raymanoz> shame, though....
<FromGitter> <mavu> you could add not_empty? to your list class ...
<FromGitter> <mavu> :P
alex`` has quit [Ping timeout: 248 seconds]
alex`` has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <rishavs> @raymanoz strange. Seems to work for me.
<alex``> I'm writing a support language for Crystal
<alex``> what is the correct term for "fooo #{2 + 2}" #{2 + 2} part
<alex``> its name is "interpolation", "placeholder"?
<FromGitter> <Blacksmoke16> `interpolation`
<alex``> and the name of the whole, is "string interpolation" ?
<alex``> "..."
<FromGitter> <rishavs> Alex beat me to it
<alex``> XD
<FromGitter> <Blacksmoke16> yea
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
sz0 has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
moei has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
gangstacat has quit [Ping timeout: 252 seconds]
gangstacat has joined #crystal-lang
ua has quit [Excess Flood]
ua has joined #crystal-lang
gangstacat has quit [Ping timeout: 252 seconds]
DTZUZO has quit [Quit: WeeChat 2.0]
<FromGitter> <watzon> alex`` what do you mean by support language?
<FromGitter> <watzon> Like a Crystal looking scripting language?
gangstacat has joined #crystal-lang
<FromGitter> <nsuchy> @watzon What they're looking for is Ruby
<FromGitter> <nsuchy> 😂
<FromGitter> <watzon> Yeah, but until Crystal has a Ruby interpreter it's of limited use
<FromGitter> <nsuchy> pretty sure given time, motivation, perhaps money and research time, a developer could create a RubyGem that creates domain specific language to use Crystal's syntax differences inside of Ruby without needing to change the Crystal code other than changing the file extension.
<FromGitter> <nsuchy> @watzon Who said the entire program had to be written in Crystal
<FromGitter> <nsuchy> I switch between Ruby and Crystal depending on the task all day long
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <jirikivaari> I wish crystal would become almost drop-in placement for ruby
<FromGitter> <jirikivaari> I think that way it might have the best future
<mistergibson> no runtime env --> but one could perhaps be fashioned
<FromGitter> <kinxer> Crystal isn't designed to be a drop-in replacement for Ruby. The syntax is based on Ruby's, but there design guidelines (e.g. to minimize duplicate methods for the same purpose) that break completely from a "compiled Ruby".
<FromGitter> <straight-shoota> @kinxer In general, you're right. But reducing the amount of aliases is just a convention of Crystal's stdlib. You could easily implement a Ruby-compatible API for Crystal. There are however essential differences in the language itself (for example the type system) which makes any typical Ruby program incompatible with Crystal
<FromGitter> <kinxer> @straight-shoota Oh, yeah. I only have an issue with assertions that Crystal itself needs to conform to a standard of interoperability with Ruby. Obviously people can make their own shards/projects for whatever.
<alex``> watzon: support in the editor
<FromGitter> <Blacksmoke16> sublime is pretty decent
<FromGitter> <Blacksmoke16> formats on save, highlighting is pretty good
<FromGitter> <Blacksmoke16> can get some info where stuff is defined on hover
<FromGitter> <Blacksmoke16> deff not as expansive as like PHPStorm + PHP or RubyMine + Ruby but its workable
<FromGitter> <nsuchy> @Blacksmoke16 You don't have to pay for sublime unless you want to use in a business. I don't want to cause problems for CrystalLang Moderators (Google is your friend y'all) but there are ways to disable the evaluation prompt, if its strictly personal/education use I don't see an ethical use as long as the projects aren't money generating.
<FromGitter> <Blacksmoke16> i usually just hit cancel every time it pops up :P
<FromGitter> <nsuchy> (Sorry to IRC Bridge users who I just spammed with edits)
<FromGitter> <nsuchy> It's a legitimate license I promise :D
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<alex``> is "parenthesis" a typo?
<alex``> Valid delimiters are "parentheses" no?
hightower2 has quit [Ping timeout: 258 seconds]
<FromGitter> <girng> yea
wymillerlinux_ has joined #crystal-lang
wymillerlinux has quit [Ping timeout: 245 seconds]
wymillerlinux_ is now known as wymillerlinux
<alex``> should %(...) be highlighted same as string?
<alex``> "..."
<alex``> I'm writing a crystal.kak file
<alex``> and for regex
<alex``> /foo/ %r(foo)
<FromGitter> <girng> what editor are you using
<FromGitter> <girng> it's highlighted for me in vscode
<alex``> kakoune
<FromGitter> <girng> hmmmmm
<alex``> can you show me a picture ?
<alex``> %q(foo) %r(foo) %a(foo) %Q(foo) "foo" 'b' /foo/
<alex``> girng and the rest?
<alex``> /foo/mia too
<alex``> don’t know about %r(foo)mia
<alex``> thanks!
<FromGitter> <girng> like that? :O'
<alex``> yep
<FromGitter> <girng> i've never heard of kakoune before
<FromGitter> <girng> is that a new editor?
<alex``> yes
<FromGitter> <girng> interesting, thx
<alex``> btw I came here because I was writing a kakoune-like extension for chrome
<alex``> I needed Crystal for the native messaging (execute external commands in Chrome / Firefox)
<FromGitter> <girng> very cool
<alex``> yes
<FromGitter> <girng> how you like Crystal so far
<alex``> multiple selections works great in web browsers
<alex``> I’d like it much, but was not very used to typed languages
<alex``> (I started Crystal 1w ago)
<alex``> (it's a demo of chrome using multi-sel)
<FromGitter> <girng> nice nice
<alex``> are regex flags supported in %r(foo)m ?
<alex``> or only /foo/m
<alex``> it looks like there is no raw regex
<alex``> ?
<FromGitter> <girng> not sure about that personally, others will know though lol
<alex``> where I can find the reference for `shell-command`
<alex``> > Matz hopes to deprecate backtick syntax(``) for Ruby 3. We should warn about it at Ruby 2.6 (or 2.7?)
moei has quit [Quit: Leaving...]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<alex``> done :)
<FromGitter> <girng> 👍