<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,
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.
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?
<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>
<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
<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
<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
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
<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!