1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 18:18:51 +03:00
mal/cpp/step1_read_print.cpp
Stephen Thirlwall 494c160856 Don't pass an env to apply
Due to some initial confusion about which env to pass to the eval
builtin, I'd been needlessly passing an env to apply all along.

No need.
2015-12-15 11:22:25 +11:00

67 lines
1.2 KiB
C++

#include "MAL.h"
#include "ReadLine.h"
#include "Types.h"
#include <iostream>
#include <memory>
malValuePtr READ(const String& input);
String PRINT(malValuePtr ast);
static ReadLine s_readLine("~/.mal-history");
static String rep(const String& input);
static malValuePtr EVAL(malValuePtr ast);
int main(int argc, char* argv[])
{
String prompt = "user> ";
String input;
while (s_readLine.get(prompt, input)) {
String out;
try {
out = rep(input);
}
catch (malEmptyInputException&) {
continue; // no output
}
catch (String& s) {
out = s;
};
std::cout << out << "\n";
}
return 0;
}
static String rep(const String& input)
{
return PRINT(EVAL(READ(input)));
}
malValuePtr READ(const String& input)
{
return readStr(input);
}
static malValuePtr EVAL(malValuePtr ast)
{
return ast;
}
String PRINT(malValuePtr ast)
{
return ast->print(true);
}
// These have been added after step 1 to keep the linker happy.
malValuePtr EVAL(malValuePtr ast, malEnvPtr)
{
return ast;
}
malValuePtr APPLY(malValuePtr ast, malValueIter, malValueIter)
{
return ast;
}