ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
ur5us has quit [*.net *.split]
markmarkmark has quit [*.net *.split]
Peter0x44 has quit [*.net *.split]
Peter0x44 has joined #crystal-lang
markmarkmark has joined #crystal-lang
postmodern has joined #crystal-lang
<postmodern> hey Blacksmoke16, i figured out my initialize with block argument number mismatch problem
<postmodern> appears that the order of the overrided #initialize methods matters
<postmodern> if i moved the #initialize which accepts a block argument that takes 0 arguments, but returns 1 value, then it works
<FromGitter> <Blacksmoke16> nice one!
<postmodern> *moved that #initialize above the other #initialize with accepts a block argument which accepts 1 argument and returns 1 value
<postmodern> is this expected behavior or a known bug, or should i report it? i have a self contained example program now
postmodern has quit [Read error: Connection reset by peer]
postmodern has joined #crystal-lang
<postmodern> if i move that last #initialize above the next one, it compiles
<FromGitter> <Blacksmoke16> does it still work if you want to call the no arg overload?
<postmodern> it does!
<postmodern> is this expected/known behavior or a defect/surprise?
<postmodern> obviously i want to support calling with both a block that accepts no args, and one arg
<FromGitter> <Blacksmoke16> im not sure
<postmodern> calling it with types of blocks fails to compile, so i'm guessing this is a bug where the compiler is not sorting the overloads based on the block arguments
<FromGitter> <Blacksmoke16> could open an issue for it, or at least a forum thread if you're not sure
postmodern has quit [Remote host closed the connection]
sagax has quit [Quit: Konversation terminated!]
hightower2 has joined #crystal-lang
<FromGitter> <anniiii:matrix.org> how can I get a pointer to a property of a object? Trying it tells me that it cant take a pointer to it
<yxhuvud> how does your code look like?
<FromGitter> <anniiii:matrix.org> The property is a c struct that I get from a c method
<FromGitter> <anniiii:matrix.org> And I need to pass a pointer to that struct to C
<FromGitter> <anniiii:matrix.org> to make it more clear the c function will not save the struct, it creates it and returns it
<yxhuvud> I repeat, please show your code.
<FromGitter> <anniiii:matrix.org> not on my pc rn so cant
<yxhuvud> It returns the struct itself or a pointer to it?
<FromGitter> <anniiii:matrix.org> The struct. since it gets generated inside of the function.
<yxhuvud> well, assuming you have put the struct in an instance variable, then `pointerof(@ivar)` should work. What have you tried?
<FromGitter> <anniiii:matrix.org> oh I took pointerof(object.var)
straight- is now known as straight-shoota
sorcus has quit [Quit: WeeChat 3.3]
<FromGitter> <anniiii:matrix.org> works now thx
repo has joined #crystal-lang
<repo> hey!
<repo> Blacksmoke16: nice job with Athena::Console \o/
<repo> i found a little typo: shotcut instead of shortcut
<repo> i'm using keyword args so i noticed
sorcus has joined #crystal-lang
sagax has joined #crystal-lang
<FromGitter> <Blacksmoke16> Oof, good catch :p
<FromGitter> <Blacksmoke16> I'll get that patched up
hightower2 has quit [Ping timeout: 256 seconds]
postmodern has joined #crystal-lang
<postmodern> so i'm still struggling with this code. i want to pass in a block that can optionally accept a String, or accept no args, and return a String, but then store that block in an ivar in an Iterator object
taupiqueur has joined #crystal-lang
<straight-shoota> postmodern, you can't capture a block without a type restriction in `.sub`
<straight-shoota> The error message is a bit confusing.
<straight-shoota> The reason is: `&block` without any restriction defaults to `Proc(Nil)`. At the call site, the block receives a parameter. That doesn't fit because `Proc(Nil)` has no parameters.
<straight-shoota> What you're trying to do here to work around the limitations explained in #11518 doesn't work for exactly the same reasons. `sub` can't capture procs with different types.
<straight-shoota> This just doesn't work
<straight-shoota> You need some other way to differentiate methods with different block argument types. Either use different names or variations in the arguments.
<postmodern> ok if i put a type signature on &block, i get this error, which also seems a bit misleading or could be more descriptive: https://carc.in/#/r/cdh6
<postmodern> are type unions not allowed for blocks?
<straight-shoota> no
<postmodern> hmm that poses a problem for this code
<postmodern> how would you capture a block that's intended to be passed to String#sub(pattern,&block) ?
<straight-shoota> Well that method is pretty unambiguous
<yxhuvud> last I checked there was a gazillion variants of String#sub, so unambigous is hardly a word I'd use :D
<straight-shoota> Sure, there's many overload that it can get crowded
<straight-shoota> but `String#sub` with a pattern parameter and a block is either `sub(pattern : Regex, &block : String, Regex::MatchData -> _)` or `sub(pattern : String, &block : String -> _)`
<straight-shoota> so the type of the pattern paramter defines the arity of the block
<postmodern> straight-shoota, ah i see, so the sub overloads rely on pattern to distinguish them, not the &block signature
<straight-shoota> exactly
postmodern has quit [Read error: Connection reset by peer]
postmodern has joined #crystal-lang
<postmodern> hmm, so crystal doesn't really verify the block arguments of the receiving block vs. the yielding method?
<postmodern> seems i can omit arguments in the receiving block
<postmodern> however if my block has more arguments than the method yields, the compiler will catch that
<riza> that's been my experience as well
<postmodern> arg this code
<postmodern> trying to do `return word.as(String).sub(@pattern,&@block.as(Proc))` results in `expected a function type, not (Proc(String, Regex::MatchData, String) | Proc(String, String))`. I assume the compiler wants me to check what type is @pattern (String or Regex) and select Proc(String,String) or Proc(String,Regex::MatchData,String), so it aligns with the String#sub overrides?
<postmodern> doing `return word.as(String).sub(@pattern,&@block.as(Proc(String,Regex::MatchData,String)))` and using `case @pattern ... in Regexp` gives me `too many block parameters (given 2, expected maximum 1)`
<FromGitter> <Blacksmoke16> sounds like a pita :S
<FromGitter> <Blacksmoke16> take a step back and rethink it?
<postmodern> i already did that :/
<postmodern> hmm should i define separate @block ivars for when the pattern is a String or Regex to ensure type isolation?
<FromGitter> <Blacksmoke16> could you do something with structs?
<FromGitter> <Blacksmoke16> use the structs to wrap the proc, then can type them via an abstract
<postmodern> that's what the Iterator class is supposed to do
<postmodern> or are you saying create a struct or tuple to couple the pattern type and the proc type, so they don't get mixed up in a type union?
<FromGitter> <Blacksmoke16> im not 100% sure what you're doing but i was thinking like:
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=61a7d90d63c1e83c953b3642]
<FromGitter> <Blacksmoke16> `StringPattern.new do`*
<postmodern> trying to capture the args and block passed to a custom #sub method, which then calls String#sub with those same args and block on every String in a wordlist in a Iterator
<FromGitter> <Blacksmoke16> idk if it'll actually work for your use case but :shrug:
<postmodern> seems to be the problem is when my data eventually reaches String#sub and the compiler gets confused about which overload to call
<postmodern> also why don't all String#sub methods have full &block signatures, one just has a generic &block which isn't very informative
<postmodern> not sure if that just needs filling in, or if it's intentionally left ambiguous so the compiler can infer the type signature
<FromGitter> <Blacksmoke16> also to be clear `&` and `&block` are technically not interchangeable
<FromGitter> <Blacksmoke16> but they prob just need filled in
<FromGitter> <Blacksmoke16> if the sig has *only* `&`, it just means it yields, but `&block` means it captures the block
<postmodern> hmm using Tuple doesn't work because the compiler combines the unioned tuples into one tuple
<postmodern> going to try structs next
<postmodern> it worked!
<FromGitter> <Blacksmoke16> 👍 nice
<postmodern> i had to ditch the abstract struct base class because of how the compiler reduces types to it's base type
<FromGitter> <Blacksmoke16> prob just needed to define some abstract def on it but a union of the two is prob the same thing
<postmodern> i also had to explicitly to args = @args.as(SubWithRegexpAndBlockArgs), even though i was inside of a `case @args in ...` statement
<FromGitter> <Blacksmoke16> might have to make it like
<FromGitter> <Blacksmoke16> ```case args = @args ⏎ in SubWithRegexAndBlockArgs then args.call ... ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=61a7e28c8853d316402626ae]
<postmodern> ah i forgot that you have to bind the ivar to a local var for the `if` or `case` statement to narrow it down
<postmodern> still, this was a ton of work to just re-send some args and a block to the appropriate overloaded method
<FromGitter> <Blacksmoke16> is `delegate` macro not enough for your needs?
<postmodern> it's because i had to forward the args into an instance of an Iterator, which meant storing them in an ivar then unpacking them
<postmodern> wouldn't have been necessary if crystal supported Generators for methods that yield data, then i wouldn't have had to use an Iterator
<FromGitter> <Blacksmoke16> mmk
<postmodern> and i had to initialize the Iterator inside of the #each method as a local variable, so Iterator state would be unique to each call of #each
<FromGitter> <Blacksmoke16> cant just rewind it?
<postmodern> it's itereatoring over Enumerable(String), so it needs to be re-initialized on each iteration
<postmodern> hmm well i am converting the Enumerable(String) to it's own Iterator by calling `.each`, so possibly i could override `#rewind` to also call `@wordlist.rewind`
<postmodern> but still, i'm delegating the `#sub` call down to each individual String that the Enumerable(String) gives back
<postmodern> would be cool if we had a `delegate_each` macro that handled that
<FromGitter> <aaaScript> Would anyone know if there's an example or a simple way of viewing attributes certificate attributes from a HTTP request? Basically I'm trying to inspect the SSL certificate from a request and read in all the attributes like subject and expiration.
<FromGitter> <paulocoghi> Any recommendation on an embeddable NoSQL database with range queries (in Crystal or C)?
<FromGitter> <paulocoghi> My best discovery so far: https://github.com/erthink/libmdbx
<FromGitter> <paulocoghi> Unfortunately LevelDB *(nor its Crystal binding)* provides range queries
<FromGitter> <Blacksmoke16> if thats a thing supported by the db, prob just have to add support to the lib
<FromGitter> <paulocoghi> I will probably creating a Crystal binding for libmdbx *(or a better embeddable db)*
postmodern has quit [Read error: Connection reset by peer]
taupiqueur has quit [Remote host closed the connection]