Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:03
    Blacksmoke16 labeled #12068
  • 00:03
    Blacksmoke16 labeled #12068
  • May 24 23:25
    ftarulla edited #12068
  • May 24 23:24
    ftarulla opened #12068
  • May 24 12:34
    straight-shoota labeled #12067
  • May 24 12:34
    straight-shoota labeled #12067
  • May 24 12:33
    straight-shoota milestoned #12067
  • May 24 09:17
    lbguilherme synchronize #10768
  • May 23 19:35
    lbguilherme synchronize #10768
  • May 23 19:06
    lbguilherme synchronize #10768
  • May 23 18:47
    lbguilherme synchronize #10768
  • May 23 18:46
    lbguilherme synchronize #10768
  • May 23 13:02
    Blacksmoke16 labeled #12066
  • May 23 13:02
    Blacksmoke16 labeled #12066
  • May 23 11:16
    lbguilherme opened #12067
  • May 23 07:58
    mig-hub labeled #12066
  • May 23 07:58
    mig-hub opened #12066
  • May 23 06:55
    straight-shoota closed #12033
  • May 23 06:54
    straight-shoota closed #12040
  • May 23 06:54
    straight-shoota edited #12040
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...
George Dietrich
@Blacksmoke16
ah i see
they're mainly just ways to generate crystal code
mfiano
@mjfiano:matrix.org
[m]
You would expect 25, but would actually get 32
George Dietrich
@Blacksmoke16
this isn't really a good use case for a macro fwiw
mfiano
@mjfiano:matrix.org
[m]
and this was a bad example, only for demonstration purposes. Clearly this should be a method, not a macro :)
Right. Macros are strictly for 2 things only.
George Dietrich
@Blacksmoke16
main benefit of macros is they can generate code based on compile time information. I.e. accessing annotations, all types that inherit from another, or all types that include a module, etc, etc
mfiano
@mjfiano:matrix.org
[m]
Syntactic abstraction and evaluation control.
But this problem comes up a lot in unhygienic macro systems, which CL and Crystal have afaict.
Unhygienic meaning that the the lexical state of the macro expansion can leak into the call site
Usually generating a temporary variable that is guaranteed to be unique is the way to solve this, which I see Crystal can do
George Dietrich
@Blacksmoke16
mhm, those can also be keyed like a hash
which can be quite helpful, when you also bring unique indexes into things
mfiano
@mjfiano:matrix.org
[m]
Maybe your head wont explode reading this, but starts out with the same (bad) example: https://malisper.me/once-only/
But as you can see, the once-only macro definition is rather complex to solve such a common issue
Was just wondering if Crystal stood on the shoulder of the giants that have solved it decades ago and included such a thing in the language :)
George Dietrich
@Blacksmoke16
hmm
you can deff run into this as you just saw, like if you did {{x}} * {{x}} but it's also fairly easy to fix
macro square(v)
  %v1 = {{v}}
  %v1 * %v1
end
macros are deff a more advanced concept, they also aren't as type safe and have quite a few quirks :P
mfiano
@mjfiano:matrix.org
[m]
Oh sure, the solution has an easy fix, but:
  • It's not always obvious that there is a problem to solve.
  • An automated solution (a macro) is fairly complicated.
  • It saves a lot of boilerplate (over time)
mfiano
@mjfiano:matrix.org
[m]
Yeah, macros are advanced and come with a lot of footguns that take years of experience to even realize their existence, especially in Lisp, which has a much more powerful macro system. I will refrain from asking more macro questions until I have had time to see how they map over :)
George Dietrich
@Blacksmoke16
mfiano
@mjfiano:matrix.org
[m]
Oh that issue surprised me...