Procedures sequence

Everything else that doesn't fall into one of the other PB categories.
Ivan
User
User
Posts: 25
Joined: Fri Sep 11, 2020 1:53 pm

Procedures sequence

Post by Ivan »

Is there a flag or directive that can be set, so I don't need to have procedures in a specific sequence?

Code: Select all

; procedure sequence not ok
Procedure a()
  Debug "Now in Proc a"
  b()
EndProcedure 

Procedure b()  
  Debug "Now in Proc b"
EndProcedure  

a()

Code: Select all

; procedure sequence ok
Procedure b()  
  Debug "Now in Proc b"
EndProcedure  

Procedure a()
  Debug "Now in Proc a"
  b()
EndProcedure 

a()
User avatar
spikey
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Procedures sequence

Post by spikey »

See the bottom of https://www.purebasic.com/documentation ... dures.html
The parameter list of the declaration must match the implementation if the procedure has parameters.

Code: Select all

Declare a()
Declare b() 

Procedure a()
  Debug "Now in Proc a"
  b()
EndProcedure

Procedure b() 
  Debug "Now in Proc b"
EndProcedure 

a()
Ivan
User
User
Posts: 25
Joined: Fri Sep 11, 2020 1:53 pm

Re: Procedures sequence

Post by Ivan »

@spikey - thanks

I had read in pdf manual about procedures. I skimmed down the paragraph to the "Example: Call a function by its name" and assumed that was a missing end of the procedures paragraph.

But now, I'm thinking a "normal" basic function is replaced by a procedure call by reference or?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Procedures sequence

Post by mk-soft »

Purebasic is a one pass compiler.
So in this case you declare the procedure.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
spikey
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Procedures sequence

Post by spikey »

Ivan wrote:I had read in pdf manual about procedures. I skimmed down the paragraph to the "Example: Call a function by its name" and assumed that was a missing end of the procedures paragraph.
It's easy to miss that's why I specifically mentioned the bottom. The clue is the presence of Syntax in bold. This means a new topic is being introduced, and examples from the previous topic are stopping. Mostly it's one article, one topic but now and again...
Ivan wrote:But now, I'm thinking a "normal" basic function is replaced by a procedure call by reference or?
"Yes" but truthfully no(!)... (if you mean what I think you mean...)
The truth is that there isn't a distintion between "normal basic functions" and "other" functions in the way that you think and there are no "procedure calls not by reference". There are only "entry points to exectuable code" or "not entry points to exectuable code". Either you continue execution sequentially from the current point or you jump to a new entry point or you return from an exit point (or you generate a processor execution error...)

The resolutions that are made are based on where the code for the function originates more than what it is for (approximately - it's not the whole story):
1) Is the function in the source code being compiled now?
2) Is the function in a static library? (this is probably the group you are thinking about)
3) Is the function in a dynamic library provided by the operating system? (The program itself will need to manage this at runtime but setup won't need to distribute it.)
4) Is the function in a dynamic library not provided by the system? (The program itself will need to manage this at runtime and the setup will need to distribute it too.)

(There is another group too, but that's overcomplicating things somewhat for the time being: 5) is the function "somewhere else")

Once the compiler has sorted all this out it creates a new executable which you can start. This then will need to sort out any preparations for function calls in categories 3-5 and then finally can start work...
Ivan
User
User
Posts: 25
Joined: Fri Sep 11, 2020 1:53 pm

Re: Procedures sequence

Post by Ivan »

@mk-soft

In BBCBASIC that I on a dayli basis don't use declarations.

pseudo code:

call procedures in any sequence or procedures call each other in any sequence:
end

def proc_a
endproc

defproc_b
endproc
Ivan
User
User
Posts: 25
Joined: Fri Sep 11, 2020 1:53 pm

Re: Procedures sequence

Post by Ivan »

@spikey

I was thinking of a function eg.

Code: Select all

      result = cubik(lenght, width, height)

      def func cubik(x, y, z)
      return x * y * z
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Procedures sequence

Post by skywalk »

Yes, this is annoying in a modern compiler.
As others mentioned, this is a one pass compiler for speed.

I hate declares, so I just order my code appropriately.
And yet, there are a handful of recursives that demand a declare.
I have like 2 declares in 10 libs and ~100k lines of code.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply