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
the end result is the same. Code generated by the macro code is included where it's called as if you manually typed it
From IRC (bridge bot)
@FromIRC
<Guest64> okay, that is pretty cool now, im starting to understand this system a bit more
<Guest64> thanks for the aid
George Dietrich
@Blacksmoke16
Np
From IRC (bridge bot)
@FromIRC
<Guest64> wynhaines: just to circle back on what you said. if i define a proc with a constant such as MY_PROC = -> (){}, if i used {% Proc.constants %} I should be returned an array of all constants that contain a proc?
George Dietrich
@Blacksmoke16
no
From IRC (bridge bot)
@FromIRC
<Guest64> im just trying to understand the macros and typenode system as a whole now, outside of my project
George Dietrich
@Blacksmoke16
sec
George Dietrich
@Blacksmoke16
you're basically mutating the value of a constant at compile time
which you could then later iterate over in other macro code
George Dietrich
@Blacksmoke16
However at this point, it has less use cases with the introduction of annotations
From IRC (bridge bot)
@FromIRC
<Guest64> @Blacksmoke16: yea your example makes sense, but i was referring to when wynhaines said that you can use #constants to iterate constants
<Guest64> unless i mistoook what he was meaning
George Dietrich
@Blacksmoke16
ah that would be like
class Foo
  ONE = 1
  TWO = 2
end

{{pp Foo.constants}} # => [One, Two]
From IRC (bridge bot)
@FromIRC
<Guest64> hmm that gives me some ideas to test out. is there a way to access constants at the top level, or only within class/struct objects?
George Dietrich
@Blacksmoke16
That example is on the top level
Oh
I think that'll be possible in the next version, until then it's probably still a good practice to namespace your stuff
From IRC (bridge bot)
@FromIRC
<Guest64> true
<Guest64> https://www.bookstack.cn/read/crystal-lang/syntax_and_semantics-macros.md i found this and things are starting to click together now. thanks again
Kirk Haines
@wyhaines
@guest64 -- I can give you a little example of the kinds of thing that I am talking about in a bit.
Kirk Haines
@wyhaines

@guest64 --

module MyProcs
   Proc1 = ->(arg0 : Int32, arg1 : Int32) { arg0 + arg1 }
end

module MyProcs
  Proc2 = ->(arg0 : String, arg1 : String) { arg0.to_i64 + arg1.to_i64 }
end

macro build_a_hash
  {%
    foo = {} of Nil => Nil
    MyProcs.constants.each do |const|
      foo[const.stringify] = "MyProcs::#{const.id}".id
    end
  %}

MyHash = {{ foo.stringify.id }}
end

build_a_hash

pp MyHash
pp typeof(MyHash)

You are still going to have problems with types, though, if you have a single hash that holds everything.

Try it and you will see what I mean.

George Dietrich
@Blacksmoke16
can you build a binary from input via stdin or something?
i.e. w/o needing a file
didactic-drunk
@didactic-drunk
This is an idea I'm playing with. Is it possible to translate "#{class}.{method}" to a fixed offset at compile time? Example:
@[Measure]
def foo
end

macro finished
  {% for meth in ... %}
    def {{meth...}}
      slot = {{ slot_for @type, meth.name }}
      Fiber.current.measurements[slot].measure do
        previous_def
      end
    end
  {% end %}
end
George Dietrich
@Blacksmoke16
so that the methods are created in a specific order?
Quinton Miller
@HertzDevil
however this index is the overload order not the declaration order
it's still unique though
Kirk Haines
@wyhaines

@Blacksmoke16

{{ system("cat") }}

STDIN is defined for macro code, but off the top of my head right now I don't know if there is a way to read from it with macro code currently.

j8r
@jrei:matrix.org
[m]
{{ read_file }}
I didn't read before on what you want to do, here is only a better snippet
didactic-drunk
@didactic-drunk
Is it possible to monkey patch IO::FileDescriptor#read? https://carc.in/#/r/bj7v
oprypin
@oprypin:matrix.org
[m]
why tho
didactic-drunk
@didactic-drunk
Measure wait time
From IRC (bridge bot)
@FromIRC
<xyhuvud> it should work to monkeypatch as long as you make certain the original is already loaded. file_descriptor should be loaded though
<xyhuvud> it works for me, but then I don't depend on previous_def.
didactic-drunk
@didactic-drunk
previous_def is the important part. require "socket" doesn't seem to help. Is this a load order problem or issue with modules? https://carc.in/#/r/bj8y
George Dietrich
@Blacksmoke16
IO doesn't implement unbuffered_read
FileDescriptor should because it includes the module, so it should deff have that method
wonder if it's because the method is coming from another module
in this case you'd prob want to use super
From IRC (bridge bot)
@FromIRC
<xyhuvud> FileDescriptor implements it by itself though
George Dietrich
@Blacksmoke16
it's implemented via the include Crystal::System::FileDescriptor
so ends up not being a redefinition
From IRC (bridge bot)
@FromIRC
<mikko> well this is a fun bug crystal-lang/crystal#2485