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

Insolvency as the New Norm in the United States' Economy
this is vastly worse than then 2008 subprime mortgage crisis
IBM's CEO Might 'Retire' or 'Step Down' by Christmas
PIP the CEO
Give Me Your "Dumbest" (Devices)
Why can't people accept that a "modern "smart" "phone" isn't necessary to check the time (overkill) and playing social control media "on the go" is far from necessary?
 
IBM Hammers a CoI Into a CoCed Fedora, RIP Fedora?
Also in the "Fedora is dead" dept. today
Gemini Links 25/07/2026: Zoo, MUD, Literature, EMF Camp, and e-ID
Links for the day
European Patent Office (EPO) Series: The Solution of No Choice: A Shortlist of One
deployment of the "shortlist of one" by Campinos
Wife of Dan Williams Has Explained Mental Factors Leading to His Death
"We need to be open and honest about mental health," his wife pleads
Several New Series Coming Soon
we'll publish 8 series in tandem, in parallel
Misleading Articles About YouTube and Google Financial Performance
The future of Google is self-serving monopolisation and destruction of the Web
Microsoft Cannot Survive the Fall of Windows
It has amassed way too much debt
Links 25/07/2026: Hong Kong Squashing Criticism/Dissent, Mirror Caught Breaking Into Voicemail
Links for the day
PIPs Are Shrinking IBM and "IBM is Managing Decline, Not Building Growth"
IBM is going down the drain
IBM is Killing the Fedora Community, Replacing It With LLM Slop From IBM Staff
Krishna buys companies only to gut them. They've all learned this from experience.
Earlier This Year Dan Williams Prepared for Scenario Where Linus Torvalds Dies
He had only just started a job at NVIDIA
Links 25/07/2026: Data Breaches Abundant and Attribution Imperiled in the Age of Slop Hype
Links for the day
Gemini Links 25/07/2026: Poetry and Plaintext Pages
Links for the day
What is Doctor of Philosophy (Ph.D.)
In many cases, the acronym became a misnomer
IBM PIPs Continue Until Morale Improves, Silent or Quiet Firings at IBM Explained
IBM is a dying company
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Friday, July 24, 2026
IRC logs for Friday, July 24, 2026
Gemini Links 24/07/2026: Animal Friendship, Squirrels, and Lagrange
Links for the day
Links 24/07/2026: IOC Drops Russia Ban, New Internationalist Raises Money
Links for the day
Poor Piece From Valnet: Microsoft Keeps Sabotaging GNU/Linux, So You Should Quit Using GNU/Linux
Really awful take
We Need More Encryption, Not Less of It
Use Free software and use encryption to ensure sources are fully protected
At 3PM on a Friday The Register MS Collects Some 'Pyramid Scheme' Money From Communist China (ZTE)
This won't age well for The Register MS
Car Companies Fail Because They Don't Manufacture What Costumers Actually Want
They try to impose their dumb vision on purchasers
What Freedom Does Not Mean
Tell Warren Buffett to go skiing; he'll soon understand how much freedom he truly has
Linuxiac is Plagiarism
We won't link to it, we're done [...] If you wish to support journalism about GNU/Linux, do not visit or link to slop
Verizon is Over 200 Billion Dollars in Debt (US Telecoms Collapsing, Wrapping Up the Failure in "Hey Hi" Clothing)
They will tell us this is "innovation", not a failure, and that only "Luddites" would oppose this
You've Been Conned If You Ever Believed That MElon (MUSK, Elon) Was a Trillionaire
Connected to corrupt officials
The People Who Tried to 'Cancel' (or Deplatform/Censor) Daniel Pocock Are Annoyed That He's Mentioned in Dozens of Press Articles
If Pocock's words did not matter, there would not be such a huge effort to silence him
Cybershow Explains Why Only Sociopaths Gravitate Towards Leadership Position in 'Tech'
The general thesis is a familiar one
Speeding Up 'Down Under': Australia, New Zealand, Tasmania...
As things stand, the best we can do is let people retrieve pages within less than 0.1 seconds since a request is received
Google's Debt Trebled in Only 9 Months and It's Not Even the Full Picture (There's Secret Debt, Too)
No wonder there are so many layoffs and workers try to unionise
Links 24/07/2026: Mass Layoffs at Patreon, Netflix Deemed Bad for People's Brains
Links for the day
Microsoft Layoffs in India
it's about cost-cutting
Deregulation is Blowing Up the Economy, Which Has Become a Multi-Level Scheme or Pyramid Scheme
Why did only Japanese media call out the BS; is that so hard to figure out and properly report on?
Google Spreads Misinformation, Google's Slop Makes Stuff Up and Calls That "Intelligence"
Google very well understands (and even publicly admits so, albeit only for legal reasons) that the slop does not work
Daniel Pocock Proves Wikipedia is for Rich People or People Who Work for Very Rich People (the True Owners of Wikipedia)
It's for billionaires and their faithful boot lickers
GNOME: Your Personal Opinions Must Overlap GAFAM's (Otherwise Those Opinions Are Impermissible)
Get well soon, GNOME
Making Excuses for Stressful, Unrewarding, and Immoral Jobs
excuses for difficult and/or barely-rewarding jobs. [...] People in tech must not be evaluated (or have their "worth" assessed) based on remuneration
US is Insolvent, GAFAM is Buying Time by Hiding (Not Disclosing) Its True Debt Which Explains Never-ending Layoffs (Unrelated to Slop or "Efficiency Drives")
Five Tech Giants are Hiding $1.65tn in AI Debt, Using the Trick that Toppled Enron
Almost 5 Years Without Social Control Media ('Mind Prison')
Life is too short to be stuck inside a skinnerbox
Linux Must be About People (Humans), Not Bribery From Slop Companies Trillions of Dollars in Debt and in Pursuit of Positive Press
We've lost Williams
John Dvorak Understood That "MSM" Was a Vehicle of Censorship
Independent publishing, which obviates the need to censor (influenced by existing advertisers or lookout for prospective advertisers), is the only credibly thing out there
To Understand Why Linus Torvalds Became a Boot-Licking Booster of Slop Look at Another Operative of 'Linux' Foundation, the "Mentor" of Clickfraud SPAMnil (According to SPAMnil Himself)
it seems like SJVN does not give a full disclosure
Blaming "Computers" Instead of Blaming Microsoft
Blaming Microsoft is "hate"
"Online We Are All Refugees" and Slop Pushers Are the Oppressors
They basically resort to nationalism and racism to distract from their commercial failure and fraud (pyramid scheme)
PIP Apocalypse (PIPocalypse) at IBM, CEO Promotes Vapouware (Lying to Shareholders)
Companies get to shrink while lying about it to the public, even to shareholders
GNU/Linux Soaring in Antigua And Barbuda
GNU/Linux is internationally approaching 8%
Calling Out the Worst Culprits in "Linux" Slop (Slopfarms That Manipulate Information and Engage in Plagiarism)
Once they're gone (offline), the slopfarms cannot carry on for much longer
Defying Discrimination
Rianne's birthday is exactly a month away
Dan Williams Represented Real Diversity in Linux
Williams probably understood based on personal experience what it was like to be marginalised and discriminated against
The First Point About Software Freedom is, You Must Understand What It Really Means (Not "Open Source")
Forty Three Years of Commitment to Software Freedom [...] Educating people about what Software Freedom actually means
Gemini Links 24/07/2026: Recovering From Broken Shoulders, Loss of Passion, and "True Hacker Versus Growth Hacker"
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Thursday, July 23, 2026
IRC logs for Thursday, July 23, 2026
Gemini Links 23/07/2026: Databases, TLGS, and RSS Feeds
Links for the day
Links 23/07/2026: Science, Censorship, and Territorial Overreach by China
Links for the day
The State of Google Security: Blocking competition
GMail is the best!
What Happens When Windows Becomes as 'Niche' as GNU/Linux on Desktops and Laptops
Android enjoys a near-monopoly and GNU/Linux isn't far behind Windows.
IBM Cash "Down $6.3 Billion From Year-end 2025." Total Debt/Equity 188.97%. (Debt Can Exceed the Company's Real Value)
the CEO alone can make well over $0.7 billion in 5 years of salaries and bonuses
Wave of PIPs Allegedly Coming to Microsoft, Managers Trained to Terminate Employees Without Paying Severance (and Without Calling it Layoffs)
They count and cut the losses
This Looks Like the End of XBox, the Console
Sharma has become the "fall man" of Microsoft
European Patent Office (EPO) Series: A Consummate Master of the "Rigged Game"
"single-candidate shortlist"
Attempts to Change Focus and Change the Subject as IBM Shares Dwindle. Buying Revenue to Mask the Rapid Decline One More Time.
IBM used to be good at engineering, not financial engineering
Down 848% Year-on-year, Negative Cash Flow, Growing Debt (Richest Man on the Planet or Shrewd Scammer?)
The latest for Tesla is more of the same
IBM Falls Below $200, Expect $199 or Less Today (Panic Threshold)
Will this be enough to topple the managers?
Gemini Links 23/07/2026: SharePoint Rants and “Junk DNA” in Commented-Out Code
Links for the day
Links 23/07/2026: RIP John C. Dvorak, Organisation Weaponised Against J.K. Rowling
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Wednesday, July 22, 2026
IRC logs for Wednesday, July 22, 2026
Freexian & Debian: antitrust, unfair competition against joint authors and volunteers
Reprinted with permission from Daniel Pocock