@misterscan/sesi 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +191 -0
  3. package/bin/sesi.js +56 -0
  4. package/dist/ai-runtime.d.ts +15 -0
  5. package/dist/ai-runtime.d.ts.map +1 -0
  6. package/dist/ai-runtime.js +214 -0
  7. package/dist/ai-runtime.js.map +1 -0
  8. package/dist/builtins.d.ts +7 -0
  9. package/dist/builtins.d.ts.map +1 -0
  10. package/dist/builtins.js +473 -0
  11. package/dist/builtins.js.map +1 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +72 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/interpreter.d.ts +36 -0
  17. package/dist/interpreter.d.ts.map +1 -0
  18. package/dist/interpreter.js +495 -0
  19. package/dist/interpreter.js.map +1 -0
  20. package/dist/lexer.d.ts +26 -0
  21. package/dist/lexer.d.ts.map +1 -0
  22. package/dist/lexer.js +340 -0
  23. package/dist/lexer.js.map +1 -0
  24. package/dist/parser.d.ts +55 -0
  25. package/dist/parser.d.ts.map +1 -0
  26. package/dist/parser.js +1022 -0
  27. package/dist/parser.js.map +1 -0
  28. package/dist/types.d.ts +304 -0
  29. package/dist/types.d.ts.map +1 -0
  30. package/dist/types.js +63 -0
  31. package/dist/types.js.map +1 -0
  32. package/docs/ARCHITECTURE.md +430 -0
  33. package/docs/BUILTINS.md +577 -0
  34. package/docs/COMPARISON.md +334 -0
  35. package/docs/DISTRIBUTED_SYSTEMS.md +71 -0
  36. package/docs/IMAGE_GENERATION.md +76 -0
  37. package/docs/IMPLEMENTATION_SUMMARY.md +533 -0
  38. package/docs/QUICKSTART.md +351 -0
  39. package/docs/README.md +191 -0
  40. package/docs/ROADMAP.md +408 -0
  41. package/docs/SPECIFICATION.md +462 -0
  42. package/docs/SYSTEMS_REASONING.md +522 -0
  43. package/examples/01_hello.sesi +2 -0
  44. package/examples/02_variables.sesi +11 -0
  45. package/examples/03_functions.sesi +6 -0
  46. package/examples/04_conditionals.sesi +6 -0
  47. package/examples/05_loops.sesi +12 -0
  48. package/examples/06_arrays_objects.sesi +18 -0
  49. package/examples/07_prompts.sesi +10 -0
  50. package/examples/08_model_call.sesi +5 -0
  51. package/examples/09_structured_output.sesi +7 -0
  52. package/examples/10_code_generation.sesi +5 -0
  53. package/examples/11_memory_conversation.sesi +16 -0
  54. package/examples/12_classification.sesi +8 -0
  55. package/examples/13_data_pipeline.sesi +35 -0
  56. package/examples/14_folder_explainer.sesi +58 -0
  57. package/examples/15_image_generation.sesi +17 -0
  58. package/main/atm_deposit.sesi +37 -0
  59. package/main/atm_withdraw.sesi +37 -0
  60. package/main/data.txt +1 -0
  61. package/main/math_aggregator.sesi +15 -0
  62. package/main/math_generator.sesi +7 -0
  63. package/main/math_processor.sesi +23 -0
  64. package/main/orchestrator.sesi +15 -0
  65. package/main/playground.sesi +1 -0
  66. package/main/setup_swarm.sesi +5 -0
  67. package/main/start.sesi +13 -0
  68. package/main/tax_calculator.sesi +15 -0
  69. package/main/tests/compare.sesi +23 -0
  70. package/main/tests/compare.ts +104 -0
  71. package/main/tests/debug.sesi +1 -0
  72. package/main/tests/demo.sesi +24 -0
  73. package/main/tests/primitive_validation.sesi +18 -0
  74. package/main/tests/test_connection.sesi +4 -0
  75. package/main/tests/test_failure_debug.sesi +2 -0
  76. package/main/tests/test_image.sesi +3 -0
  77. package/main/tests/test_parser_config.sesi +2 -0
  78. package/main/tests/test_syntax.sesi +3 -0
  79. package/main/tests/test_tool_call.sesi +14 -0
  80. package/main/tests/try.sesi +7 -0
  81. package/main/vault.sesi +15 -0
  82. package/package.json +50 -0
