-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.ts
More file actions
54 lines (49 loc) · 971 Bytes
/
demo.ts
File metadata and controls
54 lines (49 loc) · 971 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env tsx
import { reduceCLI } from './src/index.js';
console.log('🌀 λREDUCE Demo - Converting Imperative to Pure\n');
const examples = [
{
name: 'Simple Function',
code: 'x => x * 2'
},
{
name: 'Conditional',
code: `
if (x < 5) {
x + 1
} else {
x * 2
}
`
},
{
name: 'For Loop',
code: `
let sum = 0;
for (let i = 0; i < n; i++) {
sum = sum + i;
}
sum
`
},
{
name: 'Recursive Function',
code: `
function factorial(n) {
if (n === 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
`
}
];
examples.forEach(({ name, code }) => {
console.log(`\n${'='.repeat(60)}`);
console.log(`Example: ${name}`);
console.log('='.repeat(60));
reduceCLI(code);
});
console.log('\n🔮 All imperative constructs eliminated!');
console.log(' Pure lambda calculus achieved ✨');