RedefineMacro

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

RedefineMacro

Post by Josh »

In some cases it would be helpful if we could disable a macro at short notice. See the following example:

Code: Select all

Macro ComputerName
  MyComputerName
EndMacro

Procedure.s MyComputerName()
  ;.....................
  ;.....................
  CompilerIf #PB_Compiler_Debugger
    ProcedureReturn "Harrys Computer"
  CompilerElse
    UndefineMacro ComputerName
      ProcedureReturn ComputerName()
    ;RedefineMacro ComputerName
  CompilerEndIf
  ;.....................
  ;.....................
EndProcedure

MessageRequester ("", ComputerName())
Ok, rather than RedefineMacro you could rebuild the macro, but it's not very smart and the errors are pre-programmed with every change.

After UndefineMacro, there would be two possibilities:
- Create a completely new Macros (like now)
- Reactivate the old macro with RedefineMacro.
Last edited by Josh on Tue Dec 20, 2016 6:35 am, edited 1 time in total.
sorry for my bad english
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: RedefineMacro

Post by Mistrel »

Your request is very confusing; as is your example. I would highly recommend rethinking your course of logic.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: RedefineMacro

Post by Josh »

Mistrel wrote:Your request is very confusing; as is your example. I would highly recommend rethinking your course of logic.
Of course you are right, the first three lines have unfortunately been duplicated somehow. Otherwise, the example should be clear and I think that the one it affects has understood what it is all about.

I would strongly recommend that you consider your way here in the forum, that you always have to comment on everything, whether you understood what it is or not, no matter if you have something to contribute or not.
sorry for my bad english
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: RedefineMacro

Post by normeus »

@josh,
go back and edit your post. Delete first, second and third line so that it will not be confusing.
then you could do something like

Code: Select all

  CompilerIf #PB_Compiler_Debugger
    Macro ComputerName
  "JOSH"
EndMacro
  CompilerElse
    Macro ComputerName
  "FINDIT"
EndMacro
CompilerEndIf


Procedure.s findComputerName()
  If ComputerName = "FINDIT"
    Debug "LENGTHY PROCEDURE TO FIND NAME"
  Debug ComputerName 
Else
  Debug ComputerName
EndIf

EndProcedure

findComputerName()


You are requesting a change in the way the compiler works. I am just giving you a workaround until your change is implemented.
People are not trying to be rude.... it is google translate who is at fault here!

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: RedefineMacro

Post by Josh »

Hello normeus,

first of all, thank you for your mediation. Although I do not like it normally, if a answered post is changed, I have removed the lines as recommended by you.

There are always several ways to reach the same goal. Your code suggestion is from a completely different approach, but it is a quite usual method to override certain functions by macro and this would simplify by my suggestion in some cases the code.

As I wished many years ago undefineMacro, no one has screamed, we need, rather the opposite. For some years now we have this feature now and when I google to 'Purebasic undefineMacro', then I suddenly get 452 results, although at that time apparently nobody found it useful.
sorry for my bad english
Post Reply