@@ -0,0 +1,522 @@
1
+ # Systems Reasoning & Logic Guide
2
+
3
+ ## Overview
4
+
5
+ Sesi is a **Systems Language** that treats reasoning as a first-class execution primitive. In this paradigm, AI is used to evaluate state, make logical decisions, and handle complex patterns within a systems-level architecture.
6
+
7
+ This guide covers how to leverage Sesi's systems-level constructs (`spawn`, `exec`, `try/catch`) alongside its reasoning primitives (`model`, `prompt`, `structured_output`) to build resilient, stateful applications.
8
+
9
+ ## 1. Concurrency & Systems Coordination
10
+
11
+ The core of Sesi's power lies in its ability to manage distributed execution. Using the `spawn()` builtin, you can launch multiple concurrent Sesi processes that coordinate via shared state or the filesystem.
12
+
13
+ A master script can launch concurrent processes and poll for their completion.
14
+
15
+ ```sesi
16
+ spawn("atm_deposit.sesi")
17
+ spawn("atm_withdraw.sesi")
18
+ let finished = false
19
+ while !finished {
20
+ try {
21
+ if read_file("bank/done_count.txt") == "2" {
22
+ finished = true
23
+ }
24
+ } catch (e) {
25
+ // Wait on I/O contention
26
+ let i = 0 while i < 1000 { i = i + 1 }
27
+ }
28
+ }
29
+ print "Swarm task completed."
30
+ ```
31
+
32
+ ### Coordination & Distributed Locking
33
+
34
+ When multiple processes access shared resources, use Sesi's `try/catch`, `time()`, and `random()` builtins to implement mutual exclusion (locking) via the **Double-Check Write** pattern.
35
+
36
+ ```sesi
37
+ let id = "With_" + str(time()) + "_" + str(random())
38
+ let locked = true
39
+ while locked {
40
+ let status = "error"
41
+ try {
42
+ status = read_file("bank/lock.txt")
43
+ } catch (e) {
44
+ status = "error"
45
+ }
46
+ if status == "unlocked" {
47
+ try {
48
+ write_file("bank/lock.txt", id)
49
+ let i = 0 while i < 500 { i = i + 1 }
50
+ if read_file("bank/lock.txt") == id {
51
+ locked = false
52
+ }
53
+ } catch (e) {
54
+ status = "error"
55
+ }
56
+ } else {
57
+ let j = 0 while j < 1000 { j = j + 1 }
58
+ }
59
+ }
60
+ ```
61
+
62
+ ---
63
+
64
+ ## 2. AI as a Reasoning Primitive
65
+
66
+ In an orchestrated system, AI is used to make decisions that would be too complex for static logic.
67
+
68
+ Prompts are **composable message templates** that evaluate to strings.
69
+
70
+ ### Basic Prompt
71
+
72
+ ```sesi
73
+ prompt simplePrompt {"Hello, Sesi!"}
74
+ print simplePrompt // "Hello, Sesi!"
75
+ ```
76
+
77
+ ### Prompts with Variables
78
+
79
+ ```sesi
80
+ let name = "Alice"
81
+ prompt greeting {"Hello, " name "! How are you?"}
82
+ print greeting // "Hello, Alice! How are you?"
83
+ ```
84
+
85
+ ### Composing Prompts
86
+
87
+ ```sesi
88
+ prompt part1 {"First part"}
89
+ prompt part2 {part1 " " "Second part"}
90
+ print part2 // "First part Second part"
91
+ ```
92
+
93
+ ### Prompts in Functions
94
+
95
+ ```sesi
96
+ let text = "Testing"
97
+ let language = "Spanish"
98
+ fn translatePrompt(text: string, language: string) -> string
99
+ {prompt translate {"Translate the following text to "language": " text} return translate}
100
+ print translatePrompt(text, language)
101
+ ```
102
+
103
+ ## 2. Model Calls
104
+
105
+ Call Gemini with a prompt and get back text.
106
+
107
+ ### Basic Model Call
108
+
109
+ ```sesi
110
+ let response = model("gemini-3-flash-preview") {"What is machine learning?"}
111
+ print response
112
+ ```
113
+
114
+ ### Model Configuration
115
+
116
+ ```sesi
117
+ let creative = model("gemini-3-flash-preview") {"temperature": 0.9, "max_tokens": 500} {"Write a creative poem about technology."}
118
+ print creative
119
+
120
+ // Config options:
121
+ // - "temperature": 0.0-1.0 (higher = more creative) (OPTIONAL: if not specified, will use the model's default temperature=0.3)
122
+ // - max_tokens: max length of response (OPTIONAL: if not specified, will use the model's default max tokens=2048)
123
+ // - top_k: diversity parameter (OPTIONAL)
124
+ // - top_p: nucleus sampling parameter (OPTIONAL)
125
+ ```
126
+
127
+ ### Model Selection
128
+
129
+ ```sesi
130
+ // Fast model for simple tasks
131
+ let text = " Coding with Reasoning systems language is fun!"
132
+ let quick = model("gemini-3.1-flash-lite") {"Summarize this in one sentence:" text}
133
+
134
+ // Powerful model for complex reasoning
135
+ let code = "def calculate_sum(n):
136
+ total = 0
137
+ for i in range(1, n):
138
+ total += i
139
+ return total"
140
+ let smart = model("gemini-3.1-pro-preview") {"Analyze this code for bugs:" code}
141
+
142
+ // Efficient model for many calls
143
+ let item = " Programming Languages"
144
+ let cheap = model("gemini-3.1-flash-lite") {"temperature": 0} {"Classify:" item}
145
+
146
+ print quick
147
+ print smart
148
+ print cheap
149
+ ```
150
+
151
+ ### Available Models (v1.1)
152
+
153
+ - `gemini-2.5-flash` - Legacy, but supported. 1M tokens.
154
+ - `gemini-2.5-pro` - Legacy, but supported. 1M tokens.
155
+ - `gemini-2.5-flash-image` - Legacy, but reliable.
156
+ - `gemini-3-flash-preview` - Fast, balanced, 1M tokens
157
+ - `gemini-3.1-pro-preview` - Most capable, 1M tokens
158
+ - `gemini-3.1-flash-lite` - Fastest, cost-efficient
159
+ - `gemini-3.1-flash-image-preview` - Cost efficient while maintaining quality images.
160
+ - `gemini-3-pro-image-preview` - High quality image generation.
161
+
162
+ #### Planned for (v2+)
163
+
164
+ - `OpenAI` integration (GPT, Dall-E, etc.)
165
+ - `HuggingFace` integration
166
+ - `Midjourney` integration
167
+ - `Newer Reasoning Models` - Native upgrades
168
+
169
+ ## 3. Structured Output
170
+
171
+ Get typed responses from Reasoning with field validation.
172
+
173
+ ### Basic Structured Output
174
+
175
+ ```sesi
176
+ let analysis = structured_output({sentiment: string, confidence: number, summary: string})
177
+ (model("gemini-3-flash-preview") {"Analyze sentiment of: " text "Return JSON with sentiment, confidence (0-1), and summary"})
178
+ print analysis["sentiment"] // "positive"
179
+ print analysis["confidence"] // 0.85
180
+ print analysis["summary"] // "..."
181
+ ```
182
+
183
+ ### Schema Definition
184
+
185
+ ```sesi
186
+ // Schema is a record with field types
187
+ let schema = {title: string, author: string, pageCount: number, tags: string, isFiction: bool}
188
+ let bookInfo = structured_output(schema)(model("gemini-3-flash-preview") {"Extract book metadata as JSON from: " description})
189
+ print bookInfo["title"]
190
+ ```
191
+
192
+ ### Parsing Tips
193
+
194
+ - Always include instructions for JSON format
195
+ - Specify the exact schema in the prompt
196
+ - Use "temperature": 0 for consistency
197
+ - Validate output structure in code
198
+
199
+ ```sesi
200
+ let listText = "eggs, milk, bread, cheese, fruit, vegetables"
201
+ let output = structured_output({items: string})(model("gemini-3-flash-preview") {"temperature": 0}{"Return JSON with items array containing: " listText})
202
+
203
+ // Validate
204
+ if type(output["items"]) == "array" {print "Got" str(len(output["items"])) "items"} // Got 6 items
205
+ ```
206
+
207
+ ## 4. Tool Calls (Function Calling)
208
+
209
+ Let Reasoning call functions in your program.
210
+
211
+ ### Define Callable Functions
212
+
213
+ ```sesi
214
+ let city = "New York"
215
+ fn getWeather(city: string) -> string
216
+ {let weather = model("gemini-3.1-flash-lite"){"What is the weather like in " city} return weather}
217
+ let result = getWeather(city)
218
+ print result
219
+
220
+ // When defined inside a function, local variables MUST be defined on new lines.
221
+ // (A current limitation of the parser).
222
+ fn calculateTax(amount: number, rate: number) -> number
223
+ {let amount = 100
224
+ let rate = 0.08
225
+ return amount * rate}
226
+ let result = calculateTax()
227
+ print result
228
+ ```
229
+
230
+ ### Reasoning Makes Tool Calls
231
+
232
+ ```sesi
233
+ let tax = tool_call(calculateTax)(model("gemini-3.1-flash-lite") {"Calculate 8% sales tax on $100"})
234
+ print tax // 8.0
235
+ ```
236
+
237
+ ### Multiple Tool Availability (Future)
238
+
239
+ ```sesi
240
+ // v2: Allow Reasoning to choose from multiple tools
241
+ let result = with_tools([getWeather, calculateTax, getTime]) {model("gemini-3-flash-preview") {"What's the weather in NY and the sales tax on $50?"}}
242
+ ```
243
+
244
+ ## 5. Memory & Conversation
245
+
246
+ Maintain context across multiple Reasoning calls.
247
+
248
+ ### Simple Memory
249
+
250
+ ```sesi
251
+ memory chat {"You are a helpful assistant. Be concise."}
252
+
253
+ // First turn
254
+ let response1 = model("gemini-3-flash-preview") {chat "User: Hello!"}
255
+
256
+ // Update memory with conversation
257
+ chat = chat + "Assistant: " + response1
258
+
259
+ // Second turn
260
+ let response2 = model("gemini-3.1-flash-lite") {chat "User: How are you?"}
261
+ print response2 // Has context from turn 1
262
+ ```
263
+
264
+ ### Memory in Functions
265
+
266
+ ```sesi
267
+ memory conversation {"Chat history: "}
268
+ fn chat(userMessage: string) -> string
269
+ {let fullPrompt = conversation + "User:" + userMessage
270
+ let response = model("gemini-3-flash-preview") {fullPrompt}
271
+
272
+ // Append to memory
273
+ conversation = conversation + "User:" + userMessage + "Assistant:" + response
274
+ return response}
275
+ let msg = "What is the capital of France? "
276
+ print "User:" msg
277
+ print "Assistant:" chat(msg)
278
+ print "Updated Memory!"
279
+ ```
280
+
281
+ ### Memory Best Practices
282
+
283
+ - Keep memory concise to save tokens
284
+ - Summarize old messages periodically
285
+ - Reset memory when topic changes
286
+ - Monitor token usage
287
+
288
+ ```sesi
289
+ // Summarize old memory
290
+ memory conversation {"User: Hello! Assistant: Hi there! User: How are you? Assistant: I'm great!"}
291
+ fn summarizeMemory()
292
+ {let oldConversation = conversation
293
+ let summary = model("gemini-3.1-flash-lite") {"Summarize this conversation concisely:" oldConversation}
294
+ conversation = "Previous summary:" + summary + "Recent messages: " + oldConversation}
295
+ print "Original Memory:" conversation
296
+ summarizeMemory()
297
+ print "Summarized!"
298
+ print conversation
299
+ ```
300
+
301
+ ## 6. Practical Patterns
302
+
303
+ ### Classification
304
+
305
+ ```sesi
306
+ let categories = "fruit, vegetable, grain"
307
+ let item = "banana"
308
+ fn classify(item: string, categories: string) -> string
309
+ {return model("gemini-3.1-flash-lite") {"temperature": 0}
310
+ {"Classify this item into one category. Categories: " categories " Item: " item " Return only the category name."}}
311
+ print "Item: " item //banana
312
+ print "Category: " classify(item, categories) //fruit
313
+ ```
314
+
315
+ ### Extraction
316
+
317
+ ```sesi
318
+ let text = "Elon Musk is the CEO of Tesla and SpaceX."
319
+ fn extractEntities(text: string) -> object
320
+ {let result = structured_output({people: string, places: string, organizations: string})
321
+ (model("gemini-3.1-flash-lite") {"temperature": 0}{"Extract named entities from:" text})
322
+ print "Name(s) found: result"
323
+ return result}
324
+ print extractEntities(text)
325
+
326
+ ```
327
+
328
+ ### Translation
329
+
330
+ ```sesi
331
+ let text = "Hello, world!"
332
+ let language = "Spanish"
333
+ fn translate(text: string, language: string) -> string
334
+ {return model("gemini-3-flash-preview") {"Translate to" language ":" text}}
335
+ print "Translation:"
336
+ print translate(text, language)
337
+ ```
338
+
339
+ ### Image Generation
340
+
341
+ Like `model`, the `image` command evaluates prompts and accepts configuration variables mapping accurately to backend SDKs requirements.
342
+
343
+ ```sesi
344
+ let logo = image("gemini-3.1-flash-image-preview") {"ratio": "1:1", "size": "512", "temperature": 0.3} {"A high quality vector logo representing a new programming language named Sesi"}
345
+ write_image("logo.png", logo)
346
+ print "Image generated!"
347
+ ```
348
+
349
+ ### Code Generation
350
+
351
+ ```sesi
352
+ let requirement = "Write a function that reverses a string."
353
+ fn generateCode(requirement: string) -> string
354
+ {return model("gemini-3.1-flash-lite") {"temperature": 0.2} {"Generate JavaScript code for:" requirement "Only provide code, no explanation."}}
355
+ print "Code generation:"
356
+ print generateCode(requirement)
357
+ ```
358
+
359
+ ### Analysis
360
+
361
+ ```sesi
362
+ let text = "I love Sesi!"
363
+ fn analyzeSentiment(text: string) -> object
364
+ {return structured_output({sentiment: string, score: number, explanation: string})
365
+ (model("gemini-3-flash-preview") {"Analyze sentiment of:" text})}
366
+ print "Sentiment analysis:"
367
+ print analyzeSentiment(text)
368
+ ```
369
+
370
+ ## 7. Error Handling
371
+
372
+ Reasoning operations can fail. Handle gracefully.
373
+
374
+ ### Try/Catch (v1.1)
375
+
376
+ ```sesi
377
+ try
378
+ {let response = model("gemini-3-flash-preview") {"Analyze" text}
379
+ print response}
380
+ catch (e) {print "Reasoning call failed"
381
+ print e}
382
+ ```
383
+
384
+ ### Current Failure Behavior
385
+
386
+ - `model()` throws when the Gemini SDK fails or when no text is returned. `MAX_TOKENS` finish reasons are handled natively via a polling loop to automatically complete long outputs.
387
+ - `structured_output()` first tries to parse JSON from the model text, then retries with a coercion prompt.
388
+ - If structured parsing still fails, the runtime currently logs the error and returns `{}`.
389
+
390
+ ### Validation After Success
391
+
392
+ ```sesi
393
+ let text = "Coding is evolving rapidly!"
394
+ fn safeAnalyze(text: string) {
395
+ try
396
+ {let result = structured_output({sentiment: string, score: number})(model("gemini-3.1-flash-lite") {"Analyze sentiment and return JSON for:" text})
397
+ if len(keys(result)) == 0 {print "Structured parsing failed"
398
+ return null}
399
+ return result}
400
+ catch (e)
401
+ {print e
402
+ return null}}
403
+ print "Analysis Result: " safeAnalyze(text)
404
+ ```
405
+
406
+ ## 8. Performance Tips
407
+
408
+ ### Minimize API Calls
409
+
410
+ ```sesi
411
+ // Bad: Calls API 3 times
412
+ for item in items
413
+ {let analysis = model("gemini-3.1-flash-lite") {"Analyze:" item}}
414
+ print analysis
415
+
416
+ // Better: Batch into one call (v2: parallel calls)
417
+ let analyses = model("gemini-3.1-flash-lite") {"Analyze each:" join(items, " ")}
418
+ print analyses
419
+ ```
420
+
421
+ ### Use Cheaper Models for Simple Tasks
422
+
423
+ ```sesi
424
+ // Simple classification → flash-lite
425
+ let category = model("gemini-3.1-flash-lite") {"Classify:" item}
426
+ print category
427
+
428
+ // Complex reasoning → pro
429
+ let analysis = model("gemini-3.1-pro-preview") {"Deep analysis of:" complex_problem}
430
+ print analysis
431
+ ```
432
+
433
+ ### Reduce Token Usage
434
+
435
+ ```sesi
436
+ // Long prompts waste tokens
437
+ // Bad:
438
+ let response = model("gemini-3-flash-preview") {"Here is a very long system prompt that repeats itself... " "Please analyze the following text very carefully..." text}
439
+ print response
440
+
441
+ // Better:
442
+ let response = model("gemini-3-flash-lite") {"Analyze:" text}
443
+ print response
444
+ ```
445
+
446
+ ### Cache Repeated Prompts
447
+
448
+ ```sesi
449
+ // Bad: Same analysis done multiple times
450
+ for person in people {let assessment = model("gemini-3.1-flash-lite") {"Assess based on criteria A, B, C: " person}}
451
+ print assessment
452
+
453
+
454
+ // Better: Reuse cached prompt
455
+ let people = ["Elon Musk", "Bill Gates", "Steve Jobs"]
456
+ fn assessPerson(person: string) -> string {return model("gemini-3.1-flash-lite") {"Assess on A, B, C: " person}}
457
+ for person in people {print assessPerson(person)}
458
+ ```
459
+
460
+ ## 9. Token Counting (Future)
461
+
462
+ V2 will include token counters:
463
+
464
+ ```sesi
465
+ // Planned for v2:
466
+ let tokens = count_tokens(text, model)
467
+ print "This costs " str(tokens * PRICE_PER_TOKEN) " cents"
468
+
469
+ // Plan memory size
470
+ let remaining = MAX_TOKENS - count_tokens(memory, model)
471
+ if remaining < 500 {summarizeMemory()}
472
+ print "Memory size: " count_tokens(memory, model)
473
+ ```
474
+
475
+ ## 10. Advanced: Custom Reasoning Workflows
476
+
477
+ ### Multi-Stage Reasoning Workflow
478
+
479
+ ```sesi
480
+ let text = "Climate change is a long-term shift in global or regional climate patterns. Often climate change refers specifically to anthropogenic climate change, which is caused by human activities, primarily fossil fuel burning, which increases heat-trapping greenhouse gas levels in Earth's atmosphere. The term is frequently used interchangeably with the term global warming, though the latter refers specifically to the long-term heating of Earth's climate system observed since the pre-industrial period due to human activities."
481
+ fn smartSummarize(text: string) -> string
482
+
483
+ // Chain multiple Reasoning operations
484
+ // Step 1: Extract key points
485
+ {let keyPoints = model("gemini-3.1-pro-preview") {"temperature": 0} {"Extract 5 key points from:" text}
486
+
487
+ // Step 2: Analyze topics
488
+ let topics = structured_output({ topics: string })(model("gemini-3.1-flash-lite") {"Identify topics in:" keyPoints})
489
+
490
+ // Step 3: Generate summary
491
+ let summary = model("gemini-3-flash-preview") {"Summarize with topics " topics ":" keyPoints} return summary}
492
+ print "Summary:" smartSummarize(text)
493
+ ```
494
+
495
+ ### Reasoning Pattern (V2: native support)
496
+
497
+ ```sesi
498
+ // Future: Extended thinking
499
+ let analysis = model("gemini-3-flash-preview") {"temperature": 0, "thinking_level": "low"} {"Reason carefully about:" problem}
500
+ print analysis
501
+ ```
502
+
503
+ ### Few-Shot Prompting
504
+
505
+ ```sesi
506
+ let text = "banana"
507
+ fn classifyWithExamples(text: string) -> string
508
+ {return model("gemini-3.1-flash-lite") {"temperature": 0} {"Classify as A, B, or C" "Examples:" "'apple' -> A" "'dog' -> B" "'happy' -> C" "Classify: " text}}
509
+ print "Classification:" classifyWithExamples(text)
510
+ ```
511
+
512
+ ---
513
+
514
+ ## See Also
515
+
516
+ - [Compare to other languages](COMPARISON.md)
517
+ - [Language Specification](SPECIFICATION.md)
518
+ - [Image Generation](IMAGE_GENERATION.md)
519
+ - [Architecture](ARCHITECTURE.md)
520
+ - [Built-ins](BUILTINS.md)
521
+ - [Examples](../examples/)
522
+ - [Roadmap](ROADMAP.md)
@@ -0,0 +1,2 @@
1
+ // Basic "Hello World" example
2
+ print "Hello, World!"
@@ -0,0 +1,11 @@
1
+ // Variables and basic operations
2
+ let x = 10
3
+ let y = 20
4
+ let z = x + y
5
+ print "x = " x
6
+ print "y = " y
7
+ print "sum = " z
8
+
9
+ // Reassignment
10
+ x = 30
11
+ print "x updated:" x
@@ -0,0 +1,6 @@
1
+ // Functions
2
+ fn add(a: number, b: number) {print a + b}
3
+ fn greet(name: string = "World") {print "Hello" name "!"}
4
+ add(5, 3)
5
+ greet()
6
+ greet("Alice")
@@ -0,0 +1,6 @@
1
+ // Conditionals
2
+ let age = 25
3
+ if age >= 18 {print "You are an adult"} else {print "You are a minor"}
4
+ // Complex conditions
5
+ let score = 85
6
+ if score >= 90 {print "Grade: A"} else if score >= 80 {print "Grade: B"} else if score >= 70 {print "Grade: C"} else {print "Grade: F"}
@@ -0,0 +1,12 @@
1
+ // Loops
2
+ print "While loop:"
3
+ let i = 0
4
+ while i < 5 {
5
+ print i
6
+ i = i + 1
7
+ }
8
+ print "For loop (range):"
9
+ for j = 0 to 5 {print "Iteration:" j}
10
+ print "For loop (array):"
11
+ let arr = [10, 20, 30, 40]
12
+ for item in arr {print "Item:" item}
@@ -0,0 +1,18 @@
1
+ // Arrays and objects
2
+ let numbers = [1, 2, 3, 4, 5]
3
+ print "Array:" numbers
4
+ print "Length:" len(numbers)
5
+ print "First:" numbers[0]
6
+
7
+ push(numbers, 6)
8
+ print "After push:" numbers
9
+
10
+ // Objects
11
+ let person = {"name": "Alice", "age": 30, "city": "New York"}
12
+ print "Person:" person
13
+ print "Name:" person["name"]
14
+
15
+ // Array of objects
16
+ let people = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}, {"name": "Charlie", "age": 35}]
17
+ for person in people
18
+ {print person["name"] "is" person["age"]}
@@ -0,0 +1,10 @@
1
+ // Prompt blocks - composable message templates
2
+ prompt greetingTemplate {"Hello! " "How are you today?"}
3
+ prompt responseTemplate {greetingTemplate " " "I hope you're having a great day!"}
4
+ // Prompts evaluate to strings
5
+ let greeting = responseTemplate
6
+ print greeting
7
+ // Prompts can use variables
8
+ let userName = "Alice"
9
+ prompt personalGreeting {"Hello, " userName "! Welcome back!"}
10
+ print personalGreeting
@@ -0,0 +1,5 @@
1
+ // Reasoning-powered text analysis using model calls
2
+ // Requires GEMINI_API_KEY environment variable
3
+ let text = "Artificial intelligence is transforming how we work and live"
4
+ let analysis = model("gemini-3.1-flash-lite") {"temperature": 0.5, "max_tokens": 400} {"Analyze the following text and provide 3 concise key insights. Keep the total response under 120 words. " text}
5
+ print "Analysis:" analysis
@@ -0,0 +1,7 @@
1
+ // Sentiment analysis with structured output
2
+ // Requires GEMINI_API_KEY environment variable
3
+ let review = "This product is amazing! I love how it works. Highly recommended!"
4
+ let sentiment = structured_output({sentiment: string, confidence: number, keywords: string})(model("gemini-3.1-flash-lite") {"Analyze the sentiment of this review and extract key information. " "Return JSON with: sentiment (positive/negative/neutral), confidence (0-1), keywords (comma-separated) " review})
5
+ print "Sentiment:" sentiment["sentiment"]
6
+ print "Confidence:" sentiment["confidence"]
7
+ print "Keywords:" sentiment["keywords"]
@@ -0,0 +1,5 @@
1
+ // Code generation with Reasoning
2
+ // Requires GEMINI_API_KEY environment variable
3
+ let requirement = "A function that checks if a number is prime"
4
+ let generatedCode = model("gemini-3.1-flash-lite") {"temperature": 0.2, "max_tokens": 500} {"Generate JavaScript code for the following requirement: " requirement " Provide only the code, no explanation."}
5
+ print "Generated Code:" generatedCode
@@ -0,0 +1,16 @@
1
+ // Multi-turn conversation with memory
2
+ // Requires GEMINI_API_KEY environment variable
3
+ memory conversation {"You are a helpful programming assistant. Respond concisely."}
4
+ fn askBot(question: string) -> string {
5
+ let message = conversation + "User:" + question
6
+ let response = model("gemini-3.1-flash-lite") {message}
7
+ conversation = message + "Assistant:" + response
8
+ return response
9
+ }
10
+ print "Starting conversation..."
11
+ let answer1 = askBot("What is a closure in JavaScript?")
12
+ print "Q1 Answer:" answer1
13
+ let answer2 = askBot("Can you give me an example?")
14
+ print "Q2 Answer:" answer2
15
+ let answer3 = askBot("How do I use it in practice?")
16
+ print "Q3 Answer:" answer3
@@ -0,0 +1,8 @@
1
+ // Data classification using Reasoning
2
+ // Requires GEMINI_API_KEY environment variable
3
+ let items = ["A quick brown fox", "123 Main Street", "user@example.com", "New York City"]
4
+ fn classifyItem(item: string) -> string {return model("gemini-3.1-flash-lite") {"Classify this item into one of: TEXT, ADDRESS, EMAIL, LOCATION " "Item: " item}}
5
+ print "Classifying items..."
6
+ for item in items
7
+ {let classification = classifyItem(item)
8
+ print item "->" classification}
@@ -0,0 +1,35 @@
1
+ // Comprehensive example: Reasoning-powered data pipeline
2
+ // This example demonstrates: Functions and control flow, Loops and arrays, Model calls with configuration, Structured output parsing, Memory for multi-step processing
3
+ // Data to process
4
+ let reviews = ["This product is amazing! Highly recommended.", "Terrible quality. Waste of money.", "It's okay. Nothing special.", "Love it! Best purchase ever.", "Disappointed. Poor customer service."]
5
+ // Function to analyze single review
6
+ fn analyzeReview(review: string) -> object {
7
+ return structured_output({sentiment: string, confidence: number})(model("gemini-3.1-flash-lite") {"temperature": 0.3} {"Analyze sentiment. Return JSON with sentiment (positive/negative/neutral) and confidence (0-1). Review:" review})
8
+ }
9
+ // Process all reviews
10
+ print ("Processing " + len(reviews) + " reviews...")
11
+ let results = []
12
+ let positiveCount = 0
13
+ let negativeCount = 0
14
+ let neutralCount = 0
15
+ for review in reviews
16
+ {print "Review:" review
17
+ let analysis = analyzeReview(review)
18
+ let sentiment = analysis["sentiment"]
19
+ let confidence = analysis["confidence"]
20
+ print "Sentiment:" sentiment "Confidence:" confidence
21
+ push(results, analysis)
22
+ if sentiment == "positive" {positiveCount = positiveCount + 1} else if sentiment == "negative" {negativeCount = negativeCount + 1} else {neutralCount = neutralCount + 1}}
23
+ // Summary
24
+ print "=== Summary ==="
25
+ print "Total reviews:" len(reviews)
26
+ print "Positive:" positiveCount
27
+ print "Negative:" negativeCount
28
+ print "Neutral:" neutralCount
29
+ // Calculate average sentiment score
30
+ let totalConfidence = 0
31
+ for result in results {totalConfidence = totalConfidence + result["confidence"]}
32
+ let avgConfidence = totalConfidence / len(results)
33
+ print "Average confidence:" avgConfidence
34
+ // Overall recommendation
35
+ if positiveCount > negativeCount {print "Overall: RECOMMENDED (more positive reviews)"} else if negativeCount > positiveCount {print "Overall: NOT RECOMMENDED (more negative reviews)"} else {print "Overall: MIXED (balanced reviews)"}