lexical scoping and namespaces
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Workspace Variables and MAT Files in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!