New Keyword Const

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

New Keyword Const

Post by Axolotl »

I would like to suggest a new Keyword Const
1. typified constant

Code: Select all

 DeclareModule Test 
  ; Const MaxTests.i = 1000   ; typified constant 
  #MaxTests = 1000  
EndDeclareModule 
Module Test 
EndModule 
; Debug Test::MaxTests 
Debug Test::#MaxTests 
2: Helpful as an optional parameter ...

Code: Select all

Procedure Test(Const *HugeString) 
  ; do something without unintentionally changing the content 
EndProcedure 
3. tbc?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: New Keyword Const

Post by Quin »

What exactly is the point of the first example? Constants exist for that.
For parameters though it could be nice.
User_Russian
Addict
Addict
Posts: 1535
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: New Keyword Const

Post by User_Russian »

I think instead of a new method for declaring a constant, it would be better to add the type to the current declaration method.

Code: Select all

#MaxTests.i = 1000
#ByteConst.a = 200
#FloatConst.f = 10.1234
#StringConst.s = "1234"
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: New Keyword Const

Post by miso »

Isn't constants just replacement texts in the code before compilation?
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: New Keyword Const

Post by Axolotl »

Quin wrote: Sat May 17, 2025 1:22 pm What exactly is the point of the first example? Constants exist for that.
For parameters though it could be nice.
Well, the commented lines are the request, maybe thats not clear enough?
I was inspired by the different writing of strings

Code: Select all

String.s or String$  

I know that these are different strings.
Maybe it is because it looks nicer (only) or maybe I do to much FreePascal at the moment.... (Sorry, if this is bothering you)
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: New Keyword Const

Post by Quin »

Not bothering me at all, I was simply curious why you wanted to replace the way PB has defined constants for over 20 years with the const keyword?
I see the use for parameters, basically a read-only pointer, but I don't see why you'd want to change # to const.
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: New Keyword Const

Post by Axolotl »

Quin wrote: Sat May 17, 2025 4:34 pm ..., but I don't see why you'd want to change # to const.
Well, I never requested a replacement. I thought of it as an addition to the language.

BTW: (I don't like changes that make existing code invalid/uncompilable and I know, that sometimes it can't be avoided.)
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: New Keyword Const

Post by Quin »

Ah, just another way to define constants, gotcha.
I personally don't really see much of a use for it, but it would work. As a parameter modifier it could be really nice though, along with Out.
Post Reply