Basic Interpreter

Started by johnhenry, August 25, 2016, 02:00:08 PM

Previous topic - Next topic

johnhenry

Is there a published manual for the BASIC version used on the Vectrex32?


Vectrex32


crcasey

What is the reason that you have decided not to cast variable types, but allow any type to be changed at any time to a different type?  IE why can an array be changed to a int with no warning.  It seems this makes it harder to find an accidental misassignment.

Not that this is a bug, or even wrong.  I just wondered what your thinking on this is.

-Cecil

Vectrex32

Quote from: crcasey on November 15, 2016, 05:13:52 PM
What is the reason that you have decided not to cast variable types, but allow any type to be changed at any time to a different type?

If I may state it a little more precisely: a variable can be set to any value of any type at any time.

I anguished for quite a while over whether I should use static or dynamic typing. I settled on dynamic partly because I thought it was easier for novice programmers, partly because it simplified my implementation, and partly because it let me re-initialize arrays - something I envisioned being useful when working with sprites.

- Bob

crcasey

Another question along this line...

Why keep = as both assignment and as an expression?

I find the C way of = being assignment and == being compare expression makes the code read more clearly.

-Cecil

crcasey

Also a quick question on assignment and pointers...

a=10
b=a
b=b+10

is a = 10 or is a=20 now?

How about with more complex types like arrays?

-Cecil

Vectrex32

BASIC has always used = for both assignment and comparison, so I'm just keeping with that tradition.

- Bob

Vectrex32

Quote from: crcasey on November 15, 2016, 08:29:23 PM
Also a quick question on assignment and pointers...

a=10
b=a
b=b+10

is a = 10 or is a=20 now?

How about with more complex types like arrays?

-Cecil

a remains 10. However, if you did:

dim a[1]
a[1] = 10
b = a
b[1] = 20

then a[1] would also be 20. So scalar assignments are copies of the value while array assignments are copies of the references.

- Bob

crcasey

Thanks, Sorry to keep up the basic (ha) questions.

-C

crcasey

I don't think I have run into a basic version that normally can use a float type in the FOR ... STEP  <Float> format before.

Is this carried over from a Basic I have not used?  I can totally see where this will be great for camera moves and sprite translations.

-Cecil

Vectrex32

Actually, I think BASIC has always allowed floating point values in FOR statements. I remember doing it in BASIC Plus on a PDP-11 in the late 70s. It requires some care due to the imprecise nature of floating point values.

- Bob

crcasey

Function handling question...

If you define:

FUNCTION MyFunction(a, b)
RETURN a + b
ENDFUNCTION


What happens if you call it...

a=MyFunction(1)
print a

Of if you call it...

a=Myfunction(1,2,3)
print a

Just wondering how that error was handled.

-Cecil

Vectrex32

It gives you an error, that the function call has the wrong number of arguments.

- Bob

crcasey

Quote from: Vectrex32 on November 15, 2016, 09:45:13 PM
It gives you an error, that the function call has the wrong number of arguments.

- Bob

Same function def.
A more strange case, but likely follows string cat rules.

a="A number is "
b=3.33333

print myfunction(a,b)

-C

Vectrex32

Argument a will be a string, b will be a number, and when the function executes the plus sign, it will act as a string concatenation, with b being converted to a string.

- Bob