Skip to content

Commit

Permalink
Various changes; see description
Browse files Browse the repository at this point in the history
* Added `Za` function: convert numbers from base to base

* Improved `U` (`str2num`) to allow conversion to more general literals

* Improved two-input version of `!` (`permute`). Second input can now be
a scalar

* Changed the order of second and third optional inputs of `o` (convert
to double precision
array). Padding is not on the left by default

* `Yo` applied to strings or cell arrays changes case

* `Z"` (`blanks`) now accepts vector input

* Bug corrected in parser: space was not recognized as separator in
colon literals

* `Z#` (`fwrite`) now converts the file name to char if needed, and
deletes file "inout" at the
beginning of the program

* Octave compatibility: `max` and `min` now allow first and second input
to be char

* Comma can no longer be used as a separator. Use space or newline
instead

* Function `Y}` (`cell2mat`) has been unified with `g` (`logical`)

* `Yf` (prime factors) now returns an empty array for input 1

* `Xd` (`diag` / `spdiags`) now has one input by default

* `Xd` with several inputs or outputs (`spdiags`) now allows char inputs

* `YG` when used as `imwrite` now adds extension '.png' to filename if
it contains no extension
  • Loading branch information
lmendo committed Apr 6, 2016
1 parent bf2c69a commit 4e0b074
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 37 deletions.
14 changes: 14 additions & 0 deletions compatibility/max_comp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function varargout = max(varargin)
% Converts first or second inputs to double if they are char
if nargin>=1 && ischar(varargin{1})
varargin{1} = double(varargin{1});
end
if nargin>=2 && ischar(varargin{2})
varargin{2} = double(varargin{2});
end
if nargout==0
nargout = 1; % if called without outputs: produce 1 output
end
varargout = cell(1,nargout);
[varargout{:}] = builtin('max', varargin{:});
end
14 changes: 14 additions & 0 deletions compatibility/min_comp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function varargout = min(varargin)
% Converts first or second inputs to double if they are char
if nargin>=1 && ischar(varargin{1})
varargin{1} = double(varargin{1});
end
if nargin>=2 && ischar(varargin{2})
varargin{2} = double(varargin{2});
end
if nargout==0
nargout = 1; % if called without outputs: produce 1 output
end
varargout = cell(1,nargout);
[varargout{:}] = builtin('min', varargin{:});
end
Binary file modified doc/MATL_spec.pdf
Binary file not shown.
Binary file modified doc/function_table.pdf
Binary file not shown.
Binary file modified funDef.mat
Binary file not shown.
124 changes: 95 additions & 29 deletions funDef.txt

Large diffs are not rendered by default.

