1 #import
<Foundation
/Foundation.h
>
3 #import "mal_readline.h"
8 NSObject
*READ
(NSString
*str
) {
12 NSObject
*EVAL(NSObject
*ast
, NSString
*env
) {
16 NSString
*PRINT(NSObject
*exp) {
17 return _pr_str
(exp, true
);
20 NSString
*REP
(NSString
*line) {
21 return PRINT(EVAL(READ
(line), @""
));
25 // Create an autorelease pool to manage the
memory into the program
26 NSAutoreleasePool
* pool
= [[NSAutoreleasePool alloc
] init
];
27 // If using automatic reference counting
(ARC
), use @autoreleasepool instead
:
31 char *rawline
= _readline
("user
> "
);
32 if (!rawline
) { break; }
33 NSString
*line = [NSString stringWithUTF8String
:rawline
];
34 if ([line length] == 0) { continue
; }
36 printf
("
%s\n", [[REP(line) description] UTF8String]);
37 } @
catch(NSString
*e
) {
38 printf
("
Error: %s\n", [e UTF8String]);
39 } @
catch(NSException
*e
) {
40 if ([[e name
] isEqualTo
:@"ReaderContinue"
]) { continue
; }
41 printf
("Exception
: %s\n", [[e reason] UTF8String]);