<FromGitter>
<asterite> But then you have `elements = [1, 2, 3]; if elements.includes?(...)` which is grammatically wrong. I guess `include?` isn't that bad after all, or, well, depending on how you name your variable it will work or not. Actually... for String it's also `include?` in Ruby, and that's maybe why it's problematic. It should be `includes?` for String and `include?` for Array and collections in general
<FromGitter>
<fridgerator> how is `includes?` gramatically wrong for collections?
<FromGitter>
<Timbus> Yeah its not, he's just trying to stir the pot :P
<FromGitter>
<Timbus> But the sentence 'if elements include'
<FromGitter>
<Timbus> is better
<FromGitter>
<Timbus> "if my bag of apples includes a red one" hmmmm
<FromGitter>
<kolyaio> I currently reading the whole documentation as ebook that I published here earlier. I wonder how it could be more accessible to beginners. Also I think there are concepts that are based on Ruby but they werenβt explained properly as if it assumed people know Ruby πΆ β β I know Iβm weird but I didnβt like Ruby but I do love crystal π
<FromGitter>
<kaukas_gitlab> I am sorry for repeating my question: https://play.crystal-lang.org/#/r/4psw β Is there a way to achieve automatic type expansion (e.g. with `forall`) without writing a macro?
<FromGitter>
<bararchy> no shared cipher (OpenSSL::SSL::Error)
<FromGitter>
<bararchy> it's an OpenSSL error
<FromGitter>
<bararchy> the client and server does not share a cipher suite
<FromGitter>
<j8r> Does the goal of a programming language is to be grammatically correct in a spoken language? β Expressiveness in more important, please don't reproduce the English inconsistencies - Crystal isn't English, but a programming language as itself π
<FromGitter>
<kaukas_gitlab> I think there's a spectrum between expressiveness and confusion (think Perl vs Go). Ruby wants to make developers happy, and that is a good goal for Ruby. Having both `include?` and `includes?` to make the DSL read more natural in English certainly would make for less unhappy developers. Whether this goal applies to Crystal, I don't know.
<FromGitter>
<MrSorcus> > the client and server does not share a cipher suite β β But no any problems if i uses this certificate in nginx...
<FromGitter>
<j8r> I don't see the point of this `s` really. You are free to create how much aliases you want, but multiply them in the stdlib doens't add value
<FromGitter>
<j8r> I can write "bad english" and this will be valid crystal, but invalid english like `elements.includes` or `collection.include`
<FromGitter>
<j8r> For now I consider, `Object.includes`, rather than the underlying variable name. `Object` can be `Array`, `Hash` or whatever
<FromGitter>
<kaukas_gitlab> It's certainly about personal preferences. It annoys me a tiny bit every time I have to write `MyClass.include?(MyModule)`. It's 98% close to readable but not quite there yet. I would certainly enjoy having an option to use the form that makes most sense in the given situation. There are examples of such 100% fluid DSLs out there so I don't think they are totally useless. But it's a personal preference,
<FromGitter>
... of course.
<FromGitter>
<MrSorcus> @bararchy, no ideas why it's happens?
<FromGitter>
<bararchy> `New, (NONE), Cipher is (NONE)`
<FromGitter>
<bararchy> that's the issue
<FromGitter>
<bararchy> i'm not sure why it happenes, maybe you didn't configure an SSL Context?
<FromGitter>
<Timbus> I just find that 'includes' is right more often than 'include', and thus I (and my coworkers), are happy for it. β Also, you can add `include` all you want if you support my extension method proposal :p
alex`` has joined #crystal-lang
<FromGitter>
<Timbus> Hm that's an odd issue with forall btw @kaukas_gitlab . There's some cases where it works, and some where it doesn't
<FromGitter>
<Timbus> Also there's a Hash.zip() class method that you might find usefful
hightower4 has joined #crystal-lang
<FromGitter>
<kaukas_gitlab> @Timbus, I did not know about `Hash.zip`, thank you! In my case `Array` was just for simplicity, eventually I went with `Iterator`s.
<FromGitter>
<kaukas_gitlab> Although, when I think about it, `Hash.zip` *should* work with `Iterator`s, not `Array`s.
<FromGitter>
<Timbus> Yeaah probably.
<FromGitter>
<MrSorcus> > i'm not sure why it happenes, maybe you didn't configure an SSL Context? β β It's just example from Kemal documentation. http://kemalcr.com/guide/
moei has quit [Quit: Leaving...]
<FromGitter>
<Timbus> So `forall` works if you have an array that contains the entire superset of all the types you expect to pass.. Does that work for you? It's kind of a hack
<FromGitter>
<Timbus> Maybe it's something I can try to patch. Good motivation to better learn the compiler
<FromGitter>
<kaukas_gitlab> @bew, as I mentioned I ended up using Iterators https://github.com/kaukas/crystal-cassandra/blob/master/src/cassandra/dbapi/types/decoders.cr#L299 to avoid creating an intermediate array. The suggestion to unspecify the subtype is interesting though. Is there a way to do that and still win if: β β 1) I am using Iterators instead of Arrays and β 2) Sometimes there might be no items (how do I return
<FromGitter>
<kaukas_gitlab> @bew, that only works because your arrays have a single type. My arrays have multiple possible types: https://carc.in/#/r/4q11
<FromGitter>
<bew> @kaukas_gitlab you'll have to simplify your types somehow
<FromGitter>
<kaukas_gitlab> I'd be very happy to if anyone had any suggestions :-)
ashirase has quit [Ping timeout: 244 seconds]
ashirase has joined #crystal-lang
<FromGitter>
<sekkr1> Seems like this issue started in 0.20.5
<FromGitter>
<sekkr1> 1) 20.3 works as intended
<FromGitter>
<kaukas_gitlab> crystal-db allows me to specify the exact type it should return out of a query: https://crystal-lang.org/docs/database/#query, e.g. `Hash(String, Float64)`. I don't know of a way to make this work except to return a union of all possible types and allow the user to choose the one wanted.
<FromGitter>
<bew> who is the user?
<FromGitter>
<kaukas_gitlab> The developer calling crystal-db and my driver
<FromGitter>
<Timbus> @kaukas_gitlab have you tried printing the typeof(return_value) after running your macro
<FromGitter>
<Timbus> does it actually do what you expect
<FromGitter>
<bew> i guess the dev is supposed to use rs.read by itself, and specify the types he needs
<FromGitter>
<kaukas_gitlab> @Timbus the macro works, yes. It creates a cartesian product of all possible types. So then the runtime chooses the one that fits the given types at runtime.
<FromGitter>
<kaukas_gitlab> @Timbus my expectation was that `def to_hash(keys : Array(K), vals : Array(V)) : Hash(K, V) forall K, V` would actually do the same.
<FromGitter>
<bew> it doesn't choose anything at runtime
<FromGitter>
<bew> the methods are decided at compile time
<FromGitter>
<Timbus> Is that really any different than a cartesian product inside the collection though..
<FromGitter>
<kaukas_gitlab> Ok, so I guess it sees the `.as(Hash(..., ...))` and chooses the right method.
<FromGitter>
<kaukas_gitlab> @Timbus `Hash(String | Int32, String | Int32)` fails with `.as(Hash(String, Int32))` if that's what you mean.
<FromGitter>
<bew> by the way, what are you trying to do? (the more high level objective)
<FromGitter>
<Timbus> Guess that is what I meant
moei has joined #crystal-lang
<FromGitter>
<kaukas_gitlab> @bew I am trying to construct a hash of primitives, and return the exactly typed hash as a result of a Cassandra query. The exact type of a hash is chosen at runtime, e.g. for `map<int, string>` it should return `Hash(Int32, String)`.
<FromGitter>
<bew> i fear you can't do that, as the type must be known at compile time, and that `map<int, string>` is a runtime information only
<FromGitter>
<bew> and why do you want the same type?
<FromGitter>
<kaukas_gitlab> @bew because that's what crystal-db allows you to do, specify the exact type with `.as(exact-type)`.
<FromGitter>
<kaukas_gitlab> @bew I can do that, with the macro. Trouble is that macro bombs the compile times.
<FromGitter>
<kaukas_gitlab> I'd love it to work with `forall` to avoid the macro. And I had a secret hope that it would not stress the compiler as much.
<FromGitter>
<bew> no time to dig into that rightnow, sry
<FromGitter>
<kaukas_gitlab> @bew, no problem! That's for the participation :-)
<FromGitter>
<Timbus> I can't see how forall can do what you want, unfortunately. It doesn't loop 'for all' of the types to a single method call. `some_forall_method(1||'b'||"c")` will instantiate a method that takes Int32|Char|String . The more I think about this the more confused I get. β Maybe asking for the shape of the data upfront can get you where you want? Like a `mappable`
<FromGitter>
<Timbus> At this point I can only say it feels like.. Relying on the user to cast the type *after* you fetched it is the main issue? A mapping (or something similar) means you can compose the data into the type the user provided. β Will it help? I dunno. I haven't tried to design a library like yours unfortunately.
<FromGitter>
<kaukas_gitlab> @Timbus, yeah, it seems like crystal-db wants me to provide all possible combinations of types upfront, and then the user chooses afterwards.
<FromGitter>
<Timbus> But on the other hand, JSON wants the opposite (so it can avoid wrapping all types with JSON::Any)
<FromGitter>
<Timbus> Oh, right you have to conform to the crystal-db interface yeah
<FromGitter>
<kaukas_gitlab> I am sorry, I don't know enough about JSON yet. I am rather new to Crystal, this is my first bigger toe dip. I do know that somehow JSON::Any is going to be relevant because recursive aliases have been removed, and JSON uses structs while crystal-db still uses aliases (https://github.com/crystal-lang/crystal-db/blob/28b17b7dba820d7e4810493aaf0a99e368849ec6/src/db.cr#L76) which prevents me from
<FromGitter>
<Timbus> You know, @anykeyh might have the knowledge to guide you, if you ping him (and if he's willing). He's very familiar with all of these concepts.
<FromGitter>
<kaukas_gitlab> @Timbus was that enough of a ping already? :-P Or should I ask some other way?
<FromGitter>
<Timbus> Mebbe, otherwise drop him a privmsg I guess? Might be a busy guy
<FromGitter>
<kaukas_gitlab> @Timbus, thank you for all the help! I might try the #crystal-db channel first.
<FromGitter>
<Timbus> Seems fair. Although I don't really know that I helped =<
<FromGitter>
<kaukas_gitlab> @Timbus, at least you confirmed my current understanding, and I am very grateful for it.
Jenz has joined #crystal-lang
<Jenz>
Ah, lots of stuff has happened in the crystal world
<FromGitter>
<Timbus> Isn't that usually the error you get when the cipher isn't setup/selected properly or what have you. I recall a similar error someone else had
<FromGitter>
<Timbus> What if you do this before starting the server: `tls.ciphers = "HIGH+kEECDH+AESGCM:HIGH+kEECDH:HIGH+kEDH:HIGH:!aNULL"`
Jenz has quit [Quit: leaving]
alex`` has joined #crystal-lang
DTZUZO has joined #crystal-lang
kmctown has joined #crystal-lang
alex`` has quit [Ping timeout: 240 seconds]
francisl has joined #crystal-lang
alex`` has joined #crystal-lang
alex`` has quit [Client Quit]
alex`` has joined #crystal-lang
kmctown has quit [Quit: My MacBook has gone to sleep. ZZZzzzβ¦]
francisl has quit [Ping timeout: 260 seconds]
francisl has joined #crystal-lang
akaiiro has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
kmctown has joined #crystal-lang
marius has quit [Quit: baj]
marius has joined #crystal-lang
thews has quit [Ping timeout: 256 seconds]
akaiiro has joined #crystal-lang
kmctown has quit [Quit: My MacBook has gone to sleep. ZZZzzzβ¦]
kmctown has joined #crystal-lang
<FromGitter>
<MrSorcus> > What if you do this before starting the server: `tls.ciphers = "HIGH+kEECDH+AESGCM:HIGH+kEECDH:HIGH+kEDH:HIGH:!aNULL"` β β Nothing changed.
<z64>
in example, sure. i imagine in actual application code you would be doing more with T than just checking if it is of Array. (you can just do `def foo(arg : Array); true` and `def foo(arg); false` if you really just want that)
<Jenz>
(Just ignore the random lines of code I posted here)
<Jenz>
I know StaticArray uses this (e.g. `StaticArray(String?, 16).new`), but when it works with integers, why shouldn't it with other types as well?
<Jenz>
Oh, it works with floats as well apparentely, I'll change it to: why won't it work with non-numerals as well?
<z64>
no idea ;( it was my understanding that NamedTuple and StaticArray had special generic notation, unlike other types.
* Jenz
Β―\_(γ)_/Β―
<Jenz>
Oh wow, I never realized NamedTuples syntax was like that, yet, I've used it many times...
<Jenz>
I mean, I never realized it was special
<FromGitter>
<rishavs> How do I get a db query as a specific class? For example, I want to do something like this; β ` postObj = Cove::DB.query_one? "select unqid, title, content, link, author_id, author_nick from posts where unqid = $1", postid, β β ``` as: Cove::Models::User```` β ... [https://gitter.im/crystal-lang/crystal?at=5b71a1c9937eee242310a93f]
kmctown has quit [Quit: My MacBook has gone to sleep. ZZZzzzβ¦]
<FromGitter>
<rishavs> Thanks Jenz. Thats exactly what I was looking for
* Jenz
:)
<Jenz>
I guess, even *my* feeble knowledge can help at times XD
kmctown has joined #crystal-lang
<Jenz>
z64: On second thought, NamedTuple *is* a primitive, but StaticArray is not, so NamedTuple having special syntax... wouldn't really be special, would it?
* Jenz
XD
<z64>
well, sure lol.
Raimondii has joined #crystal-lang
<FromGitter>
<bew> StaticArray is also a special type
<Jenz>
No way?
<Jenz>
How so?
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<Jenz>
s/way?/way/
<Jenz>
now im super intrigued
<Jenz>
Oh, I probably use that word wrongg
<Jenz>
(last one)
<FromGitter>
<bew> ^^ checkout the code in `src/static_array.cr` look for the new & initialize methods, you'll see for example that the ivar `@buffer` is never manually initialized, and that the `new` method is implemented using a StaticArray (good luck doing that if it's not special)
<FromGitter>
<bew> It's special because there no public way to allocate a fixed size buffer on the stack, this is done by the compiler when needed when you use a StaticArray
<Jenz>
It wouldn't be possible using LibC?
<FromGitter>
<bew> No
* Jenz
O_o
<Jenz>
Ok thanks a ton
<FromGitter>
<bew> It's not what LibC is for
<Jenz>
Im very very far from being a low level expert
<Jenz>
Gtg
<Jenz>
Thanks all
Jenz has quit [Quit: leaving]
return0e_ has quit [Quit: Leaving...]
return0e has joined #crystal-lang
<FromGitter>
<Michionlion> Is there any way to access the value of a generic in a macro?
<z64>
@Michionlion do you mean something like https://carc.in/#/r/4q6m ? or could you provide a (failing) example of what you're trying to do exactly?
<FromGitter>
<Michionlion> Something like
<FromGitter>
<Michionlion> `GenericClass(T + N)` where N is the generic of another class
<FromGitter>
<bcardiff> @Michionlion for me it's not clear what you expect from `T + N`. Can you show slightly bigger example of what you are trying to solve?
<FromGitter>
<Michionlion> essentially constructing the generics of another class based on the generics of the first
<FromGitter>
<Michionlion> there's a work around in hardcoding all possible `Matrix(N,M)` types with concrete numbers, but then compile time goes through the roof because code is generated for generic versions that aren't used
<FromGitter>
<Michionlion> Generics are CONSTs, and so are known at compile time
<FromGitter>
<Michionlion> but you can't specify a compile-time CONST as a generic
<FromGitter>
<Michionlion> or rather I guess the result of a computation at compile time, in a macro
<FromGitter>
<Michionlion> The use case here is a linear algebra math library where vectors and matrices are structs and have their dimensions encoded with generics so that `StaticArray` can be used to put the values on the stack
<FromGitter>
<Michionlion> since you need a literal or generic to pass to `StaticArray` as the size
<FromGitter>
<bcardiff> @Michionlion The methods will still be generated per each combination in LLVM if you get to use macro to do the math between generic types.
<FromGitter>
<Michionlion> was that added recently? Because I was unable to replicate things like that when I was working on this a few weeks ago
<FromGitter>
<Michionlion> maybe this is just a failing of putting both macros and forall together
<FromGitter>
<bew> not really new, no
<FromGitter>
<bcardiff> when using `{{ }}` inside a method you will need a `{% begin %} / {% end %}` to parse the content as macro. maybe you was missing that in your privious experiments
<FromGitter>
<Michionlion> that was probably it
<FromGitter>
<Michionlion> wow that was a lot of work potentially wasted on my part
akaiiro has quit [Remote host closed the connection]
<FromGitter>
<rishavs> ok, this is weird. Any where in my code i can use my DB constant as a namespaced constant `Cove::DB` and it works. but mapping will only work with a `DB` constant. Wonder if the macro is expecting a hardcoded constant name
<FromGitter>
<bcardiff> Probably the top level `::DB` of crystal-db is hidden by the local `Cove::DB`. Probably some `::` needs to be added
hightower4 has joined #crystal-lang
<hightower4>
Hey, if I have an array like [ "one", "two", "three" ], how do I convert it to a Hash with contents { "one" => 1, "two" => 1, "three" => 1 }
<hightower4>
I'm having a hard time doing it with map{} since saying map{ |x| { x => 1 }} gives me an array of hashes, not hash with those keys
<FromGitter>
<Michionlion> `Array#index_by` does the opposite of what you're thinking of, but it doesn't look like there is anything that does that out of the box
<FromGitter>
<Michionlion> the easiest way is probably just to create a hash and iterate over the array, adding things to the hash
<hightower4>
ok done so thanks
<FromGitter>
<rishavs> > Probably the top level `::DB` of crystal-db is hidden by the local `Cove::DB`. Probably some `::` needs to be added
<FromGitter>
<rishavs> thanks. will check for that
<FromGitter>
<Michionlion> hmm... `NumberLiteral` should probably define `#resolve` and return itself
<oprypin>
prob
<oprypin>
hightower4, `%w[one two three].each_with_object(1).to_h`
<hightower4>
oprypin, nice one as always thanks!
<FromGitter>
<Michionlion> that's a better version :)
<FromGitter>
<Michionlion> One more question for you crystal experts: is there a way to set a constant at compile-time from the command line? something like -Dvalue=5?
<hightower4>
If I want to save/load logger severity from YAML file, is there a better way than saving severity as a string, then doing "case severity; when "debug": Logger::Severity::DEBUG" and so on for all 6 levels?
<z64>
@hightower4 Severity is an enum, so `Logger::Severity.parse("debug") #=> Logger::Severity::DEBUG". it will raise ArgumentError if it fails to find a match
<FromGitter>
<bew> You can do `Logger::Severity.parse?(severity)`
<FromGitter>
<MisterBianco> What's the best place to ask a crystal question? Is it here or in an issue on GitHub?
<oprypin>
well definitely not issue
<FromGitter>
<MisterBianco> I am looking at getting the ascii table hex code of a char... I found the ord modifier for a char but I can't seem to find a viable way to convert to the hex code on the table like 'a' #=> 61 & 'A' #=> 41
<FromGitter>
<Prutheus> Hello. Someone using crecto? How can I set up an id field with auto increment? I have in my databse table the id field set as primary key with AUTO_INCREMENT and I do not set it at my model class in any way, i just have a `field data, String` line in my `schema` .... how ti properly use autoincrement id, because like I have setup everything the id is always NULL, i think this comes from crecto which tries to
<FromGitter>
<Prutheus> does not work, is still null
<FromGitter>
<Prutheus> oh no sorry
<FromGitter>
<Prutheus> works
<FromGitter>
<Prutheus> thanks!
alex`` has quit [Ping timeout: 240 seconds]
akaiiro has quit [Ping timeout: 248 seconds]
Raimondi has joined #crystal-lang
thews has joined #crystal-lang
francisl has quit [Quit: francisl]
ashirase has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
<RX14>
does anyone know of any tools to debug memory leaks in crystal?
<RX14>
or do I have to figure out my own
<FromGitter>
<fridgerator> I think @sdogruyol has used Instruments (on mac) before
<FromGitter>
<fridgerator> so.... buy a mac? lol
<RX14>
how can instruments debug memory leaks? that doesn't make sense
<RX14>
unless it has special bdwgc integration which I doubt
<RX14>
and even then how would it know the type of the objects?
<RX14>
sorry that doesn't add up
<FromGitter>
<fridgerator> maybe it was just general profiling
<RX14>
yes, it can do profiling
<RX14>
memory leak detection is an entirely different beast
<RX14>
you can do that on linux with perf/callgrind
<RX14>
as in you can do profiling with perf/callgrind
<RX14>
memory leak detection has to be crystal-specific
hightower4 has quit [Ping timeout: 272 seconds]
<FromGitter>
<jwoertink> I've never done any memory leak detection, but maybe https://github.com/KDE/heaptrack could work with some sort of integration?
<FromGitter>
<bcardiff> @RX14, I've only used valgrind in linux (but with C++). http://valgrind.org/ . Probably you already know about it. I am not sure if it would work from a llvm generated binary directly.
<RX14>
but valgrind isn't a leak debugger
<RX14>
to debug a memory leak you really need to know what objects are on the heap and where they come from
<RX14>
no non-crystal-specific tool will be able to know what crystal type an allocation is
<RX14>
even then surely all your tool would tell you was that all the memory was allocated by __crystal_malloc
<RX14>
which is helpfulβ’
<FromGitter>
<jwoertink> ^ that sounds like the perfect use case for something to be built and added to stdlib. I mean, realistically it's probably super difficult, and how would you know you're leaking memory if the thing that's leaking memory is the thing built with the thing that's leaking memory π
<FromGitter>
<jwoertink> but that would be pretty badass to say crystal had a built-in debugger thing of some sort.
<RX14>
i've been thinking how to do that
<RX14>
but
<RX14>
there's no way to iterate GC allocated objects
<RX14>
and I really don't want to register a finalizer on *all* objects
<RX14>
I must conclude that crystal will have no way to debug memory leaks until we get a custom GC