# Chicken Scheme

> Write, compile, debug, and package CHICKEN Scheme programs. Use this skill whenever the user mentions CHICKEN Scheme, call-cc.org, csc, csi, Scheme eggs, Scheme-to-C compilation, R5RS/R7RS Scheme, call/cc, continuations, SRFI, or wants help with any Scheme programming task using CHICKEN. Also trigger for questions about the CHICKEN FFI, C interop from Scheme, egg packaging, REPL usage, or scripting with csi. Even if the user just says "scheme" without specifying CHICKEN, use this skill if context suggests CHICKEN (e.g. they mention eggs, csc, chicken-install, or wiki.call-cc.org). DO NOT USE when: the user is working with another Scheme implementation (Racket, Guile, MIT Scheme, Gambit) — those have different module systems, package managers, and idioms.

- Skill: `bsene/chicken-scheme` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx skillmds@latest add bsene/chicken-scheme`
- Raw SKILL.md: https://api.skillmd.com/api/skills/bsene/chicken-scheme/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Productivity
- Author: bsene (https://skillmd.com/u/bsene)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/bsene/chicken-scheme

---


# CHICKEN Scheme Skill

CHICKEN is a Scheme-to-C compiler + interpreter. It produces portable, efficient C from Scheme source and supports R5RS / R7RS (via extension). The main commands are:

| Command             | Purpose                                      |
| ------------------- | -------------------------------------------- |
| `csi`               | Interactive interpreter (REPL)               |
| `csc`               | Compiler driver (Scheme → C → native binary) |
| `chicken-install`   | Install eggs (libraries)                     |
| `chicken-status`    | List installed eggs                          |
| `chicken-uninstall` | Remove an egg                                |

---

## Quick-Start Workflow

```scheme
;;; hello.scm
(import (chicken base))
(print "Hello, world!")
```

```bash
# Interpreted
csi -s hello.scm

# Compiled to executable
csc hello.scm          # produces ./hello
./hello

# Compiled as shared object (for loading into csi)
csc -shared hello.scm  # produces hello.so
```

---

## Egg System (Libraries)

```bash
chicken-install srfi-1         # list utilities
chicken-install matchable      # pattern matching
chicken-install http-client    # HTTP requests
chicken-install medea           # JSON parser

# Search eggs online: https://wiki.call-cc.org/eggs
```

---

## REPL Tips (csi)

```scheme
,?          ; help
,l file     ; load a file
,t expr     ; time an expression
,d name     ; describe a binding
,q          ; quit
```

Enable readline: `chicken-install breadline`, then add to `~/.csirc`:

```scheme
(import breadline)
(current-input-port (make-readline-port))
```

---

## Common Pitfalls

- **`csc` on Windows** may conflict with the C# compiler — use a full path or rename.
- **No `use` in CHICKEN 5** — replace `(use foo)` with `(import foo)`.
- **Dynamic loading** requires a shared library on the `CHICKEN_REPOSITORY_PATH`.
- **CLI arguments**: read via `(command-line-arguments)` from `(chicken process-context)` — not `(argv)`, and not Racket's `command-line` form.
- **`call/cc` is powerful but sharp** — prefer high-level abstractions (threads, conditions) over raw continuations in application code.
- **Unsafe mode** (`-unsafe`) disables all safety checks — only use for hot inner loops after profiling.

---

## Integrated Example

**Goal:** a CLI tool that reads a JSON file and prints how many records it has.

```scheme
;;; count.scm
(import (chicken base)
        (chicken process-context)  ; command-line-arguments
        (chicken file)             ; read-string
        medea)                     ; egg: read-json — NOT (use medea)

(define data (with-input-from-file (car (command-line-arguments)) read-json))
(printf "~a records~%" (length data))
```

```bash
chicken-install medea        # install the JSON egg first
csc count.scm                # Scheme → C → ./count
./count records.json         # => 42 records
```

The `medea` egg is pulled in with `(import medea)` — in CHICKEN 5 there is no `use`. `csc`
compiles to a native binary in one step; for quick iteration `csi -s count.scm records.json`
runs the same source interpreted.

---

## Read On Demand

| Read When                                                                                              | File                                                  |
| ------------------------------------------------------------------------------------------------------ | ----------------------------------------------------- |
| Modules, imports, tail recursion, call/cc, macros, records                                             | [Core Language](references/core-language.md)          |
| Scripting, shebang, CLI tools, everyday compiler flag examples, egg structure                          | [Scripting & CLI](references/scripting-cli.md)        |
| FFI: foreign-lambda, callbacks, C interop, embedding                                                   | [FFI Guide](references/ffi.md)                        |
| Egg authoring, testing, and publishing workflow                                                        | [Egg System](references/eggs.md)                      |
| Full `csi`/`csc` flag reference, runtime options, `(declare ...)` reference, deployment/static linking | [CLI & Compiler Cheatsheet](references/cheatsheet.md) |

---

## Benchmark

Scenario: `.benchmarks/scenarios/chicken-scheme-001-chicken5-migration.md` · Run: 2026-08-31 (salience re-run `wf_9a5588bc`) · Log: `.benchmarks/runs/2026-08-31/chicken-scheme-001-chicken5-migration.json`

| Model             | Without | With | Delta |
| ----------------- | ------- | ---- | ----- |
| claude-opus-4-8   | 83%     | 100% | +17%  |
| claude-sonnet-4-6 | 100%    | 100% | +0%   |
| claude-haiku-4-5  | 100%    | 83%  | −17%  |

> **SOFT PASS (run 2026-08-31)**. Salience re-run (process-context pitfall bullet + import added to the integrated example, wf_9a5588bc): opus's args-idiom miss cleared (+17). Haiku shows a one-criterion `csc -static`/`-deploy` dip on an untouched criterion — single-run noise suspect; targeted c4 re-run on the follow-up list. No edit left this cycle (cap reached). Gate per `.agents/skills/skill-optimizer/rules/release-gates.md`.

