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

Saying "No" is Not a Bad Thing
Society benefits from people who say "No!" even when it seems impolite (and possibly inconvenient) to say so
Next Week's "Bloodbath" at Microsoft Includes "Silent Layoffs" (Which Microsoft Won't Count)
The notion of "silent layoffs" is fast becoming the "new normal"
XBox Being Discontinued, Some Models of XBox Canceled, Not on Sale Anymore
First some of the largest retailers quit stocking/selling XBox, now a 2TB model is axed
 
Gopher (Protocol) Turns 35, Gemini is 28 Years Younger
Bad technology comes and goes very fast
Be Like Stallman and Assange, Not Like MElon or Bill Epsteingate
these people treat women like worse than dirt
Exposure Leads to More Whistleblowing
In areas like IBM or European patent affairs we've always earned a lot of trust
European Patent Office (EPO) Series Will Run Well Into July
We still have a very significant chunk of EPO "trench" stories
Links 27/06/2026: Journalists Kicked Out of China, Torture in Iran and Turkey
Links for the day
How Microsoft is Preventing or Slowing Down Adoption of GNU/Linux (Fake 'GNU' Controlled by GitHub in Windows, WSL, Sabotage at Boot Level, Not Limited to Dual-Booting)
Microsoft is still at it
Rising Computer Prices Good News for GNU/Linux and Free Software
This can greatly assist the adoption of BSDs and GNU/Linux
Links 27/06/2026: More Restrictions on Social Control Media and Russia is Leveraging Cellebrite/Back Doors
Links for the day
Akira Urushibata on the Likely False (Unverifiable) Claims Anthropic Makes About Defects for Marketing/Hype
Some pro-LLM person has managed to derail the discussion on this topic
European Patent Office (EPO) Series: "Team Campinos" in Split
The EPO team was of course headed by Campinos himself who delivered a "forward-looking" keynote speech to the assembled audience consisting mainly of Administrative Council delegates from the national IP offices
Supporting Women in the Free Software Community
The common theme here is abuse of women
Left IBM After Many Years, Came to Microsoft/XBox, Now Silent Layoffs at XBox
many inside XBox will have their last day next week
Gemini Links 27/06/2026: Homeworlds and Tarot Cards
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Friday, June 26, 2026
IRC logs for Friday, June 26, 2026
Links 26/06/2026: SoftBank Forbids Mentioning That Slop is a Scam, "'We Need Courageous People' to Combat Greed and Corruption"
Links for the day
Gemini Links 26/06/2026: "Negativity of Reddit" and "Moving Blog to Gemini"
Links for the day
Same MIT Site That Fabricated the Fake News for IBM is Still Being Paid to Produce Fake "Reports" That Prop Up a Ponzi Scheme
If this is the media we deserve as a society and believe keeps us informed, then we are all doomed
'Social' Slop: The Social Control Media and Slop Crises Are Converging
Social Control Media and slop may have a shared fate. People will shun them both.
Union Syndicale Fédérale (USF) Speaks Out Against Campinos and Informs the Chairman of the EPO Administrative Council
Does Mr. Kratochvíl pay any attention at all?
'António the Pretender' Campinos is Digging His Own Grave With Grotesque Lobbying Intended to Undermine Democracy in Europe's Second-Largest Institution
One way or another, the EPO will never be the same again
The Principle of "Do No Harm"
"Do No Harm" is a common saying
After Years of Bluewashing People Who Are Still Labelled "Red Hat" Suddenly 'Leave' (Might be PIPs), IBM in "Forever Layoffs" Loop
Remember that Red Hat had mass layoffs this year
Microsoft Staff Bracing for Impact Ahead of "Layoffs Lottery"
some people start to assess who will get culled next
Donald Trump and IBM's CEO: Twins Separated at Birth, Saturating the Media With False Reports About Things That Don't Exist
Every "journalist" that went ahead with this fake news should be sacked on the spot for a rejection of fact-checking
The Register MS Will Become Indistinguishable From Spamfarms at This Current Pace
Follow the money...
Microsoft Layoffs Have Already Begun in Its PR Department
It is called Waggener Edstrom
Techrights Community as Litigants in Person (LIPs)
Unwittingly and due to circumstances we're had to step in to protect women abused by monstrous men who lack empathy
European Patent Office (EPO) Series: Rest and Recuperation on the Adriatic Coast
The EPO President's connections with the Croatian SIPO date back to his days as head of the EU trademark agency EUIPO
Firehose of Spam (Fake News) From The Register MS Today
This is how awful the state of news sites really is
Slopfarms Becoming Scarce and Few (or Inactive)
we'll try to refrain from even giving the remaining slopfarms any visibility
The Register MS Promotes Things That Do Not Exist... for Money
How much more ZTE spam will come out before 5PM?
Links 26/06/2026: RIP, Om Malik, 1966-2026
Links for the day
Memory Leaks Suck
Slop ('vibe') coding means lots of bad programs
Natural Disasters and Personal Disasters
Thank you, Om Malik, for the positive memories
Gemini Links 25/06/2026: Life Philosophy and Misery
Links for the day
GAFAM Became a Mainstream Term, and Why Words Matter
Conveying problems in useful terms [...] Impairing propaganda attempts (e.g. calling parrots "intelligence", back doors "confidential", and outsourcing "cloud") should be the first step
European Patent Office (EPO) on Strike Today, Next Week Another Historic Week
If you live in Europe, contact your delegates today
FSF FreeJS Project (Part of the GNU Project's Goals) Advanced Further in 2026
They're moving to reduce dependence on anything to do with Microsoft
SLAPP Censorship - Part 119 Out of 200: Our Suggestions to Our Politicians and Heads of State
coverage about SLAPPs and related matters
Microsoft Already Closing Down Studios, According to Some Publishers
It is being compared to what happened in Intel
IBM PIP Stories Told in Public, Fake IBM News (Fabricated Claims) Drown Media Sites
IBM is seeding fake news to help justify the bailout
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Thursday, June 25, 2026
IRC logs for Thursday, June 25, 2026
Microsoft Falls to Lowest Value Since 2023
Microsoft can come back down to somewhere below $100
This Could be the Start of Microsoft's Biggest Wave of Layoffs in 50+ Years
This is what it looked like for Intel a few years ago
The Register MS is Promoting a Pyramid Scheme for Money, But It Is Over 6 Million Pounds in Debt
How much lower can the reputation of this publisher sink?
Gemini Links 25/06/2026: Unix-like People and NeoGeo
Links for the day
Members of the Delegations in the EPO's Administrative Council Told That Amid Unrest Campinos Must Go; a Year of EPO Strikes Means It's Time to Change Leadership
Which strategy is needed for the European Patent Organisation?
The Cyber Show on How Data is Misused and Broadcast is Abused to Crush Resistance to Harmful Technology
We recently published a number of articles about how Computer Science is coming under attack
Increasing Participation Rates in Staff Representatives' Elections at the European Patent Office (EPO)
The industrial actions seem to have brought colleagues closer together
Microsoft's Mass Layoffs Have Already Begun (Could Not Wait 'Til July)
Microsoft's biggest layoffs round in 50+ years?
Assessing the "Worth" of a Life
Don't let blunt plutocrats decide whether Venezuelans deserve sympathy or not
Planning 20-Year Techrights Event
Interested people can contact us in IRC
Links 25/06/2026: Earthquakes Strike Venezuela, Conflict of Interest in Kangaroo Court UPC
Links for the day
More Weight of IBM's Stock is Ascribed to Lies and Things That Do Not Exist
Turning stones into gold?
SLAPP Censorship - Part 118 Out of 200: Exposing Crimes is Not a Crime, It is a Public Service
We will soon enter the sixth year of lawfare
Links 25/06/2026: "Why We Need Seed Legislation" and XBox Chaos Predicted by Insiders
Links for the day
Gemini Links 25/06/2026: Hobbies Change, Young love, Strange Encounter, and Raspberry Pi Zero W
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Wednesday, June 24, 2026
IRC logs for Wednesday, June 24, 2026