Add encapsulation, sum types, type constraints and all the required machinery. Also -> threading macro #64

Merged
pkulev merged 40 commits from static-dispatch into main 2026-10-19 17:07:45 +02:00
Owner
No description provided.
alex-eg added 17 commits 2026-10-09 02:18:35 +02:00
read-public-interface folded with cons and never reversed, so an
imported pub fn whose prototype named a type declared above it in the
same module was pasted before that type, and the unit did not compile.
(record point ...) emits the struct and a typedef of the same name, so
point stands alone wherever (struct point) had to -- in a var, a
pointer, an arglist, a sizeof. struct, union and enum keep C's
meaning, for a type that came from a header or is laid out to match one.
A method is reachable two ways, spelled out as vec2/length or through
its receiver as (. v length), and both land on the same function. The
registry behind the second one is why this is a form and not a
defmacro: a macro expands and vanishes, while resolution, module
export and the spec bounds still to come all want a declaration site
they can read.

The receiver is adjusted to whatever the method asks for -- & where a
value meets a pointer self, * where a pointer meets a value one -- so
the call reads the same whichever is in hand. A field wins over a
method of the same name, so adding one cannot shadow a field in
silence, and needing & on something that is not an lvalue is refused
here rather than by cc: &(f()) is not C, and an expression has nowhere
to put a temporary.

Qualified names are spelled vec2ːlength. The compiler composes them
and the user does not, so __ would collide with a hand-written
vec2__length, and is reserved in C++ besides. The separator has to be
a letter, C admitting letters in an identifier and not symbols, which
is what ruled out § -- hence U+02D0, on the same grounds as the ƛ a
lifted closure carries.

A block crosses a module boundary as a block, its pub methods cut down
to prototypes. Prototypes alone would say that vec2ːlength exists
without saying that vec2 has a length, and the receiver needs the
second thing; which is also why sex-modules now links against types.
A sum is the tag enum, a payload struct per variant that carries
fields, the record holding both, and a constructor each. match is a
switch over the tag whose arms open a block and bind the payload as
locals, so the shape of the generated C is the shape a C programmer
would have written by hand.

What it is for is the refusal: a match that leaves a variant out is an
error naming the ones missing, and so are an arm the sum does not
have, a wrong number of binders, and the same arm written twice. C
cannot say any of that, which is why every switch over a tag in the
wild ends in a defensive default nobody can tell from a real case.

Only the sum is typedef'd. A payload struct would put shapeːcircle in
the ordinary namespace, where the constructor of that name already
lives; as a bare tag it collides with nothing. The sum's own typedef
is emitted ahead of the payload structs, since a variant may hold a
pointer back to the sum, and constructors are static even for a pub
sum, which is pasted into the importer whole.

The scrutinee is read once per binding, so one that is not a path of
names is held in a local first -- otherwise (match (f) ...) would call
f once for the tag and again for every field it binds.
(. v length) made the shape of a form depend on the receiver's type:
(. a b c d e) was either the path a.b.c.d.e or a/b called on c d e,
and nothing but the ops registry could say which. Resolution had to
arbitrate, a field won, and so adding a field named length to vec2
turned every (. v length) in reach from a call into a read -- silently,
and only sometimes into a type error.

Resolution may need types; shape must not. (.length v) puts the method
where an operator belongs, so (. v x) is always the field x, a field
and a method of one name coexist, and a reader needs no symbol table
to see where the arguments start.

Which of &, * or nothing goes in front of the receiver now follows
from its own type against the method's self, rather than from whether
the caller wrote . or ->, so (.length v) and (.length p) are the same
call and -> is member access again and nothing else.

The reader already allowed it: only a standalone . becomes dot-access,
and .foo is the ordinary symbol designated initializers are made of.
The walker offered walk-fn every cdr as well as every form, so the
tail (t) of (fn g () t) read as a call to a macro named t: any
function whose return type or parameter type shared a name with a
macro expanded that tail and died on the macro's arity.
The diagnostics are what these forms are for -- a match that leaves a
variant out is the thing C cannot say -- and until now every one of
them was checked by hand and none by the suite.

The two registries refuse a second declaration of one name, which is
per translation unit and not per process, so semen-process clears
them on the way in. sexc compiles one file per process and never
noticed; a suite that compiles forty in one did.
A spec is a contract that emits nothing; a realization is that
contract's methods for one type, mangled typeːspecːmethod. A default
is copied into every realizing type with the parameter substituted, so
the `show' a default calls is that type's own and the whole thing
stays static dispatch with nothing left at runtime.

The methods land in the ops registry beside inherent ones, which is
what lets (.show v) find them with no second lookup -- and makes the
duplicate check already there catch a spec method colliding with an
ops method or with another spec's. Coherence came free.

A realization's signatures are checked against the spec, arguments and
return type both, after substituting the parameter; a missing required
method is named, and so is one the spec has not got. That is what
makes a spec a contract rather than a naming convention.

The bound is asked rather than declared: realizes? goes into the macro
API beside type-of, and a generic calls it and raises its own error.
That is the return this document was written for -- `plain does not
realize ord' where the line is, instead of a wall of C errors from a
monomorphization two stages downstream.

A default is static even when the realization is pub, and does not
travel on export: every importing unit synthesizes its own copy, so
sending one too would be a second definition of one symbol. The cost
is that a module whose defaults call printf has to pub include
stdio.h -- which is also why pub include and pub import now work, both
having been accepted by read-public-interface and refused by semen.
Encapsulation.org's example was written before any of it was built
and still called methods the way the first draft did. It compiles
now, so it lives here as well, and the doc's block and this file are
the same text.
A target is a filename, and the ː separator turned GL/gl.h into
GLːgl.h, so every program including a header from a subdirectory
stopped compiling the moment qualified names got their separator.
expression-type knew nothing about a .method head, so the receiver of
(.length-sq (.sub a b)) had no type and the outer call could not
resolve. Vector arithmetic is nothing but nested calls like that one.
Every toplevel form was followed by a blank line whether or not one
was written, so the prelude's run of typedefs arrived at twice the
height. A function had no location of its own to measure from either,
having lost it where its header and body are stitched together.
Which of C's two member operators applies is a question the compiler
can already answer -- (.length v) and (.length p) have picked & or *
off the receiver's type since methods moved into the head -- so making
the programmer answer it again asks them to restate what semen knows,
and to revisit every reader of a field the day it becomes a pointer.

A path resolves a step at a time, since only the type in hand answers
for the next field. A receiver nothing can type is read as a value and
warned about rather than refused: refusing leaves no spelling at all
for a struct out of a header nobody has parsed.

