ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.22.0 | Fund Crystal's development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<FromGitter> <ziprandom> @sdogruyol oh yes, my fault :)
onionhammer has joined #crystal-lang
onionhammer1 has quit [Ping timeout: 268 seconds]
hightower2 has quit [Ping timeout: 255 seconds]
<FromGitter> <samueleaton> if anyone could help me with DB mapping and Postgres' jsonb format I'd appreciate it. https://github.com/will/crystal-pg/issues/99
zipR4ND has quit [Ping timeout: 255 seconds]
_whitelogger has joined #crystal-lang
Kug3lis_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rohitpaulk has joined #crystal-lang
_whitelogger has joined #crystal-lang
ryanf has quit [Remote host closed the connection]
_whitelogger has joined #crystal-lang
<FromGitter> <bew> @samueleaton if you have an array of custom element in db mapping, you need to have a
<FromGitter> <bew> Db in the FightHistoryItem class
<FromGitter> <bew> @jwoertink you're on mac?
<FromGitter> <bew> And what is your hostname?
Guest28374 has quit [Quit: cya l8r alig8r]
hightower2 has joined #crystal-lang
olek_poz has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
rohitpaulk has quit [Ping timeout: 255 seconds]
rohitpaulk has joined #crystal-lang
tzekid has joined #crystal-lang
balduin has left #crystal-lang [#crystal-lang]
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
zipR4ND has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <bararchy> is it usually the case where return false wont fail a spec ?
olek_poz has quit [Ping timeout: 240 seconds]
hightower2 has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> Im always getting an error when im defining a instance variable or class variable
A124 has quit [Quit: '']
hello7871 has joined #crystal-lang
<hello7871> im always getting an error when im defining instance variables or class variables
<FromGitter> <straight-shoota> what does your code look like?
A124 has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <LuckyChicken91_twitter> this is my error:
<FromGitter> <LuckyChicken91_twitter> this is my error
<FromGitter> <LuckyChicken91_twitter> in crystalfile.cr:197: Can't infer the type of instance variable '@instanceVariable' of Myclass ⏎ ⏎ The type of a instance variable, if not declared explicitly with ⏎ `@instanceVariable : Type`, is inferred from assignments to it across ⏎ the whole program. ... [https://gitter.im/crystal-lang/crystal?at=59451e01f6a78eab4859812c]
<FromGitter> <LuckyChicken91_twitter> this is my error
Kug3lis has joined #crystal-lang
<hightower2> So why don't you add: @instanceVariable : YourType ?
<hightower2> Like, @instanceVariable : String
<hello7871> i have defined the instance variable so: @instanceVariable = myString
<hello7871> i dont understand why this is not working
<hightower2> What's myString? Maybe it's not initialized at the time of assignment
<hello7871> i have defined the variable so: myString = "this is my string"
<hightower2> Where did you define it? It may be that it is not visible when @instanceVariable = ... happens. Go with @instanceVariable = "test" and report your results.
<hello7871> i have defined @instanceVariable in a method
<hello7871> and myString too
<hello7871> in the same method
<hightower2> You need to do it at the top of class, like class Something \n @instanceVar : String
<hello7871> but then im getting undefined local variable or method 'myString'
<hello7871> because i first have defined the variable in the method
<hightower2> Yes, you can't do it like you want to
<hightower2> because it is not guaranteed that the method will be called, and so there is no guarantee that it will be a string before it is first used
<hightower2> So you must at least define the type at the top of class (you must do @instanceVar : String at the top)
<hightower2> And then you'll get a step closer
<hello7871> if im doing "myString = "hello \n @instanceVariable = myString" then its still giving me an error
<hello7871> in "initialize"
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<oprypin> hello7871, you must provide more details when you ask a question. otherwise people trying to help you (and also you) will feel frustrated.
<oprypin> in this case, and most cases, it's nice to give a full program that reproduces your problem (but try to keep the program minimal)
<hello7871> i have just defined a instance variable in an method
zipR4ND has quit [Ping timeout: 268 seconds]
<oprypin> ok, I suspect that the problem is caused by not initializing all instance variables in an `initialize` method
<hello7871> i have already tried imitate the program but its not working
<hello7871> but i have intialized the varibles in initalize
<hello7871> but its still not working
<oprypin> please post runnable code at https://carc.in/ or use https://bpaste.net/ as a general pastebin
<FromGitter> <fridgerator> try using `property var_name : String` in your class
<FromGitter> <LuckyChicken91_twitter> im getting "Syntax error in expanded macro: property:6: can't define def inside def"
<FromGitter> <fridgerator> sounds like you're already in a `def` block, trying to `def` again
<FromGitter> <LuckyChicken91_twitter> im doing this in the initalize class!
<FromGitter> <LuckyChicken91_twitter> im not trying to def again
<FromGitter> <fridgerator> can you show code?
<hello7871> i will try
<hightower2> What's the best approach if I want to ensure that classes which inherit from my class must provide their own implementation of a specific function?
<FromGitter> <fridgerator> @hightower2 use `abstract def`
<hightower2> oo, wonderful, thanks
rohitpaulk has joined #crystal-lang
<FromGitter> <fridgerator> I have a question, is this safe? https://carc.in/#/r/27a2
<FromGitter> <fridgerator> method that calls itself inside of a spawn, will the previous spawn call exit or is this going to stack up?
<FromGitter> <LuckyChicken91_twitter> this is code: ```require "colorize" ⏎ ⏎ class Theclass ⏎ def initalize ⏎ ... [https://gitter.im/crystal-lang/crystal?at=594536f16549436c7d5844b0]
<FromGitter> <felipeelias> @LuckyChicken91_twitter you have to add an enter before and after the ```
<FromGitter> <LuckyChicken91_twitter> not working
<hightower2> If I want my method to accept both an Array and a Tuple, is there some common type I can specify or I am best off saying arg : Array | Tuple ?
<hightower2> Also, how do I "alias" a method, if e.g. I want "x()" to be the same as "y()" without making any manual wrappers or copying the code?
<FromGitter> <LuckyChicken91_twitter> this is my code: https://carc.in/#/r/27aa/edit
<FromGitter> <LuckyChicken91_twitter> how can I fix this error?
<FromGitter> <fridgerator> @LuckyChicken91_twitter this works: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=594538f831f589c64fb7c589]
<FromGitter> <LuckyChicken91_twitter> i have posted a carc.in link now
<FromGitter> <LuckyChicken91_twitter> can someone pls help me with the error now?
<FromGitter> <fridgerator> @LuckyChicken91_twitter see my response
<FromGitter> <fridgerator> other than `initialize` was misspelled, I also used `property instanceVariable` in the class
<FromGitter> <fridgerator> @hightower2 you can use `alias` to alias types to create your own type: https://crystal-lang.org/docs/syntax_and_semantics/alias.html
<FromGitter> <fridgerator> or just use a union type for that variable
<FromGitter> <fridgerator> I don't think you can alias methods though, you'll just have to call one method from the other
<hightower2> Ok, thanks
<hightower2> Well, for method aliasing probably my best bet would be a macro
<FromGitter> <fridgerator> @LuckyChicken91_twitter also FYI, your variable names are not wrong, however crystal convention is to use underscore for variable names over camel case
<FromGitter> <LuckyChicken91_twitter> "cant define alias inside def"
<FromGitter> <fridgerator> right, `alias` has to be top level, inside a module or class
<FromGitter> <fridgerator> not inside def
<FromGitter> <LuckyChicken91_twitter> im getting still getting an error when im using property instanceVariable : Array(String) | Array(Colorize::Object(String))
<FromGitter> <LuckyChicken91_twitter> okay i have founded a way not to do it
hello7871 has quit [Ping timeout: 260 seconds]
<hightower2> Hey, my function receives a string in the form of "x:y". I want to find the char ':' in the string, and then initialize two slices or pointers that point to the first and second part respectively. Would someone more familiar with these data types show me how exactly I'd do it?
<crystal-gh> [crystal] mverzilli closed pull request #2913: Introduce Order as a return of `<=>` instead of Int32 (master...feature/order) https://git.io/vo9cK
rohitpaulk has quit [Ping timeout: 240 seconds]
<oprypin> hightower2, maybe you can use `Indexable`
<oprypin> (regarding array or tuple)
wdef has joined #crystal-lang
<oprypin> hightower2, `slice = s.to_slice; a = slice.to_unsafe; b = (slice + s.byte_index(':').not_nil! + 1)`
<oprypin> but keep in mind that the first of the pointers will not be null terminated in a way that you might expecct
<oprypin> hightower2, `a = s.to_unsafe; b = a + s.byte_index(':').not_nil! + 1`
<hightower2> mm, indeed
<oprypin> (much better and actually working code this time)
<oprypin> nope, needs to be ":" not ':'
<hightower2> I was hoping I could somehow specify the length, so that in the case of "ab:cd" I would create two pointers, one to "ab" and the other to "cd"
<crystal-gh> [crystal] mverzilli closed pull request #3504: added factorial function to int and float (master...factorial) https://git.io/vX86H
<oprypin> hightower2, well sure you can do that, but what would you be passing this to?
<oprypin> and what's the source of the string?
<hightower2> I have a function which is generally supposed to be called with an array or tuple, so I index elements with t[0] and t[1]. But I want to support a person passing in a custom type (based on String), which would support #[], but invoking #[0]/#[1] on it would return the part before and after the :, instead of chars like String does
<oprypin> maan
<hightower2> (E.g. if someone passed "test:test" instead of { "test", "test" }
<hightower2> I still want to just call arg[0] and arg[1]
<oprypin> why dont you make alternative method(s : String); method(s.split(":")); end
<hightower2> oh boy
<hightower2> of course
<oprypin> dangerous ruby mindset
<hightower2> thanks, I am still not used to overloading methods :)
<oprypin> and regarding "array or tuple" seems like u should use https://crystal-lang.org/api/0.22.0/Indexable.html as i mentioned
<wdef> omg this is so annoying!
<oprypin> touchè
<wdef> i want to make a normal array to an instance variable
<wdef> so that other methods can use this array
<wdef> how can I do this?
<oprypin> wdef, why dont you show what yout tried and we'll see what's wrong with it
<oprypin> generally `class C; def initialize; @arr = [1,2,3]; end; def zzz; use(@arr); end; end
<wdef> but i have defined the array in an method
<wdef> im creating the array in this method
<wdef> it must be possible to make an array from an method to an instance variable
<oprypin> sure, but you also need to consider what the value of that instance variable is before you've called that method that assigns it
<oprypin> it's easiest to just make sure it's something that makes sense right from the initialization time
<wdef> what should i do now
<oprypin> fully read https://crystal-lang.org/docs/ or post code that you expect to work but doesnt
<oprypin> again i assume dangerous ruby mindset that cannot be avoided by just trying stuff
<wdef> class Myclass ; def mymethod ; myarray = ["hello", "whatsup"] ; @instancevariable = myarray ; end ; end
<wdef> this is the code where i expect to work but doesnt
<oprypin> thanks. feel free to use carc.in - https://carc.in/#/r/27ak
<FromGitter> <sdogruyol> TechEmpower benchmarks preliminary results are out https://www.techempower.com/benchmarks/previews/round15/#section=data-r15&hw=ph&test=json&l=zb2by7
<FromGitter> <sdogruyol> Crystal is looking pretty good cc // @RX14
<wdef> this is the error which im getting
<RX14> yeah @sdogruyol
<oprypin> wdef, yes, i already posted a solution, check that out
<RX14> although kemal seems to be doing a lot worse which is weird
<wdef> and its annoying. I just want to define a instance variable in method
<oprypin> wdef, this is not how Crystal works, please don't assume that things work like in Ruby
<FromGitter> <sdogruyol> yeah that's weird
<FromGitter> <sdogruyol> i'm really surprised to see Kemal is that slow in json serialization
<FromGitter> <sdogruyol> need to recheck that
<RX14> wdef, in crystal the type of every instance variable needs to be known at compile time
<FromGitter> <sdogruyol> and plaintext also seems really slow
<RX14> and the type of instance variables is the same throughout the program's execution
<FromGitter> <sdogruyol> https://www.techempower.com/benchmarks/previews/round15/#section=data-r15&hw=ph&test=plaintext&l=zb2by7
<FromGitter> <sdogruyol> like 20x slower from crystal
<RX14> this means that the variable needs a type before you assign the array
<RX14> unless you define it in the constructor
<RX14> typically you'd use "nil"
<RX14> so assign nil in the constructor and then assign the array later
<Papierkorb> The compiler actually tells you pretty exactly the allowed ways to tell it what type the @var has
<RX14> you'll have to handle the variable being nil when you use it
<RX14> because it could happen that the variable is used before the instance variable is set
<wdef> ok this is finally working!
<wdef> but if im doing this now: https://carc.in/#/r/27as
<wdef> then im getting an error
<oprypin> wdef, yes, what if you hadn't called `mymethod`? that variable would've been nil, and the compiler detects that at compile time
<wdef> what do you mean
<oprypin> you can start thinking maybe you should assign that variable in `initialize` or you need to handle the nil case
<wdef> how can i fix this
<oprypin> i just said
<oprypin> there are your options
<wdef> where do i need to call mymethod?
<oprypin> ?
<FromGitter> <akzhan> Anyway all of framework results aren’t adjusted to production use.
<wdef> i need to define it in initilaize?
<oprypin> that would be the easiest, yes
<oprypin> i showed the alternative though
<wdef> but i want to define it in an method!
<wdef> because there im creating the array
<wdef> and its not really clean to do this in the initalize method!
<oprypin> ok so i showed you how to define it in the method. but i don't have the context on your use case so the thing ends up ugly
<RX14> crystal ensures type safety
<RX14> you have to make it safe
foca has quit [Ping timeout: 260 seconds]
<FromGitter> <fridgerator> @sdogruyol I see that crystal is using `reuse_port` in the server listen
<RX14> the way you want to do it isn't safe
<RX14> @fridgerator yes it uses reuse_port and launches an executable for each core
<FromGitter> <fridgerator> ah ok, kemal is also
z64 has quit [Ping timeout: 240 seconds]
<FromGitter> <fridgerator> @RX14 do you know if this is safe? https://carc.in/#/r/27a2
adam12 is now known as adam
<FromGitter> <fridgerator> method calling itself within a spawn, will the previous spawn exit?
<RX14> @fridgerator well your program will exit if you just run that lol
<RX14> but inside a larger program
<oprypin> seems ok though you're better off with a loop
adam is now known as Guest97411
<RX14> yes that's probably safe
<oprypin> and what rx14 said
<RX14> not sure why you'd want to though
<RX14> use a loop
<FromGitter> <fridgerator> kk
<FromGitter> <fridgerator> ty
<FromGitter> <fridgerator> setting up heartbeat for amber websockets
foca has joined #crystal-lang
snsei has quit [Remote host closed the connection]
z64 has joined #crystal-lang
<wdef> its not working!!!
<wdef> whhyyyy
olek_poz has joined #crystal-lang
<wdef> can someone please help me??
<Papierkorb> wdef: You're not providing any error messages (Complete, nothing paraphrased), nor any source code. Help us help you.
<oprypin> RTFM is honestly the best advice. I can't stand when people just write Ruby and expect Crystal to eat it up.
<FromGitter> <ultra2mh> guys hello . what is "to_h" mean in params.to_h ?????
<FromGitter> <sdogruyol> `to_h` = convert to hash
<FromGitter> <ultra2mh> thanks
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<hightower2> Hey, when I do something like: @x = {} of Something => SomethingElse , and Something/SomethingElse are unknown types, why does crystal complain about @x instead of about Something/SomethingElse being unknown classes?
rohitpaulk has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> oh my gawd my program is finally working!
<FromGitter> <straight-shoota> nice feeling ;)
rohitpaulk has quit [Ping timeout: 255 seconds]
rohitpaulk has joined #crystal-lang
saadq has joined #crystal-lang
wdef has quit [Ping timeout: 260 seconds]
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
<FromGitter> <samueleaton> @bew Adding the DB.mapping to the `FightHistoryItem` didn't help :(
<FromGitter> <sdogruyol> @LuckyChicken91_twitter congrats
hightower2 has quit [Ping timeout: 260 seconds]
olek_poz has quit [Ping timeout: 268 seconds]
Majost has quit [*.net *.split]
tilpner has quit [*.net *.split]
yopp has quit [*.net *.split]
t-richards has quit [*.net *.split]
mroth has quit [*.net *.split]
bjmllr has quit [*.net *.split]
bjmllr has joined #crystal-lang
t-richards has joined #crystal-lang
yopp has joined #crystal-lang
mroth has joined #crystal-lang
Majost has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> why does this not works? ```puts "\n Why does this not".colorize(:green) + " works?".colorize(:light_green)```
<FromGitter> <crisward> @sdogruyol looks like kemal's benchmarks are suffering when using JSON serialization is used. Can the source code be accessed for these tests?
<oprypin> LuckyChicken91_twitter, i dunno, just find some other way to output multiple things. use `print`
<oprypin> `print "\n Why does this".colorize(:green), " work?".colorize(:light_green), "\n"`
tilpner has joined #crystal-lang
hello55 has joined #crystal-lang
<havenwood> LuckyChicken91_twitter: Note you can #to_s them both then #+.
<FromGitter> <drujensen> Please fix kemalyst as well. ;-)
<hello55> how does can I call a method which is in a class which is in another class? class Class1 ; class Class2 ; def callmepls ; end ; end ; end
<havenwood> >> require "colorize"; "#{"This does".colorize(:green)}#{"work".colorize(:light_green)}"
<DeBot> havenwood: # => "\e[32mThis does\e[0m\e[92mwork\e[0m" - https://carc.in/#/r/27c0
<havenwood> >> require "colorize"; puts "#{"This does".colorize(:green)}#{"work".colorize(:light_green)}"
<DeBot> havenwood: This doeswork - more at https://carc.in/#/r/27c1
<havenwood> carc.in has just one green ;-)
<hello55> havenwood?
<hello55> do you know how this works?
<havenwood> hello55: Object#to_s(IO) is invoked on each Colorize::Object.
<hello55> what
<hello55> ??
<hello55> what does this have todo with my question?
<havenwood> hello55: Oh, I didn't read your initial question.
<hello55> how does can I call a method which is in a class which is in another class? class Class1 ; class Class2 ; def callmepls ; end ; end ; end
<hello55> this was my question
<havenwood> hello55: Class1::Class2.new.callmepls
<hello55> ooh
<hello55> thank you
rohitpaulk has quit [Ping timeout: 240 seconds]
qard has joined #crystal-lang
<qard> How does one do set-sized arrays for c bindings? like `type name[some_size]`
<qard> I can't find any examples of that in the docs.
hightower2 has joined #crystal-lang
<qard> Oh, actually I think I figured it out.
Kug3lis has joined #crystal-lang
<FromGitter> <akzhan> StaticArray.new(Type, size)?
<FromGitter> <LuckyChicken91_twitter> how can I interrupt a method directly?
<FromGitter> <straight-shoota> `return`
<FromGitter> <LuckyChicken91_twitter> ooh i forgetted ```return```
<hightower2> Hmm, I use @id= Atomic.new( UInt64.new 0) and get: can't use Atomic(T) as the type of instance variable @id of ..., use a more specific type
<hightower2> I'm not clear on why that happens since all my operations on @id involve UInt64
<FromGitter> <crisward> @sdogruyol thanks, will take a look...
<FromGitter> <straight-shoota> yeah, cause that google is gonna turn up anything related :clap:
<oprypin> hightower2, not sure why but u must specify the type like this https://carc.in/#/r/27ck
<FromGitter> <straight-shoota> Or declare a type restriction on the instance variable explicitly `@a : Atomic(UInt64)`
<oprypin> in other similar cases this works fine
<FromGitter> <straight-shoota> do you have an example?
<FromGitter> <LuckyChicken91_twitter> how can I convert to integer? .to_i isnt working
<FromGitter> <straight-shoota> lucky, what do you want to convert to integer and what das "isnt working" mean?
<oprypin> >> class A(T); def initialize(@a : T); end; end; A.new(5u64)
<DeBot> oprypin: # => #<A(UInt64):0x164dfe0 @a=5> - https://carc.in/#/r/27cl
<oprypin> there's the example
<FromGitter> <LuckyChicken91_twitter> i want to convert a gets input to integer
<oprypin> LuckyChicken91_twitter, use `gets.not_nil!.to_i`
<oprypin> check out the type that `gets` returns
<oprypin> >> typeof(gets)
<DeBot> oprypin: # => (String | Nil) - https://carc.in/#/r/27cm
<oprypin> nil is returned when the input stream ends without a value being received. you must account for that case
<FromGitter> <straight-shoota> oprypin, I guess the compiler just is not smart enough to figure this out for ivar types
<oprypin> what types?
<oprypin> >> struct A(T); def initialize(@a : T); end; end; A.new(5u64)
<DeBot> oprypin: # => A(UInt64)(@a=5) - https://carc.in/#/r/27cp
<oprypin> mm still works. i actually dont see a difference
<FromGitter> <straight-shoota> yes, but somehow he does not get it for type of instance variables
<oprypin> ohh thats
<oprypin> what I missed - sorry
<oprypin> i guess `GenericType.new` does not qualify for this because it's not an actual type
<FromGitter> <straight-shoota> yeah it's kind of indirect generic type resolution
<FromGitter> <straight-shoota> this should be doable for the compiler, though
<oprypin> straight-shoota, this inference used to be absolute, but it intentionally isn't
<oprypin> it is not wanted for accidental changes in code to invisibly affect the types of instance variables
<oprypin> though this particular case can be argued as harmless
<FromGitter> <straight-shoota> at least for such a case where the arguments of the generic class constructor are valid as imlicit type restriction themeselves
<oprypin> Crystal 0.15.0 is a name to remember https://carc.in/#/r/27d0
<oprypin> it's an entirely different beast
<qard> Is there some way for C bindings to do forward references for structs?
<oprypin> qard, I don't know such a term "forward references"
<qard> I have a struct that contains a callback which receives the struct itself, so I'm trying to define callback types before the struct, but that doesn't work due to the struct not existing yet.
<qard> "forward declaration" maybe? I've seen the two used somewhat interchangeably.
<oprypin> at the very least this seems to work https://carc.in/#/r/27d6
<oprypin> this as well https://carc.in/#/r/27d7
<oprypin> no problems at all, crystal doesnt care for the order of definitions
<qard> It does with the `type` keyword, but `alias` seems to work fine for my uses.
<qard> Now I just need to figure out how to handle empty structs...
<oprypin> qard, what, Void* ?
<qard> Maybe?
<qard> I have a header that names a struct in a header without describing the internals.
<qard> And functions that create and receive them.
<hightower2> oprypin, right, I had that and that didn't work. It started working when just 1 line above it I added @id : Atomic(UInt64)
<hightower2> not sure why...
<qard> More type-safety than just Void* would be good.
<oprypin> hightower2, please check crystal version in that example i sent
<oprypin> and discussion above
<oprypin> qard, it's such a typical and important case but it doesnt seem to be in the docs
<oprypin> these types must always be passed by pointer
<qard> Yep.
<oprypin> when you have `struct Blah; void asdf(Blah* z)` in crystal you do this: `type Blah = Void*; fun asdf(z : Blah)`
<qard> Ah, `type Foo = Void` is what I needed. :)
<qard> My thing compiles now. Yay!
<oprypin> it's preferred to go straight for `Void*
<oprypin> because without pointer it makes no sense at all and the fact it works is a miracle and im not even sure if it provides the type safety
<qard> Makes sense.
<qard> I just tried `type Foo = Void; fun create() : Foo*` rather than `type Foo = Void*; fun create() : Foo`.
<qard> The later is safer though?
<oprypin> qard, pretty sure technically it's the same but it just feels weird to rely on it
<qard> Personally I kind of prefer leaving the * out to make it clearer it is a pointer.
<qard> I'll be wrapping all this up in a more abstract interface anyway though. :)
<qard> What's the recommended way to copy an enum from a lib def to a module abstracting the lib?
<oprypin> qard, im afraid there is no good choice other than defining the enum outside of the lib in the first place
<qard> Ah.
<oprypin> you can write `alias SomeEnum = Lib::SomeEnum` but it doesnt properly display in documentation
<hightower2> Hey, I'm looking at Mutex class and I don't see a try_lock() or some form of lock that won't block. What's the catch?
<oprypin> hightower2, i dont get it, the whole point of mutex is to block
<hightower2> oprypin, yes, but I want to do a try_lock to just try to lock and exit immediately, not to block while it manages to acquire the lock. All these methods exist in Ruby's implementation of Mutex
<oprypin> ok, see i didnt have the context because i dont know ruby
<hightower2> try_lock → true or false. Attempts to obtain the lock and returns immediately. Returns true if the lock was granted.
<oprypin> hightower2, ok, this is a valid feature to have but it is indeed missing
<oprypin> i suspect that you can hack this functionality on top but it's messu
<oprypin> y
<oprypin> uhm, looking at it in more detail, no, it is not reasonably possible
<crystal-gh> [crystal] cjgajard opened pull request #4584: Implement no-copy subarray iteration (Implements #3386) (master...feature/nocopy_subarray_each) https://git.io/vHhok
<crystal-gh> [crystal] cjgajard closed pull request #3390: No-copy subarray iteration (Implements #3386) (master...feature/nocopy_each) https://git.io/vPWAd
<oprypin> ah right, the unblocking part. i thought it could be just an integer counter
_whitelogger has joined #crystal-lang
<FromGitter> <akzhan> I think that current complexity of mutex isn’t important, because Crystal will be thread-safe, with OS-mutex.
<FromGitter> <akzhan> and will import OS Mutex features too.
<RX14> why does a mutex have to be implemented by the OS?
<RX14> surely a context switch would ruin the performance
<FromGitter> <akzhan> May be I wrong. LLVM emvedded mutex based on pthread_mutex_t. But it’s just the implementation.
<FromGitter> <akzhan> and I am unsure that it is OS related. bt anyway it has pthread_mutex_trylock/
tzekid has quit [Remote host closed the connection]
hightower3 has joined #crystal-lang
hightower4 has quit [Ping timeout: 260 seconds]
hello55 has quit [Ping timeout: 260 seconds]
<qard> Is there a way to add methods to an enum?
<qard> class methods, I mean.
<oprypin> probably not but you can try some hacks
<oprypin> qard, if your real aim is to recreate some c++-like interface, there's probably a better alternative
<qard> I have an enum of possibly available backends for a thing and I want to function to check if the backend is available. Not sure the friendliest way to express that.
<oprypin> oh.. wait yeah that's a good use case and there totally is a way
<oprypin> i think you just write methods after listing the enum members
<qard> Seemed like Foo::Backends.available?(...) would be a clean API, but can't get it to work so fra.
<qard> far*
<qard> Perfect! Thanks!
<oprypin> but i missed your requirement of a class method
<oprypin> i think enums should never have a class method. that is NOT clean API
<qard> Why not?
<oprypin> qard, enum represents a choice among possibilities. the real action happens in users of the enum, they should have the methods
<qard> The problem though is that the "possibilities" vary depending on the build of the library this is for.
<qard> So I need a way to check which things are truly possible at runtime.
<oprypin> hmm I think I understand. maybe so.
<qard> So the enum is more expressing "this library is capable of supporting these" but not necessarily "your build DOES support these"
Philpax has joined #crystal-lang
<oprypin> good then. hopefully class methods work just as well as normal methods