diff --git a/examples/quine.apfl b/examples/quine.apfl new file mode 100644 index 0000000..a0a72ae --- /dev/null +++ b/examples/quine.apfl @@ -0,0 +1,35 @@ +q = "\"" +e = "\\" +is-number = { x -> == (type x) "number" } +to-repr = ({ + aux = { + [] -> "" + [x?is-number ~xs] -> & " " (tostring x) " " (aux xs) + [x ~xs] -> & q x q (aux xs) + } + + {parts -> & "[" (aux parts) "]"} +}) +fmt = { + [] _ -> "" + [x?is-number ~xs] args -> & args@x (fmt xs args) + [x ~xs] args -> & x (fmt xs args) +} +p = ["q = " 1 2 1 1 " +e = " 1 2 2 1 " +is-number = { x -> == (type x) " 1 "number" 1 " } +to-repr = ({ + aux = { + [] -> " 1 1 " + [x?is-number ~xs] -> & " 1 " " 1 " (tostring x) " 1 " " 1 " (aux xs) + [x ~xs] -> & q x q (aux xs) + } + + {parts -> & " 1 "[" 1 " (aux parts) " 1 "]" 1 "} +}) +fmt = { + [] _ -> " 1 1 " + [x?is-number ~xs] args -> & args@x (fmt xs args) + [x ~xs] args -> & x (fmt xs args) +} +p = " 0 "; print (fmt p [(to-repr p) q e])"]; print (fmt p [(to-repr p) q e]) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 424bcd9..0ad8b68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,6 +83,7 @@ functionaltest("predicate") functionaltest("compare") functionaltest("concat") functionaltest("join") +functionaltest("quine") install(TARGETS apfl DESTINATION lib) install(TARGETS apfl-bin DESTINATION bin) diff --git a/src/functional-tests/quine.at b/src/functional-tests/quine.at new file mode 100644 index 0000000..0823874 --- /dev/null +++ b/src/functional-tests/quine.at @@ -0,0 +1,72 @@ +===== script ===== +q = "\"" +e = "\\" +is-number = { x -> == (type x) "number" } +to-repr = ({ + aux = { + [] -> "" + [x?is-number ~xs] -> & " " (tostring x) " " (aux xs) + [x ~xs] -> & q x q (aux xs) + } + + {parts -> & "[" (aux parts) "]"} +}) +fmt = { + [] _ -> "" + [x?is-number ~xs] args -> & args@x (fmt xs args) + [x ~xs] args -> & x (fmt xs args) +} +p = ["q = " 1 2 1 1 " +e = " 1 2 2 1 " +is-number = { x -> == (type x) " 1 "number" 1 " } +to-repr = ({ + aux = { + [] -> " 1 1 " + [x?is-number ~xs] -> & " 1 " " 1 " (tostring x) " 1 " " 1 " (aux xs) + [x ~xs] -> & q x q (aux xs) + } + + {parts -> & " 1 "[" 1 " (aux parts) " 1 "]" 1 "} +}) +fmt = { + [] _ -> " 1 1 " + [x?is-number ~xs] args -> & args@x (fmt xs args) + [x ~xs] args -> & x (fmt xs args) +} +p = " 0 "; print (fmt p [(to-repr p) q e])"]; print (fmt p [(to-repr p) q e]) +===== output ===== +q = "\"" +e = "\\" +is-number = { x -> == (type x) "number" } +to-repr = ({ + aux = { + [] -> "" + [x?is-number ~xs] -> & " " (tostring x) " " (aux xs) + [x ~xs] -> & q x q (aux xs) + } + + {parts -> & "[" (aux parts) "]"} +}) +fmt = { + [] _ -> "" + [x?is-number ~xs] args -> & args@x (fmt xs args) + [x ~xs] args -> & x (fmt xs args) +} +p = ["q = " 1 2 1 1 " +e = " 1 2 2 1 " +is-number = { x -> == (type x) " 1 "number" 1 " } +to-repr = ({ + aux = { + [] -> " 1 1 " + [x?is-number ~xs] -> & " 1 " " 1 " (tostring x) " 1 " " 1 " (aux xs) + [x ~xs] -> & q x q (aux xs) + } + + {parts -> & " 1 "[" 1 " (aux parts) " 1 "]" 1 "} +}) +fmt = { + [] _ -> " 1 1 " + [x?is-number ~xs] args -> & args@x (fmt xs args) + [x ~xs] args -> & x (fmt xs args) +} +p = " 0 "; print (fmt p [(to-repr p) q e])"]; print (fmt p [(to-repr p) q e])