yab | yet another Basic for HAIKU

Full Version: Feature request: CLOSE ALL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
There is a trick to use the OPEN command to test whether a file exists. The problem with that is that you need to guess at which stream was opened and close it, otherwise you'll get a "stream already in use error" further down the line. A CLOSE ALL command would be a useful way to solve that problem.

In fact, leaving streams open indefinitely is a bad idea anyway. Occasionally you may want to read from one file and write to another, but even then, I prefer to read data into a variable or array, close the stream and then write it to a new one. CLOSE ALL woild make our programs a little more robust.

Yes, you could fake it with a for ... next loop. Having such a command in yab itself would be faster.
In yab, one cannot open a file without knowing the stream number. I admit that a CLOSE ALL, or just CLOSE might be a good thing. I will look at the code and see if my c++ knowledge is good enough to make it happen.
To be more precise, I am seeing this with

IF OPEN(pathname$, "r") THEN ...

which is a useful way to test for the existence of a file. This seems to be the only variation of OPEN that does not require a stream number. But it still requires the stream to be closed afterwards.

I suppose you could use SYSTEM("test -e " + pathname$) but the less we need to shell out, the better

If I've been careful with my streams, it will grab the first available one, normally #1, and CLOSE#1 will get rid of it. But If you have not been careful, well ...

BTW, when I was writing "Programming with yab", I noticed that our documentation does not explicitly mention how many streams are available, so I started increasing the number until I got an error. I was expecting 9, like in QuickBasic. In fact, it is 124. How insane is that? I'd really hate to maintain the program that had 124 files open.
handle=OPEN(pathname$, "r")
if handle then...

close handle

Aha, that does solve the problem. Thanks.
I added the option to close all files: https://github.com/bbjimmy/YAB/commit/20...6156cb9a6f

close -2 closes all open files....


close all

Free Web Hosting