From 9cd074db4da194630b223a988b25fd015b527d38 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 26 May 2016 17:42:14 +0200 Subject: Improved tree toString; reverse.smf --- Smurf.icl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'Smurf.icl') diff --git a/Smurf.icl b/Smurf.icl index 7223ce7..d4fbcb6 100644 --- a/Smurf.icl +++ b/Smurf.icl @@ -57,6 +57,9 @@ where fromChar 'g' = Get fromChar 'x' = Exec +printList :: [a] -> String | toString a +printList xs = "[" <+ concat (intersperse ":" (map (\s->'"' <+ s <+ '"') xs)) <+ "]" + instance zero State where zero = { stack = zero, store = zero } instance zero ListIO where zero = {input=[], output=[]} @@ -68,14 +71,14 @@ where instance toString Transition where toString ((p1, ip1, st1) --> (ip2, op, st2)) - = "<" <+ simple 2 p1 <+ "," <+ st1 <+ "," <+ printToString ip1 <+ "> -> (" - <+ printToString ip2 <+ "," <+ printToString op <+ "," <+ st2 <+ ")" + = "<" <+ simple 2 p1 <+ "," <+ st1 <+ "," <+ printList ip1 <+ "> -> (" + <+ printList ip2 <+ "," <+ printList op <+ "," <+ st2 <+ ")" where simple :: !Int !Program -> String simple _ [] = "λ" simple i pgm - | i <= length pgm = concat $ intersperse ":" $ map toString pgm - = concat $ intersperse ":" $ map toString (take i pgm) + | i >= length pgm = concat $ intersperse ":" $ map toString pgm + = simple i (take i pgm) +++ ":..." instance toString DerivationTree where -- cgit v1.2.3