ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
avane_ has joined #crystal-lang
avane has quit [Ping timeout: 258 seconds]
jhass[m] has quit [Read error: Connection reset by peer]
fifr[m] has quit [Read error: Connection reset by peer]
jhass[m] has joined #crystal-lang
fifr[m] has joined #crystal-lang
ur5us_ has quit [Ping timeout: 256 seconds]
ur5us_ has joined #crystal-lang
DeBot_ has quit [*.net *.split]
kevinsjoberg has quit [*.net *.split]
DeBot has joined #crystal-lang
kevinsjoberg has joined #crystal-lang
ur5us_ has quit [Ping timeout: 256 seconds]
<straight-shoota> If the purpose is to treat the `Pointer(Pointer(UInt8))` as a C array of strings, that won't work because the memory layout of `Array(String)` is different from `**char` in C.
<FromGitter> <yb66> Hello all. Quick question: `` (or `to_s`) brings back "Local", which doesn't seem all that useful. Is that based on some kind of Ruby method or something?
<straight-shoota> `Time::Location.local` by defualt loads whatever local time zone setting is configured in the application environment. See
<straight-shoota> If no TZ environment variable is set, it loads the data from `/etc/localtime` which technically only provides the time zone data, but no name for it
<FromGitter> <yb66> Right, and all the stuff like #zones brings back the right info, but no one is using "Local" as their system setting. I know I'm not.
<straight-shoota> Yes, it is
<straight-shoota> neither the file name nor content tell the name of the time zone
<FromGitter> <yb66> But it can be ascertained, or at least, I can get it on my mac.
<straight-shoota> Yeah, the file is usually a symlink, so you can guess the name from the link target
<FromGitter> <yb66> ` "/etc/localtime").parts[-2..-1].join("/")`
<straight-shoota> or maybe we could use `/etc/timezone` if available
<FromGitter> <yb66> If it's not some kind of a standard I could look into something a bit more helpful, just don't want to start if it's not worth it
<straight-shoota> This is definitely worth improving
<FromGitter> <yb66> Okay, I'll open an issue and put up some code to be shot down :)
<FromGitter> <yb66> Thanks.
<straight-shoota> Checking for a symlink into any of the ZONE_SOURCES directories should be easy to do. If it's hard copy, we could still compare the contents.
<straight-shoota> I'm not sure about the precedence of /etc/timezone vs /etc/localtime. That might need some research
<straight-shoota> Research meaning: How do others do it?
<FromGitter> <yb66> This is a bit new to me tbh, I know that Mac's use /etc/localtime, and the closest thing I found in Ruby was ActiveSupport's time zone stuff, but nothing about calling without setting first.
<FromGitter> <MrSorcus> Hey guys 😄
<FromGitter> <MrSorcus> ```require "mime" ⏎ MIME.init(true) ⏎ puts MIME.from_extension(".js")``` ⏎ ⏎ Why it prints `application/javascript`? []
<FromGitter> <Blacksmoke16> one of your local mime database files prob has that type defined
<FromGitter> <Blacksmoke16> does it work if you pass `false`
<FromGitter> <MrSorcus> @Blacksmoke16 failed if `true` replaced with `false`.
<FromGitter> <MrSorcus> If i do `MIME.init(false); MIME.init(true)` still return `application/javascript`.
<raz> hmpf, it would be tremendous if this worked:
[R] has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
<raz> i want a method to return symbols to signal errors, but the caller should decide what symbols are allowed
<raz> eh typo fix:
<raz> eh still a .new missing, but you get the idea ;)
<raz> hrm, but exhaustive case doesn't do symbols either...
* raz sad macro noises
<FromGitter> <Blacksmoke16> solution here is to use an enum, but the problem is you cant monkey patch an enum, or define an abstract/parent one
<FromGitter> <Blacksmoke16> e.g. for custom members
<raz> well, thing is, the important_operation method has multiple callers. each needs to handle it differently when e.g. :not_found is returned.
<raz> normally that's a case for an exception but i want to limit (at compile time) what can be returned. i.e. when the method decides to return :foobar then compiler should force me to handle that in all callers.
<FromGitter> <Blacksmoke16> return an exception obj and `case/in` it
<raz> yeh, guess that's the last resort
<raz> i'm trying to limit the verbosity because i already have that enum (from protobuf).
<raz> maybe i can macro-generate a class for each value tho, hm. gonna try that.
<FromGitter> <Blacksmoke16> doesnt sound worth it imo
<raz> well, i have a pretty nice protobuf impl now. you throw in the *.proto files. and then you just write a `class ProtoServiceFoo; def svc_method(arg : argType); end; end`. req's get routed there, everything is type-checked. if your method-sig or return value doesn't match the proto-spec, doesn't compile. if a method from the spec is missing, doesn't compile. the only challenge is now to have errors that occur in there equally type-safe. svc_method may call
<raz> *other* methods which may return errors. i want to limit those others to a set of errors that `svc_method` can understand (and then wrap into a valid response that matches its own signature).
<raz> anyway, i'm pretty sure it's doable, probably will have to indeed generate dummy-classes for those enum values. not pretty, but should give me the compile-errors i want. :)
<raz> just makes me wonder if exhaustive case _could_ in principle support symbols or if there's some physical blocker that makes it impossible. (my feeling is it should be possible since sym's are known at parse time? but could well be i'm missing sth)
<FromGitter> <Blacksmoke16> not really, what if someone else is also using symbols and does `:foo` in their internal API, boom broken
<raz> how would that break exhaustive case?
<raz> isn't a sym effectively a const that gets passed around?
* raz scratches head
<FromGitter> <Blacksmoke16> a symbol is a named integer
<FromGitter> <Blacksmoke16> but exhaustive case assumes it handles *all* symbols no? so if you define more it's not long exhaustive
<FromGitter> <Blacksmoke16> it's no longer*
<raz> ahh... hmmm... yea that might be the problem. i guess the compiler can't know as easily _which_ symbols a method returns
<raz> anyway, i guess for my case it would be largely syntactic sugar. typing `return :new_kind_of_error` to invent a new case that callers need to handler would be just more convenient than having to define an explicit class for it
* raz has this boilerplate allergy
<FromGitter> <HertzDevil> if there is crystal-lang/crystal#10837 you can return a symbol
<FromGitter> <Blacksmoke16> his problem is i imagine he wants to define an API that can return an enum member, but that the members are defined in the implementing code
<FromGitter> <Blacksmoke16> so would need like `abstract enum` or something
<raz> yeh, i essentially want a way to make this a compile-time error:
<raz> eh, shorter version:
<FromGitter> <HertzDevil> is `"BOO"` always a compile-time string literal
<FromGitter> <HertzDevil> if not then obviously it cannot be a compile-time error
<raz> yes, it is. i just made it a string for that example.
<raz> kinda like this
<raz> <- i think this makes more sense to understand how i mean it ;)
<FromGitter> <HertzDevil>
<raz> hurr!!!
<raz> ok that will take me a bit to study, but i feel like that may have what i want
<raz> thanks in advance 🙇
ur5us_ has joined #crystal-lang
HumanG33k has quit [Ping timeout: 252 seconds]
HumanG33k has joined #crystal-lang
ur5us__ has joined #crystal-lang
ur5us_ has quit [Ping timeout: 240 seconds]