Repository navigation
Conversation
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
|
If we go down this route, we should avoid single letter sigils due to the chance of conflicts. |
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the reviews! I pushed 0c08ae0, which removes the sigil import On the naming, I'm happy to follow your preference, but here is the
If you still prefer to avoid single-letter sigils, I'll switch to |
This is true, but I think if interpolation really is needed, one can either use I believe the sigil is strongest for literals anyway, so discouraging interpolation is a feature IMO
As I mentioned, the intent is for |
|
I'd say interpolation is a good reason to use Complex.new or Complex.polar, it will definitely be much clearer. |
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks both, that makes sense. I pushed ceed5d4:
I'll also update the PR description to match. But, just in case this has sense anymore because probably it has no sense to write ~Complex instead of Complex.new, maybe I focused more in write less than clarity of code. I'm not sure that this really has an utility it was for the sake of defining a capacitator: But really the I need to write all to use ~z(magnitud, angulo_rad)p I think that I'm wasting your time (I'm so sorry for that), and maybe I should abstract all this to a function that calculates this, I was blind by the Money library and the use of sigil on it. and maybe the problem is not to write the complex number quickly is to calculate it. Thanks to explain this to me. and I think that I made all the changes that you require, so is up to you, and finally I'm glad to spoke with two real real real great developers. |
|
Thanks both for the thorough reviews and for the patience. After going through the feedback, I agree this doesn't pull its weight: once interpolation and modifiers are out, I'm closing this PR. Appreciate the time you both put into it. |
Add
~zsigil for complex numbersAdds a
~zsigil to build complex numbers from literals:The two numbers are separated by whitespace. Without modifiers they are
the real and imaginary parts; with the
pmodifier they are the magnitudeand the angle (radians).
Motivation
Complex.new/2is verbose.~z(3 4)is much more pleasant to writeand read.
#c(re im)reader syntax.The
pmodifier (polar) is an extension specific to this library.zis the conventional name for a complex variable (z = x + iy).~z(#{re} #{im}).Changes
Complex.Sigils(new):sigil_z/2, one clause per modifier. Integersand floats are kept as written. Invalid input raises
ArgumentError(bad number) or
MatchError(not exactly two numbers); an unknownmodifier raises
FunctionClauseError.Complex.Kernel:use Complex.Kernelnow also importssigil_z/2.The sigil can be imported on its own with
import Complex.Sigils.Tests
New tests in
test/complex/sigils_test.exsandtest/complex/kernel_sigil_test.exs(8 tests): cartesian and polar forms,integer/float preservation, whitespace handling, error cases, and the
use Complex.Kernelimport.mix format --check-formattedpasses.Notes
Complex.acot/1doctest (lib/complex.ex) fails on Elixir 1.20.4 /OTP 29 on
mainas well, due to last-bit float rounding. It isunrelated to this PR.