Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Oberon > Re: Of constant...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 13 of 28 Topic 442 of 500
Post > Topic >>

Re: Of constants and variables

by "Chris Burrows" <cfbsoftware@[EMAIL PROTECTED] > Oct 19, 2007 at 11:16 PM

"Xcriber51 >" <Ken <ken-tusc@[EMAIL PROTECTED]
> wrote in message 
news:3440b1eb50c6cc3a97a37b7af5fce6d8@[EMAIL PROTECTED]
>
> A very simple question (couldn't find the answer in the Help of
BlackBox).
> I want to create a string as a lookup table, so I want to make it a
> constant. e.g.
>
>    CONST Encodings = "01230124022455012623017272";
>
> But then, since I want to use it as a lookup table, I want to access it
> with an index, e.g.
>
>    ch := Encodings[i];
>
> Unfortunately, the compiler tells me this is a no-no. What exactly is
the
> reasoning behind this rule?
>

By definition, a CONST in Oberon-2 / Component Pascal is truly a
*constant*. 
i.e. it must be possible to evaluate it at compile time and it cannot be 
changed at runtime. If you were able to access a CONST string as an array
as 
suggested e.g.

CONST Encodings = "01230124022455012623017272";

   ch := Encodings[i];

then according to the rules associated with arrays it would also be
possible 
to write:

  Encodings[i] := ch;

which is counter to the definition of a CONST.

The design of Oberon-2 / Component Pascal typically avoids these sorts of 
inconsistencies.

Furthermore, the Oberon-based languages intentionally only include the 
general-purpose language features that are deemed to be 'necessary and 
sufficient'.  If a particular task can be achieved in one way then it is
not 
seen to be necessary to implement several additional alternative ways to 
reach the same goal.

For this particular example, you can achieve what you are trying to do by 
declaring 'encodings' as a read-only variable in a separate module and 
setting its value in the initialisation code of the module that it is 
declared in.

e.g.

MODULE Constants;

VAR
  encodings-: ARRAY 27 OF CHAR;

BEGIN
  encodings := "01230124022455012623017272"
END Constants.

Client modules are then able to inspect the values of individual elements
of 
'encodings'

e.g.

  ch := Constants.encodings[i]

but they are unable to change them.

--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp
 




 28 Posts in Topic:
Of constants and variables
"Xcriber51" <  2007-10-18 07:05:37 
Re: Of constants and variables
Stefano Ferrari <ferra  2007-10-18 07:36:44 
Re: Of constants and variables
"Xcriber51" <  2007-10-18 11:02:56 
Re: Of constants and variables
pjb@[EMAIL PROTECTED] (P  2008-06-13 20:55:42 
Re: Of constants and variables
Stefano Ferrari <ferra  2007-10-19 01:22:44 
Re: Of constants and variables
Stefano Ferrari <ferra  2007-10-19 01:34:25 
Re: Of constants and variables
"Xcriber51" <  2007-10-19 07:28:00 
Re: Of constants and variables
"Xcriber51" <  2007-10-22 05:41:51 
Re: Of constants and variables
"Chris Burrows"  2007-10-22 22:26:19 
Re: Of constants and variables
"Xcriber51" <  2007-10-22 12:20:08 
Re: Of constants and variables
"Chris Burrows"  2007-10-23 08:58:31 
Re: Of constants and variables
Stefano Ferrari <ferra  2007-10-19 06:09:17 
Re: Of constants and variables
"Chris Burrows"  2007-10-19 23:16:52 
Re: Of constants and variables
=?ISO-8859-1?Q?Christian_  2007-10-19 18:43:54 
Re: Of constants and variables
fmw@[EMAIL PROTECTED] (F  2007-10-19 16:06:35 
Re: Of constants and variables
=?ISO-8859-1?Q?Christian_  2007-10-19 18:33:11 
Re: Of constants and variables
August Karlstrom <fusi  2007-10-21 11:47:08 
Re: Of constants and variables
Ulrich <keine@[EMAIL P  2007-12-02 19:15:58 
Re: Of constants and variables
Ulrich <keine@[EMAIL P  2007-12-02 19:13:44 
Re: Of constants and variables
comp.lang.oberon@[EMAIL P  2007-12-02 23:01:11 
Re: Of constants and variables
Ulrich <keine@[EMAIL P  2007-12-07 00:23:22 
Re: Of constants and variables
comp.lang.oberon@[EMAIL P  2007-12-07 09:47:11 
Re: Of constants and variables
August Karlstrom <fusi  2007-10-21 11:58:00 
Re: Of constants and variables
Ulrich <keine@[EMAIL P  2007-12-02 19:29:01 
Re: Of constants and variables
Stefano Ferrari <ferra  2007-10-21 14:52:20 
Re: Of constants and variables
August Karlstrom <fusi  2007-10-22 17:57:46 
Re: Of constants and variables
Ulrich <keine@[EMAIL P  2007-12-02 19:23:15 
Re: Of constants and variables
fmw@[EMAIL PROTECTED] (F  2007-10-22 10:20:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 10:07:41 CDT 2008.