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

The Solicitors Regulation Authority (SRA) Delusion - Part IV - Machos in Charge of the House (and System), Even If the Faces Are Female (Optics)
basically a Windows/Microsoft (US) shop
Brett Wilson LLP Seems to Have Done for Roberto Foa What It Did a Year Earlier for the Serial Strangler from Microsoft
Repeat abusers (of the legal system) will misuse it as long as regulators do nothing
Where We Stand With the Winter Series
We'll need to protect names and sources
Gemini Links 10/02/2026: "The Last Messiah", Discord for Adults
Links for the day
Mobbing at the European Patent Office (EPO) - Part V - Strongest Strike Under António Campinos
SUEPO Munich is also reminding people of the threat of PIPs
GNU/Linux May Have Grown to 7% in Equatorial Guinea
Has there been some kind of mass migration there or is this just noise in the data?
 
Ian Murdock Died in San Francisco 10 Years Ago. Cops Led to His Death.
10 years ago Ian Murdock died after cops had messed him up
US/Europe divergence: health & safety, criminality & Debian harassment culture: Open Digital Ecosystems submission F33370170
Reprinted with permission from Daniel Pocock
Links 10/02/2026: Splinternets and "Meta Goes to Trial in a New Mexico Child Safety Case"
Links for the day
Russia and China Best Off Without GAFAM
What if they abandoned GAFAM?
Will Finns Put Out the Online Cigarettes?
More people recognise that the child porn site formerly known as "Twitter" and Cheeto/Pooh-tin controlled TikTok are no longer trustworthy
As the US Economy Sags Microsoft Layoffs Carry on (Now in Larger Waves Like 15,000 Per Season or 30,000+ Per Year)
They try to avoid "negative" topics
GNU/Linux at 3.99% in Australia
now that Australians can no longer keep Vista 10
Microsoft Windows Falling
analytics.usa.gov Shows Rapid Erosion of Windows Market Share Since 'End of 10' (Vista 10)
Microsoft Windows Hits All-Time Low in The Netherlands in 2026
Europe needs to rid itself or wean itself off GAFAM
SRA: SLAPPs From Russian War Criminals and American Men Who Strangle Women Are Acceptable
The SRA, by inaction, is complicit in this
From Weber Shandwick (Microsoft PR) to Brett Wilson LLP (Hired Gun of the Serial Strangler of Microsoft)
they basically tried to charge me a lot of money for a PR project of someone who strangled women
The Solicitors Regulation Authority (SRA) is Not a Regulator, It's Part of the Litigation "Industry" in the UK (They Overlap Each Other)
Does nothing except talk about SLAPPs
In Finland, Microsoft Falls Behind Yandex (Russia)
Bing has had many layoffs in recent years
Security More Advanced in Geminispace Than on the Web (Bloat)
For real security, use Geminispace capsules, not Web sites
Slop at Microsoft is a Miserable Failure, Now Microsoft Takes the "Vista Route" (Paying People to Say Good Things About It)
This is brainwash, it's meant to delay the implosion of the bubble
Rumours About February 2026 Microsoft Layoffs: Silent Layoffs or 30,000 Culled Tomorrow
Sooner or later (and soon) Microsoft will need to say something and file some WARN notifications
GNU/Linux at 12% in Guam, Based on statCounter (Compared to 2-3% a Year Ago)
Guam's "uptick" in GNU/Linux usage started weeks after "end of 10"
Fighting Slop With the Public Domain (and Why Slopfarms Perish Faster Than New Ones Appear)
We can combat the nonsense by producing more human-made works until the slop bubble implodes
After Employee Reviews at IBM Staff Expects Another Large Wave of PIPs and "RAs" (Layoffs)
From what we can see in the "public Web"
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Monday, February 09, 2026
IRC logs for Monday, February 09, 2026
Is Europe Abandoning Digital Opium?
GAFAM-controlled social control media
Microslop is Slop, Slop is Considered "Quality"
no wonder Microsoft's stuff breaks down so often
thelayoff.com Deletes On-Topic Discussions (Layoffs) While Leaving in Tact Pro-Corporate Trolling Made by LLMs (Slop)
Who at thelayoff.com deems spam made by LLMs (slop) to be on-topic and unworthy of zapping, whereas actually on-topic and authentic threads get routinely deleted?
Gemini Links 09/02/2026: Great Salt Lake Ecological Observatory and Offpunk 3.0 "A Community is Born" Release
Links for the day
Links 09/02/2026: Mass Plagiarism and Pollution/FakeCoin Company Nvidia Contacted Anna’s Archives, Narges Mohammadi Gets Second Prison Sentence
Links for the day
Links 09/02/2026: Russia Intentionally Killing Civilians, Jimmy Lai Effectively Sentenced for Life for Publishing News
Links for the day
Microsoft Competitions, Addictions, and Popularity Contests Are Not Going to Help Perl, They'll Waste Everybody's Time and Give Microsoft More Control Over Its Competition
Microsoft does not like Perl
A Can of WORMS - Part IV - They Would Even Attack RMS for Criticising Autocrats (Saying This is "Politics")
Conforming to society's perceived expectations isn't how effective activism can ever be done or was ever done in the recent past
Gemini Links 09/02/2026: The Exploration Myth and Making JavaScript Fun
Links for the day
EPO Outrage and Maintaining the Pressure
A vending machine does not fall over after a first push
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Sunday, February 08, 2026
IRC logs for Sunday, February 08, 2026
"Low Performer" and "Underperformer" as Harmful Misnomers That Damage a Company's Reputation
Misnomers need to be avoided or called out
Expensive errors: Forbes Gold price, $44 billion Bitcoin given away by Bithumb, South Korea
Reprinted with permission from Daniel Pocock
Links 08/02/2026: Microsoft OSI (Openwashing Lobby) in Europe, Raised Against Social Control Media Provocateurs in EU
Links for the day
The Open Source Initiative (OSI) Lobbies for Microsoft in the EU, Promoting Proprietary Lock-in
OSI pushing and selling Microsoft and GitHub. OSI is Microsoft front group.
Getting the European Court of Justice to Annul the Illegal and Unconstitutional Unified Patent Kangaroo Court (UPC)
We're still working on it
Finland's Dependence on GAFAM (US) Needs to be Lessened, EU Must Follow This Path
It's unwise to make one's entire national infrastructure (computer systems) dependent on a regime which compares its black citizens to monkeys and assassinates nonviolent dissenters
Links 08/02/2026: Microsoft GitHub as Burden on Developers and "The Chomsky Epstein Files"
Links for the day
Gemini Links 08/02/2026: "Doing Not Much Tweaking" and "Reclaiming Digital Agency"
Links for the day
Forbes: BitCoin, Cryptocurrency pages removed from investment database, links stop working
Reprinted with permission from Daniel Pocock
Bitcoin warning followed immediately by network outage
Reprinted with permission from Daniel Pocock
Money Funneled to Protection of Software Freedom, But Nothing Really Lost
Crossposted from personal site
They Tell Us Slop Replaces Workers, But the Reality Is, US Debt Has Surged 2,300 Billion Dollars in Six Months (the Economy is Collapsing)
Oligarchy already entertains the option of running away to (or colonising) some other planet without pitchforks and "unwashed masses"
Mozilla Firefox Sinks to Just 1.5% in the United States
According to analytics.usa.gov
We're Still Fast
The site is even faster than the BBC's despite being on shoestring budget with only a small technical team
Gemini Protocol is Not a Waste of Time of Effort
We see more and more GNU/Linux- or BSD-focused bloggers turning to Gemini
Our Gemini Protocol Support Turns 5 Today
today is a rare anniversary for us
In Today's World, One Must be Tough and Principled to Get Ahead Morally
But not financially (sellouts)
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Saturday, February 07, 2026
IRC logs for Saturday, February 07, 2026
The Right Wing in the United States Does Not Support Free Speech, It Supports Its Own Speech
Free speech is often opposed by those who also oppose Free software
IRC is a Lot Better Than Social Control Media (They're Not the Same at All)
A good social analogy for IRC is, there are many buildings with a party in each building
Microsoft 'Open' 'AI' is 'Dead Meat'
Or 0xDEADBEEF as some geeks might call it
When Identifying "Low Performers" and "PIPs" Aren't About Improving Performance But Reinforcing a Clique in Your Company/Organisation
It's very troubling to see once-respectable brands like IBM and institutions like the EPO resorting to this
Slop and Flop (IBM), Slopfarms and Hybrids (Linuxiac)
Did Bobby Borisov assume he would never get caught?
Crowdfunding vs Bitcoins: donations are better investment than digital tulip mania
Reprinted with permission from Daniel Pocock