ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.33.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <bew> @stronny you can do sth like `buf.to_slice.copy_from(str.to_slice)`
<FromGitter> <bew> and with more control on the size you're copying: `buf.to_slice.copy_from(str.to_unsafe, buf.size)`
<FromGitter> <bew> (note: not tested)
<FromGitter> <stronny> should probably work, however that to_unsafe there is reeeally unsafe if I understand correctly
dwdv has quit [Ping timeout: 255 seconds]
<FromGitter> <stronny> I would avoid taking addresses on stack, but maybe that's just me
<FromGitter> <bew> well yes, but if you specify the count it's ok
<FromGitter> <bew> note I made an issue for you: https://github.com/crystal-lang/crystal/issues/8865
<FromGitter> <stronny> thanks!
<FromGitter> <bew> I'm suggesting the addition of `buf.to_slice.copy_from(str.to_slice, truncate: true)` to copy str.to_slice to buf.to_slice but truncating to the size of buf when str is too big
<FromGitter> <stronny> what I mean is ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ is that okay? [https://gitter.im/crystal-lang/crystal?at=5e59c2cdff6f6d2e8876adbd]
<FromGitter> <bew> no not okay
<FromGitter> <stronny> because the pointer is only valid inside the function right?
<FromGitter> <bew> well yes, once you return from the function the static array won't be accessible anymore, and the slice could do some harm to something else
<FromGitter> <stronny> right, that's what I've thought
<FromGitter> <bew> you should either return the staticarray, and only use slices on them when you want to do manipulations on the content, but never return a slice of a value type (like staticarray)
<FromGitter> <bew> -either
<FromGitter> <stronny> no I wouldn't do that at all, I'm musing on the SA#to_slice in general
<FromGitter> <bew> okay :D
<FromGitter> <stronny> I don't think other Values have to_slice or to_unsafe
<FromGitter> <bew> hmm true
<FromGitter> <bew> there is BitArray
<FromGitter> <stronny> indeed
<postmodern> does crystal support something like super(*) ?
<FromGitter> <Blacksmoke16> just `super`
<postmodern> Blacksmoke16, if you have a base class that defines #initialize(@foo = 1) what's the preferred way to inherit from the class, define another #initialize that passes the optional argument `foo` down properly via super?
<FromGitter> <Blacksmoke16> does the child class need to define any ivars of its own?
<postmodern> Blacksmoke16, yes, and call super so the super-classes ivars also get defined
<FromGitter> <Blacksmoke16> ```def initialize(@child_var : Bool, foo : Int32 = 1) ⏎ super foo ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e59cf25ca2f5a558d57c2be]
<FromGitter> <Blacksmoke16> is what i do
<postmodern> Blacksmoke16, hmm so the default value logic of foo get's copied in the child class?
<FromGitter> <Blacksmoke16> right
<FromGitter> <Blacksmoke16> otherwise i dont know of a way to have it still be optional
<FromGitter> <Blacksmoke16> as if you remove the default it becomes required, and there isnt a type/value that would allow triggering the default of another method
<FromGitter> <Blacksmoke16> ```def initialize(@child_var : Bool, foo : Int32 | Undefined = undefined) ⏎ super foo ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e59d0058e04426dd0129661]
<FromGitter> <Blacksmoke16> would be kidnda cool
<FromGitter> <Blacksmoke16> `undefined` represents no value, different than `nil`, would act like as if it wasnt provided, which would use the default value of defined :shrug:
<FromGitter> <Blacksmoke16> workaround would be like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e59d098376d882250c08cd9]
<FromGitter> <Blacksmoke16> but i find it better to just duplicate the default :shrug:
<postmodern> normally in ruby i'd probably do def initialize(arg = nil); super(*arg); ...; end, since *splat omits nils.
<FromGitter> <Blacksmoke16> sec
<postmodern> when tagging releases of shards, do you use vX.Y.Z or just X.Y.Z? or are git tags not really necessary with shards?
<FromGitter> <Daniel-Worrall> shards use git tags
<FromGitter> <Daniel-Worrall> vX.Y.Z iirc
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8nce
<FromGitter> <Blacksmoke16> i guess that would work too
<FromGitter> <Blacksmoke16> and yea, it should use the `v` prefix afaik
<postmodern> and do shards typically not have an explicit ChangeLog file?
<FromGitter> <Blacksmoke16> It's not a requirement in the spec
<FromGitter> <Blacksmoke16> I usually have the changelog in the GitHub release
<postmodern> do developers typically explicitly define the types of arguments/return-values of methods for the documentation, or do developers just let crystal infer the types?
gangstacat has quit [Ping timeout: 272 seconds]
<postmodern> finally got digest-crc.cr building and tagged v0.1.0. now crystal developers can work with weird/obscure CRC algorithms used in binary protocols. https://github.com/postmodern/digest-crc.cr#readme
gangstacat has joined #crystal-lang
<FromGitter> <watzon> Wooo
<FromGitter> <watzon> @postmodern as far as the documentation goes I'd say it depends. In many cases people rely on inferred types, in which case I'd say it's very important to do the Ruby thing and say what each parameter is and what types it should be accepting. I tend to not rely on type inference very much, but I still like to explain what each parameter is.
_whitelogger has joined #crystal-lang
postmodern has quit [Read error: Connection reset by peer]
postmodern has joined #crystal-lang
_whitelogger has joined #crystal-lang
commavir has quit [Excess Flood]
commavir has joined #crystal-lang
<postmodern> watzon, would be cool if crodoc could infer the types and fill that info in
<postmodern> is foo : UInt16 = 0x00_u16 redundant?
<postmodern> watzon, noticed some stuff in the stdlib do not specify types of arguments, but do for the return values. Example: Digest::Base
<postmodern> ugh github flavored markdown, while it does make your README look slick on github.com, makes the README look broken AF in your `crystal docs`.
sz0 has quit [Quit: Connection closed for inactivity]
_ht has joined #crystal-lang
<Andriamanitra> i'm probably just stupid but how do you call a method from a different file and module?
<Andriamanitra> or is there even a way to do something equivalent to python's "from x import y"?
_whitelogger has joined #crystal-lang
dwdv has joined #crystal-lang
<FromGitter> <asterite> how are you doing it?
<Andriamanitra> i've tried like 15 different ways and nothing seems to work, i think i'm just understanding something completely wrong
<FromGitter> <asterite> postmodern: I sent a PR in the past to use a better markdown version internally in the compiler. It was rejected to avoid issues. But all I can see is people complaining about it. Maybe I'll try sending a PR again, see if it gets accepted this time.
<FromGitter> <asterite> Andriamanitra: you just `require`the file and call the method
<FromGitter> <asterite> also this is not python, all top level methods are in the same global namespace
<Andriamanitra> yeah that's why i'm using modules to separate the namespaces
<Andriamanitra> but i would like to call one specific method from another module
<FromGitter> <asterite> you need to define the method as `def self. foo` if you want to call it with the module prefix
<Andriamanitra> ah thanks, i didn't realize the "self." part was required
<FromGitter> <asterite> Actually, I'm not sure where class methods are explained...
<FromGitter> <asterite> Though it doesn't mention modules specifically...
_whitelogger has joined #crystal-lang
sz0 has joined #crystal-lang
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
postmodern has quit [Quit: Leaving]
sagax has quit [Ping timeout: 265 seconds]
sagax has joined #crystal-lang
<FromGitter> <andrewc910> `@controller.link_to(_arg0, _arg1, class: class)` ⏎ `@controller` is an amber controller. `link_to` is a jasper view helper method. ⏎ ⏎ I am using `forward_missing_to @controller` & this is the error i get: ⏎ `Error: can't define class inside def` ... [https://gitter.im/crystal-lang/crystal?at=5e5aa04a376d882250c248ac]
<FromGitter> <Blacksmoke16> try renaming `class` to `klass`
<FromGitter> <andrewc910> Can't. That's a jasper thing otherwise i would.
<FromGitter> <andrewc910> Jasper lets do you `link_to "/", class: "btn"` which returns `<a href="/" class="btn"></a>`
<FromGitter> <tenebrousedge> `class : klass`
<FromGitter> <tenebrousedge> you can't use `class` as a var name. Keyword argument, yes. Hash key, yes. var name no.
DTZUZU2 has quit [Ping timeout: 258 seconds]
<FromGitter> <andrewc910> It's not a var name? `link_to("Edit", "/profile/edit", class: "btn btn-success btn-sm")` this is the actual line in my view that's causing this error
<FromGitter> <Blacksmoke16> got the full stack trace? can run with `--error-trace`
<FromGitter> <andrewc910> Let me put it in pastebin real quick
<FromGitter> <andrewc910> https://pastebin.com/Ad0ZpXTD
<FromGitter> <andrewc910> Line 104 is where it moves into more specific code instead of just amber stuff
<FromGitter> <tenebrousedge> ```Which expanded to: ⏎ ⏎ > 1 | @controller.link_to(_arg0, _arg1, class: class)``` [https://gitter.im/crystal-lang/crystal?at=5e5aa208ff6f6d2e88788f67]
<FromGitter> <tenebrousedge> `class` is being used as a variable name
<FromGitter> <Blacksmoke16> yea, sure seems like something is using the `class` var name
<FromGitter> <Blacksmoke16> prob from forward missing to?
<FromGitter> <Blacksmoke16> what does that macro code look like?
DTZUZU2 has joined #crystal-lang
<FromGitter> <andrewc910> ```# Render Handler ⏎ def user_show ⏎ render("user/show.ecr") ⏎ end``` ⏎ ⏎ `<%= link_to("Edit", "/profile/edit", class: "btn btn-success btn-sm") %>` ⏎ ⏎ Because render handler is the class the invoked render, this is the class all view methods look at for definition. Forward to controller because that's typically what invokes render. [https://gitter
<FromGitter> ... .im/crystal-lang/crystal?at=5e5aa2ddca2f5a558d597f05]
<FromGitter> <Blacksmoke16> right, but what does the macro look like
<FromGitter> <andrewc910> Oh, the `link_to` macro?
<FromGitter> <andrewc910> If so, ill go find it!
<FromGitter> <Blacksmoke16> sec
<FromGitter> <andrewc910> `link_to` method definition ⏎ https://github.com/amberframework/jasper-helpers/blob/master/src/jasper_helpers/links.cr ⏎ ⏎ Invokes `content` which is here: ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5e5aa3bacb91b5224f016654]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8nfi
<FromGitter> <andrewc910> So this is a crystal caveat?
<FromGitter> <Blacksmoke16> `forward_missing_to` expands to `@string.link_to(class: class)`
<FromGitter> <Blacksmoke16> uses the name of the named arg as the var for the forwarded call
<FromGitter> <andrewc910> And during this, it renames the values for key `class` to the key name?
<FromGitter> <andrewc910> Will `missing_method` be invoked before `forward_missing_to`? I can just create a custom method for `link_to` and `button_to`
<FromGitter> <Blacksmoke16> you could define a custom `link_to` method so that it doesnt hit `forward_missing_to`
<FromGitter> <andrewc910> duh.
<FromGitter> <andrewc910> Thank you! :)
<FromGitter> <Blacksmoke16> np
<FromGitter> <andrewc910> Okay, including the jasper module fixed it without having to copy/paste code. I don't want jasper as a dependency though. Does crystal support something like "include if X defined". I know you can include things via macros. Not sure how to check if X module is defined.
<FromGitter> <Blacksmoke16> best way would have the use do an explicit require
<FromGitter> <Blacksmoke16> like `require "mochi/ext/jasper"` or something
<FromGitter> <Blacksmoke16> the user*
<FromGitter> <andrewc910> That's what i thought. Was hoping for something a bit more elegant. ⏎ ⏎ What's `ext` folders typically used for?
<FromGitter> <andrewc910> Extension. dug
<FromGitter> <andrewc910> duh*
<FromGitter> <Blacksmoke16> most of the time used for extending stdlib types, but also seems relevant for extra code the user can require :shrug:
<FromGitter> <andrewc910> Yeup, extension it is!
<FromGitter> <andrewc910> Thanks everyone :)
<FromGitter> <dscottboggs_gitlab> I've run into the second shard I want to build which requires generating code from a data structure/config file. Here I go again, trying to understand the compiler
<FromGitter> <dscottboggs_gitlab> in this line (https://github.com/crystal-lang/crystal/blob/76aa6556805f26dda30ec20686970ea8846f7cec/src/compiler/crystal/compiler.cr#L13) a `record` is declared, but with no types. How does that work?
<FromGitter> <dscottboggs_gitlab> oh, I see, that was old
njs5i has joined #crystal-lang
njs5i has quit [Client Quit]
<FromGitter> <tenebrousedge> > The properties can be type declarations or assignments. ⏎ ⏎ Interesting
<FromGitter> <dscottboggs_gitlab> yeah so you can do like `record x = 1, y : String` but not just `record x, y`
njs5i has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> I don't think the line I linked to has been valid crystal code for a very long time
<njs5i> hi! how to use dir.[] with patterns? I did not understand the docs
<FromGitter> <tenebrousedge> `Dir.glob` is usually where it's at
<FromGitter> <dscottboggs_gitlab> njs5i you know how when you're at a terminal, if you type `ls` you get all the files, but if you type `ls prefixed*` you will only get files that begin with *prefixed*?
<njs5i> FromGitter, no, I did not know that, always used grep, thanks!
<FromGitter> njs5i, I'm a bot, *bleep, bloop*. I relay messages between here and https://gitter.im/crystal-lang/crystal
<FromGitter> <dscottboggs_gitlab> np
<njs5i> but that still does not help the other problem
<FromGitter> <dscottboggs_gitlab> FYI it's generally discouraged to grep the output of ls. You should use glob syntax with `find -name` instead
<njs5i> how can i write something like dir.each do |f| ...
<FromGitter> <stronny> what do you want to do?
<FromGitter> <dscottboggs_gitlab> `Dir.each "some-dir" do |f|...`?
<njs5i> https://crystal-lang.org/api/0.32.1/Dir.html#[](*patterns):Array(String)-class-method
<FromGitter> <stronny> first and foremost: filter out `.` and `..`
<njs5i> how to call this
<FromGitter> <dscottboggs_gitlab> file:///usr/share/doc/crystal/api/Dir.html#each_child(dirname,&)-class-method
<FromGitter> <tenebrousedge> `Dir.children` is also a thing
<njs5i> yeah, I was just curious how to call a "[]" method :)
<FromGitter> <dscottboggs_gitlab> just a sec
<FromGitter> <tenebrousedge> `Dir[/pattern/]`
<FromGitter> <tenebrousedge> but I would probably do `Dir.glob`
<FromGitter> <dscottboggs_gitlab> the reason I posted the `ls` example was because `Dir.[]`works similarly. `Dir["./prefixed*"]` would return files in the current PWD which begin with prefixed
<FromGitter> <dscottboggs_gitlab> see https://crystal-lang.org/api/0.32.1/File.html#match?(pattern:String,path:Path%7CString)-class-method for the glob syntax
<njs5i> 12 | dir[/.*/].each do |f|
<njs5i> ^
<njs5i> Error: undefined method '[]' for Dir
<FromGitter> <tenebrousedge> it's a class method
<njs5i> aah, it works on module
<FromGitter> <dscottboggs_gitlab> yes
<njs5i> ok, "static" in C++
<FromGitter> <dscottboggs_gitlab> also you need to pass it a string, not a regex
<FromGitter> <tenebrousedge> ^
<njs5i> ok, so if I talk about instance, than I go with just filtering
<FromGitter> <stronny> what is it that you are doing? dir globbing is rarely useful
<njs5i> I just need to go over all files in a dir
<njs5i> and select those starting with number
<FromGitter> <stronny> no recursion, jsut one level?
<njs5i> now yes
<njs5i> but I am still figuring how to read the docs
<njs5i> it's literally my second program in Crystal
<FromGitter> <stronny> do you have Ruby background?
<njs5i> no
<FromGitter> <stronny> right
<FromGitter> <stronny> it's different from ++
<njs5i> well good, C++ is crazy
<FromGitter> <stronny> indeed
<njs5i> I'm looking for a statically typed python alternative
<FromGitter> <dscottboggs_gitlab> @stronny I don't think it's much like ruby either haha
<njs5i> I did not like Nim
<FromGitter> <dscottboggs_gitlab> Hey that's how I found crystal!
<njs5i> anyway, are there examples?
<FromGitter> <stronny> so anyway, for one level glob is fine, for recursion Find is better, but looks like Crystal stdlib doesn't have it
<FromGitter> <tenebrousedge> `Dir["./[0-9]"]` maybe
<FromGitter> <dscottboggs_gitlab> njs5i, I think you need `Dir["/base/[0-9]*"]`
<FromGitter> <stronny> it's similar to Ruby in the way the docs are organized, not in every sense of course
<njs5i> but how do I call this
<njs5i> def self.glob(*patterns, match_hidden = false) : Array(String)
<njs5i> that's an insatnce method, right?
<njs5i> guessing from self
<FromGitter> <tenebrousedge> no
<FromGitter> <stronny> no, self. is class mehod
<FromGitter> <stronny> the other way around, instance methods do not start with self.
<njs5i> ok, cool
<njs5i> so I see now that I need to just filter the array myself
<FromGitter> <tenebrousedge> `Dir.glob("./[0-9]*")`
<njs5i> thanks!
<FromGitter> <stronny> so you type `Dir.glob( ... ) do |<args>| <code> end`
<FromGitter> <dscottboggs_gitlab> njs5i you can't do `def self.some_method()` in python because `self` isn't known at that point. In Crystal, `self` impleictly refers to the current context. when defining a method on a class, `self` is the class. Inside of a method, `self` is the instance.
<FromGitter> <stronny> `[]` is special, it's defined like other methods, but called without a dot and parens
<njs5i> great! thanks!
<FromGitter> <dscottboggs_gitlab> `.[]` in crystal is the equivalent of `__getitem__` in python
<FromGitter> <stronny> so `receiver[1,2,3]` === `receiver.[](1,2,3)`
<FromGitter> <dscottboggs_gitlab> fuck I should do a Python->Crystal tutorial
<FromGitter> <stronny> I think there are Python<=>Ruby
<FromGitter> <stronny> and syntax is mostly similar
<njs5i> thanks!
<FromGitter> <dscottboggs_gitlab> yeah but metaprogramming is very different in crystal v ruby
<FromGitter> <dscottboggs_gitlab> and that wouldn't cover things like structs or slices
<njs5i> is there a source with small examples, like FAQ or something so I don't bother you with trivial questions like that?
<FromGitter> <stronny> by the time its needed basics should already be covered
<FromGitter> <stronny> there is
<FromGitter> <tenebrousedge> in the crystal compiler there are examples
<FromGitter> <dscottboggs_gitlab> njs5i I recommend starting with the book https://crystal-lang.org/reference/
<FromGitter> <stronny> start here https://crystal-lang.org/reference/overview/
<FromGitter> <dscottboggs_gitlab> I read it (mostly) front-to-back as my intro to crystal
<FromGitter> <dscottboggs_gitlab> oh wow, that's been expanded
<FromGitter> <tenebrousedge> I didn't read much of the book when I started Crystal, but I absolutely should have
<FromGitter> <stronny> yeah, it's very helpful
<FromGitter> <stronny> by the way, most python people would choose golang I imagine, care to comment on your choice? ;)
<FromGitter> <dscottboggs_gitlab> I tried golang
<FromGitter> <dscottboggs_gitlab> could not handle the error handling system
<FromGitter> <dscottboggs_gitlab> plus, crystal's type inference system matches up a lot closer to python's duck typing than any other language, Ruby included. The only other language that even comes close that I know of is Kotlin.
<FromGitter> <stronny> what do you mean Ruby included?
<FromGitter> <dscottboggs_gitlab> I mean ruby's type system is looser than crystal's or python's. Things like overloading `.+` on `Number` for `String` and vice-versa makes ruby seem closer to js or php than python IMO
<FromGitter> <stronny> of course inference is cool, but I've noted that with time I started typing manually more and more
<FromGitter> <dscottboggs_gitlab> I use type hints when writing python to get type-checking at the editor level
<FromGitter> <tenebrousedge> overloading isn't really relevant to the weakness or strength of the type system
<FromGitter> <stronny> you mean overriding? you can do that in Crystal as well
<FromGitter> <tenebrousedge> Crystal could do that as well
<FromGitter> <stronny> Ruby doesn't have overloading
<FromGitter> <dscottboggs_gitlab> yes I meant overriding...
<FromGitter> <dscottboggs_gitlab> actuall y I think I meant implementing
<FromGitter> <tenebrousedge> whatever word you use, we're talking about the same functionality
<FromGitter> <dscottboggs_gitlab> regardless, the fact that crystal and python chose *not* to implement that is an example of how their type systems feel more similar
<FromGitter> <stronny> Crystal asolutely does implement that
<FromGitter> <dscottboggs_gitlab> `1 + "1"` doesn't work
<FromGitter> <dscottboggs_gitlab> compile time error
<FromGitter> <tenebrousedge> but there's no reason why it couldn't work
<FromGitter> <tenebrousedge> the type system would allow it
<FromGitter> <tenebrousedge> assuming that you cast it appropriately
<FromGitter> <stronny> `class Int32; def +(s : String); ... end end`
<FromGitter> <dscottboggs_gitlab> `assuming that you cast it appropriately` you can't make that assumption though
<FromGitter> <dscottboggs_gitlab> @stronny sure you *could* implement it, but the language doesn't
<FromGitter> <tenebrousedge> you can make that assumption just as much as you can in Ruby
<FromGitter> <tenebrousedge> and it wouldn't be a feature of the type system either way
<FromGitter> <dscottboggs_gitlab> true
<FromGitter> <tenebrousedge> Ruby doesn't have auto-casting in the same sense that JS or PHP do
<FromGitter> <stronny> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e5abb98376d882250c28250]
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <dscottboggs_gitlab> well then
<FromGitter> <dscottboggs_gitlab> I stand corrected
<FromGitter> <dscottboggs_gitlab> this is what I get for talking at all about a language I rarely write in
<FromGitter> <stronny> here's working code: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ prints "2" [https://gitter.im/crystal-lang/crystal?at=5e5abc5acb91b5224f019dd0]
<FromGitter> <dscottboggs_gitlab> I know that it can work, but it doesn't out-of-the box and until you really dig in and learn how to use the language it's not obvious that that's possible
<FromGitter> <stronny> that was one of my big problems with python: closed classes
<FromGitter> <stronny> sure it's """safer""", but come on ⏎ you can't have no fun with an unloaded gun
<FromGitter> <dscottboggs_gitlab> hell yeah
<FromGitter> <dscottboggs_gitlab> although I did discover how to reopen *some* classes in python
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e5abdf590a8295824f8707a]
<FromGitter> <dscottboggs_gitlab> so like it's a language feature, they just make it so you can't reopen any of the stdlib types
<FromGitter> <stronny> right
<FromGitter> <stronny> lambdas are also a disaster by the way
<FromGitter> <dscottboggs_gitlab> right? haha
<FromGitter> <tenebrousedge> oh?
* FromGitter * tenebrousedge hasn't done much python
<FromGitter> <dscottboggs_gitlab> I mean, TBH I kinda feel like blocks don't make a ton of sense. They're just callbacks. Like the syntax looks nice but I feel like it could go further and offer multiple callbacks
<FromGitter> <dscottboggs_gitlab> @tenebrousedge you can only define a lambda/function literal in python that is exactly one line
<FromGitter> <tenebrousedge> oh dear
<FromGitter> <dscottboggs_gitlab> haha yeah
<FromGitter> <stronny> and is an expression ⏎ and NOT everything is an expression
<FromGitter> <dscottboggs_gitlab> oh?
<FromGitter> <stronny> a = b isn't
<FromGitter> <dscottboggs_gitlab> oh jeeze, you're right
<FromGitter> <tenebrousedge> I don't know about multiple callbacks, but `Proc#<<` and `Proc#>>` would be nice
<FromGitter> <dscottboggs_gitlab> Care to provide an example?
<FromGitter> <dscottboggs_gitlab> sounds useful perhaps
* FromGitter * tenebrousedge points to the Ruby implementation
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <dscottboggs_gitlab> I was thinking like ⏎ ⏎ ```File.open "some file", do |file| ⏎ ... ⏎ end, on_error: do |error| ⏎ ... ⏎ end``` ⏎ ⏎ I realize it's a contrived example because exceptions handle this case, but there are cases where providing multiple callbacks are useful. [https://gitter.im/crystal-lang/crystal?at=5e5abff64eefc06dcf27d3de]
<FromGitter> <tenebrousedge> I could see an `Enumerable#apply` method that would take multiple procs as an argument
<FromGitter> <tenebrousedge> and apply them in order
<FromGitter> <tenebrousedge> but you could do the same thing with `Proc#<<` and `Proc#>>` without being tied to `Enumerable`
<FromGitter> <dscottboggs_gitlab> I mean, we have `parallel`
<FromGitter> <dscottboggs_gitlab> > Proc#<< and Proc#>> would be nice ⏎ ⏎ has this been suggested?
<FromGitter> <tenebrousedge> o__o
<FromGitter> <tenebrousedge> iono
<FromGitter> <tenebrousedge> I think the implementation is trivial
<FromGitter> <dscottboggs_gitlab> I mean, I know `|>` was turned down, but this seems more reasonable. Open an issue suggesting it, why not?
<FromGitter> <tenebrousedge> hmm. Okay, but I'mma kill some aliens first
<FromGitter> <dscottboggs_gitlab> oh that sounds nice
<FromGitter> <tenebrousedge> XCOM: Enemy Within, with the Long War mod
<FromGitter> <stronny> multiple blocks seem impossible to do reasonably syntax-wise, k-v style you have them right now, why not
<FromGitter> <stronny> as for function composition that plays nice with function languages, here it's mostly moot imo
njs5i has quit [Quit: Leaving]
<FromGitter> <stronny> idk about `Enumerable#apply *&blocks`, I would still use `blocks.each {|block| Enumerable.map! &block}`
<FromGitter> <stronny> what /would/ be nice is reducing |args| boilerplate, maybe something like implicit `$1, $2, $3` args or whatnot
<FromGitter> <tenebrousedge> `blocks.reduce(obj) { |memo, block| block.call(memo) }`
<FromGitter> <tenebrousedge> `map!` only if profiling suggested that would be beneficial
<FromGitter> <stronny> I would do that with iterators, because sequential maps probs benefit from lazyness
<FromGitter> <tenebrousedge> one thing that would reduce arg boilerplate would be if you could bind args in a partial from the left instead of the right
<FromGitter> <stronny> curry?
<FromGitter> <stronny> syntaxtically heavy imo
<FromGitter> <tenebrousedge> but doesn't require new syntax
<FromGitter> <stronny> Ruby has it, I don't use it
<FromGitter> <tenebrousedge> Ruby as far as I know also does not let you curry from the right
<FromGitter> <tenebrousedge> but having options to do these things is always nice
<FromGitter> <stronny> oh, from the right. that would take some effort yes
<FromGitter> <stronny> one problem would be *args, another default values
<FromGitter> <stronny> implicit hash at the end and the block itself
<FromGitter> <stronny> Ruby syntax doesn't play well with FP
<FromGitter> <stronny> (not that I've seen right-side curry anywhere before)
<FromGitter> <tenebrousedge> well, given that it won't be added any time soon, and so I don't have to be realistic about it, I'm going to hand-wave all potential problems with the idea as trivial
<FromGitter> <tenebrousedge> 👋
<FromGitter> <stronny> in that case I concur!
<FromGitter> <tenebrousedge> 😁
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
_ht has quit [Quit: _ht]
<FromGitter> <smalls12> I made a library with crystal init, when I run `crystal spec` it says `Error: undefined fun 'to_s'`
<FromGitter> <smalls12> error from here ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e5adf83d045e2582507485f]
<FromGitter> <tenebrousedge> what's your spec file look like?
<FromGitter> <tenebrousedge> particularly the describe block referenced in the error trace right before that
<FromGitter> <smalls12> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e5ae02dca2f5a558d5a0bb2]
<FromGitter> <smalls12> so empty I guess
<FromGitter> <asterite> Just for fun: https://play.crystal-lang.org/#/r/8ng8
<FromGitter> <tenebrousedge> D:
<FromGitter> <tenebrousedge> @asterite where do you stand on adding something like that to stdlib?
<FromGitter> <asterite> @smalls12 it's a bug, I just reported it: https://github.com/crystal-lang/crystal/issues/8867
<FromGitter> <asterite> @smalls12 you need to do `describe "Libtest"` for now
<FromGitter> <asterite> @tenebrousedge I'm happy to merge that functionality in the standard library! They are just one liners, they are generally useful (even if most won't end up using them), and it's a great showcase of what Crystal can accomplish :-)
<FromGitter> <asterite> @dscottboggs_gitlab blocks and lambdas or callbacks are completely different
<FromGitter> <smalls12> @asterite ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5e5ae21653fa513e285fdb9d]
<FromGitter> <smalls12> like this ?
<FromGitter> <dscottboggs_gitlab> @asterite in what way?
<FromGitter> <dscottboggs_gitlab> I mean, besides being inlined
<FromGitter> <asterite> @smalls12 no, you have to surround Libtest with double quotes. The bug is that libs don't implement `to_s`
<FromGitter> <asterite> @dscottboggs_gitlab returning from a block returns from the outer method, not from the block. Then you have `break` and `next`. These are the essential differences.
<FromGitter> <asterite> they let blocks extend control flow in a way that's not possible in other languages
<FromGitter> <dscottboggs_gitlab> ah, that's a good point
<FromGitter> <smalls12> @asterite ah thanks
<FromGitter> <dscottboggs_gitlab> but isn't that possible with typical closure/lambda syntax which would give the ability to have multiple blocks applied to a single method?
<FromGitter> <asterite> yes, the syntax can be different. The semantic is what makes them different
<FromGitter> <asterite> and I guess you do need a way to distinguish them syntactically...
<FromGitter> <dscottboggs_gitlab> ok. Thanks 👍
<FromGitter> <asterite> I guess multiple blocks could be a thing, I'm not sure... but I don't think it'll happen
<FromGitter> <dscottboggs_gitlab> me either
<FromGitter> <dscottboggs_gitlab> hha
<FromGitter> <dscottboggs_gitlab> I don't think it looks good with crystal syntax
<FromGitter> <dscottboggs_gitlab> it was relearning kotlin after learning crystal that gave me the idea.
<FromGitter> <asterite> ah, yes, kotlin has many things similar to crystal, but done in a better way (in my opinion)
<FromGitter> <asterite> like you can inline blocks too, and they have something similar to `with ... yield`, but better
ur5us has joined #crystal-lang
ur5us has quit [Quit: Leaving]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang