view src/requests.tp @ 20:92db3d1e8809

strJoin finally works.
author William Morgan <bill@mrgn.org>
date Fri, 09 Aug 2013 15:52:16 -0700
parents 5a025e6c6f89
children a4ac42c69285
line wrap: on
line source

#{

	strJoin <- :str arr {
		//head <- arr.get(0)
		//tail <- arr.
		print: "go\n"
		//print: (string: (arr length))
		acc <- ""
		arr foreach: :i el {
			print: (string: i) . " " . (string: el) . "\n"
			if: i = 0 {
				acc <- (string: el)
			} else: {
				acc <- acc . ", " . (string: el)
			}
		}
		print: "stop\n"
		acc
		//arr fold: "" with: :acc el {acc . el}
	}

	quote <- :str {
		"\"" . str . "\"" 
	}

	evalRequest <- :id args {
		#{
			string <- {
				idStr <- (quote: "id") . ":" . (quote: id)
				argsStr <- (quote: "arguments") . ":" . (quote: (strJoin: "," args))
				"{" . idStr . "," . argsStr . "}"
			}
		}
	}

	guessRequest <- :id :prog {
		#{
			string <- {
				idStr <- "\"id\":\"" . id . "\""
				progStr <- "\"program\":\"" . prog . "\""
				"{" . idStr . "," . progStr . "}"
			}
		}
	}

	main <- {
		print: ((evalRequest: "someId" #[1 2i64 3i64]) string) . "\n"
		print: ((guessRequest: "someId" "someProg") string) . "\n"
	}
}