Page 1 of 1
Function indexing
Posted: Wed Aug 21, 2013 12:15 am
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.
Re: Function indexing
Posted: Wed Aug 21, 2013 12:30 am
by Bisonte
Declare ?
Re: Function indexing
Posted: Wed Aug 21, 2013 12:56 am
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.
Re: Function indexing
Posted: Wed Aug 21, 2013 12:57 am
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.
Re: Function indexing
Posted: Wed Aug 21, 2013 1:00 am
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
Re: Function indexing
Posted: Wed Aug 21, 2013 1:29 am
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.
Re: Function indexing
Posted: Wed Aug 21, 2013 1:33 am
by LuCiFeR[SD]
you are welcome

Re: Function indexing
Posted: Wed Aug 21, 2013 11:38 am
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).
Re: Function indexing
Posted: Wed Aug 21, 2013 12:43 pm
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!

Re: Function indexing
Posted: Fri Aug 23, 2013 10:31 pm
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.
Re: Function indexing
Posted: Sat Aug 24, 2013 12:09 am
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.