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
<FromGitter> <mixflame> my crystal site is live https://www.gbaldraw.fun/
<FromGitter> <mixflame> warning, it tries to connect you to a video call
DTZUZU_ has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 260 seconds]
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 260 seconds]
<FromGitter> <caspiano> i'm trying to use the compiler directly in one of my projects (I need to traverse the requires of a crystal entrypoint), I'm also doing this in an alpine environment. ⏎ ⏎ the main thing that's blocking me is the missing `llvm_ext.o` object, which i see is dropped in the Dockerfile for alpine ⏎ ⏎ would i be better off trying to do this in the ubuntu container (doesn't look like `llvm_ext.o` is
<FromGitter> <elorest> Does anyone have experience using `YAML.build do |yaml|`?
<FromGitter> <elorest> I've tried pretty much everything I can imagine to nest yaml in yaml.
<FromGitter> <elorest> https://carc.in/#/r/b6pd
<FromGitter> <elorest> Here's a simple example.
<FromGitter> <elorest> I can always do it by creating an enormous deep nested hash and call `#to_yaml` but it feels wrong on so many levels.
<FromGitter> <elorest> This works well but is seems like using a yaml builder would be better: https://gist.github.com/elorest/ac94401211a68ccc52674ce90334d503
hendursaga has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang
hendursaga has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 260 seconds]
postmodern has quit [Quit: Leaving]
sagax has joined #crystal-lang
<jhass> elorest: ain't pretty, looks like the API design could be improved https://carc.in/#/r/b6po
<jhass> 1) inside a mapping every two scalar's form a key value pair
<jhass> 2) adding .to_yaml as a scalar will add it as a string
<jhass> maybe a little prettier? idk https://carc.in/#/r/b6pq
DTZUZU_ has quit [Read error: Connection reset by peer]
DTZUZU_ has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
hendursaga has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 260 seconds]
DTZUZU_ has joined #crystal-lang
<deavmi> Is this room on oftc of libera.chat?
<deavmi> *or
<straight-shoota> nope
<deavmi> oh
<jhass> We still have to discuss internally how to go on :)
<jhass> For now nothing is broken here
<Stephie> the room is reserved on libera but that is all for now
<Stephie> for that matter, does anyone else on the core team want permissions to handle it?
<jhass> I'll happily take the temporary hat if you want it off your things :)
sorcus has quit [Quit: WeeChat 3.1]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Client Quit]
sorcus has joined #crystal-lang
naqvis has joined #crystal-lang
<FromGitter> <Dan-Do> Is it possible to make a proc without declaring type of arguments?
<FromGitter> <Dan-Do> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60a7ea11688a2624b8a3b5e4]
<FromGitter> <Blacksmoke16> no
<FromGitter> <Blacksmoke16> prob best to rethink your design id say
<FromGitter> <Dan-Do> `Error: no overload matches 'Proc(String, Hash(String, Bool | Int32 | String), Hash(String, String))#call' with types String, Hash(String, Bool | Hash(String, String) | Int32 | String)`
<FromGitter> <tenebrousedge> no, but you can capture blocks and use `yield` instead
<FromGitter> <Dan-Do> yeah, let me try to re-write the code
<FromGitter> <tenebrousedge> `String|Int32|Bool` seems awkward to deal with
<naqvis> most of the times I just wonder, how dynamic languages have spoiled its user at the ease of development
<FromGitter> <tenebrousedge> well, I don't know about spoiling, but Crystal lends itself well to the use of structs instead of catch-all data structures, just because of the type system
<FromGitter> <tenebrousedge> I usually tend to view this as a good thing, particularly with how easy it is to define structs and aliases
<naqvis> yeah, i was trying to made my point for dynamic languages without any type system and put anything in any data structure approach
<naqvis> and that's what i was referring to as "spoil its users"
<FromGitter> <Dan-Do> I am stuck at this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60a7ece7d0f55b33baff31e4]
<FromGitter> <Dan-Do> How to call transform_data first each render?
<FromGitter> <tenebrousedge> I mean can't you yield from `render`?
<FromGitter> <tenebrousedge> `@my_data.each {|e| yield e, layout }`
<FromGitter> <Dan-Do> No, because I have many Foo instance, each instance has its own transform_data
<FromGitter> <Blacksmoke16> make the method abstract protected and implement it for each child?
<FromGitter> <Blacksmoke16> then the parent foo type's render method can just call that abstract method
<FromGitter> <Dan-Do> the data is not so generic, example ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60a7ee3bbdecf719a06fc85a]
<FromGitter> <Blacksmoke16> oh, so you only have 1 `Foo` type? not a subclass for each type of transformation?
<FromGitter> <Dan-Do> It has subclass, but the data changes so we cannot make it abstract class
<FromGitter> <Blacksmoke16> gotcha
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 240 seconds]
<FromGitter> <Dan-Do> I can convert the conplex hash to only Hash(String, String), but I dont love that idea :)
<FromGitter> <Dan-Do> `complex
<FromGitter> <Blacksmoke16> whats the problem exactly?
<FromGitter> <Blacksmoke16> just trying to get that earlier code example to work?
<FromGitter> <Dan-Do> yeap, I want to transform input_data to my_data, but the transform code is declare outside, not inside class
<FromGitter> <naqvis> @Dan-Do data type you are passing to your proc doesn't meet the signature
<FromGitter> <Blacksmoke16> so whats wrong with that `foo.transform_data do |layout, data, transpile_data|` approach instead of using a proc?
<FromGitter> <naqvis> what you are passing is of type `Hash(String, Bool | Hash(String, String) | Int32 | String)`
<FromGitter> <naqvis> while you have set the signature as `Hash(String, String|Int32|Bool)`
<FromGitter> <Dan-Do> @naqvis yeah, that's the problem. The data can be anything of Hash(String, Anything)
<FromGitter> <Blacksmoke16> gl
<FromGitter> <Blacksmoke16> thats a bad design in crystal land imo
<FromGitter> <Blacksmoke16> closest thing you could get is like `Hash(String, SomeContainer(T))`
<FromGitter> <Dan-Do> @Blacksmoke16 the thing is, it currently work with the instance variable
<FromGitter> <Dan-Do> something like this
<FromGitter> <naqvis> then use `JSON::Any` :P
<FromGitter> <naqvis> `Hash(String, JSON::Any)`
<FromGitter> <Dan-Do> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=60a7f36d43fc4a24c5b9d284]
<FromGitter> <Blacksmoke16> i feel like there has to be a better way to do this...
<FromGitter> <Dan-Do> atm, I use above code. Just want know if there is any better design
<FromGitter> <Blacksmoke16> are there a set amount of transformations? Or are they totally arbitrary
<FromGitter> <tenebrousedge> also can we do `Foo.new {|bar, baz| bar.transform } ` ?
<FromGitter> <Blacksmoke16> it would also help to know what this data is and how its used
<FromGitter> <Dan-Do> arbitrary, some time `web_data["error_message"]` as String, some time `web_data["amount"]` as Int, some time `data["user"]` as Hash...
<FromGitter> <Blacksmoke16> is this some sort of homegrown templating engine or something?
<FromGitter> <Dan-Do> You're correct :)
<FromGitter> <Blacksmoke16> solution here is just dont do that and use something better :)
<FromGitter> <naqvis> @Dan-Do also out of context to your current question, but line `if user = data["user"]` should be written as `if user = data["user"]?`
<FromGitter> <Blacksmoke16> https://github.com/straight-shoota/crinja comes to mind
<FromGitter> <naqvis> notice the *?* at the end
<FromGitter> <naqvis> this will avoid exception when the data passed doesn't contain the "user" key
<FromGitter> <Dan-Do> ah, thanks @naqvis :)
<FromGitter> <Dan-Do> > https://github.com/straight-shoota/crinja comes to mind ⏎ ⏎ Unfortunately it's difficult to write SPA using crinja, isn't it? :)
<FromGitter> <naqvis> since the data you are passing is unstructured (or you don't know the exact structure) of data, it make more sense to pass your data as json or string and then do the parsing in transformation
<FromGitter> <naqvis> because for unstructured data, you can't define a structure with known fields
<FromGitter> <Blacksmoke16> how do you have it setup then? normally a SPA is using js to change/manage the view and stuff. If you have crystal doing that it would be server rendered HTMl and not really an SPA anymore
<FromGitter> <Dan-Do> the crystal will render page when js is disabled
<FromGitter> <Blacksmoke16> i remember talking about this a while ago
<FromGitter> <Dan-Do> :)
<FromGitter> <Blacksmoke16> sounds neat but really complex
<FromGitter> <Dan-Do> I have a work around then, but want to find if I can use pro literal
<FromGitter> <naqvis> @Dan-Do https://play.crystal-lang.org/#/r/b6vf
<FromGitter> <naqvis> something like this
naqvis has quit [Quit: Connection closed]
<FromGitter> <Dan-Do> @naqvis that's great, though I have to change for some subclass :)
<FromGitter> <Dan-Do> It's better now
<FromGitter> <naqvis> also better to use alias to represent your proc type ⏎ `alias RenderProc = Proc(String, JSON::Any, Hash(String, String))`
<FromGitter> <naqvis> this will save you some typing
<FromGitter> <tenebrousedge> and one for the `Hash(String, String)` too
<FromGitter> <tenebrousedge> aliases ftw
<FromGitter> <Dan-Do> thanks guys for the help
<FromGitter> <Dan-Do> 👍
<FromGitter> <tenebrousedge> I'm also fond of using (e.g.) `alias Label = String`. Any time I can be more specific about what things are, the easier time I'm going to have modifying that code in the future
<FromGitter> <elorest> <jhass> that scalar thing was exactly what I was missing. Thanks a lot.
Seich has quit [Quit: Gone fishing.]
maxpowa has quit [Ping timeout: 260 seconds]
maxpowa has joined #crystal-lang
<FromGitter> <jrei:matrix.org> hum too bad
<FromGitter> <jrei:matrix.org> the automated crystal installation script takes my system, Debian 11 unstable, as Debian_11 instead of Debian_Unstable
<FromGitter> <jrei:matrix.org> I doubt it can be easily solved...
<FromGitter> <jrei:matrix.org> I don't think it makes sense to have Debian_Testing, because testing is the next stable - here Debian 11
<FromGitter> <HertzDevil> `user.is_a?(Hash)` will always fail since `user` is a `JSON::Any`
<FromGitter> <HertzDevil> do something like `if user_h = user.as_h?` instead, if you must
<FromGitter> <HertzDevil> also it looks like you could use `use_json_discriminator`
sagax has quit [Excess Flood]
sagax has joined #crystal-lang