Re: scope of variable in NCL

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Fri Oct 16 2009 - 04:14:18 MDT

Hi Saji,
In fact this is exactly the documented behavior of NCL. A variable
that is not explicitly local can refer to a variable defined with
within the containing scope. The solution is to use the 'local'
statement for all variables intended to be local to the function or
procedure. See this section of the reference manual for a complete
description of the behavior:

http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml#Scoping

-dave

On Oct 15, 2009, at 10:59 PM, Saji N Hameed wrote:

> Dear NCL Developers,
>
> I suppose that the following should not happen. Isn't it a bug?
> We are told that variables inside a function have local scope, and
> this unusual feature can lead to a lot of headaches. Any solutions,
> other than "local a" or using another variable name than "a"
>
> Copyright (C) 1995-2009 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 5.1.1
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> ncl 0> a=5
> ncl 1> function testme(a,b,c)
> ncl 2> begin
> ncl 3> a=2
> ncl 4> return(1)
> ncl 5> end
> ncl 6> print(""+a)
> (0) 5
> ncl 7> print(""+testme(a,1,2))
> (0) 1
> ncl 8> print(""+a)
> (0) 2
>
> Thanks,
> saji
> --
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri, 16 Oct 2009 04:14:18 -0600

This archive was generated by hypermail 2.1.8 : Thu Oct 22 2009 - 12:22:52 MDT