Last active
July 1, 2024 15:57
-
-
Save paniq/457de0dc80bdd6734dba666a776f790b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
symbol(1,"the"). | |
symbol(2,"quick"). | |
symbol(3,"brown"). | |
symbol(4,"fox"). | |
symbol(5,"jumped"). | |
symbol(6,"over"). | |
symbol(7,"the"). | |
symbol(8,"lazy"). | |
symbol(9,"dog"). | |
list(10). | |
listindex(10,0,1). | |
listindex(10,1,2). | |
listindex(10,2,3). | |
list(11). | |
listindex(11,0,4). | |
listindex(11,1,5). | |
listindex(11,2,6). | |
listindex(11,3,7). | |
listindex(11,4,8). | |
listindex(11,5,9). | |
list(12). | |
listindex(12,0,10). | |
listindex(12,1,13). | |
listindex(12,2,11). | |
listindex(12,3,11). | |
list(13). | |
root(12). | |
listcount(?id, #max(?index + 1)) :- list(?id), listindex(?id, ?index, ?subid). | |
listcount(?id, 0) :- list(?id), ~listindex(?id, ?index, ?subid). | |
obj(?id) :- symbol(?id, ?str). | |
obj(?id) :- list(?id). | |
% toposorting; did not end up needing it | |
% dist(1, ?id, ?subid) :- listindex(?id, ?index, ?subid). | |
% dist(?n + 1, ?id, ?subsubid) :- listindex(?id, ?index, ?subid), dist(?n, ?subid, ?subsubid). | |
% toposort(0, ?x) :- obj(?x), ~dist(?n, ?x, ?y). | |
% toposort(#max(?n), ?x) :- dist(?n, ?x, ?y). | |
tostr(?id,?str) :- symbol(?id, ?str). | |
tostr(?id,CONCAT("(",CONCAT(?str,")"))) :- listcount(?id, ?n), cat(?id, ?n, ?str). | |
tostr(?id,"()") :- listcount(?id, 0). | |
cat(?id, 1, ?a) :- | |
listindex(?id,0,?subid), | |
tostr(?subid, ?a). | |
cat(?id, ?n + 1, CONCAT(?a, CONCAT(" ", ?b))) :- | |
cat(?id, ?n, ?a), | |
listindex(?id,?n,?subid), | |
tostr(?subid, ?b). | |
result(?str) :- root(?id), tostr(?id, ?str). | |
@export result :- csv{resource = ""}. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment