1 //******************************************************************************
2 // MAL - step 1 - read/print
3 //******************************************************************************
4 // This file is automatically generated from templates/step.swift. Rather than
5 // editing it directly, it's probably better to edit templates/step.swift and
6 // regenerate this file. Otherwise, your change might be lost if/when someone
7 // else performs that process.
8 //******************************************************************************
12 // Parse the string into an AST.
14 private func READ(str: String) throws -> MalVal {
15 return try read_str(str)
18 // Walk the AST and completely evaluate it, handling macro expansions, special
19 // forms and function calls.
21 private func EVAL(ast: MalVal) -> MalVal {
25 // Convert the value into a human-readable string for printing.
27 private func PRINT(exp: MalVal) -> String {
28 return pr_str(exp, true)
31 // Perform the READ and EVAL steps. Useful for when you don't care about the
34 private func RE(text: String) -> MalVal? {
37 let ast = try READ(text)
39 } catch let error as MalException {
40 print("Error parsing input: \(error)")
42 print("Error parsing input: \(error)")
48 // Perform the full READ/EVAL/PRINT, returning a printable string.
50 private func REP(text: String) -> String? {
52 if exp == nil { return nil }
56 // Perform the full REPL.
60 if let text = _readline("user> ") {
61 if let output = REP(text) {