<hightower3>
I want to create a macro() and pass a variable to it that should expand to {{var.to_json}}. Is that possible or I need to specify var.to_json in a call to macro?
jnyw has joined #crystal-lang
return0e has joined #crystal-lang
return0e has quit [Client Quit]
<FromGitter>
<bew> doesn't sound like sth possible, `to_json` exists only at runtime, it's not implemented in the compiler for use in the macro system..
return0e has joined #crystal-lang
<woodruffw>
does crystal have something like ruby's `__END__` and `DATA`? i'm wondering if it's possible to embed data in a crystal program, as a way to make a binary more portable (i.e., can be moved between systems without worrying about accompanying files)
<FromGitter>
<aisrael> Am thinking that a base64 encoded string in a heredoc would work (but not ideal, since not binary). A binary heredoc might be nice.
<woodruffw>
yeah, that's what i was thinking of as a workaround, but that feels like a bit of a kludge compared to a dedicated section of the file :\
Ven`` has joined #crystal-lang
Ven`` has quit [Ping timeout: 260 seconds]
<woodruffw>
ah, i see people have worked around this with a macro that shells out and reads the file into a literal. that works!
<FromGitter>
<aisrael> Good to know
<FromGitter>
<Melliti> Hello all, I didn't find on the documentation but does it exist something like var args in C but in Crystal ?
<FromGitter>
<aisrael> Is there a standard method to get the base url from an `HTTP::Client`? Or should I just `”#{uri.scheme}://#{uri.host}”`
Ven`` has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Ven`` has quit [Ping timeout: 276 seconds]
<lvmbdv>
asterite: can i have the output of `llvm-config --host-target` on your mac
duane has quit [Ping timeout: 256 seconds]
duane has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
danielpclark has quit [Quit: Leaving]
<FromGitter>
<aisrael> Hmmn… I’m getting `macro ‘be_a’ must be defined before this point` running `crystal spec` on HI8
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<vlazar> Hello all, Is it possible in Crystal to read a file from macro to generate some code based on that data, say read CSV file and generate Hash in source code?
mark_66 has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<schoening> Hello :) ⏎ I have a question about the way crystal imports files. ⏎ I find JavaScripts/TypeScripts import { propName } from "./module" really cool. And I am trying to understand the benefit of require "./module" because to me that just imports a bunch of stuff that I might be unaware of if that makes sense? But perhaps I am overthinking this.
<FromGitter>
<schoening> import MyModule from "./MyModule" <- I know I should use MyModule.
jnyw has quit [Quit: WeeChat 2.0.1]
alex`` has joined #crystal-lang
<hightower3>
vlazar: you can run external programs with run() and have the output be placed into the program
<hightower3>
So if you run some external command which will generate the code you want, then that code will be put into the source during macro expansion
<FromGitter>
<vlazar> Thanks @hightower3, exactly what I needed. Time to have some fun now :)
faustinoaq has quit [Ping timeout: 248 seconds]
hightower2 has joined #crystal-lang
hightower3 has quit [Ping timeout: 256 seconds]
alex`` has quit [Quit: WeeChat 2.0.1]
<crystal-gh>
[crystal] asterite opened pull request #5680: Macro methods: set type of empty array literal (master...feature/macro-methods-array-literal) https://git.io/vNh3j
<FromGitter>
<drosehn> That's doable, but not necessarily a good idea.
<FromGitter>
<drosehn> For one thing, the crystal build process will not notice when that external CSV file changes, so it will not automatically know to re-compile the source file which has the macro in it.
duane has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
faustinoaq has joined #crystal-lang
<FromGitter>
<r00ster91> @marksiemers yes im using windows
<RX14>
and `case` when you use a Class as a condition matches instances
<FromGitter>
<straight-shoota> you could change it to `when Filetype::Audio.class` to get this example working, but probably you should use instances anyway
<FromGitter>
<Svenskunganka> The *only* reason I am using a class in the first place is because I want to be able to use the type system to do `case` against, since `modules` doesn't have a type.
<FromGitter>
<Svenskunganka> Dunno if this is plain stupid, but I thought it was quite a nice API and doesn't seem to have much runtime overhead since most is done at compile-time, whereas I could do this using `Hash` and having `register` methods.
<FromGitter>
<vlazar> @drosehn ⏎ ⏎ > For one thing, the crystal build process will not notice when that external CSV file changes, so it will not automatically know to re-compile the source file which has the macro in it. ⏎ ⏎ You are right, I can just generate source code and write it to file without using macro, and then build the project. [https://gitter.im/crystal-lang/crystal?at=5a7878e34a6b0dd32b905150]
<hightower>
Hey, is there something like Module.module_methods ?
<RX14>
no
<RX14>
your best bet is looking at the docs
<hightower>
too bad. Yeah, no, I'm not trying to figure out what methods exist, I'm working on a piece of docs where I'd like to have the list in git, so that I can run code to get a list, and if git diff shows anything that then means I need to update docs to document new, or remove removed, stuff
<hightower>
As in, I'd like to run code to show me if there are new methods, or if some methods have been removed
<hightower>
ok thansk
<hightower>
thanks*
<RX14>
oh
<RX14>
so you want to make sure a pit of prose is in sync with all the methods?
<hightower>
yes
<RX14>
are you sure you can't use the method docs for this?
<RX14>
like
<RX14>
the standard doc comments
<RX14>
since you can export the doc as JSON now
<hightower>
Well it requires me to look at the docs. I wanted a system that'd be automatic and require no work from me unless my running the script and saving result to a file produces some git diff
<RX14>
you can just export the docs and use jq or similar
<hightower>
How do you mean about export? (Not familiar with that)
<RX14>
oh
<RX14>
hmm
<RX14>
the JSON doc output is in crystal `master`
<hightower>
Is this specific to crystal's code base or crystal in general? My need is for a crystal-based project, not crystal itself
<RX14>
but you can just make crystal doc export a JSON file with all the information about methods and stuff
<RX14>
no it's anything that can use the crystal doc tool
<hightower>
great! Seems like a good direction then, let me check it out, thanks!
<FromGitter>
<bew> What is an array of NoReturn as in #5680 ?
<FromGitter>
<bew> Oh, weird, why would you want a useless array? Just to know it's empty ?
<RX14>
yep
<RX14>
it's the most generic representation of an empty array
<RX14>
an empty array of... nothing
<RX14>
not an empty array of strings
hightower has quit [Remote host closed the connection]
<FromGitter>
<bew> Lol
<RX14>
or whatever
<FromGitter>
<bew> Go explain this in the docs ˆˆ
<FromGitter>
<bew> It sounds like a trick to not have to use a correct type
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<RX14>
yeah
<RX14>
it pretty much is
<FromGitter>
<asterite> RX14: ah, good point. But I don't think "break" was ever involved in the error trace. I might be wrong, but nothing really changed in the source code of error tracing for a long time now
<FromGitter>
<asterite> bew: yeah, it's a hack
<FromGitter>
<bew> Could you explain in the PR about it, why you're doing this change and why you're doing it that way? (Even if it's a hack)
faustinoaq has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
qard has joined #crystal-lang
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter>
<Svenskunganka> I have a really weird issue with class reopening across files. I can't reproduce the issue with any other code than the one I am actually working on. If you dowload the following gist as zip ("Download as zip" button), and do `crystal run 1.cr` you get the output `is an audio`, but if you try to do `crystal run 2.cr` you get the result `other`. If you do `git diff 1.cr 2.cr` you can see that the *only*
<FromGitter>
... difference between them is that in `2.cr` I `require` another file.