Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 20:42
    GeopJr labeled #11323
  • 20:42
    GeopJr opened #11323
  • 18:48
    beta-ziliani milestoned #11321
  • 17:19
    asterite reopened #11322
  • 17:16
    syeopite closed #11322
  • 12:04
    syeopite edited #11322
  • 12:03
    syeopite labeled #11322
  • 12:03
    syeopite opened #11322
  • 11:27
    syeopite edited #11319
  • 10:42
    Sija opened #11321
  • 07:11
    straight-shoota labeled #11319
  • 02:25
    Blacksmoke16 labeled #11320
  • 02:25
    Blacksmoke16 opened #11320
  • 01:12
    syeopite edited #11319
  • 01:08
    syeopite labeled #11319
  • 01:08
    syeopite opened #11319
  • Oct 14 16:25
    straight-shoota labeled #11318
  • Oct 14 16:25
    straight-shoota labeled #11318
  • Oct 14 16:07
    wyhaines labeled #11318
  • Oct 14 16:07
    wyhaines opened #11318
George Dietrich
@Blacksmoke16

oh wait, it does, but then there isn't anything to get it to execute that fiber again which is why it doesnt print the after message

and no, im still confused. Is the buffer actually 1 more than what you specify. Otherwise why else would it print 2, 3, and 4 versus just 2 and 3

and if you add 5 it outputs

Before send 1
Before send 2
Before send 3
Before send 4
1
2
3
4
After send
5

which makes sense expect it printed 3 values with a buffer of 2?

except*
or maybe it's not really like a hard cutoff like im thinking and more like a way to tell the channel to trigger a reschedule when its buffer is full, which in this case value 4 "overflows" the buffer resulting in that reschedule
as opposed to the next opportunity
mfiano
@mjfiano:matrix.org
[m]
  private def all_with_index?
    each_with_index { |e, i| return false unless yield e, i }
    true
  end

  def =~(other : self, rel_tol : Float64 = DEFAULT_TOLERANCE, abs_tol : Float64 = rel_tol)
    all_with_index? { |e, i| Origin.=~(e, other[i], rel_tol, abs_tol) }
  end
I'm still a little confused when working with blocks. This works, but how would this be rewritten to inline the functionality of all_with_index?, as this is the only usage of it and it doesn't deserve its own method?
George Dietrich
@Blacksmoke16
prob like
  def =~(other : self, rel_tol : Float64 = DEFAULT_TOLERANCE, abs_tol : Float64 = rel_tol)
    each_with_index { |e, i| return false unless Origin.=~(e, other[i], rel_tol, abs_tol) }
    true
  end
mfiano
@mjfiano:matrix.org
[m]
Oh I see now.
That clears up more than I care to admit
George Dietrich
@Blacksmoke16
:P
mfiano
@mjfiano:matrix.org
[m]
Hmm, if I mixin a module with a new method by using extend, I get "... is not expected to be invoked with a block, but a block was given". Works fine copy/pasting this new into every final type though. Ideas?
George Dietrich
@Blacksmoke16
Yes
mfiano
@mjfiano:matrix.org
[m]
Where can I find the list of available macro variables like @type, @def, and @top_level?
George Dietrich
@Blacksmoke16
by virtue of you adding another constructor the others are no longer invocable i think
mfiano
@mjfiano:matrix.org
[m]
Oh
George Dietrich
@Blacksmoke16
i think that's true, but don't quote me
mfiano
@mjfiano:matrix.org
[m]
Ok, about the macro variable list, does one exist? I tried searching and only see those 3 mentioned in passing in the reference docs
George Dietrich
@Blacksmoke16
those are the only 3
mfiano
@mjfiano:matrix.org
[m]
Nothing in the api docs from what i see either
Aha!
Thank you. I'm trying to figure out how I can get at the inner right-most type string name of a module path gotten with @type.
Oh that was a mouthful. It's getting late
George Dietrich
@Blacksmoke16
@type.name.split("::").last
mfiano
@mjfiano:matrix.org
[m]
Ok so string manip it is
George Dietrich
@Blacksmoke16
ye
i always wondered what the .identify method is for on StringLiteral
Foo::Bar.name.stringify.identify # => "Foo__Bar" :thinking:
mfiano
@mjfiano:matrix.org
[m]
wonder if I can rely on the order of #instance_vars being how they are defined...
George Dietrich
@Blacksmoke16
crystal-lang/crystal#147 wew, apparently this is why :P
probably
dunno if it'll help your use case but you can pass numbers as generic args
mfiano
@mjfiano:matrix.org
[m]
Ok last question before I pass out? How do I newline split up long io << foo << bar << baz << ... chains so the parser is happy? :)
George Dietrich
@Blacksmoke16
io << foo << bar << baz
io << one << two << three
...
really could have each << on its own line as well
:shrug:
mfiano
@mjfiano:matrix.org
[m]
ah makes sense. Thanks a lot, night!
mfiano
@mjfiano:matrix.org
[m]
Going to have to figure out how to get the name of an ivar tomorrow...
George Dietrich
@Blacksmoke16
if you're iterating over @type.instnace_vars its just .name
mfiano
@mjfiano:matrix.org
[m]
in a {% for ivar in @type.instance_vars %} ... {% end %} I tried something like io << {{ivar.name}} << " " << {{ivar}} and got the value duplicated instead of the name, which makes me believe its a quoting issue, but I'm afk so I'll try any suggestions tomorrow.
George Dietrich
@Blacksmoke16
might need ivar.name.stringify
otherwise it'll prob invoke the getter instead of the name
mfiano
@mjfiano:matrix.org
[m]

I woke up today with a couple questions:

1) Why isn't #[]= included in indexable? Do I always have to implement this if it is always the same (apart from assigning) as #unsafe_fetch?

2) If I have a struct with an array as its only ivar, is there a more convenient way to make the struct Indexable besides defining #unsafe_fetch that just forwards to the array's version? I'm not really familiar with delegates but thinking they are the key here.

mfiano
@mjfiano:matrix.org
[m]
I see how delegate is used now, and it is the answer to #2. New question: Is there a technical reason why the #[]= methods with Range parameters from Array are not included for StaticArray (or a Slice of one)? I'm sad I can't assign into subranges of a homogeneous array.
oprypin
@oprypin:matrix.org
[m]
mfiano: indexable is about ability to read by index. ability to write by index wasn't seen as common enough and big enough to implement a generic module for
mfiano
@mjfiano:matrix.org
[m]
Fair enough. Any reasoning for only being able to write a single index with StaticArray?
oprypin
@oprypin:matrix.org
[m]
mfiano: ability to assign to a range is very powerful and includes resizing of the array.
staticarray can't be resized so there would be too many cases where the only way out would be too raise a runtime exception in the general case
mfiano
@mjfiano:matrix.org
[m]
That is true. If it's doing bounds checking already though, it can be implemented for SA to not dynamic grow the heap memory (since it's not heap memory)
It is looking like my types are going to be structs wrapping a regular dynamic Array then