Chez Scheme Syntax Overview

  1. Understanding Scheme Basics



  2. Basic Data Types



  3. Variables and Definitions



  4. Arithmetic Operations



  5. Comparison and Logical Operations



  6. Conditional Expressions



  7. Lists and Pairs



  8. Lambda Expressions



  9. Local Bindings: let, let*, and letrec



  10. Recursion



  11. Common List Operations



  12. String Operations



  13. Input and Output



  14. Common Predicates



  15. Quick Reference Summary



Multiple Expressions in Conditionals

  1. The Problem with if



  2. Solution: Using begin



  3. Using begin with if



  4. Alternative: when and unless



  5. Using cond for Multiple Expressions



  6. Common Patterns and Examples



  7. When begin is NOT Needed



  8. Summary: When to Use What

  9. Situation Use Example
    Multiple expressions in if then/else begin (if test (begin e1 e2) e3)
    Only execute if true, no else when (when test e1 e2)
    Only execute if false, no else unless (unless test e1 e2)
    Multi-way with multiple expressions cond (cond (t1 e1 e2) (t2 e3 e4))
    In function/lambda/let body Nothing (implicit) (define (f) e1 e2)

    ; if with multiple expressions
    (if test
        (begin e1 e2 e3)
        (begin e4 e5 e6))
    
    ; when (cleaner for one-sided if)
    (when test
      e1
      e2
      e3)
    
    ; unless (cleaner for negative one-sided if)
    (unless test
      e1
      e2
      e3)
    
    ; cond (no begin needed)
    (cond
      (test1 e1 e2 e3)
      (test2 e4 e5 e6)
      (else e7 e8 e9))
    
    ; Function body (no begin needed)
    (define (func)
      e1
      e2
      e3)


Chez Scheme Naming Conventions

  1. Understanding Scheme Identifiers



  2. Predicate Naming Convention



  3. Mutating Function Convention



  4. Type Conversion Convention



  5. Multi-word Identifier Convention



  6. Global Variable Convention



  7. Constructor and Maker Convention



  8. Private/Internal Naming



  9. Common Naming Patterns Summary

  10. Convention Pattern Examples
    Predicates (boolean returns) name? empty?, valid?, member?
    Mutating functions name! set!, vector-set!, increment!
    Type conversions type-a->type-b list->vector, string->number
    Multi-word names kebab-case string-length, file-exists?
    Global variables *name* *debug-mode*, *max-size*
    Constructors make-name make-vector, make-point
    Internal/private %name or name-internal %helper, parse-internal




Interacting with Chez Scheme

  1. Starting Chez Scheme



  2. Loading and Compiling Files



  3. Command-Line Usage



  4. REPL Features and Commands



  5. Working with Libraries and Imports



  6. Compilation and Optimization



  7. Debugging and Error Handling



  8. Creating Standalone Executables



  9. Workflow Best Practices




Chez Scheme Command Line Options

  1. Basic Invocation



  2. Execution Mode Options



  3. Library Options



  4. Optimization and Debugging Options



  5. Expression Editor Options



  6. Boot File Options



  7. Other Options



  8. Environment Variables



  9. Accessing Command Line Arguments in Scheme



  10. Quick Reference Table

  11. Option Description
    -q, --quiet Suppress greeting and prompts
    --script file Run file as shell script
    --program file Run file as R6RS program
    --libdirs dir:... Set library directories
    --libexts ext:... Set library extensions
    --compile-imported-libraries Compile libraries before loading
    --import-notify Trace library search
    --optimize-level n Set optimization (0-3)
    --debug-on-exception Enter debugger on exceptions
    --eedisable Disable expression editor
    --eehistory off|file Set/disable history file
    -b, --boot file Load boot file
    --verbose Trace boot search
    --enable-object-counts Enable GC object counting
    --retain-static-relocation Keep relocation info
    --version Print version and exit
    --help Print help and exit
    -- Pass remaining args to Scheme



R6RS in Chez Scheme

  1. What is R6RS?



  2. R6RS Standard Libraries



  3. R6RS Top-Level Programs



  4. R6RS Library Definition



  5. Import Specifications



  6. Export Specifications



  7. R6RS Records



  8. R6RS Exception Handling



  9. R6RS Bytevectors



  10. R6RS Hash Tables



  11. Chez Scheme vs R6RS Mode



  12. Compiling R6RS Programs



  13. Portability Tips




