RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.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
balduin has quit [Remote host closed the connection]
<FromGitter> <drosehn> wrt "why does Dir.mkdir_p always returns 0 ?" -> isn't it true that every crystal statement has to have *some* return value?
<FromGitter> <bew> yeah, usually it is nil, here it's 0 and it's weird, it should be nil imo
<FromGitter> <Blacksmoke16> o/
<FromGitter> <watzon> Is there any way around this? https://carc.in/#/r/3pc2
<FromGitter> <Blacksmoke16> Classes can't be generated dynamically via macros correct?
<FromGitter> <bew> @Blacksmoke16 they can
<FromGitter> <bew> @watzon huh your arg is `_name` not `name`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5aa5cc72458cbde557224533]
<FromGitter> <bew> ah wait (watzon)
<FromGitter> <watzon> @bew I'm aware. The arg `name` is being passed in as `**kwargs`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5aa5cc9653c1dbb743ce83b5]
<FromGitter> <bew> yeah I realized
<FromGitter> <bew> @Blacksmoke16 where are you calling the macro? in a method?
<FromGitter> <Blacksmoke16> in an each block
<FromGitter> <bew> @watzon yeah no, won't work
<FromGitter> <watzon> @bew shouldn't it though? Symbols are known at compile time right?
<FromGitter> <Blacksmoke16> it works when not in the .each block however
<FromGitter> <bew> @Blacksmoke16 the macro will be expanded where it is called, so in this case the class will be in the each block, and that can't work
<FromGitter> <Blacksmoke16> oooo right
<FromGitter> <watzon> @Blacksmoke16 all you have to do is do your each block in the macro
<FromGitter> <Blacksmoke16> rgr thanks, ill give that a go
<FromGitter> <watzon> So ⏎ ⏎ ```{% for var in arr %} ⏎ ... your stuff ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=5aa5cd7335dd17022e4a5e05]
<FromGitter> <Blacksmoke16> 👍 thanks
<FromGitter> <watzon> No problem
<FromGitter> <bew> @watzon "all you have to do" => we don't even know what he's trying to do...
<FromGitter> <watzon> I assume he was doing something like this ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5aa5cdf5a60157d62fd6c95f]
<FromGitter> <Blacksmoke16> correct :P
<FromGitter> <watzon> When he needs to be doing this ⏎ ⏎ ```{% for v in arr %} ⏎ build_static_model(v) ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=5aa5ce4d27c509a774502872]
<FromGitter> <bew> but is `arr` known at compile time?
<FromGitter> <watzon> This is a good question
<FromGitter> <straight-shoota> If not, there can't be any classes from that 😄
<FromGitter> <watzon> Symbols are known at compile time right? That's why they can't be modified, they're basically constants.
<FromGitter> <bew> they are known yes, but methods are not created based on their values
<FromGitter> <watzon> Hmm ok
<FromGitter> <watzon> I was trying to get something like this working https://github.com/watzon/cadmium/blob/master/src/cadmium.cr#L9
<FromGitter> <bew> where does the kind comes from?
<FromGitter> <bew> why do you need this `tokenizer` method? I think it's not needed, you'd better directly ask your lib user to create a Tokenizer with the class name, instead of relying on dynamic weird stuff with symbols
<FromGitter> <Blacksmoke16> in my case i have a yaml file that defines some data (related to the YAML.mapping question from before) that im wanting to parse and pass to a macro to generate granite model classes for each yaml object
<FromGitter> <Blacksmoke16> so in future if i add another entry to the yaml file i dont have to write another method etc, just yaml
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter> <bew> that won't be possible, because macros are run at compile time, and a yaml file can be parsed at runtime
<FromGitter> <Blacksmoke16> that seems to be what determined, darn
<FromGitter> <bew> unless you use the `run` macro method to do some fancy stuff at compile time, and generate code with another crystal program at compile time
<FromGitter> <Blacksmoke16> what if i just have a string of yaml
<FromGitter> <bew> same, macros can't parse yaml
<FromGitter> <bew> macros can only do 'basic' things, unless you use `run`
<FromGitter> <Blacksmoke16> you have some docs on `run`?
<FromGitter> <bew> https://crystal-lang.org/api/0.24.1/Crystal/Macros.html#run(filename,*args):MacroId-instance-method
<FromGitter> <Blacksmoke16> hero, thanks
<FromGitter> <bew> :)
duane has quit [Ping timeout: 240 seconds]
<FromGitter> <watzon> I just wanted to create a simpler interface for creating Tokenizers rather than having to type `Cadmium::Tokenizer::AggressiveTokenizer.new` every time it could just be `Cadmium.tokenizer(:aggressive)`
<FromGitter> <watzon> But oh well
<FromGitter> <watzon> I figured it would be possible if I used symbols to differentiate since the value would be known at compile time
<FromGitter> <bew> you could provide aliases to do `Cadmium::AggressiveTokenizer`
shalmezad has quit [Quit: Leaving]
<FromGitter> <Blacksmoke16> @bew could you elaborate on how the run will help? from what i understand it allows the program that gets called by run `read` in the example given in the docs, to have the content of the yaml file. would i then use another macro defined in that file to create the classes or?
<FromGitter> <bew> basically, the program specified in run will be compiled, and executed with the arguments you give after the first arg to run. The output of the program execution will be used *directly* as code.
<FromGitter> <bew> so if the program in run does `puts "class A; end"` after the run expansion, you'll be able to use `A`
<FromGitter> <Blacksmoke16> ohh gotcha
<FromGitter> <bew> so in your case, you could make a program `yaml_expander.cr` that receive an argument that would be the path to the yaml file, and generate the classes (outputting code to STDOUT). Then in your code, where you want your classes, you do: `{{ run("yaml_expander", "#{__DIR__}/data.yaml") }}`
<FromGitter> <Blacksmoke16> so tl;dr use content of the yaml to construct a string to print that gets used as actual code
<FromGitter> <bew> yep
<FromGitter> <Blacksmoke16> awesome
<FromGitter> <Blacksmoke16> pretty neat
<FromGitter> <bew> yeah, that's how ECR templates works (in the stdlib)
<FromGitter> <bew> and to help you, you could use `require "compiler/crystal/syntax/ast"`, and use the classes in there to help build everything, and at the end, use `root_node.to_s(STDOUT)` to print a formatted version of everything... (But it may have a little performance hit when compiling the sub program, maybe it's ok though)
<FromGitter> <bew> (using `require "compiler/crystal/syntax/to_s"` to have the `to_s` on AST nodes)
<FromGitter> <Blacksmoke16> cool, ill mess with it, thanks
<FromGitter> <Blacksmoke16> also TIL there is a diff between `p` an `puts`
<FromGitter> <bew> and `pp` too
<FromGitter> <Blacksmoke16> ayy, its pretty ugly looking but it got it working \o/
<FromGitter> <Blacksmoke16> is there a way to pring to console what the string is?
<FromGitter> <bew> where? in a macro?
<FromGitter> <Blacksmoke16> in that file where im generating the classes
<FromGitter> <bew> for your subprogram, you can just compile and run it with the yaml_path as argument
<FromGitter> <Blacksmoke16> nvm i got it
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> heres a question, how would you use YAML.mapping to get the key of a key/value pair?
<FromGitter> <Blacksmoke16> ex
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5aa5e64527c509a77450772a]
<FromGitter> <Blacksmoke16> if i wanted the 0 and 1
<FromGitter> <Blacksmoke16> also since the values are dynamic
<FromGitter> <bew> why use 0 & 1, you could use an array instead?
<FromGitter> <Blacksmoke16> its not data i make
<FromGitter> <Blacksmoke16> so dont really have an option
<FromGitter> <bew> ok
<FromGitter> <Blacksmoke16> its more than 1 and 0 tho
<FromGitter> <Blacksmoke16> goes up to 100
<FromGitter> <bew> here you have a `Hash(Int64, SomeObject)`
<FromGitter> <bew> where `SomeObject` is the object with `name` & `published`
<FromGitter> <Blacksmoke16> oh its that easy
<FromGitter> <Blacksmoke16> perfect, thanks
<FromGitter> <bew> so to parse this, you can create a class SomeObject with a YAML.mapping
<FromGitter> <Blacksmoke16> class Category ⏎ YAML.mapping( ⏎ ⏎ ```Hash(Int64, SomeObject),``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5aa5ec948f1c77ef3aad11de]
<FromGitter> <bew> then use `Hash(Int64, SomeObject).from_yaml ...`
<FromGitter> <bew> ah what you showed in part of an object?
<FromGitter> <bew> or is it the full document?
<FromGitter> <Blacksmoke16> its the full doc, but some can be null
<FromGitter> <Blacksmoke16> some also have an `iconID` but that should be easy to define in the mapping
<FromGitter> <bew> a mapping is for an object with known keys, so it's good for the object with `name` & `publisher`, but not for the top-level hash
<FromGitter> <Blacksmoke16> ah ok, so that is what the Hash(Int64, SomeObject) is for, the Int64 maps to the key and SomeObject is the class with a mapping for the known keys
<FromGitter> <bew> it should work with: https://carc.in/#/r/3pct
<FromGitter> <bew> but it hits an error we fixed in master
<FromGitter> <Blacksmoke16> perfect
<FromGitter> <Blacksmoke16> my hero :)
<FromGitter> <bew> or for now you can do https://carc.in/#/r/3pcw
<FromGitter> <bew> but keep in mind that it's a hack
<FromGitter> <bew> (using `String | Int64` instead of `Int64`)
<FromGitter> <Blacksmoke16> good enough till next release
<FromGitter> <bew> yeah and you can always "fix" it when using it https://carc.in/#/r/3pcy
<FromGitter> <Blacksmoke16> perfect
<FromGitter> <Blacksmoke16> say i always wanted the en value of the name hash, are you able to pull out a given in the mapping, or is that best done in a loop afterwards like you converting strings back to int64
<FromGitter> <bew> don't know if it's a good idea for your usecase, but you could have a mapping instead of a hash for `name`. So your name mapping would look like `name: SomeObjectForEn`, that obj would have a mapping like `en: String`.
<FromGitter> <bew> this would discard all other fields in name
<FromGitter> <Blacksmoke16> a better solution would prob to have a `Translation` Object that has them all
<FromGitter> <Blacksmoke16> then later on i could just do name.en
<FromGitter> <Blacksmoke16> etc vs having to parse the hash
<FromGitter> <Blacksmoke16> plus that way id have the other translations as well
<FromGitter> <bew> if you know the languages in advance, yes, but if you want to add a new languages you'd need to change your mapping.
<FromGitter> <bew> using a `Hash(String, String)` is more generic
<FromGitter> <bew> because your code would not be tied to a specific set of languages available (or something like that)
<FromGitter> <bew> note that I don't know your usecase, in how those languages would be used, so it may be wrong for you
<FromGitter> <Blacksmoke16> im really only going to use the english one
<FromGitter> <Blacksmoke16> the file is from a third party so they included by default
<FromGitter> <bew> then discard the rest if don't have any use for them
<FromGitter> <Blacksmoke16> yea my as well, if i ever decide to do something with them be trivial to add them back to the mapping
<FromGitter> <Blacksmoke16> cool got it working
<FromGitter> <Yive> Can't really figure out the process, but how would one go about merging two JSON::Any's together?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.24.2/Hash.html#merge%28other%3AHash%28L%2CW%29%29forallL%2CW-instance-method ?
<FromGitter> <Blacksmoke16> could you conver them to hashes and then merge?
<FromGitter> <Yive> hmm, sounds like a solid plan. Will try that
<FromGitter> <Blacksmoke16> i was able to take advantage of the default option on the mapping
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5aa5fc7d458cbde55722ee5f]
<FromGitter> <Blacksmoke16> so it'll auto set the en value as the name from the English object on another temp instance var
<FromGitter> <Blacksmoke16> now if only i could access that Int64 value in the initial mapping
<FromGitter> <bew> @Blacksmoke16 you'll have issues if the `name` is after `category_name` in the YAML document
<FromGitter> <Blacksmoke16> thats the key, there is no category_name in the YAML doc
<FromGitter> <Blacksmoke16> so it always will call the default to set the actual value
<FromGitter> <bew> wtf are you doing ><
<FromGitter> <Blacksmoke16> xD
<FromGitter> <bew> you don't need `as(English)`, `@name` has already the type `English`
<FromGitter> <Blacksmoke16> thanks
<FromGitter> <Blacksmoke16> is that only used for union types?
<FromGitter> <Blacksmoke16> to tell it what type should be used?
<FromGitter> <bew> yes if needed, but usually it's not
<FromGitter> <Blacksmoke16> rgr
<FromGitter> <Blacksmoke16> prob going to rewrite it to just set the category_name and id in a .each
<FromGitter> <Blacksmoke16> be the more sensible option
<FromGitter> <bew> I think you could remove `category_name` from the mapping (as it's useless there), and add under it: `getter category_name : String = @name`
<FromGitter> <Blacksmoke16> oo thats clever
<FromGitter> <Blacksmoke16> nice, thanks
<FromGitter> <bew> and I think you could event remove `: String`, the type inference should know how to find it
<FromGitter> <bew> ah no, you want `@name.en`
<FromGitter> <bew> so yeah you need the `: String`
<FromGitter> <Blacksmoke16> ok
<FromGitter> <Blacksmoke16> aannd i found a bug
<FromGitter> <bew> cool!
<FromGitter> <Blacksmoke16> well with Granite, not crystal
<FromGitter> <Blacksmoke16> no, sec
<FromGitter> <Blacksmoke16> is there no pluralize String method?
<FromGitter> <bew> don't think so, that's hard to do correctly
<FromGitter> <Blacksmoke16> yea esp with english lang
<FromGitter> <Blacksmoke16> i could imagine
mangoicedtea has joined #crystal-lang
qard has quit [Quit: qard]
<FromGitter> <faustinoaq> https://gitter.im/crystal-scry/Lobby?at=5aa618928f1c77ef3aadb127 ⏎ ⏎ Hi @bcardiff 😄 Take a look ^
alex`` has joined #crystal-lang
dannyAAM_ has joined #crystal-lang
daemonwrangler has quit [*.net *.split]
jetpack_joe has quit [*.net *.split]
byteflame has quit [*.net *.split]
dannyAAM has quit [*.net *.split]
daemonwrangler has joined #crystal-lang
byteflame has joined #crystal-lang
jetpack_joe has joined #crystal-lang
mangoicedtea has left #crystal-lang ["Leaving"]
marius has joined #crystal-lang
livcd has joined #crystal-lang
flaviodesousa has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <Yive> https://gist.github.com/Yive/7fbe966354dda0db10660c062575842f not sure if I'm doing this wrong or if it's a bug, but for some reason this will raise the error "Expected string for object name"
wojnar has joined #crystal-lang
<FromGitter> <bew> you can't use a field in a field's block, if you want: `{"testing":true}`, you can do: https://carc.in/#/r/3pgp
<FromGitter> <bew> note, don't use `to_json` at the end, but `to_s`: because you probably don't want to put the resulting json in a string to be embedded in another json :P
<FromGitter> <Yive> so it's absolutely not possible to do something like this? `{"id": 1, "details": { "name": "test", "states": { "banned" true, "timestamp": 12345}}`
<FromGitter> <straight-shoota> No, that's entirely possible. You just have to add additional mapping levels
Papierkorb has joined #crystal-lang
Papierkorb has left #crystal-lang ["Konversation terminated!"]
<FromGitter> <straight-shoota> For example https://carc.in/#/r/3php
<FromGitter> <Yive> yeah, slowly been figuring that out. This will likely be the most ugly code I've ever written lol
<crystal-gh> [crystal] ysbaddaden closed pull request #5680: Macro methods: set type of empty array literal (master...feature/macro-methods-array-literal) https://git.io/vNh3j
<travis-ci> crystal-lang/crystal#50aacaa (master - Macro methods: set type of empty array literal): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/352265317
return0e_ has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e_ has quit [Read error: No route to host]
return0e has joined #crystal-lang
<FromGitter> <straight-shoota> why ugly? The API is actually pretty smooth, it's just bulky
duane has joined #crystal-lang
<FromGitter> <straight-shoota> Btw. you can also use the JSON serializer of Hash or NamedTuple: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5aa67fd8458cbde557257644]
<FromGitter> <straight-shoota> or only part of that and feed it the json builder
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
<wuehlmaus> does crystal fompile with just 4 GB? i have the feeling that it is difficult, linuxbrew on my Ubuntu with just 4 GB did not work
<wuehlmaus> compile
<wuehlmaus> on my netbook it did not work, i only have 4 GB there
<FromGitter> <fridgerator> do you have any swap space enabled?
<FromGitter> <sdogruyol> @wuehlmaus be sure to have enough swap
maxpowa has quit [Ping timeout: 276 seconds]
maxpowa has joined #crystal-lang
<wuehlmaus> yes, that might be the problem
<wuehlmaus> fridgerator: sadly on my linux netbook i forgot to enable swap nad it's btrfs so i cannot use a swapfile. my bad!
<FromGitter> <codenoid> long time no see
<FromGitter> <faustinoaq> Hi @codenoid 😄
<FromGitter> <codenoid> hi @faustinoaq , lately i use python, i rarely use crystal because of library limitations
<FromGitter> <faustinoaq> > on my linux netbook i forgot to enable swap nad it's btrfs so i cannot use a swapfile. my bad! ⏎ ⏎ wuehlmaus,Oh maybe you can try crystal using a VirtualMachine? 😅
<wuehlmaus> faustinoaq: it's no problem as my main system is an Apple and there crystal is fun
<FromGitter> <faustinoaq> Hi @codenoid , I have some python/django projects as well although I trying to use amber because I like it 😉
<FromGitter> <faustinoaq> wuehlmaus Oh, nice +1
<wuehlmaus> plus, i don't have to compile crystal on my linux boxes as there are distribution packages :)
<wuehlmaus> but before it was a bit harder
<FromGitter> <codenoid> but actually i could make `efficient runtime` when using crystal, like for sentiment analyst, levensthein, etc
<wuehlmaus> jhass provided me with a compiled crystal when i only had my netbook so i had luck :)
<FromGitter> <faustinoaq> Yeah, btw, now crystal packages on release page are statically compiled using musl, so should be easier to use it I think 😅 ⏎ ⏎ https://github.com/crystal-lang/crystal/releases ⏎ ⏎ relevant post here: https://crystal-lang.org/2018/03/09/crystal-automated-release.html [https://gitter.im/crystal-lang/crystal?at=5aa6a80735dd17022e4e9ce9]
<FromGitter> <codenoid> well, i hope someday crystal compilation time just like when interpreter read the file
<wuehlmaus> musl is great, i used dietlib when it came out and found the idea of not having to use glibc rather inspiring
<FromGitter> <codenoid> 1) i hope Kemal will support Crinja https://github.com/straight-shoota/crinja
qard has joined #crystal-lang
<FromGitter> <codenoid> cc @sdogruyol
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
duane has quit [Ping timeout: 256 seconds]
flaviodesousa has quit [Ping timeout: 248 seconds]
moei has quit [Quit: Leaving...]
rohitpaulk has quit [Ping timeout: 276 seconds]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
olbat has quit [Ping timeout: 256 seconds]
olbat has joined #crystal-lang
olbat has joined #crystal-lang
olbat has quit [Changing host]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
duane has joined #crystal-lang
_whitelogger has joined #crystal-lang
qard has quit [Client Quit]
<lvmbdv> crinja sounds like an amalgamation of the words "cringe" and "ninja"
<FromGitter> <bararchy> ^ lol to me too
qard has joined #crystal-lang
<FromGitter> <bararchy> cringy ninja
duane has quit [Ping timeout: 256 seconds]
moei has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
hightower has joined #crystal-lang
wojnar has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
hightower has quit [Remote host closed the connection]
rohitpaulk has quit [Ping timeout: 256 seconds]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
baweaver has quit [Ping timeout: 256 seconds]
qard has joined #crystal-lang
rohitpaulk has joined #crystal-lang
baweaver has joined #crystal-lang
baweaver is now known as Guest15092
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
duane has joined #crystal-lang
duane has quit [Client Quit]
duane has joined #crystal-lang
duane has quit [Client Quit]
duane has joined #crystal-lang
<FromGitter> <faustinoaq> Oh, interesting presentation: https://pragtob.wordpress.com/2018/01/27/slides-where-do-rubyists-go/
_whitelogger has joined #crystal-lang
<FromGitter> <bew> very nice one!
rohitpaulk has joined #crystal-lang
<FromGitter> <straight-shoota> lvmbdv, interesting. I never thought about it that way =) it's initially supposed to be a combination of crystal jinja
<FromGitter> <straight-shoota> @codenoid you can use Kemal with Crinja! There is even an example for that in the Crinja repo
rohitpaulk has quit [Ping timeout: 248 seconds]
justinmcp has quit [Quit: No Ping reply in 180 seconds.]
justinmcp has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Creatornator has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
<crystal-gh> [crystal] straight-shoota opened pull request #5816: Refactor docs generator HTML scaffold (master...jm/features/docs-html-structure) https://git.io/vxJTE
<crystal-gh> [crystal] straight-shoota opened pull request #5817: CHANGELOG: Change release dates to use ISO format (master...patch-3) https://git.io/vxJkP
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Guest15092 is now known as lemur
lemur is now known as Guest87228
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter> <watzon> What feature should I tackle next? https://github.com/watzon/cadmium#progress
<FromGitter> <watzon> I'm thinking about doing inflectors next. Either that, classifiers, or TF-IDF
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Guest87228 is now known as baweaver
baweaver has quit [Changing host]
baweaver has joined #crystal-lang