News:

Welcome to RetroCoders Community

Main Menu

What does it do?

Started by ed davis, Oct 31, 2022, 12:43 PM

Previous topic - Next topic

ed davis

For years I've been puzzling over how the following lines of code worked (from a Basic program, circa 1976):
5 y = 2999: input "Do you want a difficult game? (y or n):", a
10 print "Stardate 3200:  your mission is ";: if a = y then y = 999
and
120 s=220: g=180: l=200: p=260: r=420: w=465: t=555: q=110: input "Captain:", a
125 if (a = s) + (a = g) + (a = l) + (a = p) + (a = r) + (a = w) + (a = t) + (a = q) then goto a

Finally, a few weeks ago, someone on the Facebook "Basic Programming Language" group solved the mystery for me.

Anyone else know how the above works? Note: The question is mainly, what value for a does input return?

By the way, the feature is really cool, and I've updated my Basic interpreters to use it. 

johnno56

Well.. I am totally confused... (Mind you, that is NOT hard... lol)

Line 5: 'y' is a number and 'a' is a string
Line 10: How can 'a', a string, be compared to 'y', a number, unless 'y' is actually a string?

Line 120: All those variables are numbers and 'a' is assumed a string.
line 125: Again, the 'a' string is compared to numeric values? The only way I can see 'goto a' working is that a line label 'a' has been defined or 'a' represents a numeric value...

Basic was so much easier when strings were defined as 'a$' and numbers were just 'a'...

Am I reading your example correctly or do you see my point of confusion?

J
May your journey be free of incident.  Live long and prosper.

ed davis

Quote from: johnno56 on Oct 31, 2022, 09:39 PMWell.. I am totally confused... (Mind you, that is NOT hard... lol)

Line 5: 'y' is a number and 'a' is a string
Line 10: How can 'a', a string, be compared to 'y', a number, unless 'y' is actually a string?

Line 120: All those variables are numbers and 'a' is assumed a string.
line 125: Again, the 'a' string is compared to numeric values? The only way I can see 'goto a' working is that a line label 'a' has been defined or 'a' represents a numeric value...

Basic was so much easier when strings were defined as 'a$' and numbers were just 'a'...

Am I reading your example correctly or do you see my point of confusion?

J

It is actually pretty tricky.  Like I said, I was never able to figure it out myself.  No need to worry about feeling confused :)

Both of those are integer inputs - no strings involved.

However, Palo Alto Tiny Basic, had a cool feature:

When it processed the input statement, it worked like so:

Input "age:", a

It would read what the user typed into a string.

And then call an internal eval routine, or internal numeric expression processor.

So, if you had:

a = 45
Input "age:", a

If the user typed:  45
It would return 45.
If the user typed:  45 + 3
It would return 48
If the user type: a + 5
It would return 50, because the value of "a" had been set to 45.

Cool, huh?

In the 2nd example, it presets all the variables to the appropriate line numbers.

So, if the user enters "r", then the program would execute "goto r", or "goto 420".

I wonder if any other Basic interpreters do something similar?

The SpecBas guy said his interpreter does that for val() functions - I wonder if it does it for input?





mysoft

yeah so it returns an expression... it then do the same as "a=y" (yeah makes sense for it to accept a expression when an integer is expected just like the basic would)