Two things had to come along. A parameter written (p * struct point)
was recorded with nothing but the `*' for a type, which left half the
paths in list-macros unanswerable. And fmt-c parenthesised a member
access written inside another, which went unnoticed while only match
nested them -- its bindings have been reading ((s.u).circle).r since
sums went in.
`.' 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.
f5eee71 spelled the closure environment in C99 for a floor nobody meant
to keep: closures were already C11 through _Static_assert. max_align_t
says the alignment in one word again, and the floor test now holds C11.
A bodyless pub record ahead of a private definition exports the handle
and keeps the fields, the way flecs keeps ecs_world_t. It worked with
nothing added, and nothing said so.
lay out threading.sex one step to a line
Some checks failed
Sex CI / build-linux (pull_request) Failing after 5m41s
dfafe8becd
alex-eg requested review from pkulev 2026-10-09 02:18:35 +02:00
alex-eg added 1 commit 2026-10-09 14:18:32 +02:00
link ops.sex against libm
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m28s
0119c85ded
sqrtf lives in libm on glibc; macOS folds it into libSystem, which hid
the missing -lm until CI linked on Linux.
pkulev requested changes 2026-10-14 00:08:07 +02:00
Dismissed
pkulev left a comment
Collaborator

Built and ran this on CHICKEN 6.0.0 at 0119c85. make run-tests is green, including encapsulation, ops, records, specs, sums, threading, worked-example, and check-modules (the opaque tally, the pasted sum, the spec default synthesized again in the importer). The holes below are outside that suite. I compiled each one with ./sexc -C and then with cc -std=c11.

The shape of the feature is right, and the parts the suite pins do what the commits say. A method in the head stays a call when a field of the same name appears. (.length v) and (.length p) agree for a self written (* const vec2). A match that drops a variant is an error that names it. A pub record with no fields is an incomplete struct, completed by the private definition, and the importer only receives the handle. -> threads, GL/gl.h is included as GL/gl.h, and the C11 floor holds under -std=c11 -pedantic-errors.

1. A required spec method stops being required as soon as it has a docstring or a comment

check-realization treats (= (length w) 4) as required and (> (length w) 4) as a default (semen.scm, realization-methods and check-realization). A docstring and a comment are both extra elements, so they are a body.

(spec (p T)
  (fn s ((self (* const T))) void
    "required, documented"))
(realize (p v))

sexc accepts the empty realization and emits a static prototype with no definition:

/* required, documented */
static void vːpːs (const v * self);

A comment is worse, because it becomes a real function. This also accepts (realize (p v)) with no s, and (.s a) compiles:

(spec (p T)
  (fn s ((self (* const T))) int
    ;; must be implemented
    ))
(realize (p v))
static int vːpːs (const v * self) {
    /* must be implemented */
}

The signature check still runs when the method is written out. The hole is the missing-method check, and it is silent. Required versus default wants "a body remains after docstrings and comments are stripped".

2. (self * const vec2) is a pointer in the method and a value at the call

make-fn-env records a spread parameter as the whole tail, which is why (. self x) inside the method is self->x. arglist-types still only unwraps a named parameter of length 2, so fn-type-of stores (self * const v) and method-self-type takes the car of that, the name self. wants-pointer? is false.

(ops v
  (fn len ((self * const v)) int
    (return (. self x))))

