implement thread-first ->

`.' 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.
This commit is contained in:
2026-10-05 02:08:15 +03:00
parent fb4b8aa1f9
commit dd3a4bdac5
21 changed files with 219 additions and 66 deletions

View File

@@ -20,8 +20,16 @@ CSC_FLAGS += -K prefix -static
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
datarootdir = $(prefix)/share
datadir = $(datarootdir)
# sexc looks for the standard library beside itself: next to the binary
# in a work tree, and bindir/../share/sex once installed
sexlibdir = $(datadir)/sex
INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644
SEX_LIB = $(wildcard lib/*.sex)
MODULE_FLAGS = -emit-all-import-libraries -module-registration -c
@@ -114,6 +122,7 @@ SEX_TEST_PROGRAMS = c99 \
serialize \
specs \
sums \
threading \
type-shapes \
unicode \
unnamed-params \
@@ -133,15 +142,18 @@ check run-tests: sexc sex-tests sextest
install: all installdirs
$(INSTALL_PROGRAM) sexc $(DESTDIR)$(bindir)/sexc
$(INSTALL_DATA) $(SEX_LIB) $(DESTDIR)$(sexlibdir)
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
installdirs:
$(INSTALL) -d $(DESTDIR)$(bindir)
$(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(sexlibdir)
uninstall:
rm -f $(DESTDIR)$(bindir)/sexc
rm -f $(SEX_LIB:lib/%=$(DESTDIR)$(sexlibdir)/%)
-rmdir $(DESTDIR)$(sexlibdir)
$(EGGS_STAMP) deps-update: export CHICKEN_EGG_CACHE := $(EGGS_DIR)/cache
$(EGGS_STAMP) deps-update: export CHICKEN_INSTALL_REPOSITORY := $(EGGS_DIR)