jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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
r0bby has quit [Ping timeout: 272 seconds]
r0bby has joined #crystal-lang
coderobe has quit [*.net *.split]
early has quit [*.net *.split]
coderobe has joined #crystal-lang
early has joined #crystal-lang
<FromGitter> <watzon> Ok I need to figure out a better way to handle the `encode` and `decode` methods which accept an IO. Right now I'm making a `UInt8[4096]` in both and then reading from or writing to it, but a) it seems kind of wasteful and b) it won't handle cases in which there are more than 4096 bytes (which I can't see ever happening, but it still just feels like bad practice to have an arbitrary ceiling. Any ideas?
<FromGitter> ... https://carc.in/#/r/a5dg
<FromGitter> <viraptor1:matrix.org> It's weird that you don't pass any size to libgmp... What are the expectations on the buffer size from their side?
<FromGitter> <watzon> A size gets passed in `import`, but in `export` it tells you the size
<FromGitter> <watzon> These are the docs for those particular operations https://gmplib.org/manual/Integer-Import-and-Export
<FromGitter> <HertzDevil> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fdffc7fce40bd3cdbf20f2c]
<FromGitter> <watzon> Wait, `LibGMP.export` returns a void pointer to the byte slice? I missed that
<FromGitter> <Blacksmoke16> is it expected you cant add the `@[Deprecated]` annotation to an alias?
<FromGitter> <Blacksmoke16> doesnt actually trigger
<FromGitter> <watzon> Thanks @HertzDevil, needed another set of eyes on that one
<FromGitter> <HertzDevil> you'll need to deallocate `bytes` yourself
<FromGitter> <HertzDevil> with `GC.free`
<FromGitter> <watzon> πŸ‘
<FromGitter> <HertzDevil> well maybe the gc will eventually collect it, but it shouldn't hurt
<FromGitter> <watzon> Any ideas on the `decode` method that takes an IO? I could do `IO#gets_to_end` to get a String and then get the underlying slice, but that feels dirty. It doesn't seem like the base IO class gives any access to the underlying pointer though.
<FromGitter> <watzon> Like this is the best I can think of, but it feels hacky https://carc.in/#/r/a5dw
<FromGitter> <watzon> Doing some digging into the `IO` class it looks like it has an `encoder` and `decoder` which store the actual pointer data, and those aren't publicly accessible. So idk what else to do.
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/IO.html#read_bytes(type,format:IO::ByteFormat=IO::ByteFormat::SystemEndian)-instance-method ?
<FromGitter> <naqvis> > Ali: not a bug. When you pass self in initialize the object isn't yet initialized. What if that method where you pass self accessed bar? Boom! ⏎ Thanks @asterite .
<FromGitter> <HertzDevil> `#gets_to_end` is okay, i think a bigger question is whether it's useful to always consume the rest of the io
<FromGitter> <HertzDevil> because `import` and `export` do not include the byte length in the data itself
<FromGitter> <HertzDevil> or sign, for that matter
<FromGitter> <HertzDevil> so to preserve bigints in a round trip you need at least `sizeof(LibC::SizeT)` extra bytes to represent that byte length
<FromGitter> <HertzDevil> you might tuck the sign in the most significant bit, or write/read one more
<FromGitter> <HertzDevil> now the problem is, whatever you choose it won't be a canonical byte representation of the bigint
<FromGitter> <HertzDevil> unlike the primitive integer types
<FromGitter> <HertzDevil> so defining them in `IO::ByteFormat` is actually not a good idea
sagax has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
<FromGitter> <watzon> What would the alternative be though?
Vexatos has joined #crystal-lang
<FromGitter> <watzon> I guess we could just have `BigInt.from_slice` and `BigInt#to_slice`. Idk how @asterite and the rest of the core team would feel about that though. The main thing I struggle with aesthetically there is that it would either need its own Endian enum, or it would need to use the IO::ByteFormat endian modules to differentiate the endianness. Either way it doesn’t flow well imo.
iwq has quit [Ping timeout: 265 seconds]
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 268 seconds]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
bazaar has quit [Ping timeout: 240 seconds]
bazaar has joined #crystal-lang
_whitelogger has joined #crystal-lang
HumanG33k has quit [Ping timeout: 272 seconds]
HumanG33k has joined #crystal-lang
<kevinsjoberg> Any vim-crystal maintainer around? See https://github.com/vim-crystal/vim-crystal/pull/109.
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
_ht has joined #crystal-lang
yxhuvud has quit [Read error: Connection reset by peer]
yxhuvud has joined #crystal-lang
hightower4 has quit [Remote host closed the connection]
<frojnd> Can someone help me out with building a json.. I still got some time to fiddle with crystal. I want my json to look like in this example: https://app.quicktype.io?share=ivPdBjWa8kpSO6QM42xS this tool made 2 classes but I don't know how can I add new dates, verses to the json. Any more knowladgable can take a look at this example and give me an actual example for 2 new dates, verses?
<FromGitter> <asterite> that's invalid json
<FromGitter> <asterite> where did you get that JSON from?
<yxhuvud> strictly speaking it is not invalid as the spec actually doesn't forbid key duplication, but yeah, it is probably not what is wanted.
<FromGitter> <asterite> yes, sorry, I meant it's not well modeled... nobody does it like that
<FromGitter> <asterite> you probably want an array, where each element has date and verses
<FromGitter> <jrei:matrix.org> @watzon: you're doing math; Float64 can't fit?
<FromGitter> <jrei:matrix.org> https://jsfiddle.net/8uqjtye9/
<kevinsjoberg> Is it possible to deconstruct a named tuple passed to a block?
<FromGitter> <jrei:matrix.org> **is not working?
<FromGitter> <asterite> not possible
<FromGitter> <Uzay-G> Hi, if I have a class with two instance variables, and I want to basically add a method to it called `match` that either uses instance var 1 or var 2, is there a nice way to do that or should I just pass a boolean like `use_var1` or `use_var2`?
<FromGitter> <jrei:matrix.org> hum, have they the same time?
<FromGitter> <jrei:matrix.org> and, not possible to use two methods?
HumanG33k has quit [Ping timeout: 260 seconds]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Max SendQ exceeded]
<FromGitter> <Uzay-G> hm ig i could do that ye using some macro or smth would probably be ugly
HumanG33k has joined #crystal-lang
<raz> if you think something's supposed to hurt, you're less likely to notice if you're doing it wrong. ;)
holst has joined #crystal-lang
<holst> I feel stupid, but after initializing a new app I am presented with a skel file that outlines a Module, all good,
<holst> but where do I put a function?
<FromGitter> <Blacksmoke16> doesnt it have a comment that says like `# put code here`?
<FromGitter> <Blacksmoke16> yea, `# TODO: Put your code here`
<FromGitter> <Blacksmoke16> within the module
<holst> Error: undefined method 'sqr' for Docker::Deploy:Module
<FromGitter> <Blacksmoke16> can you share the code?
<holst> the code for sqr is simply: def foo x \n x*x \n end
<FromGitter> <Blacksmoke16> but the method is called `foo`?
<FromGitter> <Blacksmoke16> also pretty sure method arguments need `()`, i.e. `def foo(x)`
<holst> the problem is that it is not a method its not defined in a class
<holst> (potentially)
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/cr
<holst> I just assumed I could define functions in the Module itself?
<FromGitter> <Blacksmoke16> can you make an example?
<FromGitter> <Blacksmoke16> ah ok, try doing `def self.sqr`
<FromGitter> <Blacksmoke16> when calling it within the module itself its looking for a method in the scope of the module, but it doesnt find it. Using `self.sqr` makes it similar to a class method so its available in the module
<FromGitter> <Blacksmoke16> depending on what you're doing you can probably just do stuff outside of it, i.e. for this little testing stuff
<holst> self.sqr did not work, thankfully
<holst> (I did not like the syntax)
<holst> There should not be an Instance of a module ;-)
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a5g5
<holst> I am not sure why the skel file suggests a Module?
<FromGitter> <Blacksmoke16> it generates a template for a shard, i.e. something you is intended to be released in one way or another
<FromGitter> <Blacksmoke16> i.e. its a good practice to namespace your code to avoid conflicts with other types of that name
<holst> defining sqr outside the module works
HumanG33k has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> right, it looks for it in the module scope, doesnt find it, so then checks the top level
<holst> Sure thing, but I am not sure its a good idea if it makes the barrier for newbies harder, not being able to trivially define a function is not good
<holst> is it wrong to have the "main" code inside the module body?
<FromGitter> <Blacksmoke16> if all you're wanting to do with Crystal is mess around with it for learning purposes, you can just create a file called `app.cr` and just define everything in that file w/o needing a module or anything
<holst> where should I put the code I usually put inside my __main__.py file
<holst> I should write a blog later, "Crystal lang for Python programmers" ;-)
<raz> holst: not wrong but i think rather uncommon. you probably want a class inside your module (or just make the module a class if you don't need an outer namespace)
<FromGitter> <Blacksmoke16> lets take a step back, are you planning on releasing this code as a shard?
<FromGitter> <Blacksmoke16> or just messing around for learning purposes?
<FromGitter> <HertzDevil> > There should not be an Instance of a module ;⁠-) ⏎ ⏎ that's not what `self.sqr` means though
<holst> I am not sure what a shard is, I am making an application, CLI application. I do not expect to expose any library like functionality (yet)
<holst> I am using shards though
<FromGitter> <Blacksmoke16> a shard is like a python package
<FromGitter> <Blacksmoke16> like an external dependency and/or something you can install via pip
<holst> even if its just a CLI application with no API per se?
<FromGitter> <Blacksmoke16> yea, i assume you used the `app` option when generating the project?
<holst> yes, I did use the app template
<FromGitter> <Blacksmoke16> perfect
<FromGitter> <Blacksmoke16> in that case `app` projects arent something that is used as a dependency. However the app itself is still a shard, i.e. has a version, dependencies of its own etc
<FromGitter> <Blacksmoke16> given you're making a CLI
<raz> yup, cli building, option parsing etc. is a science in itself
<raz> if you're only starting out then i'd suggest to defer that part to a bit later until you understand the language better (the type coercion etc. in most opt parsers tends to be a bit more on the advanced side)
<FromGitter> <Blacksmoke16> going back to your question, the code would go in the file that matches your app name
<FromGitter> <Blacksmoke16> i.e. `src/my_app.cr`
<FromGitter> <Blacksmoke16> *how* exactly to structure things is kinda up to you. However for CLI related things I think the general agreement is its better to have your main file for the actual domain logic and a dedicated one for the CLI part of it
<FromGitter> <Blacksmoke16> https://github.com/crystal-ameba/ameba/tree/master/src like how there is `ameba.cr` then `cli.cr` that defines the CLI, requiring the main file
<FromGitter> <Blacksmoke16> some people also like to have another directory under `src` that holds all the logic, with the main file just requiring all of it
<holst> "extend self" seems to be what I was missing
<FromGitter> <Blacksmoke16> thats essentially syntactic sugar to just doing `def self.name`
<holst> Docker::Deploy.run works if I have it, so thats good. I just needed to wrap all the code in a function (or Module method)
<holst> thanks a lot guys for the help
<FromGitter> <Blacksmoke16> "all the code", is this cli like a 1 command thing or something?
<holst> yes ;-)
<holst> its basically one command missing from the Docker CLI
<FromGitter> <Blacksmoke16> i feel like it would have been easier to write a bash script :p
<holst> i already have a python code that works, I am redoing it in crystal just to learn
<FromGitter> <Blacksmoke16> πŸ‘ fair enough
<holst> thats how I started, docker cli, jq and shell script
<FromGitter> <Blacksmoke16> should checkout `oq` πŸ˜‰
<holst> the docker config uses yaml but the API uses json
<holst> ( I am only touching the API so far )
<holst> but I just saw oq. another tool in this space is gron
<holst> "Greppable JSON"
<FromGitter> <Uzay-G> @holst I just wrote a very simple little tool in crystal that acts as cli, maybe it can help you (I'm very much of a crystal noob though πŸ˜‚ ). This is the main file: https://github.com/Uzay-G/garret/blob/main/src/garret.cr
<FromGitter> <Morantron> hi! any tips on how to distribute a CLI made with crystal? ideally a static binary for linux and OSX thorugh github releases
<FromGitter> <erdnaxeli:cervoi.se> you can compile a static build like this: https://github.com/erdnaxeli/docker-companion/blob/main/Makefile#L17
<FromGitter> <erdnaxeli:cervoi.se> you need to do it inside docker, to use Alpine and musl
<FromGitter> <Blacksmoke16> the homebrew section isnt 100% accurate anymore. It got added to core so is much easier now :p
<FromGitter> <erdnaxeli:cervoi.se> iirc OSX does not support static binary
<FromGitter> <Blacksmoke16> right
<FromGitter> <Blacksmoke16> brew is the easiest way for mac
<FromGitter> <Blacksmoke16> i sadly deleted the other repo so lost the cheatsheet :(
<FromGitter> <jrei:matrix.org> erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se): OSX? That's so old school, we are now at macOS 11
<FromGitter> <Blacksmoke16> wait what
<FromGitter> <Blacksmoke16> omg i never noticed the `X` just stands for version 10 πŸ˜†
<FromGitter> <erdnaxeli:cervoi.se> same ^^'
<FromGitter> <Blacksmoke16> i thought that was just what they called it
<FromGitter> <HertzDevil> well what do you think came after macos 9
<FromGitter> <Blacksmoke16> could be like windows and jump from 8 to 10
<FromGitter> <rukkiddo> > omg i never noticed the `X` just stands for version 10 πŸ˜† ⏎ ⏎ lol as a linux guy I also had no idea
<FromGitter> <jrei:matrix.org> `X` stands for "forbidden to use"
woodruffw has quit [Ping timeout: 240 seconds]
<straight-shoota> well version 10 was running for almost 20 year
<straight-shoota> so the version became a natural component of the OS name
HumanG33k has joined #crystal-lang
<FromGitter> <Morantron> what got added to the core?
<FromGitter> <Blacksmoke16> `oq`, so i deleted my homebrew tap that had the bottling instructions :/
<holst> this would be a cool syntax?
<holst> with object:
<holst> foo = .get "foo"
<holst> bar = .get "bar"
<holst> is there some way to do this in Crystal already?
<holst> the object is a deeply nested object method so its a lot of typing and just obfuscates the code to have it typed out on multiple lines
<FromGitter> <Blacksmoke16> not sure i follow
<holst> I guess you could do x = object and do foo, bar = x.get "foo", x.get "bar"
<FromGitter> <jrei:matrix.org> yes
<FromGitter> <Blacksmoke16> i mean if its an object why not have getters for them? `object.foo` `object.bar`?
<FromGitter> <jrei:matrix.org> tap is another solution
<holst> its object.subobject.deepstate
<holst> so its a lot of typing at best
<FromGitter> <Blacksmoke16> does something like that exist in python?
<holst> there is a "with" construct which does a little bit more than just being syntax sugar
<holst> with open('foo') as f:
<holst> lines = f.readlines()
<holst> so the object returned by open('foo') will be named 'f' in the 'with' scope
<FromGitter> <Blacksmoke16> how does that apply to the "access deep property on an object" tho?
<holst> but it only works for things that are defined as "Context" objects. I just want to have syntax sugar to avoid typing
<FromGitter> <Blacksmoke16> ```object.tap do |o| ⏎ o.foo ⏎ end ``` [https://gitter.im/crystal-lang/crystal?at=5fe0da024eba353cdfeeb054]
<FromGitter> <jrei:matrix.org> in Crystal/Ruby this is blocks
<straight-shoota> the most important property of `with open('foo') as f:` is that is ensures to release the open file descriptor after the block is left
<straight-shoota> in Crystal, this works pretty much the same
<straight-shoota> `File.open("foo") do |f| f.read_lines end`
<FromGitter> <Blacksmoke16> or event just `File.read_lines("foo")` πŸ˜‰
<FromGitter> <Blacksmoke16> even*
<FromGitter> <jrei:matrix.org> with is like begin/rescue
<FromGitter> <jrei:matrix.org> begin/ensure
<holst> straight-shoota: I agree that its greatest value is not in the reduced typing effort ;-)
deavmi has quit [Ping timeout: 264 seconds]
deavmi has joined #crystal-lang
<raz> python kinda follows a "worse is better" language design. i prefer crystals' "better is better".
deavmi has quit [Ping timeout: 264 seconds]
<FromGitter> <drum445> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe0e19eac9d8e7463c30931]
<FromGitter> <drum445> what am I supposed to do with that please, doesn't tell me what line in my code is throwing it?
deavmi has joined #crystal-lang
<FromGitter> <erdnaxeli:cervoi.se> what is your code?
<FromGitter> <drum445> there's a lot of code
<FromGitter> <erdnaxeli:cervoi.se> what is the line failing
<FromGitter> <erdnaxeli:cervoi.se> you should use `--error-trace` btw
<FromGitter> <drum445> I did
<FromGitter> <Blacksmoke16> looks like your array can contain a bool and you're trying to compare that with a int32
<FromGitter> <Blacksmoke16> er `current` is an int32 and `end_value` could be an array of bools
<FromGitter> <drum445> hmm, interesting. Thanks I'll check for it. No way to get the line no out that is throwing it?
deavmi has quit [Ping timeout: 272 seconds]
<FromGitter> <Blacksmoke16> id just look for a place you're using a range?
<FromGitter> <jrei:matrix.org> raz: is there a language, worse is worse? πŸ˜„
<oprypin> Rust
<raz> rust ain't bad, just super low level
<FromGitter> <jrei:matrix.org> I like languages experimenting and bringing new features, not just syntax
<raz> i could see a world in which rust is used for kernels, drivers and such. and crystal for the rest
<FromGitter> <jrei:matrix.org> Even if the experiment fails :/
deavmi has joined #crystal-lang
<FromGitter> <jrei:matrix.org> Also Rust is complex, which makes it a lot harder to implement a compiler for a custom micro-controller
<oprypin> i thought carefully what "worse is worse" means. really it's similar to "better is better" but you can do a special spin on it
<FromGitter> <jrei:matrix.org> What apects? Compile times?
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
<FromGitter> <watzon> Ok can someone help me figure out where this 194 byte is coming from? https://carc.in/#/r/a5ky
<FromGitter> <watzon> Feels like some witchcraft is happening
<oprypin> watzon, this shouldnt be a String.build btw. you're working with bytes, not text
<oprypin> and the byte, that's probably a utf-8 continuation mark?
<FromGitter> <watzon> I've done the same with IO::Memory as well, I get the same result
<FromGitter> <watzon> The byte in question looks like this `Γ‚`
<FromGitter> <watzon> I wonder if the `.chr` was making things weird though. Ended up just doing it with an Array and a while loop and I got the correct result.
<oprypin> watzon, im telling you again, it's the fact that you're involving a unicode string
<oprypin> "The byte in question looks like this `Γ‚`" - bytes don't look like anything FYI, purely a number
<FromGitter> <lodenos> Hey The Community <3 ⏎ Sunday I’ve speak about the macro for get the code and send at a worker ⏎ I would do something like this project in Python Dask https://dask.org ⏎ Do u know if something already in Crystal yet ? ⏎ If not I would contribut for doing the same thing in Crystal, Because I need this kind of technology in Crystal β€˜cause I use Crystal in Production for my Client
hightower2 has joined #crystal-lang
<oprypin> using an array is correct. io::memory would also work, just do `to_slice`, not `to_s`
<oprypin> oh also use `write_byte`. `chr` must not be involved because we're not working with text here! @watzon
<straight-shoota> yep, `str << b` calls `Char#to_s` which writes the char UTF-8 encoded
<oprypin> >> 222.chr.to_s.to_slice
<DeBot> oprypin: # => Bytes[195, 158] - https://carc.in/#/r/a5lm
<oprypin> is the reason for "extra" bytes in your example
<straight-shoota> 140.chr is unicode code point U+008C with UTF-8 encoding c2 8c that is `[194, 140]`
<holst> I have a fairly large structure (or object) that I would like to compare, with a few exceptions to a pair of fields that are always unique and should be ignored
<holst> I cannot do s1 == s2 but rather I would need to do filter(s1, condition on method name) == filter(s2, ...)
<oprypin> holst, can u `def ==` on it?
<holst> its part of a library so all bets are off if I redefine a global method, but maybe locally?
<oprypin> nvm then :/
<oprypin> yea u can write a macro based on https://crystal-lang.org/api/master/Crystal/Macros/TypeNode.html#methods:ArrayLiteral(Def)-instance-method
<hightower2> Folks what's an elegant way to delete the oldest half of keys in a hash?
norflow has joined #crystal-lang
<holst> oprypin: looks like I could use "#methods" but I do need to include something to make it work?
<holst> I cannot use c1.methods, (undefined method "methods")
<frojnd> asterite: I fixed that json I was away let say I have an array of fruits: https://app.quicktype.io?share=jgz7cXY8n8FroBSAVGPT how can I add new fruit to the list? https://carc.in/#/r/a5lo
<frojnd> And let's presume there is no json at all I want to build one like in comment or first link
<frojnd> I just have data for names, colors and prices...
<holst> lodenos: "I use Crystal in Production", not yet a popular T-shirt ;-)
woodruffw has joined #crystal-lang
<frojnd> Or anyone else willing to give me and actual example how to create json?
<oprypin> holst, `{% for m in TheType.methods %}`
<frojnd> oprypin: I meanat for carc link I pasted... I looked at that doc before but I don't seem to get it... I still don't know how can I create desired json I pasted in url above
<oprypin> frojnd, [Fruit.new(.......)].to_json
<frojnd> oprypin: ok that's one fruit.. let say I have many.. how can I add afte rthe firs Fruit.new ?
<frojnd> Let's presume I'm in the loop and I would like to add one by one...
<oprypin> arr << Fruit.new
<oprypin> before that you need: arr = Array(Fruit).new
<frojnd> And at the end just to_json ?
<oprypin> ye
<frojnd> It expects only one argumen: `Fruit.new(pull : ::JSON::PullParser)`
<frojnd> Do I have to wrap propertis in some kind of json structure?
<oprypin> frojnd, https://carc.in/#/r/a5lt
<frojnd> oprypin: oh thank you forgot about initializers!
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Object.html#def_equals(*fields)-macro posssibly helpful
<FromGitter> <jrei:matrix.org> @watzon: may be useful for you, crystalizer allows to (de)serialize structs from/to bytes
<frojnd> oprypin: do you think using structs in this case would be better?
<frojnd> oprypin: as in faster?
<FromGitter> <Blacksmoke16> are you ever going to want to change a property's value after creating it?
<FromGitter> <Blacksmoke16> if yes, then use a class, if no, use a struct
<oprypin> frojnd, i've been using structs and i was fine
<FromGitter> <jrei:matrix.org> if you creates and "trash" a lot, yes
<FromGitter> <jrei:matrix.org> @Blacksmoke16 is right immutable -> Struct
<FromGitter> <watzon> @j8r that's awesome actually. Might find a use for it.
<FromGitter> <jrei:matrix.org> personally, I use it for my game: https://github.com/j8r/js-byte-format + https://github.com/j8r/crystalizer
<FromGitter> <jrei:matrix.org> impressive how little data vs regular JSON. Being non destrictive + bytes saves a lot
<Andriamanitra> wouldnt classes be better if you're passing them around a lot even if immutable (since they're passed by reference)?
<oprypin> mostly depends on the size of the struct. this one is small.
<FromGitter> <jrei:matrix.org> theoretically, yes. However, I was not able in benchmarks to see a clear difference
<FromGitter> <jrei:matrix.org> also @watzon, note that you can JSON -> Struct -> Bytes seamlessly, or opposite. JSON can be replaced with YAML ;)
<FromGitter> <jrei:matrix.org> For your issue about BigInt, I'll try to find what's the format of BigInt bytes in JS (DataView type)
<FromGitter> <jrei:matrix.org> I found it. This is just Int64 bytes
norflow has quit [Ping timeout: 256 seconds]
<frojnd> Can I have optional params inside initialize?
<oprypin> frojnd, definitely
<FromGitter> <Daniel-Worrall> yeah, just `def init(optional = nil)`
<oprypin> frojnd, you really should read the whole reference, particularly for this question it's this https://crystal-lang.org/reference/syntax_and_semantics/default_values_named_arguments_splats_tuples_and_overloading.html
_ht has quit [Remote host closed the connection]
<FromGitter> <Daniel-Worrall> I really wish the reference had better search
<FromGitter> <Daniel-Worrall> It's like it only indexes headers
<oprypin> Daniel-Worrall, thats not true, it indexes all text
<oprypin> Daniel-Worrall, e.g. try searching the word "formal"
<FromGitter> <Daniel-Worrall> odd, I've always had bad results from certain searches
<FromGitter> <Daniel-Worrall> I'll try reporting here next time it happens
<frojnd> oprypin: yeah thank you reading it up to bottom
<oprypin> Daniel-Worrall, was it before or after the redesign?
<FromGitter> <Daniel-Worrall> both
<FromGitter> <Daniel-Worrall> I know a generic report like that is a bit unhelpful, so I will definitely come back when/if I find it happening again
<FromGitter> <Daniel-Worrall> Would it be stdlib appropriate to have some sort of Range Set type?
<FromGitter> <Daniel-Worrall> aka interval graph
<oprypin> Daniel-Worrall, no, never seen it in any lang
<FromGitter> <Daniel-Worrall> We could do with some good math libs in the ecosystem
kevinsjoberg has quit [Ping timeout: 244 seconds]
kevinsjoberg has joined #crystal-lang
<FromGitter> <Daniel-Worrall> Can we get a `Set(T)#-(other : T)` so I don't have to make a set/enumerable of the single element?
<FromGitter> <Daniel-Worrall> We have `#delete` but it's not as intuitive
<hightower2> Hey let's say I have a function which accepts (*args). What's any quick way to turn the args into something uniquely identifiable, like something suitable for use in a cache key? I don't care about the form of it, can be anything.
<FromGitter> <Blacksmoke16> args.hash?
<hightower2> just thought of it as I wrote the question. Let me check how that'd work
<hightower2> hm, seems like it would.. awesome, thanks
<FromGitter> <Daniel-Worrall> oprypin, example `while` gives 0 results
<Andriamanitra> i've noticed that too, it seems as if queries with too many dont show any at all, even if they would be in the title of a page
<holst> whats wrong with this macro? https://play.crystal-lang.org/#/r/a5my
<FromGitter> <Daniel-Worrall> The macro needs to be a self contained valid crystal snippet
<FromGitter> <Daniel-Worrall> You need to wrap the all_methods in {% begin %} {% end %}
<holst> jackpot that was it thx Daniel
<holst> btw, is there a way to use space to delimit the elements in a tuple instead of ","? i think i saw something like qw/foo bar/ to make {"Foo", "Bar"}?
<FromGitter> <Daniel-Worrall> It's mentioned in the macro pitfalls https://crystal-lang.org/reference/syntax_and_semantics/macros/index.html#pitfalls
<FromGitter> <Daniel-Worrall> damn you Blacksmoke, I was just on it
<FromGitter> <Daniel-Worrall> Percent literals are neat
<holst> @daniel I actually read that but I did not read it carefully enough ;-) (or I just did not get it)
<FromGitter> <Daniel-Worrall> When in doubt, reread the reference section for the topic you're trying
<FromGitter> <Daniel-Worrall> If it's not clear, maybe make a doc improvement suggestion
<holst> It makes the macro a bit nicer to read, using %w( .. )
<holst> Except, it seems %w expands to a macro variable
<holst> I'll dig on it tomorrow. https://play.crystal-lang.org/#/r/a5n4
<FromGitter> <Daniel-Worrall> you probably want to `#join` those with `,`
<FromGitter> <Daniel-Worrall> oh wait
<FromGitter> <Daniel-Worrall> I misread
<holst> slight rewrite, this works. https://play.crystal-lang.org/#/r/a5na :)
<FromGitter> <Blacksmoke16> why not just use `==` overload?
<oprypin> [20:49:19] <holst> I have a fairly large structure (or object) that I would like to compare, with a few exceptions to a pair of fields that are always unique and should be ignored
<oprypin> [20:49:55] <holst> I cannot do s1 == s2 but rather I would need to do filter(s1, condition on method name) == filter(s2, ...)
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> okey dokey
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a5nl ?
<oprypin> [20:50:14] <oprypin> holst, can u `def ==` on it?
<oprypin> [20:51:21] <holst> its part of a library so all bets are off if I redefine a global method, but maybe locally?
<FromGitter> <Blacksmoke16> > redefine a global method ⏎ ⏎ πŸ€”
<oprypin> probably meant monkeypatching
<oprypin> or thought that `==` is defined globally, not inside a class
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a5np was going to say this is also an option
sorcus has quit [Ping timeout: 272 seconds]
sorcus has joined #crystal-lang
kevinsjoberg has quit [Ping timeout: 268 seconds]
melthelesbian has quit [Ping timeout: 264 seconds]