Decide that this is how we will handle $ when showing Str values.
Chris Pressey
1 year, 4 months ago
80  80 

81  81 
instance Show Term where

82  82 
show (Int i) = show i

83  
show (Str s) = "~" ++ "$" ++ s ++ "$"


83 
show (Str s) = "~" ++ (if elem '$' s then (show s) else "$" ++ s ++ "$")

84  84 
show (Cons h t) = "[" ++ show h ++ showTail t

85  85 
where showTail Null = "]"

86  86 
showTail (Cons h t) = "," ++ show h ++ showTail t

4  4 
exhaustive, but provides a basic sanity check that the language I've designed

5  5 
here comes close to what I had in mind.

6  6 


7 
Note that, until March 2019, the Quylthulg reference interpreter displayed


8 
the final result of running a Quylthulg program as a standard derived `show`


9 
representation of its internal Haskell data structure. After March 2019,


10 
it formats the result as a literal term in Quylthulg's concrete syntax.


11 
Such terms can be roundtripped: when treated as Quylthulg programs themselves,


12 
they will evaluate to themselves. (This is true in almost all cases.


13 
Discovering the one case where it is not true is left as an exercise for the


14 
reader.)


15 

7  16 
> Tests for functionality "Interpret Quylthulg Program"

8  17 

9  18 
Integer expressions.


21  30 
String expressions.

22  31 


23  32 


33 
 ~$Hello, world!$


34 
= ~$Hello, world!$


35 

24  36 
 &~$Shoes are $&&~~&~$4.99 a pair$&&

25  
= ~$Shoes are $4.99 a pair$


37 
= ~"Shoes are $4.99 a pair"

26  38 

27  39 
List expressions.

28  40 

