Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 04:54
    aarongodin synchronize #11765
  • 04:52
    aarongodin synchronize #11765
  • 04:42
    aarongodin synchronize #11765
  • Jan 24 18:25
    straight-shoota labeled #11765
  • Jan 24 18:25
    straight-shoota labeled #11765
  • Jan 24 18:20
    FnControlOption synchronize #11476
  • Jan 24 18:06
    aarongodin opened #11765
  • Jan 24 17:42
    straight-shoota synchronize #11563
  • Jan 24 17:39
    FnControlOption synchronize #11476
  • Jan 24 17:05
    asterite closed #11756
  • Jan 24 14:30
    straight-shoota synchronize #11563
  • Jan 23 16:04
    HertzDevil labeled #11764
  • Jan 23 16:04
    HertzDevil opened #11764
  • Jan 23 16:04
    HertzDevil labeled #11764
  • Jan 23 15:34
    HertzDevil labeled #11763
  • Jan 23 15:34
    HertzDevil labeled #11763
  • Jan 23 15:34
    HertzDevil opened #11763
  • Jan 23 15:20
    HertzDevil labeled #11761
  • Jan 23 15:10
    HertzDevil labeled #11762
  • Jan 23 15:10
    HertzDevil labeled #11762
George Dietrich
@Blacksmoke16
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...
In Lisp a macro can evaluate at compile time arbitrary pieces of code, even methods that are shared with other macros or runtime code.
I did not know Crystal couldn't do that
George Dietrich
@Blacksmoke16
its a pita
because of that missing piece that you cant define reusable macro code
i.e. that you could use in two separate macros
From IRC (bridge bot)
@FromIRC
<riza> ^
George Dietrich
@Blacksmoke16
you can call a macro from a macro, but that just is moreso nested expansion, which doens't help in this case
From IRC (bridge bot)
@FromIRC
<riza> @Blacksmoke16 what do you mean fresh variables can be "keyed like a hash"