Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 18:26
    beta-ziliani milestoned #13043
  • 18:26
    beta-ziliani milestoned #13043
  • 18:00
    Blacksmoke16 labeled #13053
  • 17:59
    straight-shoota labeled #13053
  • 17:59
    straight-shoota labeled #13053
  • 17:59
    straight-shoota assigned #13053
  • 17:59
    straight-shoota opened #13053
  • 12:19
    straight-shoota closed #13010
  • 12:19
    straight-shoota closed #13050
  • 12:18
    straight-shoota closed #13048
  • Feb 07 18:12
    HertzDevil labeled #13052
  • Feb 07 18:12
    HertzDevil labeled #13052
  • Feb 07 18:12
    HertzDevil labeled #13052
  • Feb 07 18:12
    HertzDevil opened #13052
  • Feb 07 17:49
    straight-shoota closed #13051
  • Feb 07 17:46
    beta-ziliani milestoned #13051
  • Feb 07 17:46
    beta-ziliani milestoned #13051
  • Feb 07 14:03
    beta-ziliani review_requested #13050
  • Feb 07 13:59
    straight-shoota labeled #13051
  • Feb 07 13:59
    straight-shoota assigned #13051
manveru
@manveru:matrix.org
[m]
i'm still fighting with macro evaluation order i think
George Dietrich
@Blacksmoke16
oh/
?
manveru
@manveru:matrix.org
[m]
basically... i want some kind of inheritance i guess
      macro derive_from(owner, *names)
        \{% for name in names %}
          \{% var = owner.resolve.instance_vars.find{ |v| v == name } %}
          property \{{name}} : \{{var.type}}
        \{% end %}

        def initialize( \{{ names.map{ |n| "@#{n}".id }.join("").id }} )
        end
        \{% debug %}
      end
the problem is that at this point, instance_vars is empty once more
George Dietrich
@Blacksmoke16
has to be used in the context of a method
got some example code of what you ultimately want to do?
manveru
@manveru:matrix.org
[m]
yeah... gimme a minute
George Dietrich
@Blacksmoke16
:thumbsup:
manveru
@manveru:matrix.org
[m]
i basically want to write something like this:
struct Nomad::Config
  include SimpleConfig::Configuration

  options_from Common::Config, nomad_datacenters, nomad_base_url, nomad_ssl_ca, nomad_ssl_key, nomad_ssl_cert
end
and look up the types in Common::Config for each of the attributes, and generate a typesafe constructor for it
George Dietrich
@Blacksmoke16
yea idt you can do that
manveru
@manveru:matrix.org
[m]
i'm not sure how that'd work as a method
George Dietrich
@Blacksmoke16
wont be able to iterate the ivars within a method, and you of cant create a method while you're in a method
just manually create the constructor
or use a macro to generate it if you really want
manveru
@manveru:matrix.org
[m]
yeah... a macro doesn't really give much in this case then :)
George Dietrich
@Blacksmoke16
you could do like def_constructor nomad_base_url : URI, ...
manveru
@manveru:matrix.org
[m]
sure, but def initialize(@nomad_base_url : URI) is pretty much the same and less confusing
George Dietrich
@Blacksmoke16
exactly :)
this is a case of macro over complicating something that is simple
manveru
@manveru:matrix.org
[m]
i'm mostly exploring macros at this point, so was just wondering how recursive it can get :)
George Dietrich
@Blacksmoke16
I think there's away you can get this to work, but it's not recommended, give me a sec
manveru
@manveru:matrix.org
[m]
i could generate Nomad::Config when creating Common::Config though, that should cause less problems i think
George Dietrich
@Blacksmoke16
module Common::Config
  CONFIGS = {} of _ => _

  macro config(type_decl)
    {% CONFIGS[type_decl.var.id] = type_decl %}

    getter {{type_decl}}
  end

  config some_value : String
  config some_id : Int32
end

macro options_from(type, *configs)
  def initialize(
    {% for config in configs %}
      {% config = Common::Config::CONFIGS[config.id] %}
      @{{config}},
    {% end %}
    ); end
  {{debug}}
end

struct Some::Config
  options_from Common::Config, some_id, some_value
end

Some::Config.new 10, "foo" # => Some::Config(@some_id=10, @some_value="foo")
manveru
@manveru:matrix.org
[m]
just trying to reduce the number of places to change when i change options, while giving sub-commands only the minimum set of options they need for easier testing and invocation, while avoiding accidental dependencies
oh, that is kinda cool :)
didn't know => was a thing
George Dietrich
@Blacksmoke16
hm?
i will say, yes it works but im not a fan at all of this mutable concept approach
imo it still over complicates the process of just defining a constructor manually
manveru
@manveru:matrix.org
[m]
yeah
i'll try one other idea i just had though
George Dietrich
@Blacksmoke16
Mmk
manveru
@manveru:matrix.org
[m]
i think it'd be beneficial to encode the hierarchy in a single pass instead of throwing it all over the code
not sure if i'll like the result, but gotta try it anyway :)
George Dietrich
@Blacksmoke16
Fwiw, constructors are inherited
manveru
@manveru:matrix.org
[m]
yeah
George Dietrich
@Blacksmoke16
:ok_hand:
manveru
@manveru:matrix.org
[m]
atm i have for example a server that needs options [a,b,c], and it calls sub-components that require options [b] or [a,c], or [c,d] etc...
each sub-component can be called without the server, in which case you would only need to pass their specific options
so inheritance is a bit weird there...
George Dietrich
@Blacksmoke16
Are these like config values, or like unique types
manveru
@manveru:matrix.org
[m]
mostly configs
should be immutable after initial parsing
George Dietrich
@Blacksmoke16
Have you considered passing in a single config obj versus specific values?
manveru
@manveru:matrix.org
[m]
yeah
but that means i'd need to make the value types either optional, or use totally wrong default values...
George Dietrich
@Blacksmoke16
How so?