Function indexing

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
nblackburn
User
User
Posts: 67
Joined: Mon Aug 19, 2013 1:22 am
Location: United Kingdom
Contact:

Function indexing

Post by nblackburn »

Not sure if this will be a popular idea or not but it could work if the language indexes the function names before parsing (so it knows they exist), so that you no longer have to place them in a certain order, thus preventing the error of them not existing.
Image
User avatar
Bisonte
Addict
Addict
Posts: 1308
Joined: Tue Oct 09, 2007 2:15 am

Re: Function indexing

Post by Bisonte »

Declare ?
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
Demivec
Addict
Addict
Posts: 4261
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Function indexing

Post by Demivec »

nblackburn wrote:Not sure if this will be a popular idea or not but it could work if the language indexes the function names before parsing (so it knows they exist), so that you no longer have to place them in a certain order, thus preventing the error of them not existing.
The compiler makes only one pass. This is why the order is important. Bisonte's suggestion is the routine way for the language to deal with procedure's code that appears after they are first called.
User avatar
nblackburn
User
User
Posts: 67
Joined: Mon Aug 19, 2013 1:22 am
Location: United Kingdom
Contact:

Re: Function indexing

Post by nblackburn »

What i mean is if you create a function called Foo() and called it before it was declared in the code then you get an error which most languages have overcome so i was suggesting it for this language as i feel it would be a good idea.

Thanks for the suggestions but could you demonstrate to me how this would be done as I am fairly new to the language.
Image
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Function indexing

Post by LuCiFeR[SD] »

nblackburn wrote:Not sure if this will be a popular idea or not but it could work if the language indexes the function names before parsing (so it knows they exist), so that you no longer have to place them in a certain order, thus preventing the error of them not existing.
what Bisonte and Demivec say is correct. The declare command is what you are after... and already exists.

Example:

Code: Select all

EnableExplicit ; This command is your best friend!!!

; Make sure the declarations match the procedure exactly or you get an error...
;
Declare.i moo() 
Declare.s Baa()
Declare.f Woof()

Woof()
Baa()
moo()




;-Procedures
End
Procedure.i moo()
Debug "moo"
EndProcedure

Procedure.s Baa()
Debug "Baa"
EndProcedure

Procedure.f Woof()
Debug "Woof"
EndProcedure
User avatar
nblackburn
User
User
Posts: 67
Joined: Mon Aug 19, 2013 1:22 am
Location: United Kingdom
Contact:

Re: Function indexing

Post by nblackburn »

Thanks for the example, I would of replied sooner but appear to have had my IP blacklisted as I can't access the website via traditional methods.

I will see if I can get this thread closed as it is not longer relevant.
Image
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Function indexing

Post by LuCiFeR[SD] »

you are welcome :)
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Function indexing

Post by luis »

I realize the norm seem to be to try to code something and see how it goes, to eventually fallback asking in the forum, but
since you are a new user reading once the manual from top to bottom would prove to be extremely useful.
You can then fallback to the forum for what it's still missing or unclear.
help wrote: Syntax
Declare[.<type>] name(<parameter1[.<type>]> [, <parameter2[.<type>]>, ...])

Description

Sometimes a procedure need to call another procedure which isn't declared before its definition. This is annoying because the compiler will complain 'Procedure <name> not found'. Declare can help in this particular case by declaring only the header of the procedure. Nevertheless, the Declare and real Procedure declaration must be identical (including the correct type).
"Have you tried turning it off and on again ?"
A little PureBasic review
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Function indexing

Post by PB »

> Not sure if this will be a popular idea or not

Hi, I know you're new here, but PureBasic has been around for
over 12 years now and just about EVERYTHING has been asked
or discussed before. Almost literally. Including this thread. You
just need to use the forum search function first before posting.

So, as a newbie, you think you've found bugs and come up with
fresh new ideas, but as long-time member I can tell you that's
pretty much always false. That's why in your other post about
the font ID you were told to read the Bug Report FAQ. ;)

I know you're excited to be here, but just do lots of searching
the forums and reading the manual first. All answers are there.

Don't take offense at this post, as that's not my intention.

Welcome to the forums! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
nblackburn
User
User
Posts: 67
Joined: Mon Aug 19, 2013 1:22 am
Location: United Kingdom
Contact:

Re: Function indexing

Post by nblackburn »

Sorry, no offence taken.

I have been browsing the forum and reading the manual like a insane person, I just sometimes can't find what I am looking for as I don't know what I am suppose to be searching for.
Image
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Function indexing

Post by IdeasVacuum »

I just sometimes can't find what I am looking for as I don't know what I am suppose to be searching for.
We have all had that problem at first, and we are all here to help you - PB is not only powerful, it has one of the best forums too. Many of the experts very kindly donate a huge amount of their time here.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply