-
Notifications
You must be signed in to change notification settings - Fork 5
style guide
Being consistent is more important than adhering to any particular style.
Being clear is even more important than being consistent.
Use spaces to indent, not tabs. Using tabs may lead to misaligned error messages.
Library code uses kebab-case
. It is mildly suggested to follow this convention.
By design, identifiers can use all of camelCase
, PascalCase
, snake_case
, and kebab-case
with use of '
( prime ) possible as well, so you can probably use any convention you prefer.
Library code attempts to comply with the following guidelines:
- well-known combinators are named in single or double all caps
- primitive constructors ( eg.
Pair
) are named with initial caps - other functions ( eg.
fst
) are named with initial lowercase letters - predicates ( ie. functions that return a boolean, esp. unary ones ) may use a name ending in
?
- multi-part names use lowercase throughout ( eg.
zip-with
), unless using established abbreviations ( eg.is-ASCII?
) - unused bindings are named starting with
_
but are otherwise complete and descriptive - names end in a letter, digit, prime (
'
) or question mark (?
), not in-
or_
- when constructing a new primitive value within a function, split function and constructor arguments ( eg.
succ = \ n . \ f x . f (n x f)
) - for Scott-encoded numerals, use
n-1
as an argument name to destructuren
- a name ending in
s
indicates a list of things; ending in doubles
a list of lists of things ( eg.ls
is a list ofl
s )
Library code mostly reserves certain names for well-known purposes. This helps prevent ( some ) name clashes.
Single and double capital letter names are expected to be combinators; specifically B, C, I, K, M, S, T, V, W, Y, Z
and BB, CB, KK, KI, CK
are expected to be implemented as in the library combinators.lc
. Note that BB
and KK
are B B B
resp. B K K
!
( OR
might be used as logical or
in ALL_CAPS style source. )
zero, succ, pred, add, sub, mul, div-mod, div, mod, pow, gcd, lcm, compare, le, lt, eq, ge, gt
are expected to refer to numerals;
False, True, not, and, or, xor
to booleans;
LT, EQ, GT
to orderings;
Pair, fst, snd
to pairs.
The active encoding ( Church, Scott, or otherwise ) of esp. numerals and booleans should be specified in a comment ( which might be an as yet non-functional #import
pragma ).
Library code mostly indents by two spaces, except under \
or (
where it may use four for clarity.
Separating and indenting multiple arguments may be done by indenting from the previous level, indenting from the parent function position, or by aligning under the first argument if not preceded by a newline.