Files
sex/tests/sex-programs/unicode.sex
alex-eg f0a1b6712f spell ? and ! in names as letters C takes
A Lisp predicate came out as ident_start?, which no C compiler reads.
ʔ and ꜝ are letters that look the part; ǃ looks closer, but clang flags
it as a homoglyph of `!' at every use.

Fixes #49.
2026-10-19 16:04:51 +03:00

35 lines
1.2 KiB
Scheme
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(input)
(output "café 日本語 🍺" "café1" "naïve: 3" "predicate: 1 0")
(return 0)
;;; Non-ASCII string literals and identifiers.
;;;
;;; Two things are pinned here. First, a character outside printable
;;; ASCII must reach the C compiler as the UTF-8 bytes it was written
;;; as. Octal escapes are used because C's \x escape swallows every
;;; following hex digit: "café1" is the case that catches it, since a
;;; hex escape would run "\xc3\xa9" into the "1" and produce a value out
;;; of range for a char. Second, a kebab-case identifier containing
;;; non-ASCII characters must survive unkebabify intact -- getting this
;;; wrong truncates the name silently, and the program still compiles
;;; and runs, just under a different name than the one written.
;;;
;;; `?' and `!' end Lisp predicates and mutators, and C takes neither:
;;; they become the letters ʔ and ꜝ.
(include stdio.h)
(fn zero? ((n int)) bool (return (== n 0)))
(fn clear! ((n (* int))) void (= (* n) 0))
(pub fn main () int
(puts "café 日本語 🍺")
(puts "café1")
(var naïve-count int 3)
(printf "naïve: %d\n" naïve-count)
(var n int 5)
(var before bool (zero? n))
(clear! (& n))
(printf "predicate: %d %d\n" (zero? n) before)
(return 0))