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

Naming Culprits in Switzerland
Switzerland is highly secretive about white-collar crime
Sanitised Plagiarism as "AI" (How Oligarchy Plots to Use Slop to Hide or Distract From Its Abuses, or Cause People Not to Trust Anything They See/Read Online)
This isn't innovation but repression
Recent Layoffs at Red Hat (2026 the Year of Ultimate Bluewashing)
I found it amusing that Red Hat's CEO has just chosen to wear all blue, as if to make a point
Team Campinos Talks About SAP Days Before EPO Industrial Actions and a Day Before the "Alicante Mafia" Series (About Team Campinos Doing Cocaine)
EPO staff that isn't morally feeble will insist on objecting to illegal instructions
Stack(ed) Rankings and Ongoing Layoffs at Red Hat and IBM (Failure to Keep Staff Acquired by IBM)
IBM is mismanaged and its sole aim is to game the stock market (by faking a lot of things)
Linuxiac May Have Reverted Back to LLM Slop (Updated Same Day)
Is he back off the wagon?
 
Writing About Corruption
Fraud is everywhere
The B in IBM is Brown-nosing and Buzzwords (or Both)
International Buzzwords Machines
IBM's 'Scientific-Sounding' Tech-Porn Won't Help IBM Survive (or Be Bailed Out)
Who's next in the pipeline?
IBM Was Never the Good Guy
its original products were used for large-scale surveillance, not scientific endeavours
The Bluewashing is Making Red Hat Extinct (They All Become "IBM", Little by Little)
IBM does not care what's legal
Slopfarms Push Fake News About Microsoft Shutdown, 30,000+ Microsoft Layoffs Last Year Spun as Only "15,000"
The Web is seriously ill
Countries Take Action Against Social Control Media and 'Smart' 'Phones', Not Slop (Plagiarised Information Synthesis Systems or P.I.S.S.)
None of this is unprecedented except the scale and speed of sharing
Sites That Expose Corruption Under Attack, Journalism Not Tolerated Anymore (the Super-Rich Abuse Their Wealth and Political Power)
Sometimes, albeit not always, the harder people try to hide something, the more effective and important it is for the general public
Links 16/01/2026: Social Control Media Curbs in Australia Underway, MElon Still Profiting by Sexualising Kids 'as a Service'
Links for the day
More People Nowadays Say "GNU/Linux"
We still see many distros and even journalists that say "GNU/Linux"
LLM Slop on the Web is Waning, But Linuxiac Has Become a Slopfarm
I gave Linuxiac a chance to deny this or explain this; Linuxiac did not
More Signs of Financial Troubles at Microsoft, Europe Puts Microsoft Under Investigation
The end of the library is part of the cuts
The "Alicante Mafia" - Part I - An Introduction to the Mafia Governing the EPO
Are some people 'evacuating' themselves to save face?
Pedophilia-Enabling Microsoft Co-founder Cuts Staff
Compensating by sleeping with young girls does not make one younger
Microsoft Shuts Down Campus Library, Resorts to Storytelling About "AI" to Spin the Seriousness of It
Microsoft is in pain
Free Software Foundation (FSF) Back to Advertising the Talks of Richard Stallman
A pleasant surprise
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Thursday, January 15, 2026
IRC logs for Thursday, January 15, 2026
Gemini Links 16/01/2026: House Flood and Pragmatic Retrocomputing Dogfooding
Links for the day
Links 15/01/2026: Starlink Weaponised for Regime Change (by Man Who Boasted About Annexing South American Countries for Tesla's Mining), Corruption in Switzerland Uncovered by JuristGate
Links for the day
GAFAM and IBM Layoffs Outline
a lot of the layoffs happen in secrecy and involve convincing people to resign, retire, relocate etc.
Links 15/01/2026: Internet Blackouts, Jackboots Society in US
Links for the day
Coming Soon: Impact With EPO Cocainegate
Will Campinos survive 2026?
The Last 'Dilberts' or Some of the Last Salvaged (Comic Strips Which Disappeared Shortly After They Had Been Published)
Around the time the creator of Dilbert went silent he published some strips mocking TikTok and usage of it
The Creator of Git Probably Doesn't Know How to Install and Deploy Git
Nobody disputes this: Mr. Torvalds created Git
Slop is a Liability
Slopfarms too will become extinct because people aren't interested in them
GAFAM is a National and International Threat to Everybody
GAFAM is just a tentacle in service of imperialism
EPO People Power - Part XXXVI - In Conclusion and Taking Things Up Another Notch
They often say that the law won't deter or stop criminals because it's hard to enforce laws against people who reject the law
Running Techrights is Fun, Rewarding, and Gratifying
In Geminispace we are already quite dominant
Red Hat is Connected to the Military, Its Chief Comes From Military Family (From Both Sides)
The founder of Red Hat's parent company literally saluted Hitler himself (yes, a Nazi salute)
Don't Cry for Gaslighting Media in a Country Which Loathes the Press
my wife and I received threats for merely writing about Americans
Red Hat (IBM) is Driving Away Remaining Fedora Users
I've not used Fedora since Moonshine
Robert X. Cringely Has Already Explained IBM's Bullying Culture (Towards Its Own Staff)
IBM is a fairly nasty company
Proton Mail compromise, Hannah Natanson (Washington Post) police raid & Debian
Reprinted with permission from Daniel Pocock
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Wednesday, January 14, 2026
IRC logs for Wednesday, January 14, 2026
Gemini Links 15/01/2026: "Ode to elinks", envs.net Pubnix and Downtime at geminiprotocol.net
Links for the day
Still Condoning Child Labour and Exploiting Unpaid Children Developers as PR Props (to Raise Monopoly Money)
These people lack morals. So they project.
"Security, AI or Quantum" on "the IBM Titanic"
Who's RMS?
Hours Ago The Register MS Published Microsoft Windows SPAM "Sponsored by Intel." The Fake 'Article' Says "AI" 34 Times.
The Register MS isn't a serious online newspaper
EPO People Power - Part XXXV - Where Else Will Corruption and Substance Abuse be Tolerated?
We need to raise standards
Status and Capital
People who do a lot are too busy to boast about it and wear fancy garments
IBM Paying the Price for Treating Workers Badly and Discarding Real Talent (Because It's "Expensive")
IBM is dead man walking
Turbulence Ahead
I last rebooted my laptop in 2023
Google News Rewards Plagiarism With LLMs (About Linux, Too)
Google is in the slop business now
Links 14/01/2026: Failing Economy and Conquest Abroad as a Distraction From Domestic Woes
Links for the day
Gemini Links 14/01/2026: The Ephemerality of Our Digital Lives and "Summer of Upgrades"
Links for the day
Projection Tactics - Part III: Silencing Inconvenient Voices Online
If X gets banned in the UK, it'll be hard to see what the spouse says in public
Outsourcing on Microsoft's Agenda, Offshoring Also
"In some cases, India hiring is poised to replace certain roles previously based in the U.S."
Links 13/01/2026: 'Dilbert' creator Scott Adams Passes Away With Cancer, Ban on X/Twitter Considered for CSAM Profiteering
Links for the day
The Goal is Software Freedom for All
Anything to do with "Linux Foundation" is timewasting
Reminder That Red Hat Enterprise Linux (RHEL) Is Not Free, And It's Because of IBM
software freedom just 'gets in the way'
Under IBM, in Order to Game the Stock Market, Red Hat Resorted to Boosting the Biggest Ponzi Scheme in Human History
This is what IBM turned Red Hat into
Revision handed Microsoft the keys to the distortion of the past/history
This isn't the first time The Register MS rewrites computing history in Microsoft's favour, as we pointed out several times in past years
What Will Happen to GAFAM After the US Defaults Rather Than Bails Out the Market?
Or tries to topple every government that doesn't play by its rules?
EPO People Power - Part XXXIV - Bad Optics for the European Union (for Failing to Act and Tolerating Cocaine Use in Europe's Second-Largest Institution)
There are principles in laws which tie awareness with complicity
EPO's Central Staff Committee is Now Redacting (Self-Censoring) Due to Threats From the EPO "Mafia"
"On the agenda: salary adjustment procedure for 2025 (as of January 2026)"
"AI" (Slop) 'Demand' Isn't Growing, It's Fake, It's a Pyramid Scheme
They try to resort to 'creative' accounting (fraudulent schemes like circular financing)
Difficult Times at IBM and Microsoft Ahead of Mass Layoffs (Probably Before This Month's Results Unless Postponed to 'Prove' Rumours 'Wrong')
IBM and Microsoft used to be tech giants. Nowadays they mostly pretend by pumping up their stock and buying back their own shares.
Canonical: Make Ubuntu Bloated (Debian With Snaps), Then Sell the 'Debloated' Version for a Fee
If people want a light distro, then they ought not pay Canonical but instead choose a light (by design) GNU/Linux distro
People Don't Want "Just Enough", They'll Look for Quality
That's why slopfarms will go away or become inactive
Gemini Links 14/01/2026: 3D and Tiny Traffic Lights Pack
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Tuesday, January 13, 2026
IRC logs for Tuesday, January 13, 2026
Slop Waning Whilst Originals Perish
Slop is way past its "prime"
XBox's 'Major Nelson' Loses His Job Again, This Time in a Microsoft Mono Pusher
Microsoft hasn't much of a future in gaming. XBox's business is in rapid decline and people who push Mono to game developers are the same