-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathseshatStandardLibrary.ts
More file actions
34 lines (32 loc) · 927 Bytes
/
seshatStandardLibrary.ts
File metadata and controls
34 lines (32 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { EgyptianNumber } from './egyptianNumber';
type SeshatVariable = EgyptianNumber | string;
export function makeSeshatEnvironment(options: {
systemPrint: (...args: string[]) => void,
systemAssert: (expr: boolean) => void,
}) {
options = {
systemPrint: console.log,
systemAssert: console.assert,
...options,
};
return {
EgyptianNumber: EgyptianNumber,
print: (...args: SeshatVariable[]) => {
const processedArgs = args.map(item => {
if (item instanceof EgyptianNumber) {
return item.toHieroglyphs();
} else {
return item;
}
})
options.systemPrint(...processedArgs);
},
assertEqual: (a: SeshatVariable, b: SeshatVariable) => {
if (a instanceof EgyptianNumber) {
options.systemAssert((b instanceof EgyptianNumber) && a.isEqualTo(b));
return;
}
options.systemAssert(a == b);
},
};
}