Skip to content

Commit 4fec813

Browse files
committed
Fragletize: awk, elixir, php
1 parent a6e156c commit 4fec813

File tree

11 files changed

+271
-1
lines changed

11 files changed

+271
-1
lines changed

awk/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
FROM 100hellos/000-base:local
44

55
COPY --chown=human:human ./files /hello-world
6+
COPY --chown=human:human ./fraglet /
7+
8+
ENTRYPOINT [ "/fraglet-entrypoint" ]

awk/files/hello-world.awk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/awk -f
22

3+
# BEGIN_FRAGLET
34
BEGIN {
45
print "Hello World!"
5-
}
6+
}
7+
# END_FRAGLET

awk/fraglet/fraglet.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fraglet-entrypoint configuration for AWK container
2+
3+
fragletTempPath: /FRAGLET
4+
5+
injection:
6+
codePath: /hello-world/hello-world.awk
7+
match_start: "# BEGIN_FRAGLET"
8+
match_end: "# END_FRAGLET"
9+
10+
guide: /guide.md
11+
12+
execution:
13+
path: awk -f /hello-world/hello-world.awk
14+
makeExecutable: false
15+

awk/fraglet/guide.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# AWK Fraglet Guide
2+
3+
## Language Version
4+
GNU AWK (gawk)
5+
6+
## Execution Model
7+
- Interpreted, runs directly from source
8+
- Code executes in blocks: BEGIN, pattern-action, END
9+
- Scripts use `.awk` extension or can be executed with `awk -f script.awk`
10+
11+
## Key Characteristics
12+
- Pattern-action programming language
13+
- Field-based text processing
14+
- Built-in variables: `$0` (entire line), `$1`, `$2`, etc. (fields)
15+
- Automatic field splitting on whitespace
16+
- Case-sensitive
17+
- Indentation is preserved based on the injection point
18+
19+
## Fragment Authoring
20+
Write normal AWK code: define any functions first, then put runtime logic in `BEGIN { ... }`. Your fraglet becomes the script body; you don’t need to know how it’s wired into the container.
21+
22+
## Available Packages
23+
Standard AWK (gawk) is available. No additional packages are pre-installed.
24+
25+
## Common Patterns
26+
- Print: `print "message"` or `print("message")`
27+
- String concatenation: `"Hello" " " "World"` or `"Hello" " " name`
28+
- Variables: `name = "Alice"` (no declaration needed)
29+
- Arrays: `arr[1] = "value"` (associative arrays)
30+
- Loops: `for (i in array) { }` or `for (i = 1; i <= 10; i++) { }`
31+
- Conditionals: `if (condition) { } else { }`
32+
- Functions: `function name(args) { }` (must be defined outside BEGIN block, but can be included in fraglet)
33+
34+
## Examples
35+
```awk
36+
# Simple output
37+
BEGIN {
38+
print "Hello, World!"
39+
}
40+
41+
# Variable assignment
42+
BEGIN {
43+
name = "Alice"
44+
print "Hello, " name "!"
45+
}
46+
47+
# Array processing
48+
BEGIN {
49+
numbers[1] = 1
50+
numbers[2] = 2
51+
numbers[3] = 3
52+
numbers[4] = 4
53+
numbers[5] = 5
54+
55+
sum = 0
56+
for (i in numbers) {
57+
sum += numbers[i] * numbers[i]
58+
}
59+
print "Sum of squares: " sum
60+
}
61+
62+
# Function definition (outside BEGIN block) with execution (inside BEGIN block)
63+
function greet(name) {
64+
return "Hello, " name "!"
65+
}
66+
67+
BEGIN {
68+
print greet("Bob")
69+
}
70+
```
71+
72+
## Caveats
73+
- AWK is primarily designed for text processing with input streams
74+
- For fraglets without input, use BEGIN blocks (already in the file)
75+
- String concatenation is done by placing strings next to each other
76+
- Arrays are associative (can use strings as indices)
77+
- Variables don't need declaration
78+
- Field variables (`$1`, `$2`, etc.) are only meaningful when processing input
79+

elixir/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ RUN sudo \
77
elixir
88

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

elixir/files/hello-world.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
import IO, only: [puts: 1]
44

5+
# BEGIN_FRAGLET
56
puts("Hello World!")
7+
# END_FRAGLET
68

elixir/fraglet/fraglet.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fraglet-entrypoint configuration for Elixir container
2+
3+
fragletTempPath: /FRAGLET
4+
5+
injection:
6+
codePath: /hello-world/hello-world.exs
7+
match_start: "# BEGIN_FRAGLET"
8+
match_end: "# END_FRAGLET"
9+
10+
guide: /guide.md
11+
12+
execution:
13+
path: elixir /hello-world/hello-world.exs
14+
makeExecutable: false
15+

elixir/fraglet/guide.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Elixir Fraglet Guide
2+
3+
## Language Version
4+
Elixir 1.x (runs on Erlang/OTP)
5+
6+
## Execution Model
7+
- Interpreted, runs directly from source
8+
- Code executes at the top level
9+
- Scripts use `.exs` extension (executable scripts)
10+
11+
## Key Characteristics
12+
- Functional programming language
13+
- Immutable data structures
14+
- Pattern matching
15+
- Pipe operator (`|>`)
16+
- Case-sensitive
17+
- Indentation is preserved based on the injection point
18+
19+
## Fragment Authoring
20+
Write normal Elixir code; your fraglet becomes the script body. The file already imports `IO.puts`, so add modules, functions, or expressions as you normally would.
21+
22+
## Available Packages
23+
Standard Elixir library is available. No additional packages are pre-installed.
24+
25+
## Common Patterns
26+
- Print: `IO.puts("message")` or `IO.puts "message"`
27+
- String interpolation: `"Total: #{count}"`
28+
- Lists: `[1, 2, 3]`
29+
- Maps: `%{key: "value"}`
30+
- Pattern matching: `{a, b} = {1, 2}`
31+
- Pipe operator: `list |> Enum.map(fn x -> x * 2 end)`
32+
- Functions: `defmodule MyModule do ... end`
33+
34+
## Examples
35+
```elixir
36+
# Simple output
37+
IO.puts("Hello, World!")
38+
39+
# Function definition
40+
greet = fn name -> "Hello, #{name}!" end
41+
IO.puts(greet.("Alice"))
42+
43+
# List processing
44+
numbers = [1, 2, 3, 4, 5]
45+
squared = Enum.map(numbers, fn x -> x * x end)
46+
sum = Enum.sum(squared)
47+
IO.puts("Sum of squares: #{sum}")
48+
49+
# Using pipe operator
50+
[1, 2, 3, 4, 5]
51+
|> Enum.map(fn x -> x * x end)
52+
|> Enum.sum()
53+
|> IO.puts()
54+
55+
# Module example (now possible with range-based injection)
56+
defmodule Math do
57+
def sum(numbers) do
58+
Enum.sum(numbers)
59+
end
60+
end
61+
62+
IO.puts("Sum: #{Math.sum([1, 2, 3, 4, 5])}")
63+
```
64+
65+
## Caveats
66+
- Elixir uses immutable data structures
67+
- Functions are first-class citizens
68+
- Pattern matching is a core feature
69+
- The pipe operator (`|>`) is commonly used for data transformation
70+

php/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ RUN sudo \
88
php
99

1010
COPY --chown=human:human ./files /hello-world
11+
COPY --chown=human:human ./fraglet /
12+
13+
ENTRYPOINT [ "/fraglet-entrypoint" ]

php/fraglet/fraglet.yml

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

0 commit comments

Comments
 (0)