Skip to content

Commit b89b755

Browse files
authored
Merge pull request #106 from JohanWiltink/main
allow identifier names ending in '?'
2 parents 3c0f6e1 + 99ae4c9 commit b89b755

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/lambda-calculus.js

+2
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,12 @@ function parse(code) {
221221
function name(i) {
222222
if ( code[i]==='_' ) {
223223
while ( identifierChars.test( code[i] || "" ) ) i++;
224+
if ( code[i]==='?' ) i++;
224225
return [sp(i),"_"];
225226
} else if ( letters.test( code[i] || "" ) ) {
226227
let j = i+1;
227228
while ( identifierChars.test( code[j] || "" ) ) j++;
229+
if ( code[j]==='?' ) j++;
228230
return [sp(j),code.slice(i,j)];
229231
} else
230232
return null;

tests/basics-binary-scott/solution.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ shiftL = \ n . n 0 I I # mind that a shiftL in LE is a divisi
5656

5757
dbl = \ n . n 0 (K (shiftR0 n)) (K (shiftR0 n))
5858

59-
isStrictZero = \ n . n True (K False) (K False) # disallow padding zeroes # O(1)
60-
isZero = \ n . n True isZero (K False) # allow padding zeroes # amortised O(2), so don't worry too much
59+
isStrictZero? = \ n . n True (K False) (K False) # disallow padding zeroes # O(1)
60+
isZero? = \ n . n True isZero? (K False) # allow padding zeroes # amortised O(2), so don't worry too much
6161

6262
pad = \ n . n (shiftR0 0) (B shiftR0 pad) (B shiftR1 pad)
63-
unpad = \ n . n 0 ( \ z . ( \ unpadZ . isStrictZero unpadZ (shiftR0 unpadZ) 0 ) (unpad z) ) (B shiftR1 unpad)
64-
isPadded = \ n . n False ( \ z . z True (K (isPadded z)) (K (isPadded z)) ) isPadded
63+
unpad = \ n . n 0 ( \ z . ( \ unpadZ . isStrictZero? unpadZ (shiftR0 unpadZ) 0 ) (unpad z) ) (B shiftR1 unpad)
64+
isPadded? = \ n . n False ( \ z . z True (K (isPadded? z)) (K (isPadded? z)) ) isPadded?
6565

6666
# instance Ord
6767

@@ -99,11 +99,11 @@ bitXor = \ m n . m n
9999
( \ zm . n ( dbl zm) (B dbl (bitXor zm)) (B shiftR1 (bitXor zm)) )
100100
( \ zm . n (shiftR1 zm) (B shiftR1 (bitXor zm)) (B dbl (bitXor zm)) )
101101

102-
testBit = \ i n . isZero i
102+
testBit = \ i n . isZero? i
103103
(n False (testBit (pred i)) (testBit (pred i)))
104104
(n False (K False) (K True))
105105

106-
bit = \ i . isZero i (shiftR0 (bit (pred i))) (succ i)
106+
bit = \ i . isZero? i (shiftR0 (bit (pred i))) (succ i)
107107

108108
popCount = \ n . n 0 popCount (B succ popCount)
109109

@@ -139,7 +139,7 @@ minus = \ m n . gt m n 0 (go m n)
139139

140140
until = \ p fn x . p x (until p fn (fn x)) x
141141
divMod = \ m n . until (B (lt m) snd) (bimap succ shiftR0) (Pair 0 n)
142-
\ steps nn . isZero steps
142+
\ steps nn . isZero? steps
143143
(divMod (minus m (shiftL nn)) n (B Pair (plus (bit (pred steps)))))
144144
(Pair 0 m)
145145
div = \ m n . fst (divMod m n)
@@ -160,7 +160,7 @@ gcd = \ m n . m n
160160
(gcd (minus m n) n)
161161
)
162162
)
163-
lcm = \ m n . T (gcd m n) \ g . isZero g (times (div m g) n) g
163+
lcm = \ m n . T (gcd m n) \ g . isZero? g (times (div m g) n) g
164164

165165
min = \ m n . le m n n m
166166
max = \ m n . le m n m n

tests/basics-binary-scott/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {fromInt,toInt} = LC;
1111
const {False,True,not,and,or,xor,implies} = solution;
1212
const {LT,EQ,GT,compare,lt,le,eq,ge,gt} = solution;
1313
const {Pair,fst,snd,first,second,both,bimap,curry} = solution;
14-
const {shiftR0,shiftR1,shiftL,dbl,isStrictZero,isZero,pad,unpad,isPadded} = solution;
14+
const {shiftR0,shiftR1,shiftL,dbl,isStrictZero,isZero,pad,unpad,"isPadded?":isPadded} = solution;
1515
const {succ,pred} = solution;
1616
const {bitAnd,bitOr,bitXor,testBit,bit,popCount,even,odd} = solution;
1717
const {plus,times,minus,divMod,div,mod,pow,gcd,lcm,min,max} = solution;

0 commit comments

Comments
 (0)