Binary file modified help.mat
Binary file not shown.
8 changes: 4 additions & 4 deletions matl_compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
% else % Octave: seeds are set randomly automatically by Octave
end
if ~online
appendLines('diary off; delete defout; diary defout', 0)
appendLines('delete inout; diary off; delete defout; diary defout', 0)
end
% For arrays with brackets or curly braces: F = false; T = true;
appendLines('F = false; T = true;', 0)
Expand Down Expand Up @@ -113,7 +113,7 @@
% Initiallize clipboards. Clipboards H--L are implemented directly as variables.
% Clipboard L is implemented as a cell array, where each cell is one clipboard
% "level".
appendLines('CB_H = { 2 }; CB_I = { 3 }; CB_J = { 1j }; CB_K = { 4 }; CB_L = { {[1 0]} {[0 -1 1]} {[1 3 2]} {[3 1 2]} {[1 -1j]} {[2 0]} {[1 -1j 0]} {[2 -1j]} {[1 2 0]} {[2 2 0]} {3600} {86400} {1440} {[31 28 31 30 31 30 31 31 30 31 30 31]} {[31 29 31 30 31 30 31 31 30 31 30 31]} {2*pi} {0.5772156649015328606} {(sqrt(5)+1)/2} };', 0)
appendLines('CB_H = { 2 }; CB_I = { 3 }; CB_J = { 1j }; CB_K = { 4 }; CB_L = { {[1 0]} {[0 -1 1]} {[1 -1j]} {[2 0]} {[1 -1j 0]} {[2 -1j]} {[2 3 1]} {[3 1 2]} {[1 2 0]} {[2 2 0]} {3600} {86400} {1440} {[31 28 31 30 31 30 31 31 30 31 30 31]} {[31 29 31 30 31 30 31 31 30 31 30 31]} {2*pi} {0.5772156649015328606} {(sqrt(5)+1)/2} };', 0)
% Initiallize automatic clipboards. Clipboard L is implemented as a cell
% array, where each cell is one clipboard "level" containing one input. It
% is initially empty.
Expand Down Expand Up @@ -181,7 +181,7 @@
case 'controlFlow.if' % '?'
appendLines('nin = 0;', S(n).nesting);
appendLines(implicitInputBlock, S(n).nesting); % code block for implicit input
newLines = { 'in = STACK{end}; STACK(end) = [];' ...
newLines = { 'in = STACK{end}; STACK(end) = []; if ~isreal(in), in = real(in); end' ...
'if in' };
appendLines(newLines, S(n).nesting);
case 'controlFlow.else' % '}'
Expand Down Expand Up @@ -267,7 +267,7 @@
appendLines('% Define subfunctions', 0)
fnames = {'num2str' 'im2col' 'spiral' 'unique' 'union' 'intersect' 'setdiff' 'setxor' 'ismember' ...
'triu' 'tril' 'randsample' 'nchoosek' 'vpa' 'sum' 'mean' 'diff' 'mod' 'repelem' 'dec2bin' 'dec2base' ...
'hypergeom' 'disp' 'str2func' 'logical' 'circshift' 'pdist2' 'strsplit'};
'hypergeom' 'disp' 'str2func' 'logical' 'circshift' 'pdist2' 'strsplit' 'max' 'min'};
verNumTh = [4 0 0]; % first version in which a modified function is not needed:
if (verNum(1)<verNumTh(1)) || ((verNum(1)==verNumTh(1)) && (verNum(2)<verNumTh(2))) || ((verNum(1)==verNumTh(1)) && (verNum(2)==verNumTh(2)) && (verNum(3)<verNumTh(3)))
fnames = [fnames {'colon'}];
Expand Down
7 changes: 4 additions & 3 deletions matl_parse.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
(s(pos)=='.' && pos<L && any(s(pos+1)=='0123456789'))
% It may be a number literal such as +3.4e-5j, or a two-number colon array such as
% -2.3:.4e2, or three-number colon array such as 10:-2.5e-1:.5e-5
[ini, fin] = regexp(s(pos:end), '([+-]?(\d+\.?\d*|\d*\.?\d+)(e[+-]?\d+)?j?\s*:\s*){0,2}[+-]?(\d+\.?\d*|\d*\.?\d+)(e[+-]?\d+)?j?', 'once');
[ini, fin] = regexp(s(pos:end), '([+-]?(\d+\.?\d*|\d*\.?\d+)(e[+-]?\d+)?j?:){0,2}[+-]?(\d+\.?\d*|\d*\.?\d+)(e[+-]?\d+)?j?', 'once');
if ~isempty(ini) && ini==1
if any(s(pos:pos-1+fin)==':') % It's a colon array literal
S(n).type = 'literal.colonArray.numeric';
Expand Down Expand Up @@ -117,7 +117,7 @@
S(n).nesting = parseNesting;
pos = pos + fin;
n = n + 1;
elseif any(s(pos)==['!&()*+-/:;<=>\^_|~' 'A':'W' 'a':'z'])
elseif any(s(pos)==['!&()*+,-/:;<=>\^_|~' 'A':'W' 'a':'z'])
S(n).type = 'function';
S(n).source = s(pos);
S(n).nesting = parseNesting;
Expand Down Expand Up @@ -183,6 +183,7 @@
parseNesting = parseNesting + 1; % restore nesting level
m = parseControlStack(parseNesting); % innermost control structure that is open
assert(strcmp(S(m).type,'controlFlow.if'), 'MATL:parser', 'MATL error while parsing: ''else'' not associated with ''if''')
assert(~isfield(S(m),'else') || isempty(S(m).else), 'MATL:parser', 'MATL error while parsing: two ''else'' statements found associated to the same ''if''')
S(m).else = n; % associate opening statement with this
S(n).from = m; % associate this with opening statement
pos = pos + 1;
Expand Down Expand Up @@ -248,7 +249,7 @@
assert(isequal(ini,1), 'MATL:parser:internal', 'MATL internal error while parsing comment literal')
pos = pos + fin;
% There's no statement. Just move `pos` forward. Statement count n is not incremented
elseif any(s(pos)==[', ' LF CR]) % do nothing, just consume (but that
elseif any(s(pos)==[' ' LF CR]) % do nothing, just consume (but that
% doesn't mean these characters are useless. They are sometimes needed
% as separators)
pos = pos + 1;
Expand Down
Binary file modified preLit.mat
Binary file not shown.
2 changes: 1 addition & 1 deletion preLit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ Y2
11 'aeiou'
12 'AEIOU'
13 'aeiouAEIOU'
20 ['Mon';'Tue';'Wed'; 'Thu';'Fri';'Sat'; 'Sun']
20 ['Mon';'Tue';'Wed';'Thu';'Fri';'Sat';'Sun']
21 [298 302 288 305 289 296 310]


Expand Down

0 comments on commit 4e0b074

Please sign in to comment.