Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 20:43
    wontruefree synchronize #11682
  • 20:42
    wontruefree synchronize #11697
  • 20:04
    beta-ziliani milestoned #11719
  • 19:57
    beta-ziliani milestoned #11697
  • 19:53
    beta-ziliani milestoned #11690
  • 19:51
    beta-ziliani milestoned #11689
  • 19:49
    beta-ziliani milestoned #11684
  • 19:43
    beta-ziliani milestoned #11676
  • 19:40
    beta-ziliani review_requested #11591
  • 19:39
    beta-ziliani milestoned #11570
  • 19:35
    beta-ziliani review_requested #11207
  • 18:42
    beta-ziliani milestoned #11544
  • 18:34
    beta-ziliani milestoned #11533
  • 18:31
    beta-ziliani milestoned #11524
  • 18:27
    beta-ziliani milestoned #11476
  • 18:13
    beta-ziliani milestoned #11450
  • 18:12
    beta-ziliani labeled #11393
  • 18:10
    beta-ziliani synchronize #11207
  • 18:05
    beta-ziliani milestoned #11201
  • 17:57
    beta-ziliani reopened #11190
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"
From IRC (bridge bot)
@FromIRC
<riza> hm, I'm not instantly sure how that would be useful, but it's neat to see regardless
George Dietrich
@Blacksmoke16
main use case afaik is if you want to create them in a loop
otherwise if you just did %key, it would be overridden on each iteration