Page 1 of 1

New Keyword Const

Posted: Sat May 17, 2025 11:19 am
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?

Re: New Keyword Const

Posted: Sat May 17, 2025 1:22 pm
by Quin
What exactly is the point of the first example? Constants exist for that.
For parameters though it could be nice.

Re: New Keyword Const

Posted: Sat May 17, 2025 1:58 pm
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"

Re: New Keyword Const

Posted: Sat May 17, 2025 2:09 pm
by miso
Isn't constants just replacement texts in the code before compilation?

Re: New Keyword Const

Posted: Sat May 17, 2025 3:44 pm
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)

Re: New Keyword Const

Posted: Sat May 17, 2025 4:34 pm
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.

Re: New Keyword Const

Posted: Mon May 19, 2025 10:51 am
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.)

Re: New Keyword Const

Posted: Mon May 19, 2025 1:31 pm
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.