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

IBM's Kyndryl Down Almost 20% in 5 Days, IBM Down 35% in About 6 Months, Further 'Staff Reductions' at Red Hat (Problems Paying Salaries!)
Will this year's festivities be Krishna's last?
More Mass Layoffs at Microsoft, Only Weeks After the "Buyout" Nonsense (Glorified Severance to Highest-Paid American Staff)
Next up it is LinkedIn
 
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
Links 13/05/2026: Sudan War Enters Fourth Year and Strait of Hormuz Leaves Safe Passage a Gamble
Links for the day
Gemini Links 13/05/2026: Useless Protests and Foofaraw on Geminispace
Links for the day
Mainstream Media: Microsoft Says No Layoffs. Microsoft: OK, There Are Layoffs.
Where is Waggener Edstrom/Frank Shaw now?
IBM is in a Freefall, When Will IBM's CEO Fall on His Sword?
Since he controls the Board, is anyone in a position to fire him?
At GitLab, "AI" is "All India"
It says "as much as 30%," but they also hire and it's clear what demography is targeted
Verified Accounts of Microsoft Offering 'Retirement' (Layoffs) to People in Their 40s, Over Two Decades Earlier Than Retirement Age
It's not even about performance, it's about age (or "cost" as well as location; they cheapen the labour)
Links 13/05/2026: Slop Turns Into 2008-Style Subprime Bubble, Mass Layoffs at Starbucks
Links for the day
They Don't Like the Layoffs, So They Are Rebranding Them
Layoffs are layoffs
IBM Downgraded as the Shares Sink to New Lows
The current strategy of IBM is financial engineering, wage reductions, and mass layoffs that the corporate media refuses to even write about
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Tuesday, May 12, 2026
IRC logs for Tuesday, May 12, 2026
Gemini Links 13/05/2026: TUIs and Internet Radio
Links for the day
How the European Patent Office Became a Crime and Corruption Hub, One of Europe's Biggest
incomplete outline
Techrights at 19.5 (We Started in 2006, Days After the Microsoft/Novell Deal)
When Novell bought Ximian (run by the "best friend" of Graveley) it brought trouble to all of us, not just to Novell
In Croatia, Microsoft Windows Share Sank From 98% to All-Time Low of 67% (or 28% If One Counts Android)
statements made last week (and last month) by Microsoft's CEO confirm that Windows is rapidly losing users
SLAPP Censorship - Part 75 Out of 200: All True, All Verifiable, Unlike Garrett and Graveley Lying to at Least Three High Court Judges About What They Did
A lot of what I said a year ago not only turned out to be correct; it was moreover affirmed by Garrett after he had sworn on the Bible and put himself at risk to his liberty
The Corrupt Lecture the Non-Corrupt - Part XXI - EPO President Campinos Bribing to Buy His Seat, But Cautions Staff Against Bribery
This isn't a democratic institution
IBM Lost Nearly 33% in "Value" in 3 Months (Shares Down $100), But Nobody Held Accountable
This is a truly dysfunctional company
Gemini Links 12/05/2026: Spring Cleaning and New GemText Software
Links for the day
Links 12/05/2026: Samsung Sued by Dua Lipa (Publicity Rights), ‘Savage Love’ Copyright Infringement Lawsuit
Links for the day
IBM Falls to One-year Low
At one point or threshold does the Board (controlled by the CEO) sack the CEO?
Gemini Links 12/05/2026: On Astronomy and Stargazing, Coyote Time, and Freenom
Links for the day
Links 12/05/2026: Data Centres Destroying Neighbourhoods, "Care Workers Are Saying No to 24-Hour Workdays"
Links for the day
Richard Stallman to Give Public Talk in Erlangen, Germany (Next European Tour)
Seems like a large room
Google "Hey Hi" (Slop) Having a Stroke, Thinks I am Married to the Grandmother of My Grandfather
Seriously!
If IBM Suddenly Vanished in the 1980s, There Would be Chaos. Not Anymore.
IBM's management has rendered IBM more irrelevant than ever before
Beehiiv and Substack Are Platform Lock-in (Similar to Vendor Lock-in), Don't Use Beehiiv and Substack (and the Likes of These)
Proprietary platforms are a problem. Some people "get it" sooner than others.
Gitlab is in Trouble and Its Shares Have Collapsed
Down almost 80% since it began [...] The real issue has nothing to do with slop, it is a lack/loss of customers and erosion of the company's theoretical "value"
Microsoft: Mass Layoffs Are "Offers" (Like "Job Offers"), Culling Experienced and Highly-Paid Staff is "Softer Workforce-reduction Strategy"
Media sites that play along with those lies don't do journalism, they're in the PR industry
Under IBM, Mass Layoffs at Red Hat No Better Than Oracle Under Larry Ellison (Treating Workers Like Disposables - Even Enemies - Overnight)
under IBM the respect for the worker (or peer) does not exist
The Slop-Amplified Fear of Privilege Escalation (Local, Not Remote) in Linux, the Kernel
we are meant to assume this is no better and no worse than Microsoft intentionally putting back doors in everything, even encryption
Jim Zemlin/Linux Foundation Selling Anthropic Slop After Getting Bribed for Slop Marketing ('Linux' Foundation is a Pay-to-Say For-Profit Marketing Company That Buys and Manipulates the Media Based on False Pretences)
Look what they've done to Steven Vaughan-Nichols (SJVN)
GitLab the Latest Company to Do Mass Layoffs and Use Slop as the Go-to Excuse (GitLab Users Should Worry Too)
This round of layoffs (disguised as something else) has nothing to do with slop ("hey hi"). It's about commercial problems.
The Corrupt Lecture the Non-Corrupt - Part XX - EPO Management's Unified (One) Voice or Policy is, Doing Cocaine is OK When You're a Friend and/or Family of President Campinos
The management needs to resign to save the Office
Technology Not Meant to Last
A society apathetic towards declining production (or manufacturing) standards will end up ripped off
statCounter Cannot 'See' Chinese Operating Systems That Gain Many Millions of Users Per Month
There is no way for statCounter to recognise or show the market share of HarmonyOS
SLAPP Censorship - Part 74 Out of 200: The Basis of My Lawsuit Against Alex Graveley, Who Helps Garrett Stack the Docket in Another Continent
claim against the Serial Strangler from Microsoft
Update on Slop About "Linux"
"Linux" is a term many people are interested it, so it's not shocking that slopfarms target it
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Monday, May 11, 2026
IRC logs for Monday, May 11, 2026
GAFAM (Microsoft) "Cloud Computing" Means Another Country's Military Accesses All Your Data
reminder that confidentiality and Clown Computing are complete opposites
Another Discrimination Lawsuit Against IBM and Workers Say IBM Culls Older Workers (Just Like Microsoft)
If IBM fails to retain some of the smartest people, then what is the future of IBM?
Gemini Links 12/05/2026: Android Nostalgia and Switching to Guix
Links for the day