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

Links 16/05/2026: Climate Issues, Free Speech, and Monopolies/Monopsonies
Links for the day
 
Links 16/05/2026: Cuba Plunges Into Darkness (Energy Wasted by Nonsense), Googlebooks as Slop Nonsense (Energy Waste and Time Wasted)
Links for the day
Gemini Links 16/05/2026: Retreat and Devuan Manuals
Links for the day
SLAPP Censorship - Part 78 Out of 200: Slandering Me for Saying the Truth About Graveley and Garrett's Abuse of Processes, Stacking Dockets
These are the sorts of things British taxpayers ought to talk about
"AI" Became a New Name or Placeholder for Debt
Because they will only ever lose money for this thing with "tokens" or "potential"
"Microsoft Goodwill and Intangible Assets" Down Two Years in a Row, According to Microsoft
Microsoft cannot sell these, so what is their real relevance?
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Friday, May 15, 2026
IRC logs for Friday, May 15, 2026
IBM: Shares Down 30%, Mass Layoffs, IBM Says "Goodwill" Grew by 10% to Over a Third of the Company's Total "Worth"
According to IBM
Microsoft LinkedIn Layoffs "Very Likely Higher" Than 1,000 People
Microsoft is bleeding
The Corrupt Lecture the Non-Corrupt - Part XXIV - Luis Berenguer Giménez at the EPO (European Patent Office) Became the Punchline of EPO Staff
"the fact that Luis was caught with cocaine causes laughter. The use of cocaine in itself is not the real shocking bit."
IBM Keeps Culling Essential Linux, Fedora, GNOME, and GTK Staff
Over a month ago IBM laid off over 400 Red Hat engineers
Cisco Cuts Nearly 4,000 Jobs Because of Debt, Nothing to Do With Slop
The media keeps talking about revenue, not profits
Gemini Links 15/05/2026: UDP Game Forwarding Over SSH, Avoiding LLMs, and Alhena 5.5.9
Links for the day
Links 15/05/2026: Electric Company Shuns Entire Town to Prioritise Only Data Centres, Saudi Arabia and U.A.E. Carried Out Secret Attacks in Iran
Links for the day
LLM Slop is Not Reliable, Constitutes No Process of 'Thinking'; There's No Thought Process at All, No Grasp or Understanding, Let Alone Context
Lies have become the "business model" [...] More people ought to talk about it and explain to other people what LLMs really are
Not a Security Expert If You Cannot Manage to Keep Online a Simple Two-User Mastodon Instance Somebody Else Built
From uptime of ~99% to maybe 80%
Microsoft Has All the Symptoms of a Dying Company (Mass Layoffs of the People Who Built the Company)
the company's debt is going through the ceiling
Focus is Important, Focus is Everything
We are still running 6 multi-part series in tandem
For Effective 'Finlandisation' (Not Digital Sovereignty) to Be Replaced by Autonomy Finland Needs to Think Like GNU (Software Freedom), Not Linux (Openwashing Source, Plus LLM Slop and Killswitches)
What is 'Finlandisation'?
Guest Post on False Marketing and PR Blitzes by Anthropic
A lot of people my age are just tired of the nonsense
Links 15/05/2026: UK antitrust regulator is officially investigating Microsoft Office, Anthropic’s Fraudulent Lies About Mythoslop Don't Withstand Scrutiny
Links for the day
IBM's Kyndryl in Trouble: Mass Layoffs, Payroll Problems, Buybacks (in Company Whose Debt is Almost Twice Its Total Value), and Soon $9 Per Share (Down Over 80%)
Kyndryl is done. Stick a fork in it.
ICYMI: GNU/Linux Did Not Start in Finland
If we're honest/true to ourselves, we need to recognise history for what it is, not what some corporations (like GAFAM) want it to be
IBM is Googlebombing the Media With Fake Numbers to Promote Fake Technology
a classic example of why much of today's media cannot be trusted (anymore)
Up to 10,000 Microsoft Layoffs in a Couple of Months
Many ways to skin a cat
Truth Hurts. People Hurt by Truth Aren't Entitled to Compensation.
Family members aren't exempt
SLAPP Censorship - Part 77 Out of 200: They Never Knew How to Handle Women (Except to Attack Them)
The case against us was really quite simple
Update on Sirius Open Source in 2026 (When Your Former Employer Commits Crimes and Nobody is Held Accountable)
I did not envision myself spending several years (even 4 years after leaving that company) challenging the system for tolerating and even covering up corruption
Codecs and Software Patents - Part VII - Entering Phase II, the Battle Against Companies That Normalise Taxed (by Patents on Mathematics) Codecs
In the next few part we'll deal with the impact on Free software, including the GNU Project
The Corrupt Lecture the Non-Corrupt - Part XXIII - Cocaine Use at the EPO's Top-Level Management "Adds Up" and Worsens Things "Over Time"
"cocaine use knocks the IQ down permanently a tiny bit with each use. Over time that adds up."
Gemini Links 15/05/2026: Slop Fatigue and Banning LLM Use
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Thursday, May 14, 2026
IRC logs for Thursday, May 14, 2026
Links 14/05/2026: Health Science, Cheeto Meets Pooh, and Facebook Staff Loathing the CEO
Links for the day
Gemini Links 14/05/2026: Early Morning Practice and Number to Roman Numeral Converter
Links for the day
FSF Advertises the Father of Software Freedom Giving a Talk in Germany (a Digital Sovereignty Interest Hub, Sponsor of Free Software)
Free Software vs malware and the need for reverse engineering
Cybershow (UK) Shaping Up to be a Neat and Very Large Gemini Capsule
If only more platforms did the same, plenty of energy would be spared, "old" machines would be totally suitable (even with 20 tabs open), as we'd focus on substance, not bells and whistles
SLAPP Censorship - Part 76 Out of 200: The Problem With the United Kingdom Allowing Americans to File Lawsuits by Proxy (Relayed by "Hired Guns")
Solicitors in UK warned not to act as ‘hired guns’ to silence critics of super-rich
When Microsoft's LinkedIn Goes Offline All Your Fake Friends/Connections and Manufactured 'Status' Will be Gone
Many people quit social control media because they recognise it for what it truly is
Major Setback for IBM in the Courtroom, the Demolition of IBM is Proving Costly
Kyndryl is a sign of how IBM ("mother ship") is run and where IBM is heading
Links 14/05/2026: Willful Ignorance and Mass Layoffs at Microsoft
Links for the day
Gemini Links 14/05/2026: Rewatching V for Vendetta, JPEG XL, and Platform Migrations
Links for the day
The Corrupt Lecture the Non-Corrupt - Part XXII - What the Science Says About Cocaine in the Workplace (EPO President, Mr. Campinos, Please Take Note)
What the science says
European Patent Office (EPO) President, Mr. Campinos, Ignoring Its Staff While Protecting His Friends
the President is covering up cocaine use while ignoring his own workers
Slop Cannot Replace Everybody (the Story of Perl and Universities)
Quantity where abundance exists is without merit; quality is what people opt for as they have limited time and patience
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Wednesday, May 13, 2026
IRC logs for Wednesday, May 13, 2026