strings as arrays (New Features)

by koscianski, Wednesday, March 05, 2014, 11:16 (1115 days ago)
edited by koscianski, Wednesday, March 05, 2014, 11:22

Hi. Congratulations for the tool.
Would you consider (please) indexing individual characters of strings?
I'll explain.
I'm going to use basic 256 for introductory programming, in a undergraduate course. We will open the semester with Basic and end it with C (I've done that before).
Basic256 is a marvelous tool.
Now, allowing thing as

if a$[3] = 'a'
or, to avoid messing up with arrays,
if a$(3) = 'a'

opens a myriad of possibilities of useful exercises of increasing difficulty.
The goal is to keep students highly focused and motivated, something much much harder to do using Fibonacci and his friends. That's also why graphics are great, but they have their own place in the course sequence.
I built a similar tool myself 10 years ago, using Borland C++ and a recursive parser (no lex/yacc), but I simply lost the code; it was not as complete as Basic 256. Great tool
I downloaded your code, but I gave up diving into the source, installing Qt & etc.
I'll use it anyway, but I do miss string indexing.

strings as arrays

by Jim ⌂ @, Russell, KY, Wednesday, March 05, 2014, 15:19 (1115 days ago) @ koscianski

Thinking about your request has opened up several little issues. BASIC-256 does not have the concept of a 'x' char like c does. What would the behavior a$[6] = "abcde" do? Insert replacing one char (at 6) or replace 5 chars starting at 6? I believe either way would be confusing.

I have looked at the MID statement in other BASICS and find it confusing but doable. Making it work like VB6 or GWBASIC would be very possible. Would that be a solution for you?

Let me think about array indexing a string variable. It might not be as difficult as my first thought.

Would love to know more about how you are using this in your University. I have been teaching an intro class using BASIC-256 then moving to VB.NET for several years. It seems successful.


strings as arrays

by koscianski, Wednesday, March 05, 2014, 22:35 (1115 days ago) @ Jim

Thank you so much for your fast answer!

I figured out how to play with strings the way I wanted to.
It's quite simple:

aux$ = explode (s$, "")
.. access individual characters in aux$[i] ..
s$ = implode (aux$)

And voilà.
There's no need to touch anything in Basic 256.

This little twist is by no means a real problem.
On the contrary: the language keeps consistent.
Strings and arrays remain different things.

I never thought of writing s$[3] = "abc" where s$ isn't an array.
Implementing my request could open the way for confusion:
two meanings for the same symbol [].
It seems better to rule this possibility out.

Thanks again. And, I'll be glad to share details about
the course, in 1 or 2 months I'll have more info.

strings as arrays

by Jim ⌂ @, Russell, KY, Thursday, March 06, 2014, 03:39 (1115 days ago) @ koscianski

How cool is that. I never would have thought of the empty string as a delimiter. :)

I have written a little demo program that shows the extra "" element at the beginning and ending of the exploded array.

a$ = "abcd1234"
print a$
letters$ = explode(a$,"")
for t = 0 to letters$[?]-1
print t + " " + letters$[t]
next t
b$ = implode(letters$,"")
print b$
print b$ = a$


1 a
2 b
3 c
4 d
5 1
6 2
7 3
8 4

RSS Feed of thread
powered by my little forum