`.' now writes whichever of C's member operators the type calls for, so nothing needs the arrow spelled out and the name is free for the macro Clojure spells the same way: (-> 5 double-it (add 3)) reads in the order it happens rather than inside out. It has no business in the prelude, which every unit pays for whether or not it threads anything, so it opens the standard library instead and is imported like anything else. The compiler finds lib/ by asking the binary where it is -- beside sexc in a work tree, under ../share/sex once installed -- and looks there last, so a module of one's own by that name still wins. The C arrow becomes `%->', and that rename is what makes the rest possible. The closure lifter writes arrows of its own for the capture record, those forms go back through walk-statement, and a macro named `->' threads them: (-> ƛcaptures n) turns into a call to n, with nothing saying so until the C compiler. fmt-c rendered a bare `->' as the arrow, which left the one spelling that cannot be right -- threading with no import -- looking like the operator it stopped being. It goes through c-apply now, the way any other head nothing knows does.
46 lines
1.2 KiB
Scheme
46 lines
1.2 KiB
Scheme
(input)
|
|
(output "p 3 4 / n 7 zoe / area 12 / sizes 8 8")
|
|
(return 0)
|
|
|
|
;;; A record is a struct that also names itself, so the bare name
|
|
;;; stands wherever (struct name) had to: a var, a pointer, an array
|
|
;;; element, an arglist, a return type, a sizeof. struct keeps C's
|
|
;;; meaning, for a type that came from a header or is laid out to
|
|
;;; match one.
|
|
|
|
(include stdio.h)
|
|
|
|
(record point ((x int) (y int)))
|
|
|
|
(record named "Fields of more than one kind, and a docstring."
|
|
((id int) (first-name (* const char))))
|
|
|
|
(struct raw ((a int) (b int)))
|
|
|
|
(fn shift ((p (* point)) (dx int) (dy int)) void
|
|
(+= (. p x) dx)
|
|
(+= (. p y) dy))
|
|
|
|
(fn area ((p point)) int
|
|
(return (* (. p x) (. p y))))
|
|
|
|
(fn origin () point
|
|
(return #(point : 0 0)))
|
|
|
|
(pub fn main () int
|
|
(var p point #(point : 1 2))
|
|
(shift (& p) 2 2)
|
|
|
|
(var n named #(named : .id 7 .first-name "zoe"))
|
|
(var r (struct raw) #(struct raw : 1 2))
|
|
|
|
(var ps [point 2])
|
|
(= [ps 0] p)
|
|
(= [ps 1] (origin))
|
|
|
|
(printf "p %d %d / n %d %s / area %d / sizes %zu %zu\n"
|
|
(. p x) (. p y) (. n id) (. n first-name)
|
|
(area [ps 0])
|
|
(sizeof point) (sizeof (struct raw)))
|
|
(return (+ (. [ps 1] x) (- (. r a) 1))))
|