[Implemented] Make compiler constants as string available

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

[Implemented] Make compiler constants as string available

Post by AND51 »

Hello!

It would be very fine, if you could make some numeric compiler constants available as string constants, too!
It's annoying to convert numbers to strings with Str().
But the main reason for this request is that this issue makes it imnpossible to create new constants when you have to convert numbers!

My idea would be, that you dublicate #PB_Compilrer_Line for example. The numeric version is still #PB_Compilrer_Line, the new string version would have a trailing '$':

Code: Select all

Debug #PB_Compiler_Line+1                 ; 1+1=2
Debug "Error in line "+#PB_Compiler_Line$ ; no conversion neccessary
Maybe you can realize this with other useful constants, too.
One numeric/float constant (without '$') and its string version (with trailing '$'). Currently, I only remember #PB_Compiler_Version, but you may add other constants that could fit this request.

This request already exists with the new-line-constants:
#CRLF is 9 (nine) and #CRLF$ is the real new-line-character.

// Edit:
You might also add #PB_Editor_*Count (by the way, these constants are not being auto-completed!).
PB 4.30

Code: Select all

onErrorGoto(?Fred)
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post by #NULL »

just for fun :lol: :

Code: Select all

Macro mk2(CONST,VAL)
  #CONST = VAL
  CONST.s = Str(VAL)
EndMacro

mk2(foo,6)

Debug #foo+2
Debug ".."+foo
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Using this method I could stay regressive. I'd go on not being able to build constants and I would waste precious memory to unneccessary variables.
Just for fun, as you said.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Make some compiler constants as string available, too

Post by PB »

> #CRLF is 9 (nine)

Why should this be 9? It's two characters: CR and LF. And 9 is for tabs.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Re: Make some compiler constants as string available, too

Post by AND51 »

PB wrote:> #CRLF is 9 (nine)

Why should this be 9? It's two characters: CR and LF. And 9 is for tabs.
Sorry, I swapped something...
The correct example should be:
#TAB => 9
#TAB$ => " " (a real tab)
PB 4.30

Code: Select all

onErrorGoto(?Fred)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Make some compiler constants as string available, too

Post by PB »

> The correct example should be:
> #TAB => 9
> #TAB$ => " " (a real tab)

They both already do this. I don't know what you mean?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Re: Make some compiler constants as string available, too

Post by Dare »

lol.

From #pb_number_1 to #pb_number_9223372036854775807, which gives us a positive quad's worth. Then the negatives. Then the floats. Then the hex renditions. Then the binary renditions.

Posting just for fun. :)
Dare2 cut down to size
Post Reply