1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/swift/step0_repl.swift
2015-03-23 01:23:27 -07:00

65 lines
1.5 KiB
Swift

//******************************************************************************
// MAL - step 0 - repl
//******************************************************************************
// This file is automatically generated from templates/step.swift. Rather than
// editing it directly, it's probably better to edit templates/step.swift and
// regenerate this file. Otherwise, your change might be lost if/when someone
// else performs that process.
//******************************************************************************
import Foundation
// Parse the string into an AST.
//
func READ(str: String) -> String {
return str
}
// Walk the AST and completely evaluate it, handling macro expansions, special
// forms and function calls.
//
func EVAL(ast: String) -> String {
return ast
}
// Convert the value into a human-readable string for printing.
//
func PRINT(exp: String) -> String {
return exp
}
// Perform the READ and EVAL steps. Useful for when you don't care about the
// printable result.
//
func RE(text: String) -> String {
let ast = READ(text)
let exp = EVAL(ast)
return exp
}
// Perform the full READ/EVAL/PRINT, returning a printable string.
//
func REP(text: String) -> String {
let exp = RE(text)
return PRINT(exp)
}
// Perform the full REPL.
//
func REPL() {
while true {
if let text = _readline("user> ") {
println("\(REP(text))")
} else {
println()
break
}
}
}
func main() {
load_history_file()
REPL()
save_history_file()
}