Compiler command "Forget()"

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Compiler command "Forget()"

Post by jassing »

Similar to define, in that it checks for "something"
ie:

Code: Select all

CompilerIf Defined(MyProc,#pb_Procedure)
Forget would allow us to handle collisions with external libraries.
ie: Droppy lib has RegDeleteKey(); but let's say we've got one we're using.
Rather than changing all instances of our function, or removing droopy; we could issue:

Code: Select all

Forget(RegDeleteKey,#pb_procedure)
this would tell the compiler to ignore any pre existing definitions of RegDeleteKey(); so if we had droopy lib; you could do:

Code: Select all

Forget(RegDeleteKey,#pb_procedure)
procedure RegDeleteKey()
...
and then the compiler would use our definition of RegDeleteKey instead of the one the compiler already knows about.

I used droopy as an example, as it seems popular; I wrote a bunch of code that when I handed it over; they sent it back with requests to change a few (internal to my block) function names as they collide with the pre-existing programs functions.

A variation on it, might be similar to a module:

Code: Select all

 ; fnShowWindow() is already defined or it may be defined 'later' but for our block of code, we also have it, so:
SetLocal() ; Compiler directive to keep the following code as it's own universe
global hWnd
procedure fnShowWIndow()
endprocedure
EndLocal() ; Compiler directive to end the 'local definitions'
In that context, our hwnd and fnshowwindow would not collide with any pre-existing objects or any objects defined later in the program.

Part of this is thinking outloud about other ways to handle the same basic concept...
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Compiler command "Forget()"

Post by IdeasVacuum »

Not sure, sounds as dangerous as the issue it would fix..........
To use it, you would need to know there is a clash? - and if you do know, then a Procedure name change is a simple find/replace........
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Compiler command "Forget()"

Post by c4s »

If you don't want to alter your code you can easily do this with macros:

Code: Select all

Procedure ProcOld()
	Debug "ProcOld"
EndProcedure

Procedure ProcNew()
	Debug "ProcNew"
EndProcedure


;Macro ProcOld()
;  ProcNew()
;EndMacro

ProcOld()  ; Prints "ProcOld", uncomment above macro for "ProcNew"
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Compiler command "Forget()"

Post by jassing »

c4s wrote:If you don't want to alter your code you can easily do this with macros:
I tried that; macro didn't alter the existence of a function w/in a userlib
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Compiler command "Forget()"

Post by PB »

If the compiler is told to forget a procedure, then
what happens when it finds that same procedure
again later in the code? How will it know if it's from
the lib or your replacement procedure?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Compiler command "Forget()"

Post by PMV »

This Feature would be much more dangerous and confusing as what
we have discussed for a view days with moduls:
http://www.purebasic.fr/english/viewtop ... =3&t=56574

MFG PMV
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Compiler command "Forget()"

Post by BorisTheOld »

@jassing

Just rename your procedures. That's what the rest of the world does.

I suggest you prefix your procedure names with "jassing_". I doubt other people would be doing the same.

And if you run into naming problems in the future --- just rename your procedures.

We use prefixes of the form: dvsnnnnn_

dvs = the initials of my company name
nnnnn = the reference number of the module in our Data Dictionary database
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Post Reply