Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 11:54
    straight-shoota milestoned #12158
  • 10:59
    straight-shoota edited #12158
  • 10:59
    straight-shoota review_requested #12158
  • 10:59
    straight-shoota labeled #12158
  • 10:59
    straight-shoota labeled #12158
  • 10:59
    straight-shoota opened #12158
  • 10:01
    straight-shoota milestoned #12094
  • 09:02
    asterite closed #12157
  • 04:44
    acodervic edited #12157
  • 04:39
    acodervic edited #12157
  • 04:35
    acodervic labeled #12157
  • 04:35
    acodervic opened #12157
  • Jun 24 20:09
    straight-shoota labeled #12156
  • Jun 24 20:09
    straight-shoota opened #12156
  • Jun 24 20:09
    straight-shoota edited #12155
  • Jun 24 20:05
    straight-shoota edited #12155
  • Jun 24 19:31
    straight-shoota opened #12155
  • Jun 24 19:31
    straight-shoota labeled #12155
  • Jun 24 19:31
    straight-shoota assigned #12155
  • Jun 24 18:54
    straight-shoota labeled #12154
D. Scott Boggs
@dscottboggs_gitlab
because dup is a function call, which is a runtime action, as opposed to dropping the literal in, which would be a compile-time action
but putting it in a macro doesn't work either, probably because of the order compilation and type inference happen in at compile time
Ghost
@ghost~5abda813d73408ce4f93b6bf
your gonna kill me, but dup is used here and it works though property char_img : Array(Int32) = DEFAULT_CHAR_IMG_ARRAY.dup
so the function call (runtime actions), can only work when you are explicitly setting a type? if i got that right?
D. Scott Boggs
@dscottboggs_gitlab
I mean, that's what it seems be doing, although the messsage seems to indicate that as long as dup has a Type signiature on it it should work
Ghost
@ghost~5abda813d73408ce4f93b6bf
i mean am i the only one who finds this confusing? we are taught not to use .dup, function calls in property macros. but then when setting a type, we are free to use a function call and it works.. so :confused:
D. Scott Boggs
@dscottboggs_gitlab
OH I misread rule 4
and then reread over the type inference rules
Ghost
@ghost~5abda813d73408ce4f93b6bf
why is there 2 initializers
D. Scott Boggs
@dscottboggs_gitlab
one with an argument, one that leaves it as the default. different overloads
so you could do Klass.new [1, 2, 3] and Klass.new
Ghost
@ghost~5abda813d73408ce4f93b6bf
i see
D. Scott Boggs
@dscottboggs_gitlab
the one with the type annotation tells the compiler what type @ary is supposed to be using rule 4
Ghost
@ghost~5abda813d73408ce4f93b6bf
WTF
Ghost
@ghost~5abda813d73408ce4f93b6bf
https://play.crystal-lang.org/#/r/628i here (given 0, expected 1)
that's the duped array trying to come
then, add the second initializer, boom: https://play.crystal-lang.org/#/r/628j
Ghost
@ghost~56c7afa6e610378809c26230
The first one, there is no Klass.new method that takes no arguments. There is only a Klass.new that takes an Array(Int32). Every Klass#initialize generates a Klass.new method
But with your first one, you could do https://play.crystal-lang.org/#/r/628k
Ghost
@ghost~5abda813d73408ce4f93b6bf
interesting, ty
and @dscottboggs_gitlab ty too. i think i'm getting it now
mavu
@mavu
Hi, I made a more detailed forum post with my c-binding proc problem from yesterday, if anyone has some time to take a look and give me some suggestions, that would be great :)
https://forum.crystal-lang.org/t/help-c-binding-of-function-that-takes-callback/325
Ghost
@ghost~55586c4815522ed4b3e08557
@mavu I've replied on the forum, let me know if it gives you sth useful :)
mavu
@mavu
@bew Thanks! That does get me a small step further, although I don't like the idea of checking a variable every second to see if i need to trigger something. I think I have to have a look at the ruby bindings for this function and see if that gives me some ideas.
Haha :) If i read this correctly the ruby bindings neatly sidestep the issue: https://github.com/WiringPi/WiringPi-Ruby/blob/master/lib/wiringpi/event.rb
by polling :)
Ghost
@ghost~55586c4815522ed4b3e08557
I agree with you, polling looks wrong (either the ruby way, or checking a var change)
Ghost
@ghost~55586c4815522ed4b3e08557
it might be worth looking at how the signal are handled in the stdlib! Signal are kinda like interrupts as they are triggered by external event, and the handler is a C function (registered with LibC.signal) which doesn't take data argument
@mavu ^
the signal handling code is 'a bit' complex though
mavu
@mavu
Thats a good idea, I'll have a look at the signals code.
on a sidenote, if I ever invent a programming language I shall name it "gmahbld", because that word yields exactly 3 hits on google and will make searching stuff much easier without constantly having esoteric articles or things about chemistry in my results.
mavu
@mavu
from crystal signal.cr :
module Crystal::Signal
The number of libc functions that can be called safely from a signal(2)
handler is very limited. An usual safe solution is to use a pipe(2) and
just write the signal to the file descriptor and nothing more. A loop in
the main program is responsible for reading the signals back from the
pipe(2) and handle the signal there.
Apparently the "loop to read variable" idea is not too far off the way signals are handled.
Ghost
@ghost~55586c4815522ed4b3e08557
yeah but the loop is event-ed, meaning that if there is nothing to read it'll just wait until there's something to read from the pipe (using the libevent that the crystal runtime uses for everything)
mavu
@mavu
Ahhh
Thats a great point.
If I do the same thing, write to a pipe instead of a global variable, I can to the same and wait for IO. That sounds promising!
Ghost
@ghost~5abda813d73408ce4f93b6bf
Dir.children("./src/Data/Levels") WOW that was easy lmao noiccee!!!
now just need to cut off the .txt of the file names
puts file_name.chomp(".txt") :heartpulse: me some chomp
Ghost
@ghost~5a5bc22cd73408ce4f8836a6
or rchop
I find chomp(String | Char) confusing, this duplicates .chomp.rchop(String | Char)
I'm opening an issue on this
the internal code is also duplicated from rchop :/
Ghost
@ghost~5abda813d73408ce4f93b6bf
oh is rchop the same?
chomp is an alias?
if you use the parameter
i guess it removes last character, not carriage
Ghost
@ghost~5a5bc22cd73408ce4f8836a6
chomp(suffix) do a chomp, removing any potential \n or \r, and a rchop (removing the suffix)