Page 1 of 1

[Implemented] This would allow Procedures more versatile

Posted: Wed Feb 13, 2008 5:20 pm
by Psychophanta
Let me explain with this example:
I have this nice function:

Code: Select all

Procedure BezierCubicLine(PointList.f(2),res.f=0.02)
  Protected t0.f=0.0,t1.f=1.0,bx0.f=PointList(3,0),by0.f=PointList(3,1),bx.f,by.f
  t0.f+res:t1.f-res
  While t1.f>=0
    bx.f=PointList(0,0)*t0*t0*t0+3*PointList(1,0)*t1*t0*t0+3*PointList(2,0)*t1*t1*t0+PointList(3,0)*t1*t1*t1
    by.f=PointList(0,1)*t0*t0*t0+3*PointList(1,1)*t1*t0*t0+3*PointList(2,1)*t1*t1*t0+PointList(3,1)*t1*t1*t1
    LineXY(bx0,by0,bx,by)
    bx0.f=bx:by0.f=by
    t0.f+res:t1.f-res
  Wend
EndProcedure
As you can see, the function gets an array (PointList.f(2)) which is a table containing a total of 4 2D coordenates.
In order to call to that function this can be done:

Code: Select all

Dim Pointsl.f(3,1)
BezierCubicLine(Pointsl.f())
or also

Code: Select all

Dim Pointsl.f(3,1)
BezierCubicLine(@Pointsl.f())
.
The fact is that the array is passed by reference (and the same happens when passing a linked list), i.e. we are indeed passing a pointer.

Well, if i have the table in a DataSection (i.e. pointed by a label) or in general in a '*pointer' variable, then i can not use that function, but another like this:

Code: Select all

Procedure BezierCubicLine(*PointList.f,res.f=0.02)
, which does not allow the array passing.
Making possible the call with any kind of pointer (not just an array or linkedlist pointer), the function is much more versatile.

Posted: Wed Feb 13, 2008 5:41 pm
by Trond

Code: Select all

Procedure BezierCubicLine(*PointList.float,res.f=0.02)
You can pass a one-dimensional array to this code.

Posted: Thu Feb 14, 2008 5:00 pm
by Psychophanta
Trond wrote:

Code: Select all

Procedure BezierCubicLine(*PointList.float,res.f=0.02)
You can pass a one-dimensional array to this code.
Yes, but can not handle it as an array inside the Structure, you see?
The point is to get a data stream and handle it as array (if wanted to work with a random access data stream), or as linked list (if wanted to work with a sequential access data stream).
I really think that it would be a good implementation.

Posted: Thu Feb 14, 2008 7:47 pm
by freak
Both arrays and linkedlists store extra information which is not available when you
pass a simple pointer.
Thats why this is not possible.

Posted: Thu Feb 14, 2008 11:17 pm
by Psychophanta
Ohh! That's a pity,
i thought for a while there was a good reason why it was not already implemented.
Thank you for your clear explanation.