AtlatestRepositorysigil-doc
1
#lang sigil/doc/book2
@(import (fixtures practical-author-support))3
@(define tip-calls 0)4
@(define (tip body)5
(set! tip-calls (+ tip-calls 1))6
body)7
@(define-syntax strong8
(syntax-rules () ((_ child) (em child))))9
@chapter [10
"A Useful First Script"11
authors: '("David Wilson")12
]14
@section ["A Useful First Script" id: "first-script"]16
@p {17
This is practical Scheme—small functions composed without ceremony.18
}20
@p {21
The important idea is to shape the problem as a pipeline: obtain text, split it22
into lines, select what matters, and render the answer.23
}25
@code ["sigil"] {26
(import (sigil core) (sigil fs))27
(define lines (string-split (read-file-string "tasks.txt") "\n"))28
(define todos (filter (lambda (line) (string-prefix? "TODO " line)) lines))29
(display (string-append "Open tasks: " (number->string (length todos))))30
(newline)31
(for-each (lambda (line) (display (string-append "- " line "\n"))) todos)32
}34
@tip35
@section ["run the script on a deliberately messy file" id: "messy-input"]36
@p: Unicode such as καλημέρα, and a line that merely contains the word TODO.37
@end section38
@end tip40
@p: This @strong{macro-expanded phrase} is authored with an ordinary local macro.42
@(tip (p (text "computed inline expression")))44
@end section46
@section ["Change the Question" id: "change-the-question"]48
@p {49
Once a small program works, its value comes from how readily it can answer the50
next question.51
}53
@exercise [54
"change-the-question"55
"add a command-line word that selects TODO or DONE"56
] {57
@p {58
Then add three small examples that cover an empty list, mixed tasks, and59
non-ASCII task text.60
}61
}63
@p {64
Return to @ref ["first-script"] {the first script} when the revised version65
starts to feel complicated.66
}68
@end section70
@repeat-sections [71
"Computed Section"72
count: (+ 1 1)73
] {}75
@section["Verified Examples" id: "verified-examples"]{76
@example["stdout" expect-stdout: "hello\n" timeout: 30]{77
@code["sigil"]{(display "hello\n")}78
}79
@example["value" expect-value: "42" timeout: 30]{80
@code["sigil"]{(+ 20 22)}81
}82
@example["expected-error" expect-error: "error: expected boom" timeout: 30]{83
@code["sigil"]{(error "expected boom")}84
}85
@example["session-one" session: "progress" expect-value: "#<undefined>" timeout: 30]{86
@code["sigil"]{(define answer 40)}87
}88
@example["session-two" session: "progress" expect-value: "42" timeout: 30]{89
@code["sigil"]{(+ answer 2)}90
}91
@example["file-source" source-file: "d3-project/file-example.sgl" expect-stdout: "file-ok\n" timeout: 30]{}92
@example["timeout" expect-timeout: #t timeout: 1 display: 'hidden]{93
@code["sigil"]{(let loop () (loop))}94
}95
@project-check["d3-project" root: "d3-project"96
files: '("package.sgl" "src/d3-project/main.sgl")97
expect-stdout: "project-ok\n" timeout: 30]{}98
}100
@end chapter