free software resistance
the cost of computing freedom is eternal vigilance
### fig4.txt
*original date:* jan 2017
*originally posted:* oct 2024
fig4.txt:
```
ive been working on the second version (or first non-draft version) of the 10-chapter fig manual, covering the entire language.
believe me, i understand that you can teach yourself coding in basic before age 7 (having done so myself) or python around the same age. the sugarlabs people suggest grade 3 for starting with python, but thats a generalization.
that being said, ive always wondered what basic if-- learning from the things that made basic easy enough for everyone to learn to code-- someone took out a few more things that made basic (or python) more complicated to teach. here are a few thoughts on that; you may not agree with all of them:
** while you can certainly make a case for them, sigils in basic like thisone$ for a string, make code a little more complicated.
* qbasic and freebasic make these optional (sometimes) by using the dim statement to declare strings, and freebasic doesnt require $ for built-in string functions.
* python (like a number of modern languages) has dynamic typing, so you can mix types in a type of array called a "list" and you can set the same variable to 5 or "5" or [5. "5"] (python uses square bracket notation for a list, compared to basics parentheses.)
** while basic treats an undeclared (even un-set) variable as 0 when referenced, enabling lines like "x = x + 1" to work before x is ever mentioned, programming is getting away from this as a bad practice.
* python doesnt require you to declare a variable (dynamic typing makes that pointless) but it does require you to set the variable to a value before referencing it.
* to encourage this practice, fig tries to make it easier. instead of doing this: x = 0 ; print x ...you can do this: x print
* instead of requiring a line number like early basic environments, fig requires that most lines (ploc) begin with a variable.
* a superfluous variable like x or p or "now" can be used on most lines, if it is not going to be referenced.
* but this variable (known as the "main variable") is not useless; it is the main work-area for the physical line of code, similar to a named pipe in bash.
* the main variable can be referenced (implicitly or explicitly) on its own line, and also on all lines that follow
for example:
x print # prints 0
x 5 print # prints 5
x 9
now = x times 17 colortext 4 str left 2 plus " apples!" ucase print ## prints "15 APPLES!" in red
note that logical lines of code (lloc) do not require separators, because all commands (except the one for defining functions, which is called "function") have a fixed parameter count.
many functions have zero parameters (str, print, ucase) and can reference and/or alter the main variable. some dont even do that: cls for example.
functions have a minimal parameter count-- when reasonable, the count is zero or one. the "longest" builtin function call is line, which has the familiar parameters: x1, y1, x2, y2, color
parameters also do not require separators. this can (depending on the audience, or skill level of the coder) create more confusion than simplification. rather than have mandatory syntax conventions, most of the syntax in fig is up to the coders preferences:
now = x times 17 colortext 4 str left 2 plus " apples!" ucase print ## prints "15 APPLES!" in red
now x : times 17 : colortext 4 : str : left 2 : plus " apples!" : ucase : print
python coders, javascript coders, and others in many english-speaking countries may prefer using semicolons to colons-- they dont require shifting:
now x ; times 17 ; colortext 4 ; str ; left 2 ; plus " apples!" ; ucase ; print ;
(you dont need the final ; of course.) and people who just love oop syntax can usually make it work pretty easily:
now := x.times(17).colortext(4).str().left(2).plus(" apples!").ucase.print()
note the pascal assignment operator (optional, of course.)
by making most syntax optional, fig encourages users to look at programming as a language more like any other written language. it has some very strict rules, but most punctuation for example does not have real syntactic/sematic meaning, except in terms of examples that are read by coders (rather than the computer.)
exceptions are:
"strings in quotes"
# hashes for comments-- ' was considered but # is compatible with bash and python, and was ultimately chosen for being ## easier to notice ## in code
decimals generally do what you they are supposed to: x=5.5;print # works
...usually: x=5.str.print # nope
x=(5).str.print # ok
x=(5.0).str.print # ok
optional punctuation allowed:
( ) : ; | = , .
currently _ seems to work in many cases, though it is not guaranteed to be allowed (figs de-facto "specification"/implementation/documentation doesnt cover its use) if syntax checking gets stricter.
** python is case-sensitive and mandates indentation. fig does neither.
* X "APPLE ][ COMPATIBLE! ...IN CASE YOU TELNET TO A SERVER RUNNING PYTHON OR SOMETHING."
** python (and some relatively obscure basic dialects, like smallbasic) let you append arrays using + the same way you can append strings with +
** instead of requiring dim to create an array, you convert a variable to an array (python list) type using arr (think of the str function, but for arrays.)
* x arr times 10000 ##### dim x(1 to 10000) 'in basic ##### x = [0,] * 10000 #in python
* what if you want strings?
* x "" arr times 10000
* instead of zeroing the array, pi every item: x 1 ; atn ; times 4 ; arr ; times 10000
* use mid to get an array item, just like you would for a string:
* x 1 atn times 4 ; arr ; times 100 ; print ; mid 5 1 ; print
* # set x to pi... array with 100 items... print it... get 5th item... and print that
* did we print the entire array with a single command? we did!
** fig has inline python, so if you want to transition to python you can.
* you can also define functions that contain inline python, so say you want a fig function that accesses the textblob library for um... semantic analysis...
function analyze text
python
from textblob import TextBlob
now = TextBlob(text).sentiment.polarity ; return now
fig
fig
paste that bit of python (and fig function definition) into your program, and now you can call it like other functions:
p "i know, its too sentimental"
x analyze p print # (sentiment analysis returns a negative 0.25)
p "but i like it!"
x analyze p print # (sentiment analysis returns 0.0 because everyone knows he cant get no satisfaction)
** fig functions work like functions in basic or python, except that (like in python and also in freebasic, optionally) if you dont use the return command, a "function" definition works like a sub-- calling it will not change the main variable. there is no "sub" command.
if you do leave the function with a return command, calling it will act like a function, and change the main variable. so the only difference between a sub and a function, is that function has (and thus changes) a value, and sub doesnt.
function clear
now cls
fig
x 5 clear print # prints 5
function clear
now cls return 9
fig
x 5 clear print # prints 9
** functions are easy to define, but fig does not have many to learn. if you want to expand fig, the easiest way is to learn (or have people share) enough extra functions that use inline python code, or to modify the fig translator to create a newer and more complicated version of the language.
* the way functions were chosen and added were, to add them only when not having them got too tedious. a version of fig would be used until the lack of a function got to be too much, then it was finally added to the next version.
* the first version of fig was probably 0.3 or 0.4, increasing one at a time to 0.9 then 1.0, all the way up until 2.9 (the 25th version or so.)
* 3.0 and 3.1 are python 3 based
* 4.0 and 4.1 go back to python 2, as the 3.x versions are a slight disappointment. hopefully in or before 2020, someone will fork python 2, or pypy will continue to support it through rpython.
* fig still has under 100 commands, if the user wishes to learn them all:
[code]commandname(parametercount):
timer arrstdin lineinput flineinput(1) time arropen(1) date
arrcurl(1) sleep(1) command print prints fprint(1) display
cls graphics textmode colortext(1) highlight(1) locate(2) pset(3)
line(5) while break for(4) forin(2) iftrue(1) ifequal(2)
ifmore(2) ifless(2) try except resume else function(1...)
get(1) python fig next nextin wend pass
lcase ucase str shell asc val len randint(2)
not ltrim rtrim chr arrshell arreverse reverse
arrsort # " . left(1) right(1) arrget(2)
arrset(2) mid(2) string(2) split(2) join(2) instr(2) chdir
system close end open(1) return(1) swap(2) plus(1) arr
minus(1) divby(1) times(1) oct hex cos sin
tan atn int sgn sqr mod(1) topwr(1)
[/code]
(this doesnt show in a fixed width font for me-- if you paste it into notepad, the spacing/column lineup is preserved.)
license: creative commons cc0 1.0 (public domain)
http://creativecommons.org/publicdomain/zero/1.0/
```
license: 0-clause bsd
```
# 2017 mn
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
```
=> https://freesoftwareresistance.neocities.org