An open API service indexing awesome lists of open source software.

https://github.com/aygp-dr/scope-safari

Cross-language exploration of module systems, scope, closures, and environment handling with formal verification
https://github.com/aygp-dr/scope-safari

closure concurrency cross-language emacs environment formal-methods formal-verification freebsd language-comparison literate-programming makefile module-systems org-mode programming-languages scope thread-safety tla-plus verification

Last synced: 4 months ago
JSON representation

Cross-language exploration of module systems, scope, closures, and environment handling with formal verification

Awesome Lists containing this project

README

          

#+TITLE: Scope Safari
#+AUTHOR: Environment Explorer
#+DATE: 2025-06-22

#+HTML:


#+HTML: Status: Development
#+HTML: License: MIT
#+HTML: Platform: FreeBSD 14.3
#+HTML:

* Scope Safari: A Cross-Language Environment Exploration

This project explores scope, environment, and closures across different programming languages.

Each implementation provides a minimal utility that converts boolean values to emoji:
- ~true~ → "😊"
- ~false~ → "😔"

The focus is on examining how different languages handle scope, environment, and module systems.

* Tested Languages Matrix (FreeBSD 14.3-RELEASE)

| Language | Version | Status | Notes |
|------------+--------------+---------+-------------------------------|
| Python | 3.11.11 | ✅ | Using uv for venv management |
| JavaScript | Node 22.14.0 | ✅ | npm 10.9.2 |
| Elisp | Emacs 30.1 | ✅ | GNU Emacs |
| Guile | 3.0.10 | ✅ | GNU Guile 3 |
| Clojure | 1.12.0.1488 | ✅ | Clojure CLI |
| Hy | 1.0.0 | ✅ | Lisp syntax for Python |
| Smalltalk | 3.2.5 | ✅ | GNU Smalltalk |
| Go | 1.21.13 | ✅ | Thread-safe implementation |
| Rust | 1.85.0 | ✅ | Using AtomicUsize for safety |
| C | Clang 19.1.7 | ✅ | Using atomic variables |
| Zig | 0.13.0 | ✅ | Memory-safe systems language |
| Haskell | 9.4.8 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/1][Issue #1]], [[https://github.com/aygp-dr/scope-safari/issues/17][#17]] (High) |
| Elixir | 1.16.1 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/2][Issue #2]] (Medium) |
| OCaml | 4.14.0 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/4][Issue #4]] (High) |
| Kotlin | 1.9.20 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/14][Issue #14]] (Low) |
| Crystal | 1.9.2 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/19][Issue #19]] (Low) |
| Julia | 1.10.0 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/18][Issue #18]] (Low) |
| V | 0.4.0 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/20][Issue #20]] (Low) |
| Nim | 1.6.14 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/23][Issue #23]] (Medium) |
| Racket | 8.11.1 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/24][Issue #24]] (Medium) |
| Ruby | 3.2.7 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/25][Issue #25]] (Low) |
| Perl | 5.36.3 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/26][Issue #26]] (Low) |
| Tcl | 8.6.15 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/27][Issue #27]] (Low) |
| Lua | 5.4.7 | ⬜ | [[https://github.com/aygp-dr/scope-safari/issues/28][Issue #28]] (Medium) |

* Setup

1. Clone the repository
2. Install language dependencies (optional):
#+begin_src bash
make install-deps # Requires sudo
#+end_src
3. Create and activate the Python virtual environment:
#+begin_src bash
uv venv
source .venv/bin/activate
#+end_src

* Project Structure

The project follows a simple structure for each language implementation:

#+begin_src
scope-safari/
├── com/
│ └── example/
│ └── truthmoji/
│ ├── index.js # JavaScript implementation
│ ├── index.ts # TypeScript implementation
│ ├── __init__.py # Python implementation
│ ├── truthmoji.hy # Hy implementation
│ ├── truthmoji.el # Elisp implementation
│ ├── truthmoji.scm # Guile Scheme implementation
│ ├── truthmoji.st # Smalltalk implementation
│ ├── truthmoji.go # Go implementation
│ ├── truthmoji.rs # Rust implementation
│ ├── truthmoji.c # C implementation
│ └── truthmoji.zig # Zig implementation
├── contracts/ # Formal specifications
│ ├── TruthMoji.tla # TLA+ specification
│ ├── TruthMoji.cfg # TLA+ configuration
│ ├── TruthMoji.sol # Solidity contract
│ ├── truthmoji.lean # Lean theorem proving
│ └── truthmoji_contract.py # Pydantic contract
├── scripts/ # Utility scripts
│ └── download_tools.sh # Downloads TLA+ tools and reference manuals
├── tools/ # TLA+ and verification tools (created by download_tools.sh)
├── docs/ # Documentation and reference manuals
│ └── references/ # Language reference manuals (created by download_tools.sh)
├── .venv/ # Python virtual environment
├── scope-safari.el # Emacs support for the project
├── .dir-locals.el # Emacs directory local variables
└── README.org # This file
#+end_src

* Language Selection

The languages for this project were selected based on several factors:

- Initial focus on Lisp family languages (Elisp, Scheme, Clojure, Hy)
- High popularity/usage languages from the [[https://www.tiobe.com/tiobe-index/][TIOBE Index]]
- Languages available in FreeBSD ports (/usr/ports/lang/)
- Inspiration from [[https://github.com/kanaka/mal][MAL (Make A Lisp)]] project
- Diverse representation of programming paradigms

Additional language implementations are tracked as GitHub issues, allowing other contributors or AI agents to extend the project while maintaining the consistent test structure. Implementation priorities (High, Medium, Low) reflect the importance of each language to the core goals of the project.

* Key Insights

From the exploration of scope and environment across different languages:

1. *Lexical vs Dynamic*: All modern implementations use lexical scope by default
2. *Privacy*: Ranges from convention (Python ~_~) to enforced (JS closures)
3. *Introspection*: Lisp-family languages generally offer more runtime inspection
4. *State Management*: Closures remain the universal pattern for encapsulation

* Usage

Each language implementation can be run independently. Use the Makefile targets for running implementations:

#+begin_src bash
# Run a specific language implementation
make run-js # JavaScript
make run-py # Python
make run-hy # Hy
make run-el # Elisp
make run-scm # Guile Scheme
make run-clj # Clojure
make run-st # Smalltalk
make run-go # Go
make run-rust # Rust
make run-c # C
make run-zig # Zig

# Run all implementations
make run-all
#+end_src

See SS.org for details on each implementation.

* Formal Verification

This project includes formal specifications of the TruthMoji behavior using:

- TLA+ specification (contracts/TruthMoji.tla)
- Pydantic model for Python (contracts/truthmoji_contract.py)
- Solidity smart contract (contracts/TruthMoji.sol)
- Lean theorem proving (contracts/truthmoji.lean)

To download TLA+ tools and language reference manuals:

#+begin_src bash
make download-tools
#+end_src

To run the TLA+ model checker against the specification:

#+begin_src bash
make verify-tla
#+end_src

To verify against the Pydantic contract:

#+begin_src bash
make verify-contract
#+end_src

To run all verification tools:

#+begin_src bash
make verify-all
#+end_src

* License

MIT