RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.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
a_b_m has joined #crystal-lang
abm has quit [Ping timeout: 240 seconds]
ashirase has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
vikaton has quit [Quit: Connection closed for inactivity]
DTZUZO has quit [Ping timeout: 240 seconds]
a_b_m has quit [Ping timeout: 256 seconds]
ashirase has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ashirase has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
Creatornator has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<FromGitter> <drinkmorewaters> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b6a6860359c70045ca0edc5]
<FromGitter> <drinkmorewaters> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b6a687be8698a2dca2149e3]
<FromGitter> <drinkmorewaters> First is Crystal and second is Ruby. Is that the correct way to add to an array and to print out an array?
<FromGitter> <drinkmorewaters> ```code paste, see link``` ⏎ ⏎ I find it so interesting that i can look at Ruby files and somewhat hack together something that works now, in less than 2 weeks. ⏎ ⏎ Also gotta say, the more time i spend learning things the more awesome Crystal has been, tried Julia and it wasn't as easy as Crystal to get setup. Neither was Ruby or Python. But Crystal has been so simple to setup, compile,
<FromGitter> <drinkmorewaters> Crystal*
moei has quit [Quit: Leaving...]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
Creatornator has quit [Client Quit]
<FromGitter> <bew> @drinkmorewaters `else cart != 0` here is useless, it's the same as `else; cart != 0`, if you want to use a condition here, you have to do `elsif cart != 0`
<FromGitter> <bew> And in this case, the second condition is superfluous here, the only case where `cart` is not `== 0` is when its `!= 0` so only `else` is enough here.
<FromGitter> <OSN64> Is anyone here familiar with the web3 ethereum module for crystal?
<FromGitter> <OSN64> I'm having an issue returning back the result after a json rpc request.
<FromGitter> <OSN64> I have posted an issue on the repo here, https://github.com/light-side-software/web3.cr/issues/2.
hightower4 has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
moei has joined #crystal-lang
DTZUZO has joined #crystal-lang
beizhia has joined #crystal-lang
<beizhia> Just noticed this, and kinda curious if there's a reason for it, but methods like Enumerable#includes? take any type as an arg. Seems to me like they should only allow the same type that the enumerable is generic to?
<beizhia> Seems like this https://play.crystal-lang.org/#/r/4otg shouldn't compile, rather than just returning false
<FromGitter> <bew> Yeah I don't like this behavior too (and some others like this one), but there are some cases where its necessary iirc
<beizhia> Seems like an easy pitfall to me :-\ It would be nice if there was an #includes_object? method or something like that, and then #includes? just worked on the same type.
<beizhia> Ya, I can see the case though, when you've got some objects of a common superclass or something in an array.
<beizhia> And, well, someone pointed out that apparently Java lets you do the same thing. Guess I just have to be more careful, heh
<FromGitter> <drinkmorewaters> Is there a place i can find all methods included in the standard library? I can't find .between? @bew Thanks for that!
<FromGitter> <drinkmorewaters> I have looked here https://crystal-lang.org/api/0.25.1/Spec/Methods.html
ua has quit [Ping timeout: 256 seconds]
ua has joined #crystal-lang
alex`` has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.2]
alex`` has joined #crystal-lang
alex`` has quit [Client Quit]
alex`` has joined #crystal-lang
beizhia has quit [Ping timeout: 256 seconds]
abm has joined #crystal-lang
ashirase has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
<FromGitter> <kolyaio> Hey, ⏎ I don’t get what is the purpose of Symbols in crystal, can somebody explain it? ⏎ I read this: https://crystal-lang.org/docs/syntax_and_semantics/literals/symbol.html ⏎ But it doesn’t explain what is the purpose of this feature :-/ [https://gitter.im/crystal-lang/crystal?at=5b6ab851e9ab53770ca5b53c]
<FromGitter> <vegai> they are a ruby feature, which in turn took it from Smalltalk. And I think Lisps have’em too
<FromGitter> <vegai> I found this explanation http://kresimirbojcic.com/2011/11/24/symbols-in-ruby.html
<FromGitter> <vegai> I suppose they could be replaced with just strings without losing too much
<FromGitter> <vegai> in fact, I found a recentish PR from asterite where he suggests just that https://github.com/crystal-lang/crystal/pull/6074
<RX14> between strings and enums they can be replaced
<RX14> I might submit an RFC for doing just that
<FromGitter> <vegai> symbols in Lisp were mostly an optimization, I think? Hashing them could happen at compile-time automatically
<FromGitter> <vegai> Crystal doesn’t do such optimizations, does it?
<FromGitter> <bararchy> They were used in Ruby for performence and visability, keeping a key unique
<FromGitter> <kolyaio> Sorry but I still don’t understand what they are ? Why and When I Should use thjem ?
<FromGitter> <bararchy> they are a "string looking" but an actual Int behind the scene
<FromGitter> <bararchy> so ⏎ ⏎ ```{"bar" => "test"}``` [https://gitter.im/crystal-lang/crystal?at=5b6abc783bca002dcbda4139]
<FromGitter> <j8r> Their primary use is on the compiler. Very often you don't have to use it
<FromGitter> <j8r> And should not when you can use a string
<FromGitter> <kolyaio> So it’s a string but I won’t need to use it often ?
<FromGitter> <j8r> The difference is they are interpreted at compile time, not dynamic at runtime like strings. If you don't have to use them, don't :)
<FromGitter> <j8r> there was some discussion if we could remove it, and what can be the alternatives. Nothing is planned at medium term
<jokke> quick question: if i have tons and tons of macro generated methods that i never use, that won't slow down compilation, right?
<FromGitter> <j8r> IIRC there are symbols under named arguments and named tuple
<jokke> (except if generating them takes time of course)
<jokke> i'm just wondering because i plan on making a pull request for `ArrayLiteral#combinations` (as well as for `TupleLiteral`). This could be used for creating type safe mass assignment methods.
<jokke> but the amount of combinations for larger arrays will be huge even though maybe only a fraction of those methods are actually used
<FromGitter> <vegai> making compilation slower sounds bad, since it’s rather slow already in a lot of places :-/
<FromGitter> <j8r> yes jokker, they won't be called
<FromGitter> <j8r> e.g. ⏎ ⏎ ```macro gen ⏎ gen ⏎ end ⏎ # gen``` [https://gitter.im/crystal-lang/crystal?at=5b6ac015cf8ab4758abb5336]
<FromGitter> <j8r> if uncommented, this will segfault. Else, nothing will happen
<jokke> vegai: it does have the potential of creating many gigabyes worth of code depending on how you use it ^^
<jokke> can someone explain this to me? https://carc.in/#/r/4ovn
<jokke> it doesn't matter if i put the include before or after the getter
<jokke> i mean.. doesn't JSON::Serializer do exactly this
<jokke> access instance vars of the including class
<FromGitter> <vegai> I don’t get it, what’s weird there?
<jokke> well instance vars is empty
<jokke> it should contain foobar
<jokke> it probably has something to do with the order the macros are executed
<FromGitter> <vegai> ah, right. I guess the macro expansion happens too early?
<jokke> since getter is also a macro
<FromGitter> <vegai> yea
<jokke> but i haven't found any way around it yet...
<FromGitter> <vegai> crystal macros are so damned pretty, I gotta say
<jokke> yeah
<jokke> but they can become very ugly too :D
<FromGitter> <vegai> in pretty much every other language where I’ve seen them, I have to meditate 15 minutes before trying to figure them out
<FromGitter> <vegai> I suppose the flipside is less power
<jokke> crystal macros are _super_ powerful
<FromGitter> <vegai> are they?
<jokke> yes
<FromGitter> <vegai> I guess there’s no flipside then :)
<jokke> here's a more complex example (not working because of the instance vars issue)
<FromGitter> <vegai> well, even in that case I immediately feel like I can understand that code without the meditation :)
<jokke> also the combinations method is something i patched into my crystal compiler
<FromGitter> <vegai> not immediately obviously, but that it’s theoretically possible to understand it
<jokke> yeah
<jokke> it's prettry readable, that's true
<FromGitter> <vegai> as a counter-example, https://danielkeep.github.io/quick-intro-to-macros.html#indexing-and-shuffling (look for “recurrence”)
<FromGitter> <vegai> and that’s not a complicated macro in any way
<FromGitter> <vegai> but just the effort of reading the declaration is too much for my adhd brain
<jokke> oh wow
<jokke> but rust is also great :) it's on my bucket list
<FromGitter> <vegai> many parts of it are great, yes, but I don’t enjoy its macros at all
<jokke> mmh
<jokke> RX14: can i bother you for some hints regarding the ivars?
<jokke> RX14: afair you had pretty deep understanding of the macro system
<FromGitter> <j8r> joke: https://carc.in/#/r/4owi
<jokke> yeah that's not the issue
<jokke> i need reflection
<jokke> what ivars are there
a_b_m has joined #crystal-lang
abm has quit [Ping timeout: 256 seconds]
<z64> jokke: this is what JSON::Serializable does: https://carc.in/#/r/4owq
<jokke> mh i see inside a macro generated instance method
<jokke> too bad i can't access them outside of a instance method
<z64> yeah. i forget the particulars as to why that doesn't work
a__b__m has joined #crystal-lang
<FromGitter> <j8r> but that's logic
flaviodesousa has joined #crystal-lang
a_b_m has quit [Ping timeout: 248 seconds]
<jokke> z64: do you know how i can find out if the type part of a TypeDeclaration is nilable or not?
<z64> not sure, i'll try real quick
<z64> jokke: {{dec.type.types.any? { |t| t.resolve == Nil }}}
<jokke> ah
<jokke> type.types.. sure :D
<z64> dec.type => Union (you will have to check for this), Union#types => ArrayLiteral(Path), Path#resolve & compare to Nil
<jokke> mhm
<jokke> are you sure that works?
<z64> yes
<jokke> because dec.type gives only an AstNode according to docs
<jokke> *ASTNode
<z64> Path, ArrayLiteral, etc *are* ASTNode
<jokke> sure
<FromGitter> <asterite> jokke at the top level instance variable information isn't available. Only inside methods. It's a known limitation (at least to me and a few others), and there's no easy way to improve that
<z64> jokke: https://carc.in/#/r/4oxp etc
<jokke> thanks!
ashirase has quit [Ping timeout: 244 seconds]
ashirase has joined #crystal-lang
jeromegn has joined #crystal-lang
snapcase has joined #crystal-lang
DTZUZO has quit [Quit: WeeChat 2.0]
DTZUZO has joined #crystal-lang
<jokke> hmmm
<jokke> any idea what's wrong here? https://p.jokke.space/e3V3gd/
<jokke> why does it show only one overload?
alex`` has quit [Ping timeout: 248 seconds]
<z64> you're overriding, not overloading
<jokke> but why?
<jokke> it's a different method signature
<jokke> doesn't crystal distinguish between generics?
<lvmbdv> oh no
<z64> specifically not with a NT it seems
<jokke> wtf :(
<jokke> that's a problem
<jokke> asterite: is this a known limitation/issue?
<FromGitter> <straight-shoota> it seems to be an issue with NamedTuple
<FromGitter> <straight-shoota> using a different generic type works: https://carc.in/#/r/4oyh
<FromGitter> <straight-shoota> I guess there are just some specific generic type features not properly implemented for NamedTuple and also StaticArray which are have unique generic features
<FromGitter> <Flink> Hey everyone :) Is there a way to list the available macros for a class from a macro? Or that a specific macro is defined in a class? I can’t find anything and it’s starting to drive me crazy 😅
alex`` has joined #crystal-lang
<FromGitter> <straight-shoota> @Flink I don't think so
<FromGitter> <straight-shoota> Why would you need thatß
<FromGitter> <straight-shoota> ?
<FromGitter> <Flink> I’m currently trying to test that when I require a file of a small library I’m writing, it’s not mixin automatically a module inside classes. Because if I require my lib by default its module is included in `Object` but otherwise with the other require you can do the include yourself only where you want.
<FromGitter> <Flink> But everything I’m including are macro defs
<FromGitter> <Flink> so I’d like to find a way of checking that when I require this particular file, I don’t have any macros defined in a test class and when I include the proper thing then only I have access from this class to these macros
<FromGitter> <Flink> but I can’t try to call a non existent method/macro either as it will throw a compilation error
<FromGitter> <Flink> and I can’t rescue it
<FromGitter> <Flink> I’m a rubyist by the way so all this macro thing is kind of very strange to me (trying to understand how it’s working though)
akaiiro has joined #crystal-lang
<FromGitter> <Flink> if there is an idiomatic way of doing what I want, just tell me I’ll be happy to apply it 😅
<livcd> asterite: can I ask something ?/q ?
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
olbat__ is now known as olbat
<FromGitter> <vegai> jokke: what are you building there?
<jokke> vegai just a convenience lib for type safe mass assigning
<jokke> but it doesn't seem to be possible anyhow
<FromGitter> <noahlh> good morning everyone! quick question: Is there a way to check how many arguments a method requires before calling it? I want (or I think I want) to do something like "if this method takes 3 arguments, call with 3, otherwise call with 2". I might be thinking about this the wrong way.
abm has joined #crystal-lang
<FromGitter> <j8r> hum nope, this would make sense in a dynamic language but here all arguments and how many of them are known at compile time
<FromGitter> <j8r> you can create 2 overloads, one with 3 args and one with 2
a__b__m has quit [Ping timeout: 256 seconds]
<FromGitter> <j8r> You can use scry (an IDE plugin) to know in you IDE how many args and what args provides a method
<FromGitter> <j8r> or just call the method and read the error 😄
<FromGitter> <noahlh> yup that's what I figured - gotta stop thinking in terms of dynamic language (old ruby habits die hard). Thanks @j8r !
wontruefree has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
a_b_m has joined #crystal-lang
a__b__m has joined #crystal-lang
abm has quit [Ping timeout: 248 seconds]
DTZUZO has quit [Quit: WeeChat 2.0]
DTZUZO has joined #crystal-lang
a_b_m has quit [Ping timeout: 244 seconds]
<FromGitter> <Svenskunganka> The `String#to_slice` (https://crystal-lang.org/api/0.25.1/String.html#to_slice%3ABytes-instance-method) documentation says "Returns the underlying bytes of this String in an *unsafe* way.". Why is that? I though a `Slice` were a safe alternative to pointers.
nathanj has joined #crystal-lang
<FromGitter> <Svenskunganka> Or is the unsafe part of the description only there to explain why the Slice returned is read-only? (I only need a read-only Slice so that's fine)
<FromGitter> <Flink> Ok so I guess there’s no proper way in Crystal to actually check a module is not polluting other classes when using macros, that’s too bad 😐 Should I report that as a bug?
<FromGitter> <asterite> I'm not sure what bug you are talking about, but without code it's very hard to understand what you mean
<FromGitter> <asterite> livcd shoot :-)
akaiiro has joined #crystal-lang
Creatornator has joined #crystal-lang
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
akaiiro has quit [Ping timeout: 256 seconds]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.2]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
a__b__m is now known as abm
<FromGitter> <straight-shoota> @Flink The information which macros are defined on a type is theoretically available, it just seems it is not exposed in the macro language. There is Crystal::Macros::Macro (https://crystal-lang.org/api/0.25.1/Crystal/Macros/Macro.html) but I don't think there is a way to actually get one. It should be feature request though.
<FromGitter> <straight-shoota> @Svenskunganka It's considered unsafe because if the string is changed, the pointer may become invalid.
bmcginty has quit [Ping timeout: 260 seconds]
<oprypin> actually GC will just keep it alive
<FromGitter> <bew> If I keep a pointer on the N-th char of a String, and loose the reference to the String object, does anyone know if the gc will collect it and invalidate my pointer?
<FromGitter> <r00ster91> `@instance_vars are not yet allowed in metaclasses: use @@class_vars instead` ⏎ Is there some reason why @instance_vars are not yet allowed in modules and will it even ever be allowed? Or some internal limitations which makes @instance_vars for modules hard to implement?
<FromGitter> <bew> @r00ster91 what does it mean to have instance vars for a module? As you can't get an instance of that module..
Creatornator has joined #crystal-lang
<oprypin> macro included
<FromGitter> <bew> Ah right you can include a module, 'forgot that
akaiiro has joined #crystal-lang
<z64> @r00ster91 that error doesn't say anything about modules. https://carc.in/#/r/4p0y
<FromGitter> <asterite> Actually, `String#to_slice` used to be unsafe because you could then modify the slice, and if the string was in the ROM (read only memory) section of the program it would cause a segfault. That's not true anymore because the returned slice is read-only, so the docs should be updated. (you can, however, get a pointer from that slice, but doing that is unsafe and is marked as such because it's called `to_unsafe`)
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <Svenskunganka> @asterite I see, so what @straight-shoota said is not possible? That is, if the String that you call `to_slice` on is modified, the Slice reflects the same changes and isn't invalid?
<FromGitter> <Svenskunganka> Or is the Slice copied?
<FromGitter> <asterite> Strings can't be modified
<FromGitter> <asterite> strings are immutable
<FromGitter> <Svenskunganka> Oh right
<FromGitter> <r00ster91> ooh okay I understand it now. I always thought `@@class_vars` can be used in every class and `@instance_vars` only in the current class. But `@instance_vars` are only for the current instance (so something that you can instantiate) but a module cant be instantiated. Thanks @bew and z64
<FromGitter> <asterite> r00ster91: you get that error if you use instance variables in a class method (`def self.something`)
wontruefree has quit [Quit: this is not the client you are looking for]
<FromGitter> <jwoertink> Is there a way with spec to test that a method gets called with a specific argument at least once?
<z64> @jwoertink a few ways, probably - you could reopen `Foo` to add a collector for method calls, populated by an override that calls previous_def
<FromGitter> <jwoertink> ah. That might be good. I'll look in to that. Thanks!
<z64> @jwoertink a simple example of what i'm thinking of: https://carc.in/#/r/4p2e
<FromGitter> <bararchy> @bcardiff is the 0.26 version build is running? or is it "not ready yet" ?
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 244 seconds]
Creatornator has joined #crystal-lang
ashirase has quit [Quit: ZNC - http://znc.in]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
Creatornator has joined #crystal-lang
hightower4 has quit [Ping timeout: 256 seconds]
kosmonaut has quit [Quit: The Lounge - https://thelounge.chat]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
Raimondii has joined #crystal-lang
asterite_ has joined #crystal-lang
maxpowa_ has joined #crystal-lang
Raimondi has quit [*.net *.split]
maxpowa has quit [*.net *.split]
Combinatorialist has quit [*.net *.split]
asterite has quit [*.net *.split]
go|dfish has quit [*.net *.split]
Cyrus has quit [*.net *.split]
chkilroy has quit [*.net *.split]
maxpowa_ is now known as maxpowa
Raimondii is now known as Raimondi
asterite_ is now known as asterite
Cyrus has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang