It is currently Tue Dec 01, 2020 9:21 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Procedures sequence
PostPosted: Mon Sep 14, 2020 10:10 am 
Offline
User
User

Joined: Fri Sep 11, 2020 1:53 pm
Posts: 25
Is there a flag or directive that can be set, so I don't need to have procedures in a specific sequence?

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

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

a()


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

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

a()


Top
 Profile  
Reply with quote  
 Post subject: Re: Procedures sequence
PostPosted: Mon Sep 14, 2020 12:21 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:17 pm
Posts: 355
Location: United Kingdom
See the bottom of https://www.purebasic.com/documentation/reference/procedures.html
The parameter list of the declaration must match the implementation if the procedure has parameters.
Code:
Declare a()
Declare b()

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

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

a()


Top
 Profile  
Reply with quote  
 Post subject: Re: Procedures sequence
PostPosted: Mon Sep 14, 2020 1:50 pm 
Offline
User
User

Joined: Fri Sep 11, 2020 1:53 pm
Posts: 25
@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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Procedures sequence
PostPosted: Mon Sep 14, 2020 2:28 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2730
Location: Germany
Purebasic is a one pass compiler.
So in this case you declare the procedure.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Procedures sequence
PostPosted: Mon Sep 14, 2020 5:15 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 22, 2010 1:17 pm
Posts: 355
Location: United Kingdom
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...


Top
 Profile  
Reply with quote  
 Post subject: Re: Procedures sequence
PostPosted: Mon Sep 14, 2020 8:00 pm 
Offline
User
User

Joined: Fri Sep 11, 2020 1:53 pm
Posts: 25
@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


Top
 Profile  
Reply with quote  
 Post subject: Re: Procedures sequence
PostPosted: Mon Sep 14, 2020 8:30 pm 
Offline
User
User

Joined: Fri Sep 11, 2020 1:53 pm
Posts: 25
@spikey

I was thinking of a function eg.

Code:
      result = cubik(lenght, width, height)

      def func cubik(x, y, z)
      return x * y * z


Top
 Profile  
Reply with quote  
 Post subject: Re: Procedures sequence
PostPosted: Mon Sep 14, 2020 9:13 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3347
Location: Boston, MA
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye