Meaning of ":="

Hello, I am completely new to Natural and have been poring over as much documentation and code examples as I can to get a better understanding of syntax.

I keep seeing multiple examples of the operator “:=” and am wondering about what exactly this means as opposed to a single “=”? From what I can tell, I just assumed it is shorthand for assignment as opposed to writing out COMPUTE or something else wordy.

What else can “:=” do?

The “becomes” operator ( := ) was introduced as shorthand for the “ASSIGN =” syntax, ASSIGN being a synonym of COMPUTE. Then, at the user community’s request, “becomes” was allowed in combination with a keyword. Now, all five variations are legal:

ASSIGN #A = 'string'
COMPUTE #A = 'string'
#A := 'string'
ASSIGN #A := 'string'
COMPUTE #A := 'string'
1 Like

There’s one difference: You have to use ASSIGN or COMPUTE for the ROUNDED option.
The following code wouldn’t work:

define data local
1 #n2(n5.2)
1 #n5(n5.5) init <123.98765>
end-define
rounded #n2 := #n5
display #n5 #n2
end

Well, I think keyword options are a bit off-topic, but now that you have mentioned them, … :slight_smile:

It was a bit of a surprise to me, but your example ran and produced the correct result under Natural for Windows 9.1.1.

DEFINE DATA LOCAL  
1 #N2(N5.2)
1 #N5(N5.5) INIT <123.98765>  
END-DEFINE  
ROUNDED #N2 := #N5  
DISPLAY #N5 #N2  
END 

Page     1                                                   09/12/19  11:42:31
 
    #N5         #N2
------------ ---------
 
   123.98765    123.99

My personal preference is to always use keywords. I find it easier to skim down the left side of the code to see what’s going on. Random characters (that is, variable names) slow that process.