Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:07
    Blacksmoke16 labeled #12783
  • 00:07
    Blacksmoke16 labeled #12783
  • Nov 26 23:55
    carlhoerberg opened #12783
  • Nov 26 11:21
    straight-shoota milestoned #12781
  • Nov 26 11:21
    straight-shoota milestoned #12781
  • Nov 26 02:15
    straight-shoota assigned #11331
  • Nov 25 23:24
    straight-shoota labeled #12782
  • Nov 25 23:24
    straight-shoota labeled #12782
  • Nov 25 23:24
    straight-shoota opened #12782
  • Nov 25 23:17
    straight-shoota labeled #12781
  • Nov 25 23:17
    straight-shoota labeled #12781
  • Nov 25 23:17
    straight-shoota opened #12781
  • Nov 25 23:01
    straight-shoota synchronize #11635
  • Nov 25 22:56
    straight-shoota synchronize #11840
  • Nov 25 22:49
    straight-shoota labeled #12636
  • Nov 25 19:21
    straight-shoota labeled #12780
  • Nov 25 19:21
    straight-shoota labeled #12780
  • Nov 25 19:21
    straight-shoota labeled #12780
  • Nov 25 19:21
    straight-shoota opened #12780
  • Nov 25 19:11
    straight-shoota labeled #12779
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
<mikko> my almost trivial code has been compiling for many minutes due to this line: StaticArray(Bool, 10_000).new(true)
George Dietrich
@Blacksmoke16
nice
is there a reason to have a 10k member static array tho?
From IRC (bridge bot)
@FromIRC
<mikko> i was just wanting to experiment with bitarray vs staticarray vs array