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
chachasmooth has quit [Ping timeout: 245 seconds]
f1reflyylmao has joined #crystal-lang
chachasmooth has joined #crystal-lang
f1refly has quit [Ping timeout: 250 seconds]
f1reflyylmao is now known as f1refly
<FromGitter> <636f7374> Does Crystal have `std::atomic<bool>` similar to C++?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Atomic.html this?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Mutex.html also might be of interest
<FromGitter> <636f7374> @Blacksmoke16 Yes, but there seems to be no Boolean?
<FromGitter> <Blacksmoke16> atomic is a generictype
<FromGitter> <Blacksmoke16> `Atomic(Bool).new true`
<FromGitter> <Blacksmoke16> oh wait
<FromGitter> <636f7374> @Blacksmoke16 Oh oh sorry :(
<FromGitter> <Blacksmoke16> idt that would work ⏎ ⏎ > Only primitive integer types, reference types or nilable reference types can be used with an Atomic type.
<FromGitter> <Blacksmoke16> `Bool` is a `Value` type
<FromGitter> <636f7374> @Blacksmoke16 Thank you very much.
<FromGitter> <636f7374> @Blacksmoke16 Another stupid question, how does C++ or Java `volatile` type do it in Crystal? Do I have to use Mutex?
<FromGitter> <636f7374> There is a common problem with visibility of variables in multithreaded environments. Let's assume that we have a shared variable (or object) that is being accessed by two different threads (each thread on its own processor). ⏎ If one thread updates the variable/object, we cannot know for sure when exactly this change will be visible to the other thread. The reason why this happens is because of CPU caching.
<FromGitter> <Blacksmoke16> a mutex would be what you want in order to ensure only 1 thread access something at a time
<FromGitter> <Blacksmoke16> ofc this is only relevant if you're using the MT opt in feature
<FromGitter> <Blacksmoke16> 1 fiber*
<FromGitter> <636f7374> @Blacksmoke16 Ok thanks a lot. :)
sagax has quit [Quit: Konversation terminated!]
<FromGitter> <naqvis> > Does Crystal have `std::atomic<bool>` similar to C++? ⏎ ⏎ https://crystal-lang.org/api/master/Atomic/Flag.html
<FromGitter> <Blacksmoke16> :0 well there you go
<FromGitter> <HertzDevil> this is how overload ordering will look like in my potential fix
<FromGitter> <HertzDevil> (assuming the two defs cannot be ordered according to restrictions)
<FromGitter> <HertzDevil> and some kind of semi-formal specification that goes with it: https://gist.github.com/HertzDevil/b2150e2c1051fc29f191e5ac69644641
_ht has joined #crystal-lang
eiro has joined #crystal-lang
hipertracker has joined #crystal-lang
hipertracker has quit [Client Quit]
hendursaga has joined #crystal-lang
hendursa1 has quit [Ping timeout: 240 seconds]
chachasmooth has quit [Ping timeout: 265 seconds]
chachasmooth has joined #crystal-lang
chachasmooth_ has joined #crystal-lang
chachasmooth has quit [Ping timeout: 245 seconds]
<FromGitter> <asterite> That's amazing! I'll take a look at that later today. Also maybe post it in github for more visibility and discussion
shalokshalom has quit [Remote host closed the connection]
shalokshalom has joined #crystal-lang
<eiro> hello people.
<eiro> newbie question: what's the simplest way to implement the equivalent of perl /../g
<eiro> (which mean create a list of the chars of the initial string 2 by too
<eiro> i meant: two by two. like my ( $index, @chars ) = '02helo' =~ /../g
<eiro> $index => '02 '
<eiro> @chars = ('he','lo')
andremedeiros has joined #crystal-lang
<FromGitter> <asterite> I think it's String#scan
Vexatoast has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
<eiro> FromGitter: asterite you think right. there is also hexbytes which solves exactly my problem :) also https://github.com/crystal-lang/crystal/issues/132
<FromGitter> eiro, I'm a bot, *bleep, bloop*. I relay messages between here and https://gitter.im/crystal-lang/crystal
<FromGitter> <MrSorcus> https://gist.github.com/MrSorcus/13f3ad55f8461de4301a71f83697b4ef ⏎ Hmm. It's not what i expecting O_o
<eiro> talk about the ruby * that isn't supported so
<eiro> i can't write index, *chars = "hello".scan(/../) # would have been nice
<FromGitter> <MrSorcus> `pp String.new peek[16, index]` - i thought it should return `Бланки/10_Направление в стационар_1 ЛИСТ.pdf`, not `Бланки/10_Направление в стационар_1 ЛИСТ.pdf\n123456789009876`...
<eiro> i just don't get it ... transforming a simple, lightweight protocol like irc to a gitter stream ....
<FromGitter> <MrSorcus> Oops, forget it. 😆
eiro has quit [Quit: cya]
alexherbo2 has joined #crystal-lang
<FromGitter> <asterite> Yes, `index, *chars = ...` was already implemented by the awesome HertzDevil, but it didn't go through 1.0. But I'm sure it will be included in upcoming versions
<FromGitter> <asterite> Also, it needs to be `"02helo".scan(/../).map(&.string)`
libneko[m] has joined #crystal-lang
chachasmooth has joined #crystal-lang
chachasmooth_ has quit [Ping timeout: 246 seconds]
shalokshalom has quit [Ping timeout: 246 seconds]
<FromGitter> <riffraff169> so, building with `shards build`, i presume that is the proper way for a whole project
<FromGitter> <Blacksmoke16> that builds the targets you have defined in your `shard.yml`
<FromGitter> <riffraff169> you just set a target of one file, that `require`s all the other files (assuming you just have one binary output)
<FromGitter> <riffraff169> not like c where you specify all the files you need to compile and build together into one output
<FromGitter> <Blacksmoke16> right
<FromGitter> <riffraff169> basically im having a bunch of requires in my main with all the files to be included...since they are all classes, they arent actually called until i create a class and use it
<FromGitter> <riffraff169> ok
<FromGitter> <riffraff169> still getting my way around crystal programming...never dug in that deep in ruby either, so never really used modules
<FromGitter> <Blacksmoke16> at a high level you should use them to namespace your types and stuff
<FromGitter> <Blacksmoke16> e.g. if you do `class SomeClass` then some other shard does the same thing you'll have problems
<FromGitter> <riffraff169> although looking at the shards source, i noticed that it just does `require './config'`, with an ending `.cr`
<FromGitter> <Blacksmoke16> so you cod `class MyLib::SomeClass`
<FromGitter> <Blacksmoke16> you should*
<FromGitter> <Blacksmoke16> modules can also be used as interfaces and/or to include methods into various other types as a form of composition
<FromGitter> <riffraff169> so i have a struct, loading with yaml like i talked about yesterday, so a hash of structs
<FromGitter> <riffraff169> ill have to do things with the data, of course...i have a class that loads up all the data into an instance var....i was going somewhere with this, lost my train of thought
<FromGitter> <riffraff169> ok then this question....enums, can they be loaded from yaml with `.from_yaml`?
<FromGitter> <Blacksmoke16> sure
<FromGitter> <riffraff169> so i would use `getter a : MyEnum`, then have i presume the fully qualified enum in the yaml like `a: MyEnum::TEST`
<FromGitter> <Blacksmoke16> by default you would want `a: test` in your yaml
<FromGitter> <Blacksmoke16> i.e. the string representation of it
<FromGitter> <riffraff169> ah, ok
<FromGitter> <riffraff169> fantastic, that worked perfectly
zorp has joined #crystal-lang
andremedeiros has quit [Read error: Connection reset by peer]
andremedeiros has joined #crystal-lang
<FromGitter> <lodenos> Hello everyone I’ve a question about HTTP::Headers, I would to use the feature from HTTP Content-Range form https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range for build my request ⏎ ⏎ ```response = HTTP::Client.get route_api, HTTP::Headers { "Content-Range" => "bytes=0-“ }``` ⏎ ⏎ but it’s seem doesn’t work I get all data, what’s wrong I don’t have really understand,
<FromGitter> ... how was allready try this option of HTTP [https://gitter.im/crystal-lang/crystal?at=606c72f5657d022d5a66743f]
<FromGitter> <Blacksmoke16> does the API you're hitting up actually support it?
<FromGitter> <Blacksmoke16> and sure you dont mean https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range ?
<straight-shoota> I don't think HTTP::Client supports any of these headers
<FromGitter> <Blacksmoke16> whats there to support? you make a request with `range` header, and response includes only that range if supported
<FromGitter> <Blacksmoke16> afaik theres nothing special needed to support it on the client side
<straight-shoota> yeah, if you just do the ranges manually, this should work at client side
<FromGitter> <lodenos> @Blacksmoke16 u know I’ve understand my mistake ⏎ this systax work's ⏎ ⏎ ```response = HTTP::Client.get route_api, HTTP::Headers { "Range" => "bytes=0-0" }``` [https://gitter.im/crystal-lang/crystal?at=606c748e0147fb05c5ddab7c]
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Blacksmoke16> shameless plug, athena supports `range` requests for static files via https://athenaframework.org/Routing/BinaryFileResponse
<FromGitter> <Blacksmoke16> as well as other conditional request constructs ;)
<FromGitter> <lodenos> Thx
<mipmip> straight-shoota: I just submitted a PR to fix the tests for JSON.mapping
<mipmip> I understand it's depreciated, but it still works and I need https://github.com/crystal-lang/json_mapping.cr/pull/5
<FromGitter> <Blacksmoke16> @straight-shoota would it be worth having another test case for like `name : String? = "Jim"`. E.g. `name: ~` should be `nil`, `name:` should be `nil`, `name: John` should be `John`, and if it's missing it should be `Jim`
<FromGitter> <Blacksmoke16> `name: ""` should be`""`
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<FromGitter> <riffraff169> is `a : Array of Int32` sufficient? how about if i know that exact number of elements in the array, say 10?
<FromGitter> <Blacksmoke16> `a : Array(Int32)`, this is just the type. Knowing the size only helps when first creating one
<FromGitter> <riffraff169> another question, can you build up regexes? like, `a1 = /\d+/`, `a2 = /\s+/`, `a3 = a1 + a2`
<FromGitter> <riffraff169> ok so i would do `Array(Int32)` instead of `Array of Int32`, or are they both the same
<FromGitter> <oprypin:matrix.org> @riffraff169: yes build them up, why not
<FromGitter> <oprypin:matrix.org> @riffraff169: these are different things. to avoid confusion just forget about the `of` syntax
<FromGitter> <Blacksmoke16> `Array of Int32` pretty sure this isnt valid syntax
<FromGitter> <riffraff169> ok, so `+` works fine, i dont have to do interpolation like `a3 = /#{a1}#{a2}/`
<FromGitter> <oprypin:matrix.org> @riffraff169: i don't know, try and see
<FromGitter> <Blacksmoke16> not quite
<FromGitter> <riffraff169> sure, ill do that
<FromGitter> <Blacksmoke16> `+` is an alias for `union` iirc, so you end up with like `\d+|\s+`
<FromGitter> <oprypin:matrix.org> wat
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/as82
<FromGitter> <riffraff169> ah, hmm, thats not what i want...i want to basically concatenate several pieces together to make a longer regex
<FromGitter> <oprypin:matrix.org> ok that's dumb
<FromGitter> <Blacksmoke16> i think i brought this up before, let me find the chat
<FromGitter> <riffraff169> i have to interpolate apparently
<FromGitter> <riffraff169> `c = /#{a}#{b}/`
<FromGitter> <riffraff169> https://play.crystal-lang.org/#/r/as83\
<FromGitter> <riffraff169> ack... https://play.crystal-lang.org/#/r/as83
<FromGitter> <oprypin:matrix.org> @riffraff169: so use interpolation OR just concatenate strings and only in the end convert to regex
<FromGitter> <Blacksmoke16> so the interpolation one is technically correct iirc
<FromGitter> <riffraff169> hmm, maybe as @oprypin:matrix.org said, create strings and convert to regex afterwards
<FromGitter> <riffraff169> so like `Regex.new(regex_string)`
<FromGitter> <Blacksmoke16> cant just create the end result regex without using these parts?
<FromGitter> <riffraff169> well, the parts can be used in other portions, and i dont want to duplicate the strings
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Max SendQ exceeded]
HumanG33k has joined #crystal-lang
<FromGitter> <Blacksmoke16> fair enough
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
shalokshalom has joined #crystal-lang
<straight-shoota> @Blacksmoke16 > would it be worth having another test case for like `name : String? = "Jim"`. E.g. `name: ~` should be `nil`, `name:` should be `nil`, `name: John` should be `John`, and if it's missing it should be `Jim`
<straight-shoota> I think that should all be covered already in that spec
<FromGitter> <Blacksmoke16> 👍 i didnt look thru all them, just that in the spec you added it wouldnt be nilable
<straight-shoota> ah, you're taking about nilable type, sry didn't catch that
<FromGitter> <Blacksmoke16> yea, like nilable type + explicit nil
<straight-shoota> I don't think that matters here
<FromGitter> <Blacksmoke16> 👍 ight
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
_ht has quit [Remote host closed the connection]
<FromGitter> <lodenos> @Blacksmoke16 I’ve a question for u if u know, how work Array behind, it’s a linked list or a perfect continus pointer realloc when we use the operator << (append)
<oprypin> lodenos, "continuous pointer realloc"
<FromGitter> <Blacksmoke16> one of the overloads allows you to specify initial capacity as well
<FromGitter> <Blacksmoke16> constructor overloads*
<FromGitter> <erdnaxeli:cervoi.se> hi, I just see the news about the crystal conf, what are those community discounts? https://www.eventbrite.com.ar/e/crystal-conference-10-launch-tickets-149153252393
<FromGitter> <lodenos> @oprypin:matrix.org @Blacksmoke16 thx 🍺🍺
<FromGitter> <ryanstout> is there a way to create an unitialized Array(UInt16) for example. (So on the heap, but just malloc'ed and not filled in)
<straight-shoota> https://crystal-lang.org/api/1.0.0/Array.html#new(initial_capacity:Int)-class-method
<FromGitter> <ryanstout> @ straight-shoota the array size will still be 0 if you specify it that way
<FromGitter> <ryanstout> I'm wanting to malloc it, then start assigning values with []=
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/1.0.0/Array.html#new(size:Int,&block:Int32-%3ET)-class-method
<FromGitter> <ryanstout> @Blacksmoke16 I'm trying to avoid the overhead of a fill operation
<FromGitter> <ryanstout> (Trying to write a fast image format decoder)
<FromGitter> <asterite> No way, all allocated memory is zeroed
<FromGitter> <ryanstout> @asterite ok, fair enough, is that for saftey reasons?
<straight-shoota> yes
<FromGitter> <ryanstout> ok, thanks for the help
<FromGitter> <asterite> Is the memory fill the bottleneck?
<FromGitter> <ryanstout> yea
<FromGitter> <ryanstout> in this case
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/1.0.0/Array.html#build(capacity:Int,&):self-class-method there's also this overload if thats helpful
<FromGitter> <ryanstout> (not usually obviousl)
<straight-shoota> you could pass in an uninitialized instance to https://crystal-lang.org/api/1.0.0/Array.html#new(size:Int,value:T)-class-method
<FromGitter> <ryanstout> @ straight-shoota I don't follow, pass in an uninitialized something for value?)
<straight-shoota> na, not really useful I guess
<FromGitter> <ryanstout> ok, so the next question then. If you can't do it in the safe part of the language, is there a way to do it with Pointer(UInt16).malloc?
<FromGitter> <ryanstout> looks like all the `malloc` methods initialize also
<straight-shoota> The build method posted by Blacksmoke16 should work for that
<FromGitter> <ryanstout> ok, I misread the docs on that. I think I can make that work
<FromGitter> <ryanstout> thanks
<straight-shoota> Like `ary = Array(T).build(size) { size }`
<FromGitter> <ryanstout> cool, thanks!
<straight-shoota> Damn. I just realized I could've used that for https://github.com/crystal-lang/crystal/pull/10009 without introducing Array.unsafe_build
<FromGitter> <ryanstout> thanks everyone, that shaved off 5% of the run time :-)
<FromGitter> <lodenos> This is really nice for the C binding
alexherbo2 has quit [Quit: Ping timeout (120 seconds)]
alexherbo2 has joined #crystal-lang
hendursaga has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
<FromGitter> <Daniel-Worrall> Can you have the same C link called by a different name? So for example you could define the same links that the stdlib does and not worry about conflicts
<FromGitter> <oprypin:matrix.org> @Daniel-Worrall: question is unclear
<FromGitter> <Daniel-Worrall> C lib binding. Could I have 2 bindings to the same method
<FromGitter> <oprypin:matrix.org> probably not but still unclear
<FromGitter> <Daniel-Worrall> Hmm