Skip to content

Commit d7d2b0c

Browse files
make \cdot, \interpunct, and \cdotp equivalent (#25157)
Co-authored-by: Steven G. Johnson <stevenj@alum.mit.edu> Co-authored-by: Steven G. Johnson <stevenj@alum.mit.edu>
1 parent fc02458 commit d7d2b0c

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ New language features
1414

1515
Language changes
1616
----------------
17+
1718
* `macroexpand`, `@macroexpand`, and `@macroexpand1` no longer wrap errors in a `LoadError`. To reduce breakage, `@test_throws` has been modified so that many affected tests will still pass ([#38379]].
19+
* The middle dot `·` (`\cdotp` U+00b7) and the Greek interpunct `·` (U+0387) are now treated as equivalent to the dot operator `` (`\cdot` U+22c5) (#25157).
1820

1921
Compiler/Runtime improvements
2022
-----------------------------

doc/src/manual/variables.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ ERROR: syntax: unexpected "="
136136
Some Unicode characters are considered to be equivalent in identifiers.
137137
Different ways of entering Unicode combining characters (e.g., accents)
138138
are treated as equivalent (specifically, Julia identifiers are [NFC](http://www.macchiato.com/unicode/nfc-faq)-normalized).
139-
The Unicode characters `ɛ` (U+025B: Latin small letter open e)
140-
and `µ` (U+00B5: micro sign) are treated as equivalent to the corresponding
141-
Greek letters, because the former are easily accessible via some input methods.
139+
Julia also includes a few non-standard equivalences for characters that are
140+
visually similar and are easily entered by some input methods. The Unicode
141+
characters `ɛ` (U+025B: Latin small letter open e) and `µ` (U+00B5: micro sign)
142+
are treated as equivalent to the corresponding Greek letters. The middle dot
143+
`·` (U+00B7) and the Greek
144+
[interpunct](https://en.wikipedia.org/wiki/Interpunct) `·` (U+0387) are both
145+
treated as the mathematical dot operator `` (U+22C5).
142146

143147
## Stylistic Conventions
144148

src/flisp/julia_charmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
static const uint32_t charmap[][2] = {
55
{ 0x025B, 0x03B5 }, // latin small letter open e -> greek small letter epsilon
66
{ 0x00B5, 0x03BC }, // micro sign -> greek small letter mu
7+
{ 0x00B7, 0x22C5 }, // middot char -> dot operator (#25098)
8+
{ 0x0387, 0x22C5 }, // Greek interpunct -> dot operator (#25098)
79
};

src/flisp/julia_extensions.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ value_t fl_accum_julia_symbol(fl_context_t *fl_ctx, value_t *args, uint32_t narg
351351
return symbol(fl_ctx, allascii ? str.buf : normalize(fl_ctx, str.buf));
352352
}
353353

354+
/* convert a string to a symbol, first applying normalization */
355+
value_t fl_string2normsymbol(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
356+
{
357+
argcount(fl_ctx, "string->normsymbol", nargs, 1);
358+
if (!fl_isstring(fl_ctx, args[0]))
359+
type_error(fl_ctx, "string->normsymbol", "string", args[0]);
360+
return symbol(fl_ctx, normalize(fl_ctx, (char*)cvalue_data(args[0])));
361+
}
362+
354363
static const builtinspec_t julia_flisp_func_info[] = {
355364
{ "skip-ws", fl_skipws },
356365
{ "accum-julia-symbol", fl_accum_julia_symbol },
@@ -360,6 +369,7 @@ static const builtinspec_t julia_flisp_func_info[] = {
360369
{ "op-suffix-char?", fl_julia_op_suffix_char },
361370
{ "strip-op-suffix", fl_julia_strip_op_suffix },
362371
{ "underscore-symbol?", fl_julia_underscore_symbolp },
372+
{ "string->normsymbol", fl_string2normsymbol },
363373
{ NULL, NULL }
364374
};
365375

src/julia-parser.scm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
(define prec-colon (append! '(: |..|) (add-dots '(… ⁝ ⋮ ⋱ ⋰ ⋯))))
2222
(define prec-plus (append! '($)
2323
(add-dots '(+ - ¦ |\|| ⊕ ⊖ ⊞ ⊟ |++| ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣))))
24-
(define prec-times (add-dots '(* / ⌿ ÷ % & ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗ ⨟)))
24+
(define prec-times (add-dots '(* / ⌿ ÷ % & · · ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗ ⨟)))
2525
(define prec-rational (add-dots '(//)))
2626
(define prec-bitshift (add-dots '(<< >> >>>)))
2727
;; `where`
@@ -234,7 +234,7 @@
234234
(if (and (eqv? c0 #\*) (eqv? (peek-char port) #\*))
235235
(error "use \"x^y\" instead of \"x**y\" for exponentiation, and \"x...\" instead of \"**x\" for splatting."))
236236
(if (or (eof-object? (peek-char port)) (not (op-or-sufchar? (peek-char port))))
237-
(symbol (string c0)) ; 1-char operator
237+
(string->normsymbol (string c0)) ; 1-char operator
238238
(let ((str (let loop ((str (string c0))
239239
(c (peek-char port))
240240
(in-suffix? #f))
@@ -267,7 +267,7 @@
267267
(loop newop (peek-char port) sufchar?))
268268
str))
269269
str))))))
270-
(string->symbol str))))
270+
(string->normsymbol str))))
271271

272272
(define (accum-digits c pred port _-digit-sep)
273273
(let loop ((str '())

test/syntax.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ let f = function (x; kw...)
819819
end
820820

821821
# normalization of Unicode symbols (#19464)
822-
let ε=1, μ=2, x=3, î=4
822+
let ε=1, μ=2, x=3, î=4, =5
823823
# issue #5434 (mu vs micro):
824824
@test Meta.parse("\u00b5") === Meta.parse("\u03bc")
825825
@test µ == μ == 2
@@ -829,6 +829,9 @@ let ε=1, μ=2, x=3, î=4
829829
# latin vs greek ε (#14751)
830830
@test Meta.parse("\u025B") === Meta.parse("\u03B5")
831831
@test ɛ == ε == 1
832+
# middot char · or · vs math dot operator ⋅ (#25098)
833+
@test Meta.parse("\u00b7") === Meta.parse("\u0387") === Meta.parse("\u22c5")
834+
@test (·) == (·) == () == 5
832835
end
833836

834837
# issue #8925

0 commit comments

Comments
 (0)