matlab: fix do/slice, strings. Self-hosting!
authorJoel Martin <github@martintribe.org>
Tue, 10 Feb 2015 07:51:28 +0000 (01:51 -0600)
committerJoel Martin <github@martintribe.org>
Tue, 10 Feb 2015 07:51:28 +0000 (01:51 -0600)
Fix Makefile stats/stats-lisp.

16 files changed:
matlab/+types/List.m
matlab/Env.m
matlab/Makefile
matlab/core.m
matlab/printer.m
matlab/reader.m
matlab/step2_eval.m
matlab/step3_env.m
matlab/step4_if_fn_do.m
matlab/step5_tco.m
matlab/step6_file.m
matlab/step7_quote.m
matlab/step8_macros.m
matlab/step9_try.m
matlab/stepA_interop.m
matlab/types.m

index 3fc1429..1a9571c 100644 (file)
@@ -30,7 +30,7 @@ classdef List < handle
             if nargin < 3
                 last = length(obj.data);
             end
-            ret = types.List(obj.data{start:end});
+            ret = types.List(obj.data{start:last});
         end
 
         function ret = clone(obj)
index 0a09db8..66862ff 100644 (file)
@@ -43,7 +43,7 @@ classdef Env < handle
                 ret = fenv.data(k.name);
             else
                 throw(MException('ENV:notfound', ...
-                                 strcat('''', k.name, ''' not found')));
+                                 sprintf('''%s'' not found', k.name)));
             end
         end
     end
index 445512a..a603822 100644 (file)
@@ -1,6 +1,8 @@
-SOURCES_BASE = Reader.m types/Symbol.m reader.m printer.m
-#SOURCES_LISP = env.m core.m stepA_interop.m
-SOURCES_LISP = stepA_interop.m
+SOURCES_BASE = types.m types/Nil.m types/MalException.m \
+              types/Symbol.m types/List.m types/Vector.m \
+              types/HashMap.m types/Function.m types/Atom.m \
+              Reader.m reader.m printer.m
+SOURCES_LISP = Env.m core.m stepA_interop.m
 SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
 
 
index ef3848e..2f9e1f3 100644 (file)
@@ -206,6 +206,7 @@ classdef core
             n('count') = @(a) length(a);
             n('apply') = @core.apply;
             n('map') = @core.map;
+            n('conj') = @(x) disp('not implemented yet');
 
             n('with-meta') = @core.with_meta;
             n('meta') = @core.meta;
index 0642e7b..5200a6e 100644 (file)
@@ -9,13 +9,13 @@ classdef printer
                 str = num2str(obj);
             case 'char'
                 if types.keyword_Q(obj)
-                    str = strcat(':', obj(2:end));
+                    str = sprintf(':%s', obj(2:end));
                 else
                     if print_readably
                         str = strrep(obj, '\', '\\');
                         str = strrep(str, '"', '\"');
                         str = strrep(str, char(10), '\n');
-                        str = strcat('"', str, '"');
+                        str = sprintf('"%s"', str);
                     else
                         str = obj;
                     end
@@ -23,11 +23,11 @@ classdef printer
             case 'types.List'
                 strs = cellfun(@(x) printer.pr_str(x, print_readably), ...
                                obj.data, 'UniformOutput', false);
-                str = strcat('(', strjoin(strs, ' '), ')');
+                str = sprintf('(%s)', strjoin(strs, ' '));
             case 'types.Vector'
                 strs = cellfun(@(x) printer.pr_str(x, print_readably), ...
                                obj.data, 'UniformOutput', false);
-                str = strcat('[', strjoin(strs, ' '), ']');
+                str = sprintf('[%s]', strjoin(strs, ' '));
             case 'types.HashMap'
                 strs = {};
                 ks = obj.keys();
@@ -36,7 +36,7 @@ classdef printer
                     strs{end+1} = printer.pr_str(k, print_readably);
                     strs{end+1} = printer.pr_str(obj.get(k), print_readably);
                 end
-                str = strcat('{', strjoin(strs, ' '), '}');
+                str = sprintf('{%s}', strjoin(strs, ' '));
             case 'types.Nil'
                 str = 'nil';
             case 'logical'
index fc72ac5..84f6806 100644 (file)
@@ -36,12 +36,12 @@ classdef reader
             seq = {};
             token = rdr.next();
             if not(strcmp(token, start))
-                error(strcat('expected ''', start, ''''));
+                error(sprintf('expected ''%s''', start));
             end
             token = rdr.peek();
             while true
                 if eq(token, false)
-                    error(strcat('expected ''', last, ''''));
+                    error(sprintf('expected ''%s''', last));
                 end
                 if strcmp(token, last), break, end
                 seq{end+1} = reader.read_form(rdr);
index 34559c0..d742d6f 100644 (file)
@@ -33,6 +33,7 @@ function ret = eval_ast(ast, env)
 end
 
 function ret = EVAL(ast, env)
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
index 801ad6f..55a3668 100644 (file)
@@ -33,6 +33,7 @@ function ret = eval_ast(ast, env)
 end
 
 function ret = EVAL(ast, env)
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
index 0e24b28..a864194 100644 (file)
@@ -33,6 +33,7 @@ function ret = eval_ast(ast, env)
 end
 
 function ret = EVAL(ast, env)
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
index a4385e4..c0c46f6 100644 (file)
@@ -34,6 +34,7 @@ end
 
 function ret = EVAL(ast, env)
   while true
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
index cfca152..6a9476d 100644 (file)
@@ -34,6 +34,7 @@ end
 
 function ret = EVAL(ast, env)
   while true
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
@@ -120,7 +121,7 @@ function main(args)
     rep('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))"', repl_env);
 
     if ~isempty(args)
-        rep(strcat('(load-file "', args{1}, '")'), repl_env);
+        rep(sprintf('(load-file "%s")', args{1}), repl_env);
         quit;
     end
 
index cb572a6..3d1149a 100644 (file)
@@ -57,6 +57,7 @@ end
 
 function ret = EVAL(ast, env)
   while true
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
@@ -148,7 +149,7 @@ function main(args)
     rep('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))"', repl_env);
 
     if ~isempty(args)
-        rep(strcat('(load-file "', args{1}, '")'), repl_env);
+        rep(sprintf('(load-file "%s")', args{1}), repl_env);
         quit;
     end
 
index 8757c7a..5567649 100644 (file)
@@ -76,6 +76,7 @@ end
 
 function ret = EVAL(ast, env)
   while true
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
@@ -182,7 +183,7 @@ function main(args)
     rep('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))', repl_env);
 
     if ~isempty(args)
-        rep(strcat('(load-file "', args{1}, '")'), repl_env);
+        rep(sprintf('(load-file "%s")', args{1}), repl_env);
         quit;
     end
 
index a9bf92f..1f338b2 100644 (file)
@@ -76,6 +76,7 @@ end
 
 function ret = EVAL(ast, env)
   while true
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
@@ -201,7 +202,7 @@ function main(args)
     rep('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))', repl_env);
 
     if ~isempty(args)
-        rep(strcat('(load-file "', args{1}, '")'), repl_env);
+        rep(sprintf('(load-file "%s")', args{1}), repl_env);
         quit;
     end
 
index f9e3364..5b8e720 100644 (file)
@@ -76,6 +76,7 @@ end
 
 function ret = EVAL(ast, env)
   while true
+    %fprintf('EVAL: %s\n', printer.pr_str(ast, true));
     if ~types.list_Q(ast)
         ret = eval_ast(ast, env);
         return;
@@ -202,7 +203,7 @@ function main(args)
     rep('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))', repl_env);
 
     if ~isempty(args)
-        rep(strcat('(load-file "', args{1}, '")'), repl_env);
+        rep(sprintf('(load-file "%s")', args{1}), repl_env);
         quit;
     end
 
index 91f052d..4d78f91 100644 (file)
@@ -45,8 +45,8 @@ classdef types
         end
 
         function ret = keyword(str)
-            ret = strcat(native2unicode(hex2dec('029e'),'UTF-8'), ...
-                         str(2:end));
+            ret = sprintf('%s%s', native2unicode(hex2dec('029e'),'UTF-8'), ...
+                          str(2:end));
         end
         function ret = keyword_Q(obj)
             ret = length(obj) > 1 && ...