Bonum Certa Men Certa

How To Write fig Programs

By figosdev

Young programmer



Summary: This is the second in a two-part series on fig

This is the second in a two-part series on fig, an educational language that I use for other practical purposes.



Because I designed fig for computerphobes, you may decide it has a few odd qualities. One example is that it uses a "plus" command instead of + and a "minus" command instead of -. It also has an inline Python feature, which can be used to import Python functions into fig programs, as well as allow more traditional expressions to be evaluated, if you prefer:

python
    import math
    evaluated = math.sqrt(p ** int(s / 2.5))
    fig


Fig has its own function definition command, which you can use to create functions with Python-like scope:

function greet whom
    now = "Hello, " plus whom ; print
    fig


Fig is the standard command that in Python would be unindenting, and it is named for "return to fig programming" after inline Python. In most instances, you can use "next" if you prefer:

function greet whom
    now = "Hello, " plus whom ; print
    next


You can use this as a wrapper around a python feature like this:

function pi
python
    from math import pi as ppi ; return ppi
    fig
    fig   



r = 50 circumference = pi times 2 times r ; print


In fig, the only mandatory punctuation in syntax is "quotes for strings" and # hashes for comments. Decimal points work the same way they do in Python.

These characters are optional, and for the most part can be freely used to help visually organise your code: = ( ) | ; : ,

The vertical bar can be used to introduce students to Bash. With the exception of a few commands that start on their own line -- such as for, next, forin, ifmore, ifless, iftrue, ifequal, else, break, while, wend -- nearly all fig commands share a line with a variable on the far left:

height = 60 ; plus 5 ; str ; len ; print


height is 60, it adds 5 to become 65, is converted to a string: "65" then the length is found, and 2 is printed to the screen.

As in Python, there are a few ways to create arrays:

titles = "" ; arr ; times 100


This will create an array of 100 string items. you can add items like this:

titles plus "A History of Red Hat: From Cottage Industry to Corporation"


Each time a variable is used on the left, it is set to 0-- arrays are the exception:

now 5 print # prints 5
now print # prints 0
now 5 arr 
now print # prints [5]


You can create an array using split:

ingredients = "milk eggs sugar flour water" ; split ingredients " "


Unlike Python, split and join both put the variable to split or join first -- then the thing to split or join it with:

ingredients = "milk eggs sugar flour water" ; split ingredients " "
ingredients = join ingredients " " ; print


