<postmodern>
i could return nil, but then that would change the type-signature of the Indexable to Buffer?
<FromGitter>
<naqvis> postmodern not sure I follow you, got some example?
<FromGitter>
<naqvis> @wyhaines yeah, that look like Crystal :P
<FromGitter>
<naqvis> good thing, it will make transition of Rubyists to Crystal more smooth
<postmodern>
currently doing `include Indexable(Linux::V4L2Buffer)` and `def unsafe_fetch(index : Int) : Linux::V4L2Buffer`. If I `return nil if index < 0` in unsafe_fetch, then i'd have to change the T type to `Linux::V4L2Buffer?`, which i guess works but i'd rather just not deal with nils somehow
<FromGitter>
<naqvis> you shouldn't be returning Nil, instead raising exception when `index < 0`
<FromGitter>
<naqvis> `raise IndexError.new if index < 0`
<postmodern>
ah ha
<postmodern>
what's the proper way to convert an Int to an UInt32, if i've already guarded against negative values?
<FromGitter>
<naqvis> `.to_uXX`
<FromGitter>
<naqvis> like `32.to_u32`
<postmodern>
Error: undefined method 'to_uint32' for Int32, hmm
<postmodern>
er right u32
<postmodern>
v4l2's API is weird and somehow complex (but surprisingly well documented)
<FromGitter>
<naqvis> what are you building?
<postmodern>
slowly making progress. can query props and set the format, but still can't query the buffers.
<postmodern>
v4l2 crystal bindings. i have all of the C stuff mapped in, now working on writing the classes to wrap around the ioctl functions and deal with the structs
<FromGitter>
<naqvis> great 👍
<postmodern>
i tried researching other language's v4l2 bindings, but everyone designs them slightly differently
<postmodern>
goal is to get direct video frame access to the webcam
<FromGitter>
<naqvis> awsome
<postmodern>
can then use that to do video effects, hopefully more efficient than ffmpeg
<FromGitter>
<benphelps> if I have a virtual type that I want to pass to a method, and I know it will be only 1 of the virtual types, can I make the compiler not complain about overloading the method to accept the other virtual types?
<FromGitter>
<naqvis> got some example?
<FromGitter>
<benphelps> sort of psudo code but it gets the gist of it
<FromGitter>
<benphelps> because I call test_statement with a string in the test where I know it's only LetStatement, it expects an overload for the other types
<FromGitter>
<benphelps> maybe casting is the only way ?
<FromGitter>
<benphelps> I'm guessing that all makes sense ?
<FromGitter>
<benphelps> methods can't be assigned to a variable like JavaScript or Go, so I have to use Proc's, if I'm going to follow the structure of this books examples
<FromGitter>
<benphelps> at least from what I understand reading through the crystal gitbook
<FromGitter>
<benphelps> ahh, seems to not complain at least after fixing the syntax
<FromGitter>
<naqvis> @benphelps `{} of KeyType => ValueType`
<FromGitter>
<naqvis> not comma
<FromGitter>
<naqvis> `prefix_parsers = {} of Token::Type => PrefixParser`
<FromGitter>
<benphelps> yeah, but that gives an interesting error from the compiler
<FromGitter>
<benphelps> expected -> not NEWLINE
<FromGitter>
<benphelps> but I figured it out :P
<FromGitter>
<naqvis> :P
<FromGitter>
<benphelps> would you say it makes more sense to alias types in a Module over a Class
<FromGitter>
<benphelps> even if it's only going to be used in this one class
<FromGitter>
<naqvis> alias usage is different, not sure I understand your point here
<FromGitter>
<benphelps> maybe I'm trying to match the structure of the Go implementation too closely
<FromGitter>
<benphelps> but he defines a function (template?, type?) with specific arguments and return values, the closest I can get in Crystal is a Proc alias
<FromGitter>
<naqvis> in Go func pointers are good to be translated as alias
<FromGitter>
<naqvis> the way you have done above
<FromGitter>
<naqvis> that seems good
<FromGitter>
<benphelps> alright, I'll roll with it and see where it falls apart, haha
<FromGitter>
<benphelps> AST::LetStatement doesn't have an expression property, AST::ExpressionStatement does
<FromGitter>
<benphelps> trying to test the expression property on an AST::ExpressionStatement and it's complaining because AST::LetStatement wouldn't have that property
<FromGitter>
<benphelps> I'm inside a `if statement.is_a?(AST::ExpressionStatement)` block, so the type is guaranteed to be an AST::ExpressionStatement, but it still complains
<FromGitter>
<dorianmariefr> is there any way to have some sort of "did_you_mean" but for crystal?
heidar has quit [Ping timeout: 244 seconds]
<jhass>
the compiler already does that in some cases
<postmodern>
should i raise an exception instead to perform a long-jump back to the catch point?
<Rounin>
postmodern: I mean, raise is the same as throw, though, isn't it?
<Rounin>
and rescue is the same as catch
<Rounin>
I'm not sure I would say exceptions are the ideal thing for control flow in a program, but it's certainly a simple way to jumpt out of some nested code
<Rounin>
If you do it often, I would expect that it eats some CPU time
<Rounin>
I wonder what happens in C, if you make a label "gohere:" and then goto gohere from a function many levels down from that label... Does it neatly unwind all the stack frames, or just jump and leave everything a mess
<postmodern>
Rounin, i mean sure you can emulate throw/catch usig exceptions and even embed any additional variables into the exception object
<postmodern>
Rounin, in C goto's are function local, to long-jump back several functions, you have to use setjmp() and longjmp()
<Rounin>
postmodern: Oh, OK... Regarding throw/catch, though, in Java, those are used for exceptions... throw/catch and exceptions are one and the same
<Rounin>
I'm not familiar with any other use
<postmodern>
Rounin, ah in Ruby throw/catch behave like raise/rescue, but can pass data back to the catch()ing block
<Rounin>
postmodern: Oh, so ... It's kind of an extra exception mechanism, which is slightly different? I've been using Ruby for years, and I had no idea
<Rounin>
That's very interesting... You learn something new every day
<Rounin>
From reading up on it for like 2 seconds, I guess what you throw with throw isn't typically an exception, so it's more general?
<Rounin>
In which case, that's very clever... Perhaps other languages could benefit from that flexibility
<postmodern>
yeah i used it in this ruby library to wrap around a passed in block. If the block happens to call Extractor.abort! it throws an :abort signal. In the outer wrapping block around the user given closure, i catch the :throw and return 0, indicating to the C function that the callback wants to break out of the loop it's running
<postmodern>
this way the user given closure doesn't have to worry about explicitly returing 0 or 1, since that's a C thing that we're trying to abstract away
Elouin has joined #crystal-lang
<Rounin>
Ah... Interesting mechanism, that... Very interesting
sorcus has quit [Quit: WeeChat 2.9]
sorcus has joined #crystal-lang
<postmodern>
hmm trying to append *arguments from a closure to an [] of Tupes, but I'm getting this error:
<postmodern>
Error: no overload matches 'Array(Tuple(Symbol, LibExtractor::MetaType, LibExtractor::MetaFormat, String, Slice(UInt8) | String))#<<' with type Symbol
<FromGitter>
<Blacksmoke16> Looks like you're trying to push a symbol, not a tuple?
<postmodern>
i double checked that the arguments passed to the proc matches the tuple
<postmodern>
`findings << arguments`
<postmodern>
this is within a spectator spec, so macros might be doing something weird...
<FromGitter>
<Blacksmoke16> :shrug:
<postmodern>
explicitly specifying the closure arguments and crafting a tuple with them worked, :shrug: indeed
<postmodern>
hmm how to convert a Pointer(Char) to a String? All of the String constructors take Pointer(UInt8)
<postmodern>
ah tht was a Char vs LibC::Char issue
<postmodern>
hmm you can't use yield within proc literals? :(
<postmodern>
guess i'll turn that into a class
<postmodern>
hmm why doesn't ->call work from within an instance method, but ->obj.call works outside of the class?
<FromGitter>
<Blacksmoke16> hm?
<postmodern>
ah i have to do ->call(ArgType1, ArgType2, ...)
<postmodern>
hmm now cutting my teeth on parsin YAML
<postmodern>
trying to parse the YAML arrays, coerce via #as_a, then convert that to Tuples via MyTuple.from(array)
<FromGitter>
<Blacksmoke16> prob have to cast each item in the array as something as well
<FromGitter>
<Blacksmoke16> otherwise you end up with `Array(YAML::Any)`
<FromGitter>
<Blacksmoke16> or maybe use serializable stuff
<postmodern>
is there an easy to convert Strings to Symbols?
<FromGitter>
<Blacksmoke16> no, but you can do the otherway around
<postmodern>
(the yaml contains symbols that are supposed to map to some enums)
<FromGitter>
<Blacksmoke16> prob could use a converter to pass the string/symbol to `.parse` of the enum
<postmodern>
like MyEnum.parse(array[1].as_s) ?
<postmodern>
not sure how crystal's YAML implementation will handle ":sym"
<FromGitter>
<j8r> how can bcrypt be useful...
<FromGitter>
<Blacksmoke16> no i mean a custom converter
<FromGitter>
<Blacksmoke16> where you interact directly with `YAML::PullParser`