Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 28 21:02
    Blacksmoke16 labeled #13025
  • Jan 28 21:02
    Blacksmoke16 labeled #13025
  • Jan 28 21:02
    Blacksmoke16 labeled #13024
  • Jan 28 21:02
    Blacksmoke16 labeled #13024
  • Jan 28 18:45
    asterite opened #13025
  • Jan 28 16:23
    meatball133 synchronize #13024
  • Jan 28 15:53
    meatball133 edited #13024
  • Jan 28 15:51
    meatball133 opened #13024
  • Jan 28 15:10
    meatball133 ready_for_review #13008
  • Jan 28 13:24
    straight-shoota closed #13014
  • Jan 28 02:34
    Blacksmoke16 labeled #13023
  • Jan 28 02:19
    cyangle labeled #13023
  • Jan 28 02:19
    cyangle opened #13023
  • Jan 28 00:41
    devnote-dev labeled #13022
  • Jan 28 00:41
    devnote-dev opened #13022
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota opened #13021
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
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