ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.24.2 | Fund Crystal's development: | GH: | Docs: | API: | Gitter:
<FromGitter> <aisrael> First off, I’d find a way to translate the array literal from `[8]uint16{...}` into the Crystal equivalent. And translate the function declaration (parameters and return type).
<FromGitter> <aisrael> Next, in Crystal (and Ruby) we generally don’t loop with an iterator. In this case the what he Go code is doing is really “mapping” a collection into another collection and returning that. So, you’d use `Enumerable#map`
<FromGitter> <unn4m3d> I'd use `reduce` in this case
<FromGitter> <unn4m3d> I think IO::ByteFormat::BigEndu
<FromGitter> <unn4m3d> Oops, accidentaly pressed enter
<FromGitter> <unn4m3d>
<FromGitter> <bajro17> how to implement this part on best way
<FromGitter> <bajro17> for _, shift := range shifts { ⏎ result = append(result, byte((value>>shift)&mask)) ⏎ }
return0e has quit [Read error: Connection reset by peer]
return0e_ has joined #crystal-lang
<FromGitter> <codenoid> owsom
<FromGitter> <codenoid> ma bos just accept my request to hire a frontend-dev
<FromGitter> <aisrael> @bajro17 Crystal has the same binary shift and bitwise or operators
<FromGitter> <codenoid> and i'll have more time to play a real programming lang
<FromGitter> <bajro17> @aisrael I will try to do something then I will send here code on review :)
<FromGitter> <aisrael> 👍🏽 Am sure you’ll figure it out
<FromGitter> <codenoid> i use crystal and cython for sentiment analyst
<FromGitter> <codenoid> from words to words
<FromGitter> <codenoid> owosome UwU
<FromGitter> <unn4m3d> @bajro17 I think IO::ByteFormat::BigEndian.encode(UInt64) does the same think
<FromGitter> <unn4m3d> Thing*
<FromGitter> <aisrael> @bajro17 Just remember that instead of looping across the `shifts`, transforming each element, then appending to a result array, it’s easier to use `Enumerable#map()`
<FromGitter> <aisrael> Or just use an existing method if it does the same thing, as Stepan suggests
<FromGitter> <bajro17> Thank you @aisrael and @unn4m3d I will check now simple
<FromGitter> <bajro17> I just want to convert this from golang to crystal
<FromGitter> <bajro17> to I learn more about crystal
_whitelogger has joined #crystal-lang
<FromGitter> <codenoid> awesome @unn4m3d
<FromGitter> <plainas> Ok, confused, there was a Matrix class that appears to be gone?
<FromGitter> <plainas> Why? Does that class live somwhere else that not the standard api?
duane has quit [Ping timeout: 264 seconds]
duane has joined #crystal-lang
<FromGitter> <Blacksmoke16> :0
<FromGitter> <Blacksmoke16> and here i am trying to make my own
<FromGitter> <Blacksmoke16> heh
<FromGitter> <codenoid> hi, is there any driver for ScyllaDB (Cassandra-Driver)
_whitelogger has joined #crystal-lang
straight-shoota has quit [Ping timeout: 240 seconds]
straight-shoota has joined #crystal-lang
straight-shoota has quit [Read error: Connection reset by peer]
straight-shoota has joined #crystal-lang
return0e_ has quit [Ping timeout: 240 seconds]
return0e has joined #crystal-lang
rohitpaulk has joined #crystal-lang
straight-shoota has quit [Ping timeout: 240 seconds]
straight-shoota has joined #crystal-lang
straight-shoota has quit [Read error: Connection reset by peer]
straight-shoota has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
straight-shoota has quit [Read error: Connection reset by peer]
straight-shoota has joined #crystal-lang
<FromGitter> <yxhuvud> @bajro17 what your code is doing is picking out the individual bytes of the int. I'd use IO::Byteformat.encode(int, slice(Uint8).new
<FromGitter> <yxhuvud> )
straight-shoota has quit [Ping timeout: 263 seconds]
straight-shoota has joined #crystal-lang
rohitpaulk has joined #crystal-lang
straight-shoota has quit [Read error: Connection reset by peer]
straight-shoota has joined #crystal-lang
alex`` has joined #crystal-lang
dragonkh has quit [Quit: Textual IRC Client:]
alex`` has quit [Quit: WeeChat 2.0.1]
alex`` has joined #crystal-lang
ryan_ford has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter> <codenoid> yeah
<FromGitter> <codenoid> mongo c 1.1.0 succesfully installed on my computer machine
Groogy has quit [Disconnected by services]
Groogy_ is now known as Groogy
<Groogy> Morning! o/
Groogy2 has joined #crystal-lang
straight-shoota has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <aisrael> Would it be possible to define a macro to read in `shards.yml` and "embed" the `version:` specified there as a constant?
<FromGitter> <aisrael> (Am getting tired of shard version mismatches :p )
<FromGitter> <aisrael> Well, I suppose this'll have to do: ⏎ ⏎ ``` VERSION = {{ `cat ./shard.yml|grep ^version:|awk '{print $2}'`.stringify }}``` []
straight-shoota has joined #crystal-lang
<FromGitter> <unn4m3d>
<FromGitter> <aisrael> 👍
<FromGitter> <codenoid> i can't install crystal in my pentium 4 pc :(
straight-shoota has quit [Ping timeout: 256 seconds]
rohitpaulk has quit [Ping timeout: 245 seconds]
_whitelogger has quit [K-Lined]
_whitelogger has joined #crystal-lang
<jokke> hey
<jokke> anyone here using slang? i'm having trouble to understand how to span attributes for an element over multiple lines
<FromGitter> <codenoid> ```div: - span ⏎ - span``` []
straight-shoota has joined #crystal-lang
<FromGitter> <straight-shoota> @aisrael `{{ `shards version #{__DIR__}`.chomp.stringify }}`
<FromGitter> <straight-shoota> `` {{ `shards version #{__DIR__}`.chomp.stringify }} ``
<FromGitter> <bararchy> Does anyone work on HAR files parser?
<FromGitter> <straight-shoota> You should really not install a shard just for this @unn4m3d
<Groogy> I'm a bit late, but yeah you definetly can. I parse entire shaders at compile time so
<FromGitter> <bararchy> @aisrael @unn4m3d
<FromGitter> <Sija> for any1 wanting abuse bit of crystal (code), please do here => (works only with crystal nightlies) (:
<Groogy> aCtually... if I could open up an OpenGL context I can do the entire linkage of the shader program at compile time.... 🤔
<FromGitter> <bararchy> Groogy macro-fu !
<Groogy> if I manage to get OpenGL context to work inside of macros I think the devs gonna have a heartattack
<Groogy> probably better to just have the macro run an external crystal script that does it instead
<FromGitter> <straight-shoota> @bararchy could at least be somewhat useful if it would reuse the parser from shards and allow reading arbitrary shard files.
<FromGitter> <straight-shoota> @maiha
<FromGitter> <straight-shoota> still, I wouldn't recommend using any shard just for getting the version out of the shards file
<FromGitter> <bararchy> XD
<FromGitter> <Sija> @unn4m3d just FYI, getting a version out of `shard.yml` as oneliner: `YAML.parse(, "../..", "shard.yml")))["version"].as_s`
<FromGitter> <straight-shoota> @sija that will be executed at runtime when the shards file is probably not going to be available
<FromGitter> <straight-shoota> the purpose is to embed the build version into the binary
<FromGitter> <straight-shoota> for this, I don't think anything beats `` {{ `shards version #{__DIR__}`.chomp.stringify }} ``
<FromGitter> <straight-shoota> retriable looks nice
<FromGitter> <straight-shoota> but I'm overwhelmed by the features. This looks quite complicated for such a simple tool.
<FromGitter> <straight-shoota> I know, you don't have to use anything if you don't need it. But I think the API could probably be simplified without compromising most use cases
<FromGitter> <straight-shoota> Did you consider suggesting this for the stdlib?
<FromGitter> <bararchy> I would really love a retry
<FromGitter> <Sija> @straight-shoota true that, exponential backoff adds quite a bit of settings, yet as you noticed, none of them is actually required (maybe except `times` to escape endless loop)
<FromGitter> <Sija> I did, yet there was resistance to that idea
<FromGitter> <bararchy> I really missed `retry` when moving to Crystal
<FromGitter> <bararchy> there was an issue with ... unwinding ? or something like that
<FromGitter> <straight-shoota> is it times or max_attempts?
<FromGitter> <straight-shoota> the README is inconclusive
<FromGitter> <Sija> @straight-shoota see
<FromGitter> <Sija> it’s both
<FromGitter> <Sija> imho `retry times: 10 { … }` reads better than `retry max_attempts: 10 { … }`
<FromGitter> <straight-shoota> I don't see any opposition in
<FromGitter> <straight-shoota> the issue
<FromGitter> <straight-shoota> as long as it doesn't need an additional language feature
<FromGitter> <straight-shoota> but your shard is essentially doing the same as the suggestion from @lbguilherme just with a bit extras around it
<FromGitter> <straight-shoota> I think most people would really welcome having a consolidated implementation of your shard in the stdlib 👍
<FromGitter> <Sija> that’s right, @lbguilherme’s snippet was my starting point
<FromGitter> <Sija> I’ll update the issue with this suggestion, let’s see
<FromGitter> <Sija> still, it’s sth tad different than Ruby’s `retry`
<FromGitter> <straight-shoota> of course
<FromGitter> <straight-shoota> but IMO it's even better
rohitpaulk has joined #crystal-lang
<FromGitter> <straight-shoota> however, a nice addition would maybe if it wouldn't just work with exceptions but you can retry until some condition matches
<FromGitter> <Sija> I was just thinking about that :)
<FromGitter> <straight-shoota> yes
<FromGitter> <Sija> I’m very fond of that lil’ addition too
<FromGitter> <straight-shoota> Or maybe even simpler: ⏎ ⏎ ```retry_until condition_matched? { ... }``` ⏎ ⏎ That would require a macro, though []
<FromGitter> <Sija> looks sweet! for the time being I wanted to stay away from macros but I’ll add it to TODO list
<FromGitter> <Sija> it’s certainly more pleasant (& performant) to use than passing a `Proc`
<FromGitter> <straight-shoota> yeah of course, this would be an extra feature
<FromGitter> <straight-shoota> but it should be kept in mind that it's not necessarily limited to exceptions
<FromGitter> <straight-shoota> I think using a strategy pattern for the backoff times would help simplify the API
<FromGitter> <straight-shoota> most use cases will probably be fine with the defaults, but if you need something else, just pass in an enumerable or proc that returns the backoff times to use
<FromGitter> <straight-shoota> and maybe provide some default strategies
<FromGitter> <Sija> that makes sense
<FromGitter> <Sija> as long as there’s an `Iterator(Time::Span)` returned...
<FromGitter> <Sija> since we don’t know the total number of retries it’s impossible to return a finite array
<FromGitter> <straight-shoota> in that case, array.size would just be max_retries
<FromGitter> <Sija> which might be `nil`
<FromGitter> <Sija> that’s the catch - you might `retry` as long as you wish (technically up to `Int32::MAX`)
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter> <Sija> OTOH, all of it could be done with `loop` alone,
<FromGitter> <Sija> meh, time for breakfast
<FromGitter> <Sija> @RX14 /nitpicking allert!/ docker tag list would look bit moar readable if *someone* could cleanup those stray `nightly-YYYYMMDD[-build]` tags :)
ryan_ford has quit [Ping timeout: 246 seconds]
<RX14> I don't have access to that
<FromGitter> <straight-shoota> @Sija true. But then you'd also have to put in a backoff time
<FromGitter> <straight-shoota> at least than it makes sense to put this pattern in a reusable tool
<FromGitter> <Sija> yup, agreed
Papierkorb has joined #crystal-lang
ryan_ford has joined #crystal-lang
<lvmbdv> anyone working on an IPFS implementation in crystal?
<lvmbdv> i wish i had the spare time to do it
<FromGitter> <bararchy> And... 1h to create a parser for the HAR format :)
<FromGitter> <bararchy> enjoy if you need it
bonemind has joined #crystal-lang
Papierkorb has left #crystal-lang ["Konversation terminated!"]
duane has quit [Ping timeout: 264 seconds]
ragmaanir has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<crystal-gh> [crystal] RX14 closed pull request #5628: Fix URI encoding in StaticFileHandler#redirect_to (
duane has joined #crystal-lang
<ragmaanir> hi, is it possible to supply lambdas to a constructor so that self is rebound? i know that a passed block can be rebound via 'yield with self', but is it possible with lambdas so one can have multiple lambdas passed in that have self rebound?
<FromGitter> <yxhuvud> No.
<ragmaanir> damn :-/
<FromGitter> <straight-shoota> why would you need that?
<ragmaanir> to get rid of the repeated parameter. or is there an other way to rebind self in a lambda? maybe i am confusing something ...
<RX14> no
<RX14> there's no way
<ragmaanir> ok
<RX14> rebinding self is a pretty crazy feature anyway
<ragmaanir> why?
<RX14> what other language have it?
<RX14> ok, statically-typed languages
<ragmaanir> ^^ yeah, i dont know an statically typed ones, only dynamically typed ones
<Groogy> I think D let's you in a very hacky way reset the context
<Groogy> but it's really... eh not a stable thing to do
<Groogy> at least didn't use to be
<ragmaanir> why? i dont really see why this is bad.
<RX14> it's pretty magic
<ragmaanir> i mean, maybe it is semantically impossible or so, but i dont think so atm.
<RX14> suddenly you're calling methods that the caller thinks doesn't exist
<RX14> it's only useful for magicing DSLs
<ragmaanir> hm, not sure. my example would be something like this:
<RX14> at the end of the day it's not a big deal if the block has to do instead of just bar
<ragmaanir> yes, but it can become pretty repetitive in some cases
wdtxung has joined #crystal-lang
wdtxung has quit [Client Quit]
<RX14> yeah but don't overuse it
<RX14> i've never used `with self`
<RX14> ever
<ragmaanir> i have used it, but only in rare cases. its certainly a more exotic feature.
<travis-ci> crystal-lang/crystal#502ef40 (master - Fix URI encoding in StaticFileHandler#redirect_to (#5628)): The build passed.
<DeBot> ( Fix URI encoding in StaticFileHandler#redirect_to )
<RX14> yeah
<RX14> well we don't have it right now
<RX14> I think ary wanted to remove with self but I doubt that'll hapen
<RX14> and I also kinda doubt that it'll happen re:proc either
<FromGitter> <yxhuvud> I like having with self. Instance_exec is about the only runtime (as opposed to class definition time) meta programming I use in Ruby, and with self solves the same issue. It allows *clean* declarative DSLs like
<FromGitter> <greenbigfrog> I've currently got the following code: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ What's the best way, if I only directly want to do a #from_json on User by just taking the first User out of the UserArray? []
That_Guy_Anon has joined #crystal-lang
<jhass> best as in most performant or least code?
<FromGitter> <greenbigfrog> doesn't rly matter that much
<FromGitter> <greenbigfrog> best way as in, not some weird hacky way my stupid mind comes up with
<jhass> then just parse the entire thing and #first afterwards
<jhass> and maybe not use Set but Array if order is any important
<FromGitter> <greenbigfrog> Wdym with parse?
<FromGitter> <greenbigfrog> And when should I use a Array and when a Set?
<FromGitter> <greenbigfrog> ah. I think you meant sth like `UserArray.from_json(response).first`, right?
<jhass> .data.first, but yeah
<FromGitter> <greenbigfrog> ah. right... it's a struct :)
<jhass> also me personally would call it UserList instead of UserArray
<FromGitter> <greenbigfrog> Thanks 😃
<jhass> you do know the difference between Set and Array?
<FromGitter> <greenbigfrog> Set is unordered, no duplicates and uses a Hash to store stuff
<jhass> there you go, when you want any of these features use it, else stick to Array
<FromGitter> <greenbigfrog> 👍
<RX14> There's Array(User).new(PullParser, &block)
<RX14> @greenbigfrog `Array(User).from_json(json) { |user| break user }`
<RX14> it's ugly
<RX14> but it's short
<RX14> and it's fast
<RX14> and it works
<FromGitter> <greenbigfrog> oh. nice... thanks
<FromGitter> <greenbigfrog> just wondering: is there a downside to requiring the same files multiple times? (eg. `json` each time you use a json mapping)
<RX14> @greenbigfrog no
<RX14> require never requires the same file twice
<FromGitter> <greenbigfrog> ok
bonemind has quit [Quit: WeeChat 2.1]
ragmaanir has quit [Quit: Leaving]
bmcginty has quit [Ping timeout: 256 seconds]
bmcginty has joined #crystal-lang
<FromGitter> <greenbigfrog> now that I think of it, my question was kinda stupid considering crystal is compiled...
hightower has joined #crystal-lang
hightower3 has quit [Ping timeout: 264 seconds]
straight-shoota has quit [Ping timeout: 240 seconds]
straight-shoota has joined #crystal-lang
ryan_ford has quit [Quit: WeeChat 1.4]
t0nyandre has quit [Quit: Leaving]
straight-shoota has quit [Read error: Connection reset by peer]
straight-shoota has joined #crystal-lang
azur_kind has joined #crystal-lang
<FromGitter> <mlobl> Hi, is there a page for a shard wish list? I'm really enjoying Crystal and looking for something to work on as I wind down a job.
<That_Guy_Anon> ye, second
<FromGitter> <mlobl> terrific, thank you
That_Guy_Anon has quit [Ping timeout: 255 seconds]
rohitpaulk has joined #crystal-lang
return0e has quit [Ping timeout: 276 seconds]
return0e has joined #crystal-lang
<FromGitter> <straight-shoota> or take a look at the stdlib issues list:
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<FromGitter> <mlobl> thanks
<FromGitter> <greenbigfrog> why was decided that to require "" in the same path requires to do `require "./file"` instead of just `require "file"`?
That_Guy_Anon has joined #crystal-lang
Groogy has quit [Disconnected by services]
Groogy2 is now known as Groogy
<Groogy> Hey is there a way to get an UInt out from YAML?
Groogy_ has joined #crystal-lang
<Groogy> I want to be able to write a really big number that can't be negative and I have a problem with from what I can see, only Int64 is supported in the builtin interface?
<Groogy> also oddly enough 0 seems to be interpreted as "0"
<FromGitter> <faustinoaq> ^ So...
<FromGitter> <faustinoaq> is possible a REPL for crystal?
<FromGitter> <faustinoaq> I mean, a true REPL :)
<RX14> no
<RX14> the problem was never being compiled
<RX14> nobody ever said that
<RX14> the problem has and has always been the type system
<FromGitter> <faustinoaq> Oh, ok 👍
<RX14> well
<RX14> kinda
<robacarp> I think I pretty regularly hear people saying that it is because it's compiled
<RX14> it's the interaction between the two actually
<RX14> I meant nobody on the core team
<robacarp> misinformed though they may be
<RX14> the thing with crystal is that when you add more code it changes the behavior of arbitrary places elsewhere in the codebase
<RX14> because of the type inference
<RX14> and etc.
<RX14> if crystal was interpreted you could run it like ruby and "simulate" the type system on top of that
<RX14> and it would be as if it was typed
<RX14> if crystal didn't have it's "everything is a template" type system, you could make a repl for it
hightower has quit [Remote host closed the connection]
<FromGitter> <faustinoaq> RX14 What about a dual backend, I mean a crystal clon that looks and feels like crystal but is slower and interpreted with aims to be used only on development environments like a REPL?
<Groogy> wouldn't that be double the work though?
<robacarp> if the dual backend isn't generated from the baseline crystal, it's bound to bitrot and get out of date
azur_kind has quit [Remote host closed the connection]
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter> <drosehn> I'm confident it is "doable". I'm also confident it would be a huge amount of work to do it right. About as much work as writing the current crystal compiler. And given how fast the current compiler is changing, I'd bet that anyone working on a true-REPL for crystal would give up before too long.
<FromGitter> <drosehn> You're welcome to prove me wrong, as long as you do all the work... 😄
<FromGitter> <faustinoaq> 😆
duane has quit [Ping timeout: 248 seconds]
<Groogy> oh really starting to like how smooth things are starting to get with the framework ^^
<FromGitter> <faustinoaq> Groogy, 😄 D +1
<RX14> It socially wouldn't
<RX14> Actually*
<RX14> Since you can reuse the existing compiler
<RX14> What you'd do is pass the whole program through most of the existing crystal compiler
<RX14> And instead of Codegen use the existing AST in a vm
<RX14> It'd be slow as shit but who cares
<RX14> Every time you make an update youd reconstruct the AST for the whole program again
<RX14> Check it
<RX14> Then pass the diff off to the interpreter
<Groogy> O.O
<RX14> Making an interpreter with no checking (its already been done by the compiler) is far easier than making one from scratch
<FromGitter> <faustinoaq> RX14 slow but interpreted, interesting, a Crystal VM 👍
<RX14> Bonus points for just translating to ruby
<RX14> Instead of writing your own vm
<FromGitter> <faustinoaq> Oh, even more interesting! :)
<FromGitter> <straight-shoota> xD
Creatornator has joined #crystal-lang
greengriminal has joined #crystal-lang
heaven31415 has joined #crystal-lang
That_Guy_Anon has quit [Ping timeout: 240 seconds]
greengriminal has quit [Quit: This computer has gone to sleep]
t0nyandre has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<oprypin> RX14, that's an amazing idea
<RX14> is it
<RX14> i've been sitting on it for a while
<RX14> should have spoken earlier
<oprypin> (not talking about ruby btw)
<RX14> my observation is that the compiler isn't actually that slow
<RX14> and the compiler being slow isn't the problem
<oprypin> right
<RX14> you just run "half" the compiler
<oprypin> not for a 10-line repl session lol
<RX14> and then spit it into a custom VM
<RX14> yeah exactly
<RX14> even for a moderately sized application
<RX14> you should be able to do hot reload with this
<RX14> ...eventually
<oprypin> RX14, that part about "custom" - why? isnt there an LL-VM lol
<RX14> there is
<RX14> but the point of the VM is to abstract the application state away from the binary representation of the state
<oprypin> so how about passing newly added lines of LLVM IR to that?
<RX14> because the type system means that a small change means a massive change to the LLVM ir
<RX14> and any diffing algorithm to work out where in hell to resume the program from will be lost
<oprypin> is it that bad though if you don't allow reopening?
<oprypin> well that's quite a limited system then
<RX14> yes
<oprypin> but i dont see how a custom vm solves that
<RX14> then there's little point in more than ICR
<RX14> icr is uselss to me
<RX14> i'd use crystal play
<oprypin> sure
<RX14> what I want is the ability to use it as an in-program debugger
<RX14> and possibly for hot-reload
mooe has joined #crystal-lang
<heaven31415> hi
That_Guy_Anon has joined #crystal-lang
<FromGitter> <builtap_twitter> Is there a way to search the API for method/functions and not just the TOC at Any other way?
Yxhuvud has quit [Ping timeout: 240 seconds]
Yxhuvud has joined #crystal-lang
return0e has quit []
Creatornator has joined #crystal-lang
<RX14> @builtap_twitter it's implemented in the next release
<RX14> for now you can use
<RX14> which is the documentation for the `master` branch
<RX14> so it's built using the new doc search
<FromGitter> <builtap_twitter> 👏
<FromGitter> <faustinoaq> RX14, Would be possible to use `crystal docs` to manage other type of documentation? I mean like guides and tutorials.
<FromGitter> <faustinoaq> > Any other way? ⏎ ⏎ @builtap_twitter There is as well