mirror of
https://github.com/kanaka/mal.git
synced 2024-09-20 10:07:45 +03:00
4769962955
- Workarounds for Octave 4.0.0: - no containers.Map yet so use new Dict structure when running under Octave. - weird error when +FOO/ directory and FOO.m file both exist so rename types.m to type_utils.m - no getReport so implement custom stack printer - workaround weird issue that happens when a class initializer is called with the first argument of the same class as per Env(outer, ...). The class is not properly initialized. So for now, wrap the outer in a cell as Env({outer}, ...) - missing MException object types so when in Octave, use a global variable to store the error object. - missing native2unicode so just use 0xff character for keyword prefix. - workaround some function calling/passing differences. For example, the "@" anonymous function symbol does not seem to work for conveying an existing function but only for defininign a new one. E.g. this works: @(a,b) a+b but this doesn't @my_adder_fn. so just do this: @(a,b) my_adder_fn(a,b) - Add Dockerfile with Octave - Active Travis for matlab implementation using Octave
56 lines
2.0 KiB
Matlab
56 lines
2.0 KiB
Matlab
% this is just being used as a namespace
|
|
classdef printer
|
|
methods (Static = true)
|
|
function str = pr_str(obj, print_readably)
|
|
switch class(obj)
|
|
case 'types.Symbol'
|
|
str = obj.name;
|
|
case 'double'
|
|
str = num2str(obj);
|
|
case 'char'
|
|
if type_utils.keyword_Q(obj)
|
|
str = sprintf(':%s', obj(2:end));
|
|
else
|
|
if print_readably
|
|
str = strrep(obj, '\', '\\');
|
|
str = strrep(str, '"', '\"');
|
|
str = strrep(str, char(10), '\n');
|
|
str = sprintf('"%s"', str);
|
|
else
|
|
str = obj;
|
|
end
|
|
end
|
|
case 'types.List'
|
|
strs = cellfun(@(x) printer.pr_str(x, print_readably), ...
|
|
obj.data, 'UniformOutput', false);
|
|
str = sprintf('(%s)', strjoin(strs, ' '));
|
|
case 'types.Vector'
|
|
strs = cellfun(@(x) printer.pr_str(x, print_readably), ...
|
|
obj.data, 'UniformOutput', false);
|
|
str = sprintf('[%s]', strjoin(strs, ' '));
|
|
case 'types.HashMap'
|
|
strs = {};
|
|
ks = obj.keys();
|
|
for i=1:length(ks)
|
|
k = ks{i};
|
|
strs{end+1} = printer.pr_str(k, print_readably);
|
|
strs{end+1} = printer.pr_str(obj.get(k), print_readably);
|
|
end
|
|
str = sprintf('{%s}', strjoin(strs, ' '));
|
|
case 'types.Nil'
|
|
str = 'nil';
|
|
case 'logical'
|
|
if eq(obj, true)
|
|
str = 'true';
|
|
else
|
|
str = 'false';
|
|
end
|
|
case 'types.Atom'
|
|
str = sprintf('(atom %s)', printer.pr_str(obj.val,true));
|
|
otherwise
|
|
str = '#<unknown>';
|
|
end
|
|
end
|
|
end
|
|
end
|