Control Flow in Chez Scheme

  1. Conditional Expressions



  2. Sequencing



  3. Iteration with Named let



  4. The do Loop



  5. Higher-Order Iteration



  6. Multiple Values



  7. Continuations



  8. Dynamic Wind



  9. Exception Handling



  10. Non-Local Exit Patterns



  11. Tail Calls and Optimization



  12. Fluid Bindings (Parameters)



  13. Control Flow Summary

  14. Construct Purpose Returns
    if Two-way branch Consequent or alternative
    cond Multi-way branch on predicates First matching clause
    case Match against literal values Matching clause
    when/unless One-sided conditional Body or unspecified
    and/or Short-circuit boolean First false/true or last
    begin Sequence expressions Last expression
    begin0 Sequence with first value First expression
    Named let Local recursion/iteration Final result
    do Traditional loop Result expression
    for-each Iterate for side effects Unspecified
    map Transform list(s) New list
    fold-left/fold-right Accumulate over list Accumulated value
    values Return multiple values Multiple values
    let-values Bind multiple values Body result
    call/cc Capture continuation Body or continuation result
    dynamic-wind Ensure cleanup Body result
    guard Exception handling Body or handler result
    parameterize Dynamic binding Body result


Chez Scheme Debugging

  1. Print Debugging with printf



  2. Tracing Procedures



  3. The Debugger



  4. The Inspector



  5. Breakpoints



  6. Interrupting Infinite Loops



  7. Debug Parameters



  8. Pretty Printing



  9. Assertions and Contracts



  10. Timing and Profiling



  11. Café System



  12. Common Debugging Patterns




Foreign Interface in Chez Scheme

  1. Subprocess Communication



  2. Calling Out of Scheme



  3. Calling Into Scheme



  4. Continuations and Foreign Calls



  5. Foreign Data



  6. Foreign Arrays of Managed Objects



  7. Providing Access to Foreign Procedures



  8. Using Other Foreign Languages



  9. C Library Routines



  10. Example: Socket Operations




