Skip to content

Commit 674628d

Browse files
authored
Merge pull request #19 from bethropolis/dev
2 parents 8d62a6d + 0b29a86 commit 674628d

File tree

14 files changed

+375
-198
lines changed

14 files changed

+375
-198
lines changed

.npmignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Development
2+
.github/
3+
.vscode/
4+
.idea/
5+
6+
# Documentation
7+
docs/
8+
*.md
9+
!README.md
10+
!LICENSE
11+
12+
# Playground and extensions
13+
playground/
14+
extensions/
15+
16+
# Tests
17+
test/
18+
*.test.js
19+
*.spec.js
20+
21+
# Build artifacts
22+
*.bundle.js
23+
*.min.js
24+
25+
# Config files
26+
.eslintrc*
27+
.prettierrc*
28+
jsconfig.json
29+
tsconfig.json
30+
vite.config.*
31+
tailwind.config.*
32+
postcss.config.*
33+
svelte.config.*
34+
35+
# Misc
36+
.DS_Store
37+
Thumbs.db
38+
*.log
39+
.env
40+
.env.*
41+
!.env.example

docs/_sidebar.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
* [Array Operations](syntax/array-operations.md)
2020
* [Style Guide](syntax/style-guide.md)
2121
* Examples
22-
* [Inventory](examples/inventory/app.mimo)
23-
* [Quiz](examples/quiz/main.mimo)
24-
* [Task Manager](examples/task-manager/main.mimo)
22+
* [Inventory](examples/inventory/README.md)
23+
* [Quiz](examples/quiz/README.md)
24+
* [Task Manager](examples/task-manager/README.md)

docs/examples/inventory/README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Inventory Example
2+
3+
A product catalog system with dynamic pricing based on user type.
4+
5+
## Files
6+
7+
- `catalog.mimo` - Product data and search
8+
- `pricing.mimo` - Discount calculation with pattern matching
9+
- `app.mimo` - Main application
10+
11+
## catalog.mimo
12+
13+
```mimo
14+
export const PRODUCTS [
15+
{ id: "P1", name: "Laptop", price: 1200, category: "electronics", stock: 10 },
16+
{ id: "P2", name: "Mouse", price: 25, category: "electronics", stock: 50 },
17+
{ id: "P3", name: "Shirt", price: 30, category: "clothing", stock: 100 },
18+
{ id: "P4", name: "Keyboard", price: 75, category: "electronics", stock: 0 }
19+
]
20+
21+
export function find_product(id)
22+
for p in PRODUCTS
23+
if = p.id id
24+
return p
25+
end
26+
end
27+
return null
28+
end
29+
```
30+
31+
## pricing.mimo
32+
33+
```mimo
34+
import "math" as math
35+
36+
export function calculate_discount(product, user_type)
37+
match [product.category, user_type]
38+
case ["electronics", "VIP"]:
39+
return 0.20 // 20% off
40+
case ["electronics", "standard"]:
41+
return 0.05 // 5% off electronics for everyone
42+
case ["clothing", "VIP"]:
43+
return 0.15 // 15% off clothing for VIP
44+
default:
45+
return 0.0
46+
end
47+
end
48+
49+
export function get_final_price(product, user_type)
50+
set discount call calculate_discount(product, user_type)
51+
set reduction * product.price discount
52+
return - product.price reduction
53+
end
54+
```
55+
56+
## app.mimo
57+
58+
```mimo
59+
import "./catalog.mimo" as catalog
60+
import "./pricing.mimo" as pricing
61+
62+
show "--- Mimo Inventory Report ---"
63+
64+
for p in catalog.PRODUCTS
65+
set status call if_else(> p.stock 0, "In Stock", "Out of Stock")
66+
show `Product: ${p.name} | Price: $${p.price} | ${status}`
67+
68+
if > p.stock 0
69+
set vip_price call pricing.get_final_price(p, "VIP")
70+
show ` -> VIP Special Price: $${vip_price}`
71+
end
72+
end
73+
74+
show "--- End of Report ---"
75+
```
76+
77+
## Output
78+
79+
```
80+
--- Mimo Inventory Report ---
81+
Product: Laptop | Price: $1200 | In Stock
82+
-> VIP Special Price: $960
83+
Product: Mouse | Price: $25 | In Stock
84+
-> VIP Special Price: $20
85+
Product: Shirt | Price: $30 | In Stock
86+
-> VIP Special Price: $25.5
87+
Product: Keyboard | Price: $75 | Out of Stock
88+
--- End of Report ---
89+
```

