parent
e7010aaeb0
commit
c421f4123d
File diff suppressed because one or more lines are too long
@ -1,5 +1,7 @@ |
||||
import { n } from './core'; |
||||
import { _l, g, n } from './core'; |
||||
import { snd } from './pair'; |
||||
import { show as nshow } from './num.show'; |
||||
|
||||
n('byte.show'); |
||||
|
||||
export { show } from './num.show'; |
||||
export const show = g('show', _l(n => nshow._(snd._(n)))); |
||||
|
||||
@ -1,25 +1,50 @@ |
||||
import { Term, _, _l, g, id, n } from './core'; |
||||
import { Term, _, _l, cnst, g, n } from './core'; |
||||
import { iif } from './bool'; |
||||
import { Succ, Zero, fromNumber as _n, eq } from './num'; |
||||
import { toNumber as $n, Zero, fromNumber as _n, cmp as ncmp, eq as neq, even as neven, ge as nge, gt as ngt, le as nle, lt as nlt, odd as nodd, pred, succ } from './num'; |
||||
import { Pair, snd, uncurry } from './pair'; |
||||
|
||||
n('byte'); |
||||
|
||||
export const x00 = g('x00', Zero); |
||||
export const x00 = g('x00', Pair._(_n(255))._(Zero)); |
||||
|
||||
export const xFF = g('xFF', _n(255)); |
||||
export const xFF = g('xFF', Pair._(Zero)._(_n(255))); |
||||
|
||||
export const Inc = g('Inc', _l(p => iif._(eq._(xFF)._(p))._(x00)._(Succ._(p)))); |
||||
export const Inc = g('Inc', uncurry._(_l(i => _l(s => i._(x00)._(_l(pi => Pair._(pi)._(succ._(s)))))))); |
||||
|
||||
export { ifz, cmp, lt, le, eq, ge, gt, even, odd, div, mod, toNumber } from './num'; |
||||
export const ifz = g('ifz', _l(n => _l(t => _l(f => snd._(n)._(t)._(cnst._(f)))))); |
||||
|
||||
export const inc = g('inc', Inc); |
||||
|
||||
export const dec = g('dec', _l(n => n._(xFF)._(id))); |
||||
export const dec = g('dec', _l(n => uncurry._(_l(i => _l(s => s._(xFF)._(_l(ps => Pair._(succ._(i))._(ps))))))._(n))); |
||||
|
||||
export const sum = g('sum', _l(l => _l(r => r._(l)._(sum._(inc._(l)))))); |
||||
export const cmp = g('cmp', _l(l => _l(r => ncmp._(snd._(l))._(snd._(r))))); |
||||
|
||||
export const sub = g('sub', _l(l => _l(r => r._(l)._(sub._(dec._(l)))))); |
||||
export const lt = g('lt', _l(l => _l(r => nlt._(snd._(l))._(snd._(r))))); |
||||
|
||||
export const mul = g('mul', _l(l => _l(r => l._(x00)._(_l(pl => sum._(r)._(mul._(pl)._(r))))))); |
||||
export const le = g('le', _l(l => _l(r => nle._(snd._(l))._(snd._(r))))); |
||||
|
||||
export const fromNumber: (n: number) => Term = n => _n(n % 256); |
||||
export const eq = g('eq', _l(l => _l(r => neq._(snd._(l))._(snd._(r))))); |
||||
|
||||
export const ge = g('ge', _l(l => _l(r => nge._(snd._(l))._(snd._(r))))); |
||||
|
||||
export const gt = g('gt', _l(l => _l(r => ngt._(snd._(l))._(snd._(r))))); |
||||
|
||||
export const even = g('even', _l(l => _l(r => neven._(snd._(l))._(snd._(r))))); |
||||
|
||||
export const odd = g('odd', _l(l => _l(r => nodd._(snd._(l))._(snd._(r))))); |
||||
|
||||
export const sum = g('sum', _l(l => _l(r => snd._(r)._(l)._(_l(_ => sum._(inc._(l))._(dec._(r))))))); |
||||
|
||||
export const sub = g('sub', _l(l => _l(r => snd._(r)._(l)._(_l(_ => sub._(dec._(l))._(dec._(r))))))); |
||||
|
||||
export const mul = g('mul', _l(l => _l(r => snd._(l)._(x00)._(_l(_ => sum._(r)._(mul._(dec._(l))._(r))))))); |
||||
|
||||
export const div = g('div', _l(l => _l(r => iif._(lt._(l)._(r))._(x00)._(inc._(div._(sub._(l)._(r))._(r)))))); |
||||
|
||||
export const mod = g('mod', _l(l => _l(r => iif._(lt._(l)._(r))._(l)._(mod._(sub._(l)._(r))._(r))))); |
||||
|
||||
export const byte = g('byte', _l(n => n._(x00)._(_l(pn => inc._(byte._(pn)))))); |
||||
|
||||
export const fromNumber: (n: number) => Term = n => !n ? x00 : Inc._(_(() => fromNumber(n - 1))); |
||||
|
||||
export const toNumber: (n: Term) => number = n => $n(snd._(n)); |
||||
|
||||
@ -1,8 +1,9 @@ |
||||
import { _, _l, g, n } from './core'; |
||||
import { iif } from './bool'; |
||||
import { fromNumber as _n, div, lt, mod, sum } from './num'; |
||||
import { char } from './char'; |
||||
import { Empty, append, cons } from './string'; |
||||
|
||||
n('num.show'); |
||||
|
||||
export const show = g('show', _l(n => iif._(lt._(n)._(_n(10)))._(cons._(sum._(n)._(_n(48)))._(Empty))._(append._(show._(div._(n)._(_n(10))))._(show._(mod._(n)._(_n(10))))))); |
||||
export const show = g('show', _l(n => iif._(lt._(n)._(_n(10)))._(cons._(char._(sum._(n)._(_n(48))))._(Empty))._(append._(show._(div._(n)._(_n(10))))._(show._(mod._(n)._(_n(10))))))); |
||||
|
||||
Loading…
Reference in new issue