Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:32
    bew closed #5743
  • 10:56
    straight-shoota milestoned #11234
  • 09:34
    jhass closed #7293
  • 03:02
    superhawk610 opened #11235
  • 00:13
    bcardiff synchronize #11228
  • Sep 19 22:23
    HertzDevil synchronize #11233
  • Sep 19 19:37
    HertzDevil labeled #11234
  • Sep 19 18:49
    maiha opened #11234
  • Sep 19 17:55
    HertzDevil synchronize #11230
  • Sep 19 15:40
    straight-shoota closed #10996
  • Sep 19 15:39
    straight-shoota closed #11220
  • Sep 19 15:39
    straight-shoota closed #11080
  • Sep 19 15:39
    straight-shoota synchronize #10467
  • Sep 19 15:37
    straight-shoota closed #11056
  • Sep 19 15:37
    straight-shoota closed #9998
  • Sep 19 15:37
    straight-shoota milestoned #11215
  • Sep 19 09:14
    HertzDevil edited #11230
  • Sep 19 09:13
    HertzDevil ready_for_review #11230
  • Sep 19 09:13
    HertzDevil synchronize #11230
  • Sep 19 09:09
    HertzDevil labeled #11231
mfiano
@mjfiano:matrix.org
[m]
Does Crystal have the distinction of shallow vs deep copying builtin?
clone vs dup i take it?
George Dietrich
@Blacksmoke16
yes
mfiano
@mjfiano:matrix.org
[m]
Thanks, and the last question before lunch: Is there any way to emit the disassembly, or at the very least, the IR, of a given method (preferably the former)?
George Dietrich
@Blacksmoke16
IR meaning LLVM IR yea?
mfiano
@mjfiano:matrix.org
[m]
Yes, though that is foreign to me so preferably the machine code (asm)
George Dietrich
@Blacksmoke16
--emit [asm|obj|llvm-bc|llvm-ir] Comma separated list of types of output for the compiler to emit
mfiano
@mjfiano:matrix.org
[m]
? I want to inspect a single function.
George Dietrich
@Blacksmoke16
the compiler explorer allows going to a specific def, but you'd prob need to include prelude for your code to work
otherwise there isn't a way to output specific IR, other than the whole file afaik
so would need to output all the IR and find the method you want in it
mfiano
@mjfiano:matrix.org
[m]
Ok thanks. Nothing will beat (disassemble name) at runtime I suppose :)
manveru
@manveru:matrix.org
[m]
so... method overloading on works for argument and not return types?
George Dietrich
@Blacksmoke16
yes
why?
manveru
@manveru:matrix.org
[m]
well, would've been a bit nicer to write the other way :)
George Dietrich
@Blacksmoke16
got some example code?
manveru
@manveru:matrix.org
[m]
def convert(value : String) : Array(String) instead of def convert(value : String, kind : Array(String).class)
George Dietrich
@Blacksmoke16
how would it know which one to use
i guess it could look at each overload's return type and compare that to something? :shrug:
manveru
@manveru:matrix.org
[m]
well, i have a bunch of those that take a string and return some other type
George Dietrich
@Blacksmoke16
could you monkey patch constructors onto various other types instead?
manveru
@manveru:matrix.org
[m]
given that crystal already infers the return type, and it knows what type i want to assign to a given instance variable, i was hoping there was a way to elide that annoation
George Dietrich
@Blacksmoke16
def Array.convert(value : String)
  # ...
end

kind.convert value
manveru
@manveru:matrix.org
[m]
yeah... not a big fan of messing with existing classes :)
George Dietrich
@Blacksmoke16
that's how all the JSON/YAML serializable stuff is implemented
manveru
@manveru:matrix.org
[m]
anyway, just got my code to pass a bunch of tests, here's what i got: https://gist.github.com/manveru/5050af58be7e36bbc9d116eb5d8eccba
maybe you can suggest some other ways to do this better :)
so to add other conversions, you'd add another convert method to Test::Configuration instead of having them infect all other types... i guess i'm still thinking functional
for json/yaml it makes more sense, since they're already in stdlib anyway
George Dietrich
@Blacksmoke16
@{{ivar.id}} = {{ivar.type}}.from_parameter %value
is what i would do
it's not going to harm anything, as you're not messing with the state of the internal obj or anything
can get complicated if you need to support like Int32 | Bool | String tho
manveru
@manveru:matrix.org
[m]
yeah...
George Dietrich
@Blacksmoke16
are you making a config lib or a cli maker lib?
manveru
@manveru:matrix.org
[m]
both ^^;
i tried a bunch of existing ones, but none really fit my use-case...
George Dietrich
@Blacksmoke16
oh?
manveru
@manveru:matrix.org
[m]
well, habitat was nice, but it assumes you configure all via crystal, envy/envyable are yaml, totem was probably the closest to what i wanted i think
but i wanted flag generation for optionparser and special handling for file paths passed as option values, since they're usually files containing secrets that i'd like to encapsulate and avoid accidental leaking of
plus it had no idea of how to handle URIs and the types it handles are not extendable afaict
George Dietrich
@Blacksmoke16
there's als ohttps://athenaframework.org/components/config/. technically it's not coupled with the rest of athena. but not sure how useful it would be in your context. I.e. if you need to support runtime alteration of the values as it doesn't support that atm
does support alternate instantiation methods, e.g. from a file but meh
manveru
@manveru:matrix.org
[m]
will have a look at it :)
George Dietrich
@Blacksmoke16
eh, i wouldn't worry about it. it's not what you're wanting
mfiano
@mjfiano:matrix.org
[m]
I'm curious how Crystal handles the once-only evaluation problem with macros, but that may be a question for the forums/someone experienced with macros not limited to the Crystal subset of the concept.
George Dietrich
@Blacksmoke16
whats the problem?
mfiano
@mjfiano:matrix.org
[m]
Well, I know very little about Crystal macros but consider you wanted to write a square() macro, that takes 1 argument and multiplies it by itself. Because macros take in AST nodes and output AST nodes, and are expanded before the semantic analysis, such an invocation could be: x = 4; square(x += 1), which would expand into code that basically does (x+=1) * (x+=1), that is, the side effect of incrementing x is evaluated before the second occurence of x is evaluated, giving a wrong answer. I'm not sure if I explained that well enough...