docs/examples/inventory/app.mimo

Lines changed: 0 additions & 16 deletions
This file was deleted.

docs/examples/inventory/catalog.mimo

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/examples/inventory/pricing.mimo

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/examples/quiz/README.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Quiz Example
2+
3+
A simple quiz application demonstrating modules and data structures.
4+
5+
## Files
6+
7+
- `data.mimo` - Quiz questions data
8+
- `engine.mimo` - Quiz logic functions
9+
- `main.mimo` - Main quiz application
10+
11+
## data.mimo
12+
13+
```mimo
14+
export const QUESTIONS [
15+
{
16+
q: "What is the result of '+ 2 3' in Mimo?",
17+
a: "5",
18+
options: ["1", "5", "6", "23"]
19+
},
20+
{
21+
q: "Which keyword is used for block-scoped variables?",
22+
a: "let",
23+
options: ["set", "let", "const", "var"]
24+
},
25+
{
26+
q: "Is Mimo dynamically typed?",
27+
a: "yes",
28+
options: ["yes", "no"]
29+
}
30+
]
31+
```
32+
33+
## engine.mimo
34+
35+
```mimo
36+
import "array" as array
37+
38+
export function check_answer(question, user_answer)
39+
return = question.a user_answer
40+
end
41+
42+
export function get_score_percentage(correct, total)
43+
return * (/ correct total) 100
44+
end
45+
```
46+
47+
## main.mimo
48+
49+
```mimo
50+
import "./data.mimo" as data
51+
import "./engine.mimo" as engine
52+
53+
show "--- Mimo Programming Quiz ---"
54+
show `Starting quiz with ${call len(data.QUESTIONS)} questions.`
55+
56+
let score 0
57+
58+
for q in data.QUESTIONS
59+
show ""
60+
show `Question: ${q.q}`
61+
// Display options
62+
show ` A) ${q.options[0]}`
63+
show ` B) ${q.options[1]}`
64+
if > call len(q.options) 2
65+
show ` C) ${q.options[2]}`
66+
end
67+
if > call len(q.options) 3
68+
show ` D) ${q.options[3]}`
69+
end
70+
71+
// Simulate an answer
72+
set simulated_choice q.a
73+
show `Your answer: ${simulated_choice}`
74+
75+
if call engine.check_answer(q, simulated_choice)
76+
show "Correct!"
77+
set score + score 1
78+
else
79+
show `Wrong! The correct answer was: ${q.a}`
80+
end
81+
end
82+
83+
show ""
84+
show "--- Quiz Results ---"
85+
show `Score: ${score} / ${call len(data.QUESTIONS)}`
86+
set percent call engine.get_score_percentage(score, call len(data.QUESTIONS))
87+
show `Grade: ${percent}%`
88+
89+
if = percent 100
90+
show "Perfect Score!"
91+
else
92+
if >= percent 70
93+
show "Well done!"
94+
else
95+
show "Keep practicing!"
96+
end
97+
end
98+
```
99+
100+
## Output
101+
102+
```
103+
--- Mimo Programming Quiz ---
104+
Starting quiz with 3 questions.
105+
106+
Question: What is the result of '+ 2 3' in Mimo?
107+
A) 1
108+
B) 5
109+
C) 6
110+
D) 23
111+
Your answer: 5
112+
Correct!
113+
114+
--- Quiz Results ---
115+
Score: 3 / 3
116+
Grade: 100%
117+
Perfect Score!
118+
```

docs/examples/quiz/data.mimo

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/examples/quiz/engine.mimo

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/examples/quiz/main.mimo

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)