Binding Forms in Chez Scheme

  1. Definitions



  2. Multiple-value Definitions



  3. Recursive Bindings



  4. Fluid Bindings



  5. Top-Level Bindings



  6. Additional Binding Forms



  7. Binding Forms Comparison

  8. Form Scope Evaluation Use Case
    define Top-level or local Immediate Variables and procedures
    let Local (lexical) Parallel Independent bindings
    let* Local (lexical) Sequential Dependent bindings
    letrec Local (lexical) Recursive Mutually recursive procedures
    letrec* Local (lexical) Sequential + recursive Recursive with order guarantees
    let-values Local (lexical) Parallel Multiple value bindings
    let*-values Local (lexical) Sequential Chained multiple values
    define-values Top-level or local Immediate Multiple value definitions
    parameterize Dynamic For dynamic extent Fluid/dynamic bindings
    let-syntax Local (lexical) Compile-time Local macros
    letrec-syntax Local (lexical) Compile-time Mutually recursive local macros
    case-lambda N/A (creates procedure) Immediate Multi-arity procedures
    do Local (lexical) Iterative Loop with bindings


    Choosing the Right Binding Form Need bindings? Local or Top-level? top-level define local Need recursion? no Dependencies? none let sequential let* yes letrec / letrec* For dynamic scope (value depends on call site, not definition site): use make-parameter + parameterize

    ; 1. Use the simplest form that works
    (let ([x 1] [y 2]) ...)     ; Prefer over let* when order doesn't matter
    
    ; 2. Use let* for step-by-step transformations
    (let* ([raw (read-input)]
           [parsed (parse raw)]
           [validated (validate parsed)])
      (process validated))
    
    ; 3. Use letrec only for recursive procedures
    (letrec ([f (lambda (n) ...)])   ; Good: f calls itself
      ...)
    
    ; 4. Use internal defines for cleaner code
    (define (process data)
      (define (helper x) ...)   ; Cleaner than letrec
      (define (another y) ...)
      (helper (another data)))
    
    ; 5. Prefer parameters over fluid-let
    (define config (make-parameter default-config))
    (parameterize ([config special-config])
      (do-work))                ; Safe with continuations
    
    ; 6. Use case-lambda for optional arguments
    (define greet
      (case-lambda
        [() (greet "World")]
        [(name) (printf "Hello, ~a!~n" name)]))
    
    ; 7. Named let for simple loops
    (let loop ([lst items] [acc '()])
      (if (null? lst)
          (reverse acc)
          (loop (cdr lst) (cons (f (car lst)) acc))))
    



Control Structures in Chez Scheme

  1. Conditionals



  2. Mapping and Folding



  3. Continuations



  4. Engines



  5. Delayed Evaluation



Operations on Objects in Chez Scheme

  1. Missing R6RS Type Predicates



  2. Pairs and Lists



  3. Characters



  4. Strings



  5. Vectors



  6. Bytevectors



  7. Stencil Vectors



  8. Boxes



  9. Symbols



  10. Void



  11. Sorting



  12. Hashtables



  13. Record Types



  14. Record Equality and Hashing



  15. Procedures



Numeric Operations in Chez Scheme

  1. Numeric Type Predicates



  2. Fixnum Operations



  3. Flonum Operations



  4. Inexact Complex Operations



  5. Bitwise and Logical Operators



  6. Random Number Generation



  7. Miscellaneous Numeric Operations




Input/Output Operations in Chez Scheme

  1. Generic Ports



  2. File Options



  3. Transcoders



  4. Port Operations



  5. String Ports



  6. File Ports



  7. Custom Ports



  8. Input Operations



  9. Output Operations



  10. Input/Output Operations



  11. Non-Unicode Bytevector/String Conversions



  12. Pretty Printing



  13. Formatted Output



  14. Input/Output Control Operations



  15. Fasl Output



  16. File System Interface



  17. Generic Port Examples




Libraries and Top-level Programs in Chez Scheme

  1. Built-in Libraries



  2. Running Top-level Programs



  3. Library and Top-level Program Forms



  4. Standalone Import and Export Forms



  5. Explicitly Invoking Libraries



  6. Library Parameters



  7. Library Inspection



  8. Complete Library Example



Syntactic Extension and Modules in Chez Scheme

  1. Fluid Keyword Bindings



  2. Syntax-Rules Transformers



  3. Syntax-Case Transformers



  4. Compile-time Values and Properties



  5. Modules



  6. Standalone Import and Export Forms



  7. Built-in Modules



  8. Meta Definitions



  9. Conditional Expansion



  10. Aliases



  11. Annotations



  12. Source Tables



  13. Complete Macro System Example



System Operations in Chez Scheme

  1. Exceptions



  2. Interrupts



  3. Environments



  4. Compilation, Evaluation, and Loading



  5. Source Directories and Files



  6. Compiler Controls



  7. Profiling



  8. Waiter Customization



  9. Transcript Files



  10. Times and Dates



  11. Timing and Statistics



  12. Cost Centers



  13. Parameters



  14. Virtual Registers



  15. Environmental Queries and Settings



  16. Subset Modes



  17. Complete System Example




Storage Management in Chez Scheme

  1. Garbage Collection



  2. Weak Pairs, Ephemeron Pairs, and Guardians



  3. Locking Objects



  4. Immobile Objects



  5. Phantom Bytevectors



  6. Complete Storage Management Example



Expression Editor in Chez Scheme

  1. Expression Editor Parameters



  2. Key Binding



  3. Editing Commands



  4. Creating New Editing Commands



  5. Advanced Expression Editor Topics



Thread System in Chez Scheme

  1. Thread Creation



  2. Mutexes



  3. Conditions



  4. Locks



  5. Locked Increment and Decrement



  6. Reference Counting with Ftype Guardians



  7. Memory Consistency



  8. Thread Parameters



  9. Buffered I/O



  10. Example: Bounded Queues



  11. Thread System Best Practices




Compatibility Features in Chez Scheme

  1. Hash Tables



  2. Extend-Syntax Macros



  3. Structures



  4. Compatibility File




File Conventions in Chez Scheme

  1. Scheme File Extensions



  2. Identifying Chez Scheme Files



  3. R6RS Library and Program Files



  4. Executable Scripts



  5. Project Organization