Learn Scarp through practical, runnable code examples.
Browse the learning catalog · Scarp compiler · Official documentation · Project website · Contribute
Scarp by Example is the hands-on companion to the Scarp programming language. Lessons are arranged from first program to numeric and AI-oriented programming. Every runnable lesson includes a Scarp .srp source file, an exact .stdout fixture, and bilingual teaching notes shown directly on the lesson page from the existing source-linked chapter guides.
Development-stage language: Scarp syntax can change between prereleases. This repository tests Scarp v0.0.6-alpha.3 at exact source commit
398b8fffor CI. Do not assume that a lesson compatible with compilermainwill run unchanged on an older download. See compatibility.
The learning portal now provides a dedicated URL for every runnable lesson, plus six chapter overview pages, source code, byte-exact expected output, previous/next lesson navigation, direct chapter-to-chapter journeys and last-lesson lab handoffs, English/Hindi explanations with exercises, bilingual source-aware lesson search with chapter filters and shareable links and compiler-source previews, optional on-device lesson completion and resume, and dark/light themes. It remains a static GitHub Pages site: Scarp code executes locally with the compiler, not in the browser. The Pages workflow validates all lessons before publishing.
Project inspection (introduced in alpha.5): The new English and हिन्दी tutorials demonstrate a real two-module project. The command scarp inspect modules --json DIRECTORY reports the statically checked module graph without executing runtime statements. The independent CLI tests compare project and entrypoint inventories. The optional online tutorial makes the source and verified output visible. The experimental C11 emitter is Rust embedding-only, not a scarp compile CLI command.
Scarp-first CLI quickstart: English guide · हिन्दी गाइड. Static verify is different from the older check, which can evaluate runtime expressions.
Local progress: On a lesson page, choose Mark lesson complete to save that lesson's ID in this browser only. The homepage shows overall completion and lets you resume the next unfinished lesson, export a JSON backup, import a backup to merge progress across browsers or devices, or clear saved progress. Backups contain only completed lesson IDs and are processed locally without upload, account or tracking. Import rejects corrupt and oversized files and never deletes existing completions. On browsers without local storage, normal lesson navigation still works.
Interactive checkpoints and chapter review: Eighteen carefully reviewed lessons (three in each chapter) have optional English/Hindi multiple-choice questions with immediate feedback and source-backed explanations. Each chapter overview also has an expandable Practice this chapter section reusing those same three verified questions in independent forms, so learners can review without changing pages. Every review question links to its original .srp lesson and recorded output; the chapter review introduces no new or unverified questions. Chapter cards and lesson search identify available checkpoints. Questions are checked against the lessons' real .stdout fixtures at build time. They do not execute Scarp in the browser, store quiz results, or replace each lesson's independent practical exercise. If JavaScript is unavailable, the same answers remain readable through a disclosure control. See question authoring rules.
Connected learning path: Each chapter now offers a three-step sequence: read its source-verified lessons, check understanding with three exact-output-backed English/Hindi questions, then build a real Scarp program in that chapter's local coding lab. Chapter, lesson, checkpoint and lab pages link back to each other. Previously saved lesson completions display in the path, but the site deliberately does not claim to grade quizzes or locally executed programs. Start with the Basics learning path.
Guided coding labs: Six English/Hindi compiler-verified core challenges (one per chapter) have runnable starter programs, exact target output, hints, and reference solutions. Control flow also offers an optional, independently verified stretch challenge for scanning integer readings and stopping at the first match. Every starter runs but differs from its solution; each solution matches an exact output fixture under the pinned compiler. A second optional stretch challenge in the AI foundations lab teaches alpha.3 topk, softmax_temp and logsoftmax_temp, with bilingual guidance and an upstream exact-output fixture. Practice locally; the website neither runs Scarp nor collects your attempts. Open the coding lab index or read the workflow.
Mobile and keyboard navigation: On narrow screens, the site uses an accessible Menu disclosure rather than a horizontally scrolling header. It works without JavaScript, and keyboard users can close it with Escape and return focus to the menu trigger. Chapter, search, project, lab, compiler and GitHub destinations stay consistent across desktop and mobile. The skip-to-content link remains available on every page.
Website navigation: Open a chapter from the home page, then select an example. For a direct link, use a path like 01 · Hello. The same source and output fixtures remain in Git; site development notes document the generated routes.
- Install Rust and Cargo to run the current compiler source, or select a supported binary from Scarp prereleases.
- Clone the Scarp repository, check out exact tested commit
ceff07d9014f466974e0c9e02fc5d23573f55777, then build it withcargo build --locked --offline. Confirm the current executable version withtarget/debug/scarp version(Windows:target\\debug\\scarp.exe version). - Clone this repository. From your Scarp checkout, run the binary on a lesson, using the absolute path to its
.srpfile:./target/debug/scarp exec /path/to/scarp-by-example/examples/01-basics/01-hello.srp. - Compare output with the lesson's adjacent
.stdoutfile. On Windows, usetarget\\debug\\scarp.exe.
For modules, the compiler resolves imports relative to the lesson file. Keep the companion _support directory with that lesson.
Learn to create, statically verify, and launch a real offline Scarp project. Follow the English project tutorial or the हिन्दी प्रोजेक्ट गाइड; the checked-in sample project runs with the official interpreter. Project commands are not native compilation or package publishing, and the sample is kept separate from the 52 numbered lessons.
Source-navigation workshop (now with an interactive source explorer): Trace two separately scoped bindings and named arguments through a real imported module. Open the bilingual workshop or inspect the original Scarp project. Click a declaration or use to highlight all its compiler-verified links across both .srp files, with English/Hindi explanations and working no-JavaScript anchor links. The teaching map is checked against the pinned compiler on Linux, macOS and Windows; no browser execution or live LSP is implied.
New in compiler alpha.6: A root mean square lesson demonstrates numerically stable signal magnitude. The English source navigation guide and हिन्दी मार्गदर्शिका explain read-only inspect symbols and inspect references; neither command executes the program.
New in published compiler alpha.3: Practice deterministic Top-K and temperature-controlled probabilities in the optional AI lab. This is score ranking, not random sampling, model training or a GPU runtime.
| Section | Topics | Status |
|---|---|---|
| 01 · Basics | Output, bindings, scopes, Unicode construction, conversions, comments and bitwise operations | Runnable lessons |
| 02 · Control flow | Conditions, while, counted repeat | Runnable lessons |
| 03 · Functions | Typed functions, recursion, executable contracts and accumulator recursion | Runnable lessons |
| 04 · Numerical collections | Numeric vectors, norms, refinement, windows and numeric kernels | Runnable lessons |
| 05 · Modules | Imports, exported definitions, private helpers, numeric collections and inspectable signatures | Runnable lessons |
| 06 · AI foundations | Matrix inference, composition, numerical probabilities and explicit gradients | Runnable lessons |
| Future topics | Structured errors, general collections, async, networking, agents | Not taught as implemented |
Status is not a promise of stable semantics. Each section records its upstream example provenance and current CI target. Advanced examples represent numeric building blocks, not an integrated model-training framework.
The example verification workflow builds Scarp v0.0.6-alpha.3 from its immutable source commit of the official compiler and performs static scarp verify then byte-exact scarp exec on every lesson on GitHub-hosted runners. An independent CLI smoke test checks legacy commands, real project creation/launch and alpha.5 project-directory module inspection, including file/project inventory equivalence, static-only behavior and invalid-manifest handling. Run the same checks locally:
python3 scripts/verify_examples.py --compiler /absolute/path/to/scarp/target/debug/scarpNo network calls or external Python packages are required by the verifier. A lesson without a matching expected-output fixture is rejected. See compatibility policy.
English remains the canonical source language. Read all 52 lessons in Hindi through companion guides for all six chapters. Each translated explanation links to the original .srp and exact .stdout fixture, and is displayed directly on its corresponding lesson page using a language toggle. Neither Scarp syntax nor verified outputs are translated. See translation guidelines, contributing, and the lesson format.
License: MIT for this learning repository. Some compiler-source examples originated in the separately licensed Scarp compiler repository; preserve upstream attribution and applicable licensing when reusing material. No stable Scarp by Example release is announced.