Add quine
This commit is contained in:
parent
07655c31bd
commit
86e148554d
3 changed files with 108 additions and 0 deletions
35
examples/quine.apfl
Normal file
35
examples/quine.apfl
Normal file
|
|
@ -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])
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
72
src/functional-tests/quine.at
Normal file
72
src/functional-tests/quine.at
Normal file
|
|
@ -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])
|
||||
Loading…
Reference in a new issue