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

An American War on GNU/Linux, Software Freedom, and British Investigative, Science-Based Reporting - Part III - Very Strong Legal Basis for an Appeal
The case is now being escalated to a Foreign Secretary and former Deputy Prime Minister
No Slop Found in RSS Feeds, Only in Google News
No slopfarm will survive for very long, certainly it'll go bust as soon as readers (if it had any) know what it is
What the Solicitors Regulation Authority (SRA) and Action Fraud UK Have in Common
Don't let London become the world's "crime capital"
Dr. Andy Farnell on How GAFAM, NVIDIA and Others Lie to People Via the Sponsored Media to Prop Up Lies Under the Guise of "AI"
Lots of key aspects are covered
Richard Stallman Gives Talk in 20 Hours at Ostschweizer Fachhochschule Campus in Rapperswil-Jona
The talk is in English
 
The Register MS Has Just Taken Money From Google (Where the Former Chief Editor Now Works) for Femmewashing and Ponzi Scheme Promotion
now The Register MS not only promotes a Ponzi scheme but also bags money to pretend Google respects women
People at IBM Are Still Smart Enough to Understand What's Really Going on
"I would never refer someone to work at IBM that I liked! I hope all of you have reviewed IBM on Glassdoor."
European Patent Office (EPO) to "Eventually Eliminate the Tasks Performed by Formalities Officers"; EPO Run by People Without Experience in Patents
full paper
RMS is 73 Next Week
Richard Matthew Stallman (RMS) turns 73 exactly 7 days from now
Iran & FSFE: blackmailing women, from football to the French Government (CNIL)
Reprinted with permission from Daniel Pocock
Police investigations, lawsuits & Debian leader election candidate shortage
Reprinted with permission from Daniel Pocock
Richard Stallman (RMS) Has Defeated Cancel Culture, a Mostly American Phenomenon
RMS is talking now
Links 09/03/2026: Many Security Breaches and a Pandemic of Censorship
Links for the day
People Who Work or Worked at IBM Hate It
bluewashing is only the first step
Richard Stallman (RMS) Talks in 30 Minutes, Next Stop Bern (Last Stop)
We assume he'll travel back to Boston after that
IBM's Fedora as a Booster of Slop Disguised as Code or Computer Programs
Maybe we should also stop seeing a doctor and instead ask chatbots about symptoms?
Richard Stallman (RMS) Talk Five Hours From Now
there is growing recognition for what he really did for everybody
EPO Strike 10 Days From Now, Planning Assembly Tomorrow, Last Couple of Strikes Had High Participation Rates (1,500-1,600 Staff Went on Strike)
The next strike is in 10 days' time and then there will be another strike
Links 09/03/2026: GAFAM Outsourcing, "MAGA Political Meddling" in EU, Indonesia Bans Social Control Media for Children Under 16
Links for the day
Using Slop (and Slop in Articles) to Attack Copyleft 'on Budget'
This article is pure BS from an anti-GPL and anti-RMS 'activist'
Why The Register MS Sold Out to Microsoft: They're Losing Lots of Money, The Register MS is Bleeding to Death, Based on Its Own Financial Records
With over 6 million pounds in debt (nearly 10 million US dollars) we guess it's likely some other company will take over the site (if it deems it worthwhile)
Microsofters' SLAPP Censorship - Part 7 Out of 200: Like With the Serial Strangler From Microsoft, Misuse of UK-GDPR to Try to Hide Embarrassing Facts
They do and say really bad things, then allege it's a "privacy violation" to mention those things
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Sunday, March 08, 2026
IRC logs for Sunday, March 08, 2026
Gemini Links 09/03/2026: Exponentials and Tailscale
Links for the day
Sloppyleft
Article by Alexandre Oliva
Hard to Replace 'Human Touch'
The reason many people insist on using GNU
The Slop Companies Gamble at Our Economy's Expense and They Know It's a Losing Bet (So It's a de Facto Robbery)
The crash of this bubble isn't just inevitable, it's already happening and receding sporadically because of false announcements about money that does not actually exist (to "buy time")
Suppressing Speech by Blackmail, the Iran Story
When Debian wanted to stage a seemingly legitimate election it needed to have more than one candidate running; so eventually the female partner of a geek rose to the challenge (had no coding skills at all, no technical history in Debian) and lost to the "incumbent German"
Too Focused on Buzzwords the Media is Paid to Saturate the Collective Mind With
Just because companies do really bad things in the digital realm does not imply "AI" or follow from "AI"
Discrimination and Prejudice Against Female Journalists
we can shame people who attack a reporter on the grounds of gender
An American War on GNU/Linux, Software Freedom, and British Investigative, Science-Based Reporting - Part II - Trying to Put People in Prison for Committing the Act of Journalism
This is abuse of process
Attack on Copyright and Copyleft by Code Conversion Is Nothing New, It Predates Slop (Code Produced by LLMs) by Several Decades
Even back in the 90s many people converted programs from one language to another. That could invalidate copyleft (and copyright), which already existed
Almost a Slopless Weekend for "Linux"
Let's hope slop will come to an end or sites will cease linking to slop
Insiders Explain Why IBM is Dying and the Inherent Culture Problem
There are many ways to shave this IBM cat
Links 08/03/2026: Microsoft Lost $400 Million on "Project Blackbird" and Half the States Sue Over Illegal Tariffs
Links for the day
Links 08/03/2026: Cisco Holes Again and "Blatant Problem With OpenAI That Endangers Kids"
Links for the day
Activism/Journalism in Our Blood
one must fight for one's principles
Gemini Protocol in Its Prime
What's particularly neat about Gemini Protocol is that it's fast and cheap
Microsofters' SLAPP Censorship - Part 6 Out of 200: Intentionally Misnaming Women, People Who Offered to Testify That They Too Had Been Subjected to Similar Abuse
Today it is International Women's Day
Even Fedora Leadership Cannot Figure Out the Microsoft Kill Switch/Back Door, 'Secure' Boot
It does not actually enhance security
Bruce Perens: Richard Stallman "Has Achieved His Goal"
Stallman's next talk is tomorrow
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Saturday, March 07, 2026
IRC logs for Saturday, March 07, 2026
Gemini Links 07/03/2026: Buying Woodland, Indra 1.3.0 Available, and LLM Exhaustion
Links for the day
The Harder They Attempt to Take Down This Site (and Take Away Liberties), the More People Will See This Site
We'll carry on as usual, as from sunlight comes justice
An American War on GNU/Linux, Software Freedom, and British Investigative, Science-Based Reporting - Part I - A Matter of National Security
Those people are Americans who try to advance the interests of American corporations by weaponising courts abroad
Why They Always Try to Shoot the Messenger (When the Message Harms Profits)
A matter of economics
Coinbase - Like Block - is in Huge Trouble, Its Debt Nearly Doubled in Half a Year
The real reason Block is collapsing is its debt
Starting Another New Series This Evening, It's About American Folly
today commences a series long in the making (years)
Nations Stand to Benefit From Gender Equality and Increased Participation by Women
International Women's Rights Day starts in about 6 hours in the UK
Microsoft is Losing It, Now It's Censoring Its Critics and Sceptics
Whether the measurements made by statCounter are accurate or not, the trends (long-term) typically make sense
WIRED (Conde Nast) Reviews Are Paid-for Marketing Spam, They Change Dates on Old 'Articles' to Make Them Look Relevant and New
The Web is fast becoming a burial ground for ads, trash, spam, and slop
Gemini Links 07/03/2026: Humour, Chilling, and Oversized 'Phones'
Links for the day
Cyber|Show by Andy and Helen Recommended by Techrights and Tux Machines
If your time is limited and you look for informative essays and shows (audio)
Links 07/03/2026: CJEU to Finally Examine Behaviour of the Illegal and Unconstitutional Unified Patent Kangaroo Court, Creative Commons (CC) Hosts Open Heritage Statement Event in Amsterdam
Links for the day
Microsoft's Thailand Problem
It's definitely not Windows
New Lows for Microsoft in Micronesia
GNU/Linux has shown some growth there too
Microsofters' SLAPP Censorship - Part 5 Out of 200: Clearly Not a Security Professional/Expert, Only Ever Pretending to be One
"The Claimant says he is “a computer security expert”, but his background and his track record in the education sense (genetics) does not support this assertion."
Links 07/03/2026: Fuel Already Running Low and "Economic Crisis of the Iran War"
Links for the day
The Corporate Media Repeated the Lies Told by Jack Dorsey ("AI" Hype), Now It Does the Same for Larry Ellison
Disregard the hundreds of headlines that say mass layoffs at Oracle are due to "AI" something
The Free Software Community is Gaining Momentum as Its Importance is More Broadly Realised
As long as "trendy" technology goes in a negative direction there will be a growing portion in society looking for alternatives
Spooking or Chasing Away Women (From Computer Science)
The status quo discourages women from even trying to study Computer Science and related disciplines
"IBM Has Changed So Much in the Last Decade to the Point It's Completely Unrecognizable."
IBM is a dying, rotting company with a morbid culture
The Register MS, Sponsored by Communist Party of China (CPC)
What will happen when the bubble crashes the economy?
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Friday, March 06, 2026
IRC logs for Friday, March 06, 2026
Gemini Links 07/03/2026: Coffee Problem, Marchintosh, Learning, and "Selectively Disabling HTTP"
Links for the day