<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>
<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>
<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>
<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>
<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> 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>
<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> 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>
<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…]