Arrays are 1-based (apologies purists, it's an educational language) and for loops are started with count-variable, start-var, stop-var, step-var:

ingredients = "milk eggs sugar flour water" ; split ingredients " "
howmany = ingredients ; len
for each, 1, howmany, 1
    now = each ; print
    next


Forin loops are started with value-tracking-variable, array:

ingredients = "milk eggs sugar flour water" ; split ingredients " "
forin each, ingredients
    now = each ; print
    next


(nextin can be used instead of next)

Files can be opened with arropen, and webpages with arrcurl:

urls = arropen "urls.txt"
buffer = arr ; mid 1 0 # zero-length array
newline = 10 ; chr 



forin each urls iftrue each geteach arrcurl each ; join geteach newline buffer plus geteach fig nextin


Failed downloads create an error, so add error trapping (no, this is not how you should do this in python -- it is just a simple introduction to error trapping)

try
        geteach arrcurl each ; join geteach newline
        buffer plus geteach
except
        geteach ""
        resume


Finally, you can open geany using fig:

openleafpad = "leafpad &" shell


Or get the output of shell commands into an array:

textfiles = "ls *.txt" arrshell


To compile your fig program, give it a .fig extension and run it this way:

$ fig46.py program.fig



$ ./program.fig.py


To get help on a command, type part of it into the help feature:

$ fig46.py help
print


It will return all commands containing "print" in the name. hit enter instead to list all commands.

This will not work:

$ fig46.py help print


This will:

$ echo print | fig46.py help


All commands:

$ echo | fig46.py help


Fig is based on Python 2 -- as much as the Python Foundation is trying to kill Python 2, I think it is a much friendlier language than the latest Python.

PyPy is Python 2 compatible, and is the interpreter fig will most likely to be paired with in the future. There are two factors being waited on: PyPy is planning to support Pygame (an optional component for fig that lets it do real graphics) and Python 2 is still supported by many distros, not least of all Debian, Devuan and Refracta.

The Python Foundation will officially drop Python 2 on January 1. If you love it anyway, try PyPy.

To make fig use PyPy instead, change the two lines that contain the string "env python2" to "env pypy" and that should do it. You can download fig 4.6 here.

Happy Coding!

Licence: Creative Commons cc0 1.0 (public domain)

Recent Techrights' Posts

Pushers of systemd Rewrite History (Richard Stallman Said UNIX "Was Portable and Seemed Fairly Clean")
Unlike systemd
Trajectory of The Register: From News Site/s Into "B2B"... and Into Microsoft Salespeople
Something isn't right at The Register
 
The Week to Come
Planning ahead
LLM Slop Has Only Been a Boon for Misinformation Online
The very same companies that were supposed to maintain quality (again, not limited to Google with PageRank) are now actively participating in generating and spreading slop
When They Tell You It's Free, Does That Mean No Charges (If So, Who's Paying and Why)?
there's "no free lunch"
We're Going to Focus Less on the Molotov Cocktail-Throwing Microsofters and More on Patents
We can get back to focusing on what we wanted to focus on all along
Just Trying to Keep Web Sites Honest (Journalistic Integrity)
the latest articles in LinuxIac are real
Links 27/07/2025: Political Affairs, Data Breaches, Attacks on Freedom of the Press
Links for the day
Gemini Links 27/07/2025: Hot in Japan and Terminal Escape Codes
Links for the day
Links 27/07/2025: More Microsoft Layoffs Coming, Science and Hardware News
Links for the day
Links 27/07/2025: FSF Hackathon and "Hulk Hogan Was a Very Bad Man"
Links for the day
Gemini Links 27/07/2025: DAW Mixer Chains and Simple Software
Links for the day
The Register MS is Inventing or Giving Air Time to New Conspiracy Theories so as to Distort the Narrative As High-Profile Agencies Fall Prey to Microsoft Holes
But the problem is holes, i.e. Microsoft making bad products; the problem is Microsoft
Most Editors at The Register Are American, Including the Editor in Chief, a Decade-Long Microsoft Stenographer (Writing Prose to Sell Microsoft)
It's not easy to tell where the site is based (we tried) because it's hiding behind ClownFlare and CrimeFlare hasn't been well lately
"New Techrights" Soon Turns 2 (A Few Days Before the FSF Turns 40)
We have a lot more to say about LLM bots
When Silence Says So Much
Garrett, a 'secure' boot pusher, will need to defend himself in the UK High Court
The Register in Trouble
There is not much that can be done at this point
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Saturday, July 26, 2025
IRC logs for Saturday, July 26, 2025
Misinformation in Social Control Media
Social control media passes around all sorts of tropes
Slopwatch: Fake Linux 'Articles' and Slopfarms With "Linux" in Their Names/Domains
throwing bots at "Linux" to make some fake articles
Links 26/07/2025: Amazon Shutdown in China, Russian Economy Slows
Links for the day
Gemini Links 26/07/2025: History of Time (1988) and Gemini Games
Links for the day
Links 26/07/2025: 50 Percent Tariffs in Amazon, Dying Intel Offloads Network and Edge Group (NEX)
Links for the day
Doing My Share to Tackle Online Slop and SPAM
Trying my best to 'fix' the Web
Blaming Programming Languages for Users' and Developers' Bad Practices
That's like blaming cars for drivers who crash into things
Slopwatch: Fakes, FUD, Duplicates, and Charlatans Galore
The Web as we once know it is collapsing. Some opportunists try to replace it with low-quality slop.
The Register UK Seems to Have Become American and Management is Changing (Microsofter as Editor in Chief)
The Register 'UK' is now controlled by the Directions on Microsoft guy
Many People Still Read Techrights Because It Says the Truth, Produces Evidence, and Does Not Self-Censor
Unlike so many other sites
The Register is Desperate for Money, According to The Register
I decided to check how they're doing as a business
Microsoft Finally Finds a Use Case for Slop?
Create low-quality chaff to shift the media's attention?
Microsoft Windows Lost 400 Million Users in a Few Years, Why Does The Register Double Down on Windows With New US Editor?
days ago they hired a new US editor
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Friday, July 25, 2025
IRC logs for Friday, July 25, 2025
For Libel Reform One Must First Bring (or Raise) Awareness to the Issues and Their Magnitude
I myself know, from personal experience
Links 26/07/2025: Rationed Meals in the US and TikTok Repels Investments (Too Toxic)
Links for the day
Gemini Links 26/07/2025: "Bloody Google" and New People in Geminispace
Links for the day
Response to Solderpunk (Father of Gemini Protocol) About the Gemini Community
Solderpunk responds to non-sequitur
HTML and the Web Used to be Something a Child Could Learn, "Modern" Web is a Puzzle of Frameworks, Bloat, and Worse
When the Web was more like Gemini Protocol
New US Editor in The Register is 84% Microsoft/Windows Booster
It'll be worrying if it carries on like this
Links 25/07/2025: Slop Blunders and China Has Code of Conduct for Lawmakers in HK
Links for the day
Gemini Links 25/07/2025: Some Books and Babies and Capital
Links for the day
Links 25/07/2025: NOAA Cuts Endanger Lives, "Europe's Self Inflicted Cloud Crisis"
Links for the day
They Try to Lecture Us on Ethics
They even removed "master" from Microsoft GitHub
The Future of the Web is One Rendering Engine or 'Flavours' of Chrome
The future of the Web does not look bright at all
Best Sites Are Not Optimised for Any Browser, They Work Equally Well With All of Them
Red Hat (IBM) is making rubbish sites
YouTube is a Spamfarm, Slopfarm, and Clickfarm (a Lot of Numbers There Are Fake)
Those who don't fake look unpopular and unimportant
We Don't Do JavaScript and Pages Are Small
Thankfully Gemini Protocol has nothing like JavaScript
'Tech' is Not Technology
Some people use terms like 'Old Tech'
IBM's Debt Rose by Almost 10 Billion Dollars in the Past 6 Months Alone
The "hey hi" circus is coming to an end
Yes, Master
Gaslighting by actual racists
Microsoft Bribes and Buys Politicians to Tell Europe What to Do About Free Software (Which It's Attacking)
Microsoft: we speak for the thing that we are attacking! Follow the money...
Making Backups Quickly and Reliably
Backups are imperative, more so in an age of uncertainty, unpredictable weather, and worsening standards (quality of products going down while prices go up)
Techrights Investigation: Estimating the Point in Time LinuxIac Turned Into LLM Slop (Part of the Time)
Bobby Borisov got lazy
10th Month, Ten Weeks From Now, at Ten AM
In Wentworth Institute of Technology in Boston
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Thursday, July 24, 2025
IRC logs for Thursday, July 24, 2025
A Nadella Memo Distracts From Microsoft's Cheapening Of the Workforce
Right now the "MSM" (mainstream media) is flooded/overwhelmed by garbage pieces that relay lies for Nadella
Vanishing Faces of GNU/Linux
Free software projects do not depend on any one person or company to still exist
Microsoft Says It Lost 400 Million Windows Users, Now It's Waiting for GNU/Linux to Stop Booting on 'Old' PCs
When it comes to Windows, Microsoft is fully aware of the issue and statements it made earlier this summer suggest it lost 400 million Windows users
Slopwatch: LinuxTechLab, linuxsecurity.com, LinuxIac, and More
Also: The Register's Microsoft agenda (new editor)
Gemini Links 25/07/2025: Gemtext Aware Titan Editor and Gemini Protocol Comeback
Links for the day