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
<FromGitter> <oprypin:matrix.org> erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se): fyi https://github.com/crystal-lang/crystal/issues/10575#issuecomment-817397990
<postmodern> if you assign a new Struct or Value type object to a constant, and pass that constant to a method, is it passed by value or reference?
<FromGitter> <oprypin:matrix.org> postmodern, by value
<postmodern> i noticed that Set(T) inherits from Struct. I want to create a class that acts like a Set(T), with additional methods, and pre-define various types of these sets to constants, but not have them be passed by value because that would end up copying a lot of data onto the stack.
<FromGitter> <naqvis> postmodern you can wrap `Set(T)` inside your custom class
DTZUZU_ has joined #crystal-lang
<FromGitter> <naqvis> composition is much more better than inheritance :P
DTZUZU has quit [Ping timeout: 240 seconds]
<postmodern> naqvis, i could, then maybe delegate all the set operation methods?
<FromGitter> <naqvis> yeah
<FromGitter> <naqvis> or `forward_missing_to`
<FromGitter> <naqvis> though if you want to expose a specific methods, then `delegate` would be best option
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 240 seconds]
andremedeiros has quit [Read error: Connection reset by peer]
andremedeiros has joined #crystal-lang
<postmodern> can you define the type of a *splat argument?
<FromGitter> <naqvis> not sure I understand
<postmodern> something like `def self.[](*values : Array(Char | Byte))`?
<FromGitter> <Blacksmoke16> `*values : Char | Byte`
<FromGitter> <Blacksmoke16> would ensure each arg is a char or byte
<postmodern> nice
<postmodern> also is there a method to get the UInt word form of a given Char? According to the docs Char#to_i only works if the char is ASCII. I want to support getting the integer word form of UIT16/UTF32 chars
<postmodern> er multi-byte chars. I remember crystal only supports UTF8, but I assume it's possible to have a multi-byte char?
<postmodern> er wait, Char#ord looks like what i want
<postmodern> odd that Char#ord returns Int32. I see lots of things in stdlib use Int32, when UInt32 or UInt8 might be more suitable.
<FromGitter> <Blacksmoke16> Int32 is the default because there isnt much diff than unsigned ints and prevents your from shooting yourself in the foot
<postmodern> except that most-significant signedness bit
<postmodern> *bits if it's sign-extended
<postmodern> why doesn't Set's Enumerable methods return an Array and not a new Set?
<postmodern> is this because we want to allow Set#map to return an Array containing duplicates?
<postmodern> Set#select could technically return another Set
DTZUZU has quit [Read error: Connection reset by peer]
<postmodern> also noticed some things in stdlib use Int while others use Int32?
andremedeiros has quit [Read error: Connection reset by peer]
andremedeiros has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 240 seconds]
f1reflyylmao is now known as f1refly
<FromGitter> <HertzDevil> `dup.select!`
<FromGitter> <HertzDevil> looks like lib funs don't support autocasting of symbols to lib enums
<postmodern> why can't you define methods where an argument is pinned to a literal value, and have the overloading matcher select that method based on the literals. `def do_stuff(data : String, offset : true) vs. def do_stuff(data : String)`
<FromGitter> <naqvis> can you elaborate more with examples from existing languages which support such use-case?
<FromGitter> <naqvis> i would say Crystal is already flexible enough where it doesn't require one to provide types during method declaration, while all other languages which comes with inference capability, mandates types on method definition, as that's the only thing where compiler doesn't prefer to infer types at call-site
<postmodern> naqvis, i want to have an altnernate method that returns a Hash instead of an Array if `offsets: true`. Also being able to match argument literals allows us to do really cool stuff, like what Prolog and Haskell can do.
<FromGitter> <naqvis> what's prohibiting you from using default arguments?
<postmodern> if `offset: false`, then the method shouldn't return a Hash
<FromGitter> <naqvis> `def do_stuff(val : String, offset : Bool = true)`
<FromGitter> <naqvis> method can return `Union`
<FromGitter> <naqvis> either Hash or Array
<FromGitter> <naqvis> but personally I will prefer not to go such route, as that's confusing to user of such library
<postmodern> would also be nice if the method overload matcher could match the return type, that way i could do `result : Hash = do_stuff(data)` and it would use the Hash version of the method.
<postmodern> you can't define a variable who's type is returned by another method call, can you? ex: `word : word_type(bytesize) = 0`
<postmodern> is there a constant for \n vs \r\n new-line character?
DTZUZU has joined #crystal-lang
<FromGitter> <naqvis> overloading works on argument types, not on return type
<FromGitter> <naqvis> you don't need to provide a type for variable, as it will be inferred by the compiler
<FromGitter> <naqvis> afaik there is no such pre-defined constant, but it should be easy to define one ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6073c638a9dd556843d1a77f]
dom96 has quit [*.net *.split]
_ht has joined #crystal-lang
ua has quit [Ping timeout: 252 seconds]
ua has joined #crystal-lang
hendursaga has joined #crystal-lang
hendursa1 has quit [Ping timeout: 240 seconds]
<FromGitter> <owen2345> Hey here: ⏎ could someone help me to retrieve all #local_variables from a block/method? ⏎ Ruby sample: https://ruby-doc.org/core-3.0.1/Kernel.html#method-i-local_variables ⏎ I tried with this, but no success: ⏎ ... [https://gitter.im/crystal-lang/crystal?at=60741191dc24646812b73bf6]
<FromGitter> <erdnaxeli:cervoi.se> `instance_vars` returns the type's attribute, and it must be executed in a method to works, else it returns nothing
<FromGitter> <erdnaxeli:cervoi.se> i don't know any way to get local variables
<FromGitter> <erdnaxeli:cervoi.se> I think that when macros are executed the compiler does not know local variables already (and a macro could generate new local variables)
<FromGitter> <erdnaxeli:cervoi.se> what are you trying to achieve?
<FromGitter> <owen2345> Check my comment here: ⏎ https://github.com/crystal-community/icr/issues/127
<FromGitter> <erdnaxeli:cervoi.se> hmm, yeah, I don't know how to do it without parsing the user input to detect variables declaration. Maybe the compiler expose methods to parse crystal code and get the AST?
<FromGitter> <owen2345> My final idea is to retrieve all the local variables from a block, sample: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Having this I can do the next [https://gitter.im/crystal-lang/crystal?at=607413dbdc24646812b74338]
<FromGitter> <erdnaxeli:cervoi.se> I'm afraid there is no way to do that
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Client Quit]
alexherbo2 has joined #crystal-lang
<FromGitter> <alexherbo2> how to accees low level functions, such as `statfs`? https://man7.org/linux/man-pages/man2/statfs.2.html
<FromGitter> <alexherbo2> I would like to check various information for a status line without running too many external programs
alexherbo20 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 252 seconds]
alexherbo20 is now known as alexherbo2
<FromGitter> <naqvis> afaik stdlib doesn't have one, so you should do your own FFI
hendursaga has quit [Quit: hendursaga]
hendursaga has joined #crystal-lang
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <Blacksmoke16> the easiest solution here is to not use icr :P problem solved
<FromGitter> <Blacksmoke16> just have a `test.cr` file and run it
<FromGitter> <Daniel-Worrall> icr be janky
<FromGitter> <dineshgadge> I want to load some values from a config.yml file. When I am shipping a binary, how do I load the config.yml file relative to the binary? (as opposed to the src folder)
<FromGitter> <Blacksmoke16> it would be possible to include the source of the config file in the binary
<FromGitter> <Blacksmoke16> then thats all you need to ship, but i hope you arent actually shipping the source code with the binary yea?
<FromGitter> <dineshgadge> no I am not shipping the source code ..
<FromGitter> <Blacksmoke16> good :)
<FromGitter> <dineshgadge> but I want the client to be able to change some config settings using a config file ..
<FromGitter> <dineshgadge> thanks @wyhaines .. I'll try this out ..
<FromGitter> <wyhaines> Dir.current returns the current working directory. So, something like `File.join(Dir.current, "config.yml")` will give you what you need.
<straight-shoota> @Blacksmoke16 Embedding a YAML file into the binary wouldn't be useful at all. You could just embed data directly without YAML
<FromGitter> <dineshgadge> @Blacksmoke16 let me check if pseudo constants work better for me .. or Dir.current as @wyhaines suggested
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Blacksmoke16> even if you have another build process generate the yaml file?
<straight-shoota> current directory won't help for a path relative to the executable location
<straight-shoota> @Blacksmoke16 Yeah, you can still parse it at compile time
<FromGitter> <Blacksmoke16> wait, yea thats what i meant. I.e. with `read_file`
<straight-shoota> pseudo constants are compile time values, so they don't help at all to figure out runtime paths
<FromGitter> <Blacksmoke16> couldnt you just put the config file next to the binary and do like `"./config.yml"`?
<straight-shoota> that only works when you call the executable as ./program
<straight-shoota> This is what you're looking for: https://crystal-lang.org/api/1.0.0/toplevel.html#PROGRAM_NAME
<FromGitter> <Blacksmoke16> ah fair point
<straight-shoota> It's the name of the program. If it's being called by path, you can use that path to figure out the location.
<FromGitter> <dineshgadge> does PROGRAM_NAME give you the path too?
<FromGitter> <erdnaxeli:cervoi.se> PROGRAM_NAME is exactly whath you type: `ls` => PROGRAM_PATH == "ls", `/bin/ls` => PROGRAM_PATH == "/bin/ls"
<FromGitter> <erdnaxeli:cervoi.se> erf you should read PROGRAM_NAME instead of PROGRAM_PATH
<straight-shoota> ah executable_path is even better
<FromGitter> <dineshgadge> executable_path looks promising ..
<FromGitter> <Val> Hello, apt source may have some problem:
<FromGitter> <Val> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60744c22b9e6de24d62e1d09]
<FromGitter> <Val> Ok, under maintenance https://status.bintray.com/
<postmodern> how do you mix double-splatted named tuples with literal named keyword arguments?
<postmodern> porting some ruby code that does foo(bar: bar, **options)
<FromGitter> <Blacksmoke16> pretty sure that would work
<FromGitter> <Blacksmoke16> as is
<postmodern> `subject { described_class.new(base: base, **options) }` Error: expected named argument, not **
<FromGitter> <Blacksmoke16> what happens if you do like `**options, base: base`
<postmodern> ah that worked!
<postmodern> hmm Proc doesn't respond to #[] ?
<FromGitter> <Blacksmoke16> why would it? what would that do?
<postmodern> let's you use a proc like an infinite Hash map
<FromGitter> <Blacksmoke16> 🤔 why not just use a `Hash`?
<postmodern> if all you're defining is the default block, then why not just use a Proc?
<straight-shoota> Hm, that might actually be an interesting use cas
<straight-shoota> e
<FromGitter> <Blacksmoke16> got an example?
<postmodern> Blacksmoke16, from the code I'm porting: https://github.com/postmodern/hexdump.rb/blob/bcad30d5909b9e9d9951af1f8c07e46c2b32dd17/lib/hexdump/dumper.rb#L12-L27 using a mix of Hashes and Procs to calculate string widths
<FromGitter> <Blacksmoke16> wouldnt that be like `Hash(String, Proc(Int32), Hash(Int32, Int32))`?
<FromGitter> <Blacksmoke16> sorry `|` as the value
<FromGitter> <Blacksmoke16> could maybe have another type that wraps it and defines `#[]` that checks if the value is a proc and calls it or just returns the value?
<postmodern> correct, the error i get is `Error: undefined method '[]' for Proc(UInt8, UInt8) (compile-time type is (Hash(Int32, Int32) | Proc(UInt8, UInt8)))`
<FromGitter> <Blacksmoke16> can you make a little playground example?
<postmodern> in a bit
<FromGitter> <asterite> I think adding `#[]` to Proc might be nice. If a method argument is a Hash, or quacks like a hash, making it also work with Proc is nice
<FromGitter> <asterite> It should also be really simple. Maybe you can add it yourself for now. I think `def [](*args); call(*args); end` might work
<postmodern> i guess the only difference would then be that Hash can sometimes return Nil, while Proc is usually guaranteed to return non-Nil (unless it explicitly contains an if/else branch)
<postmodern> also I noticed that IO::ByteFormat uses IO#read_fully. This prevents it from doing partial reads (i.e you're trying to convert some bytes to a uint32, but only have 3 bytes left)
<postmodern> i wonder if copying the IO::ByteFormat code which casts a buffer and reverses it based on endianness would be faster that just shifting in each byte into a word as I read them
<FromGitter> <naqvis> i guess you have a misconception on `IO::ByteFormat#decode` doing `IO#read_fully` :P
<FromGitter> <naqvis> `read_fully` will read to the size of passed buffer
<FromGitter> <naqvis> so buffer#size is that of bytesize of type you have passed
<FromGitter> <naqvis> https://carc.in/#/r/auqs
<FromGitter> <Blacksmoke16> im still confused on how adding `#[]` to `Proc` would help in that ruby example
<FromGitter> <Blacksmoke16> ohh you would do like `WIDTHS["hexadecimal"][1]` and that would do like `call(1)`
<FromGitter> <naqvis> IMO this will cause confusion to reader of the code
hightower2 has quit [Ping timeout: 268 seconds]
<FromGitter> <lebogan> 1) 0. Yes! I cross-compile for my Raspberry Pi boxex and ran into a 404 error for: https://raw.githubusercontent.com/crystal-lang/crystal/master/src/ext/sigfault.c. Where did it go? Or, is it even needed any to compile libcrystal.a?
<postmodern> naqvis, i meant the length of the input buffer, which may not be evenly divisible by the sizeof(type): https://carc.in/#/r/auqx
hightower2 has joined #crystal-lang
<FromGitter> <naqvis> that means encoding is not standard and you shouldn’t be using standard approach. instead do a custom decoding or follow the encoding approach to perform decoding
<FromGitter> <lebogan> This is my original cc command: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Crystal doesn't exist on my Pi boxes. And it seems like libcrystal.a is still needed. I'm so lost! [https://gitter.im/crystal-lang/crystal?at=607486bdb9e6de24d62ebf14]
<FromGitter> <Blacksmoke16> prob shouldn't use `master` for this reason
<FromGitter> <Blacksmoke16> use an explicit version, e.g. `1.0.0`
<FromGitter> <lebogan> I'm using 1.0.0 ⏎ When: ⏎ `crystal build src/myapp.c --cross-compile --target "armv6k-unknown-linux-gnueabihf" --reliase` yields: ⏎ `cc bin/raptor.o -o bin/raptor -rdynamic -L/usr/bin/../lib/crystal/lib -lreadline -lpcre -lm -lgc -lpthread /usr/share/crystal/src/ext/libcrystal.a -levent -lrt -ldl ⏎ ` ... [https://gitter.im/crystal-lang/crystal?at=6074884897cf5067465a40c6]
<FromGitter> <lebogan> Pardon my misspellings:(
<FromGitter> <Blacksmoke16> right, again you're using `master` which it doesnt exist anymore as it was removed
<FromGitter> <Blacksmoke16> use `1.0.0` release tag
<FromGitter> <Blacksmoke16> but in the next release you wont even need `sigfault.c` as it's now implemented in crystal
<FromGitter> <lebogan> Thank you for that clarification. I totally misunderstood your use of `master`. I get it. Thank you oh so much.
<FromGitter> <Blacksmoke16> awe, you cant use enums as a namespace?
<FromGitter> <oprypin:matrix.org> @Blacksmoke16: you can put the enum's values into a namespace though
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60748d7197cf5067465a4e6e]
<FromGitter> <Blacksmoke16> prob could just do `struct CIBuild` then `enum Provider`
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <oprypin:matrix.org> @Blacksmoke16: https://github.com/oprypin/crsfml/search?q=Util+extract
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> is the forum broken for anyone else? When i open a thread all the replies disappear 🤔. Console suggests its some issue with the service worker
<straight-shoota> works for me
<FromGitter> <Blacksmoke16> hm, let me clear cache and stuff
<straight-shoota> might be a user client issue. try remove the service worker locally
<FromGitter> <Blacksmoke16> ok interesting, only happens when im logged in
<FromGitter> <Blacksmoke16> and when using the dark theme
_ht has quit [Remote host closed the connection]
fifr has quit [Quit: ZNC 1.8.2 - https://znc.in]
fifr has joined #crystal-lang
ua has quit [Ping timeout: 252 seconds]
ua has joined #crystal-lang
alexherbo2 has joined #crystal-lang
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter> <Blacksmoke16> is it expected you can't do https://play.crystal-lang.org/#/r/auv3 ?
<FromGitter> <oprypin:matrix.org> @Blacksmoke16: ?? yes
<FromGitter> <oprypin:matrix.org> it's like `JSON = ::JSON.parse`
<FromGitter> <Blacksmoke16> makes sense :S i just made it `LOGGER = ...`
<FromGitter> <oprypin:matrix.org> @Blacksmoke16: u can do it inside a namespace ofc
<FromGitter> <Blacksmoke16> yea ofc, was on top level just wanting a named logger
<straight-shoota> I've also tried `Log = Log.for(self)` multiple times :D
hightower2 has quit [Ping timeout: 252 seconds]
hendursaga has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang