-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change or remove @equivalence
?
#2
Comments
I was in fact working on this yesterday, but i didn't quite got what i wanted. I was trying to include |
Figuring out whether the type exists or not seems not easily possible.
Do you mean attaching the docstring to the struct in the macro? That’s what
Okay, then I will implement option 1. |
Well, i think i managed to do that with macro equivalence(name, relation)
quote
try
isa($name, DataType)
$(_eqrelation(name, relation))
catch
Base.@__doc__ struct $(esc(name)) <: Equivalence end
$(_eqrelation(name, relation))
end
end
end and then we don't need to bother whether a relation has been defined or not and don't need to bother whether to use """
Spectral
Equivalence that relates the energy of a photon to its frequency and wavelength according to
the relation ``E = hf = hc/λ``, where
* ``E`` is the photon energy,
* ``f`` is the frequency,
* ``λ`` is the wavelength,
* ``h`` is the Planck constant and
* ``c`` is the speed of light in vacuum.
!!! Note
The `Spectral` equivalence does not include the wavenumber. This is to avoid mistakes,
since there are two competing definitions of wavenumber (``1/λ`` and ``2π/λ``).
"""
@equivalence Spectral Energy/Frequency = h
@equivalence Spectral Energy*Length = h*c0
@equivalence Spectral Length*Frequency = c0 This worked well with the test. Do you think this is "stable", i mean, do you think it will suffer from the same problem that I like this way, so the user just need to bother with one macro, but if you think option 1 is better (or safer), it is fine with me. |
This version does work, but I would still prefer one of the two options above. Some comments on your solution:
Since you are ok with option 1, I would merge #3. |
Ok, I understand the problems with my solution. Let's go with option 1, then! |
@equivalence
does not do much more than@eqrelation
, it just defines the struct before adding the relation. That doesn’t seem like it provides much value. I see two options:@equivalence
to only define the struct. Users would then write@equivalence
provides much value either.@equivalence
, the user would then writeI currently prefer option 2.
The text was updated successfully, but these errors were encountered: