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

Links 18/09/2025: A Taliban Ban on Internet Access and Troubled US Job Market
Links for the day
Gemini Links 18/09/2025: Computer Literacy and Accessing Alhena's Database
Links for the day
Links 18/09/2025: US War on Media (Truth Banned, Cancel Culture by the Hard Right), NYT Chief Executive Warns Cheeto is Deploying ‘Anti-press Playbook'
Links for the day
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Wednesday, September 17, 2025
IRC logs for Wednesday, September 17, 2025
Slopwatch: Fake Articles, Fake Text, Fake Images, Negative Slant on "Linux"
Google News has lost its value; the signal-to-noise ratio has fallen off a cliff
Gemini Links 17/09/2025: Relax-and-Recover on Proxmox and New Smolweb File Transfer Service
Links for the day
Fact: EFF Got Corrupted by Corporate Money. Microsoft Lunduke (Political Noise): The Issue With EFF is, It Kills Babies.
Microsoft Lunduke - as usual - finds a way to make it about abortions
Pacing Publication Up a Bit
The news cycles have gotten rather light and slow
Links 17/09/2025: Power Outages, Digital Controls, and Attacks on the Mainstream Media (by Insecure and Corrupt Dictators)
Links for the day
Gemini Links 17/09/2025: Flashing LineageOS and ROOPHLOCH
Links for the day
Links 17/09/2025: Long COVID Study, "Exposing Pegasus", and Chatbots Exposing Sensitive Data
Links for the day
Links 17/09/2025: Secret Settlement for Internet Archive and Google’s LLM Slop Summaries Attracting Lawsuits
Links for the day
The True Cost of 'Generative Models'
Funded and promoted by the companies that profit from the waste
'Big Slop' Attacks Contemporary Information/Knowledge and Creative Works, 'Big Copyright' (Cartel) Attacks the Old
Someone at IA will hopefully "blow the whistle" on what they actually agreed
Why We Find It Difficult to Trust Rust
A comparison between C/C++ and Rust
Slop Nihilism is Funded by Big Oil
Eventually human civilisation will destroy itself
Watching the OSI: Our Series Will Carry on Irrespective of the Chief's 'Resignation'
the OSI isn't even the real guardian of the term "Open Source"
Professor Eben Moglen Recovering From Open Heart Surgery
From his public pages (this is not secret)
Just What LibreOffice Needs? Another Language? (Rust)
what's all this concern about memory safety?
Many Microsoft Managers Are Leaving
"Hey hi" chaff or chaff about "hey hi" cannot eternally distract from the difficulties inside the company
There Are Red Hat (IBM) Layoffs, But Google News is Infested With Slopfarms
It contributes a lot to misinformation and it encourages plagiarism
Tomorrow, Microsoft's Tim Anderson's 'The Register MS' Offshoot Will Have Been Inactive for 2 Months (There's Also a Slop Problem)
We've already caught The Register MS using LLM slop for articles
Microsoft's Chief Legal Officer Leaves Microsoft After Nearly 30 Years
And not retiring
Even Windows Users Are Having Problems With "Secure Boot"
When it comes to security - Microsoft strives for the very opposite
Another Competition Crime of Microsoft, Long Facilitated and Advocated by a Bad Actor, Who is Funded by a Third Party to Commit Extortion Against People Who Have Correctly and Repeatedly Warned About It for Over 13 Year
We must always go back to the core issues
3 More Reasons to Replace Mozilla Firefox With LibreWolf
Thankfully there are de-enshittified versions of Firefox
USA Not a Place for Free Speech
In America, as in the US, the attacks seem more enhanced or advanced these days
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Tuesday, September 16, 2025
IRC logs for Tuesday, September 16, 2025
Links 17/09/2025: Google Layoffs in "Hey Hi" (AI), Perplexity Hit With More "Hey Hi" (Plagiarism) Lawsuits
Links for the day
Gemini Links 17/09/2025: Reclaiming Things in a Digital Age and Moon Phases in CGI
Links for the day
Slopwatch: Google News is Slop, Google News is Plagiarism, Google News is Dying
Google is off the rails
Links 16/09/2025: "The Censorship Alarm Is Ringing in the Wrong Direction" and ASRock Does Microsoft E.E.E. on GNU/Linux
Links for the day
Serious "Breach of Confidentiality of Personal Data" in Europe's Second-Largest Institution, the EPO
Yes, the same EPO that routinely uses "data protection" and "GDPR" as a pretext for hiding or covering up its corruption and white-collar crimes (it even uses that as an excuse for refusing to obey courts' orders)
Adrienne Rockenhaus Says Her Husband Was Arrested for Running Tor and Denied Basic Rights in the United States
the US seems to be getting "russified" in its approach towards Tor
This is What Happens When Microsoft Canonical Lets Decisions on Ubuntu be Made by a Youngster From the British Army (Where He Did Mass Surveillance)
"Is Ubuntu Compromised?"
Back Doored Windows Giving GNU/Linux a Hard Time (Under the Guise of 'Security')
Is this complication intentional? Most likely, yes
Links 16/09/2025: Science, Security, and Conflicts
Links for the day
Gemini Links 16/09/2025: Command-line Options in POSIX Shell and Introducing Acre 0.9
Links for the day
Microsoft 'Secure' Boot Versus Dual Boot With GNU/Linux
they're meant to assume everything is OK
Links 16/09/2025: While Oracle Pretends to be Rich It's Firing About 70 MySQL Workers, "Oracle's Revenge" (Faking Demand With "AI")
Links for the day
Microsoft Has Just Published a New Web Page About "Secure Boot Update Process" (Microsoft Also Admits Issues; PCs Can Stop Booting)
Why was this page issued and published only hours ago?
Microsoft Lunduke: I Spread Hate and Then I Receive Hate
Cry us a river, Microsoft Lunduke
"Use Wayland" Isn't a Bugfix for X (X11 is Still Necessary)
They tell us X is "dead" and we must all be herded into Wayland ASAP
"Disable Secure Boot and Fast Boot. Wipe and Start Over."
At least they didn't say, buy a new computer...
The Oracle Ponzi Scheme
Oracle isn't doing well, but it's nowadays fashionable to say "clown" and "hey hi" to prop up one's stock, even based on nothing at all
The New Head of OSI is an "Hey Hi" (AI) Obsessed Person
when Bryant says "AI" that doesn't mean AI
Taking Out the Battery, Opening Up Your Computer, Just Like a "Normie" Would
At this stage, any person who still says "enable Secure Boot" is misguided or persuaded by companies that sell rootkits
Slopwatch: Serial Sloppers and Slopfarms Still Infesting Google News (Fake 'Articles' About "Linux" Spreading FUD)
searching for "Linux" today yields a lot of FUD
"Governments, local authorities, schools and hospitals can lead by example by procuring only Free Software"
Crossposted from Tux Machines
Cindy Cohn Leaving the Electronic Frontier Foundation While Its Co-founder John Gilmore, Whom She Apparently Helped Oust, Will Celebrate 40 Years of the Free Software Foundation, Inc.
EFF has been busy hoarding GAFAM money, whereas the latter is where all the real activism is done
The Reach of Techrights Has Broadened
We nowadays cover a broader range of issues
"Google is Googlebombing KDE's Project Banana"
So is Google googlebombing KDE's Project Banana? You decide.
Complicating Things for No Actual Benefit, Just Added Risk and More Difficulties Adding GNU/Linux and BSDs
Watch what it's like for people who wish to use BSDs
Some Very Large IRC Networks Are Growing
IRC will turn 38 next year
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Monday, September 15, 2025
IRC logs for Monday, September 15, 2025
Links 16/09/2025: Autumn Party, RPG Planet, and Optical ROOPHLOCH
Links for the day