(var a v #(v : 3))
(var p (* const v) (& a))
(.len a)
(.len p)
static int vːlen (const v * self) {
    return self->x;
}
return vːlen(a) + vːlen(*p);

cc rejects both arguments. The same split makes the spec checker refuse two spellings of one type: a spec written (self * const T) against a realization written (self (* const v)) is "method's arguments do not match the spec". arglist-types should use the same reading make-fn-env already does.

3. match still lets through things it exists to refuse, and one of them crashes sexc

Two else arms compile. cc reports multiple default labels in one switch.

A repeated variant compiles. cc reports a redeclared enumerator and two shapeːa with different types. A repeated method is already a sex error; a repeated variant is the same fact about a sum.

A variant named tag compiles. The enum is enum shapeːtag and the payload is struct shapeːtag, and those tags share a namespace:

error: ‘shapeːtag’ defined as wrong kind of tag

(match s foo) does not get a sex error. sexc dies in match-arm-variant with (car) bad argument type: foo, because (car arm) runs before the pair check.

match in expression position compiles to a switch where C wants an expression:

(var n int (match s
             ((circle (r)) r)
             ((empty ()) 0)))
int n = switch (s.tag) {

cc: expected expression before ‘switch’. match is a statement. sexc should say so at the form, the way it says so for a scrutinee that is not a sum.

4. A macro in the receiver or the scrutinee is typed before it expands

walk-statement expands a macro when the form it is looking at is the macro call. walk-method-call and walk-match ask expression-type of the receiver and the scrutinee first, and walk them afterwards. A macro standing in either place is still the unexpanded call, so it has no type.

(defmacro (the a) a)
(.len (the a))
(match (the s) ...)

sexc: receiver of this has no type to dispatch on: len, and match wants a sum, and this is not one: unknown. Both expansions are names it already knows how to type. (-> a .len) works only because -> expands before the method call is walked.

5. A typedef alias is the type for fields, and a different type for methods and match

get-fields follows a typedef. ops-key returns the symbol as written, and get-sum looks that symbol up.

(record v ((x int)))
(typedef alias v)
(ops v (fn len ((self (* const v))) int (return (. self x))))
(var a alias #(alias : 4))
(. a x)     ; a.x, compiles
(.len a)    ; no such method on alias len
(sum shape ((circle ((r int))) (empty ())))
(typedef alias shape)
(var s alias (shape/circle 1))
(match s ...)   ; match wants a sum, and this is not one: alias

The alias has the fields and the constructors. Dispatch and match want the underlying name as well.

6. An array field in a variant compiles to C that is not C

(sum shape ((row ((xs [int 4]))) (empty ())))
(var s shape (shape/row #(1 2 3 4)))
(match s
  ((row (xs)) ...)
  ...)
shape s = shapeːrow({1, 2, 3, 4});
int xs[4] = s.u.row.xs;

cc: expected expression before ‘{’, and invalid initializer. A struct field in the same position works (shapeːdot((point){3, 4}), and the binder is a copy). An array cannot be a function argument or the initializer of another array. sexc should refuse the field until it can emit something cc accepts.

Notes, not blocking

Match binders are copies. (= r 9) changes the local and leaves s.u.circle.r alone. That matches the C the commit describes; it is worth one sentence next to the form, because the binder looks like a reference.

(match p ...) with p a (* shape) is refused, and the error names (* shape). (match (* p) ...) works. Fine.

A method can call a method already defined. A later one is no such method, including a spec default that calls a default written further down the spec. A static function has the same forward-reference rule, and here the error is a sex error. Mutual recursion needs a prototype either way.

A method that wants (* v) accepts (* const v). sexc emits the call; cc -Wall warns discards ‘const’ qualifier. The adjustment only asks "is it a pointer".

-> with no import is the call ->(p, x), which cc rejects. %-> is still the arrow ((%-> p x) emitted p->x and compiled). The readme covers . and the threading macro. One line for %-> would save the untyped-pointer case, where (. (no-such) x) warns and emits no_such().x.

(sum box ((inner ((x box))))) is an incomplete type at cc (field ‘x’ has incomplete type). The worked example already says a sum recurs through a pointer.

ops and match indent in sex-mode.el and are absent from the keyword regexp, which did gain record, spec, realize, and sum.

Built and ran this on CHICKEN 6.0.0 at `0119c85`. `make run-tests` is green, including `encapsulation`, `ops`, `records`, `specs`, `sums`, `threading`, `worked-example`, and `check-modules` (the opaque `tally`, the pasted sum, the spec default synthesized again in the importer). The holes below are outside that suite. I compiled each one with `./sexc -C` and then with `cc -std=c11`. The shape of the feature is right, and the parts the suite pins do what the commits say. A method in the head stays a call when a field of the same name appears. `(.length v)` and `(.length p)` agree for a self written `(* const vec2)`. A match that drops a variant is an error that names it. A `pub record` with no fields is an incomplete `struct`, completed by the private definition, and the importer only receives the handle. `->` threads, `GL/gl.h` is included as `GL/gl.h`, and the C11 floor holds under `-std=c11 -pedantic-errors`. ## 1. A required spec method stops being required as soon as it has a docstring or a comment `check-realization` treats `(= (length w) 4)` as required and `(> (length w) 4)` as a default (`semen.scm`, `realization-methods` and `check-realization`). A docstring and a comment are both extra elements, so they are a body. ```sex (spec (p T) (fn s ((self (* const T))) void "required, documented")) (realize (p v)) ``` sexc accepts the empty realization and emits a static prototype with no definition: ```c /* required, documented */ static void vːpːs (const v * self); ``` A comment is worse, because it becomes a real function. This also accepts `(realize (p v))` with no `s`, and `(.s a)` compiles: ```sex (spec (p T) (fn s ((self (* const T))) int ;; must be implemented )) (realize (p v)) ``` ```c static int vːpːs (const v * self) { /* must be implemented */ } ``` The signature check still runs when the method is written out. The hole is the missing-method check, and it is silent. Required versus default wants "a body remains after docstrings and comments are stripped". ## 2. `(self * const vec2)` is a pointer in the method and a value at the call `make-fn-env` records a spread parameter as the whole tail, which is why `(. self x)` inside the method is `self->x`. `arglist-types` still only unwraps a named parameter of length 2, so `fn-type-of` stores `(self * const v)` and `method-self-type` takes the car of that, the name `self`. `wants-pointer?` is false. ```sex (ops v (fn len ((self * const v)) int (return (. self x)))) (var a v #(v : 3)) (var p (* const v) (& a)) (.len a) (.len p) ``` ```c static int vːlen (const v * self) { return self->x; } return vːlen(a) + vːlen(*p); ``` `cc` rejects both arguments. The same split makes the spec checker refuse two spellings of one type: a spec written `(self * const T)` against a realization written `(self (* const v))` is "method's arguments do not match the spec". `arglist-types` should use the same reading `make-fn-env` already does. ## 3. match still lets through things it exists to refuse, and one of them crashes sexc Two `else` arms compile. `cc` reports `multiple default labels in one switch`. A repeated variant compiles. `cc` reports a redeclared enumerator and two `shapeːa` with different types. A repeated method is already a sex error; a repeated variant is the same fact about a sum. A variant named `tag` compiles. The enum is `enum shapeːtag` and the payload is `struct shapeːtag`, and those tags share a namespace: ``` error: ‘shapeːtag’ defined as wrong kind of tag ``` `(match s foo)` does not get a sex error. sexc dies in `match-arm-variant` with `(car) bad argument type: foo`, because `(car arm)` runs before the pair check. match in expression position compiles to a switch where C wants an expression: ```sex (var n int (match s ((circle (r)) r) ((empty ()) 0))) ``` ```c int n = switch (s.tag) { ``` `cc`: `expected expression before ‘switch’`. match is a statement. sexc should say so at the form, the way it says so for a scrutinee that is not a sum. ## 4. A macro in the receiver or the scrutinee is typed before it expands `walk-statement` expands a macro when the form it is looking at is the macro call. `walk-method-call` and `walk-match` ask `expression-type` of the receiver and the scrutinee first, and walk them afterwards. A macro standing in either place is still the unexpanded call, so it has no type. ```sex (defmacro (the a) a) (.len (the a)) (match (the s) ...) ``` sexc: `receiver of this has no type to dispatch on: len`, and `match wants a sum, and this is not one: unknown`. Both expansions are names it already knows how to type. `(-> a .len)` works only because `->` expands before the method call is walked. ## 5. A typedef alias is the type for fields, and a different type for methods and match `get-fields` follows a typedef. `ops-key` returns the symbol as written, and `get-sum` looks that symbol up. ```sex (record v ((x int))) (typedef alias v) (ops v (fn len ((self (* const v))) int (return (. self x)))) (var a alias #(alias : 4)) (. a x) ; a.x, compiles (.len a) ; no such method on alias len ``` ```sex (sum shape ((circle ((r int))) (empty ()))) (typedef alias shape) (var s alias (shape/circle 1)) (match s ...) ; match wants a sum, and this is not one: alias ``` The alias has the fields and the constructors. Dispatch and match want the underlying name as well. ## 6. An array field in a variant compiles to C that is not C ```sex (sum shape ((row ((xs [int 4]))) (empty ()))) (var s shape (shape/row #(1 2 3 4))) (match s ((row (xs)) ...) ...) ``` ```c shape s = shapeːrow({1, 2, 3, 4}); int xs[4] = s.u.row.xs; ``` `cc`: `expected expression before ‘{’`, and `invalid initializer`. A struct field in the same position works (`shapeːdot((point){3, 4})`, and the binder is a copy). An array cannot be a function argument or the initializer of another array. sexc should refuse the field until it can emit something `cc` accepts. ## Notes, not blocking Match binders are copies. `(= r 9)` changes the local and leaves `s.u.circle.r` alone. That matches the C the commit describes; it is worth one sentence next to the form, because the binder looks like a reference. `(match p ...)` with `p` a `(* shape)` is refused, and the error names `(* shape)`. `(match (* p) ...)` works. Fine. A method can call a method already defined. A later one is `no such method`, including a spec default that calls a default written further down the spec. A static function has the same forward-reference rule, and here the error is a sex error. Mutual recursion needs a prototype either way. A method that wants `(* v)` accepts `(* const v)`. sexc emits the call; `cc -Wall` warns `discards ‘const’ qualifier`. The adjustment only asks "is it a pointer". `->` with no import is the call `->(p, x)`, which `cc` rejects. `%->` is still the arrow (`(%-> p x)` emitted `p->x` and compiled). The readme covers `.` and the threading macro. One line for `%->` would save the untyped-pointer case, where `(. (no-such) x)` warns and emits `no_such().x`. `(sum box ((inner ((x box)))))` is an incomplete type at `cc` (`field ‘x’ has incomplete type`). The worked example already says a sum recurs through a pointer. `ops` and `match` indent in `sex-mode.el` and are absent from the keyword regexp, which did gain `record`, `spec`, `realize`, and `sum`.
alex-eg added 11 commits 2026-10-14 17:22:39 +02:00
A required method with a docstring or a comment counted as a default:
the realization could leave it out, and got a prototype with no
definition or a function with no return.
(self * const v) typed the method's self as `self', so a call passed a
value where the method took a pointer, and a spec written one way
refused a realization written the other. A const receiver handed to a
method taking (* v) is now refused rather than left to cc's warning.
Two else arms, a variant declared twice, and a match standing where a
value is wanted all reached cc as broken C; an arm that is not a list
crashed sexc. A variant called tag collided with the tag enum, now
spelled shapeǂ so no variant name can reach it.
A receiver, a scrutinee or the start of a path was typed before the
walk had expanded it, so (.len (the a)) had no type to dispatch on and
(. (the p) x) read a pointer as a value.
A typedef had the fields of its record but none of its methods, and a
typedef of a sum was not a sum to match. A typedef that ends in a
scalar still keeps its own, so (typedef meters float) does not lend
its methods to every float.
The walk stopped at a vector, so whatever a literal held reached the
writer as written: #(v : (.get a)) was (v){.get(a)}, and a path through
a pointer inside one read it as a value.
Only a local's initializer was walked, so at file scope a path was not
dispatched, a lambda was never lifted, and a constructor written in
place would have been left a call to nothing.
A constructor was a static function per variant. One taking an array
field cannot exist, its parameter being a pointer, and building some
variants in place and others by call would make two kinds of
constructor. In place, every one is a constant where one is wanted, an
lvalue a method can take the address of, and nothing a pub sum has to
paste into its importer.

What the function did for free is done here instead: arity is checked,
since a short compound literal zero-fills quietly, and an argument is
converted against its field's closure type. The price is that a
constructor is no longer a function value; a lambda makes one.
An array field compiled to C that cc refused: an array is neither an
initializer of another nor something a payload literal can be built
from. Both the constructor and the binder now spell it out element by
element, which needs a length sexc can count. A sum holding itself by
value is refused at the declaration rather than as cc's incomplete type.
say that a binder is a copy, and where %-> is
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m40s
0a565046af
A match binder looks like a reference to its field and is not one. And
with `.' reading an untyped receiver as a value, nothing said how to
write the arrow by hand.
Author
Owner

Thanks, all six are fixed on the branch, each with its repro turned into a test (tests/encapsulation.scm, sums.sex). make run-tests is green.

1. Required spec methods

f5c53cd. A method is a default when a body remains after the docstring and comments are stripped, as you put it; realization-methods and check-realization now ask the same spec-default?. Both repros report realization is missing a method of.

2. (self * const v)

5ba55f0. arglist-types reads a spread parameter the way make-fn-env does, so the repro is vːlen(&a) + vːlen(p), and a spec accepts a realization written in the other spelling. The const note is folded in here: a (* const v) receiver handed to a method taking (* v) is now method may change its receiver, and this one is const.

3. match

3baaafa. A second else, a variant declared twice, and an arm that is not one are sex errors; (match s foo) no longer crashes. A match where a value is wanted is match is a statement, and has no value: initializers, returns, arguments, receivers, literal elements. An if or while condition is not covered yet, since walk-parts takes every slot alike; cc still refuses that one.

A variant named tag is not refused: the enum moved out of its way. It is enum shapeǂ now, constants shapeǂcircle (U+01C2, clean under -Wunicode-homoglyph), so shapeːtag is only ever a payload struct.

4. Macros in the receiver and the scrutinee

bb2f05f. expression-type expands a macro call and types the expansion, so this holds wherever a type is asked of an unwalked form. The base of a . path had the same hole: (. (the p) x) warned and wrote ..

5. Typedef aliases

224ef8f. Methods, realizations and sums are filed under what a typedef names, so alias dispatches and matches as v and shape do. A typedef chain that ends in a scalar stops at its last typedef: (typedef meters float) keeps its methods rather than lending them to every float.

6. Array fields

Not refused; supported, which took four commits.

  • 9af9113: the walk never entered a brace literal, so #(v : (.get a)) was (v){.get(a)}, and a path through a pointer inside a literal read it as a value. This one was already live on vs-map-viewer.
  • e91b44d: a global's initializer is walked like a local's.
  • 427177d: constructors are written in place, with no function at all. A function cannot take an array, its parameter being a pointer, and two kinds of constructor were worse than none. In place, (shape/circle 1) is a constant at file scope, an lvalue a pointer-self method can be handed, and a pub sum pastes nothing but declarations. sexc now checks the argument count (a short compound literal zero-fills quietly) and converts an argument against its field's closure type. The price: a constructor is not a function value, and the error says to call it from a lambda.
  • 9c5f678: an array field takes a literal in place, (struct shapeːrow){{1, 2, 3, 4}}, and an array by its elements, {a[0], a[1], a[2], a[3]}. A binder is initialized the same way, so it stays a copy. The length has to be countable (a number or a define of one), equal to the field's, and the array read from a path, not a call.

Notes

  • Binders are copies: one line next to the first match in worked-example.sex (0a56504).
  • (match p ...) on a pointer: left as it is.
  • Forward references to methods: left as they are. It is C's rule for functions, and the error is already a sex error.
  • (* v) accepting (* const v): refused now, in 5ba55f0.
  • %->: one line under Member access in the Readme (0a56504).
  • A sum holding itself by value: refused at the declaration, in 9c5f678. A pointer back is fine.
  • ops and match in the keyword regexp: b51cda0.
Thanks, all six are fixed on the branch, each with its repro turned into a test (`tests/encapsulation.scm`, `sums.sex`). `make run-tests` is green. ## 1. Required spec methods f5c53cd. A method is a default when a body remains after the docstring and comments are stripped, as you put it; `realization-methods` and `check-realization` now ask the same `spec-default?`. Both repros report `realization is missing a method of`. ## 2. `(self * const v)` 5ba55f0. `arglist-types` reads a spread parameter the way `make-fn-env` does, so the repro is `vːlen(&a) + vːlen(p)`, and a spec accepts a realization written in the other spelling. The const note is folded in here: a `(* const v)` receiver handed to a method taking `(* v)` is now `method may change its receiver, and this one is const`. ## 3. match 3baaafa. A second `else`, a variant declared twice, and an arm that is not one are sex errors; `(match s foo)` no longer crashes. A match where a value is wanted is `match is a statement, and has no value`: initializers, returns, arguments, receivers, literal elements. An `if` or `while` condition is not covered yet, since `walk-parts` takes every slot alike; cc still refuses that one. A variant named `tag` is not refused: the enum moved out of its way. It is `enum shapeǂ` now, constants `shapeǂcircle` (U+01C2, clean under `-Wunicode-homoglyph`), so `shapeːtag` is only ever a payload struct. ## 4. Macros in the receiver and the scrutinee bb2f05f. `expression-type` expands a macro call and types the expansion, so this holds wherever a type is asked of an unwalked form. The base of a `.` path had the same hole: `(. (the p) x)` warned and wrote `.`. ## 5. Typedef aliases 224ef8f. Methods, realizations and sums are filed under what a typedef names, so `alias` dispatches and matches as `v` and `shape` do. A typedef chain that ends in a scalar stops at its last typedef: `(typedef meters float)` keeps its methods rather than lending them to every float. ## 6. Array fields Not refused; supported, which took four commits. - 9af9113: the walk never entered a brace literal, so `#(v : (.get a))` was `(v){.get(a)}`, and a path through a pointer inside a literal read it as a value. This one was already live on vs-map-viewer. - e91b44d: a global's initializer is walked like a local's. - 427177d: constructors are written in place, with no function at all. A function cannot take an array, its parameter being a pointer, and two kinds of constructor were worse than none. In place, `(shape/circle 1)` is a constant at file scope, an lvalue a pointer-self method can be handed, and a pub sum pastes nothing but declarations. sexc now checks the argument count (a short compound literal zero-fills quietly) and converts an argument against its field's closure type. The price: a constructor is not a function value, and the error says to call it from a lambda. - 9c5f678: an array field takes a literal in place, `(struct shapeːrow){{1, 2, 3, 4}}`, and an array by its elements, `{a[0], a[1], a[2], a[3]}`. A binder is initialized the same way, so it stays a copy. The length has to be countable (a number or a `define` of one), equal to the field's, and the array read from a path, not a call. ## Notes - Binders are copies: one line next to the first match in `worked-example.sex` (0a56504). - `(match p ...)` on a pointer: left as it is. - Forward references to methods: left as they are. It is C's rule for functions, and the error is already a sex error. - `(* v)` accepting `(* const v)`: refused now, in 5ba55f0. - `%->`: one line under Member access in the Readme (0a56504). - A sum holding itself by value: refused at the declaration, in 9c5f678. A pointer back is fine. - `ops` and `match` in the keyword regexp: b51cda0.
pkulev approved these changes 2026-10-14 21:22:32 +02:00
Dismissed
pkulev left a comment
Collaborator

Re-reviewed at 0a56504 on CHICKEN 6.0.0. make run-tests is green, including the new cases in encapsulation and sums.sex. I recompiled the six repros with ./sexc -C and cc -std=c11.

All six are fixed.

  1. A required method with a docstring or a comment is still required. The empty realization reports realization is missing a method of, and providing s emits the body.
  2. (self * const v) is vːlen(&a) + vːlen(p), and that spelling realizes a spec written (* const v). A (* const v) receiver handed to (* v) is method may change its receiver, and this one is const.
  3. A second else, a repeated variant, and (match s foo) are sex errors. A variant named tag compiles: the enum is shapeǂ, the payload is struct shapeːtag. (var n int (match ...)) is match is a statement, and has no value.
  4. (.len (the a)) and (match (the s) ...) compile to the expansion.
  5. An alias of a record dispatches, and an alias of a sum matches. (typedef meters float) does not lend its method to a float.
  6. (shape/row src) is (struct shapeːrow){{src[0], src[1], src[2], src[3]}}, and the binder is the same copy element by element. A sum that holds itself by value is refused at the declaration.

ops and match are in the sex-mode keyword list. %-> is in the readme.

Still open

if, while, and for still walk every slot as a statement, so a match in the condition is a switch where C wants an expression:

if (switch (s.tag) {
while (switch (s.tag) {
for (int i = 0; switch (s.tag) {

cc rejects each one. An argument, a returned value, an assignment, and (&& (match ...) ...) are already match is a statement. This is the gap you named; for's condition is the same one.

A file-scope constructor is a compound literal, and -std=c11 -pedantic-errors rejects it as initializer element is not constant, the same way it rejects (var g point #(point : 1 2)). Plain cc -std=c11 accepts both. The new test checks that the spelling is static t g = (t){ and does not compile it. A brace initializer would be a C11 constant; the nested (struct shapeːcircle){1} is the part that is not.

A brace literal longer than an array field still reaches cc (excess elements in array initializer). A shorter one zero-fills. A named array of the wrong length is already array is not as long as its field.

Re-reviewed at `0a56504` on CHICKEN 6.0.0. `make run-tests` is green, including the new cases in `encapsulation` and `sums.sex`. I recompiled the six repros with `./sexc -C` and `cc -std=c11`. All six are fixed. 1. A required method with a docstring or a comment is still required. The empty realization reports `realization is missing a method of`, and providing `s` emits the body. 2. `(self * const v)` is `vːlen(&a) + vːlen(p)`, and that spelling realizes a spec written `(* const v)`. A `(* const v)` receiver handed to `(* v)` is `method may change its receiver, and this one is const`. 3. A second `else`, a repeated variant, and `(match s foo)` are sex errors. A variant named `tag` compiles: the enum is `shapeǂ`, the payload is `struct shapeːtag`. `(var n int (match ...))` is `match is a statement, and has no value`. 4. `(.len (the a))` and `(match (the s) ...)` compile to the expansion. 5. An alias of a record dispatches, and an alias of a sum matches. `(typedef meters float)` does not lend its method to a `float`. 6. `(shape/row src)` is `(struct shapeːrow){{src[0], src[1], src[2], src[3]}}`, and the binder is the same copy element by element. A sum that holds itself by value is refused at the declaration. `ops` and `match` are in the `sex-mode` keyword list. `%->` is in the readme. ## Still open `if`, `while`, and `for` still walk every slot as a statement, so a match in the condition is a switch where C wants an expression: ```c if (switch (s.tag) { while (switch (s.tag) { for (int i = 0; switch (s.tag) { ``` `cc` rejects each one. An argument, a returned value, an assignment, and `(&& (match ...) ...)` are already `match is a statement`. This is the gap you named; `for`'s condition is the same one. A file-scope constructor is a compound literal, and `-std=c11 -pedantic-errors` rejects it as `initializer element is not constant`, the same way it rejects `(var g point #(point : 1 2))`. Plain `cc -std=c11` accepts both. The new test checks that the spelling is `static t g = (t){` and does not compile it. A brace initializer would be a C11 constant; the nested `(struct shapeːcircle){1}` is the part that is not. A brace literal longer than an array field still reaches `cc` (`excess elements in array initializer`). A shorter one zero-fills. A named array of the wrong length is already `array is not as long as its field`.
alex-eg added 3 commits 2026-10-15 12:31:05 +02:00
An if, while or for walked every slot as a statement, so a match in
its test came out as a switch inside the condition, which cc refuses.
A longer one reached cc as excess elements, and a shorter one filled
the rest with zeros where a named array of that length was refused.
start a global from braces, not a compound literal
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m42s
913af0b463
A compound literal is no constant in C11, so a global built by a
constructor or a typed literal failed under -pedantic-errors; gcc says
so, clang lets it pass.
Author
Owner

Thanks. The three that were still open are closed on the branch. make run-tests is green.

match in a test

0a5eb1e. if, while, for and switch no longer walk every slot alike. The slots C reads as values are walked as operands: an if's tests (not its trailing else), all three of for's header, the value a while tests or a switch switches on. All three repros are match is a statement. A match in a branch, the else among them, is still a switch.

Globals

913af0b. A global's initializer is written as braces, the compound literal's type dropped at every level: static t g = {.tag = tǂa, .u = {.a = {1}}};, and (var g point #(point : 1 2)) is static point g = {1, 2};. Locals keep their compound literals. c11.sex now holds a global record and a global sum, so -std=c11 -pedantic-errors compiles them. It fails there with gcc before the fix. Clang accepted the old spelling even under -pedantic-errors, which is why it got past my checks.

Array literals

6cda087. A brace literal for an array field is held to the field's length, the same as a named array: longer or shorter is array is not as long as its field. A shorter one no longer zero-fills quietly, the same reasoning as the constructor's argument count.

Thanks. The three that were still open are closed on the branch. `make run-tests` is green. ## match in a test 0a5eb1e. `if`, `while`, `for` and `switch` no longer walk every slot alike. The slots C reads as values are walked as operands: an `if`'s tests (not its trailing else), all three of `for`'s header, the value a `while` tests or a `switch` switches on. All three repros are `match is a statement`. A match in a branch, the else among them, is still a switch. ## Globals 913af0b. A global's initializer is written as braces, the compound literal's type dropped at every level: `static t g = {.tag = tǂa, .u = {.a = {1}}};`, and `(var g point #(point : 1 2))` is `static point g = {1, 2};`. Locals keep their compound literals. `c11.sex` now holds a global record and a global sum, so `-std=c11 -pedantic-errors` compiles them. It fails there with gcc before the fix. Clang accepted the old spelling even under `-pedantic-errors`, which is why it got past my checks. ## Array literals 6cda087. A brace literal for an array field is held to the field's length, the same as a named array: longer or shorter is `array is not as long as its field`. A shorter one no longer zero-fills quietly, the same reasoning as the constructor's argument count.
alex-eg requested review from pkulev 2026-10-18 13:26:49 +02:00
pkulev requested changes 2026-10-18 20:43:07 +02:00
Dismissed
pkulev left a comment
Collaborator

Re-reviewed at 913af0b on CHICKEN 6.0.0. make run-tests is green, including modules ok and exit code ok. The three programs from the last note compile.

A match in an if test, a while test, a for header or a switch scrutinee is match is a statement, and has no value. A match in either branch, the else among them, is still a switch, and (for (var i int 0) (< i 3) (++ i) ...) is for (int i = 0; i < 3; ++i). (for (var i _ 0) ...) infers int.

A global is braces, and cc -std=c11 -pedantic-errors accepts them: {2, 3}, {.x = 4, .y = 5}, {.tag = shapeǂsquare, .u = {.square = {1}}}, {.tag = shapeǂdot}, {.tag = shapeǂrow, .u = {.row = {{8, 9}}}}, {{1, 2}, {3, 4}}. A local stays (point){6, 7}.

#(1) and #(1 2 3) for an [int 2] field are array is not as long as its field. #(1 2) stays {{1, 2}}.

Two programs beside those still fail.

1. A case label is still a statement. if, while, for and switch walk their value slots as operands. case and case/fallthrough still walk every slot as a statement, and the label is a value.

(switch 1
  (case (match s ((circle (r)) r) (else 0)) (= n 1)))

sexc accepts it. The C is case switch:, and cc says expected expression before 'switch'. case/fallthrough splices the same switch into the label: case switch: then case s.tag:.

2. Stripping a global's type happens before _ is solved. bare-braces drops the words before : and then resolve-wildcard sees what remains. A brace list has no type of its own.

(record point ((x int) (y int)))
(var g _ #(point : 2 3))

is cannot infer the type of: g. The same declaration inside main is point g = (point){2, 3}. A global (var n _ (+ 1 2)) is still static int n = 1 + 2, and (var xs [_ 3] #(4 5 6)) is still static int xs[3]. An array of typed literals loses the element type with the prefix:

(var ps [_ 2] #(#(point : 1 2) #(point : 3 4)))

is cannot infer the type of: ps. (var u _ (shape/square 1)) at file scope fails the same way; inside a function it is shape u = (shape){.tag = shapeǂsquare, ...}.

Re-reviewed at `913af0b` on CHICKEN 6.0.0. `make run-tests` is green, including `modules ok` and `exit code ok`. The three programs from the last note compile. A match in an `if` test, a `while` test, a `for` header or a `switch` scrutinee is `match is a statement, and has no value`. A match in either branch, the else among them, is still a switch, and `(for (var i int 0) (< i 3) (++ i) ...)` is `for (int i = 0; i < 3; ++i)`. `(for (var i _ 0) ...)` infers `int`. A global is braces, and `cc -std=c11 -pedantic-errors` accepts them: `{2, 3}`, `{.x = 4, .y = 5}`, `{.tag = shapeǂsquare, .u = {.square = {1}}}`, `{.tag = shapeǂdot}`, `{.tag = shapeǂrow, .u = {.row = {{8, 9}}}}`, `{{1, 2}, {3, 4}}`. A local stays `(point){6, 7}`. `#(1)` and `#(1 2 3)` for an `[int 2]` field are `array is not as long as its field`. `#(1 2)` stays `{{1, 2}}`. Two programs beside those still fail. **1. A case label is still a statement.** `if`, `while`, `for` and `switch` walk their value slots as operands. `case` and `case/fallthrough` still walk every slot as a statement, and the label is a value. ```sex (switch 1 (case (match s ((circle (r)) r) (else 0)) (= n 1))) ``` sexc accepts it. The C is `case switch:`, and cc says `expected expression before 'switch'`. `case/fallthrough` splices the same switch into the label: `case switch:` then `case s.tag:`. **2. Stripping a global's type happens before `_` is solved.** `bare-braces` drops the words before `:` and then `resolve-wildcard` sees what remains. A brace list has no type of its own. ```sex (record point ((x int) (y int))) (var g _ #(point : 2 3)) ``` is `cannot infer the type of: g`. The same declaration inside `main` is `point g = (point){2, 3}`. A global `(var n _ (+ 1 2))` is still `static int n = 1 + 2`, and `(var xs [_ 3] #(4 5 6))` is still `static int xs[3]`. An array of typed literals loses the element type with the prefix: ```sex (var ps [_ 2] #(#(point : 1 2) #(point : 3 4))) ``` is `cannot infer the type of: ps`. `(var u _ (shape/square 1))` at file scope fails the same way; inside a function it is `shape u = (shape){.tag = shapeǂsquare, ...}`.
pkulev requested changes 2026-10-19 00:24:19 +02:00
Dismissed
Readme.org Outdated
@@ -145,0 +176,4 @@
~sexc~ looks for them beside itself, so a work tree needs nothing set
up; installed, ~$(bindir)/sexc~ finds them under ~$(prefix)/share/sex~.
There is one so far.
Collaborator

That is a bit excessive. There will be others for sure.

That is a bit excessive. There will be others for sure.
Author
Owner

True.

True.
Readme.org Outdated
@@ -145,0 +178,4 @@
There is one so far.
*** threading-macros
Collaborator

I would look ahead a little and avoided introducing the whole standard library in the README. It'll better to create separate org file and link it here.

I would look ahead a little and avoided introducing the whole standard library in the README. It'll better to create separate org file and link it here.
Author
Owner

Indeed. But I don't think that one file will be enough. Every module should have it's own file at least.

Indeed. But I don't think that one file will be enough. Every module should have it's own file at least.
@@ -184,1 +192,4 @@
(('dot-access . rest) (cons '%. (map walk-expr rest)))
;; `%->' is the C arrow. Nothing writes it: it is what a member
;; path lowers to where the thing it reads from is a pointer, the
;; name `->' itself being the threading macro
Collaborator

Why C writer would know anything about what you do with the sex standard library? I suppose that mention should be rather deleted.

Why C writer would know anything about what you do with the sex standard library? I suppose that mention should be rather deleted.
Author
Owner

Well... Because it's a name clash with very well known and widely used bit of C syntax. So one might want to know why it's missing from Sex, while most of other semantics is accounted for.
However I don't have strong preference, might as well drop the comment.

Well... Because it's a name clash with very well known and widely used bit of C syntax. So one might want to know why it's missing from Sex, while most of other semantics is accounted for. However I don't have strong preference, might as well drop the comment.
@@ -0,0 +12,4 @@
(record point ((x int) (y int)))
(record named "Fields of more than one kind, and a docstring."
Collaborator

Maybe that would be better, dunno.

(record named 
  "Fields of more than one kind, and a docstring."
  ((id int) (first-name (* const char))))
Maybe that would be better, dunno. ```scheme (record named "Fields of more than one kind, and a docstring." ((id int) (first-name (* const char)))) ```
@@ -0,0 +1,56 @@
(input)
Collaborator

Dunno, maybe stdlib tests deserve their own space.

Dunno, maybe stdlib tests deserve their own space.
Author
Owner

They do, but I think we should do it later. Probably also groom sex-programs too, or even eliminate it altogether. I envision something like gcc's test suite, or autotools' feature test programs. In any case, for now test programs will do.

They do, but I think we should do it later. Probably also groom sex-programs too, or even eliminate it altogether. I envision something like gcc's test suite, or autotools' feature test programs. In any case, for now test programs will do.
@@ -0,0 +6,4 @@
"one step is just the value: 7")
(return 0)
;;; `->' used to be C's arrow. The arrow is what `.' writes now when
Collaborator

Why that story is important?
The language is in alpha stage, everything changes from PR to PR, no need to write it down everywhere.

Why that story is important? The language is in alpha stage, everything changes from PR to PR, no need to write it down everywhere.
Author
Owner

I agree.

I agree.
@@ -0,0 +3,4 @@
"-5")
(return 0)
;;; The worked example from Encapsulation.org, kept here so it stays
Collaborator

Who? From where? Why worked-example.sex?

Who? From where? Why worked-example.sex?
Author
Owner

Something that moved from an uncommited doc. Will be rephrased.

Something that moved from an uncommited doc. Will be rephrased.
types.scm Outdated
@@ -93,0 +148,4 @@
;;; Both of these refuse a second declaration of the same name, which
;;; is per translation unit rather than per process -- so a process
;;; that compiles two units has to start the second one clean.
(define (reset-declarations!)
Collaborator

The order of definitions here is quite chaotic. +ops-db+ defined below. That is difficult to read for a human.

The order of definitions here is quite chaotic. `+ops-db+` defined below. That is difficult to read for a human.
Author
Owner

True, I'll rearrange them.

True, I'll rearrange them.
alex-eg added 8 commits 2026-10-19 14:57:18 +02:00
case and case/fallthrough walked their label as a statement, so a match
there was taken and wrote `case switch:'.
A global's initializer was stripped to plain braces before `_' was
solved, so #(point : 2 3) left nothing to infer point from.
The lookups came after the tables built on them, type-key after the
sums filed under it, and reset-declarations! before +ops-db+.
give a record's docstring a line of its own
All checks were successful
Sex CI / build-linux (pull_request) Successful in 5m43s
Sex CI / build-linux (push) Successful in 5m42s
db5507b180
Author
Owner

Thanks. Both programs are fixed on the branch, and the inline notes are addressed. make run-tests is green.

A case label

a0b3239. case and case/fallthrough read their label as a value, the way switch reads its scrutinee; their body is still statements. Both repros are match is a statement. A match in a case body is still a switch.

_ on a global

a885c21. The type is now solved before the braces are stripped, so #(point : 2 3) still names point when _ needs it. (var g _ #(point : 2 3)) is static point g = {2, 3};. (var ps [_ 2] #(#(point : 1 2) #(point : 3 4))) is static point ps[2] = {{1, 2}, {3, 4}};. (var u _ (shape/square 1)) is static shape u = {.tag = shapeǂsquare, .u = {.square = {1}}};. c11.sex now declares its globals with _ and adds the array, so all three compile under -pedantic-errors.

Inline notes

  • 063770d: the standard library section no longer counts its modules. Each module gets its own doc file beside it, starting with lib/threading-macros.org, listed from the readme.
  • 958978e: the %-> comment no longer mentions the threading macro.
  • 8f7b26e: worked-example.sex is now encapsulation.sex, and its header says what the program covers.
  • b5030e3: threading.sex says what it checks, without the history.
  • 5f130f4: types.scm reads top down: lookups, type-key, sums, ops, specs, then reset-declarations!.
  • db5507b: the record's docstring is on its own line.

Stdlib tests stay in tests/sex-programs/ for now, as discussed in the thread.

Thanks. Both programs are fixed on the branch, and the inline notes are addressed. `make run-tests` is green. ## A case label a0b3239. `case` and `case/fallthrough` read their label as a value, the way `switch` reads its scrutinee; their body is still statements. Both repros are `match is a statement`. A match in a case body is still a switch. ## `_` on a global a885c21. The type is now solved before the braces are stripped, so `#(point : 2 3)` still names `point` when `_` needs it. `(var g _ #(point : 2 3))` is `static point g = {2, 3};`. `(var ps [_ 2] #(#(point : 1 2) #(point : 3 4)))` is `static point ps[2] = {{1, 2}, {3, 4}};`. `(var u _ (shape/square 1))` is `static shape u = {.tag = shapeǂsquare, .u = {.square = {1}}};`. `c11.sex` now declares its globals with `_` and adds the array, so all three compile under `-pedantic-errors`. ## Inline notes - 063770d: the standard library section no longer counts its modules. Each module gets its own doc file beside it, starting with `lib/threading-macros.org`, listed from the readme. - 958978e: the `%->` comment no longer mentions the threading macro. - 8f7b26e: `worked-example.sex` is now `encapsulation.sex`, and its header says what the program covers. - b5030e3: `threading.sex` says what it checks, without the history. - 5f130f4: `types.scm` reads top down: lookups, `type-key`, sums, ops, specs, then `reset-declarations!`. - db5507b: the record's docstring is on its own line. Stdlib tests stay in `tests/sex-programs/` for now, as discussed in the thread.
alex-eg requested review from pkulev 2026-10-19 15:03:07 +02:00
pkulev approved these changes 2026-10-19 16:55:16 +02:00
pkulev left a comment
Collaborator

Approved at db5507b on CHICKEN 6.0.0. make run-tests is green, including modules ok and exit code ok.

Both programs from the last review are fixed.

A match in a case label or a case/fallthrough label is match is a statement, and has no value. A match in the case body, and one in default, is still a switch. (case (+ x 1) ...) is a separate matter, below.

_ is solved before the braces are stripped. With cc -std=c11 -pedantic-errors:

static point g = {2, 3};
static shape u = {.tag = shapeǂsquare, .u = {.square = {1}}};
static point ps[2] = {{1, 2}, {3, 4}};

(var n _ (+ 1 2)) is static int n = 1 + 2, and a designated (var named point #(.x 4 .y 5)) is static point named = {.x = 4, .y = 5}. A local stays point local = (point){6, 7}. c11.sex prints c11: 42 43 6 4 6 12.

Still open

c-case reads a pair label as several labels, which is how (case (1 2 3) ...) stacks case 1: case 2: case 3:. A call is a pair too, so

(case (+ 1 2) (= n 9))

is case +: case 1: case 2:. An atom label is unchanged.

Approved at `db5507b` on CHICKEN 6.0.0. `make run-tests` is green, including `modules ok` and `exit code ok`. Both programs from the last review are fixed. A match in a `case` label or a `case/fallthrough` label is `match is a statement, and has no value`. A match in the case body, and one in `default`, is still a switch. `(case (+ x 1) ...)` is a separate matter, below. `_` is solved before the braces are stripped. With `cc -std=c11 -pedantic-errors`: ```c static point g = {2, 3}; static shape u = {.tag = shapeǂsquare, .u = {.square = {1}}}; static point ps[2] = {{1, 2}, {3, 4}}; ``` `(var n _ (+ 1 2))` is `static int n = 1 + 2`, and a designated `(var named point #(.x 4 .y 5))` is `static point named = {.x = 4, .y = 5}`. A local stays `point local = (point){6, 7}`. `c11.sex` prints `c11: 42 43 6 4 6 12`. ## Still open `c-case` reads a pair label as several labels, which is how `(case (1 2 3) ...)` stacks `case 1:` `case 2:` `case 3:`. A call is a pair too, so ```sex (case (+ 1 2) (= n 9)) ``` is `case +:` `case 1:` `case 2:`. An atom label is unchanged.
pkulev merged commit db5507b180 into main 2026-10-19 17:07:45 +02:00
pkulev deleted branch static-dispatch 2026-10-19 17:07:45 +02:00
Author
Owner

Still open

c-case reads a pair label as several labels, which is how (case (1 2 3) ...) stacks case 1: case 2: case 3:. A call is a pair too, so

(case (+ 1 2) (= n 9))

is case +: case 1: case 2:. An atom label is unchanged.

This is fixed in 39a5f4, will be merged later

> ## Still open > > `c-case` reads a pair label as several labels, which is how `(case (1 2 3) ...)` stacks `case 1:` `case 2:` `case 3:`. A call is a pair too, so > > ```sex > (case (+ 1 2) (= n 9)) > ``` > > is `case +:` `case 1:` `case 2:`. An atom label is unchanged. > This is fixed in 39a5f4, will be merged later
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alex-eg/sex#64