aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/Main.hs3
-rw-r--r--jotter.cabal15
-rw-r--r--package.yaml11
-rw-r--r--readme.md20
-rw-r--r--src/Lib.hs16
5 files changed, 27 insertions, 38 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 913bbb2..7a8bffa 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE LambdaCase #-}
+
module Main
( main
) where
@@ -18,6 +20,5 @@ main :: IO ()
main = do
args <- getArgs
case args of
- -- ["transpile", path] -> transpile path
["reduce", path] -> reduce path
_ -> putStrLn "Usage: jotter [transpile|reduce] <file>"
diff --git a/jotter.cabal b/jotter.cabal
index 2f7b480..c61e73d 100644
--- a/jotter.cabal
+++ b/jotter.cabal
@@ -50,18 +50,3 @@ executable jotter
, containers
, jotter
default-language: Haskell2010
-
-test-suite jotter-test
- type: exitcode-stdio-1.0
- main-is: Spec.hs
- other-modules:
- Paths_jotter
- hs-source-dirs:
- test
- ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
- build-depends:
- async
- , base >=4.7 && <5
- , containers
- , jotter
- default-language: Haskell2010
diff --git a/package.yaml b/package.yaml
index 6d1c483..03236d2 100644
--- a/package.yaml
+++ b/package.yaml
@@ -49,14 +49,3 @@ executables:
- -fllvm
dependencies:
- jotter
-
-tests:
- jotter-test:
- main: Spec.hs
- source-dirs: test
- ghc-options:
- - -threaded
- - -rtsopts
- - -with-rtsopts=-N
- dependencies:
- - jotter
diff --git a/readme.md b/readme.md
index 0f7a61b..9828dad 100644
--- a/readme.md
+++ b/readme.md
@@ -1,7 +1,7 @@
# Jotter
-Jotter (pronounced /dʒɑt.ər/) is a Turing tarpit and “an even better
-Gödel-numbering” than its “sister language”
+Jotter (pronounced /dʒɑt.ər/) is a Turing tarpit and an even better
+Gödel-numbering than its sister language
[Jot](https://esolangs.org/wiki/Jot).
## Semantics of Jotter
@@ -13,18 +13,22 @@ Gödel-numbering” than its “sister language”
[F1]ᵣ -> ([F]ₗK)
`[F]` converts the Jotter program `F` to combinatory logic. The
-associativity toggles between left and right (denoted by `ₗ/ᵣ`),
-starting with the `ₗ` state.
+associativity toggles between left and right (denoted by `ₗ/ᵣ`).
+
+The starting state depends on the length of the program: `ₗ` if
+`len % 2 == 0` (even) and `ᵣ` if `len % 2 == 1` (odd). Don’t worry, this
+only forces the core (the empty string, `I`) to always be on the left
+side of the application.
## Jot vs. Jotter
Jotter has exactly the same (regular) syntax as Jot, including support
-of the null program.
+for the null program.
Every Jot program can easily be translated to Jotter:
- [] -> -> I
- [F0] -> ???
+ [] -> -> I
+ [F0] -> [F]01 -> ([F]S)
[F1] -> ???
-Therefore Jotter is *Turing complete*.
+Therefore Jotter is *Turing-complete*.
diff --git a/src/Lib.hs b/src/Lib.hs
index 4f4d2f3..5d58008 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -5,6 +5,7 @@ module Lib
) where
import Term
+import Utils
data State = L | R
@@ -17,13 +18,22 @@ k = Abs (Abs (Idx 1))
i :: Term
i = Abs (Idx 0)
+clean :: String -> String
+clean (x : xs) | x == '0' || x == '1' = x : clean xs
+ | otherwise = clean xs
+clean [] = []
+
-- reverse wouldn't be needed if [0F] instead of [F0]
-fromJotter :: String -> Term
-fromJotter = go L . reverse
+fromCleanJotter :: String -> Term
+fromCleanJotter t | even $ length t = go L $ reverse t
+ | otherwise = go R $ reverse t
where
go L ('0' : xs) = App s (go R xs)
go R ('0' : xs) = App (go L xs) s
go L ('1' : xs) = App k (go R xs)
go R ('1' : xs) = App (go L xs) k
- go d (_ : xs) = go d xs
go _ [] = i
+ go _ _ = invalid
+
+fromJotter :: String -> Term
+fromJotter = fromCleanJotter . clean