Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 29 20:34
    straight-shoota labeled #12544
  • Sep 29 20:34
    straight-shoota labeled #12544
  • Sep 29 20:34
    straight-shoota opened #12544
  • Sep 29 20:34
    straight-shoota labeled #12544
  • Sep 29 19:47
    straight-shoota synchronize #12541
  • Sep 29 15:01
    straight-shoota opened #12543
  • Sep 29 15:01
    straight-shoota labeled #12543
  • Sep 29 15:01
    straight-shoota labeled #12543
  • Sep 29 14:41
    zw963 opened #12542
  • Sep 29 14:41
    straight-shoota milestoned #12282
  • Sep 29 14:41
    straight-shoota milestoned #12282
  • Sep 29 14:41
    straight-shoota unlabeled #12282
  • Sep 29 13:44
    beta-ziliani milestoned #12536
  • Sep 29 13:44
    beta-ziliani milestoned #12536
  • Sep 29 13:32
    straight-shoota closed #12109
  • Sep 29 13:06
    beta-ziliani milestoned #12494
  • Sep 29 13:06
    beta-ziliani milestoned #12494
  • Sep 29 13:05
    beta-ziliani milestoned #12539
  • Sep 29 13:05
    beta-ziliani milestoned #12539
  • Sep 29 11:36
    straight-shoota converted_to_draft #12541
From IRC (bridge bot)
@FromIRC
<oprypin> no
Yuri Vendruscolo da Silveira
@yvern
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!
Ghost
@ghost~55586c4815522ed4b3e08557
Dir.current should give you the runtime current working directory
Cris Ward
@crisward
Didn't think so...
Ghost
@ghost~55586c4815522ed4b3e08557
It calls internally getcwd which does just that
Peter Leitzen
@splattael
As Crystal 0.23.1 is out, is there a timeline to release 0.23.1 as a docker image on https://hub.docker.com/r/crystallang/crystal/?
Yuri Vendruscolo da Silveira
@yvern

I have compiled simply :

puts Dir.current

and I got:

Yuris-MacBook-Pro:~ yuri$ /Users/yuri/Desktop/test ; exit;
/Users/yuri

so even though I opened it from desktop, it gives me another path... ):

Ghost
@ghost~55586c4815522ed4b3e08557
Well, it gives you your current working directory, not the directory where the binary is. I can see in your prompt that you are in ~ which corresponds to your home, which is /Users/yuri.
The binary is in Desktop, but you launched it from your home directory
Yuri Vendruscolo da Silveira
@yvern
in that case, is there a way to get the dir where the binary is?
From IRC (bridge bot)
@FromIRC
<oprypin> @yvendruscolo, it's File.dirname(PROGRAM_NAME)
<oprypin> or the notorious crystal-lang/crystal#4715
Yuri Vendruscolo da Silveira
@yvern
thanks guys!
From IRC (bridge bot)
@FromIRC
<Papierkorb> $PROGRAM_NAME can be changed, by the running program, or by the program executing it
<oprypin> sorry what
<oprypin> this is the better alternative, but i dont get your comment about PROGRAM_NAME
<Papierkorb> program name is the name, which doesn't have to be the name of the binary.
<oprypin> demonstrate
MB
@marceloboeira
Hello Guys
From IRC (bridge bot)
@FromIRC
<Papierkorb> See exec(3).
MB
@marceloboeira
quick question, is it possible to get the real class/type of a object from a macro?
From IRC (bridge bot)
@FromIRC
<oprypin> @marceloboeira, {{ @type }}
MB
@marceloboeira
hmm, not sure. the type of a given parameter of a macro
macro foo(value)
      MyGenericClass({{value.class_name.id}}).new
end

foo("hello")
From IRC (bridge bot)
@FromIRC
<oprypin> that's fair. @yvendruscolo, see Papierkorb's suggestion. File.dirname(Process.executable_path)
MB
@marceloboeira
given "hello" I want to create MyGenericClass(String).new("hello")
From IRC (bridge bot)
@FromIRC
<oprypin> @marceloboeira, macros deal only with literals
MB
@marceloboeira
that's what I thought :/
From IRC (bridge bot)
@FromIRC
<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
MB
@marceloboeira
hmm
the typeof works!!1
thanks :)
From IRC (bridge bot)
@FromIRC
<oprypin> @marceloboeira, yeah but pls dont ignore the part about not needing it
MB
@marceloboeira
yes, I actually am experimenting the limits of the macros
it is nothing serious
From IRC (bridge bot)
@FromIRC
<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
MB
@marceloboeira
interesting that, given a default name of a class (upper camelcase), I can't define a macro with a similar structure. e.g.:
class Foo; end

macro FooBar(value)
...
end

FooBar("foo")
... expecting token 'CONST', not 'nil'
even if I don't have a class with the same name, which would be understandable...
Ghost
@ghost~55586c4815522ed4b3e08557
a macro name, like methods should start with a lowercase letter
a word starting by an upper case letter is recognized as a CONST (a type, a constant, ..)
MB
@marceloboeira
:+1:
but is that because of the order of evaluation of the macro?
Ghost
@ghost~55586c4815522ed4b3e08557
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))
and it mess up something when trying to parse it
MB
@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
From IRC (bridge bot)
@FromIRC
<oprypin> that's the magical part