Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:58
    HertzDevil synchronize #13034
  • 00:47
    HertzDevil synchronize #13034
  • Feb 02 22:23
    HertzDevil ready_for_review #13034
  • Feb 02 22:22
    straight-shoota closed #13039
  • Feb 02 22:21
    straight-shoota closed #13020
  • Feb 02 22:21
    straight-shoota closed #11646
  • Feb 02 22:21
    HertzDevil synchronize #13034
  • Feb 02 19:26
    straight-shoota labeled #13044
  • Feb 02 19:26
    straight-shoota labeled #13044
  • Feb 02 19:26
    straight-shoota assigned #13044
  • Feb 02 19:26
    straight-shoota opened #13044
  • Feb 02 18:56
    straight-shoota synchronize #13043
  • Feb 02 18:55
    straight-shoota labeled #13043
  • Feb 02 18:55
    straight-shoota labeled #13043
  • Feb 02 18:55
    straight-shoota labeled #13043
  • Feb 02 18:55
    straight-shoota labeled #13043
  • Feb 02 18:55
    straight-shoota assigned #13043
  • Feb 02 18:55
    straight-shoota opened #13043
  • Feb 02 18:07
    straight-shoota closed #12915
  • Feb 02 18:07
    straight-shoota edited #12915
Benjamin Wade
@RespiteSage
Maybe "type promotion" was the wrong wording.
Unless I'm sorely mistaken, the hardware doesn't do arithmetic on numbers of mismatched length, so either Crystal or LLVM has to turn those numbers into the same type under the covers.
Presumably it's the larger type, and then they try to convert it to the left-hand type, which could raise overflow.
I'm asking this because I'm trying to handle arithmetic with mismatched numeric types in saline.
Benjamin Wade
@RespiteSage
Okay, found it
Daniel Worrall
@Daniel-Worrall
yikes, my playground docker container was using 1.2GB of memory
From IRC (bridge bot)
@FromIRC
<Guest15> hello all. i am wondering if variadic functions are supported for crystal functions and procs. ive tried playing around with VaList and viewing the specs around it, but i cant seem to make sense of it. does anyone happen to have an example of passing multiple arguments via variadic functions with crystal?
maybe you could use valist exactly like c i don't know
Lance Dillon
@riffraff169
just a question: c varargs no, but is it possible to link to a c function that accepts varargs, but you dont pass varargs...so you would create a crystal function for each variant you want...
if you only need one, you would create the static (sort of) crystal function, pass the data to the varargs c function statically, but the c function would do its varargs thing with your data...
i hope that was clear
George Dietrich
@Blacksmoke16
image.png
From IRC (bridge bot)
@FromIRC
<Guest64> hey, is it possible for a crystal macro to edit other portions of the code base when called? for example, i have a macro that defines a proc, but i also want to append the procs name to a case clause in another def method. so that each time the macro is called, it creates the proc, but also adds it to the list of when clauses
<Guest64> https://pastebin.com/sPpFLwhP is a quick little mock up
Lance Dillon
@riffraff169
you could probably have a macro create another source file to be added to the list of files to be compiled and linked...that file will define the method
maybe
From IRC (bridge bot)
@FromIRC
<Guest64> hmm, i will try exploring that avenue. i was also thinking perhaps a macro calling a macro might work, in which the second macro might define the when clause. id have to play with it later
<Guest64> as a side question: is there a cleaner way to create default args
<Guest64> from a splat of types for a macro? for example if *types contains
<Guest64> {Int32, Int32}, when the macro defines a definition i use: def my_def({%
<Guest64> for type, index in args %}arg{{index}} : {{type}},{% end %}) which
<Guest64> expands to def my_def(arg0 : Int32, arg1 : Int32)
George Dietrich
@Blacksmoke16
You can append them to a constant, then iterate over it in a finished hook
But im not really sure you need a macro here, versus just a method and hash of procs
Lance Dillon
@riffraff169
yeah, just create a dispatch table....hash key being name, value being proc, then call the proc when a key matches
could even have it be a list of procs, that can be called in order... and can change them dynamically if needed... basically like hooks
From IRC (bridge bot)
@FromIRC
<Guest64> i was thinking something similar as well. i may be able to make a hash of string, proc() work to my liking
<Guest64> thanks for the ideas
Kirk Haines
@wyhaines
@guest64 Macros create code in the place where the macro is called. Also, macros can not call other macros -- they look like methods, but they aren't really methods. However, macros do have access to constants. So you could have your first macro, the one that defines a proc, inject data into a constant that a later macro, involved with the case statement creation, accesses to build said case statement.
From IRC (bridge bot)
@FromIRC
<Guest64> thanks for the advice, im trying to use a hash to contain my map of String, Proc, but while trying to add my procs to the hash I get this error:
<Guest64> ProcMap = Hash(String, Proc).new
<Guest64> Error: can't use Proc(T, R) as generic type argument yet, use a more specific type
George Dietrich
@Blacksmoke16
you need to type your proc
Proc(String, Int32) e.g. if it accepts a string an returns an int32
From IRC (bridge bot)
@FromIRC
<Guest64> each proc has diufferent types, how can i make that work with the hash
<Guest64> IE each proc added to the hash do not share the same definition
George Dietrich
@Blacksmoke16
that's going to be painful
what are these procs used for?
From IRC (bridge bot)
@FromIRC
<Guest64> thats hard to explain without going into depth of the project. the procs are basically synonyms of existing libc functions which their pointer address is returned back to the dynamic linker during the binding stage to determine which function symbol points to which function
George Dietrich
@Blacksmoke16
might be able to wrap these procs in structs
somethign like
abstract struct Callable
end

struct Proc1 < Callable
  def call # define args/return type
  end
end

struct Proc2 < Callable
  def call # define args/return type
  end
end

hash = Hash(String, Callable).new
the gist of it is that you cant have a hash with type of Proc, would need to specify the types of procs that can be in the hash
i suppose technically the macro approach you wanted to take would work around this by defining a hash literal, which would essentially type itself
From IRC (bridge bot)
@FromIRC
<Guest64> hmm, wrapping the procs inside a struct might work. i never thought of that
<Guest64> could you expand more on this hash literal you speak of?
George Dietrich
@Blacksmoke16
the type of literal hashes are inferred based on the values in the literal