Procedures able to call other procedures

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

I miss this feature from other Basic. The ability to call a procedure from another procedure would be a godsend so we could re-use code blocks.

At the moment, PureBasic seems not to allow this.

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

You're kidding ? :). The called procedure must be declared BEFORE the actual procedure and it works perfectly.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
You're kidding ? :). The called procedure must be declared BEFORE the actual procedure and it works perfectly.

Fred - AlphaSND
I think either you or I have misinterpreted something here. I have a whole lot of procedures declared and working. When I call them from main program code, they work (obviously).

If I call a procedure from INSIDE another procedure, I always get the error ("It is not a procedure, array or linked list")

Not working. Not kidding. I could do this with PowerBasic.

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wavemaker.

There's no problem with calling a procedure from another procedure. But the CALLED procedure must be declared before the CALLING procedure, and that's all. PureBasic is a one-pass compiler -or that's what it seems-, so it doesn't know about a procedure if it hasn't been declared before. Correct, Fred?

Regards,



Juan Calderón Alonso
Registered user
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wayne1.

;this works fine for me
Procedure Wait()
Delay(2000)
ProcedureReturn
EndProcedure

Procedure PrintSomething()
Print("Something")
For i= 1 To 8
Print(".")
Delay(300)
Next
PrintN("")
EndProcedure

Procedure.w AddTwoNums(first.l,second.l)
temp.l=first+second
ProcedureReturn temp
EndProcedure

Procedure.l OpenTextScreen()
OpenConsole()
PrintSomething();call my procedure
temp.l=AddTwoNums(342,65);call my procedure
PrintN("The two nums = "+Str(temp))
Wait();call my procedure
ProcedureReturn
EndProcedure


;################################################################


OpenTextScreen()





Edited by - wayne1 on 09 November 2001 06:08:38
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
There's no problem with calling a procedure from another procedure. But the CALLED procedure must be declared before the CALLING procedure, and that's all. PureBasic is a one-pass compiler -or that's what it seems-, so it doesn't know about a procedure if it hasn't been declared before. Correct, Fred?

Regards,

Juan Calderón Alonso
Registered user
I see what you mean and Wayne1 illustrated the point (your point) perfectly. However, we must be careful of our terminology here. to DECLARE a routine means to specifically put in a declaration to that routine at the head of any other code, in line with *most* other Basic variants out there.

To use a single pass compiler, a procedure that uses other procedures must be at the bottom of the procedures it calls. That is not a definitive declaration.

To DECLARE a procedure in most basics doesn't require a multipass compiler either. The declarations sit at the top of the compiler stack as an index. Each call to a procedure checks the stack so that procedures and others calling each other can be in any order at all.

Regards.

Fangles
Post Reply