<FromGitter>
<bew> one that accept a block and one who dosn't @NARKOZ
<FromGitter>
<bew> look the second, there is a `yield` that will inline the passed block
fazibear has joined #crystal-lang
Raimondi has joined #crystal-lang
pwned has joined #crystal-lang
<FromGitter>
<NARKOZ> how comes that methods don't get overwritten?
rohitpaulk has joined #crystal-lang
<FromGitter>
<bew> because a method that accept a block and one that doesn't are 2 different methods, they don't override each other, even though they have the same name
<FromGitter>
<straight-shoota> this aspect got lost though in the remainder which was about top level macros
fazibear has quit [Ping timeout: 255 seconds]
fazibear has joined #crystal-lang
Raimondi has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
<FromGitter>
<bew> @straight-shoota right, that was what I remembered, but can't find it again
<FromGitter>
<sdogruyol> Morning everyone :)
<Groogy>
It's midday but okay :P
<FromGitter>
<sdogruyol> haha yeah :D
<FromGitter>
<bew> Midday everyone then :P
<FromGitter>
<bew> @straight-shoota I edited my comment to remove the "final word"
<FromGitter>
<straight-shoota> ^^
fazibear has quit [Ping timeout: 276 seconds]
fazibear has joined #crystal-lang
crack08 has quit [Ping timeout: 258 seconds]
<FromGitter>
<bew> @straight-shoota if like you say, all your examples should call the method, how do we do to call the macro `foo`? Do we need to use special syntax?
<FromGitter>
<konovod> @bararchy same error message is in #4719 with Ubuntu. Don't know the cause.
<FromGitter>
<straight-shoota> @bew you can call it like a class method: https://carc.in/#/r/2dsw
<Groogy>
@bararchy you building with the aur package crystal-git?
<Groogy>
if you have bauerbill you can just do bb-wrapper --aur -S crystal-git
<Groogy>
and that should just install latest for you
fazibear has quit [Ping timeout: 246 seconds]
<Groogy>
at least I have 0.23.0+13 from (2017-07-17) installed through that
<FromGitter>
<bew> @straight-shoota but this makes that you need to know where the macro is defined, and it breaks the logic of `include`-ing a module with methods and macros and being able to simply call them
<FromGitter>
<straight-shoota> If `self.class.my_macro` worked this shouldn't be a problem I think
<FromGitter>
<bew> this is quite ugly..
<FromGitter>
<straight-shoota> True, but currently you need to prefix method calls with `self.` as well, so it's not that different
<FromGitter>
<straight-shoota> at least if macros are visible but methods have precedence
<FromGitter>
<bew> also, self.class is the runtime class of the instance, the compiler who needs to find which macro to call can't know what you want I think
<FromGitter>
<straight-shoota> I'm currently working on refactoring Kemal to use encapsulation instead of global state. There I have a macro `Kemal::Base.get` and an instance method `Kemal::Base#get`. Currently, when I call `get` from inside a instance method, it calls the macro, but I would expect it to call the instance method. And it's ugly if you have to invoke the instance method with explicit receiver...
<FromGitter>
<bew> you could use `with my_obj yield` to specify a strong implicit receiver
<FromGitter>
<straight-shoota> this only works with a block, not if you're directly inside a method
<Groogy>
mersenne twister random generation isn't that good though :/
<FromGitter>
<straight-shoota> Well the `initialize_instance_routes` method is not part of the DSL, it could be any method defined in a custom application subclass.
fazibear has quit [Ping timeout: 240 seconds]
<FromGitter>
<bew> I like the idea of macro only for class scope though!
<FromGitter>
<straight-shoota> The use case is that you might want to optionally add routes depending on configuration values or some other decision run-time
<FromGitter>
<bew> but in this case, you should have a Router object, that you configure via methods or sth like that
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<straight-shoota> The router is configured through the application
<FromGitter>
<straight-shoota> `get` method would actually call `route_handler.add_route("GET", path, &block)`
<FromGitter>
<yvendruscolo> hello, ⏎ how can I get current working dir path (pwd) at run time? ⏎ basically I need to access other files that are going to be at the same folder, but if I either use "./file_name" or Dir.current+"/fie_name", crystal gets the path at compile time, and if I place this same folder anywhere else, it tries to look for those files at the dir I compiled it. ⏎ thanks!
<FromGitter>
<bew> Well, it gives you your current working directory, not the directory from where the binary is. I can in your prompt that you are in `~` which corresponds to your home, which is `/Users/yuri`.
rohitpaulk has joined #crystal-lang
<FromGitter>
<bew> The binary is in Desktop, but you launched it from your home
<FromGitter>
<yvendruscolo> in that case, is there a way to get the dir where the binary is?
<FromGitter>
<marceloboeira> given "hello" I want to create MyGenericClass(String).new("hello")
<oprypin>
marceloboeira, macros deal only with literals
<FromGitter>
<marceloboeira> that's what I thought :/
<oprypin>
that would hopefully be `MyGenericClass.new({{value}})`
<Papierkorb>
marceloboeira, that syntax should work fine without for this case: The generic type can be auto-deduced from the arguments given to #initialize
<oprypin>
`MyGenericClass(typeof({{value}})).new({{value}})` might work but is redundant
<FromGitter>
<marceloboeira> hmm
<FromGitter>
<marceloboeira> the typeof works!!1
<FromGitter>
<marceloboeira> thanks :)
<oprypin>
marceloboeira, yeah but pls dont ignore the part about not needing it
<FromGitter>
<marceloboeira> yes, I actually am experimenting the limits of the macros
<FromGitter>
<marceloboeira> it is nothing serious
<Papierkorb>
Macros are quite capable in general, up to the point that you can call external programs (!), or as long you adhere to the Crystal language syntax, implement your own little 'script' language with it.
<Papierkorb>
The latter because you have pretty good access to the AST if passed as argument
deep-book-gk_ has joined #crystal-lang
deep-book-gk_ has left #crystal-lang [#crystal-lang]
<FromGitter>
<marceloboeira> interesting that, given a default name of a class (upper camelcase), I can't define a macro with a similar structure. e.g.: ⏎ ⏎ ```... expecting token 'CONST', not 'nil'``` [https://gitter.im/crystal-lang/crystal?at=596e52ac1c8697534a388a94]
<FromGitter>
<marceloboeira> even if I don't have a class with the same name, which would be understandable...
<FromGitter>
<bew> a macro name, like methods should start with a lowercase letter
<FromGitter>
<bew> a word starting by an upper case letter is recognized as a CONST (a type, a constant, ..)
<FromGitter>
<marceloboeira> 👍
<FromGitter>
<marceloboeira> but that's because of the order of evaluation of the macro?
<FromGitter>
<bew> no it has nothing to do with the order of execution, but with the parser: `FooBar(...)` is recognized as a generic type (like `Array(String)`)
<FromGitter>
<bew> and it mess up something when trying to parse it
<FromGitter>
<marceloboeira> I thought maybe the macro expansion happened before the rest of the evaluation/parsing. But it makes sense to happen after considering that you need to check the types
Guest62357 is now known as adam12
<oprypin>
that's the magical part
<oprypin>
macros need to be evaluated before everything but also after everything :D
<oprypin>
in simple cases macros are evaluated before everything, but for example if you refer to the current type in the macro, that delays the expansion until the type's semantics are figured out
<FromGitter>
<marceloboeira> just experimenting, I wanted to do it with macros, but then I've realised that it does not make any sense considering that you might have dynamic results
<Papierkorb>
For real code, you'd just rely on Nil
<Papierkorb>
In your example, it'd simply be a `Unsafe.new.io || "Empty..."`
<FromGitter>
<marceloboeira> not everything, but the calls to unsafe things
<FromGitter>
<marceloboeira> IO related
<Papierkorb>
That's the whole point. Nil is a type on its own in Crystal. Try this: `def foo(a : String); a; end; foo(nil)` - Won't work
<Papierkorb>
..huh
<Papierkorb>
IO is a type. If you expect an `IO`, or pledge to return an `IO`, you can only return that, no nil
<Papierkorb>
Impossible. If you do find a way, it's a serious compiler bug
<RX14>
if you do find a way you'll get segfaults lol
<Papierkorb>
The only way to 'escape' having to return something matching the method prototype is raising an Exception. Another common theme is something like this: `def read_input : String?; ...; end`. It may return a String, or nil. In this case, the compiler will force you to work with the result in a type-safe manner
<FromGitter>
<johnjansen> thanks @fridgerator, i feel another broken record coming on ;-)
<FromGitter>
<fridgerator> lol
<FromGitter>
<fridgerator> nah there is a workaround for this one
<FromGitter>
<fridgerator> add `--no-debug`
<FromGitter>
<johnjansen> thanks, reading all that would have taken an age
pwned has quit [Ping timeout: 255 seconds]
Renich has quit [Quit: Renich]
<FromGitter>
<crisward> @johnjansen Just tried compiling with --release and --no-debug and I'm get a strange bug where my app doesn't recognise '/' as a path. Will try and isolate the specific bug tomorrow.
<FromGitter>
<johnjansen> interesting
<FromGitter>
<crisward> It's fine without --release, which means it's probably something to do with an llvm optimisation.
greengriminal has quit [Quit: This computer has gone to sleep]
rohitpaulk has joined #crystal-lang
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]