Add working catalog code and example

This commit is contained in:
Leni Aniva 2023-05-12 01:08:36 -07:00
parent 5a297e8fef
commit 9f53781ffe
2 changed files with 17 additions and 7 deletions

View File

@ -45,7 +45,9 @@ def catalog (args: Catalog): Subroutine CatalogResult := do
let state ← get let state ← get
match state.environments.get? args.id with match state.environments.get? args.id with
| .some env => | .some env =>
let names := env.constants.toList.map (λ ⟨x, _⟩ => toString x) let names := env.constants.fold (init := []) (λ es name info =>
if info.isUnsafe es.length > 500 then es else (toString name)::es)
--let names := env.constants.toList.map (λ ⟨x, _⟩ => toString x)
return { theorems := names } return { theorems := names }
| .none => throw s!"Invalid environment id {args.id}" | .none => throw s!"Invalid environment id {args.id}"
@ -96,5 +98,6 @@ unsafe def loop : T IO Unit := do
| .ok obj => IO.println <| toString <| obj | .ok obj => IO.println <| toString <| obj
loop loop
unsafe def main : IO Unit := unsafe def main : IO Unit := do
Lean.initSearchPath (← Lean.findSysroot)
StateT.run' loop ⟨#[]⟩ StateT.run' loop ⟨#[]⟩

View File

@ -8,14 +8,21 @@ Install `elan` and `lean4`. Then, execute
``` sh ``` sh
lake build lake build
``` ```
In order to use `mathlib`, its binary must also be built
``` sh
lake build std
lake build mathlib
```
## Usage ## Usage
Before usage, put the packages that you wish the REPL to use into a directory The binary must be run inside a `lake env` environment.
and build them. Put this directory into the variable `$LEAN_PATH`. Then
``` ```
$ build/bin/Pantograph $ lake env build/bin/Pantograph
{"cmd": "create", "payload": {"imports": ["Mathlib.Analysis.Seminorm"]}} {"cmd": "create", "payload": {"imports": ["Mathlib.Analysis.Seminorm"]}}
{"cmd": "catalog", "payload": {"id": 0}}
``` ```
There is temporarily a limit of 500 symbols to prevent stack overflow.