Lack in pb manual about Procedures explanation

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Lack in pb manual about Procedures explanation

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Imho, <parameter[.<type>]> =! <parameter[.<structure>]>
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

you're right, but a bit more descriptive explanation wouldn't hurt...
oh... and have a nice day.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Psychophanta wrote:You see?
I guess you got a point there.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply