From ef21239e2e6123e831cc5755e112a639f43d377c Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Mon, 30 Jan 2023 20:25:52 +0100 Subject: [PATCH 01/18] Update 643-language-elif.markdown --- _build/reference/643-language-elif.markdown | 26 ++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/_build/reference/643-language-elif.markdown b/_build/reference/643-language-elif.markdown index ee17d1e0..459a3110 100644 --- a/_build/reference/643-language-elif.markdown +++ b/_build/reference/643-language-elif.markdown @@ -2,6 +2,30 @@ > ELIF -foo = 2: if foo==1: ? "one": ELIF foo==2: ? "two": fi +Short for ELSEIF. + +### Example 1 + +~~~ +foo = 2 +if foo == 1 + print "one" +ELIF foo == 2 + print "two" +fi +~~~ + +### Example 2: using IF ... ELSE ... IF instead of ELIF + +~~~ +foo = 2 +if foo == 1 + print "one" +else + if foo == 2 + print "two" + fi +fi +~~~ From 23a64560ddea5460267f17dda0808cf08c1714aa Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Mon, 30 Jan 2023 20:36:23 +0100 Subject: [PATCH 02/18] Update 645-language-elseif.markdown --- _build/reference/645-language-elseif.markdown | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/_build/reference/645-language-elseif.markdown b/_build/reference/645-language-elseif.markdown index ae40f70c..67e90db7 100644 --- a/_build/reference/645-language-elseif.markdown +++ b/_build/reference/645-language-elseif.markdown @@ -2,6 +2,30 @@ > ELSEIF -foo = 2: if foo==1: ? "one": ELSEIF foo==2: ? "two": fi +Alternative condition in an IF statement. + +### Example 1 + +~~~ +foo = 2 +if foo == 1 + print "one" +ELSEIF foo == 2 + print "two" +endif +~~~ + +### Example 2: using IF ... ELSE ... IF instead of ELSEIF + +~~~ +foo = 2 +if foo == 1 + print "one" +else + if foo == 2 + print "two" + endif +endif +~~~ From 07929f7f2a70be3cf8fcc0638dad44397af5fec5 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sat, 25 Feb 2023 21:32:51 +0100 Subject: [PATCH 03/18] Update 644-language-else.markdown --- _build/reference/644-language-else.markdown | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/_build/reference/644-language-else.markdown b/_build/reference/644-language-else.markdown index e08b73cf..2c4e541b 100644 --- a/_build/reference/644-language-else.markdown +++ b/_build/reference/644-language-else.markdown @@ -2,6 +2,16 @@ > ELSE -foo = 2: if foo==1: ? "one": ELSE: ? "not one": fi +Part of an if ... then ... else statement. For more information see `IF`. +### Example + +``` +foo = 2 +if foo == 1 + print "one" +else + print "not one" +fi +``` From 1561022363340665727bba2eb5e3ecdd849a7e5d Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sat, 25 Feb 2023 21:41:24 +0100 Subject: [PATCH 04/18] Update 543-data-empty.markdown --- _build/reference/543-data-empty.markdown | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/_build/reference/543-data-empty.markdown b/_build/reference/543-data-empty.markdown index 1168cbdc..89318c36 100644 --- a/_build/reference/543-data-empty.markdown +++ b/_build/reference/543-data-empty.markdown @@ -2,11 +2,22 @@ > EMPTY (x) -Returns true if x is: a zero length array, an empty string, an integer or real with the value 0. +Returns true if x is +* a zero length array +* an empty string +* a number with the value 0. +### Example -* If x is a string, returns true if the len(x) is 0. -* If x is an integer or a real returns true if the x = 0. -* If x is an array, returns true if x is a zero-length array (array without elements). +``` +s = "" +a = [] +dim b +i = 0 +if(empty(s)) then print "s is empty" +if(empty(a)) then print "a is empty" +if(empty(b)) then print "b is empty" +if(empty(i)) then print "i is empty" +``` From 21032d6e136a19b483322b6f4046799862a436f2 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sat, 25 Feb 2023 21:51:14 +0100 Subject: [PATCH 05/18] Update 778-string-enclose.markdown --- _build/reference/778-string-enclose.markdown | 26 ++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/_build/reference/778-string-enclose.markdown b/_build/reference/778-string-enclose.markdown index 5aa78b39..f45b4fa5 100644 --- a/_build/reference/778-string-enclose.markdown +++ b/_build/reference/778-string-enclose.markdown @@ -2,23 +2,29 @@ > ENCLOSE (str[, pair]) -Encloses a string. +Encloses a string using the two characters in string `pair`. ENCLOSE defaults to double quotes if `pair` is not used. + +### Example 1: Enclose brackets ``` -? enclose("abc", "()") -' Result: (abc) +print enclose("abc", "()") ' output: (abc) ``` -ENCLOSE defaults to double quotes if the [pair] option is not used. - -~~~ +### Example 2: Enclose quotes using default setting +``` test=10 myStr="myStr" -? enclose(test) -? enclose(myStr) -pause +print enclose(test) ' output: "10" +print enclose(myStr) ' output: "myStr" +``` + +### Example 2: Enclose letters + +``` +test = 10 +print enclose(test, "aB") ' output: a10B +``` -~~~ From 21f87372ed6791cc82843fadf2879b8f83c4660a Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sat, 25 Feb 2023 21:54:59 +0100 Subject: [PATCH 06/18] Update 679-language-end.markdown --- _build/reference/679-language-end.markdown | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/_build/reference/679-language-end.markdown b/_build/reference/679-language-end.markdown index 1734f715..c0d67c17 100644 --- a/_build/reference/679-language-end.markdown +++ b/_build/reference/679-language-end.markdown @@ -4,4 +4,23 @@ Declares the END of a SUB or FUNC. +### Example 1: Sub +``` +sub MySub(a) + print a + 10 +end + +MySub(10) +``` + +### Example 2: Func + +``` +func MyFunc(a) + return a + 10 +end + +Result = MyFunc(10) +print Result +``` From 86ee30b0071b04b4c63d68891afbf741339168bd Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sat, 25 Feb 2023 22:29:43 +0100 Subject: [PATCH 07/18] Update 679-language-end.markdown --- _build/reference/679-language-end.markdown | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/_build/reference/679-language-end.markdown b/_build/reference/679-language-end.markdown index c0d67c17..1b5f475d 100644 --- a/_build/reference/679-language-end.markdown +++ b/_build/reference/679-language-end.markdown @@ -2,7 +2,7 @@ > END -Declares the END of a SUB or FUNC. +Declares the END of a SUB, a FUNC or the program. ### Example 1: Sub @@ -24,3 +24,18 @@ end Result = MyFunc(10) print Result ``` + +### Example 3: End of the program + +``` +while(1) + ii = ii + 1 + print ii + + if(ii == 5) then + end ' end program + endif + + delay(500) +wend +``` From c34e54e4b2768a1ba6b4f75ef4a097a41c78a929 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sat, 25 Feb 2023 22:33:10 +0100 Subject: [PATCH 08/18] Update 1427-language-endtry.markdown --- _build/reference/1427-language-endtry.markdown | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/_build/reference/1427-language-endtry.markdown b/_build/reference/1427-language-endtry.markdown index d8b67279..07a34a86 100644 --- a/_build/reference/1427-language-endtry.markdown +++ b/_build/reference/1427-language-endtry.markdown @@ -2,8 +2,6 @@ > END TRY -The END TRY statement marks the end of a TRY/CATCH block. - - +The END TRY statement marks the end of a TRY/CATCH block. For more information and examples please see TRY. From f9ad613c182c96deaf2af3ff4976791ebaa2293f Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sat, 25 Feb 2023 22:36:26 +0100 Subject: [PATCH 09/18] Update 646-language-endif.markdown --- _build/reference/646-language-endif.markdown | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/_build/reference/646-language-endif.markdown b/_build/reference/646-language-endif.markdown index b937d638..add2a9dd 100644 --- a/_build/reference/646-language-endif.markdown +++ b/_build/reference/646-language-endif.markdown @@ -2,6 +2,15 @@ > ENDIF -foo = 1: if foo==1: ? "one": ENDIF +ENDIF ends an if statement. For more information see IF. + +### Example + +``` +foo = 1 +if foo == 1 then + print "one" +endif +``` From 317be6d33a90c8c4f48cd771fcd60de8861e2f94 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 16:15:55 +0100 Subject: [PATCH 10/18] Update 807-system-env.markdown --- _build/reference/807-system-env.markdown | 150 +++++++++++------------ 1 file changed, 73 insertions(+), 77 deletions(-) diff --git a/_build/reference/807-system-env.markdown b/_build/reference/807-system-env.markdown index 49b73efa..42008b2d 100644 --- a/_build/reference/807-system-env.markdown +++ b/_build/reference/807-system-env.markdown @@ -2,85 +2,81 @@ > ENV expr -Adds a variable to or deletes a variable from the current environment variable-table. +Adds a variable to the current environment variable-table. -ENV can be used as SUB for setting or erasing Environment Variables (EV) and ENV can be used as a FUNCtion for returning a particular EV or the whole set of them into an array using: -EVarray=ENV("") +ENV can be used as SUB for setting and deleting Environment Variables and ENV can be used as a FUNCtion for returning a particular Environmet Variable or the whole set of them into an array. -~~~ +### Example 1: Setting and getting Evironment Variables -' ENV test.bas SmallBASIC 0.12.2 [B+=MGA] 2016-04-10 -'OK this works -'OK this is supposed to return an array of my Environment variables -EVS=ENV("") -for e in EVS - ? e -next -?:? "press any..." -pause -'wow it worked! I have a load of them... -'OK now try and set one of my own -cls -myEV1="This is a test of ENV." -ENV "myEV1="+myEV1 -'did it get added to list? -EVS=ENV("") -for e in EVS - ? e +``` +SB1 = 5 +SB2 = "My evironment variable" + +'Set Environmet Variables +ENV("SB1=" + SB1) +ENV("SB2=" + SB2) +ENV("SB3=6") +ENV("SB4=\"test\"") + +' Get Environment Variables +print ENV("SB1") +print ENV("SB2") +print ENV("SB3") +print ENV("SB4") +``` + +### Example 2: Querry all Environment Variables + +``` +AllEnv = ENV("") + +for a in AllEnv + print a next -?:? "press any..." -pause -'YES! -'OK let's see it -myEV1return=ENV("myEV1") -cls -? myEV1return -?:? "press any..." -pause -'now can we erase it? -ENV "myEV1=" -cls -? "myEV1 should be erased, it is now '";ENV("myEV1");"'" -?:? "Test of ENV is complete." -pause -'yes, it was erased because when I ran same code a second time, it wasn't there THEN! -' so it didn't just LOOK erased from a bad call - -~~~ - - -~~~ -ENV "myEV1=" -~~~ - does not erase the variable on Linux... -On Linux I could only erase the variable from a terminal: - -~~~ -unset $myEV1 -~~~ - -In general: -1. -Never use names which are already used by the system or another process, such as "PATH", "HOME", "PWD", etc. -You can check which variable names are already used, from SmallBASIC: - -~~~ -? Environ("") -~~~ - -2. -Use short and unique names, such as: "SB1", SB2" or "SBv1", "SBv2", etc. -It will keep the environment-variables-table readable, and will save space in the table. -3. -Don't create more variables then you need. Reuse any variable which is not used. -i.e. if "SB1" is unused anymore, then reuse it: -~~~ -Environ "SB1=5" -~~~ -. -Again, it keeps the environment-variables-table readable, and saves space in the table. -4. -On some systems the environment-variables-table is unique for each session (Linux for example) and this may be a bit confusing. -5. -Environment variables may or may not be case sensitive, i.e. "SB1" may be different then "sb1" on some systems (Linux for example). +``` + +### Example 3: (Linux) Querry DESKTOP_SESSION + +``` +print ENV("DESKTOP_SESSION") 'i.e will print "plasma" if using KDE +``` + +### Example 4: Delete a Environment Variable (doesn't work in Linux) + +``` +ENV("SB1=") ' Deletes SB1 +``` + +### Example 5: Using ENV and CHAIN to create a eval-function + +``` +' Dedicated to MGA. +' s is any legal SmallBASIC Math Expression as String, e.g. "1 + 2 / 4" +Func eval(s) + Chain "Env " + Enclose("SBEVAL=") + " + Str(" + s + ")" + eval = Val(Env("SBEVAL")) +End Func + +' now run few demos: +? eval("1+2") +? eval("Rad(45) * 2") +? eval("PI / 2 + PI") +? eval("0b1111 * Pow(2, 4)") +? eval("Sin(2) * Tan(4) / Cos(6)") +? eval("1 + 2 / 4") +? eval("6 * (Pow(2, 4) * 8)") +? eval("Rad((45 * 3) - 20) * 2") +``` + + +### General suggestions using Environment Variables + +1. Never use names which are already used by the system or another process, such as "PATH", "HOME", "PWD", etc. + You should check which variable names are already in use. +2. Use short and unique names, such as: "SB1", SB2" or "SBv1", "SBv2", etc. + It will keep the environment-variables-table readable, and will save space in the table. +3. Don't create more variables then you need. Reuse any variable which is not used. + i.e. if "SB1" is unused anymore, then reuse it. +4. On some systems the environment-variables-table is unique for each session (Linux for example) and this may be a bit confusing. +5. Environment variables may or may not be case sensitive, i.e. "SB1" may be different then "sb1" on some systems (Linux for example). From 350a87faee3fd187c74bcc6d528afd34dd9f5712 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 16:18:33 +0100 Subject: [PATCH 11/18] Update 815-system-env.markdown --- _build/reference/815-system-env.markdown | 115 ++++++++++++++--------- 1 file changed, 73 insertions(+), 42 deletions(-) diff --git a/_build/reference/815-system-env.markdown b/_build/reference/815-system-env.markdown index e6af1899..d107873b 100644 --- a/_build/reference/815-system-env.markdown +++ b/_build/reference/815-system-env.markdown @@ -1,51 +1,82 @@ # ENV -> ENV expr +> result = ENV(expr) -Returns the value of a specified entry in the current environment table. If the parameter is empty ("") then returns an array of the environment variables (in var=value form). +Reads an Environment Variable from the current environment variable-table. -ENV can be used as SUB for setting or erasing Environment Variables (EV) and ENV can be used as a FUNCtion for returning a particular EV or the whole set of them into an array using: -EVarray=ENV("") +ENV can be used as SUB for setting and deleting Environment Variables and ENV can be used as a FUNCtion for returning a particular Environmet Variable or the whole set of them into an array. -~~~ +### Example 1: Setting and getting Evironment Variables -' ENV test.bas SmallBASIC 0.12.2 [B+=MGA] 2016-04-10 -'OK this works -'OK this is supposed to return an array of my Environment variables -EVS=ENV("") -for e in EVS - ? e -next -?:? "press any..." -pause -'wow it worked! I have a load of them... -'OK now try and set one of my own -cls -myEV1="This is a test of ENV." -ENV "myEV1="+myEV1 -'did it get added to list? -EVS=ENV("") -for e in EVS - ? e +``` +SB1 = 5 +SB2 = "My evironment variable" + +'Set Environmet Variables +ENV("SB1=" + SB1) +ENV("SB2=" + SB2) +ENV("SB3=6") +ENV("SB4=\"test\"") + +' Get Environment Variables +print ENV("SB1") +print ENV("SB2") +print ENV("SB3") +print ENV("SB4") +``` + +### Example 2: Querry all Environment Variables + +``` +AllEnv = ENV("") + +for a in AllEnv + print a next -?:? "press any..." -pause -'YES! -'OK let's see it -myEV1return=ENV("myEV1") -cls -? myEV1return -?:? "press any..." -pause -'now can we erase it? -ENV "myEV1=" -cls -? "myEV1 should be erased, it is now '";ENV("myEV1");"'" -?:? "Test of ENV is complete." -pause -'yes, it was erased because when I ran same code a second time, it wasn't there THEN! -' so it didn't just LOOK erased from a bad call - -~~~ +``` + +### Example 3: (Linux) Querry DESKTOP_SESSION + +``` +print ENV("DESKTOP_SESSION") 'i.e will print "plasma" if using KDE +``` + +### Example 4: Delete a Environment Variable (doesn't work in Linux) + +``` +ENV("SB1=") ' Deletes SB1 +``` + +### Example 5: Using ENV and CHAIN to create a eval-function + +``` +' Dedicated to MGA. +' s is any legal SmallBASIC Math Expression as String, e.g. "1 + 2 / 4" +Func eval(s) + Chain "Env " + Enclose("SBEVAL=") + " + Str(" + s + ")" + eval = Val(Env("SBEVAL")) +End Func + +' now run few demos: +? eval("1+2") +? eval("Rad(45) * 2") +? eval("PI / 2 + PI") +? eval("0b1111 * Pow(2, 4)") +? eval("Sin(2) * Tan(4) / Cos(6)") +? eval("1 + 2 / 4") +? eval("6 * (Pow(2, 4) * 8)") +? eval("Rad((45 * 3) - 20) * 2") +``` + + +### General suggestions using Environment Variables +1. Never use names which are already used by the system or another process, such as "PATH", "HOME", "PWD", etc. + You should check which variable names are already in use. +2. Use short and unique names, such as: "SB1", SB2" or "SBv1", "SBv2", etc. + It will keep the environment-variables-table readable, and will save space in the table. +3. Don't create more variables then you need. Reuse any variable which is not used. + i.e. if "SB1" is unused anymore, then reuse it. +4. On some systems the environment-variables-table is unique for each session (Linux for example) and this may be a bit confusing. +5. Environment variables may or may not be case sensitive, i.e. "SB1" may be different then "sb1" on some systems (Linux for example). From 70d806c38a7cbefadf9e2e35d13e9578b9a55555 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 16:24:39 +0100 Subject: [PATCH 12/18] Update 603-file-eof.markdown --- _build/reference/603-file-eof.markdown | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/_build/reference/603-file-eof.markdown b/_build/reference/603-file-eof.markdown index 08f45aae..f569cf63 100644 --- a/_build/reference/603-file-eof.markdown +++ b/_build/reference/603-file-eof.markdown @@ -4,4 +4,53 @@ Returns true if the file pointer is at end of the file. For COMx and SOCL VFS returns true if the connection is broken. +### Example 1: Reading data from a file +``` +' create a text file +open "MyDemoFile.txt" for output as #1 + +for i = 1 to 10 + print #1, i +next + +close #1 + +' open text file and print content line by line +open "MyDemoFile.txt" for input as #1 + +while(!eof(1)) ' eof works only without # + input #1, c + print c +wend + +close #1 +``` + +### Example 2: Reading from a TCP/IP socket + +``` +rem Print a date string like '29 SEP 2018 09:31:49 ACST' +func get_time + local today = julian(date) + local start = timer + local t_hour, t_min, t_sec, t_str + timehms start, t_hour, t_min, t_sec + rem TODO, format should support multiple arguments + t_str = format(" ##:", t_hour) + format("##:", t_min) + format("##", t_sec) + return datefmt("dd mmm yyyy", today) + t_str +end + +while 1 + open "SOCL:8080" as #1 + while (not eof(1)) + lineinput #1, s + if (s == "time") + print #1, get_time + else + print #1, "unknown command" + endif + wend + close #1 +wend +``` From 1b963e8f28d35050c2f961cf115df21157eb2fdc Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:05:03 +0100 Subject: [PATCH 13/18] Update 665-language-eqv.markdown --- _build/reference/665-language-eqv.markdown | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/_build/reference/665-language-eqv.markdown b/_build/reference/665-language-eqv.markdown index d5b40d01..22da5a89 100644 --- a/_build/reference/665-language-eqv.markdown +++ b/_build/reference/665-language-eqv.markdown @@ -4,5 +4,40 @@ Bitwise equivalence. -EQV and IMP manipulating only the lower 4 bits +Truth table: + +| a | b | a EQV b | +|:-:|:-:|:-------:| +| 0 | 0 | 1 | +| 0 | 1 | 0 | +| 1 | 0 | 0 | +| 1 | 1 | 1 | + +### Example 1: Print truth table + +``` +print "0 eqv 0 = " + bin(0 eqv 0) +print "0 eqv 1 = " + bin(0 eqv 1) +print "1 eqv 0 = " + bin(1 eqv 0) +print "1 eqv 1 = " + bin(1 eqv 1) +``` + +### Example 2: Bitwise equivalence of two numbers + +``` +a = 0b110010011111000010101011 +b = 0b101010010101011100010101 + +print " " + bin(a) +print "EQV " + bin(b) +print "----------------------------" +print " " + bin(a eqv b) + +' Output: +' +' 110010011111000010101011 +' EQV 101010010101011100010101 +' ---------------------------- +' 100111110101100001000001 +``` From 7d2ac1614bcf65fb5f1d83f9003435577d8af259 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:17:02 +0100 Subject: [PATCH 14/18] Update 571-data-erase.markdown --- _build/reference/571-data-erase.markdown | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/_build/reference/571-data-erase.markdown b/_build/reference/571-data-erase.markdown index 6ed45181..78fcd4d1 100644 --- a/_build/reference/571-data-erase.markdown +++ b/_build/reference/571-data-erase.markdown @@ -4,12 +4,16 @@ Deallocates the memory used by the specified arrays or variables. After that these variables turned to simple integers with zero value. +### Example + ``` DIM x(100) -... -PRINT FRE(0) + +x(1) = 1 +x(2) = 2 + ERASE x -PRINT FRE(0) -PRINT x(1):REM ERROR + +PRINT x(1) ' This will create an error ``` From 6876e39f046863413fed73d318eb834fd949433b Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:39:25 +0100 Subject: [PATCH 15/18] Update 1443-system-exec.markdown --- _build/reference/1443-system-exec.markdown | 69 +++------------------- 1 file changed, 9 insertions(+), 60 deletions(-) diff --git a/_build/reference/1443-system-exec.markdown b/_build/reference/1443-system-exec.markdown index d2db3a74..ba4e4bb4 100644 --- a/_build/reference/1443-system-exec.markdown +++ b/_build/reference/1443-system-exec.markdown @@ -2,67 +2,16 @@ > EXEC file -Transfers control to another operating system program. +Transfers control to another operating system program. Control returns to the .bas immediately and the system command is executed parallel and independent to SmallBASIC. File name is case sensitive in Linux. -~~~ +See `run` for starting an external program and wait until program finished execution. -Const IS_LINUX = (Left(HOME, 1) = "/") ' Check if it's Linux system -Const IS_WINDOWS = Not IS_LINUX -Const FILE_NAME = "demo.bas" ' demo file name - -' Print header before each mission: -Sub header(text) - ? Cbs("\\n\\n" + Cat(0) + Cat(3) + Enclose(text, " ") + Cat(0) + Chr(7)) - Pause -End Sub - -' Create demo SmallBASIC file: -code << "Color 15, 1: ? " + Enclose("Hello World") + ": Pause" ' append line -Tsave FILE_NAME, code - -' CHAIN(source) -' -' Compile and run the given source. Source can be a file name, a line of code -' or an array of code. Use ENV to share variables with the parent process. -header "Press a key to Chain another SB program and return afterwards..." -Chain FILE_NAME ' Chain only executes another SmallBASIC code. - -' RUN(command) ' invoked as a COMMAND -' x = RUN(command) ' invoked as a FUNC, returning the results of the sub process -' -' With both of these, control returns to the .bas once system 'command' -' has completed. -header "Press a key to Run another program and return afterwards..." -Select Case 1 - Case IS_LINUX: Run "gedit " + FILE_NAME - Case IS_WINDOWS: Run "Notepad " + FILE_NAME -End Select -? "OK." - -' EXEC(command) -' -' Invoked as a COMMAND, control returns to the .bas immediately and the -' system command does it's own thing external to SmallBASIC: -header "Press a key to Execute another program in the background..." -Select Case 1 - Case IS_LINUX: Exec "gedit" - Case IS_WINDOWS: Exec "Notepad" -End Select -? "Done."; -Pause - -~~~ - -Apparently, RUN/EXEC have bugs in SmallBASIC version 0.12.2...: - -RUN/EXEC - -There are three modes: -1. RUN(command) ' invoked as a COMMAND -2. v=RUN(command) 'invoked as a FUNC, returning the results of the sub process -With both of these, control returns to the .bas once system 'command' has completed. -3. EXEC(command) 'invoked as a COMMAND, control returns to the .bas immediately and the system command does it's own thing external to SmallBASIC. - -Note: In the android version you can use v=RUN to look at interesting things in the /proc file system. +``` + ' Select your editor for testing +exec "kate" ' Editor KDE +'exec "gedit" ' Editor Gnome +'exec "Notepad" ' Editor Windows +print "This line will be printed immediately without delay" +``` From c55bdd451213a0ccb98c4563174cb8bd45ad3aac Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 20:01:37 +0100 Subject: [PATCH 16/18] Update 604-file-exist.markdown --- _build/reference/604-file-exist.markdown | 31 ++++++------------------ 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/_build/reference/604-file-exist.markdown b/_build/reference/604-file-exist.markdown index caa98315..408501a5 100644 --- a/_build/reference/604-file-exist.markdown +++ b/_build/reference/604-file-exist.markdown @@ -5,28 +5,13 @@ Returns true if file exists. -~~~ - -' Return nonexisting file or directory name (12 A..Z letters + extension) -' in the current directory; e.g. filename = tempfile("-me.tmp") -Func tempfile(ext) - Local i, f = Space(12) + ext - Repeat - For i = 1 To 12 - f = Replace(f, i, Chr(floor((Rnd * 25.5) + 65))) - Next - Until Not Exist(f) - tempfile = f -End Func -' demo: -filename = tempfile(".bak") -a << "This is a backup file: " + filename ' append one line -Tsave filename, a -Tload filename, b -? b -Pause -Kill filename ' delete demo file - -~~~ +### Example + +``` +if(exist("test.bas")) then + print "test.bas exists" +endif +``` + From a005a0ce6cd8b4b01a33246bc2c1cc92eee05209 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 20:10:23 +0100 Subject: [PATCH 17/18] Update 648-language-exit.markdown --- _build/reference/648-language-exit.markdown | 44 ++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/_build/reference/648-language-exit.markdown b/_build/reference/648-language-exit.markdown index 57ea3abb..d747f29b 100644 --- a/_build/reference/648-language-exit.markdown +++ b/_build/reference/648-language-exit.markdown @@ -4,10 +4,52 @@ Exits a multi line function definition, a loop, or a subprogram. By default (if no parameter is specified) exits from last command block (loop, for-loop or routine). - * FOR - Exit from the last FOR-NEXT loop * LOOP - Exit from the last WHILE-WEND or REPEAT-UNTIL loop * SUB - Return from the current routine * FUNC - Return from the current function +### Example 1: for + +``` +for i = 1 to 100 + print i + exit for +next + +' Output: 1 +``` + +### Example 2: while + +``` +while(i) + i++ + print i + exit loop +wend + +' Output: 1 +``` + +### Example 3: sub + +``` +sub MySub(a) + exit sub + print a +end + +MySub(10) ' No output, because print in MySub will not be reached +``` + +### Example 4: func + +``` +func MyFunc(a) + exit func + return a + 10 +end +print MyFunc(10) ' Output: 0, because return command in MyFunc will not be reached +``` From c15f1f4d6826c61994b5c20dd67f2d83a0e660d0 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 26 Feb 2023 20:18:16 +0100 Subject: [PATCH 18/18] Update 1440-system-export.markdown --- _build/reference/1440-system-export.markdown | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/_build/reference/1440-system-export.markdown b/_build/reference/1440-system-export.markdown index e178cf7d..f86efb6b 100644 --- a/_build/reference/1440-system-export.markdown +++ b/_build/reference/1440-system-export.markdown @@ -4,4 +4,26 @@ Export a SUB, FUNC or variable from a UNIT to be used by the unit consumer. +See `UNIT` for more information. + + +### Example: Create an unit + +``` +UNIT MyTestUnit + +export const my_pi = 3.145 +export my_two_pi = 6.29 +export MyFunc +export MySub + +func MyFunc(a) + return a + 10 +end + +sub MySub(a) + print a + 10 +end +``` +