Page 2 of 2
Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 2:20 pm
by Psychophanta
This is still a big but fixable issue:
Compiler is not able to differenciate external variables neither constants from a macro local ones.
I suggested a way to fix it:
Make obligatory the '#' postfix for Macro input params
Will you fix it?
Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 3:02 pm
by Little John
Psychophanta wrote:I suggested a way to fix it:
Make obligatory the '#' postfix for Macro input params
That's no good idea, and it has been told you years ago.
Psychophanta wrote:Will you fix it?
It seems that you really like to beat dead horses ...
Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 3:51 pm
by Psychophanta
Little John wrote:
That's no good idea, and it has been told you years ago.
Sorry to have to correct that:
The only things has been told are workarounds to solve it, but not a solution to differenciate external variables and the input parameters inside a macro.
Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 4:26 pm
by Little John
Psychophanta wrote:Sorry to have to correct that:
There's no need to discuss that further: Everyone who is interested can read her/himself what has been written in this thread more than 6-7 years ago.
Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 5:04 pm
by Psychophanta
Little John wrote:Psychophanta wrote:Sorry to have to correct that:
There's no need to discuss that further: Everyone who is interested can read her/himself what has been written in this thread more than 6-7 years ago.
Agree, but repeat with the fact, and don't try to escape from reality, just like german people is in use to do again and again:
no solution to differenciate external variable names from input parameters names for macros.

Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 8:58 pm
by Demivec
Psychophanta wrote:...no solution to differenciate external variable names from input parameters names for macros.

Use a different name.

Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 9:40 pm
by Tenaja
Demivec wrote:Psychophanta wrote:...no solution to differenciate external variable names from input parameters names for macros.

Use a different name.

Exactly. There is no confusion with this:
Code: Select all
Define .f
v=1.0
Macro ma(Macro_ma_Parameter_v=2.0)
Debug Pow(Macro_ma_Parameter_v,v)
EndMacro
ma()

<---note: indicates friendly sarcasm towards both Psycho's request and Demivec's suggestion.
IMO, the compiler should parse variable names with precedence from inside out. That is, automatically search the scope starting with the most recent construct. So, any v references should be forced to be the macro parameter v if you are within a macro, and local v if within a procedure, and last, the global var. This would make all other references to v essentially invisible if you are doubling-up on your variable name use. (I have not tested to see if PB does this or not.)
I know this does not help find frustrating bugs within large code, but neither does repetitive re-use of variable names.
...and yes, I see the value within the request, as well. I think it would be handy, and would certainly give it a +1 regardless of how "ugly" it is. However, I just work around it as Demivec suggests.
Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 9:47 pm
by Tenaja
Demivec wrote:Use a different name.

A simple technique is to habitually prefix an underscore (or "InsertYourFavoritePrefixHere") to all macro parms:
Code: Select all
Define .f
v=1.0
Macro ma(_v=2.0)
Debug Pow(_v,v)
EndMacro
ma()
Re: Make obligatory the '#' postfix for Macro input params
Posted: Wed Apr 29, 2015 10:24 pm
by Little John
Psychophanta wrote:don't try to escape from reality, just like german people is in use to do again and again:
You really made my day.

I'm so sorry that I can't confirm your prejudices.
You better shouldn't project your character onto others.
Psychophanta wrote:no solution to differenciate external variable names from input parameters names for macros.
Huh, really? Oh what a
big problem!
Tenaja wrote:Demivec wrote:Use a different name.

A simple technique is to habitually prefix an underscore (or "InsertYourFavoritePrefixHere") to all macro parms:
I've suggested the same thing to him more than 6 years ago.
This is probably too far away from his ... erm ... "reality".

