Are include file named parameters positional?

Posted by jmartin104 on 21-Feb-2020 19:19

For the code below, I expected the named parameter to be compiled in the named position. However, it did not, leading me to believe include parameters are positional only. Is this the case?

Test.p

{test-1.i &buffer=buffer}   // no &copy

test-1.i

{test-2.i &copy={&copy} &buffer={&buffer}} <-- Skips buffer, putting buffer in copy instead

test-2.i

message "Buffer" "{&buffer}" "Copy" "{&copy}" view-as alert-box.

All Replies

Posted by Alex Herbstritt on 21-Feb-2020 19:40

I am not seeing it. When I compile and run on 12.2 it generates the expected output:

Buffer buffer Copy copy

Adding additional messages in test.p, test-1.i, and test-2.i shows that the include parameters are as expected.

Posted by jmartin104 on 21-Feb-2020 19:55

I made a slight change to test-1.i. Although, it had the same result with my version (11.5). Odd.

Posted by frank.meulblok on 24-Feb-2020 08:29

In 11.7.5 the message I see is "Buffer Copy &buffer=buffer".

Adding a " &GLOBAL-DEFINE copy . " to the top of test.p gives a more expected "Buffer buffer Copy ."

Seems the preprocessor messes up when you try to pass an undefined preprocessor into a named argument, and treats the next token as the value to be passed in.

Posted by jmartin104 on 25-Feb-2020 16:31

Kind of throws a monkey wrench into what I'm trying to do. I would love to know if this is by design.

Posted by James Palmer on 26-Feb-2020 10:00

Maybe if you could explain what you are trying to do, someone might be able to help with a better solution. 

Posted by jmartin104 on 26-Feb-2020 12:25

James, I am working with legacy code. And the example is pretty much that. I have a dataset include that contains a temp-table include that needs to be compiled passing named arguments - to add flexibility.

Posted by Marco Aurelio on 26-Feb-2020 12:46

hi,

  what happens if you change a little

{test-2.i &copy2={&copy} &buffer2={&buffer}} <-- Skips buffer, putting buffer in copy instead

test-2.i

message "Buffer" "{&buffer2}" "Copy" "{&copy2}" view-as alert-box.

Posted by ChUIMonster on 26-Feb-2020 13:13

To answer the titular question...  No.  You can have either named or positional arguments but named arguments are not secretly positional.

It has been several decades since I did much with named arguments to include files but I do recall that being very careful about quoting strings properly at each level of a multi-level chain of includes was always very tricky.  And thinking about what is needed (or not needed) for quoting at each level gets messy too.

I tested your example back to 10.2B and it behaves the same so your issue does not seem to be a newly broken sort of thing.  I think it is more of a misunderstanding regarding how an undefined argument value, the first reference to {&copy}, gets handled or possibly just how the tokens are parsed.  You might find this subtle (note the extra spaces around "=") variation interesting to consider:

/* test.p  

*/

{test-1.i &buffer = buffer}

quit.

====

/* test-1.i

*/

{test-2.i &copy = {&copy} &buffer = {&buffer}}

====

/* test-2.i

*/

message "Buffer" "{&buffer}" "Copy" "{&copy}" view-as alert-box.

If it is legacy code then there are probably lots of existing examples of the particular thing that you are trying to do.  And if there are not then it seems like this would be an excellent opportunity to introduce a better way of doing things.

This thread is closed