Add working catalog code and example

This commit is contained in:
Leni Aniva 2023-05-12 01:08:36 -07:00
parent b5cb464694
commit 7c96479bb5
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
match state.environments.get? args.id with
| .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 }
| .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
loop
unsafe def main : IO Unit :=
unsafe def main : IO Unit := do
Lean.initSearchPath (← Lean.findSysroot)
StateT.run' loop ⟨#[]⟩

View File

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