Re: Make obligatory the '#' postfix for Macro input params
Posted: Thu Apr 30, 2015 11:04 am
by Psychophanta
No matters if big or small problem Litle John, just a problem.
A problem which a good and elegant compiler like PB is, should solve.
Thanks!
Re: Make obligatory the '#' postfix for Macro input params
Posted: Thu Apr 30, 2015 6:19 pm
by Little John
Psychophanta wrote:A problem which a good and elegant compiler like PB is, should solve.
You did actually not understand the replies that you got 6-7 years ago, among others from Fred and Freak.
Sorry, I can't help you.
Re: Make obligatory the '#' postfix for Macro input params
Posted: Thu Apr 30, 2015 7:35 pm
by Psychophanta
Little John wrote:Psychophanta wrote:A problem which a good and elegant compiler like PB is, should solve.
You did actually not understand the replies that you got 6-7 years ago, among others from Fred and Freak.
Sorry, I can't help you.
Mmm... allow me to remember....
Yes.
Just look:
freak wrote:You are the only one i have seen putting a # behind every macro parameter.
I think it is a very weird thing to do (as the # is the concatination operator for macros, not a parameter postfix)
I don't think this is a good idea.
Never mind if i are the only one who do that (I am not really), it is irrelevant.
very weird thing to do?
Not good idea, well, I think it is not.
Fred wrote:It's way too ugly ! Don't mess with global var in your macro..
ugly ! ¿?
Fred wrote:# is already used in the macros to join 2 parameters together.
We know it, thanks for remember it anyway.
freak wrote:I don't see the problem really. It is just like with procedures.
In procedures, if you reuse a global variable (not as a parameter and without protected),
you are referencing the global variable. Same thing happens with macros.
In a procedure, if you reuse the global variable name inside a procedure as a parameter
or with protected, it will not use the global one, and you have actually no more a way
to access the global variable from inside this procedure (as the name represents the local variable then)
The same thing is with macro parameters that have the same name as a variable used elsewhere. makes perfect sense.
You always have to make sure you do not reuse the same name for different purposes.
That is a problem that exists in every language, not just in PB macros.
You can't just name all your global variables "var" and expect to get no conflict.
Choosing descriptive names solves this problem easily.
Yeah, just like procedures. Makes perfect sense... o_o :
Code: Select all
Structure stru
var1.f
var2.l
EndStructure
Global v.stru
v\var2=4
var2.l=5
Procedure ma(var2=6)
Debug v.stru\var2
EndProcedure
ma()
and:
Code: Select all
Structure stru
var1.f
var2.l
EndStructure
Global v.stru
v\var2=4
var2.l=5
Macro ma(var2=6)
Debug v.stru\var2
EndMacro
ma()
Patience....
EDIT:
NOTICE: I don't say to use '#' as postfix if for you is ugly, ok, right, but just suggest to improve another good idea from your part to avoid this issue.
Re: Make obligatory the '#' postfix for Macro input params
Posted: Thu Dec 14, 2017 12:18 am
by Psychophanta
About 4 hours with a powerful pain in brain because of this topic.
Finally I got to isolate the problem, and here it is:
Look at this one:
Code: Select all
#Colorhilo2=$AAEE90
Global .f a=12,b=12,c=11,e=3
Global fasehilo1.u=0,fasehilo2.u
Macro seno(f=0,desv=0)
Sin(f#+e*x/c)
EndMacro
Macro dibuja2(h,c)
For x.u=0 To 2
y.f = Sin(fasehilo#h#+e*x/c)
Debug y
y.f = seno(fasehilo#h#)
Debug y
Debug "-----------------"
Next
EndMacro
dibuja2(2,#Colorhilo2)
Re: Make obligatory the '#' postfix for Macro input params
Posted: Mon Jan 01, 2018 6:28 pm
by BorisTheOld
@Psychophanta
You might save yourself a lot time and trouble if you didn't use single-letter parameters, constants, and variables. Here are a few of our macros that might show you a better way of organizing your code.
Rod
Code: Select all
;-----------------------------------------------
;
; Macro 1 : QQ double quote character used in macro creation
;
;
Macro QQ
"
EndMacro
;
;-----------------------------------------------
;
; Macro 2 : QQColon colon character used in macro creation
;
;
Macro QQColon
:
EndMacro
;
;-----------------------------------------------
;
; Macro 3 : QQJoin join parameter strings for macro creation
;
; bvsP1 16725 : PB macro parameter: 1
; bvsP2 16726 : PB macro parameter: 2
; bvsP3 16727 : PB macro parameter: 3
; bvsP4 16728 : PB macro parameter: 4
; bvsP5 16729 : PB macro parameter: 5
; bvsP6 16730 : PB macro parameter: 6
; bvsP7 16731 : PB macro parameter: 7
; bvsP8 16732 : PB macro parameter: 8
;
Macro QQJoin (bvsP1, bvsP2=, bvsP3=, bvsP4=, bvsP5=, bvsP6=, bvsP7=, bvsP8=)
bvsP1#bvsP2#bvsP3#bvsP4#bvsP5#bvsP6#bvsP7#bvsP8
EndMacro
;
;-----------------------------------------------
;
; Macro 4 : CreateBlockName create the QQBlock macro
;
; bvsBlockName 16663 : the name of a class or module
;
Macro CreateBlockName (bvsBlockName)
QQJoin (Macro QQBlock, QQColon, bvsBlockName, QQColon, EndMacro)
EndMacro
;
;-----------------------------------------------
;
; Macro 5 : DestroyBlockName destroy the QQBlock macro
;
;
Macro DestroyBlockName
QQJoin (UndefineMacro Q, QBlock)
EndMacro
;
;-----------------------------------------------
;
; Macro 6 : CreateLibraryName create the QQLib macro
;
; bvsLibName 16505 : the name of a dynamic library
;
Macro CreateLibraryName (bvsLibName)
QQJoin (Macro QQLib, QQColon, bvsLibName, QQColon, EndMacro)
EndMacro
;
;-----------------------------------------------
;
; Macro 7 : DestroyLibraryName destroy the QQLib macro
;
;
Macro DestroyLibraryName
QQJoin (UndefineMacro Q, QLib)
EndMacro
;
;-----------------------------------------------
;
; Macro 8 : AttachDynamicLibrary attach a dynamic library to the program
;
; bvsLibName 16505 : the name of a dynamic library
;
Macro AttachDynamicLibrary (bvsLibName)
Global lib#bvsLibName.typInt32
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
lib#bvsLibName = OpenLibrary(#PB_Any, QQ./lib#bvsLibName.so#QQ)
If IsFalse(lib#bvsLibName)
MessageRequester("Critical Error", QQ#Dynamic Library not found -- lib#bvsLibName.so#QQ, #PB_MessageRequester_Ok)
End
EndIf
CompilerCase #PB_OS_Windows
lib#bvsLibName = OpenLibrary(#PB_Any, QQ#bvsLibName.dll#QQ)
If IsFalse(lib#bvsLibName)
MessageRequester("Critical Error", QQ#Dynamic Library not found -- bvsLibName.dll#QQ, #PB_MessageRequester_Ok)
End
EndIf
CompilerCase #PB_OS_MacOS
????
CompilerCase #PB_OS_AmigaOS
????
CompilerEndSelect
EndMacro
;
;-----------------------------------------------
;
; Macro 9 : DetachDynamicLibrary detach a dynamic library from the program
;
; bvsLibName 16505 : the name of a dynamic library
;
Macro DetachDynamicLibrary (bvsLibName)
CloseLibrary(lib#bvsLibName)
EndMacro
;
;-----------------------------------------------
;
; Macro 10 : BeginLibraryDeclare link the program to dynamic library procedures
;
; bvsLibName 16505 : the name of a dynamic library
;
Macro BeginLibraryDeclare (bvsLibName)
CreateLibraryName(bvsLibName)
EndMacro
;
;-----------------------------------------------
;
; Macro 11 : EndLibraryDeclare end declares for a dynamic library
;
;
Macro EndLibraryDeclare
DestroyLibraryName
EndMacro
;
;-----------------------------------------------
;
; Macro 12 : FunctionPrototype dynamic library prototype: function
;
; bvsProcName 15157 : name of the proc being generated
; bvsDataParmType 15080 : parameter data type
;
Macro FunctionPrototype (bvsProcName, bvsDataParmType)
Prototype.bvsDataParmType QQLib#bvsProcName
EndMacro
;
;-----------------------------------------------
;
; Macro 13 : SubroutinePrototype dynamic library prototype: subroutine
;
; bvsProcName 15157 : name of the proc being generated
;
Macro SubroutinePrototype (bvsProcName)
Prototype QQLib#bvsProcName
EndMacro
;
;-----------------------------------------------
;
; Macro 14 : CreateFunctionReference create a reference to a library function
;
; bvsProcName 15157 : name of the proc being generated
;
Macro CreateFunctionReference (bvsProcName)
Global lib#QQLib#_fun#bvsProcName.QQLib#bvsProcName = GetFunction(lib#QQLib, QQ#QQLib#bvsProcName#QQ)
EndMacro
;
;-----------------------------------------------
;
; Macro 15 : CreateSubroutineReference create a reference to a library subroutine
;
; bvsProcName 15157 : name of the proc being generated
;
Macro CreateSubroutineReference (bvsProcName)
Global lib#QQLib#_sub#bvsProcName.QQLib#bvsProcName = GetFunction(lib#QQLib, QQ#QQLib#bvsProcName#QQ)
EndMacro
;
;-----------------------------------------------
;
; Macro 16 : LibCall call a dynamic library subroutine
;
; bvsLibName 16505 : the name of a dynamic library
; bvsProcName 15157 : name of the proc being generated
;
Macro LibCall (bvsLibName, bvsProcName)
lib#bvsLibName#_sub#bvsProcName
EndMacro
;
;-----------------------------------------------
;
; Macro 17 : LibReturn return a value from a dynamic library function
;
; bvsLibName 16505 : the name of a dynamic library
; bvsProcName 15157 : name of the proc being generated
;
Macro LibReturn (bvsLibName, bvsProcName)
lib#bvsLibName#_fun#bvsProcName
EndMacro
;