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
<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`
<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>
<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 :)
<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?
<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"`
<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
<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
<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>
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
<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.