jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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> <dscottboggs> fuck it, I submitted it. #9703
<DeBot> https://github.com/crystal-lang/crystal/pull/9703 (Add implicit yield for tap and try)
<FromGitter> <Blacksmoke16> bum bum bum
<FromGitter> <dscottboggs> 😂 watch it get shot down in like 10 minutes haha
Elouin has quit [Quit: Ping timeout (120 seconds)]
Elouin has joined #crystal-lang
chachasmooth has quit [Ping timeout: 240 seconds]
chachasmooth has joined #crystal-lang
postmodern has joined #crystal-lang
<postmodern> hmm how do i convert a String into a StaticArray(UInt8,N)? String#bytes is not doing it.
<postmodern> trying to assign a string value into a UInt8[32] struct array field
<Andriamanitra> postmodern: something along these lines? https://play.crystal-lang.org/#/r/9lgd
<postmodern> hmm weird you can't do `if foo; then ...` in crystal?
<Andriamanitra> sure you can although there's no then keyword that i'm aware of
<postmodern> hmm so how do you filter out the \x00 characters when converting a UInt8 array into a String from a slice?
<postmodern> there's no length field i can use from the struct, just have to strip the null chars
<Andriamanitra> one code golf way to remove certain characters is this https://play.crystal-lang.org/#/r/9lgi
<postmodern> hmm can't #- a StaticArray
<Andriamanitra> oh, guess you can #take_while then
<Andriamanitra> assuming all \x00's are at the end, i'm not entirely sure what you're trying to do
<Andriamanitra> #reject would work if you want to remove them from the middle too
<postmodern> has to be a nicer way to do this
<postmodern> i tried doing name[0,(name.index(0) || name.length)] to get a sub-static-array and #to_slice that
<Andriamanitra> seems like .take_while{ |x| x != 0 } would achieve the same thing as that
<postmodern> would have to create a Slice(UInt8) from the resulting Array(UInt8)
<postmodern> ah actually, @struct.name.to_slice, then using #[0,(slice.index(0) || slice.size)] did the trick
<postmodern> what's the deal with the delegate macro definition, how is the `to:` part defined?
<postmodern> trying to define my own delegate method
<postmodern> *macro
<postmodern> hmm, if i define a macro within a namespace, do classes under that namespace also get access to the macro?
<FromGitter> <Geo-7> Hi, Is there any FTP client in standard lib or any shard?
f1refly has joined #crystal-lang
<Andriamanitra> Geo-7: https://github.com/crystal-community/crystal-libraries-needed/issues/58 surprisingly this is all i could find, of course you could use ftp through libcurl bindings instead
<FromGitter> <Geo-7> Thank you
alexherbo2 has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
Stephie has quit [Quit: Fuck this shit, I'm out!]
Vexatos has joined #crystal-lang
Stephie has joined #crystal-lang
Vexatos has quit [Read error: Connection reset by peer]
Vexatoast has joined #crystal-lang
woodruffw has quit [Ping timeout: 240 seconds]
woodruffw has joined #crystal-lang
Vexatoast has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
alexherbo25 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo25 is now known as alexherbo2
alexherbo28 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo28 is now known as alexherbo2
woodruffw has quit [Ping timeout: 258 seconds]
postmodern has quit [Quit: Leaving]
Elouin has quit [Ping timeout: 246 seconds]
zorp_ has joined #crystal-lang
woodruffw has joined #crystal-lang
Elouin has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
FromGitter has joined #crystal-lang
<FromGitter> <asterite> Andriamanitra: chaining operators is a special rule in the language, that's why it works
<Andriamanitra> asterite: makes sense, is it only the comparison operators (<, >, <=, >=, ==, !=) or are there others?
<FromGitter> <mtsmmp_gitlab> guys
<FromGitter> <mtsmmp_gitlab> im trying to require "markdown"
<FromGitter> <Blacksmoke16> you're looking at old docs
<FromGitter> <Blacksmoke16> its internal now, use https://github.com/icyleaf/markd
<FromGitter> <mtsmmp_gitlab> ok
<FromGitter> <mtsmmp_gitlab> @Blacksmoke16 any way to make it ignore the front matter?
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <mtsmmp_gitlab> my file has a front matter
<FromGitter> <mtsmmp_gitlab> like
<FromGitter> <mtsmmp_gitlab> ```--- ⏎ layout: post ⏎ title: Blogging Like a Hacker ⏎ ---``` [https://gitter.im/crystal-lang/crystal?at=5f47b92189cf2d584b7cbe4c]
<FromGitter> <mtsmmp_gitlab> it parses the whole thing
<FromGitter> <Blacksmoke16> is that actually a markdown construct?
<FromGitter> <Blacksmoke16> i always thought those were used by something on top of markdown to store metadata
<FromGitter> <mtsmmp_gitlab> its used by blog generators
<FromGitter> <Blacksmoke16> right, but not actually part of the markdown spec?
<FromGitter> <mtsmmp_gitlab> hm
<FromGitter> <mtsmmp_gitlab> yep
<FromGitter> <mtsmmp_gitlab> i guess ill use this https://github.com/chris-huxtable/front_matter.cr
<FromGitter> <mtsmmp_gitlab> to separate then
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <3n-k1> is `y` garbage collected here? `x = 5; y = pointerof(x)`
<FromGitter> <3n-k1> i would assume so, but i've dealt with weird languages lol
<FromGitter> <asterite> it's on the stack, it disappears after you exit that method
<FromGitter> <asterite> @mtsmmp_gitlab that's a yaml file with two documents, you should parse that first
<FromGitter> <3n-k1> you're absolutely correct, i haven't touched c in a while haha. is there any case in crystal where you could have a pointer to something that isn't garbage collected?
<FromGitter> <mtsmmp_gitlab> @asterite yeah bro front_matter.cr did the trick
<FromGitter> <mtsmmp_gitlab> it does exactly that
<FromGitter> <mtsmmp_gitlab> good thing that crystal is more mature
<FromGitter> <mtsmmp_gitlab> i mean it wouldnt be hard to code that, but have a lib that does it already saves time
<FromGitter> <mtsmmp_gitlab> this front matter module is like 100 lines of code
<FromGitter> <mtsmmp_gitlab> could be even less
<FromGitter> <Blacksmoke16> good to hear
duane has quit [Ping timeout: 265 seconds]
duane has joined #crystal-lang
postmodern has joined #crystal-lang
<postmodern> what's the preferred way to expose macros in a library, so that all of the classes in the namespace have access to them? Define a module and include it everywhere? Explicitly call them like Macros.foo_macro?
<FromGitter> <Blacksmoke16> that would be the most clear id say
<FromGitter> <Blacksmoke16> sorry, the latter option
<FromGitter> <Blacksmoke16> but pretty sure it would work w/o the FQN
<postmodern> how do i define my own `delegate` macro? wondering how `delegate` defines it's `to:` keyword param
<FromGitter> <Blacksmoke16> basically just defines a method for you, not much magic going on
alexherbo20 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo20 is now known as alexherbo2
alexherbo20 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo20 is now known as alexherbo2
<oprypin> @3n-k1: there was a conversation on this a few days ago. i concluded that the `pointerof` (the construct itself) is never safe. other ways of getting a pointer might be.
<postmodern> trying to define my own delegate method with `to object` but getting this error "Error: can't use instance variables at the top level" with `struct_field capability, to: @struct.parm.capture`
<FromGitter> <Blacksmoke16> got a playground example?
<FromGitter> <Blacksmoke16> sounds like you're not using it within a class/struct
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo2 has joined #crystal-lang
<postmodern> it's within a class. will need to extract the example code into something easier to test.
<FromGitter> <dscottboggs> is there a construct a reference to a local variable? for example ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ or pass a `Pointer` or `Slice` (of size 1) to the other object, but I feel like using a raw pointer is a smell unless there's a really good reason for it (since the length is technically unknown) and a slice isn't really for this [https://gitter.im/crystal-lang/crystal?at=5f482bf536e6f709fd084e0c]
<FromGitter> <j8r> If `Bar` is a class, it could be passed to `Foo.new`
<FromGitter> <dscottboggs> ahhh, that could do it
<FromGitter> <franciscoadasme> hey everyone, I've been trying to find a way to implement something like copy-on-write for an array wrapper (via `method_missing` macro), that is, make a copy of the internal array before calling a mutating method on it. The use case is to expose an array of internal data that should not be modified by external entities, but I'd like to avoid doing copies of it every time that it is accessed. However, I
<FromGitter> ... cannot find a way to determine if a method is mutating the array or not :/... can anyone think of a way to do this?
<FromGitter> <dscottboggs> no, this is a bit of a gripe I have with the type system personally
<FromGitter> <dscottboggs> Only way I can think of is to use an immutable array (there's a shard for that) or manually make a list of all the methods which don't mutate an array and make a list to allow them, then make a copy on any missing method from that list
<FromGitter> <Blacksmoke16> cant just call `.dup` or something?
<FromGitter> <dscottboggs> also that seems more useful for something passed by copy instead of passed by reference like an array
<FromGitter> <dscottboggs> would be cool to add mutation methods to `StaticArray` in a COW way
<FromGitter> <franciscoadasme> @dscottboggs I thought of that but non-mutating methods added to Array would also trigger copies... so it is not ideal but it's the "best" idea so far
<FromGitter> <j8r> @franciscoadasme note that: https://carc.in/#/r/9lmy
<FromGitter> <j8r> If you pass a StaticArray, being a struct, it will be passed by copy
<FromGitter> <j8r> This will be cheaper than `Array#dup`
<FromGitter> <franciscoadasme> @Blacksmoke16 I'd like to avoid doing copies every time the array is accessed, especially if you're then going to generate a new array (e.g., calling map)
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <franciscoadasme> @j8r But you need to know the array size at compilation time, right?
<FromGitter> <dscottboggs> no, i think you misunderstood.... if you manually write down a list of all the methods that *don't* mutate, you can check for that. ⏎ ⏎ I still think this would be more useful if you added to or wrapped StaticArray rather than wrapping Array
<FromGitter> <dscottboggs> yes, for a StaticArray
<FromGitter> <j8r> @franciscoadasme right, you don't in your case?
<FromGitter> <dscottboggs> but that's the only way you can pass by copy, so there's no way to *not* do that and still pass by copy.
<FromGitter> <dscottboggs> and you could still wrap a StaticArray in a reference (by putting it in some wrapper class like @j8r said) once you finish adding to the immutable base
<FromGitter> <dscottboggs> actually I take back that second paragraph, that doesn't make sense
<FromGitter> <j8r> however, if you only need an array for iterating, creating arrays can be avoided. ⏎ For example, a hash could store the difference between the initial and the virtual array
<FromGitter> <j8r> For example, index 2 is modified, to the hash will be `{2 => ... }`
<FromGitter> <j8r> Maybe there is a way to have "views" of the parts of the array by messing around with Slice. Then, we dig with low-level, unsafe code.
<FromGitter> <franciscoadasme> sure... the idea is to have "mutable views" that make a copy of the original array before mutation
<postmodern> is there something special about the `to` keyword in the definition of the `delegate` macro?
<FromGitter> <Blacksmoke16> Got that example yet?
<postmodern> Blacksmoke16, now my simplified example gives me a completely different macro error
<postmodern> wait no, hmm
<FromGitter> <dscottboggs> postmodern, no. The if you put an argument after a splat, it must be present as a named argument, and all args before it are folded into the splat
<FromGitter> <dscottboggs> https://carc.in/#/r/9ln9
<postmodern> ah ha
<FromGitter> <dscottboggs> TBH I love that feature, really makes for a nice DSL-building feature
<postmodern> don't think i ever seen the `foo bar` syntax for arguments
<FromGitter> <Blacksmoke16> It's the internal external name thing
<FromGitter> <dscottboggs> another absolute beauty of a feature
<FromGitter> <dscottboggs> some languages don't even have named args, we've got args with *two* names! 😂
<postmodern> can `external internal` arugments have default values?
<FromGitter> <Blacksmoke16> PHP8 is adding them
<FromGitter> <Blacksmoke16> As far as I know yea
<FromGitter> <dscottboggs> yup they work the same as regular named args, just have a different name outside the method vs inside
<FromGitter> <dscottboggs> ugh....I wish PHP weren't so damn ugly, I probably wouldn't mind it.
<FromGitter> <Blacksmoke16> It's pretty legit these days
<FromGitter> <Blacksmoke16> From an oop point of view
Stephie has quit [Quit: Fuck this shit, I'm out!]
<postmodern> can macro arguments default to the value of another macro argument? `field = name` is assigning `field` to the literal of `name`
Stephanie has joined #crystal-lang
<FromGitter> <Blacksmoke16> IDK, try it?
Elouin has quit [Quit: Ping timeout (120 seconds)]
Elouin has joined #crystal-lang
Elouin has quit [Client Quit]
Elouin has joined #crystal-lang