It is currently Tue May 23, 2017 9:50 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Constants
Unread postPosted: Tue May 02, 2017 8:02 am 
Offline

Joined: Mon Aug 08, 2016 12:36 pm
Posts: 6
Can we add the ability to declare number and string variables as constants?


Report this post
Top
 Profile  
 
 Post subject: Re: Constants
Unread postPosted: Tue May 02, 2017 10:45 am 
Offline
User avatar

Joined: Thu Nov 21, 2013 7:00 pm
Posts: 638
Is there any reason why you can't use a variable instead ?

_________________
- Failure is not an option. It is bundled with the software. -


Report this post
Top
 Profile  
 
 Post subject: Re: Constants
Unread postPosted: Tue May 02, 2017 11:09 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 656
Location: UK
humpty wrote:
Is there any reason why you can't use a variable instead ?

I think it is good to have syntax that indicates a constant. "High-level" languages are all about indicating intentions. But a string-substitution "macro" mechanism can be an equivalent and slightly more flexible...

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Constants
Unread postPosted: Wed May 03, 2017 10:40 am 
Offline
User avatar

Joined: Thu Nov 21, 2013 7:00 pm
Posts: 638
I've never understood the reason for constants.
I've always thought it was lazy way to get compilers to catch your errors.

If it's about intention: Even if you could define a real constant, it would just look like a variable when you actually use it.
But you can also capitalise a variable e.g ACONSTANT
or call it something like constant_A or C_a$, which can remind you not to change it.

The only other reason I can think of is compiler optimisation. I'm not sure
if it makes that much difference in Basic!

_________________
- Failure is not an option. It is bundled with the software. -


Report this post
Top
 Profile  
 
 Post subject: Re: Constants
Unread postPosted: Wed May 03, 2017 6:09 pm 
Offline

Joined: Mon Aug 08, 2016 12:36 pm
Posts: 6
mjcoon wrote:
But a string-substitution "macro" mechanism can be an equivalent and slightly more flexible...


What exactly is that? And I personally want constants for user-friendly libraries. The algorithm I am specifically working on that I would especially want is:
Code:
LET statusbar = 1 %Boolean for status bar visibility
...
GR.OPEN 255,0,0,0,statusbar,1
GR.STATUSBAR sbar_height
GR.SCREEN scr_w,scr_h
IF scr_w > scr_h THEN SWAP scr_w,scr_h
...
GR.RECT tbar,0,statusbar * sbar_height,scr_w,75 + statusbar * sbar_height
...
END


So, if statusbar = 0, then it wouldn't show up, and if it would be 1, it would and drawings adjust accordingly. I know it could be done a different way, but this seems to be the most efficient way.


Report this post
Top
 Profile  
 
 Post subject: Re: Constants
Unread postPosted: Thu May 04, 2017 4:50 am 
Offline
User avatar

Joined: Sat Aug 24, 2013 1:37 pm
Posts: 85
I keep a list of those variables I am using as constants, then just make sure I don't mess with em...

_________________
I love RFO basic!

Tablets owned:
Hisense Sero 7 Pro
Samsung Galaxy Player 5.0


Report this post
Top
 Profile  
 
 Post subject: Re: Constants
Unread postPosted: Thu May 04, 2017 6:04 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 656
Location: UK
soulfighter wrote:
mjcoon wrote:
But a string-substitution "macro" mechanism can be an equivalent and slightly more flexible...


What exactly is that? And I personally want constants for user-friendly libraries.

One use of named string constants would be to put in a separate module of natural-language messages. For different language versions of the program, use different modules. The module is only read by the pre-processor, so does not contribute to run time, and the strings themselves are only processed if-and-when they need to be shown by the program.

Mike.


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred