Page 1 of 1

Lack in pb manual about Procedures explanation

Posted: Fri Apr 17, 2009 10:06 am
by Psychophanta
Syntax
Procedure[.<type>] name(<parameter1[.<type>]> [, <parameter2[.<type>] [= DefaultValue]>, ...])
...
[ProcedureReturn value]
EndProcedure

Description

A Procedure is a part of code independent from the main code which can have any parameters and it's own variables. In PureBasic, a recurrence is fully supported for the procedures and any procedure can call it itself. At each call of the procedure the variables inside will start with a value of 0 (null). To access main code variables, they have to be shared them by using Shared or Global keywords (see also the Protected and Static keywords).

The last parameters can have a default value (need to be a constant expression), so if these parameters are omitted when the procedure is called, the default value will be used.

Like variables also arrays and linked lists can be passed as parameters to the procedure using the Array or List keyword.

A procedure can return a value or a string if necessary. You have to set the type after Procedure and use the ProcedureReturn keyword at any moment inside the procedure. A call of ProcedureReturn exits immediately the procedure, even when its called inside a loop.
ProcedureReturn can't be used to return an array or a linked list. For this purpose pass the array or the linked list as parameter to the procedure.

If no value is specified for ProcedureReturn, the returned value will be undefined (see inline assembly for more information).

Note: To return strings from DLLs, see DLLs. For advanced programmers ProcedureC is available and will declare the procedure using 'CDecl' instead of 'StandardCall' calling convension.

Selected procedures can be executed asynchronously to the main program by using of threads.
There is not said that this can not be done:

Code: Select all

Structure ier
  a.f
EndStructure
Procedure Th(his.ier) 
EndProcedure 
but it really can not be done.
In other words, in the manual seems not said that input parameters for procedures must be all only in any of the internal native types, pointers, or Array or List.

Posted: Fri Apr 17, 2009 12:24 pm
by gnozal
Imho, <parameter[.<type>]> =! <parameter[.<structure>]>

Posted: Fri Apr 17, 2009 12:26 pm
by Kaeru Gaman
you're right, but a bit more descriptive explanation wouldn't hurt...

Posted: Fri Apr 17, 2009 12:50 pm
by Psychophanta
gnozal wrote:Imho, <parameter[.<type>]> =! <parameter[.<structure>]>
But in that case there are lots of things to correct in the PB manual. For example:
Syntax
Define.<type> [<variable> [= <expression>], <variable> [= <expression>], ...]

Description

If no <variables> are specified, Define is used to change the default type for future untyped variables (including procedure parameters, interface method parameters and data to read with the Read keyword). The initial default type is long (.l). Each variable can have a default value directly assigned to it.

Code: Select all

Structure ier 
  a.f 
EndStructure
Define .ier <- STRUCTURE ????
a\a=34.345
Debug a\a
You see?

EDIT: Besides of that incoherence demonstration, i think there is no doubt a structure name is just an user defined data type, so then when in manual is written "type" there is intended to say any data type: natives and user defined ones.

Posted: Fri Apr 17, 2009 1:18 pm
by gnozal
Psychophanta wrote:You see?
I guess you got a point there.