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

Gemini Links 23/12/2025: Hydraulic Pressure Balance and mercury://
Links for the day
Techrights as 'Regulator' Against Runaway Trains
"Runaway trains" never scared us because we know that they, unlike us, don't think rationally
Social Control Media is Bots (Fake Traffic, Fake 'Engagement')
As per FORTUNE, 76% of Twitter is alleged to be bots now
"Major [IBM] Reductions Will Take Place Soon in Rochester MN"
Maybe that's just the latest office gossip
 
A Good End for a Fine Year
Today we saw some pleasant news online about the growth of GNU/Linux and more perils impacting Windows and XBox
Serial Sloppers Lost Momentum, Sites With "Linux" in Their Name Barely Bother Anymore
Will 2026 be the year slopfarms jump the shark?
Gemini Links 23/12/2025: "The sun is shinning" and "problem in the Butlerian Jihad setup"
Links for the day
Links 23/12/2025: "Over 8,700 News Articles Censored in Turkey in 2024" and "Photos Are Being Deleted From the Epstein Files"
Links for the day
Links 23/12/2025: That ‘Satisfying Click’ and Security Lapses, Car Bomb Kills Russian Lieutenant General Fanil Sarvarov
Links for the day
Links 23/12/2025: GNU Taler 1.3, US Regime Censors Television Again
Links for the day
Valve Can Bring More Users to GNU/Linux, But It Won't Bring Freedom
Steam is DRM
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Monday, December 22, 2025
IRC logs for Monday, December 22, 2025
How the Slop (So-called 'AI') Bubble Will Burst Next Year
There are already talks about mass layoffs in January
"Generative AI Bubble Has Begun to Pop", Nvidia Rides “Circular Financing... a Strategy That Hearkens Back to the Dot-com Crisis”
For companies like Microsoft this may mean another 30,000+ layoffs next year
Microsoft-Connected Media Talking About XBox Division "Profit Margins" is Distraction From XBox Sales Collapsing 70% in One Year
The simple fact is, Microsoft's console is dead in the water
The Reality is "Vibe Code" (Slop) is That It's Worthless
“Confidently Wrong”
British Web Developers Can Probably Ignore Firefox Users (Based on US Standards)
Mozilla has managed to piss off enough people
On the 'Digital Gulag' of 'Secure Boot' and Microsoft Disguising Its Attacks on Users as "Security"
Dr. Andy Farnell has this new article
Slopfarms Can Only Survive in Google News, Which is Still Promoting Them
Google News promoted only 3 slopfarms today
Gemini Links 22/12/2025: Films, Creativity vs. Consumption, Slop in YouTube
Links for the day
Microsoft XBox Losing Money, Layoffs and Studio Shutdowns (As Well as Price Hikes) Not the Solution
Microsoft does not quite talk about profits
Links 22/12/2025: Data Breaches, deterioration in Politics, and Geminispace
Links for the day
Links 22/12/2025: North Korean Applicants Target GAFAM (Amazon), ‘Orwellian Climate of Fear’ of CPC (Even Outside China)
Links for the day
More IBM Layoffs in India
It's not as simple as "laid off to be replaced by an Indian"
GAFAM Deeply Connected to Jeffrey Epstein, Richard Stallman (RMS) in No Way Connected to Jeffrey Epstein
people who hoarded all the capital get to decide what people think and say
Linus Torvalds Has a Birthday This Coming Weekend, Thankfully He Still Controls His Main Project
GNU and Linux should remain under their control as long as they live
Mozilla is Getting Attention for All the Wrong Reasons, Take a Look at LibreWolf
Just last week Mozilla added a new top-level manager who (as usual) came from a "tech giant"
When Conformism Means Capitulation and Defeat
In an age of injustices like these, we all have some kind of moral obligation not to be conformist.
Text is Still King
But the so-called 'industry' insists that we should download 10 MB of objects from multiple domains... even just to read 5-10 paragraphs of text
Links 22/12/2025: Facebook "Testing $14.99 Monthly Subscription Fee to Post Links" and "Middle East Petrostates as American Media Owners"
Links for the day
Beyond the World Wide Web (WWW)
We continue to treat Gemini Protocol as a first-class citizen
Serbia: GNU/Linux Rises, Windows Down to All-Time Lows
According to statCounter
"Wrestling With Pigs"
"Never wrestle with a pig. You both get dirty, and the pig likes it."
Productive Year and Better Access to Techrights' Archives Going Back to 2006
we've long needed and wanted native, local, independent search facilities
Linux Abandoned by Linux Foundation
It speaks for Microsoft and for so-called 'AI' companies
Microsoft Has Practically Given Up on XBox Already
Expect many XBox related layoffs when 2026 starts (Q1)
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Sunday, December 21, 2025
IRC logs for Sunday, December 21, 2025
"Today's [Red Hat] is run by a cabal of vultures."
it seems safe to assume Red Hat too will languish away
Microsoft Layoffs in 2026 Can be Bigger Than 2025 Microsoft Layoffs (30,000+ Workers Laid Off)
"Is there going to be any reorg or Microsoft layoffs?"
Gemini Links 21/12/2025: Solstice, Chaos of CSS, and Program Interpreter Fun
Links for the day
The Free Software Foundation (FSF) Represents People, Not Corporations
FSF isn't in the "business" of appeasing oligarchs
Why?
Why write articles?
Microsoft-Connected Publisher Spinning XBox's Death Spiral (It's Dying Fast) as a Strength and Something Deliberate
"Microsoft’s big gaming pivot"
Slop is Rare by Now
A year ago slop was so abundant that we did a whole series about it, and it was daily
Links 21/12/2025: U.S. Strikes in Syria, "Epstein Files Photos Disappear From Government Website"
Links for the day
Gemini Links 21/12/2025: Labrador Retriever of Lagrange's Developer Dies From Cancer, Political Philosophy, and "Getting to Inbox Zero"
Links for the day
IBM: We Can't Make 'AI' (Voice Recognition) Do the Work of a McDonald's Teenager, So Let's Try the Same on Saudi Planes
IBM is lost. It's truly lost.
Microsoft is Becoming Irrelevant: The Case of Georgia
Not Georgia Tech
Sirius Open Source is Now Imminently Dead (Struck Off)
compulsory strike-off
Dr. Richard Stallman, Invited by LibreTech Collective, is Giving a Public Talk in Georgia Tech Next Month (Scheller College of Business)
They can probably squeeze about 400 people into this room
25 Years of Activism for GNU/Linux
My passion for GNU/Linux brought a lot of contentment
Africa, Where Microsoft Used De Facto Slaves to Pretend to be "AI", Chatbots Usage is 0.2% of Measured Online Traffic
Judging by recent trends in Africa, many "Windows PCs" are being converted into GNU/Linux computers
New Drone Footage Shows IBM is Dead (Parts of It)
The people who participated in IBM when IBM actually mattered probably have boasting rights, unlike people who work for IBM today
Michael Larabel Adds Slop Category to Phoronix, Quickly Realises That It's Worthless
Phoronix nowadays gets carried away; it made a new category to talk about slop and it decided to call it "intelligence" with some caricature of a brain (that's misleading)Phoronix nowadays gets carried away; it made a new category to talk about slop and it decided to call it "intelligence" with some caricature of a brain (that's misleading)
After 35 Years the World Wide Web, HTML, and HTTP Are Proprietary
HTTP/2 added a lot of complexity (it's just a Google protocol, based on SPDY originally), many image formats are proprietary and patented, HTML got 'replaced' by Java-Scripts [sic], and many URLs (the URL system was created in the early 90s) are just long strings for proprietary 'webapps'
The General Public License (GPL) Inspired the Web's Original Openness/Freedom, According to Tim Berners-Lee
"During the preceding year I had been trying to get CERN to release the intellectual property rights to the Web code under the General Public License (GPL) so that others could use it."
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Saturday, December 20, 2025
IRC logs for Saturday, December 20, 2025