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 joined #crystal-lang
<wwalker> OK, I want to do code like this: doc.first_element_child.first_element_child.other_xml_method.another_xml_method # But that results in this error,
<wwalker> Error: undefined method 'first_element_child' for Nil (compile-time type is (XML::Node | Nil))
<FromGitter> <Blacksmoke16> Probably need to ensure there is a first child on the doc
<FromGitter> <Blacksmoke16> I.e. handle the case it returns nil
<wwalker> Is there any nice clean way to tell it "yes, just do it and fail at run time if the data is bad" rather than having to do each method call and verify each return is "not nil?" ?
<wwalker> @Blacksmoke16 this is at compile time, not run time. I know that the nodes will exist.
<FromGitter> <Blacksmoke16> If you are 100% sure, you can use `.not_nil!`
<wwalker> I tried wrappign it in a begin...rescue, but it still refuses to compile
<FromGitter> <Blacksmoke16> That only rescues runtime exceptions. You need to do something to prove that the value isn't nil
<FromGitter> <Blacksmoke16> E.g. conditional logic, use .try, etc
<FromGitter> <Blacksmoke16> Prove to the compiler*
<wwalker> @Blacksmoke16 thank you! That worked great. In the rare condition that the inbound xml is bad, I'm okay with a runtime error.
<FromGitter> <Blacksmoke16> Should ideally still gracefully handle it, but:shrug:
<wwalker> Yes, but since it is xml, there will be like 6 of those calls, and 6 nested if statements is just ugly.
<FromGitter> <Blacksmoke16> Xpath it?
<wwalker> which shard? I tried to use naqvis/crystal-xpath2 but gave up because I can't figure out how to just read in xml with it. "refer to spec for usage examples" The spec seems to only build the document 1 element at a time.
<FromGitter> <Blacksmoke16> No shard, it's built into the stdlib
<wwalker> I started with 'require "xml"' and that loads and all, how do I do an xpath with it?
<wwalker> may have found it...
<wwalker> Yep, Thank you!
<FromGitter> <Blacksmoke16> 👍
Sankalp has quit [Ping timeout: 246 seconds]
Sankalp has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
ur5us has joined #crystal-lang
lanodan has quit [Read error: Software caused connection abort]
lanodan has joined #crystal-lang
ssw has quit [Quit: ZNC 1.7.5+deb4 - https://znc.in]
ssw has joined #crystal-lang
walez has joined #crystal-lang
walez___ has joined #crystal-lang
walez has quit [Ping timeout: 252 seconds]
ur5us has quit [Ping timeout: 255 seconds]
taupiqueur has quit [Remote host closed the connection]
taupiqueur has joined #crystal-lang
taupiqueur has quit [*.net *.split]
jmdaemon has quit [Ping timeout: 255 seconds]
<Ober> xml is soo evil
walez___ has quit [Ping timeout: 255 seconds]
<FromGitter> <naqvis> > *<wwalker>* which shard? I tried to use naqvis/crystal-xpath2 but gave up because I can't figure out how to just read in xml with it. "refer to spec for usage examples" The spec seems to only build the document 1 element at a time. ⏎ ⏎ Seems shard README and/or documentation isn't good enough to explain the use-case of that shard. That shard implements the `xpath2` and is designed to be used by
<FromGitter> ... libraries which require to add `xpath2` support. Like the way its used in crystal-html5 (https://github.com/naqvis/crystal-html5) library for parsing HTML5, json-xpath (https://github.com/naqvis/json-xpath) library to add `xpath` support on JSON documents.
<FromGitter> <naqvis> For xml you can stick to stdlib and that should do the work for you
taupiqueur has joined #crystal-lang
taupiqueur has quit [Remote host closed the connection]
<wwalker> Thank you @naqvis
<FromGitter> <naqvis> 🌹
<FromGitter> <noaheverett> @naqvis didn't realize you were in here! Thank you for your work on wasmer-crystal 👏
<FromGitter> <naqvis> Thanks @noaheverett 🌹
<FromGitter> <vgramkris> Is there a macro or variable that by default holds the name of the calling function (like *func* in c)?
<FromGitter> <Blacksmoke16> got an example?
<FromGitter> <Blacksmoke16> like if you're within a method, something to get the name of that method?
<FromGitter> <vgramkris> thats right @Blacksmoke16
<FromGitter> <Blacksmoke16> `{{ @def.name.stringify }}`
<FromGitter> <vgramkris> thanks
_ht has joined #crystal-lang
ur5us has joined #crystal-lang
_whitelogger has joined #crystal-lang
jmdaemon has joined #crystal-lang