Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 18 22:28
    straight-shoota closed #11751
  • Jan 18 17:33
    straight-shoota milestoned #11751
  • Jan 18 16:48
    Blacksmoke16 labeled #11753
  • Jan 18 16:42
    yxhuvud labeled #11753
  • Jan 18 16:42
    yxhuvud opened #11753
  • Jan 18 13:52
    straight-shoota synchronize #11751
  • Jan 18 13:34
    HertzDevil opened #11752
  • Jan 18 13:34
    HertzDevil labeled #11752
  • Jan 18 13:34
    HertzDevil labeled #11752
  • Jan 18 13:34
    HertzDevil labeled #11752
  • Jan 18 12:54
    straight-shoota synchronize #11751
  • Jan 18 12:48
    straight-shoota labeled #11751
  • Jan 18 12:48
    straight-shoota opened #11751
  • Jan 18 12:45
    straight-shoota synchronize #11716
  • Jan 18 10:38
    straight-shoota milestoned #11742
  • Jan 18 01:09
    straight-shoota closed #11747
  • Jan 18 01:09
    straight-shoota closed #11745
  • Jan 17 19:16
    straight-shoota synchronize #11716
  • Jan 17 19:11
    straight-shoota synchronize #11715
  • Jan 17 18:34
    straight-shoota milestoned #11747
mfiano
@mjfiano:matrix.org
[m]
I read the whole thing yesterday.
George Dietrich
@Blacksmoke16
:thumbsup: nice
mfiano
@mjfiano:matrix.org
[m]
Working my way through the stdlib api docs now
(while writing code, because no book will teach you to do :))
Benjamin Wade
@RespiteSage
Advent of Code is also a very good source for exercises, especially if you want to learn the standard library. There's a lot of opportunity to use the very useful methods on Iterable/Enumerable/Indexable/Array.
mfiano
@mjfiano:matrix.org
[m]
I have a problem with AoC even with the language I've been using for ~20 years...not very good at human descriptions of problems with tons red herrings
Benjamin Wade
@RespiteSage
That's fair.
I tend to use Crystal pretty often to implement math routines that I find interesting (e.g. I've recently been interested in Lucas Sequences for estimating roots), so that could also be another way to practice, if you find that interesting.
mfiano
@mjfiano:matrix.org
[m]
Yes, I am writing a little linear algebra library to practice, actually.
Benjamin Wade
@RespiteSage
:thumbsup:
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?