if (!(x/2-1)) { ...
EDIT: Oops, confused the original with x==2 || x==3. Instead, we can use !(x-1>>1), which precedence rules parse as !((x-1)>>1). Int L[A],m,b,*D=A,
*c,*a=L,C,*U=L,u;s
(_){u--&&s(a=*a);}
char*B,I,O;S(){b=b
--?b:m|read(0,&I,1
)-1;return~I>>b&1;
}k(l,u){for(;l<=u;
U-L<A?*U++=46^l++[
"-,&,,/.--/,:-,'/"
".-,-,,/.-,*,//..,"
]:exit(5));}p(Int*m){
return!*U?*m=S()?U++,!S
()?m[1]=p(++U),2:3:1,p(U)
:S()?U+=2:p(U[1]++),U-m;}x(
c){k(7*!b,9);*U++=b&&S();c&&x
(b);}d(Int*l){--l[1]||d(l[d(*l),
*l=B,B=l,2]);}main(e){for(k(10,33
),a[4]-=m=e-2&7,a[23]=p(U),b=0;;e-2
?e?e-3?s(D=a),C=a [3],++1[a=a[2]],d(
D):c?D=c,c=*D,*D= a,a=D:exit(L[C+1])
:C--<23?C=u+m&1?O =O+O|C&1,9:write(m
||(O=C+28),&O,1)+ 1:(S(),x(0<b++?k(0,
6),U[-5]=96:0)):( D=B?B:calloc(4,X))
?B=*D,*D=c,c=D,D[ 2]=a,a[++D[1]]++,D
[3]=++C+u:exit(6) )e=L[C++],u=L[C];}
while a less obfuscated and highly performant implementation https://github.com/tromp/AIT/blob/master/uni.c based on combinatory graph reduction takes 446 lines. 01000110100001000
00001100000010111
00110000111111100
00101110011111110
00000111100000010
11101110011011110
01111111100001111
11110000101111010
01110100101111101
00101101010011010
which encodes the term
(λ11)(λ(λλλ1(λλ2(1(λ6(λ2(6(λλ3(λλ23(14))))(7(λ7(λ31(21)))))))(41(111))))(11))
in De Bruijn notatation, with lambda diagram [3] ┬─┬ ────────────────────────────────────────────┬─┬
└─┤ ──────┬───────────────┬──────────────────── ├─┘
│ ──────┼───┬───────────┼─┬─────────┬──────── │
│ ┬─────┼───┼───────────┼─┼─────────┼──────── │
│ │ ┬───┼───┼───────────┼─┼─────────┼──────── │
│ │ ┼─┬─┼───┼───────────┼─┼─────────┼─┬─┬─┬─┬ │
│ │ │ │ ┼─┬─┼───────────┼─┼──────── └─┤ └─┤ │ │
│ │ │ │ │ ┼─┼─┬─────────┼─┼─┬────── │ ├─┘ │
│ │ │ │ │ │ │ ┼───────┬ │ ┼─┼───┬── ├───┘ │
│ │ │ │ │ │ │ ┼───┬───┼ │ │ ┼─┬─┼─┬ │ │
│ │ │ │ │ │ │ │ ┬─┼───┼ │ │ └─┤ ├─┘ │ │
│ │ │ │ │ │ │ │ ┼─┼─┬─┼ │ │ ├─┘ │ │
│ │ │ │ │ │ │ │ └─┤ ├─┘ │ ├───┘ │ │
│ │ │ │ │ │ │ │ ├─┘ ├─┘ │ │
│ │ │ │ │ │ │ ├───┘ │ │ │
│ │ │ │ │ │ ├─┘ │ │ │
│ │ │ │ │ └─┤ │ │ │
│ │ │ │ │ ├───────────┘ │ │
│ │ │ │ ├───┘ │ │
│ │ │ ├─┘ │ │
│ │ └─┤ │ │
│ │ ├───────────────────────────────┘ │
│ └───┤ │
│ ├───────────────────────────────────────┘
└─────┘
10 times smaller than the 7 lines of R5RS Scheme (define (eval e env) (cond
((symbol? e) (cadr (assq e env)))
((eq? (car e) 'λ) (cons e env))
(else (apply (eval (car e) env) (eval (cadr e) env)))))
(define (apply f x)
(eval (cddr (car f)) (cons (list (cadr (car f)) x) (cdr f))))
(display (eval (read) '())) (newline)
> This code will read a program from stdin, parse it, evaluate it and print the result. cons' = \x\y\zx\zy. zx x (zy y)
which allows a list of bits like "1110" (the code for de Bruijn index 3) to index the environment by simply applying it to the environment.
Homepage https://tromp.github.io/