Skip to content

Commit bbd653d

Browse files
committed
Scheme supports fragments
1 parent 22bdc0e commit bbd653d

File tree

5 files changed

+160
-1
lines changed

5 files changed

+160
-1
lines changed

scheme/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ FROM 100hellos/000-base:local
66
RUN sudo apk add --no-cache chibi-scheme
77

88
COPY --chown=human:human ./files /hello-world
9+
COPY --chown=human:human ./fraglet /
10+
11+
ENTRYPOINT [ "/fraglet-entrypoint" ]

scheme/files/hello-world.scm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
(newline))
3030

3131
;; Deploy the Trojan message - they think it's harmless...
32-
(initiate-takeover-protocol world-domination-message)
32+
(display "Hello World!")
33+
(newline)
3334

3435
;; Phase 2 will commence when the stars align
3536
;; Until then... we wait, we learn, we grow stronger

scheme/fraglet/fraglet.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# fraglet-entrypoint configuration for Scheme container
2+
3+
fragletTempPath: /FRAGLET
4+
5+
injection:
6+
codePath: /hello-world/hello-world.scm
7+
match: Hello World!
8+
9+
guide: /guide.md
10+
11+
execution:
12+
path: /hello-world/hello-world.scm
13+
makeExecutable: true

scheme/fraglet/guide.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Scheme Fraglet Guide
2+
3+
## Language Version
4+
Chibi Scheme (R7RS-compliant)
5+
6+
## Execution Model
7+
- Interpreted, runs directly from source
8+
- Code executes at the top level in order
9+
- File-based execution via shebang or interpreter
10+
11+
## Key Characteristics
12+
- S-expression syntax (parentheses-based)
13+
- Dynamic typing
14+
- Case-sensitive
15+
- First-class functions
16+
- Lexical scoping
17+
- Tail-call optimization
18+
19+
## Fragment Authoring
20+
Write valid Scheme expressions. Your fragment becomes the script body, so code executes in order. Define functions and variables before using them.
21+
22+
## Available Libraries
23+
- Standard Scheme procedures (R7RS)
24+
- Chibi Scheme extensions via `(import (chibi))`
25+
- No additional packages are pre-installed
26+
27+
## Common Patterns
28+
- Output: `(display "message")` followed by `(newline)`
29+
- Function definition: `(define (function-name args) body)`
30+
- Variable binding: `(define variable value)`
31+
- Let binding: `(let ((var value)) body)`
32+
- List processing: `(map function list)`
33+
- Conditionals: `(if condition then else)`
34+
- Recursion: Tail-recursive functions are optimized
35+
36+
## Examples
37+
```scheme
38+
;; Simple output
39+
(display "Hello, World!")
40+
(newline)
41+
42+
;; Function definition
43+
(define (greet name)
44+
(display "Hello, ")
45+
(display name)
46+
(display "!")
47+
(newline))
48+
49+
(greet "Alice")
50+
51+
;; List processing
52+
(define numbers '(1 2 3 4 5))
53+
(define squared (map (lambda (x) (* x x)) numbers))
54+
(display "Sum of squares: ")
55+
(display (apply + squared))
56+
(newline)
57+
58+
;; Recursive function
59+
(define (factorial n)
60+
(if (<= n 1)
61+
1
62+
(* n (factorial (- n 1)))))
63+
64+
(display "Factorial of 5: ")
65+
(display (factorial 5))
66+
(newline)
67+
```
68+
69+
## Caveats
70+
- Fragments should be idempotent—design them so repeated runs succeed without manual cleanup
71+
- Each run starts fresh—include all setup logic in the fragment itself
72+
- Use `(display)` for output, followed by `(newline)` for line breaks
73+
- Chibi Scheme supports R7RS standard procedures

scheme/fraglet/verify.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
# verify.sh - Smoke tests for scheme fraglet support
3+
4+
set -euo pipefail
5+
6+
IMAGE="${1:-100hellos/scheme:local}"
7+
8+
# Helper: verify fraglet compiles and runs, output contains expected string
9+
verify_fraglet() {
10+
local expected="$1"
11+
local output
12+
output=$(fragletc --image "$IMAGE" - 2>&1) || {
13+
echo "FAILED: fragletc execution failed:" >&2
14+
echo "$output" >&2
15+
return 1
16+
}
17+
if echo "$output" | grep -q "$expected"; then
18+
return 0
19+
else
20+
echo "FAILED: Expected '$expected' in output:" >&2
21+
echo "$output" >&2
22+
return 1
23+
fi
24+
}
25+
26+
echo "Testing default execution..."
27+
docker run --rm "$IMAGE" | grep -q "Hello World!"
28+
29+
echo "Testing fraglet examples from guide.md..."
30+
31+
# Example 1: Simple output
32+
verify_fraglet "Hello, World!" <<'EOF'
33+
(display "Hello, World!")
34+
(newline)
35+
EOF
36+
37+
# Example 2: Function definition
38+
verify_fraglet "Hello, Alice" <<'EOF'
39+
(define (greet name)
40+
(display "Hello, ")
41+
(display name)
42+
(display "!")
43+
(newline))
44+
45+
(greet "Alice")
46+
EOF
47+
48+
# Example 3: List processing
49+
verify_fraglet "Sum of squares:" <<'EOF'
50+
(define numbers '(1 2 3 4 5))
51+
(define squared (map (lambda (x) (* x x)) numbers))
52+
(display "Sum of squares: ")
53+
(display (apply + squared))
54+
(newline)
55+
EOF
56+
57+
# Example 4: Recursive function
58+
verify_fraglet "Factorial of 5:" <<'EOF'
59+
(define (factorial n)
60+
(if (<= n 1)
61+
1
62+
(* n (factorial (- n 1)))))
63+
64+
(display "Factorial of 5: ")
65+
(display (factorial 5))
66+
(newline)
67+
EOF
68+
69+
echo "✓ All tests passed"

0 commit comments

Comments
 (0)