Previous Thread
Next Thread
Print Thread
Optional DIMX array passing #37511 23 Aug 24 02:15 PM
Joined: Aug 2016
Posts: 371
J
John Andreasen Offline OP
Member
OP Offline
Member
J
Joined: Aug 2016
Posts: 371
Hi,

It appears that currently you cannot pass an unspecified array to another function. It generates a BASIC error. The below program can demonstrate. Could this be supported as it would be handy?

Code
DEFSTRUCT TEST_STRUCT
	MAP2 test$,s,10
ENDSTRUCT

MAIN'ROUTINE:
	CALL fn'test1()
	END

FUNCTION fn'test1(ary()=.NULL as TEST_STRUCT) as f8
	Trace.Print "1: "+.EXTENT(ary())
	.fn = fn'test2(ary()=ary())
ENDFUNCTION

FUNCTION fn'test2(ary()=.NULL as TEST_STRUCT) as f8
	Trace.Print "2: "+.EXTENT(ary())
ENDFUNCTION


Thanks,
John Andreasen
Diversified Data Software

Re: Optional DIMX array passing [Re: John Andreasen] #37513 23 Aug 24 07:03 PM
Joined: Jun 2001
Posts: 11,794
J
Jack McGregor Offline
Member
Offline
Member
J
Joined: Jun 2001
Posts: 11,794
Hmmm... What happens now is that the ary() within fn'test1() acts like a dimx array that has not yet been initialized. But you're not currently allowed to do much of anything with an uninitialized dimx array, besides get the .extent() of it. And the compiler can't tell if an array has been initialized, since it depends on the dimx statement being executed. (It knows the array's type from having seen the dimx statement during compilation, but it can't know if it has been executed.)

The end result in terms of runtime behavior that you're looking for would be something like this:
Code
FUNCTION fn'test1(ary()=.NULL as TEST_STRUCT) as f8
    Trace.Print "1: "+.EXTENT(ary())
    if .extent(ary()) < 0 then
        .fn = fn'test2()
    else
        .fn = fn'test2(ary()=ary())
    endif
ENDFUNCTION

So maybe the solution is to have the runtime system detect the attempt to pass the uninitialized array and just remove the parameter entirely from the calling parameter list (logically equivalent to the example above) but integrated into the call directly.

No matter what it's going to require an update, but I'm not completely sure whether it can be just a runtime update or a compiler update. One possible concern is that if the called function doesn't declare a default value for the received array and instead uses .argcnt to determine whether the argument was passed, then having the runtime system automatically remove the passed parameter in the case of an uninitialized array might lead to further confusion. The issue is probably moot here since currently the attempt to pass the uninitialized array will generate an error immediately, before the called function would have a chance to use .argcnt, but I'm not sure I've thought through all the permutations. Let me ponder it a bit.

Re: Optional DIMX array passing [Re: John Andreasen] #37514 24 Aug 24 05:25 AM
Joined: Aug 2016
Posts: 371
J
John Andreasen Offline OP
Member
OP Offline
Member
J
Joined: Aug 2016
Posts: 371
OK, thank you Jack

Re: Optional DIMX array passing [Re: John Andreasen] #37521 26 Aug 24 03:25 PM
Joined: Jun 2001
Posts: 11,794
J
Jack McGregor Offline
Member
Offline
Member
J
Joined: Jun 2001
Posts: 11,794
I think this is supported now in 7.0.1762.0 if you want to test it ...

ash-7.0.1762.0-el7-upd.tz
ash70notes.txt

Note that it's purely a runtime adjustment, so no recompilation should be necessary.

Re: Optional DIMX array passing [Re: John Andreasen] #37524 26 Aug 24 05:42 PM
Joined: Jun 2001
Posts: 11,794
J
Jack McGregor Offline
Member
Offline
Member
J
Joined: Jun 2001
Posts: 11,794
Warning: I just ran into a segmentation fault in during some collection-related testing. So I suspect there is going to be another update of this soon.

Re: Optional DIMX array passing [Re: John Andreasen] #37527 26 Aug 24 07:10 PM
Joined: Jun 2001
Posts: 11,794
J
Jack McGregor Offline
Member
Offline
Member
J
Joined: Jun 2001
Posts: 11,794
Ok, 7.0.1762.0 has been recalled and replaced by 1762.1 ...

ash-7.0.1762.1-el7-upd.tz
ash70notes.txt


Moderated by  Jack McGregor, Ty Griffin 

Powered by UBB.threads™ PHP Forum Software 7.7.3