sigildocs

Libraries

Sigil includes a collection of libraries for building real applications. This overview highlights the most useful ones.

Core Language

These libraries form the foundation of Sigil and are available in every program.

(sigil core)

Essential utilities that extend R7RS: list operations, association lists, string helpers, and common patterns. This module is automatically imported everywhere.

(filter-map (lambda (x) (and (> x 0) (* x 2))) '(-1 2 -3 4))
; => (4 8)

(assoc-ref 'name '((name . "Alice") (age . 30)))
; => "Alice"

(sigil struct)

Define record types with keyword construction and default values.

(import (sigil struct))

(define-struct point (x) (y default: 0))

(define p (point x: 10 y: 20))
(point-x p)  ; => 10

(sigil match)

Pattern matching for destructuring and control flow.

(import (sigil match))

(match '(1 2 3)
  ((a b c) (+ a b c))    ; => 6
  (_ 'no-match))

Data Formats

(sigil json)

Parse and generate JSON with hash-table literals.

(import (sigil json))

(define data #{ name: "Sigil" version: "0.1.0" })
(json-encode data)
; => "{\"name\":\"Sigil\",\"version\":\"0.1.0\"}"

(json-decode "{\"x\": 10}")
; => #{ x: 10 }

(sigil markdown)

Parse Markdown to an AST for processing or rendering.

(import (sigil markdown))

(define doc (markdown-parse "# Hello\n\nSome *text*."))

(sigil sxml)

Work with XML/HTML as S-expressions.

(import (sigil sxml))

(sxml->string
  '(html (head (title "Hello"))
         (body (p "Welcome!"))))

Networking

(sigil http)

HTTP client and server with a simple, functional API.

(import (sigil http))

;; Client
(define response (http-get "https://example.com/api"))
(http-response-body response)

;; Server
(define (handler req)
  (http-response HTTP-OK "Hello, World!"))

(http-serve 8080 handler)

(sigil socket)

Low-level TCP and UDP networking.

(import (sigil socket))

(define sock (tcp-connect "example.com" 80))
(socket-send sock "GET / HTTP/1.0\r\n\r\n")
(socket-recv sock 1024)

(sigil websocket)

WebSocket client and server support.

(import (sigil websocket))

(websocket-connect "wss://echo.websocket.org"
  (lambda (ws)
    (websocket-send ws "Hello!")
    (display (websocket-recv ws))))

System

(sigil io)

File I/O beyond R7RS: read entire files, write strings, file metadata.

(import (sigil io))

(write-file "output.txt" "Hello, file!")
(read-file "output.txt")  ; => "Hello, file!"

(sigil fs)

Filesystem operations: directories, paths, globbing.

(import (sigil fs))

(directory-list ".")
(glob "src/**/*.sgl")
(file-exists? "config.json")

(sigil process)

Spawn and manage external processes.

(import (sigil process))

(define result (run "ls" "-la"))
(process-output result)

(sigil path)

Path manipulation that works across platforms.

(import (sigil path))

(path-join "src" "lib" "main.sgl")  ; => "src/lib/main.sgl"
(path-extname "file.tar.gz")        ; => ".gz"
(path-dirname "/home/user/file")    ; => "/home/user"

Concurrency

(sigil async)

Cooperative multitasking with lightweight tasks.

(import (sigil async))

(with-async
  (go (begin
        (display "Task A\n")
        (sleep 0.1)
        (display "Task A done\n")))
  (go (begin
        (display "Task B\n")
        (sleep 0.05)
        (display "Task B done\n"))))

(sigil channels)

CSP-style channels for communicating between tasks.

(import (sigil async)
        (sigil channels))

(with-async
  (define ch (make-channel))
  (go (channel-send ch "hello"))
  (display (channel-recv ch)))  ; => "hello"

Database

(sigil sqlite)

SQLite database access.

(import (sigil sqlite))

(define db (sqlite-open "app.db"))
(sqlite-exec db "CREATE TABLE users (id INTEGER, name TEXT)")
(sqlite-exec db "INSERT INTO users VALUES (1, 'Alice')")
(sqlite-query db "SELECT * FROM users")

Text Processing

(sigil string)

String utilities beyond R7RS.

(import (sigil string))

(string-split "a,b,c" ",")        ; => ("a" "b" "c")
(string-join '("a" "b" "c") "-")  ; => "a-b-c"
(string-trim "  hello  ")         ; => "hello"

(sigil ansi)

Terminal colors and formatting.

(import (sigil ansi))

(display (ansi-bold (ansi-red "Error: ")))
(display "Something went wrong\n")

Command-Line Tools

(sigil args)

Parse command-line arguments with flags and subcommands.

(import (sigil args))

(define parser
  (args-parser
    (flag 'verbose "-v" "--verbose" "Enable verbose output")
    (option 'output "-o" "--output" "Output file" default: "out.txt")))

(define opts (args-parse parser (command-line)))

Development

(sigil test)

Testing framework with assertions and test suites.

(import (sigil test))

(test-group "math"
  (test "addition" (assert-equal (+ 1 2) 3))
  (test "multiplication" (assert-equal (* 3 4) 12)))

(run-tests)

(sigil repl)

Embed a REPL in your application for debugging.

R7RS Compatibility

Sigil includes the standard R7RS libraries:

  • (scheme base) - Core language
  • (scheme write) - Output procedures
  • (scheme read) - Input procedures
  • (scheme file) - File ports
  • (scheme char) - Character operations
  • (scheme cxr) - Extended car/cdr
  • (scheme lazy) - Delayed evaluation
  • (scheme case-lambda) - Multi-arity procedures
  • (scheme process-context) - Environment access