<crystal-gh>
[crystal] mosop closed pull request #2593: Rescue doesn't accept global type path (master...rescue_accepts_global_type_path) https://git.io/vrskA
<crystal-gh>
[crystal] mosop reopened pull request #2593: Rescue doesn't accept global type path (master...rescue_accepts_global_type_path) https://git.io/vrskA
<emancu>
anyone online ?
<emancu>
some questions:
<emancu>
1) I'm defining a `initialize` method on a module, and I expect to have that initialize on every class that includes that module, is it possible? I can't make it work
<emancu>
2) When I do `include SomeModule` I want to add methods as instance methods, but also the ones defined as `def self.class_method` as class methods
<emancu>
I know the trick on ruby is using the `def self.included(klass)` and do `klass.extend ClassMethods` or something similar. How can I accomplish that in Crystal ?
<emancu>
3) How can I start playing with the named tuples? I found that I really need them =)
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
soveran has quit [Remote host closed the connection]
<BlaXpirit>
emancu, 2) macro included
<BlaXpirit>
emancu, 1) probably doesn't work, but you can try... might be a better bet to use def self.new
<BlaXpirit>
emancu, 3) download source code from git and `make`
pawnbox has quit [Read error: Connection reset by peer]
<jhass>
emancu: 1) seems sensible to me, might want to open an issue for that
<jhass>
still not sure what you're trying to do exactly initially, maybe show what you have?
<BlaXpirit>
i dunno, it's not obvious, def self.new sounds clearer to me
<jhass>
def initialize still looks like a normal method, that it's included into the class and behaves the same as defined directly there is a sensible expectation IMO
<BlaXpirit>
could be confused with initialization of the module
<jhass>
could it? There's no module initialization
<jhass>
at the end of the day a class is a module + initialization or if we flip sides, what makes a module is having no initialization
Ven has joined #crystal-lang
Philpax has quit [Ping timeout: 252 seconds]
trapped has joined #crystal-lang
Philpax has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
pawnbox_ has quit [Remote host closed the connection]
Philpax has quit [Ping timeout: 252 seconds]
pawnbox has joined #crystal-lang
Philpax has joined #crystal-lang
pawnbox has quit [Ping timeout: 246 seconds]
pawnbox has joined #crystal-lang
asie has quit [Quit: WeeChat 1.4]
asie has joined #crystal-lang
pawnbox has quit [Ping timeout: 260 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 276 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
Ven has joined #crystal-lang
<RX14>
upgrading power_assert.cr to the new version of crystal will be "fun"
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<emancu>
BlaXpirit: jhass thanks for the answers, here is my feedback
<emancu>
1) I'm building an ORM so I need a special `initialize` for all the objects, but the programmer can still have his own initializers.
<emancu>
Don't know why but {{@type.instance_vars}} is empty inside the `macro included`
<emancu>
asterite: ^ can you shed some light here?
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<RX14>
whats the best way to get a Array(Char) to a String
<RX14>
because there's no string constructor
<emancu>
Did you tried with `.join('')` ?
<RX14>
nope
<emancu>
and does it works ?
<RX14>
it looks pretty inefficient
<RX14>
i'll see if llvm manages to optimise it
<emancu>
ok
<RX14>
it's 7% slower than using a stringbuilder and each
<RX14>
so
<RX14>
it's pretty fast
<RX14>
but if you have an array and want a subset of chars it's easier to use a stringbuilder yourself and iterate over the indexes in a range then to take a subsection using [Range] and use join
<RX14>
well
<RX14>
not easier, faster
<emancu>
Well, you can define it for a Array(Char)
<emancu>
something like `stringify` or something
<emancu>
which is really simple but it actually uses a stringbuilder under the hood
<jhass>
eh but we probably should have String.new(Slice(UInt32)) and/or String.new(Slice(Char))
A124 has quit [Quit: '']
A124 has joined #crystal-lang
Philpax has quit [Ping timeout: 252 seconds]
<pawnbox>
Since you can no more use class vars in generic classes, what are the alternatives?
<|2701>
is crystal going to avoid the weird sjw plague? Ruby has a CoC now, Rust crew rewrote dining philosophers problem because of some transgender garbage, where does it end? Is crystal going to avoid all of that?
<BlaXpirit>
I have some array of strings that don't really have any meaning other than the identity, until the very end of the program.
<BlaXpirit>
so I'm thinking about replacing the strings with integers, and putting them back at the end
<BlaXpirit>
would I gain any performance by doing that?
<jhass>
well, that's what symbols are for
<BlaXpirit>
jhass, I'm reading those at runtime
<jhass>
mmh
<jhass>
yet comparing them to constant strings?
<BlaXpirit>
jhass, no, to each other
<jhass>
or other read in strings?
<jhass>
String#== does do an identity check first, whether it's the same object
<BlaXpirit>
OK, that's nice. and if I put these strings in all kinds of arrays?
<BlaXpirit>
they should just act like pointers?
<jhass>
doesn't copy them, they're Reference's after all
<BlaXpirit>
meh I just realized it's easy to switch out these things later and actually test it
<BlaXpirit>
thanks
brunto has joined #crystal-lang
globalkeith has joined #crystal-lang
<BlaXpirit>
isn't there a center function like ljust and rjust?
<BlaXpirit>
I mean String method
<jhass>
mmh, Ruby does have one, looks like nobody ported it yet
Oliphaunte has joined #crystal-lang
<jhass>
should be fun
Raimondii has joined #crystal-lang
brunto has quit [Ping timeout: 252 seconds]
Raimondi has quit [Ping timeout: 265 seconds]
Raimondii is now known as Raimondi
Raimondi is now known as Raimondii
Raimondii has quit [Quit: The road to wisdom?—Well, it's plain and simple to express: Err and err and err again, but less and less and less. — Piet Hein]
Raimondi has joined #crystal-lang
<BlaXpirit>
so I would like to 'reject!' based on array index
<BlaXpirit>
:/ cleanest would be to make a new array and each/<<
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
globalkeith has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
pawnbox has quit [Remote host closed the connection]
<BlaXpirit>
undefined method '<=>' for <NamedTuple> sigh
<BlaXpirit>
i would like NamedTuple < Tuple
soveran has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 250 seconds]
soveran has quit [Remote host closed the connection]
Oliphaunte has quit [Remote host closed the connection]
Oliphaunte has joined #crystal-lang
<crystal-gh>
[crystal] davydovanton opened pull request #2596: Fix some typos in comments (master...fix-typos) https://git.io/vrGuw
<BlaXpirit>
how to count non-nil elements? .count { |x| x } is hmm
asie has quit [Ping timeout: 244 seconds]
asie has joined #crystal-lang
globalkeith has joined #crystal-lang
trapped has quit [Read error: Connection reset by peer]
Oliphaunte has quit [Remote host closed the connection]
Raimondi has quit [Quit: The road to wisdom?—Well, it's plain and simple to express: Err and err and err again, but less and less and less. — Piet Hein]
Raimondi has joined #crystal-lang
Philpax has joined #crystal-lang
Oliphaunte has joined #crystal-lang
Philpax has quit [Ping timeout: 252 seconds]
Oliphaunte has quit [Ping timeout: 265 seconds]
<asterite>
emancu: macros inside methods are expanded when a method is instantiated. There's no way the compiler can figure out the type of those instance vars
<asterite>
I'd also avoid Hash-oriented programming in Crystal... mostly because most of the time it doesn't work
<asterite>
I'd also try to use GitHub more, I'm not always around in IRC and I don't always read the logs
|2701 has quit [Quit: Connection closed for inactivity]
globalkeith has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
globalkeith has joined #crystal-lang
smarr has joined #crystal-lang
|2701 has joined #crystal-lang
<smarr>
Hi, I am running into an issue with Crystal 0.16, which used to work before. Crystal crashes with an error when it tries to compile an assignment of a class or its subclasses to a field, is this know? code+output here: https://gist.github.com/smarr/a2709444f192b971e97a8ffbe931c678
globalkeith has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<emancu>
asterite: ok, I'm using Hash-oriented because Im' waiting for the named params and that would be an easier transition =)
<emancu>
asterite: also, "macros inside methods are expanded when a method is instantiated." that is what I actually want. It should know the @type at that moment, right ?
pawnbox has joined #crystal-lang
<emancu>
I mean, if I use the debug() I can see how the type is known, but `instance_vars` is empty :/
pawnbox has quit [Ping timeout: 260 seconds]
<BlaXpirit>
so I'm having the weirdest effect
<BlaXpirit>
my file writer IO breaks after some number of writes
<BlaXpirit>
but no exception
<BlaXpirit>
just truncated file, always at the boundary of writes
<BlaXpirit>
oh i'm not closing it...
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 252 seconds]
<crystal-gh>
[crystal] ysbaddaden pushed 1 new commit to master: https://git.io/vrGwQ
<crystal-gh>
crystal/master 8d90285 Anton Davydov: Fix some typos in comments (#2596)