ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | 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
ur5us has quit [Quit: Leaving]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
walez has joined #crystal-lang
walez has quit [Client Quit]
ur5us has joined #crystal-lang
hightower3 has quit [Ping timeout: 248 seconds]
ur5us has quit [Ping timeout: 260 seconds]
jmdaemon has quit [Ping timeout: 248 seconds]
Sankalp has quit [Ping timeout: 252 seconds]
hightower2 has joined #crystal-lang
Guest96 has joined #crystal-lang
<Guest96> hello all, how far do u think crystal is to being able to use arrays and hash with dynamic types without using unions? (if its in the roadmap), i love crystal btw
<FromGitter> <Blacksmoke16> I don't think that's on the roadmap. Crystal is a typed language so they have to be typed with something
<FromGitter> <Blacksmoke16> What's your use case?
hightower2 has quit [Ping timeout: 260 seconds]
Guest96 has quit [Quit: Client closed]
<FromGitter> <moe:busyloop.net> fwiw i've found https://github.com/Sija/any_hash.cr very pleasant to work with mixed type hashes. ⏎ perhaps something similar could make it into stdlib at some point.
<FromGitter> <Blacksmoke16> id argue against it. feels like a bit of a code smell people would use just so they dont have to think about typing
<FromGitter> <Blacksmoke16> prob fine for smaller/one-off apps/scripts tho
<FromGitter> <moe:busyloop.net> i consider that a good thing. removes a truckload of boilerplate that serves no purpose other than making the code harder to read (and minimally faster, but by a margin that most people don't care about in most cases).
<FromGitter> <Blacksmoke16> at that point just use Ruby? sacrificing the type safety for convenience
<FromGitter> <Blacksmoke16> hashes with large unions is a pain to work with for sure, but to me thats just a sign i need to take a step back and think about things. like move the data into objects and just store those in the hash, etc
<FromGitter> <moe:busyloop.net> you don't lose type-safety, you still have to tell it `as_s` and such when you access the elements. ⏎ the advantage is that you have to be explicit in fewer places and even retain the safety in places where it's inferred.
<FromGitter> <Blacksmoke16> wouldnt you lose it on inserts?
<FromGitter> <moe:busyloop.net> true, in some areas you might. in practice i've never had a problem with that.
<FromGitter> <moe:busyloop.net> was def a price worth paying for not having to deal with nested unions or object trees like you mentioned.
<FromGitter> <moe:busyloop.net> e.g. i've used it to dynamically build up swagger json blobs. ⏎ building such with any_json is trivial. when you look at the swagger-shards on github that ⏎ do it the traditional way (one class per node-type) it's a nightmare.
<FromGitter> <moe:busyloop.net> (literally dozens of lines vs thousands)
<FromGitter> <Blacksmoke16> yea thats fair, each has their pros and cons
<FromGitter> <moe:busyloop.net> well, it's a problem that comes up quite often in our API-driven world. ⏎ the moment you start dealing with json APIs, you are either forced to model all ⏎ their nooks and crannies as classes. or you resort to `JSON.parse` and things like `any_json`. ⏎ ⏎ i'd argue it's common enough a pattern that better support in stdlib would be nice. [https://gitter.im
<FromGitter> ... /crystal-lang/crystal?at=636bb957b1a759643663c112]
<FromGitter> <moe:busyloop.net> but i understand it goes a bit against the grain of the crystal mindest ;)
<FromGitter> <moe:busyloop.net> (and it's not my biggest gripe anyway, `any_json` works well enough for me - exception safety and usable backtraces [no ???] would be higher on my wishlist)
<FromGitter> <Blacksmoke16> key diff there is its scoped to JSON data, while hashes could be used for anything
<FromGitter> <Blacksmoke16> could create a thread/issue for it at least. i'm not sure its a good idea to make it that easy by having it in the stdlib
<FromGitter> <moe:busyloop.net> well, usually you receive the data from somewhere and then want to do something with, that's where the trouble starts
<FromGitter> <moe:busyloop.net> but yea i'm arguing to *change* Hash. just to perhaps add a more ruby-like `AnyHash` or such on top.
<FromGitter> <moe:busyloop.net> but agree, it's not a small ticket. documentation etc. would be tricky. the current `Hash` vs `NamedTuple` is already quite difficult to grasp for newbies. adding a third to the mix would make the learning curve even steeper.
<FromGitter> <Blacksmoke16> i get that yea, but my thinking is if you have an any hash built in, people would just use that for everything and not on a case-by-case basis to when it *should* be used
<FromGitter> <moe:busyloop.net> nothing wrong with that. if it's easier then you just made the language easier. :)
<FromGitter> <moe:busyloop.net> just let them know that for better type safety they can *also* go the more verbose old fashioned way
hightower2 has joined #crystal-lang
<FromGitter> <moe:busyloop.net> in some cases that's warranted. in most it's probably not. ⏎ for me type-errors usually stem from input data (JSON having `null` where `String` was expected). ⏎ ⏎ in the current way these cause a runtime error at `#from_json`. ⏎ in the new way that runtime error would move to the place where ... [https://gitter.im/crystal-lang/crystal?at=636bbcaa15a3885c70e2c092]
<FromGitter> <Blacksmoke16> no i agree that `JSON.parse` is really good for this kind of stuff. Its when its extended to basically be compatible with `Hash` that i have some reservations
<FromGitter> <moe:busyloop.net> yeh it's mostly a mindset thing. my argument on these things is always "the machine should be doing the hard work". ⏎ i'm basically a smaller, less educated version of this guy: https://www.youtube.com/watch?v=8Ab3ArE8W3s&t=402s (that's a great talk in general btw)
Guest96 has joined #crystal-lang
<Guest96> sorry gitter i got disconnected
<Guest96> i know in c you can store like void* and then recast to their type, sure could be done in crystal, its a great language
<Guest96> i use mruby in c, but when it comes to ffi you have to wrap all the functions u gonna use
<Guest96> i noticed its quite a time consumer, so i thought about store all c functions pointers in a hashmap, so i can go call("funcname",args), the get the function from the hashmap. the problem is that you loose the function signature so you have to recast it. so i noticed that id like some thing c cant provide in order to make ffi easier:
<Guest96> if i could store my arguments inside an array of wathever type, and then do call(funcname,arr_args) i would need a way to deconstruct thoses arguments automatically so that it becomes cfunc(arg0,arg1,arg2) and no need to write wrapper, just a thought but C language dont allow that
<Guest96> mainly for mruby interop, i have to go to the dentist
Guest96 has quit [Ping timeout: 260 seconds]
Guest96 has joined #crystal-lang
<Guest96> sorry fromgitter, can i pm you later?
<jmiven> Guest96: FromGitter is a bot, bridging this IRC channel with the Gitter channel
<jmiven> the actual nicknames of people talking are shown inside the angle brackets
hightower2 has quit [Ping timeout: 260 seconds]
repo has quit [Ping timeout: 246 seconds]
repo has joined #crystal-lang
alexherbo2 has joined #crystal-lang
Guest76 has joined #crystal-lang
<Guest76> ```crystal
<Guest76> struct QueueOutboundElement
<Guest76>   property test : Int32
<Guest76>   getter mutex : Mutex
<Guest76>   def initialize(@test : Int32)
<Guest76>     @mutex = Mutex.new protection: :unchecked
<Guest76>   end
<Guest76>   def lock
<Guest76>     @mutex.lock
<Guest76>   end
<Guest76>   def unlock
<Guest76>     @mutex.unlock
<Guest76>   end
<Guest76> end
<Guest76> staged = Channel(QueueOutboundElement*).new capacity: 128_i32
<Guest76> spawn do
<Guest76>   128_i32.times do
<Guest76>     staged_received_pointer = staged.receive
<Guest76>     staged_received_pointer.value
<Guest76>   end
<Guest76> Hello everyone, I have a problem, why use Channel to send pointerof(struct) will get the same struct, how should I solve it, thx.
<Guest76> Maybe where am I doing wrong?
<FromGitter> <Blacksmoke16> can you even get a pointer to stack memory?
<Guest76> Sorry, there seems to be some glitches in sending via Libera Chat, Playground: https://play.crystal-lang.org/#/r/e1dy
<Guest76> @Blacksmoke16 Sorry, I see it seems possible to do this in Golang?
<Guest76> Golang:  make(chan *QueueOutboundElement, QueueStagedSize)
<Guest76> var elem *QueueOutboundElement
<Guest76> ...
<Guest76> peer.StagePacket(elem)
<Guest76> ...
<Guest76> select {
<Guest76>     case peer.queue.staged <- elem:
<Guest76> ...
Guest76 has quit [Quit: Client closed]
Guest76 has joined #crystal-lang
<Guest76>   for {
<Guest76>     select {
<Guest76>     case elem := <-peer.queue.staged:
<Guest76>       ...
<Guest76>       elem.keypair = keypair
<Guest76>       elem.Lock()
<Guest76>       if peer.isRunning.Load() {
<Guest76>         peer.queue.outbound.c <- elem
<Guest76>         peer.device.queue.encryption.c <- elem
<Guest76>       ...
hightower2 has joined #crystal-lang
<Guest76> But it seems that pointerof(Bytes) has no problem, https://play.crystal-lang.org/#/r/e1e6
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
Guest96 has quit [Ping timeout: 260 seconds]
<Guest76> Maybe I can convert the structure to Bytes through the Channel send (pointerof(element).as(UInt8*).to_slice(sizeof(typeof(element))).dup), and then use (staged_received_pointer.to_unsafe.as(QueueOutboundElement*).value), But what about Mutex? If Mutex is added to Struct, Invalid Memory Access will appear... '=(
<Guest76> It seems that Golang does not have class, only struct, Crystal Mutex is a class... \O/
<Guest76> Crystal::RWLock, Crystal::SpinLock are also Class...
<Guest76> Maybe use class instead of struct? Maybe the performance will be lower than golang?
<FromGitter> <Blacksmoke16> you kinda me 😅. Maybe a forum thread would be a better way
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
<Guest76> @Blacksmoke16 yes, but didn't find a solution about this issue from the forum thread, so I came to IRC, I wanted to use Crystal to do something like WireGuard, but I ran into this problem and still haven't solved it after 2 days of research \O/  =$
<FromGitter> <Blacksmoke16> right, make a new thread about your issue :P
<Guest76> @Blacksmoke16 ok thanks, you are a great person, I will go to the forum to create an issue later. (y)
Guest76 has quit [Quit: Client closed]
Guest76 has joined #crystal-lang
<Guest76> Hello,
<Guest76> Our automated spam filter, Akismet, has temporarily hidden your post in Send different pointer structs through Channel and receive the same value for review.
<Guest76> A staff member will review your post soon, and it should appear shortly.
<Guest76> We apologize for the inconvenience. =$
<Guest76> Looks like it's ok now:] (y) ,
<Guest76> Send different pointer structs through Channel and receive the same value: https://forum.crystal-lang.org/t/send-different-pointer-structs-through-channel-and-receive-the-same-value/5100
<FromGitter> <Blacksmoke16> 👍 huh, never saw that before ha
Guest76 has quit [Quit: Client closed]
Guest76 has joined #crystal-lang
<Guest76> @straight-shoota, @asterite @Blacksmoke16 Thanks for yours help! Issue resolved! =*  (y)
Guest76 has quit [Client Quit]
ur5us has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #crystal-lang
Guest96 has joined #crystal-lang
<Guest96> fromgitter , where can i find informations about crystal language roadmap please ?
<Guest96> ho ok i get it lol, its a bridge not a bot sorry people
hightower2 has quit [Ping timeout: 260 seconds]
jmdaemon has joined #crystal-lang
hightower2 has joined #crystal-lang
Guest96 has quit [Ping timeout: 260 seconds]
<FromGitter> <stellarpower> Has anyone done any linear algebra etc. in Crystal? I have just had a quick play with Crystalla and num.cr. Main issue with both for me is that they whilst they provide implementations of tensors/matrices, they don't parameterise the dimensions of these at compile-time. Having done some similar work in C++ with Eigen or boost::qvm or what have you, and having been forced to work in numpy at times, it
<FromGitter> ... certainly makes things exponentially more bearable when the compiler can refuse to build code that has mathematical errors in it, in the former case. I.e. multiplying matrices with inconsistent dimensions is simply impossible, not the cause of an exception, because the code will never build. And given we have macros etc. it wou ... [https://gitter.im/crystal-lang/crystal?at=636c2e31b1a759643664ad6f]
hightower2 has quit [Ping timeout: 260 seconds]
hightower2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]