Skip to content

About

suchi scheme implement by ruby

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

Sucheme - RubyによるR5RS Schemeインタープリタ

CI

Sucheme(スキーム)は、純粋なRubyで実装されたR5RS準拠のSchemeインタープリタです。

アーキテクチャ

graph LR
    A[ソース] --> B[Lexer]
    B --> C[Parser]
    C --> D[Evaluator]
    D --> E[結果]
    D <--> F[Environment]
    D <--> G[Primitives]
Loading

特徴

  • R5RS準拠: 標準的なScheme仕様に準拠
  • 末尾呼び出し最適化: トランポリニングによるTCO
  • 完全な数値タワー: 整数、有理数、浮動小数点
  • syntax-rules: 省略記号付きマクロシステム
  • call/cc: 継続(脱出継続)
  • REPL: インタラクティブ環境
  • Web UI: ブラウザベースの実行環境

インストール

export PATH="$HOME/.local/share/gem/ruby/3.2.0/bin:$PATH"
bundle install --path vendor/bundle

使い方

# REPL起動
bundle exec ruby bin/sucheme

# ファイル実行
bundle exec ruby bin/sucheme samples/01_basics/variables.scm

# 式の評価
bundle exec ruby bin/sucheme -e '(+ 1 2 3)'

# Web UI
bundle exec ruby web/app.rb

Windows (PowerShell)

# REPL起動
bundle exec ruby bin/sucheme

# ファイル実行
bundle exec ruby bin/sucheme samples\01_basics\variables.scm

# 式の評価(シングルクォートの代わりにダブルクォートを使用)
bundle exec ruby bin/sucheme -e "(+ 1 2 3)"

# バッチラッパー経由(bin\sucheme.bat)
.\bin\sucheme.bat -e "(+ 1 2 3)"

# Web UI
bundle exec ruby web\app.rb

クイックスタート

; 基本的な算術
(+ 1 2 3)      ;=> 6
(* 2 3 4)      ;=> 24

; 関数定義
(define (fact n)
  (if (= n 0) 1 (* n (fact (- n 1)))))
(fact 10)      ;=> 3628800

; 高階関数
(map (lambda (x) (* x x)) '(1 2 3 4 5))
;=> (1 4 9 16 25)

; マクロ
(define-syntax swap!
  (syntax-rules ()
    ((swap! a b)
     (let ((t a)) (set! a b) (set! b t)))))

テスト

bundle exec rspec spec/ --format progress

ライセンス

MIT

About

suchi scheme implement by ruby

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages