sz0 has quit [Quit: Connection closed for inactivity]
<olbat>
Hello everyone, I'm trying to figure out a solution to fix a build error that appeared after Crystal 1.x's release on one of my projects https://bit.ly/3fI6q5i . I went through a bunch of issues on the shards' project board (eg. https://github.com/crystal-lang/shards/issues/413) but I did not really find a consensus in the discussions about a solution for the issue.
<olbat>
Will you recommend to bump the `crystal` version to 1.0.0 in my project and all my dependencies? (it looks like an unnecessary constraint to me as technically theses projects worked fine with crystal < 1.x)
<olbat>
Also, if this is the way to go, do you have some plans to update projects like crystal_lib, yaml_mapping.cr, json_mapping.cr, etc. to depend on crystal > 1.x as well? (I can help out with that if it's what you want to do)
<olbat>
I'm going to give it a shot, thank you for sharing :)
<olbat>
So ">= 0.35.0" doesn't have the implicit "< 1.0.0"?
<olbat>
Nice, it looks like it doesn't :)
<olbat>
Small question for the core team: I'm planning to propose updates for shards.yml of clang.cr, crystal_lib, json_mapping.cr & yaml_mapping.cr. Should I switch the Crystal dependency declaration to ">= 0.y.z" or to "1.0.0" ?
<FromGitter>
<asterite> If it works with both versions, the first form
<FromGitter>
<erdnaxeli:cervoi.se> Hi, I have troubles building a static binary with the alpine image 1.0.0. I run `docker run --rm -it -v ${PWD}:/workspace -w /workspace crystallang/crystal:1.0.0-alpine ./build.sh` with build.sh containing β β ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=606afec20508990a25d5fae1]
<FromGitter>
<erdnaxeli:cervoi.se> ok IΒ needed `yaml-static`
<FromGitter>
<m33:nitro.chat> Hi guys, for some reason I can't find mastodon (activitypub) librairies in crystal, but I saw https://bantha.tatooine.space/@jokke/105568254068434658 ... so it seems such librairies exist. Are you aware of such libs ?
<FromGitter>
<Blacksmoke16> using a module is the ideal way when making interfaes
<FromGitter>
<Blacksmoke16> interfaces*
<FromGitter>
<djberg96> Understood, I was just trying to most closely copy the Go example
<FromGitter>
<Blacksmoke16> just because you can do more with them. I.e. include multiple modules into another module and include them into both classes and structs
<FromGitter>
<Blacksmoke16> could also combine the two. I.e. abstract parent class that includes the interface
<FromGitter>
<djberg96> yep!
<FromGitter>
<kingsleyh> Beware when using Github actions - a scammer sent a pull request to my repo that modified my Github actions config file to run a mining bot net for the cyrptocurrency Monero when the PR runs in the github actions CI. Looks like he's automated this to run like this on over 300 repos
<FromGitter>
<Blacksmoke16> without merging the PR?
<FromGitter>
<kingsleyh> yeah
<FromGitter>
<kingsleyh> the GH action runs as soon as the PR is created
<FromGitter>
<kingsleyh> the author closed it themselves immediately - probably hoping I would not spot it
<FromGitter>
<kingsleyh> because you can keep re-running it even when it's closed
<FromGitter>
<kingsleyh> also you can't delete the PR - only GH support can do that
<FromGitter>
<kingsleyh> GH support deleted the PR and the scammers account now
<FromGitter>
<Blacksmoke16> nice
<straight-shoota>
that's Github's problem, though
<straight-shoota>
And they should have mechanisms to detect such malicious behaviour
<FromGitter>
<kingsleyh> yeah - but it's annoying for this kind of PR to arrive in my repo and I can't even delete it lol
<straight-shoota>
yeah, that's true
<FromGitter>
<Blacksmoke16> and now there'll be a gap in the PR numbers :P
<FromGitter>
<kingsleyh> hehhe
<FromGitter>
<rishavs> Checking back into Crystal after a while. I have just updated to v1. But now my shards updates are failing; β β ```code paste, see link``` β β is there something that I am missing? [https://gitter.im/crystal-lang/crystal?at=606b1c4f0508990a25d645c7]
<FromGitter>
<Blacksmoke16> looks like you'll need to use `--ignore-crystal-version` or update `helmet`
<FromGitter>
<rishavs> thanks both of you!
<FromGitter>
<rishavs> I was surprised because I thought that clearly so many core libs cannot be be left un-updated for this long. Therefore, I must be doing something wrong. :/
<FromGitter>
<Blacksmoke16> helmet is like 4 years old so that doesnt surprise me :P
<FromGitter>
<Blacksmoke16> be easy enough to just define your own handler to do that versus using that dep tho
<shalokshalom>
IDK about your system, but my system does not let me launch shell scripts like described.
<shalokshalom>
bin/crystal is a shell, and altough it works with ./, it does not so with crystal --version, as shown.
<FromGitter>
<Blacksmoke16> what system are you on then?
<FromGitter>
<Blacksmoke16> the idea is you link `bin/crystal` to some dir on your PATH, then you can
hipertracker has joined #crystal-lang
<shalokshalom>
KaoS
<shalokshalom>
And I did that
<shalokshalom>
Well, maybe usr/local/bin is not in my path
<FromGitter>
<Blacksmoke16> that would do it
<shalokshalom>
Still, a text file is no binary, so I find that a bit confusing.
<straight-shoota>
That ln -s command is just an example. Do whatevery fits for you to place bin/crystal in your PATH if you want to run it as crystal
<shalokshalom>
Well, stack works from the same directory, so it is likely in here.
<shalokshalom>
I mean the --version example.
<straight-shoota>
yes
<hipertracker>
How to make Crystal Formatter working with VSCode? I'd like o run the format after every file save. It does do nothing at the moment. I have to go to the terminal and run 'crystal tool format' to do that
<FromGitter>
<Blacksmoke16> using the plugin?
<straight-shoota>
shalokshalom, yes that `crystal --version` is just to verify that the installation was successful
<shalokshalom>
Yeah, it is already in the path.
<shalokshalom>
echo $PATH
<shalokshalom>
bin:/usr/local/bin
<shalokshalom>
And stack works also from here
<straight-shoota>
ls -l /usr/local/bin/crystal
<shalokshalom>
Why could a link change the nature of the text file?
<shalokshalom>
It is already ther.e
<straight-shoota>
it doesn't, it just places it in path
<straight-shoota>
you can run the shell wrapper directly, if you want
<shalokshalom>
How could a text file be called as a binary?
<straight-shoota>
it doesn't?
<straight-shoota>
it's a shell script
<shalokshalom>
Yep.
<shalokshalom>
And shell scripts are always called with ./
<hipertracker>
The VSCode plugin Crystal Formatter does not work out of box.
<straight-shoota>
no
<shalokshalom>
Well, it does here on Linux.
<shalokshalom>
Are you on MacOS?
<straight-shoota>
linux
<straight-shoota>
it doesn't matter if an executable is a script or a binary, if it's in PATH you can run it by its name
<straight-shoota>
Idk why that doesn't work for you
<shalokshalom>
This has been explained to me like 6 years ago, as one of the first things I learned about Linux.
<shalokshalom>
I could never run shell scripts, the way you describe it.
<shalokshalom>
On no distro.
<FromGitter>
<Blacksmoke16> do you need to make it executable?
<straight-shoota>
well, I can run `echo "#! /bin/sh\necho Hello World" > /usr/bin/hello; chmod +x /usr/bin/hello; hello` on any distro, and the shell script executes
<straight-shoota>
(on some distros echo needs -e flag, but that's unrelated)
<FromGitter>
<oprypin:matrix.org> shalokshalom, yes. it's just not true what you're saying
<FromGitter>
<oprypin:matrix.org> what I ran: `echo 'echo foo' | sudo tee /usr/local/bin/foo; sudo chmod +x /usr/local/bin/foo; foo`
<FromGitter>
<oprypin:matrix.org> shalokshalom, seems that your symlink is to `'[/home/shalokshalom/Dokumente/crystal-1.0.0-1/bin/crystal]'` rather than to `/home/shalokshalom/Dokumente/crystal-1.0.0-1/bin/crystal`
<shalokshalom>
I originally did and changed this
<shalokshalom>
The [] come with the documentation and I assumed they have some hidden meaning.
<straight-shoota>
so what happens if you run /usr/local/bin/crystal directly?
<shalokshalom>
not found
<shalokshalom>
Its not a binary.
<FromGitter>
<oprypin:matrix.org> it's a broken symlink ffs
<FromGitter>
<oprypin:matrix.org> yes the fact that you thought it's some hidden meaning is the big fault of the documentation
<straight-shoota>
and `readlink /usr/local/bin/crystal`
<FromGitter>
<oprypin:matrix.org> please delete that symlink and create it anew
<FromGitter>
<oprypin:matrix.org> without square brackets now
<shalokshalom>
Yep, that works. Seems like my previous change did not get accepted, probably because I did try it from the normal user account.
<shalokshalom>
oprypin: No, its my fault. Altough its usually described without brackets and more like /add/path/here or something.
<straight-shoota>
it's because ln -s doesn't override existing links
<shalokshalom>
So shell scripts in paths get evaluated as executables
<shalokshalom>
Nice to know.
<shalokshalom>
And that works without LLVM?
<shalokshalom>
Since I am on 11 here, and I read that is not supported yet.
<FromGitter>
<oprypin:matrix.org> ? what's the relation to LLVM
<FromGitter>
<oprypin:matrix.org> oh it's a separate question
<FromGitter>
<oprypin:matrix.org> i think you'll be fine. you dont need llvm at all to use crystal. just to compile *crystal itself*. and even then llvm 11 may sometimes work
<FromGitter>
<noaheverett_twitter> even though I see the character I read into the buf and re-written back out on the client side tool I'm using to debug
<FromGitter>
<noaheverett_twitter> how can I access the string/character contained in `buf`?
<straight-shoota>
Crystal strings are immutable and have a different memory layout than C strings
<straight-shoota>
so you shouldn't use `String` for C interop
<FromGitter>
<noaheverett_twitter> @straight-shoota ok good to know, in this instance (i'm a bit over my head on low level c stuff / pointers) which should the buf type be? Ironically this code "works" as it echoes the characters I type back to me, but just not viewable in the puts line
<straight-shoota>
yeah, it works because you can pass a `String` instance to a C function, which is automatically mapped to a C char pointer by `String#to_unsafe`
<straight-shoota>
but you can't read into a String that way
<straight-shoota>
best use a `Slice(UInt8)` instead
<straight-shoota>
you can then create a Crystal string using `String.new(buf)`
<FromGitter>
<noaheverett_twitter> @straight-shoota that worked! Thank you very much. Coming from the Ruby world I'm working to get my head wrapped around Slices/Pointers etc...thank you again for the direction
<FromGitter>
<MrSorcus> > *<straight-shoota>* best use a `Slice(UInt8)` instead β β Or `Bytes`as short alias π
<FromGitter>
<noaheverett_twitter> @MrSorcus that worked too, good to know thank you!
<FromGitter>
<RespiteSage> Is carc.in working for anyone else?
<FromGitter>
<MrSorcus> @RespiteSage yeah, i can open.
<FromGitter>
<oprypin:matrix.org> @RespiteSage: it fails to run code, yea
<FromGitter>
<RespiteSage> Okay, cool. Glad to know it isn't just me.
<FromGitter>
<RespiteSage> Is there an issue that I can follow?
<straight-shoota>
jhass, carc.in seems down
_whitelogger has joined #crystal-lang
<hipertracker>
Is anybody using VSCode with working format on save for *.cr files? I can't set it up.
<FromGitter>
<riffraff169> what would be the best way to initialize an array of structs (or hash, whatever) with a bunch of static values?
<FromGitter>
<Blacksmoke16> is this array immutable?
<FromGitter>
<riffraff169> it will never change, so it could be in an external file and parsed and read in, but being in the code is no problem either
<FromGitter>
<riffraff169> yeah, basically
<FromGitter>
<Blacksmoke16> use a tuple and a const
<FromGitter>
<Blacksmoke16> if it'll never change would a tuple not be better?
<straight-shoota>
no
<straight-shoota>
why would it`
<FromGitter>
<Blacksmoke16> wouldnt the array still need memory allocated when a tuple wouldnt
<FromGitter>
<Blacksmoke16> even if its a const
<straight-shoota>
yes, but it doesn't matter
<straight-shoota>
it's a one time heap allocation
<FromGitter>
<riffraff169> i might change to a hash with a key being one of the values in the item, better for indexing rather than a search
<straight-shoota>
but even a tuple is likely allocated on the heap, unless it's only ever used in a local variable
<FromGitter>
<riffraff169> well, this program will most likely be a one and done type thing....it parses some input, indexes with the data to get some more information, then outputs results, and quits
<FromGitter>
<riffraff169> so not sure memory will really be an issue
<straight-shoota>
Yes, so don't worry about it. Just use an array.
<FromGitter>
<riffraff169> so for each item, actually a struct could work, but a hash would work just as well...just a hash of hashes
<FromGitter>
<riffraff169> hmmm
<FromGitter>
<riffraff169> thanks, i just needed to talk it out
<FromGitter>
<Blacksmoke16> > *<straight-shoota>* but even a tuple is likely allocated on the heap, unless it's only ever used in a local variable β β ah interesting
<FromGitter>
<riffraff169> so for clarification, what would be the benefits/drawbacks of tuple vs array?
<FromGitter>
<riffraff169> more in a long term program...short term probably wont notice
<FromGitter>
<riffraff169> or even hash, although hash can be indexed by non-numeric key
<straight-shoota>
there are none. Tuple is not really an approriate data type for that use case.
<FromGitter>
<riffraff169> i mean just in general
<FromGitter>
<riffraff169> why would one use a tuple over an array, or vice versa?
<straight-shoota>
I don't think there should ever by a reason to use a tuple over an array. If you can use an array, you should use an array.
<straight-shoota>
tuples are just a container of anonymous variables.
<FromGitter>
<riffraff169> hmm
<straight-shoota>
`tuple = {"foo", 1}` is more or less just something like `tuple_1 = "foo"; tuple_2 = 1` and a common way to address all indexed variables as `tuple`.
<FromGitter>
<riffraff169> if you are to return a group a values from a function, in c, for example, you have to create a struct and return it (on the heap of course)...in crystal, an array would be just as good as a tuple, or better
<FromGitter>
<riffraff169> hmm
<straight-shoota>
Main use case is if a method returns two different value but you don't want to define a proper data type for that
<FromGitter>
<riffraff169> i see
<straight-shoota>
tuple members can be completely unrelated data type
<FromGitter>
<riffraff169> yeah, thats not really the case here, it is strictly defined in the array
<straight-shoota>
arrays on the other hand are a collection of instances of a specific type
<FromGitter>
<riffraff169> in this case, every entry is `String, String, Int32, Int32, Int32, Int32, Int32, Int32`
<FromGitter>
<riffraff169> actually, Int16 would even work, probably even Int8 (the numbers dont even reach triple digits)
<straight-shoota>
there's also a stack-allocated collection type called StaticArray, that could technically be an alternative for Array in some case. But it's usually not worth to think about.
<FromGitter>
<oprypin:matrix.org> @Blacksmoke16: tuple can give you a small runtime advantage but i suspect it gives a big compiletime disadvantage, and also is semantically technically wrong as straight-shoota is saying
<FromGitter>
<riffraff169> or should it be `weapons = [...]`
<straight-shoota>
I don't know what you want to do here
<FromGitter>
<Blacksmoke16> prob easier to store it as JSON or something then load it in then you're not coupling your code with the static data
<FromGitter>
<riffraff169> weapons will be a hash of weapon name, and values for the weapon
<straight-shoota>
okay, so no array at all
<FromGitter>
<riffraff169> you maybe that would be better...it is static, never changing, but i could save it in a file and read it in
<FromGitter>
<asterite> Introduce a Weapon type that's a class?
<FromGitter>
<riffraff169> no, i was just seeing what type of internal crystal class the weapons var turned out to be (since it was basically created dynamically, ie, no type information)
<FromGitter>
<riffraff169> going to be parsing a file that will have descriptions and information, one of which will be a weapon spelled out...going to find that weapon name, index into this data, and get the relevant numerical information about it
<FromGitter>
<riffraff169> it could be an array where i use `.select` to find the specific entry i want, but adding a hash key doesnt add a lot and might make the code easier
<straight-shoota>
Yeah, hash is probably a better data structure than array if you want name-based lookup
<FromGitter>
<riffraff169> ok, lets figure out yaml parsing
early` has quit [Quit: Leaving]
<FromGitter>
<riffraff169> hmm, i dont see yaml in api, but i do see json...wonder if it moved
<FromGitter>
<riffraff169> ah man, left panel didnt scroll all the way to the bottom...its still there
<FromGitter>
<riffraff169> is it best to use `getter a : Int32` or just `@a : Int32` if it is immutable data (for YAML::Serializable)
<FromGitter>
<Blacksmoke16> you'd need a getter if you want to actually access it
<FromGitter>
<riffraff169> ah ok, there we go then
<FromGitter>
<Blacksmoke16> id also define these types as structs
early has joined #crystal-lang
<FromGitter>
<riffraff169> yeah...i see property in the yaml examples, is that different from a getter? where could i see that in the docs?
<FromGitter>
<Blacksmoke16> property defines a getter and setter
<FromGitter>
<riffraff169> ah ok i dont need a setter, so im good, thanks
<FromGitter>
<Blacksmoke16> but as you said this data is immutable, so no need for a setter, and no need for it to be a class either imo
<FromGitter>
<riffraff169> okay, great, got yaml::serializable working and parsing the yaml data, that much easier...
<FromGitter>
<riffraff169> comes in as YAML::Any, of course, although i can still index it by name...
<FromGitter>
<riffraff169> great, all working, fantastic
<FromGitter>
<Blacksmoke16> if you're using serializable it shouldnt come in as yaml any
<FromGitter>
<Blacksmoke16> make sure you're using like `Type.from_yaml` not `YAML.parse`
<FromGitter>
<riffraff169> ah, i am using yaml.parse
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<FromGitter>
<riffraff169> is there an example somewhere, a github project or something someone knows about, where i can see examples of from_yaml being used?
<FromGitter>
<Blacksmoke16> what are you having trouble with?
<FromGitter>
<riffraff169> just a sec, testing something...
<FromGitter>
<Blacksmoke16> π
<FromGitter>
<riffraff169> getting `Unhandled exception: Missing YAML attribute: name at line 1, column 1 (YAML::ParseException)`, trying to track that down
<FromGitter>
<Blacksmoke16> can you share your types and an example of the data structure you have setup?
<FromGitter>
<riffraff169> yes, here we go
<FromGitter>
<riffraff169> These are the structs: ```
<FromGitter>
<Blacksmoke16> the value is no longer another hahs
<FromGitter>
<riffraff169> ah, should be `.`
<FromGitter>
<riffraff169> getter of a struct
<FromGitter>
<riffraff169> exactly, got it
<FromGitter>
<riffraff169> first time ive ever used the yaml module for crystal...because of the static typing, more involved than ruby
<FromGitter>
<Blacksmoke16> a bit yea, but is a lot safer type wise
<FromGitter>
<riffraff169> i like type safety, i did most of my programming in c, but you end up writing your own parsers often, where i knew the data types before hand
<FromGitter>
<riffraff169> yaml kind of has no types, or all types, so anything could be anything at any time
<FromGitter>
<riffraff169> you really have to have a schema
<FromGitter>
<Blacksmoke16> right, ofc serializable stuff doesnt work if the data is dynamic
<FromGitter>
<Blacksmoke16> have to know it ahead of time
<FromGitter>
<riffraff169> at one company we had a a precommit hook for git that would run a schema verifier against the yaml data files for our ansible code, and if it failed it wouldnt commit
<FromGitter>
<riffraff169> and if you created a new file, you had to create a schema to go with it
<FromGitter>
<riffraff169> so made it more structured than basically free-form
Nekka has joined #crystal-lang
hipertracker has quit [Ping timeout: 240 seconds]
<FromGitter>
<HertzDevil> thinking if we really need to tie language versioning and stdlib versioning together
_ht has quit [Remote host closed the connection]
<FromGitter>
<asterite> Good point. I think there were discussions around that
<FromGitter>
<zomatree0:matrix.org> is there any plans to make concurrency a bit more easier to use, currently making something concurrent is a bit annoying and waiting for one to finish is a bit annoying as well
<straight-shoota>
@zomatree0 Yes, there's plans like
<shalokshalom>
That seems like a little bit sparse as information.
<straight-shoota>
the many assignment operators are just combinations with other operators
<shalokshalom>
Yeah, I know
<straight-shoota>
yeah byte shift is the original meaning of `<<`. But the language just defines the existence of operators, not their behaviour. So `<<` is also used for appending.
<shalokshalom>
It just looks overwhelming at first