2015-02-08 10:13:41 +03:00
|
|
|
classdef core
|
|
|
|
methods(Static)
|
2015-02-08 22:18:08 +03:00
|
|
|
function str = pr_str(varargin)
|
|
|
|
strs = cellfun(@(s) printer.pr_str(s,true), varargin, ...
|
|
|
|
'UniformOutput', false);
|
|
|
|
str = strjoin(strs, ' ');
|
|
|
|
end
|
|
|
|
function str = do_str(varargin)
|
|
|
|
strs = cellfun(@(s) printer.pr_str(s,false), varargin, ...
|
|
|
|
'UniformOutput', false);
|
|
|
|
str = strjoin(strs, '');
|
|
|
|
end
|
|
|
|
function ret = prn(varargin)
|
|
|
|
strs = cellfun(@(s) printer.pr_str(s,true), varargin, ...
|
|
|
|
'UniformOutput', false);
|
|
|
|
fprintf('%s\n', strjoin(strs, ' '));
|
|
|
|
ret = types.nil;
|
|
|
|
end
|
|
|
|
function ret = println(varargin)
|
|
|
|
strs = cellfun(@(s) printer.pr_str(s,false), varargin, ...
|
|
|
|
'UniformOutput', false);
|
|
|
|
fprintf('%s\n', strjoin(strs, ' '));
|
|
|
|
ret = types.nil;
|
|
|
|
end
|
|
|
|
|
2015-02-09 04:23:49 +03:00
|
|
|
function ret = concat(varargin)
|
|
|
|
if nargin == 0
|
|
|
|
ret = {};
|
|
|
|
else
|
|
|
|
ret = cat(2,varargin{:});
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-08 10:13:41 +03:00
|
|
|
function n = ns()
|
|
|
|
n = containers.Map();
|
2015-02-08 22:18:08 +03:00
|
|
|
n('=') = @types.equal;
|
|
|
|
|
|
|
|
n('pr-str') = @core.pr_str;
|
|
|
|
n('str') = @core.do_str;
|
|
|
|
n('prn') = @core.prn;
|
|
|
|
n('println') = @core.println;
|
2015-02-09 03:56:13 +03:00
|
|
|
n('read-string') = @reader.read_str;
|
|
|
|
n('slurp') = @fileread;
|
|
|
|
|
2015-02-08 10:13:41 +03:00
|
|
|
n('<') = @(a,b) a<b;
|
|
|
|
n('<=') = @(a,b) a<=b;
|
|
|
|
n('>') = @(a,b) a>b;
|
|
|
|
n('>=') = @(a,b) a>=b;
|
2015-02-08 22:18:08 +03:00
|
|
|
n('+') = @(a,b) a+b;
|
|
|
|
n('-') = @(a,b) a-b;
|
|
|
|
n('*') = @(a,b) a*b;
|
|
|
|
n('/') = @(a,b) floor(a/b);
|
2015-02-08 10:13:41 +03:00
|
|
|
|
|
|
|
n('list') = @(varargin) varargin;
|
|
|
|
n('list?') = @iscell;
|
2015-02-09 04:23:49 +03:00
|
|
|
|
|
|
|
n('cons') = @(a,b) [{a}, b];
|
|
|
|
n('concat') = @core.concat;
|
2015-02-08 10:13:41 +03:00
|
|
|
n('empty?') = @(a) length(a) == 0;
|
|
|
|
n('count') = @(a) length(a);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|