From 53beaa0a6ddd9d8a5fb531f97c44a9c7129d1de7 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Sun, 6 Apr 2014 22:13:14 -0500 Subject: CS: add step1_read_print --- cs/printer.cs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 cs/printer.cs (limited to 'cs/printer.cs') diff --git a/cs/printer.cs b/cs/printer.cs new file mode 100644 index 0000000..7ee5c03 --- /dev/null +++ b/cs/printer.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using Mal; +using MalVal = Mal.types.MalVal; +using MalList = Mal.types.MalList; + +namespace Mal { + public class printer { + public static string join(List value, + string delim, bool print_readably) { + List strs = new List(); + foreach (MalVal mv in value) { + strs.Add(mv.ToString(print_readably)); + } + return String.Join(delim, strs.ToArray()); + } + + public static string join(Dictionary value, + string delim, bool print_readably) { + List strs = new List(); + foreach (KeyValuePair entry in value) { + if (print_readably) { + strs.Add("\"" + entry.Key.ToString() + "\""); + } else { + strs.Add(entry.Key.ToString()); + } + strs.Add(entry.Value.ToString(print_readably)); + } + return String.Join(delim, strs.ToArray()); + } + + public static string _pr_str(MalVal mv, bool print_readably) { + return mv.ToString(print_readably); + } + + /* + public static string _pr_str_args(MalList args, String sep, + bool print_readably) { + return join(args.getList(), sep, print_readably); + } + */ + + } +} -- cgit v1.2.3