[ncl-talk] Set 10 variables at once to true? - on one line?

Alan Brammer abrammer at albany.edu
Wed May 6 12:20:35 MDT 2015


This will only change variables though, you'd still need the x number of
lines to initially define them. Missed that part of the request.

On 6 May 2015 at 11:14, Alan Brammer <abrammer at albany.edu> wrote:

> I made a quick 3 line procedure that might do what you want.  Utilising
> the list functionality.  No error checks or anything but the simple idea
> could be expanded.
>
>
>
>
> undef("test")
> procedure test(x, val)
> begin
>  print("Setting "+ListCount(x)+" variables to "+val)
>  do i=0, ListCount(x)-1
>   x[i] = val
>  end do
> end
>
>
> begin
>
> a=True
> b=True
> c=True
> d=True
>
> test( [/a,b,c,d/], False)
> print( (/a,b,c,d/) )
>
> end
>
>
>
> Alan.
>
>
> On 6 May 2015 at 09:04, Rick Brownrigg <brownrig at ucar.edu> wrote:
>
>> Hi Erik,
>>
>> No, I don't believe the language supports multi-var assignment in the
>> fashion you are wanting, nor is there an end-of-line delimiter (other than
>> newline).
>>
>> You could of course do something like:
>>
>>    res = new((/ 10 /), logical, True)
>>
>> HTH....
>> Rick
>>
>>
>> On Wed, May 6, 2015 at 8:33 AM, Erik Jan Schaffernicht <
>> eschaffe at uni-koeln.de> wrote:
>>
>>> I use ten resources variables. At the beginning of my script I have to
>>> set them one by one to "true".  That is ten lines of code without much
>>> interesting information.   Is there a better/shorter way to do this?  Eg.
>>> on one line?
>>> It is not only about these, furthermore, I have to define some arrays
>>> later on where I repeat a similar non-informative code as well over several
>>> lines.
>>>
>>> And a separating character to write more than one command per line does
>>> not exist, right?
>>>
>>>
>>> My actual code:
>>> Res1=true
>>> Res2=true
>>> ...
>>> Res10=true
>>>
>>> Looking for sthg like:
>>> [ Res1, Res2, ..., Res10 ] = true
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> 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
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150506/85f78ef0/attachment.html 


More information about the ncl-talk mailing list