ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.30.1 | 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
<rkeene> Migration of Tcl from CVS to Fossil: https://core.tcl-lang.org/tips/doc/trunk/tip/386.md
<FromGitter> <rmarronnier> Macros are driving me crazy...
<FromGitter> <Blacksmoke16> oh/
<FromGitter> <rmarronnier> What is the simplest way to make this : ` def self.stop_words(language = @@lang) ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c9099d45f7c26fa06e185]
<FromGitter> <Blacksmoke16> what isnt working?
<FromGitter> <rmarronnier> works instead of getting : `12 | @@stop_words = {{ read_file("#{__DIR__}/data/stopwords/#{language}.txt") }}.split("\n") ⏎ ⏎ ``` ^-------``` ⏎ ⏎ Error: undefined macro variable 'language'` [https://gitter.im/crystal-lang/crystal?at=5d5c90c38e8dde63d80c5e83]
<FromGitter> <Blacksmoke16> well its not going to work if you pass in the language at runtime
<FromGitter> <Blacksmoke16> since macros are compile time
<FromGitter> <rmarronnier> Hmm so self.stop_words should be a macro method ?
<FromGitter> <Blacksmoke16> without knowing the whole problem, hard to say
<FromGitter> <Blacksmoke16> whats the end goal you're trying to accomplish?
<FromGitter> <rmarronnier> I want to let the developer choose which file(s) (i18n list of words) she needs whitout loading all files when compiling
<FromGitter> <rmarronnier> for example she should be able to set `language = "ru"` and only the ru.txt will be read at compile time
<FromGitter> <Blacksmoke16> but also able to load multiple?
<FromGitter> <rmarronnier> Yes, exactly !
<FromGitter> <Blacksmoke16> i dont suppose you could use an env var, split that, iterate over the names, load each file and concat into a big string
<FromGitter> <Blacksmoke16> or use a constant thats an array of languages
<FromGitter> <rmarronnier> Mmm, I think I'm starting to understand that what I'm trying to do is impossible (feed macros values with dynamically set variables)
<FromGitter> <Blacksmoke16> can only do that via annotations, constants, or env vars
<FromGitter> <Blacksmoke16> cant use runtime values as macros would already be resolved by then
<FromGitter> <rmarronnier> Yeah.. and crystal compiler isn't smart enough to guess which runtime values are possible vs impossible :-p
<FromGitter> <rmarronnier> Thanks for the tips
<FromGitter> <Blacksmoke16> depending on the context it couldnt possibly know
<FromGitter> <rmarronnier> yep
<FromGitter> <nsuchy> Does crystal have a good Apache Cassandra library?
<FromGitter> <Blacksmoke16> i doubt it
<FromGitter> <Blacksmoke16> https://github.com/kaukas/crystal-cassandra, there is *a* library, dunno if its a *good* one tho
<FromGitter> <nsuchy> Yeah was looking at it
<FromGitter> <nsuchy> How’s code quality looking?
<FromGitter> <Blacksmoke16> :shrug:
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <Blacksmoke16> @bew you around?
alex`` has quit [Ping timeout: 244 seconds]
ukd1 has joined #crystal-lang
<FromGitter> <bew> Hmm? Not for long no idea why i woke up, it's 4am here ^^
<FromGitter> <bew> @Blacksmoke16 you have 5 min before i sleep again
<FromGitter> <bew> Timeout, peer took too long to respond
<FromGitter> <Blacksmoke16> :(
<FromGitter> <Blacksmoke16> next time :P
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ nice [https://gitter.im/crystal-lang/crystal?at=5d5cb4db5ba4a84f69620de3]
<FromGitter> <Blacksmoke16> UX is still up in the air, debating if its ok to require the user to call `validate` once and pass the groups to that vs valid?
<FromGitter> <Blacksmoke16> im thinking it is
ukd1 has quit [Quit: leaving]
chemist69 has quit [Ping timeout: 250 seconds]
chemist69 has joined #crystal-lang
gangstacat has quit [Quit: Ĝis!]
ht_ has joined #crystal-lang
fyber has quit [Remote host closed the connection]
<cerulean> sup all? My crystal game is nearly completion
<cerulean> it's my first game ever
<cerulean> the prototype works somewhat
<cerulean> give me a few days to get iit perfect and i will show you guys
<cerulean> I used PixiJS
ht_ has quit [Remote host closed the connection]
docelic has joined #crystal-lang
<FromGitter> <j8r> cerulean can't wait to try it out :)
docelic has quit [Ping timeout: 258 seconds]
dingenskirchen has quit [Ping timeout: 246 seconds]
dingenskirchen has joined #crystal-lang
<FromGitter> <bew> @Blacksmoke16 nice, groups are a good idea! Not sure about `.valid? some_array` though, I'd do without the array for the most common case (like: `.valid? "one"` or `.valid? "one", "two"`), so we avoid an array allocation for "nothing", but still allow to pass an array if you already have one
<FromGitter> <bew> And you already know my opinion on `.validate`, I wouldn't want to have a desynchronization between the checks and the `.valid? xx` call. Calling `.valid?` should do the checks (with optional caching of the result)
alex`` has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
<FromGitter> <Blacksmoke16> it just feels weird to me to have to pass the groups in `.valid?` as well
<FromGitter> <Blacksmoke16> it should be something that happens when you call `.validate`
<FromGitter> <Blacksmoke16> @bew thoughts on dropping `.valid?` in favor of like `.validate("one", "two").empty?`
<FromGitter> <Blacksmoke16> change validate to return the errors if any
PMunch has joined #crystal-lang
<PMunch> Hi everyone. We have an interesting (hopefully) proposal for you! Since last years FOSDEM conference the people over in #nim have been talking about creating a developer room for small/new/unknown languages. The room will feature presentations about parts of the language, or specific cool projects done in a language. If anyone from the Crystal community wants to join in on the effort, come join us over in #fosdem19newerlangs.
<Stephie> PMunch, channel doesn't seem to exist?
<Stephie> i'm *probably* going to fosdem 19
<FromGitter> <alehander42> it's on freenode
<Stephie> this is freenode
<FromGitter> <alehander42> ahh
<Stephie> well
<FromGitter> <alehander42> then you can copy #fosdem19newerlangs
<Stephie> i'm on freenode :)
<FromGitter> <alehander42> without the `.`
<FromGitter> <alehander42> in the end
<Stephie> i did
<Stephie> channel is empty
<PMunch> Weird, we're three people in there (plus ChanServ)
<Stephie> whoops
<Stephie> it did copy the dot
<FromGitter> <alehander42> : P
<PMunch> Yeah, my IRC client also highlighed the dot as part of the name
coderobe has quit [Remote host closed the connection]
gangstacat has joined #crystal-lang
lucasb has joined #crystal-lang
coderobe has joined #crystal-lang
coderobe has quit [Ping timeout: 245 seconds]
coderobe has joined #crystal-lang
sorcus has quit [Read error: Connection reset by peer]
sorcus has joined #crystal-lang
PMunch has quit [Remote host closed the connection]
mntmn has quit [Ping timeout: 250 seconds]
OvermindDL1 has quit [Ping timeout: 250 seconds]
CommanderViral has quit [Ping timeout: 250 seconds]
OvermindDL1 has joined #crystal-lang
mntmn has joined #crystal-lang
ht_ has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <Blacksmoke16> actually @bew, can you think of any use case that would require running validations a bunch of times? I.e. that would make cacheing them make sense?
<FromGitter> <nsuchy> If anyone here wants to chime in: https://gitlab.com/gitlab-org/project-templates/contributing/issues/2
<FromGitter> <Blacksmoke16> you know about the `crystal init` command?
<FromGitter> <nsuchy> @Blacksmoke16 Yeah, this is specifically for amber though
<FromGitter> <nsuchy> to make crystal web apps even easier for GitLab users who've never used crystal before
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <nsuchy> this is great exposure to a huge userbase
rohitpaulk has quit [Ping timeout: 244 seconds]
alex`` has quit [Read error: Connection reset by peer]
alex`` has joined #crystal-lang
go|dfish has quit [Ping timeout: 246 seconds]
go|dfish has joined #crystal-lang
<FromGitter> <Blacksmoke16> i hope so, we shall se
gangstacat has quit [Quit: Ĝis!]
gangstacat has joined #crystal-lang
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
sagax has joined #crystal-lang
<FromGitter> <nsuchy> waiting to see what peeps say
fyber has joined #crystal-lang
fyber has quit [Client Quit]
fyber has joined #crystal-lang
<FromGitter> <rmarronnier> ok, tell me if I'm wrong : ⏎ 1- I create a module with a macro defining a method which reads a file at compile time with `{{ read_file("#{__DIR__}/a/static/path/blabla.txt") }}` ⏎ 2- I include this module in a class located in another file whose `__DIR__` is different. ⏎ 3- The read_file obviously fails. ⏎ 4- There is no strategy to have the `read_file` macro works in this scenario. ...
<FromGitter> <Blacksmoke16> use a constant or just use the full path?
<FromGitter> <Blacksmoke16> constants or env variables can be used in a macro
<FromGitter> <watzon> ^
<FromGitter> <rmarronnier> I want to use a constant
<FromGitter> <rmarronnier> hmm
<FromGitter> <Blacksmoke16> then do it?
<FromGitter> <Blacksmoke16> `MY_CONST = "/path/to/dir"
<FromGitter> <Blacksmoke16> `{{ read_file("#{MY_CONST}/a/static/path/blabla.txt") }}`
<FromGitter> <rmarronnier> yeah but if the developer has the code in another path, it won't work anymore (?)
<FromGitter> <Blacksmoke16> env var then?
<FromGitter> <asterite> could you show complete code? where is blabla.txt in the end?
<FromGitter> <Blacksmoke16> could default it to something sane, but allow it to be overridable by an env var
<FromGitter> <rmarronnier> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5da5336ddc404fbceb26f6]
<FromGitter> <Blacksmoke16> might just be easier to make this a runtime config thing
<FromGitter> <Blacksmoke16> ```Config.stop_words_path = "/some/path"```
<FromGitter> <asterite> Store `__DIR__` in a constant in that module, then reference it in the macro
<FromGitter> <asterite> but I18N is something that most likely users choose at runtime, I wouldn't try to do all of that with macros
<FromGitter> <rmarronnier> Nice @asterite !
<FromGitter> <asterite> did that work?
<FromGitter> <rmarronnier> No, but I'm hopeful :-D
<FromGitter> <asterite> haha
<FromGitter> <j8r> @rmarronnier why do you want absolutely use a constant?
ht__ has joined #crystal-lang
ht_ has quit [Ping timeout: 250 seconds]
<FromGitter> <j8r> `{{ env("MY_PATH") }}` would do it
<FromGitter> <rmarronnier> I want this macro to be called wherever the developer needs to call it. This macro gives her/him a list of stop words. I want it to be determined at compile time so that the library is batteries-included without forcing the developer to grow the binary with 50 languages files if she doesn't them
ht__ is now known as ht_
<FromGitter> <watzon> Oh hey @rmarronnier lol
<FromGitter> <watzon> You're working on Cadmium stuff right?
<FromGitter> <rmarronnier> yeah :-)
<FromGitter> <rmarronnier> I'm struggling hard on things that seemed simple at first :-D But asterite tip put me in a good way
<FromGitter> <watzon> @j8r the problem is this: currently Cadmium has only a list of English stop words, which can easily be stored in a Crystal array and loaded at compile time. What we want to do is expand those stop words to multiple languages. Originally I had things being stored in a json file in a data directory, but the problem is if you create a binary that relies on Cadmium and don't have that data directory it screws
<FromGitter> ... everything up, so the obvious solution would be to make the stop words a part of the binary for portability purposes.
<FromGitter> <watzon> The only problem is how best to accomplish that. Any suggestions?
<FromGitter> <j8r> we could compile our application with flags
<FromGitter> <j8r> a flag to have english, another spanish, etc
ht_ has quit [Remote host closed the connection]
<FromGitter> <j8r> like the venerable `./configure --with-curl --enable-static`
<FromGitter> <Blacksmoke16> @bew new feature :slight_smile:
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5dab8c142faa4fbd47a00d]
<FromGitter> <Blacksmoke16> or using a method
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5dabe17d3c163641182c33]
<FromGitter> <Blacksmoke16> will be built into some assertions, namely the string ones. i.e. if you wanted to do `.strip` before checking size or something
<FromGitter> <rmarronnier> `DATA_DIR = "#{__DIR__}/data/stopwords/"`
<FromGitter> <rmarronnier> `Error: StringLiteral#+ expects char or string, not Call`
<FromGitter> <rmarronnier> So I can use `__DIR__` in a macro but not in a constant value ?
<FromGitter> <Blacksmoke16> i think the error is from somewhere else? https://play.crystal-lang.org/#/r/7fnf
<FromGitter> <Blacksmoke16> prob where you are using the const?
<FromGitter> <rmarronnier> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5dae5267969726f93f06b6]
<FromGitter> <Blacksmoke16> make it like `#{DATA_DIR}en.txt`
<FromGitter> <rmarronnier> Thanks :-)
<FromGitter> <rmarronnier> now I get this :
<FromGitter> <rmarronnier> `Error: Error opening file '\"/home/remy/crystal/masters/cadmium/src/cadmium/i18n/data/stopwords/\"en.txt' with mode 'r': No such file or directory`
<FromGitter> <rmarronnier> Is this an escaping character problem ?
<FromGitter> <Blacksmoke16> try doing `#{DATA_DIR.id}`
<FromGitter> <rmarronnier> Where does the \ before en.txt comes from ?
<FromGitter> <rmarronnier> Great !!!!
<FromGitter> <rmarronnier> @Blacksmoke16 and @asterite : thanks so much, I'll get some sleep tonight :-p
<FromGitter> <Blacksmoke16> np
<FromGitter> <Blacksmoke16> hey @asterite do you happen to know if a new line is added to macros when they're expanded?
<FromGitter> <Blacksmoke16> have a macro that defines a method, was trying to add doc comments above it to add to the default comments within the macro, but if you remove one or the other it works, but not both together
<FromGitter> <Blacksmoke16> which would be caused by like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5db667b059db27dfb92e21]
<FromGitter> <Blacksmoke16> from ⏎ ⏎ ```# some docs above the macro call ⏎ make_foo``` [https://gitter.im/crystal-lang/crystal?at=5d5db68179229b63d9997306]
<FromGitter> <asterite> you can't merge docs from the macro call and the doc call, only one wins (I think the one on the macro call)
<FromGitter> <asterite> but might be something to improve, I don't know
<FromGitter> <watzon> If we had a doc system similar to YARD it would be possible
<FromGitter> <bew> @Blacksmoke16 nice for assert!
<FromGitter> <Blacksmoke16> @asterite how so? if the line break there wouldnt it inherently work?
<FromGitter> <absolutejam_gitlab> dunno if it's any real difference @Blacksmoke16 but you can do
<FromGitter> <absolutejam_gitlab> ```def foo() end```
<FromGitter> <absolutejam_gitlab> vs ⏎ ⏎ ```def foo; end``` [https://gitter.im/crystal-lang/crystal?at=5d5dc5057e160727e0868934]
<FromGitter> <absolutejam_gitlab> I just don't like semicolons
<FromGitter> <Blacksmoke16> i like the latter better :p
<FromGitter> <absolutejam_gitlab> you're free to be wrong
<FromGitter> <Blacksmoke16> pretty sure the formatter would change the to
<FromGitter> <absolutejam_gitlab> 😉
<FromGitter> <Blacksmoke16> ```foo() ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5d5dc6f2c508da44c35bc9a4]
<FromGitter> <absolutejam_gitlab> yeah ti does
<FromGitter> <absolutejam_gitlab> fuck
<FromGitter> <Blacksmoke16> :p
<FromGitter> <jwoertink> How do y'all handle when you have 2 shards that have the same dependency, but each require a different version of that dep, and you need to use a specific one?
<FromGitter> <jwoertink> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5dd0d1142faa4fbd4897b8]
<FromGitter> <jwoertink> and I want to use the "shard2" dep from master branch, but the dep from "shard1" is what's being loaded
<FromGitter> <jwoertink> oh, look at that. If I flip the order of those two, it'll use the one I want
<FromGitter> <jwoertink> neat
<FromGitter> <Blacksmoke16> *doom*)
<FromGitter> <asterite> Blacksmoke16 macros aren't really copy pasted into the program and then everything reparsed and so the comments are joined. If there's a comment on top of a macro call that comment will be copied to all nodes the macro generates, just ignoring the existing comments in the macro
<FromGitter> <asterite> so an extra line or not doesn't matter in the current implementation
<FromGitter> <Blacksmoke16> ah gotcha, thanks for the explanation