<FromGitter>
<iambudi> Hi. can someone explain why atomic add() in a hash does not work? see line 4 in the playground https://play.crystal-lang.org/#/r/9ir7
<FromGitter>
<iambudi> @oprypin thanks, i did not know there's already discussion about that and still on going
zorp has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 265 seconds]
chachasmooth has quit [Ping timeout: 246 seconds]
chachasmooth has joined #crystal-lang
<postmodern>
what does crystal do if LibC.malloc fails (out-of-memory)? will Pointer.malloc return nil, or raise an exception, or Sig 11?
alexherbo2 has joined #crystal-lang
<woodruffw>
postmodern: i believe `Pointer.malloc` is implemented in terms of `GC.malloc`, which in turn is implemented in terms of either `LibGC.malloc` (boehm) or `LibC.malloc` directly. both of those return `Void*` and i can't find any checks against that value, so my best guess is that it'll segfault on OOM
<woodruffw>
in particular `Pointer.malloc(size : Int, value : T)` and `Pointer.malloc(size : Int, &block : Int32 -> T)` should segfault right away on a null deref
<FromGitter>
<ImAHopelessDev_gitlab> i love null dereferencing
<FromGitter>
<grkek> How does one check if a string is in an array of strings?
<FromGitter>
<naqvis> you will have to implement some custom mechanism to find that out, either find the `[` in the string and make a guess or you can use `JSON.parse` and see if it returns an array ⏎ ⏎ ```str = <<-STR ⏎ ["Hello", "World","Foo"] ⏎ STR ⏎ ⏎ pp JSON.parse(str).as_a?.nil? #=> false``` [https://gitter.im/crystal-lang/crystal?at=5f30e20cdca038052a5c3fb2]
<postmodern>
is there a easier way to define methods that take UInt32 | Int32, convert to UInt32 but reject values < 0?
alexherbo2 has joined #crystal-lang
alexherbo23 has joined #crystal-lang
<postmodern>
if a method is tagged with @[Raises(...)] and another method happens to call that method, does the calling method inherit the @[Raises]?
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo23 is now known as alexherbo2
<FromGitter>
<naqvis> > *<postmodern>* if a method is tagged with @[Raises(...)] and another method happens to call that method, does the calling method inherit the @[Raises]? ⏎ ⏎ Answer is yes. The compiler infers this attribute for a method if it invokes a method that is marked as @[Raises] or raises (recursively).
<FromGitter>
<dscottboggs_gitlab> I have a type which I wrote a method to deserialize with YAML::PullParser... ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Or do I need to rewrite the original `from_yaml` into a `.new(ctx, value)` somehow? [https://gitter.im/crystal-lang/crystal?at=5f31a8bf9231d665df6bc7cc]
<FromGitter>
<Blacksmoke16> or something along those lines?
<FromGitter>
<dscottboggs_gitlab> yeah but `Bar` has a bazillion members and I wanted to use `YAML::Serializable` to parse it. YAML::Serializable doesn't define `.new(YAML::PullParser)` :(
<FromGitter>
<Blacksmoke16> `OtherType.from_yaml parser.raw` or something like that maybe?
<FromGitter>
<dscottboggs_gitlab> where would I get the parser from?
<FromGitter>
<dscottboggs_gitlab> oh I guess I could try initializing one outside and passing it in
<FromGitter>
<Blacksmoke16> normally you apply the converter to a given property
<FromGitter>
<Blacksmoke16> which gives you access to that stuff
<FromGitter>
<dscottboggs_gitlab> ...I don't see any docs for that
<FromGitter>
<Blacksmoke16> i know, was just being a :trollface:
<FromGitter>
<dscottboggs_gitlab> I'm confused...how do you advance to the next node when using `YAML::Nodes::Node`? Specifically I want to be able to translate ⏎ ⏎ ```{ name: "foo", values: { "bar" =>"baz", "dar" =>"daz"``` [https://gitter.im/crystal-lang/crystal?at=5f31bea69231d665df6c03e8]
<FromGitter>
<dscottboggs_gitlab> so I can get `name = node.as(YAML::Nodes::Scalar).value` but then what do I do to get the mapping?
<FromGitter>
<Blacksmoke16> that would get into `foo`
<FromGitter>
<dscottboggs_gitlab> that's for `PullParser`, I'm looking at trying to use the `.new(ParseContext, Nodes::Node)` overload used by `Serializable`
<FromGitter>
<Blacksmoke16> oh
<FromGitter>
<dscottboggs_gitlab> yeah that was how I did it before
<FromGitter>
<Blacksmoke16> prob be something in there
<FromGitter>
<dscottboggs_gitlab> I don't really see any way to do this without also manually writing an overload of `#initialize(*, __context_for_yaml_serializable ctx : YAML::ParseContext, __node_for_yaml_serializable node : ::YAML::Nodes::Node)` in the parent type 😦
<FromGitter>
<dscottboggs_gitlab> only a `YAML::Mapping` has access to its child nodes, you can't just say "give me the next node" like with a PullParser
oddp has quit [Ping timeout: 264 seconds]
<FromGitter>
<dscottboggs_gitlab> TBH I think this is due to a technical limitation in YAML, but it would be nice if YAML::Serializable somehow supported YAML::Pullparser for documents that can be parsed with it (I.E. those without anchors)
alexherbo2 has quit [Ping timeout: 240 seconds]
<FromGitter>
<Blacksmoke16> :shrug: possibly
<FromGitter>
<Blacksmoke16> `BUG: `max` at /home/george/dev/git/athena-framework/validator/src/constraints/range.cr:44:70 has no type (Exception)` 😐
<FromGitter>
<dscottboggs_gitlab> > "has no type" ⏎ ⏎ excuse me, Mr. Compiler?