Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Quine/Main.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def s := "\ndef main : IO Unit := do\n IO.println (\"def s := \" ++ s.quote)\n IO.println (s)"

def main : IO Unit := do
IO.println ("def s := " ++ s.quote)
IO.println (s)
20 changes: 20 additions & 0 deletions Quine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Quine example

This is an example of a program that outputs its own source code.

```bash
~/lean4-samples/Quine$ lake build && build/bin/quine
def s := "\ndef main : IO Unit := do\n IO.println (\"def s := \" ++ s.quote)\n IO.println (s)"

def main : IO Unit := do
IO.println ("def s := " ++ s.quote)
IO.println (s)
~/lean4-samples/Quine$ cat Main.lean
def s := "\ndef main : IO Unit := do\n IO.println (\"def s := \" ++ s.quote)\n IO.println (s)"

def main : IO Unit := do
IO.println ("def s := " ++ s.quote)
IO.println (s)
```

This relies on the `quote` method of `String.quote : String → String`, which escapes and quotes a string.
15 changes: 15 additions & 0 deletions Quine/lakefile.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Lake
open Lake DSL

package quine {
-- add package configuration options here
}

lean_lib Quine {
-- add library configuration options here
}

@[defaultTarget]
lean_exe quine {
root := `Main
}
1 change: 1 addition & 0 deletions Quine/lean-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leanprover/lean4:nightly
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ in 3D which can be animated with the movement of a slider.

Explore how you can extend the Lean syntax to implement the popular python-style
[List Comprehension](ListComprehension/README.md).


## Quine

A simple [quine](https://en.wikipedia.org/wiki/Quine_(computing)): a program that outputs its own source code.