<crystal-gh>
[crystal] ddfreyne opened pull request #3426: Fix #divmod for Float (master...denis/bug/float-divmod-int) https://git.io/vPisb
<jokke>
can i get the compile time return type of a method of a given type?
<jokke>
from a macro
<BlaXpirit>
jokke, you can get the type but not in a macro context, so to say
<jokke>
:/
<BlaXpirit>
you can do typeof(f(5)) but not {% typeof(f(5)) %}
<BlaXpirit>
i've recently had to deal with this, maybe i can offer an alternative if u explain
<jokke>
BlaXpirit: well i'm desperately trying to write some kind of simple mocking library
<BlaXpirit>
ah lol
<BlaXpirit>
that's totally mind-boggling
<jokke>
so i'm basically wrapping an object with a mock class that basically hooks into method_missing and returns a value that's given to it in form of a mapping
<jokke>
i want to check the values in the mapping so that they are of the same type than what the method originally returns
<jokke>
it is totally mind-boggling
<jokke>
i feel like going way too deep into the rabbit hole
<jokke>
but if i can't access the infered type of a macro variable i think i'm doomed
<jokke>
also my approach makes it really hard to check for arguments that were passed to the method call
<jokke>
because i'd need to know their types in beforehand to store them in a instance variable
<jokke>
otherwise i'd need to generate the mocker class on the fly but that's not possible from inside of defs
grindhold_ has quit [Quit: No Ping reply in 180 seconds.]
<jokke>
BlaXpirit: so, any alternatives come to mind? :)
grindhold has joined #crystal-lang
ltran has joined #crystal-lang
ltran has quit [Ping timeout: 256 seconds]
soveran has quit [Remote host closed the connection]
Philpax has joined #crystal-lang
<jokke>
it's not possible to make procs with splat args?
<jokke>
hmm
<jokke>
i'm trying to find out the return type of a proc literal
<jokke>
but apparently it's not possible
<jokke>
undefined macro method 'ProcLiteral#def'
<BlaXpirit>
sorry, i'm bailing on this :|
<BlaXpirit>
yes there's no way to get return type of anything inside macros
HakanD____ has quit [Quit: Be back later ...]
HakanD____ has joined #crystal-lang
Ven has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 252 seconds]
<crystal-gh>
[crystal] timcraft opened pull request #3427: Handle non array return values in Enumerable#flat_map (master...fix-enumerable-flat-map) https://git.io/vPiCW
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 250 seconds]
Ven has quit [Ping timeout: 250 seconds]
Ven has joined #crystal-lang
Ven has quit [Read error: Connection reset by peer]
Ven has joined #crystal-lang
Ven has quit [Ping timeout: 244 seconds]
Ven has joined #crystal-lang
HakanD____ has quit [Quit: Be back later ...]
<jokke>
BlaXpirit: not entirely correct. You can get the return type of methods
<jokke>
so if you actually pass a type to a macro like this my_macro(String, ..) you can use #resolve and then #methods on the first argument
pawnbox has quit [Remote host closed the connection]
<BlaXpirit>
jokke, but you need to be aware that this is only the annotated return type which may be missing or not precise enough
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
eizua has joined #crystal-lang
Ven has quit [Read error: Connection reset by peer]
Ven has joined #crystal-lang
ltran has joined #crystal-lang
Philpax has quit [Ping timeout: 245 seconds]
ltran has quit [Ping timeout: 256 seconds]
Ven has quit [Read error: Connection reset by peer]
Ven has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 265 seconds]
<BlaXpirit>
so seems like there is no method_missing for class methods :/
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vPi0k
<crystal-gh>
crystal/master 9119c33 Ary Borenszweig: Compiler: rename `considered_external` to `c_calling_convention` and don't use it for fun linkage.
pawnbox has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
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
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
dhk has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
<BlaXpirit>
i would argue that @type should automatically be ignored until the last moment
<BlaXpirit>
what do you think?
<BlaXpirit>
by 'ignored' i mean something like the escaping that you did
<BlaXpirit>
it's difficult and maybe not intuitive but who would ever want the current behavior if it alwaysw returns the type that you're writing code in
<RX14>
BlaXpirit, no thats just more confusing
<RX14>
and i can think of plenty of reasons
<BlaXpirit>
yeah actually it's crazy
<BlaXpirit>
it can be part of a bigger expression and it would have to ignore that whole thing
* BlaXpirit
closes "New Issue" tab
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
HakanD____ has quit [Quit: Be back later ...]
HakanD____ has joined #crystal-lang
HakanD____ has quit [Ping timeout: 252 seconds]
<BlaXpirit>
I'm looking for a very optimal way of converting a bunch of, let's say, 32-bit numbers into a Slice(UInt8)
<BlaXpirit>
and the size of the slice may not always be n*3
<BlaXpirit>
and the size of the slice may not always be n*4
pawnbox has quit [Remote host closed the connection]
ltran has joined #crystal-lang
pawnbox has joined #crystal-lang
ltran has quit [Ping timeout: 244 seconds]
soveran has joined #crystal-lang
snsei has joined #crystal-lang
soveran has quit [Ping timeout: 252 seconds]
snsei has quit [Ping timeout: 265 seconds]
soveran has joined #crystal-lang
ponga has quit [Quit: Connection closed for inactivity]
snsei has joined #crystal-lang
<BlaXpirit>
[1, 2, 3].shuffle(SecureRandom) works
<BlaXpirit>
this is the best day of my life
<BlaXpirit>
finally i understand what `extend` does
<Yxhuvud>
same as include but into the class level.
eizua has quit [Quit: Leaving]
kulelu88 has joined #crystal-lang
ltran has joined #crystal-lang
soveran has quit [Remote host closed the connection]
ltran has quit [Ping timeout: 252 seconds]
<jokke>
when does this happen? Bug: trying to upcast String <- String+
HakanD____ has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
HakanD____ has quit [Ping timeout: 250 seconds]
pawnbox has quit [Remote host closed the connection]
ltran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Ping timeout: 260 seconds]
<Papierkorb>
I'm constantly surprised how few memory crystal programs require, besides how efficient they run
soveran has joined #crystal-lang
HakanD____ has joined #crystal-lang
soveran has quit [Ping timeout: 245 seconds]
soveran has joined #crystal-lang
<RX14>
BlaXpirit, did you work out your slice problem?
<RX14>
it's for random_bytes right?
<RX14>
i was thinking about that too
<RX14>
didn't really come up with much
<BlaXpirit>
RX14, yeah i have a solution. though didn't code for big endian
<BlaXpirit>
basically i create a slice that is too big, not to bother with the end
<RX14>
does it really matter?
<BlaXpirit>
and cast it to another type and blah
<RX14>
BlaXpirit, you could always write some assembly
<RX14>
i think you can load numbers into a register then address that register as 4 smaller registers or something on x86
<RX14>
BlaXpirit, the slice too large requires an extra memory copy right
<BlaXpirit>
RX14, no
<RX14>
hmm?
<RX14>
of you don't have it like write(sclie)
<BlaXpirit>
i think how it works is the memory is allocated and information about it is written into a Slice
<RX14>
you return a slice?
<BlaXpirit>
but if you make another Slice with different size but the same pointer, it doesnt need another allocation and keeps the original pointer alive
<RX14>
I think it might be easier to use byte shifts to extract the bytes
<RX14>
handle each unsigned size seperately
<FromGitter>
<johnjansen> ok guys here is a philosophical question, should `“hello”.rindex(/.l/)` match `el` or `ll`
<BlaXpirit>
certainly not easier
<BlaXpirit>
what's philosophical about it
<FromGitter>
<johnjansen> haha, yeah
<BlaXpirit>
can this even be implemented?
<BlaXpirit>
with pcre
<FromGitter>
<johnjansen> i got hit by a car, dont pick ;-)
<RX14>
well
<RX14>
you match against the string
<RX14>
and pick the last match
<RX14>
or
<RX14>
attempt to match strings from the end
<BlaXpirit>
yes it is posible, sorry
<jokke>
is there a way to get all arguments from within a def without knowing the names or amount of the arguments?
<RX14>
they give different results BlaXpirit
<BlaXpirit>
johnjansen, it would be 'll' for sure
<FromGitter>
<johnjansen> so both ruby and crystal return `el`
<RX14>
yep
<RX14>
because matches can't overlap BlaXpirit
<FromGitter>
<johnjansen> but `ll` seems right to me
<RX14>
so matching from left matches el
soveran has quit [Ping timeout: 260 seconds]
<RX14>
then doesn't find ll
<RX14>
because it overlaps
<jokke>
the method is being defined by a macro
<RX14>
unfortunately it's hard to implement the other case
<FromGitter>
<johnjansen> but this is `rindex`, which is meant to scan from the right, so technically it should be `ll`
<FromGitter>
<johnjansen> yeah, thats what i was thinking
<FromGitter>
<johnjansen> there is a funny situation here as `rpartition` in ruby does in fact work correctly
<BlaXpirit>
RX14, i don't think what you're saying is correct. why is it so certain that matches can't overlap?
<RX14>
maybe for each match, start matching from the first match index + 1
<RX14>
BlaXpirit, because thats how pcre works
<FromGitter>
<johnjansen> but obviously doesnt use rindex
<RX14>
thats how regex works
<RX14>
they just don't
<BlaXpirit>
pcre only implements "search starting at x position"
<BlaXpirit>
pcre only implements "match starting at x position"
<RX14>
pcre can return multiple matches
<BlaXpirit>
it you keep calling it
<FromGitter>
<johnjansen> so here is the philosophical part … do we follow ruby or come up with what i think is the correct answer `ll` in this case
<FromGitter>
<johnjansen> it makes me wonder how many people have used `rindex`in ruby and not seen this situation arise and pondered
<RX14>
hmm
<BlaXpirit>
this is definitely not correct behavior, makes no sense at all. in fact, it's best not to have this method
<BlaXpirit>
as it seems to be currently
<FromGitter>
<johnjansen> haha, so both rindex and rpartition by regex are problematic
bjz has joined #crystal-lang
<BlaXpirit>
of course they are
<FromGitter>
<johnjansen> haha great
<BlaXpirit>
the same regex could match from position 1 to position 7 and also match from position 3 to position 5
<BlaXpirit>
which is the last one then?
<FromGitter>
<johnjansen> ok i have a PR coming to add rpartition with a Char and String sep, but im going to avoid regex for now
<FromGitter>
<johnjansen> YUP !!!
soveran has joined #crystal-lang
<RX14>
well
<RX14>
regex shouldn't be in the stdlib at all in my opinion
<FromGitter>
<johnjansen> it seems like you would need to scan the string backward testing with each additional prefix, then bail on the first matching case
<RX14>
like, using regex
<RX14>
it should be avoided
<RX14>
for perf reasons
<RX14>
not remove regex xupport
<FromGitter>
<johnjansen> +1
<FromGitter>
<johnjansen> thanks guys
<Yxhuvud>
honestly, in the ll case I'd submit a bug report to the ruby guys as well.
<RX14>
they won't change it
<FromGitter>
<johnjansen> too late for them im afraid
<RX14>
i'm sure it's been reported
<Papierkorb>
Is it possible to dump all fibers and what they're currently doing or waiting for?
<Yxhuvud>
how sure?
<RX14>
Yxhuvud, ruby has millions of users over 10 years sure
<RX14>
and I spotted that bug in 10 mins
<RX14>
so
<Yxhuvud>
because I wouldn't be certain enough people even know rindex exist, and even takes regexps as an argument (I certainly didn't know the last part of that)
<FromGitter>
<johnjansen> id be 50/50 on if this kind of thing has been reported, but ill take a look
<Yxhuvud>
they *are* constantly fixing bugs you know, and this totally smells like one.
<RX14>
its likely not a bug
<RX14>
just how things are
<FromGitter>
<johnjansen> haha, back to philosophical again ...
<RX14>
its one of those things you can't change until ruby 3
<Yxhuvud>
They are perfectly happy changing stuff that they consider pure bugs.
<RX14>
well
<RX14>
report it if you wish
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 260 seconds]
<Yxhuvud>
eh, actually, no. at least in ruby 2.3.1 "hello".rindex(/.l/) returns 2. meaning that the match start with the l.
soveran has quit [Remote host closed the connection]
<Yxhuvud>
meaning that the method work the obvious way.
<wlib>
but it gives my this error : `undefined constant Tempfile
<wlib>
what am i doing wrong
<FromGitter>
<raydf> @johnjansen, that's default behavior for regex.
<FromGitter>
<raydf> try with http://regexr.com/ and you'll see the same.
<FromGitter>
<jwoertink> Wouldn't you want `/.l+/` to match more than one?
<FromGitter>
<johnjansen> String#scan *Searches the string for instances of pattern, yielding a Regex::MatchData for each match.* ⏎ *EACH* being the operative word … so why not yield all of [‘el’, ‘ll’] since the both match
<FromGitter>
<raydf> because overlapping
<FromGitter>
<johnjansen> understood … @raydf
<FromGitter>
<johnjansen> unfortunately this is causing a deviation from ruby in String#rindex
<FromGitter>
<johnjansen> although scan itself is correct …arrrggh
<FromGitter>
<raydf> I haven't used much ruby, sorry, didn't knew about difference in behavior.
<BlaXpirit>
wlib, you probably need to import the module that contains that
<BlaXpirit>
Defined in: tempfile.cr -> `require "tempfile"`
soveran has joined #crystal-lang
<wlib>
silly me, thanks @BlaXspirit
wlib has quit [Quit: Page closed]
soveran has quit [Ping timeout: 245 seconds]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<FromGitter>
<johnjansen> yeah, sorry @raydf this relates to a specific deviation between the way rpartition and rindex work (in ruby) so im not so much looking for regex help as well help from the man above
<FromGitter>
<raydf> \K removes the part found by the first ".*". Of course still that's a very different behavior from ruby
<FromGitter>
<raydf> :)
<FromGitter>
<raydf> i wrote at the same time :)
<FromGitter>
<johnjansen> one would think that you could use rindex to implement rpartition for regex seperators
<FromGitter>
<johnjansen> but alas, rpartition should split “hello” into [“he”, “ll”, “o”] with /.l/ but rindex find ‘el’ not ‘ll'