AtlatestRepositorysigil-fp

sigil-fp / tree / src / sigil / fpchain.sgl

1;;; (sigil fp chain) - Threading Macros (re-exported from core)
2;;;
3;;; The threading macros `chain`, `->`, and `some->` now live in
4;;; `(sigil core)`, where they were before the 2026-03-31 FP extraction.
5;;; They are structural control-flow syntax used throughout idiomatic Sigil,
6;;; not optional combinators, so they belong in core. Since `(sigil core)` is
7;;; auto-imported into every module, any program already has these macros in
8;;; scope without importing anything.
9;;;
10;;; This module re-exports them so existing `(import (sigil fp chain))` and
11;;; `(import (sigil fp))` consumers keep working unchanged. Because the
12;;; re-exported bindings ARE core's bindings (not fresh definitions), a program
13;;; importing both `(sigil core)` and `(sigil fp)` sees no duplicate-binding
14;;; conflict.
15;;;
16;;; The optional combinators (`compose`, `pipe`, `partial`, `partial-right`,
17;;; `flip`, `complement`, `juxt`, `const`) remain in `(sigil fp fn)`.
18;;;
19;;; ## Basic Threading
20;;;
21;;; ```scheme
22;;; ;; Thread-first (no placeholder needed)
23;;; (chain 5 (+ 3) (* 2))
24;;; ; => 16 (same as (* (+ 5 3) 2))
25;;;
26;;; ;; Explicit placeholder with _
27;;; (chain '(1 2 3)
28;;; (map (lambda (x) (* x 2)) _)
29;;; (apply + _))
30;;; ; => 12
31;;; ```
32;;;
33;;; ## Short-Circuit Threading
34;;;
35;;; ```scheme
36;;; ;; Returns #f if any step produces #f
37;;; (some-> user
38;;; (dict-ref _ name:)
39;;; (string-split " " _)
40;;; car)
41;;; ```
43(define-library (sigil fp chain)
44 (import (sigil core))
45 (export chain -> some->))