Merge pull request #400 from asarhaddon/improve-mal-impl-macro-no-meta
[jackhill/mal.git] / swift / step0_repl.swift
1 //******************************************************************************
2 // MAL - step 0 - repl
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 //******************************************************************************
9
10 import Foundation
11
12 // Parse the string into an AST.
13 //
14 private func READ(str: String) -> String {
15 return str
16 }
17
18 // Walk the AST and completely evaluate it, handling macro expansions, special
19 // forms and function calls.
20 //
21 private func EVAL(ast: String) -> String {
22 return ast
23 }
24
25 // Convert the value into a human-readable string for printing.
26 //
27 private func PRINT(exp: String) -> String {
28 return exp
29 }
30
31 // Perform the READ and EVAL steps. Useful for when you don't care about the
32 // printable result.
33 //
34 private func RE(text: String) -> String {
35 let ast = READ(text)
36 let exp = EVAL(ast)
37 return exp
38 }
39
40 // Perform the full READ/EVAL/PRINT, returning a printable string.
41 //
42 private func REP(text: String) -> String {
43 let exp = RE(text)
44 return PRINT(exp)
45 }
46
47 // Perform the full REPL.
48 //
49 private func REPL() {
50 while true {
51 if let text = _readline("user> ") {
52 print("\(REP(text))")
53 } else {
54 print("")
55 break
56 }
57 }
58 }
59
60 func main() {
61 load_history_file()
62 REPL()
63 save_history_file()
64 }