lexical scoping and namespaces
Ältere Kommentare anzeigen
This code...
function [] = foo()
bar();
baz();
function [] = bar()
a = 1;
end
function [] = baz()
if a
fprintf('Foo!\n');
end
end
end
...gives me this error...
Undefined function or variable 'a'.
Error in foo/baz (line 12)
if a
Error in foo (line 5)
baz();
...but this code...
function [] = foo()
bar();
a;
baz();
function [] = bar()
a = 1;
end
function [] = baz()
if a
fprintf('Foo!\n');
end
end
end
...gives me...
Foo!
Please explain what is going on here. Is there any documentation for this behavior? I would appreciate any documentation which can help me better understand Matlab's lexical scoping rules, and how symbols are imported into certain namespaces.
Thanks.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!