Obfuscated Natural ...

Hello all,

just for fun. Please complete the following Natural code by writing the data definition:

define data local
... 
end-define
for for eq to to step step to
write edited (EM=-ZZ9) to step
end-for
end

The Output of the program is:


Page      1                                                  13-09-19  16:22:26
   1    1    2
   2    1    2


More

:wink:

DEFINE DATA LOCAL
1 FOR (N3)
1 REDEFINE FOR
  2 EDITED (N3)
1 TO (N3) CONST<1>
1 STEP (N3) CONST<2>
END-DEFINE

Funny when you STRUCT itā€¦

0010 	DEFINE DATA LOCAL                       
0020 	1 FOR (N3)                              
0030 	1 REDEFINE FOR                          
0040 	  2 EDITED (N3)                         
0050 	1 TO (N3) CONST<1>                      
0060 	1 STEP (N3) CONST<2>                    
0070 	END-DEFINE                              
0080 	*                                       
0090 	FOR FOR EQ TO TO STEP STEP TO           
0100 	    WRITE EDITED (EM=-ZZ9) TO STEP      
0110 	  END-FOR                               
0120 	END                                     

Runtime:

MORE 	                                                                          
Page 	     1 	                                                 	13-09-19  12:11:52
                                                                               
   1 	   1 	   2 	                                                                
   2 	   1 	   2 	                                                                
                                                                               

That was strangely fun. Glad I didnā€™t notice Brian beat me to the answer else I probably wouldnā€™t have worked at figuring it out. I failed to look at the spaces between columns. I think Brianā€™s N3s are more accurate than my I4s would have been, though Brianā€™s output seems to suggest his runtime results were not using the N3. I found the same struct problem on v6.3.12 on HP UX .

DEFINE DATA LOCAL       
1 TO       (I4) INIT <1>
1 STEP     (I4) INIT <2>
1 FOR      (I4)         
1 REDEFINE FOR          
  2 EDITED (I4)         
END-DEFINE              

Obviously you can gain even more obfuscation using struct :wink:

How about this one:

define data local
01 for (I1)
01 redefine for
  02 edited(I1)
01 to  (I1) init <1>
01 step(I1) init <2>
end-define
for
  for eq to to step step to write edited (EM=-ZZ9) to step
  end-for
end

This is why KCHECK=ON should be the default setting in NatParms. Of course you still would have to look for overrides (during code walkthroughs) to stop programmers from cheating.

OPTIONS KCHECK=OFF
DEFINE DATA LOCAL  
1 FOR (I1)      1 REDEFINE FOR
  2 EDITED (I1)
1 TO (I1) INIT <1>
1 STEP (I1) INIT <2>
END-DEFINE
FOR
  FOR EQ TO TO STEP STEP TO WRITE EDITED (EM=-ZZ9) TO STEP
END-FOR
END

PCHECK is another interesting parameter. But we got some trouble with catall with this both parameters set to ON. Natural crashes with coredump.

It is planned to upgarde to the latest natural version the next few months. Letā€™s seeā€¦

Hi Matthias,
I suspect that after your post (and upgrading to the latest Natural release :slight_smile: you will read something like this from the Natural documentation:

ā€œHere is a list of keywords in the Natural programming language. You cannot use any of the following as identifiers in your programs: ā€¦ā€ :slight_smile:

The weird thing is that the compiler Nat 4.2.6 on zOS at least will catch some things but not others. Your example stowed fine for me - I even called the program PROGRAM - and this example also works


DEFINE DATA LOCAL         
1 EQ (A2)                 
1 THEN (A2) INIT <'IF'>   
END-DEFINE                
INPUT EQ                  
IF THEN EQ EQ             
  WRITE '='               
END-IF                    
END                       

but each part of this one fails - as you cannot INPUT INPUT or WRITE WRITE let alone IF IF


INPUT INPUT            
IF IF EQ EQ            
  WRITE WRITE          

Or how about these few statements which will also compile and execute provided you have the data areas to match


MOVE MOVE TO TO                                                   
EXAMINE EXAMINE FOR GIVING GIVING POSITION POSITION
DIVIDE SUBTRACT INTO ADD REMAINDER MULTIPLY                   

Maybe SAG should start a competion to see who can code the weirdest application of unintelligible code that actually runs

Sorry, this is ā€œthe serious partā€ which Iā€™ve missed in my previous message.
Well, it is still optional ((KCHECK) Keyword checking ā€¦ OFF) ā€œfeatureā€ of our Natural 8.2.2.3. If it were within my power, I think Iā€™d rather removed this altogether - what`s the reason to keep it ā€œoptionalā€? The good program should be simple and clear

I understand the need for having options because there could be issues if existing code breaks. I would tighten enforcement up in development but leave it open in production until I was sure the bad code was fixed.

Weā€™re on Natural 4.2.7 so this is something I will need to handle the next upgrade.

In the meantime, this challenge was fun!

Canā€™t disagree less with Brian: the challenge was VERY fun! :slight_smile: Many thanks to Matthias indeed

Every programming language has strange syntax and naming conventions. Personally, I think reserved words should never be permitted as variable names. However, as Brian noted, this could cause problems when new reserved words might be added to the language and existing programs suddenly fail.

Here is one of my favorite Natural Syntax anomalies: (use SAGā€™s employees demo file)

DEFINE DATA LOCAL
1 MYVIEW VIEW OF EMPLOYEES
2 NAME
2 FIRST-NAME
2 CITY
2 COUNTRY
END-DEFINE
*
READ MYVIEW BY NAME FIRST-NAME CITY
DISPLAY COUNTER NAME FIRST-NAME CITY
END-READ
*
** WRITE T
NAME NAME FIRST-NAME CITY / T*CITY ā€˜LOOK AT THE VALUE OF CITYā€™
*
END

Questions:

  1. Will this program Check?

  2. Will it Run?

  3. If it runs, what will it be doing?

  4. If it runs, explain the output.

  5. If it runs, why does the output end where it does?

  6. If stuck on last question, uncomment the WRITE statement and re-run.

enjoy.

  1. Yes, it checks.
  2. Yes, it runs.
  3. I would expect the following: Display all Employees with empty NAME since the fields in the from-to-clause (i.e. first-name and city) are empty at the beginning.
  4. We got no employees file at our test systemā€¦ :frowning: Let me see what I can do.

We only got the SAGTOURS-File on our test Databaseā€¦

BTW: NAME is a reserved keyword.

Hi Matthias;

Answers 1) and 2) are, of course correct. That was the real objective of the example, to point out that the words ā€œstarting fromā€ and ā€œtoā€ are unnecessary. This can be very confusing. Some people look at the statement and think that they can read logical by three fields.

However, you really need a file to properly answer the rest of the questions. There are no records with blank names; but, there is quite a bit of output.

Do you have an old Personnel file around?

Or do you have Natural on the PC, which has the same employees file?

steve

I got Natural+Adabas@Solaris with SAG-TOURS-File.
I also got Natural@Win. Thereā€™s the employee DDM but no ADABAS.

How about posting the output here?

http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat6314win/pg/pg_keyw.htm#pg_keyw

Does anyone know of a link to a list of currently and actually reserved keywords.