Allow: Macro Test(ID, Text$, Word.s, , Line.i)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Allow: Macro Test(ID, Text$, Word.s, , Line.i)

Post by Sicro »

To determine whether a macro parameter requires a number or a string, it would be good if the parameter name can have a dollar sign ($) at the end or a dot inside.

Code: Select all

Macro Test(ID, Text$, Word.s, Line.i)
  ; ...
EndMacro
Last edited by Sicro on Sun Apr 08, 2018 12:32 am, edited 2 times in total.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Macro Test(ID, Text$)

Post by skywalk »

The suffix '$' = String datatype.
Macros perform search and replace before compile. Datatypes have no meaning before compile.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Macro Test(ID, Text$)

Post by mk-soft »

Simple way is with prefix...

Code: Select all

Macro foo(iID, sText, lValue, wValue, pPointer)
  ;  
EndMacro
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Macro Test(ID, Text$)

Post by Sicro »

skywalk wrote:The suffix '$' = String datatype.
Yes, that's why I chose this sign. If someone sees the suffix "$", it is immediately clear that a string is requested.
skywalk wrote:Macros perform search and replace before compile. Datatypes have no meaning before compile.
Yes, I know. My point is that later in the code it should be recognizable whether the macro parameter requires a string or a number.

Code: Select all

Macro Test(Value)
  Debug Val(Value)
EndMacro
For example, if I define the above macro in a huge code and I want to call the macro later, I somehow need to know how to enter the values in the macro parameters:

Code: Select all

Test("123")
; or
Test(123)
; I don't know... I must go to the macro definition to take a look...
With procedures, I always see which data type the parameter requires in the status bar of the PB IDE.
mk-soft wrote:Macro foo(... sText ...)
Yes, this is a possibility that is immediately understandable for many programmers, although the suffix "$" would be more understandable.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Macro Test(ID, Text$)

Post by helpy »

Sicro wrote:... although the suffix "$" would be more understandable.
;-)
I never use the $ sign for text variables!
;-)
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Macro Test(ID, Text$)

Post by Mistrel »

helpy wrote:
Sicro wrote:... although the suffix "$" would be more understandable.
;-)
I never use the $ sign for text variables!
;-)

I ALWAYS use .s for clarity and to match all other types. :D
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Macro Test(ID, Text$)

Post by skywalk »

I always use myStrVar$ to easily spot a string.
Else you have to use some other prefix to know it is a string.
Like smyStrVar or myStrVar_s.
The trailing $ is just easy.
But I define them with Define.s myStrVar$ for my code parsing tools.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Allow: Macro Test(ID, Text$, Word.s, , Line.i)

Post by Sicro »

I have edited my first post to take into account the other variable definitions.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Allow: Macro Test(ID, Text$, Word.s, , Line.i)

Post by TI-994A »

Sicro wrote:

Code: Select all

Macro Test(ID, Text$, Word.s, Line.i)
  ; ...
EndMacro
Technically, even if such were to be implemented, it would purely be as syntactic sugar, with no type reflection. And the full notation would have to be expressed within the macro as well; like so:

Code: Select all

Macro Test(ID, Text$, Word.s, Line.i)
  Debug Word.s
  Debug (Line.i + Line.i)
EndMacro
Because macros merely perform syntactic refactoring without any functional evaluation. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Allow: Macro Test(ID, Text$, Word.s, , Line.i)

Post by Sicro »

TI-994A wrote:

Code: Select all

Macro Test(ID, Text$, Word.s, Line.i)
  Debug Word.s
  Debug (Line.i + Line.i)
EndMacro
That's exactly how I imagine it. The names of the macro parameters should also be allowed to contain "$" and dot.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Post Reply