Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:23
    caspiano edited #10531
  • Dec 08 23:04
    HertzDevil edited #12623
  • Dec 08 22:57
    Blacksmoke16 edited #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil opened #12828
  • Dec 08 22:34
    straight-shoota edited #12827
  • Dec 08 22:32
    straight-shoota edited #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota opened #12827
  • Dec 08 22:15
    straight-shoota closed #12814
  • Dec 08 17:12
    straight-shoota assigned #12814
  • Dec 08 17:12
    straight-shoota assigned #12813
  • Dec 08 17:12
    straight-shoota assigned #12809
  • Dec 08 17:12
    straight-shoota assigned #12802
  • Dec 08 17:12
    straight-shoota assigned #12797
  • Dec 08 17:12
    straight-shoota assigned #12664
George Dietrich
@Blacksmoke16
:thumbsup:
mfiano
@mjfiano:matrix.org
[m]
I'm having a ton of fun learning, albeit slow, thanks for your help :)
George Dietrich
@Blacksmoke16
np
George Dietrich
@Blacksmoke16

is there a better way to create read addition bytes into a larger Bytes slice other than doing like:

    bytes = Bytes.new 4
    io.pos -= 3
    io.read_fully bytes

where the original bytes slice was 3

mfiano
@mjfiano:matrix.org
[m]
Do the property/getter/setter macros inline the generated method defs?
George Dietrich
@Blacksmoke16
im not sure, would be up to LLVM i'd think
could you even inline that? like since its internal state
mjfiano
@mjfiano:matrix.org
[m]
I guess it depends how they are implemented. In Lisp, struct members are regular functions that access the internal state, and are inlined by default, but can be told not to be.
I was just wondering if that was the case here, and if the AlwaysInline annotation was implied, or a way to opt in/out
George Dietrich
@Blacksmoke16
@HertzDevil might know
manveru
@manveru:matrix.org
[m]
undefined macro method 'Path#instance_vars' confused me way longer than i wanna admit... it refers to Crystal::Macros::Path and not Path :P
George Dietrich
@Blacksmoke16
yea...all that stuff is macro level types
manveru
@manveru:matrix.org
[m]
i was using Path around that area, so got quite confused :)
George Dietrich
@Blacksmoke16
that would do it
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