language questions

Hello,

I have downloaded and am playing with the Bronze Demo version of TrueBASIC. There are several things I don't know how to do in the language (and whether they are at all possible).

1) How do I declare an array of non-constant size, i.e. one that is determined at run-time? Or, can the size of an existing array be extended/shrinked at run-time?

2) How can I have a Boolean-valued variable, so that, e.g. I could simplify some Boolean expressions or have Boolean formal parameters in a sub-routine?

3) How can a program determine whether, say, line input s$ does indeed read something into s$ or the input stream is already `exhausted'?

4) How do I place more than one instruction in a single line?

Tnank you,
Boyko

Comments

TB reference guide

Boyko,
A very elementary programming guide for True Basic can be found at: http://maeresearch.ucsd.edu/herz/basicRef/

Evidently you have a good bit of experience programming in other languages, and the above may seem overly simple. But if you have no documentation whatsoever, it may help to understand how things are done in True Basic.

Frankly I don't see why PDF manuals are not available on this site for those who don't have them, or have lost them.

Hope this helps.

Regards. Mike C.

thanks and elaboration

Thank you for answering my questions, guys!

However, I have to elaborate on questions (2), (3) and (4):

(2) In TB Boolean variables are the same as numeric variables except they only have two values: 0 or 1
Trying to compile
if 1 then print "y" else print "n"
gives a “Wrong type” message (of 1).
Trying to compile
let y = a<b
gives a “Doesn't belong here” message (of the < operator).

As of (3) …
Tom:
A string being empty as a result of executing LINE INPUT … does not (and should not) mean end-of-input, it just means that the user entered a blank line. I was asking for a way to detect end-of-input.

Big John:
DO while more #0
seems to work in theory (#0 turns to be, as expected, the “standard input” channel), but in practice, since the standard input in TB is not the real console but a window, and that window neither accepts Ctrl-Z for EOF nor seems to have a way to fake it, we have no means to invert the more #0 condition. Eventually, the loop is indefinite.

(4) There is no advantage in putting multiple instructions on the same line and it makes the code much more difficult to read and debug.
I tend to put (in other languages) 2 or 3 short statements – usually initializing assignments – on the same line in order to make it explicit that they are tightly related, but it's ok – I can certainly live without that.

Boyko

More on questions

An IF.....THEN statement requires a comparison e.g.
LET x=5
IF x>1 then.....etc
I think IF will even work on a single variable but not with a constant - hence the wrong type message, e.g.
IF key input THEN

Your other question related to an assignment:
LET y=(a less than b) ! this site doesn't like the less than sign.

I don't know what you trying to do here. Perhaps you are trying to make y=the lowest value of a or b? In this case you would use:
LET y=MIN(a,b)

Basically if you read TB code then it should make sense in English. If it doesn't then there is every chance that something is wrong.

(3) If you read the documentation it refers to channel numbers greater than #0. In TB channel #0 is reserved for the default window. You cannot use #0 for transmitting data to and from files, external devices etc. or for any other purpose.

(4) You can make multiple assignments on the same line, e.g. LET x,y,z=0
This is the only exception to the single statement rule.

Big John

...

An IF.....THEN statement requires a comparison e.g.
LET x=5
IF x>1 then.....etc
I think IF will even work on a single variable but not with a constant…

No it doesn't work on a variable, as can easily be checked. It turns out that True BASIC lacks Boolean values (let alone Boolean variables) other than the conditional expressions within IF, WHILE etc. statements. Those conditional expressions include comparisons, AND/OR/NOT, and several other operators, but this is all – one cannot use 0, 1, -1 or whatever integer or other value in place of a truth value.
Moreover, one cannot store a Boolean value in a variable, e.g.
let a = 1
let b = 2
let y = a<b

can be expected to store the value ‘true’ in y (as in almost all other programming languages and also some BASIC dialects), but sadly is impossible in TB.

Your other question related to an assignment:
LET y=(a less than b) ! this site doesn't like the less than sign.
I don't know what you trying to do here.

See my comments above: I was trying if it was possible to store a Boolean value – and it turns out it isn't. Booleans are not first-class values in TB.

this site doesn't like the less than sign

Write &lt; and &gt; instead of < and >, respectively. The site is in HTML, which means that less-than and greater-than characters are treated specially (for markup).

If you read the documentation …

Sadly, the Bronze Demo which I am using comes with 0 pages of documentation. That is why I am finding out the things I need about TB by experimenting & asking questions.

… In TB channel #0 is reserved for the default window. You cannot use #0 for transmitting data to and from files, external devices etc. or for any other purpose.

I do not mean reading files. What I mean is precisely reading the so called ‘standard input channel’, or ‘the console’, which in the case of TB is the default window you talk about (LINE INPUT #0 is just the same as LINE INPUT).
Now, I would like to be able to terminate the standard input stream as being read by a program. Were it the usual kind of console – in a DOS window, say – I would type Ctrl-Z for that. In the TB default window this is impossible, which in turn renders the while more #0 condition useless.

Boyko

Even more on questions

You say that:
let y = a(less than)b
can be expected to store the value ‘true’ in y
This may well work in some languages but in TB this is not a legitimate assignment. You would have to use:
IF a(less than)b then
LET y=1
ELSE
LET y=0
END IF

There is no "standard input" channel. Input from the keyboard or mouse does not require a channel number. Hence INPUT n or INPUT c$ will read numeric or strings from the keyboard. Similarly LINE INPUT c$ will read keyboard input containing quote marks, commas and other punctuation. In both cases the RETURN key signifies the end of the input. GET KEY k will also read single keystrokes from the keyboard.

There is no "standard output" channel either. To display data on the monitor you can use PRINT or PLOT TEXT, AT x,y:text$

Channel numbers are only required for sending and receiving data from files or the printer.

Big John

Input from the keyboard …

Input from the keyboard … does not require a channel number.

I do understand that a channel number is not required, but it may be used: as I pointed out earlier, LINE INPUT #0: s$ is equivalent to LINE INPUT s$. Given that, I might also want to say DO WHILE MORE #0 so that I (i.e., my program) could know when the input ends (please note, we are talking of the end of the input, not the end of a single line). But, alas, that is not possible.

…the RETURN key signifies the end of the input.

RETURN does not signal the end of the input – just the end of the (current) line.

I know there are workarounds for both the inability of TB to detect the end of input and its lack of true Boolean values. However, I believe these are issues with TB. I will try to explain why in a separate post.
Boyko

Questions

(1)First of all you must use DIM string$(0) to initialize a string array for example. At runtime you can now re-dimension this array e.g. MAT REDIM string$(x) where x is a numeric variable that assumes a value during runtime.

(2)In TB Boolean variables are the same as numeric variables except they only have two values: 0 or 1

You can also use statements such as:
IF key input then ! meaning if it is true that a key has been pressed then execute the next line.
DO While MORE 1#: meaning if it i true that channel #1 has more data then continue with the DO...LOOP

(3) If you want to test the input stream for more LINE INPUT then use the above construction e.g.
DO while more #1
LINE INPUT #1: string$
LOOP

(4)Only one instruction per line is allowed in TB. There is no advantage in putting multiple instructions on the same line and it makes the code much more difficult to read and debug.

Big John

language question

Boyko ... The Bronze Demo doesn't come with a user manual that can answer your questions. TB Bronze does, but you need to get access to a TB Silver or Gold manual for good answers.

For question 1, first you just need to declare a vacuous DIM statement near the top of your program listing, like:

DIM Q(0) ! for a one dimension array. Remember, TB supports MAT (array) statements. What other laqnguages do?

Then, when you want to activate array Q, you use the REDIM statement, like:

MAT REDIM Q(75)

For question 2, TB does support Boolean variables, discussed in the first three pages of Gold/Silver manual Chapter 5 "Decision Structures". TB (all editions) allow you to compare the values of both numeric and string expressions. TB implements two different decision structures: the IF structure and the SELECT CASE structure.

For Q3, You can always check the length of s$, and there are other ways to check if s$ is empty in TB.

For Q4, if "instruction" means "statement" the answer is "You can't do that!". Regards ... Tom M