1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
%% Correctly defined arguments block
function y = foo (x)
% Some comment here
% And, maybe, here
arguments
x (1,2) {mustBeReal(x)}
end
y = x*2;
arguments = 1;
y = y + arguments;
end
%% No arguments block, "arguments" is used
% as a variable name (identifier)
% Prevent arguments from folding with an identifier
function y = foo (x)
% Some comment here
x = x + 1;
arguments = 10;
y = x + arguments;
end
% Prevent arguments from folding with a number
function y = foo (x)
4
arguments = 10;
y = x + arguments;
end
% With a double quote string
function y = foo (x)
"test"
arguments = 10;
y = x + arguments;
end
% With a string
function y = foo (x)
'test'
arguments = 10;
y = x + arguments;
end
% With a keyword
function y = foo (x)
if x == 0;
return 0;
end
arguments = 10;
y = x + arguments;
end
% With an operator (illegal syntax)
function y = foo (x)
*
arguments = 10;
y = x + arguments;
end
% Semicolon is equivalent to a comment
function y = foo(x)
;;;;;;;
arguments
x
end
y = x + 2;
end
% Arguments block is illegal in nested functions,
% but lexer should process it anyway
function y = foo (x)
arguments
x (1,2) {mustBeReal(x)}
end
function y = foo (x)
arguments
x (1,2) {mustBeReal(x)}
end
var = 0;
arguments = 5;
y = arguments + x;
end
% Use as a variable, just in case
arguments = 10;
end
% Erroneous use of arguments block
function y = foo(x)
% Some comment
x = x + 1;
arguments
x
end
y = x;
end
% "arguments" is an argument name too
function r = foo(x, arguments)
arguments
x
arguments
end
r = bar(x, arguments{:});
end
% Multiple arguments blocks
function [a, b] = foo(x, y, varargin)
arguments(Input)
x (1,4) {mustBeReal}
y (1,:) {mustBeInteger} = x(2:end);
end
arguments(Input, Repeating)
varargin
end
arguments(Output)
a (1,1) {mustBeReal}
b (1,1) {mustBeNonNegative}
end
var = 10;
arguments = {"now", "it's", "variable"};
[a, b] = bar(x, y, arguments);
end
% One line function with arguments block.
% This code style is rarely used (if at all), but the
% lexer shouldn't break
function y = foo(x); arguments; x; end; y = bar(x); end
|