<FromGitter>
<asterite> constants are kinda hoisted. They are actually lazily evaluated and cached the first time their value is used.
<FromGitter>
<asterite> lbarasti: the value on the right side of a constant assignment has its own scope, it can't access variables outside of it. That's why your snippet fails to compile. This is different from Ruby
<FromGitter>
<tenebrousedge> methods can have the same name but accept different types
<FromGitter>
<silasb> Good point.
<FromGitter>
<silasb> It'd be nice if the compiler saw there was only one version and allowed that to go through, otherwise you end up with type annotation scattered around.
<FromGitter>
<tenebrousedge> procs are always annoying / explicitly typed
<FromGitter>
<tenebrousedge> it's at least consistently annoying
<FromGitter>
<silasb> :P
<FromGitter>
<christopherzimmerman> @kinxer thanks for the gist! That looks great, I'll have to integrate it
hightower3 has quit [Ping timeout: 240 seconds]
hightower2 has quit [Ping timeout: 240 seconds]
<FromGitter>
<christopherzimmerman> Also small plug for Bottle (https://github.com/crystal-data/bottle). If anyone is interested in scientific computing I would love other contributors to form a core team of devs!
<FromGitter>
<watzon> I'm wondering if anyone is using NixOS and if you've found that Crystal gives you any issues with the nonFHS compliant filesystem
<FromGitter>
<watzon> I'm thinking about installing it soon, but I don't want it to screw up my workflow
<FromGitter>
<ImAHopelessDev_gitlab> What OS are you currently on
<FromGitter>
<tenebrousedge> which ignores the default
<FromGitter>
<cserb> I think you are missing the point that the problem is when the key has a value not when the key has no value
<FromGitter>
<tenebrousedge> did you click that link?
<FromGitter>
<tenebrousedge> did you read the text on that line?
<FromGitter>
<cserb> line 1038?
<FromGitter>
<cserb> the weird part is that `pp bar["test']` return the value `[2]` which is *not* the default value (that would be `[]`), but on the other hand `pp bar["test"]?` returns `nil` while it should return `[2]`. And yes `pp bar["whaveter"]` should return `nil` but that's not the problem because it does that
<FromGitter>
<tenebrousedge> it is the default value. You mutated the default value by inserting something into it
<FromGitter>
<tenebrousedge> `<<` mutates its receiver
<hightower4>
yeah, the default it returned to you wasn't a fresh default value assigned to your key, but the same object you'd get on any missing key
<FromGitter>
<tenebrousedge> there's a difference between passing a default value and a default block
<hightower4>
you used a non-existent key to gain access to, and mutate, the default object (as tenebrousedge says), rather than managing to define the value for this key
<FromGitter>
<cserb> > *<hightower4>* you used a non-existent key to gain access to, and mutate, the default object (as tenebrousedge says), rather than managing to define the value for this key ⏎ ⏎ oh now I get!
<FromGitter>
<Daniel-Worrall> Yeah, that's some bad practice since the default value is the same Array each time
<FromGitter>
<Daniel-Worrall> The same thing happens in Ruby
<hightower4>
it's funny though, this approach allows you to create a "hidden hash", doesn't it :) Like, if you define Hash x with default value of Hash.new, then accessing "x[somekey] = " would define key on real hash, while accessing "x[somekey].update(...)" would operate on the default/hidden hash :)
* FromGitter
* tenebrousedge twitches
<FromGitter>
<Daniel-Worrall> Hmm... Would anyone be interested in a `each_with_spawn` convenience?
<FromGitter>
<bararchy> @asterite so... Process and spawn ah? not good friends I guess
<FromGitter>
<kinxer> @christopherzimmerman Would you please update the API docs at http://crystaldata.org?
<FromGitter>
<kinxer> Also, the Bottle specs don't run.
<FromGitter>
<christopherzimmerman> Yea, I haven't updated the tests since I switched to n-dimensional arrays, I'll update the api docs though.
<FromGitter>
<christopherzimmerman> The API is *very* unstable right now, I feel like I re-write the entire thing every few days :), but definitely getting closer to what I want.
<FromGitter>
<bararchy> what's crystaldata ? :)
<FromGitter>
<bararchy> it seems to return no-acess
<FromGitter>
<christopherzimmerman> All user facing methods are exposed in the `B` module, so if you just want an overview I would look at that
<FromGitter>
<christopherzimmerman> That and the `Tensor` class are the meat of the library
<FromGitter>
<bararchy> What are you aiming at with this lib?
<FromGitter>
<bararchy> *shard* :)
<FromGitter>
<bararchy> as in, future goal
<FromGitter>
<christopherzimmerman> Ideally what `numpy` is for Python.
alexherbo2 has joined #crystal-lang
alexherbo2 is now known as alex```
<FromGitter>
<bararchy> interesting :)
<FromGitter>
<bararchy> we do need `Narray` in Crystal
<FromGitter>
<bararchy> that's for sure
<FromGitter>
<christopherzimmerman> I had looked at NArray, possibly to just use it with c-bindings. Based on its performance, I didn't see a reason to not just implement the array in crystal and let the compiler optimize things, kind of like how Julia handles it.
<FromGitter>
<bararchy> Makes sense
<FromGitter>
<bararchy> The more data science options we get in Crystal the better
ht_ has joined #crystal-lang
<FromGitter>
<christopherzimmerman> Yea, data science tools really bring lots of people to the language, `pandas` brought a ton of people to Python from R.
<FromGitter>
<Daniel-Worrall> Is there a docker tagged I can use to test my app with MT?
<FromGitter>
<Blacksmoke16> pretty sure you can use nightly or latest and just pass the flag in when building your app
<FromGitter>
<Daniel-Worrall> ah I thought I had to use crystal compiled specifically with MT
<FromGitter>
<Blacksmoke16> naw
<FromGitter>
<Blacksmoke16> its in there just behind a compiler flag
<FromGitter>
<Daniel-Worrall> so I can probably just use my local crystal
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<Daniel-Worrall> what's the flag?
<FromGitter>
<Daniel-Worrall> Since I have you here :^)
<FromGitter>
<Blacksmoke16> `crystal run --release -Dpreview_mt my_app.cr`
<FromGitter>
<Daniel-Worrall> does it have to be release?
<FromGitter>
<Blacksmoke16> no
<FromGitter>
<Blacksmoke16> but if you're benchmarking or something should have it
<FromGitter>
<Daniel-Worrall> I just wanted to test speed/cpu by eye
<FromGitter>
<Daniel-Worrall> Ah, so my C lib bindings aren't MT safe
<FromGitter>
<Daniel-Worrall> (duktape)
<FromGitter>
<Daniel-Worrall> I'd have to spin up new runtimes for each thing hmm
<FromGitter>
<Daniel-Worrall> So I think I'll keep the module level class variable for the simplicity of `Beautify.js(content)`, but also add a Runtime Class with an instance mutex and allow Runtimes to be created on request with the same api, so `runtime = Beautify.js_runtime; runtime.js(content)
<FromGitter>
<Daniel-Worrall> Should MT be supported at the lib level or app level?
<FromGitter>
<Daniel-Worrall> cause I could let the user create their own mutex
<FromGitter>
<Daniel-Worrall> OR I could add a macro to create a mutex on the MT flag
<FromGitter>
<Daniel-Worrall> so single threaded don't have mutexes built in
<FromGitter>
<bararchy> ^ איןד
<FromGitter>
<bararchy> bla
<FromGitter>
<bararchy> ^ this
<FromGitter>
<bararchy> makes sure you protect your lib with Mutex
<FromGitter>
<Daniel-Worrall> So flag for MT support at the lib level
<FromGitter>
<christopherzimmerman> I looked at that lib a bit, interesting for sure
<FromGitter>
<bararchy> @Daniel-Worrall yeha
<FromGitter>
<kinxer> @christopherzimmerman Looks good. There's a bit of code duplication (the strategy structs), but I'm glad you were able to improve your iterator speed.
<FromGitter>
<kinxer> Ah, right. I see the difference now. That could probably be handled with a macro, though.
<FromGitter>
<Blacksmoke16> mutex question since thats on topic atm
<FromGitter>
<Blacksmoke16> say im using fibers for generating files
<FromGitter>
<Daniel-Worrall> File.write is MT safe I believe
<FromGitter>
<Blacksmoke16> more so was thinking for the db queries to get the data?
<FromGitter>
<christopherzimmerman> @bararchy just noticed you're the primary contributor ha! How far do you think you are from GPU acceleration?
<FromGitter>
<Daniel-Worrall> depends on the db query, method, and driver, since they support multiple connections ⏎ but, if they weren't, you'd only need to mutex.synchronize on the db lookups
<FromGitter>
<Daniel-Worrall> io not being MT safe is breaking exception printing
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
<FromGitter>
<asterite> what does MT at the lib or app level mean?
<FromGitter>
<asterite> I mean, MT support
<FromGitter>
<Daniel-Worrall> Having the lib introduce use mutex for calls instead of an app (user calling the lib)
<FromGitter>
<Daniel-Worrall> Whether it's the libs responsibility or apps for missing
<FromGitter>
<Daniel-Worrall> Mutex'ing*
<FromGitter>
<asterite> Oh, I see. In Go it's a convention to say "this type is safe for concurrent use", and when nothing is said you can't assume it's safe. And I think it's always safe if the library provides MT safety. But it's not always possible.
<FromGitter>
<Blacksmoke16> whats the equivalent to `$string1 ^ $string2` in crystal, from PHP?
<FromGitter>
<Blacksmoke16> https://www.php.net/manual/en/language.operators.bitwise.php `If both operands for the &, | and ^ operators are strings, then the operation will be performed on the ASCII values of the characters that make up the strings`
<FromGitter>
<Blacksmoke16> `Error: undefined method '^' for Array(Char)`
<FromGitter>
<tenebrousedge> really? huh
<FromGitter>
<tenebrousedge> then `zip` I guess
<FromGitter>
<asterite> @christopherzimmerman what numeric types do you use in your libraries? I always wonder what are good types in a statically typed language, unlike in python where ints are unbounded
<FromGitter>
<tenebrousedge> `str1.each_char.zip(str2.each_char).map {|a,b| a ^ b }`
<FromGitter>
<tenebrousedge> assuming that `Char#^` exists
<FromGitter>
<tenebrousedge> otherwise use `ord` as appropriate
<FromGitter>
<tenebrousedge> use `join` instead of `map` if the result needs to be a string
<FromGitter>
<Blacksmoke16> hmm that seems to work but output is diff
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<FromGitter>
<Blacksmoke16> hmm
<FromGitter>
<Blacksmoke16> actually what if they are diff sizes
<FromGitter>
<Blacksmoke16> nvm, they'll be the same size
<FromGitter>
<christopherzimmerman> @asterite right now I support `Int32`, `Float64`, `Float32` and `Bool`. Since a lot of routines use BLAS and LAPACK, integer support is a bit limited. I also need to write my own Bool implementation that supports numerical operations, but that will be a ways away.
<FromGitter>
<Blacksmoke16> @tenebrousedge i figured it out
<FromGitter>
<Blacksmoke16> php pads its hex values
<FromGitter>
<tenebrousedge> yeah, that's my point of reference too 👀 I ran away scared
<FromGitter>
<christopherzimmerman> Is there any way to have a variable number of arguments in a setter? so `a[1, 2, 3] = 10` and `a[1, 2] = 10` both calling the same method?
<FromGitter>
<christopherzimmerman> I kind of doubt it because you can't have positional arguments after *args :(
<FromGitter>
<Daniel-Worrall> so, I'm not too familiar with C. https://silverhammermba.github.io/emberb/embed/ ⏎ Would I need to write a C library and then write a Crystal binding to that C lib, or would I be able to write Crystal code to bind to the header file?
<FromGitter>
<Fryguy> I think if you build Ruby with --enabled-shared, then you get a libruby.so file, which you can then link to. At that point, you create a Crystal lib based on the exported functions you want to link to. I'm not sure if Ruby exports its functions though
<FromGitter>
<Fryguy> 1) --enable-shared
<FromGitter>
<Fryguy> ruby-install and rbenv support this flag as well
<FromGitter>
<Fryguy> or whatever rbenv uses... ruby-build?
<FromGitter>
<tenebrousedge> @asterite what does that do? o__o
<FromGitter>
<christopherzimmerman> Oh I think that was meant for me
<FromGitter>
<tenebrousedge> I think you're right o__o
<FromGitter>
<christopherzimmerman> I'm surprised, even if I mix types in args, the type of the last argument is still correctly inferred. My use case is closer to this (https://play.crystal-lang.org/#/r/7yz8)
<FromGitter>
<christopherzimmerman> I would have expected a union type.
<FromGitter>
<asterite> the thing is that splats are implemented as tuples, and tuples know what type is in each position
<FromGitter>
<asterite> we designed it like that mainly to be able to forward method args, but from there a lot of benefits appeared (like this one)
<FromGitter>
<asterite> though ideally you could slice a tuple with the regular syntax
ht_ has quit [Quit: ht_]
yukai has joined #crystal-lang
Human_G33k has joined #crystal-lang
Human_G33k has quit [Remote host closed the connection]