RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
faitswulff has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
<devil_tux> vladfaust: sorry for late response, though someone was pinging you ... yup, that may work
<devil_tux> meanwhile, this is how I did it:
<devil_tux> child_ptr = Pointer(LibXML::Node).new(child.object_id)
<devil_tux> tmp_child_ptr = Pointer(LibXML::Node).malloc(sizeof(LibXML::Node))
<devil_tux> tmp_child_ptr.copy_from(child_ptr, sizeof(LibXML::Node))
<devil_tux> tmp_child = XML::Node.new(tmp_child_ptr)
<devil_tux> basically, create new pointer with object from previous child and work upon it, inside the each I redeclare tmp_doc and push tmp_child to it
<devil_tux> might be a bit unsafe tho' :> haven't tried slices yet
<devil_tux> btw im not sure content would be appropriate here .. mind sharing a snippet?
laaron has quit [Remote host closed the connection]
<devil_tux> let me create a skeleton
laaron has joined #crystal-lang
<FromGitter> <codenoid> i'm back lmao
<FromGitter> <codenoid> after long vacation
<FromGitter> <HarrisonB> Is there a way to restrict a generic type, similar to how one would do it in java? (`T extends Foo`)
<devil_tux> hi codenoid, wb :>
<devil_tux> time spent well?
<FromGitter> <codenoid> @devil_tux yeah, <3
<devil_tux> glad to hear <3
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<devil_tux> so @channel, this is what am trying to accomplish: https://carc.in/#/r/6ha4
<devil_tux> any direction points are appreciated
<devil_tux> in short, recursive xml node children rebuilder on struct avoiding complete overwrite yielding array of string w/ value document content .. uh, not even kidding ..
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<devil_tux> i think i made it o.o https://carc.in/#/r/6hcg
laaron has quit [Remote host closed the connection]
faitswulff has quit [Remote host closed the connection]
laaron has joined #crystal-lang
faitswulff has joined #crystal-lang
laaron has quit [Remote host closed the connection]
faitswulff has quit [Ping timeout: 240 seconds]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
chemist69 has quit [Ping timeout: 240 seconds]
chemist69 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
faitswulff has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
faitswulff has quit [Remote host closed the connection]
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
crystal-lang564 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
fullforce has joined #crystal-lang
<fullforce> hi
<crystal-lang564> hi there
<fullforce> I am trying to pass an argument to a function call but it doesnt seem to compile
<fullforce> 1min
<fullforce> args is supposed to be a hash that I want to pass on to the function
<fullforce> apologies for the bad wording
<crystal-lang564> how does the function look like. Please show me the first line
<fullforce> def test2(args : EventHolster)
<fullforce> alias EventHolster = Hash(String, Int32 | String | EventHolster)
<fullforce> crystal-lang564:
<crystal-lang564> if you call that function then it must match. I'm new to crystal and had similar problems but could solve them after having a close look to the error message
<fullforce> ah I see now
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<fullforce> is there a way I can make the overload accept different types?
<fullforce> tried to cast Hash(String, String) to a Hash(String, Int32|String)
laaron has quit [Remote host closed the connection]
<crystal-lang564> maybe you write functions with different signatures. The compiler will use then that function that match.
<fullforce> can you elaborate on that please
<crystal-lang564> crystal play is a good help
<fullforce> what do you mean by diffent signatures
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<crystal-lang564> example: foo(h : Hash(String, String)) and foo(h : Hash(String, Int32))
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
za1b1tsu 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]
<FromGitter> <yxhuvud> fullforce: `String` and `String|Int32` have a different size in memory, so they can't be casted directly.
<FromGitter> <bew> @HarrisonB not yet #3298
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Ping timeout: 256 seconds]
<FromGitter> <ditsara> quick question - does Crystal have a relatively uniform way to check for empty objects? for instance `#present?` and `#presence` in Rails
<FromGitter> <yxhuvud> `present?` doesn't only check for emptyness, it also checks for not being nil etc. a variable that is nil is totally separate from if it is empty.
laaron has joined #crystal-lang
laaron has quit [Client Quit]
<FromGitter> <ditsara> yes that's what I meant -- a check for nil, empty, whitespace only in a string, etc
laaron has joined #crystal-lang
<FromGitter> <bararchy> `"string".nil?` will check for nil
<FromGitter> <bararchy> `["a"].empty?` will check if it's empty
<FromGitter> <bararchy> and `[nil, "a", nil].compact` will clear all `nil` values in the array for example
<FromGitter> <bararchy> hope it helps
<FromGitter> <ditsara> thanks ... it sort of helps i guess
<FromGitter> <bararchy> btw, a better way idiomatic to Crystal is ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c88d5b9aa0efc2382df1810]
<FromGitter> <ditsara> i was thinking more along the lines of `#presence` in Rails, where you have one uniform way to set default values
<FromGitter> <bararchy> I don't actually use rails so no idea :)
<FromGitter> <ditsara> ie `x = some_input.presence || "default value"`
<FromGitter> <bararchy> oh
<FromGitter> <bararchy> you can just do ⏎ ⏎ ```a = var || "default value" ``` [https://gitter.im/crystal-lang/crystal?at=5c88d6027d754e09e39a87b1]
<FromGitter> <bararchy> same way TBH
<FromGitter> <bararchy> if it's nil it's falsy, so will take default value
<FromGitter> <ditsara> i mean if `some_input` could be an empty string
<FromGitter> <bararchy> ahh
<FromGitter> <bararchy> ok
<FromGitter> <bararchy> no such magic here :)
<FromGitter> <ditsara> ah okay :)
<FromGitter> <straight-shoota> It's not magic, I think it's more of a hack.
<FromGitter> <bararchy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c88d68384c0313aab4166ce]
<FromGitter> <bararchy> that's the only way I can think of doing similar logic
<FromGitter> <ditsara> yeah that's the same logic, just a bit more verbose
<FromGitter> <bararchy> @straight-shoota It's just a VERY ruby thing to do, automagiclly get rid of Nils or unexpected input, while the right way would be to make a more restrictive checking and validation
<FromGitter> <straight-shoota> IMHO it doesn't make much sense to combine the meaning of `nil` and an "empty" value
<FromGitter> <straight-shoota> Especially in Crystal where we have static nil checks
<FromGitter> <bararchy> ^ agree
<FromGitter> <straight-shoota> But also in Ruby it stinks. If `nil` and `""` mean the same thing, there should only be one of them.
<jokke> has anyone here worked with webrtc? is there a way to send broadcasts or do any type of peer discovery?
<FromGitter> <bew> #aliases 😂
<FromGitter> <bew> Gnn
<FromGitter> <straight-shoota> :P
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<jokke> yxhuvud: `"foo".try(&.size.> 0)` would work as a sort of `present` for strings
<jokke> Yxhuvud: since crystal supports re-opening classes you could also write a shard for this
<FromGitter> <yxhuvud> @straight-shoota I think `present?` make sense in a rails context when handling different inputs, but as a general language feature it doesn't make sense
<FromGitter> <ditsara> @yxhuvud yeah I agree it's most useful in a web app (or general input handling) context. i guess it wouldn't be too hard to write a shard for this that monkey patches Object, String, etc.
<FromGitter> <straight-shoota> Yeah, maybe. But even there it should only be used once for mapping input to internal representation. There is no need to have this everywhere in your business logic.
<FromGitter> <ditsara> > it should only be used once for mapping input to internal representation ⏎ yeah that's pretty much the use case -- processing user input
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <straight-shoota> And user input is usually strings, so you only need `String#present?` and don't inject a method in every `Object`.
<FromGitter> <bararchy> `String#present?` is strange, because `String`can't be Nil, otherwise it's not `String`
<FromGitter> <bararchy> then it only becomes a matter of `.empty?` which we already have
<FromGitter> <straight-shoota> @bararchy But then you can do `string.try &.present?`
<FromGitter> <straight-shoota> It's just a negation of `#empty?` which works with try
<FromGitter> <bararchy> hmm I see, well, I guess it's fine :)
ua has quit [Ping timeout: 246 seconds]
ua 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> <vladfaust> Could you please reminder how to get a dev/null IO?
<FromGitter> <vladfaust> I.e. `Logger.new(DEV_NULL)`
laaron has quit [Remote host closed the connection]
<FromGitter> <vladfaust> `Logger.new(File.open(File::DEVNULL))`
laaron has joined #crystal-lang
za1b1tsu has quit [Ping timeout: 245 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
ternarysolo has joined #crystal-lang
laaron has joined #crystal-lang
za1b1tsu has joined #crystal-lang
faitswulff has joined #crystal-lang
laaron has quit [Remote host closed the connection]
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
xaxisx has joined #crystal-lang
ternarysolo has quit [Ping timeout: 240 seconds]
ternarysolo has joined #crystal-lang
faitswulff has quit [Remote host closed the connection]
laaron has joined #crystal-lang
faitswulff has joined #crystal-lang
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
za1b1tsu has quit [Remote host closed the connection]
ua has quit [Excess Flood]
ua has joined #crystal-lang
sagax has quit [Remote host closed the connection]
sagax has joined #crystal-lang
<FromGitter> <j8r> Hey folk, what do you think of having `myvar.not Nil`? This will be contrary of `myvar.as T`
<FromGitter> <bew> Like... `myvar.not_nil!` ?
<Yxhuvud> so a replacement to not_nil! that can handle arbitrary type subtraction?
<FromGitter> <j8r> and deprecate not_nil! then
<FromGitter> <bew> That's actually pretty simple to implement @j8r
<FromGitter> <bew> Deprecate?... Meh
<FromGitter> <j8r> Yeah because `not` can provide a nice error message compared to a very useful `Nil assertion failed`
<FromGitter> <j8r> that's another reserved method, I know this may be not ideal. But I haven't found any other alternative
<FromGitter> <bew> Why reserved?
<FromGitter> <bew> It can be just a method
<FromGitter> <bew> On Object
<FromGitter> <bew> Or whatever
<FromGitter> <j8r> I've tried
<Yxhuvud> `def not(Type)` would normally not be super easy to create a conflict with.
<FromGitter> <j8r> I haven't succeed to got something like `Cast from T to U failed`
<Yxhuvud> but perhaps it needs to be syntax?
<FromGitter> <j8r> ... perhaps I haven't done this properly, I looked how `as` was implemented
<FromGitter> <bew> @j8r https://carc.in/#/r/6hg6
<FromGitter> <j8r> yeah got it too
<FromGitter> <j8r> Thanks you :)
<FromGitter> <j8r> I have seen this in the wrong angle
<FromGitter> <Blacksmoke16> neat
<FromGitter> <j8r> you have done better than me @bew !
<Yxhuvud> That works out with the types? niiice.
<FromGitter> <bew> Crystal is awesome 🎉
<FromGitter> <bew> :D
<Yxhuvud> indeed.
<FromGitter> <Blacksmoke16> https://carc.in/#/r/6hg9 what now :0
<FromGitter> <j8r> I mention your solution @bew
<Yxhuvud> blacksmoke: it would always raise.
<Yxhuvud> just as nil.not_nil!
<FromGitter> <Blacksmoke16> yea i see that now, just didnt because of the typeof
<FromGitter> <j8r> thats like `typeof(raise "")`
<FromGitter> <j8r> I posted in the @Blacksmoke16 issue
rohitpaulk has joined #crystal-lang
<Yxhuvud> @j8r: I think you should create a new issue for the not suggestion rather reuse one that is about the error message, which frankly, your suggestion is totally orthogonal to
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
lvmbdv has quit [Ping timeout: 240 seconds]
lvmbdv has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<fullforce> trying to cast a Hash(String, String) to a Hash(String, String|Int32) overload
<fullforce> is this possible?
<FromGitter> <Blacksmoke16> so creating a method overload with that extra union, or convert an existing hash to make it compatible with that union?
<fullforce> creating a method overload with that extra unin
<fullforce> *union
<FromGitter> <kinxer> @fullforce Could you make an example on carc.in?
<fullforce> sure
<FromGitter> <Blacksmoke16> that would be best yea
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<fullforce> sorry for the delay blacksmoke and kinxer
<FromGitter> <kinxer> Unrelated to your actual question/problem: `EventHolster` is a very cool name for a class.
<fullforce> haha thank you
<FromGitter> <Blacksmoke16> https://carc.in/#/r/6hh8
<fullforce> ah I see npw
<fullforce> thanks blacksmoke
<fullforce> is there a way to move the cast to line 17?
<fullforce> might get a little messy once I start writing code with this
ternarysolo has quit [Ping timeout: 250 seconds]
<FromGitter> <Blacksmoke16> hm
<FromGitter> <kinxer> https://carc.in/#/r/6hhf
<FromGitter> <kinxer> Trading in messy for (probably) slow, but that's a solution.
<fullforce> hmm
<FromGitter> <Blacksmoke16> kinda annoying you have a type restriction for `Int32 | String` yet it isnt that
<fullforce> hmm
<fullforce> whoops hit enter again sorry
<fullforce> I want to be able to accept both int32 and string avlues
<fullforce> *values
ternarysolo has joined #crystal-lang
<FromGitter> <kinxer> @Blacksmoke16 Isn't there something different between method type restrictions and type checking elsewhere? I think I remember Asterite saying something about that in all the discussions about generics and type-checking.
<FromGitter> <Blacksmoke16> might be easier to use a struct?
<FromGitter> <Blacksmoke16> but depends on the full context of what hes trying to do
<FromGitter> <Blacksmoke16> i.e. dynamic keys
<FromGitter> <Blacksmoke16> where data is coming from et
<FromGitter> <kinxer> You can't have an arbitrarily large number of keys and values with a struct.
<fullforce> synamic keys yes
<fullforce> *dynamic
<FromGitter> <Blacksmoke16> in reality this is only going to be a problem when there is only a single type in your hash
<FromGitter> <Blacksmoke16> https://carc.in/#/r/6hhl
scott_tams has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<fullforce> intresting
<FromGitter> <kinxer> Also, if you didn't notice, you can replace ⏎ `@storage[event] = Array(HookFunc).new if !@storage.has_key?(event)` ⏎ with ⏎ `@storage[event] ||= Array(HookFunc).new` [https://gitter.im/crystal-lang/crystal?at=5c8967891fae6423ca7dbb25]
laaron has joined #crystal-lang
<fullforce> thanks again kinxer and blacksmoke
<FromGitter> <kinxer> Which is here (https://crystal-lang.org/reference/syntax_and_semantics/assignment.html) in the docs.
<FromGitter> <kinxer> No problem.
ternarysolo has quit [Ping timeout: 240 seconds]
laaron- has joined #crystal-lang
laaron has quit [Remote host closed the connection]
scott_tams has quit [Remote host closed the connection]
ternarysolo has joined #crystal-lang
oprypin has quit [Quit: No Ping reply in 180 seconds.]
faitswulff has quit [Remote host closed the connection]
<FromGitter> <bew> I'm wondering.... why does this work? (from your example @kinxer) Why the Hash passed the restriction against `EventHolster` ??
ternarysolo has quit [Ping timeout: 245 seconds]
faitswulff has joined #crystal-lang
faitswulff has quit [Remote host closed the connection]
<FromGitter> <kinxer> My guess is that there's a difference between the explicit check in the method definition and the check against `Proc(T*, R)#call(*args : *T)`.
faitswulff has joined #crystal-lang
<FromGitter> <kinxer> So the check in the generic method isn't as flexible as the check in the explicit method.
<FromGitter> <kinxer> But I don't have enough knowledge about Crystals guts to know why that would be.
<FromGitter> <bew> Basically the check in the method definition is a type restriction, but the problem I see is that the given args's type is `Hash(String, String)`, which shouldn't match the restriction with is `Hash(String, Int32 | String)` IMO.. (If we follow crystal's type system)
<FromGitter> <kinxer> Yeah, I definitely see the weirdness there. I didn't think generics were flexible enough to do that yet (but this didn't occur to me when I wrote the code that works...).
<FromGitter> <bew> ^^
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
faitswulff has quit [Ping timeout: 252 seconds]
gangstacat has quit [Ping timeout: 244 seconds]
faitswulff has joined #crystal-lang
return0e_ has quit [Ping timeout: 252 seconds]
return0e has joined #crystal-lang
gangstacat has joined #crystal-lang
DTZUZO has quit [Ping timeout: 255 seconds]
faitswulff has quit []
<FromGitter> <MineraftSteve> Hi, I have a problem with reading a file in crystal
<FromGitter> <MineraftSteve> I'm using the windows bash subsystem with debian, idk if thats the problem
<FromGitter> <MineraftSteve> but, I have a file with just 'puts File.read("a")'
<FromGitter> <MineraftSteve> and I compile it, and execute it, and while there is 100% a file named a in the same path, it prints this: "Unhandled exception: Error opening file 'a' with mode 'r': No such file or directory (Errno)"
<FromGitter> <bew> Try `File.exists? "a"` to see if it detects it
<FromGitter> <bew> also check `Dir.current` to make sure you're at the right place
<FromGitter> <MineraftSteve> what's even weirder, is that if I run "crystal eval 'puts File.read("a")'" it prints out the file contents
<FromGitter> <MineraftSteve> okay
<FromGitter> <MineraftSteve> hmm
<FromGitter> <MineraftSteve> the path I get is "/mnt/c/Users/(my user name)/Documents/project"
<FromGitter> <MineraftSteve> even though the executable is in "/mnt/c/Users/(my user name)/Documents/project/src"
<FromGitter> <MineraftSteve> if I run 'puts File.read("src/a")' it works
<FromGitter> <bew> how are you running it?
<FromGitter> <bew> (the executable)
<FromGitter> <MineraftSteve> how do I get it to read files at the executable's path?
<FromGitter> <MineraftSteve> ./src/out
<FromGitter> <bew> yeah that's why
<FromGitter> <MineraftSteve> ?
<FromGitter> <bew> basically your program runs where you are, it doesn't matter where the binary is really located
<FromGitter> <MineraftSteve> oh
<FromGitter> <MineraftSteve> lol okay
<FromGitter> <MineraftSteve> thanks
<FromGitter> <bew> think about `ls`, the binary is somewhere in `/usr/bin`
<FromGitter> <bew> but when you run `ls` you get the files in your current directory
<FromGitter> <bew> not the files in `/usr/bin/`
<FromGitter> <bew> you can do `which ls` to see where is `ls` if you want to check yourself
<FromGitter> <MineraftSteve> yeah, okay
<FromGitter> <MineraftSteve> that makes since lol
<FromGitter> <MineraftSteve> thanks for the hel
<FromGitter> <MineraftSteve> p
<FromGitter> <bew> ;)
moei has quit [Quit: Leaving...]
ternarysolo has joined #crystal-lang
ternarysolo has quit [Ping timeout: 246 seconds]
devil_tux has quit [Ping timeout: 245 seconds]
<FromGitter> <epoch> hello
<FromGitter> <bew> hi!
<FromGitter> <epoch> hi @bew
<FromGitter> <epoch> just notice enum doesn't implement enumerable
<FromGitter> <epoch> just wondering if you or anyone know the reason for that
<FromGitter> <bew> Well an enum in crystal is just a value, you can't iterate on it
<FromGitter> <Blacksmoke16> ^
<FromGitter> <Blacksmoke16> can call `#names` or `#values` and iterate over those
<FromGitter> <epoch> .each is implemented though
<FromGitter> <epoch> I mean the whole set
<FromGitter> <bew> oh on the enum type, not a specific instance.. We don't (can't ?) do that on types, only on instances for example for containers
<FromGitter> <bew> what are you trying to do with your enum?
<FromGitter> <epoch> I want to loop over that the set
<FromGitter> <epoch> I see .each is implemented, having map and reduce as well would be nice
<FromGitter> <bew> you can implement them yourself if you need them
<FromGitter> <bew> I could see a use for map, but reduce....
<FromGitter> <bew> AAAND as @Blacksmoke16 mentioned, you can do `YourEnum.values.map blablabla`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6hi2
<FromGitter> <epoch> oh thats everything I need
<FromGitter> <Blacksmoke16> you already ca n iterate over it?
<FromGitter> <epoch> YourEnum.values will be just fine
<FromGitter> <epoch> missed that
<FromGitter> <bew> I forgot about it too^^ ty black!