|
Post by sarossell on Jan 17, 2020 20:47:25 GMT -5
How cool would it be if we could do this?
idecode$() = idecode$() + "print "Did I just modify my source code on the fly?"
|
|
|
Post by honkytonk on Jan 18, 2020 5:21:08 GMT -5
alincon : Very clever indeed. I do like that Word$ command. Any idea of a quick way to count the number of words in a string other than the obvious loop and incremented counter? I don't think there's a command for that. source$ = idecode$() for n = 1 to time$("ms") w$ = word$(source$,n) if w$ = "" then exit for next print n;" words total."
a$="a b c d e f g h"' i j k l m"' n"' o"' p q r s t u v w x y z 1 2 3 4" for n=1 to len(a$) if word$(a$,n)="" then total=n-1: exit for next n
|
|
|
Post by mknarr on Jan 18, 2020 10:06:11 GMT -5
Sarrossell. Please don't take this the wrong way. I started programming in Princeton basic in 1967 for work at AT&T. Then we we got our first Wang Desktop calculator and I became the goto guy to program those. Then I got my first Radio Shack Color computer at home and programed in that basic. Then Quick Basic and now LB since 2004. I don't ever remember the need to clear variables until I had to. Since the Wang had only 960 registers for both code and data, and the Color computer started with only 4K of memory, I developed an obsession for tight code and minimal memory use. At one point in the 17000 line program I decided that I would reduce memory use by redim every array as soon as I was done using it just to save memory. Oddly enough it saved no memory use at all. It finally dawned on me that with today gigabit and terabyte memory I was only kidding myself. BTW funny story. Sometime in the early 80s I was the diffusion engineer on a 64K memory line. At that time AT&T (Western Electric) was going to open a new plant every year for 10 years to make 64K memory chips. I thought who was every going to need that much memory. How wrong I was.
|
|
|
Post by sarossell on Jan 18, 2020 13:38:56 GMT -5
mknarr: The issue is not about memory. All I can tell you is that in my 25 years as a technical writer for military projects, I had to verify that all code met the standards of Code Title 50 (h.3.B): Theater-Wide Operative Data Infrastructure Integrity. "Deployed Information Technology software applications must adhere to "live fire" protocols (87-C-12.6) ...including programmatic initial state reset." The programmers groused about it for reasons I never fully understood. I figured, how hard could it be? But apparently with COBOL and PL/I, it was an issue. My limited experience with programming just filed that in the same drawer in my brain with Sinclair BASIC having a CLEAR command, and I never questioned it until now.
|
|
ernie
New Member
Posts: 44
|
Post by ernie on Feb 2, 2020 2:39:57 GMT -5
I find that as a program increases in size and complexity, so does the chance of my mistakenly reusing a value believed to be in its initial state. And there are jobs where policing variables is not the best use of my time. Years ago I wrote a a CLEARing function into a LB program that went like this:
MYPROGRAM.BAS: (write to disk file any information that needs to survive the CLEAR) run "CLEAR.EXE" end
CLEAR.EXE: (wait a couple of seconds) run "MYPROGRAM.BAS (wait a couple seconds) end
MYPROGRAM.BAS: (read from disk the saved information)
Unconventional but it works.
|
|
|
Post by sarossell on Feb 2, 2020 2:47:30 GMT -5
Wow, yeah, that's hard core. Interesting approach though. Thanks!
|
|
|
Post by mpranger on Jan 14, 2022 2:26:18 GMT -5
I came here looking for a CLEAR command also. RESET would be nice to have too.
|
|
|
Post by Rod on Jan 14, 2022 3:43:21 GMT -5
Well if you read the thread the answer was no, it’s not coming, it isn’t needed and Sub EndSub wraps up variables, resets them and clears them on closure. So what you want is there just in another name.
|
|
|
Post by tsh73 on Jan 14, 2022 3:59:41 GMT -5
SUDDENLY I've got an idea.
we could make a program that * reads source code (never tried idecode$(). Then run from TKN, will it read current loaded source?) * gathers all variables - upper level only (skipping sub, functions) * output [clearVars] subroutine that ** sets all numeric vars to 0, and string ones to "" ** then returns
So we just append that block to main program and GOSUB [clearVars] then wanted.
I pretty sure we have ( * reads source code * gathers all variables ) parts, I should search my sources as well...
|
|
|
Post by colinmcm on Jan 14, 2022 4:58:32 GMT -5
From the era of 'clear' I also remember a 'chain' command.
Chaining a program meant calling from one program another program to replace it in memory (with no way back - prog2 removes prog1 from ram). However a few variables ( A...Z ??) remained unchanged in ram and accessible to the next program, which could therefore be used to transfer information between programs. Running a new program automatically cleared these A..Z variables, chaining did not. Therefore 'run prog2' starts with cleared variables, 'chain prog2' inherits variables from prog1, and 'clear : chain prog2' presumably does the same as 'run prog2'.
It was good practice, therefore, to use 'clear' at the start of program, to prevent the unwated inheritance of previously defined values A...Z, unless the program was designed to be used as a chained program. Similarly, it may have been polite to use 'clear' before the 'end' command, to tidy things up before the next program is started. My memory is hazy about that. - A little later on 'overlays' were used to swap parts of large programs in and out of memory.
Nowadays, programs are allocated a 'clean slate' by the operating system, so we have no need for 'chain' or for 'clear'. That is done automatically for us. If we want to pass information bettween programs now, we can use the command line, we can use files or pipes, or set environment variables (although perhaps not all of these are built in to LB).
|
|
|
Post by tsh73 on Jan 14, 2022 6:43:19 GMT -5
Colin, thanks for reminding good(?) old(*sigh*) days. Time flies by, but having easy way to pass data from running program to started TKN in LB would be nice.
I would say you are mixing different things * "don't have need" / "don't have means" * "we don't need" / "I don't need"
If means were here, some creative uses would spring up for sure.
|
|
|
Post by colinmcm on Jan 14, 2022 7:08:36 GMT -5
Yep, you are right. The means are no longer there, and 'SetEnv' and 'GetEnv' could be useful additions to LB.
|
|
|
Post by Brandon Parker on Jan 14, 2022 11:47:12 GMT -5
Yep, you are right. The means are no longer there, and 'SetEnv' and 'GetEnv' could be useful additions to LB. It would be nice if they were built-in, but until then you can use the functions listed in this post. libertybasiccom.proboards.com/post/9839As far as the other stuff goes, it could be done, but would it be worth it...? {:0) Brandon Parker
|
|
|
Post by klewlis on Jan 14, 2022 13:28:04 GMT -5
alincon : Any idea of a quick way to count the number of words in a string other than the obvious loop and incremented counter? I don't think there's a command for that. source$ = idecode$() for n = 1 to time$("ms") w$ = word$(source$,n) if w$ = "" then exit for next print n;" words total." not better or quicker, I am sure, but... mystring$ = "80% of First column generated by freeform, next three were copy/paste/modify. Fifth column was trial and error."
dim mynewstring$(100)
mynewstring$(0) = mystring$
for x = 1 to 100 mynewstring$(x) = after$(mynewstring$(x-1), " ") if instr(mynewstring$(x), " ") = 0 then exit for end if next x
numWords = x + 1
print numWords
wait
end
|
|