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

End of the Smartphone Era? No.
Maybe the media should focus on producing accurate, factual news
Slopwatch: Sites Gone Rogue, Google Promoting Lies, and DDoS Attacks by Plagiarism Giants
Charlatans and frauds engage in a war against artistic industries, mislabeling plagiarism as "AI"
Latest Is Not Greatest: The Case of "Foldable" Tech
don't be shamed into abandoning old things just because the "fashion industry" of Apple and Samsung tells you to
Gemini Links 21/08/2025: The Attraction of Back Alleys, Initramfs, and BSD ISPs
Links for the day
 
Links 22/08/2025: Cisco Layoffs, LA Times Says "AI Hype is Fading Fast"
Links for the day
Gemini Links 22/08/2025: K for Kentucky and Caddy Versus LLM Slopbots
Links for the day
The "End Software Patents" Initiative of the FSF Explains "WHY [to] ABOLISH SOFTWARE PATENTS"
We hope to cover patent-related issues more and more as the big anniversary of the FSF approaches
This Saturday It's Gonna be 3.5 Years Since Russia Invaded Ukraine. No Microsoft Protests Against Microsoft Having Provided Russia With Services.
Companies do not have consistent policies and enforcement of "corporate values" is somewhat of an egg salad
Freenode Sniffing
The grown-ups left the building
The Only Thing Worse Than Misinformation is Misinformation Sold to Everyone as "Intelligence"
Misplaced trust is worse than none at all
The Register MS Now Openly Admits LLM Hype Does Damage, But It's Also Being Paid to Participate in the LLM Hype (With Paid 'Articles' and 'Webcasts' for Paying Advertisers)
The Register MS gets paid to do this
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Thursday, August 21, 2025
IRC logs for Thursday, August 21, 2025
Enshittification of Airports, Airlines, and Airplanes
If people are willing to tolerate standard declines and enshittification (nowadays sold as "pivot to AI" or "replaced by AI" or "AI layoffs") they will pay for it some other way
Airlines and Their Tricks That Only Work in the 'Digital Age'
People sceptical of the direction technology has taken are not "Luddites"
Open Source Initiative (OSI), Which Became a Propaganda Front of Microsoft and "Hey Hi" (Hype, Misnomer), Wants You to Forget These Scandals
A lot of these issues won't be set aside until there's a resolution
The Culture of Overnight Coding
An industry-wise push-back is needed
Windows Down to New Lows in Guinea Bissau and Many Countries Around It
If Android is accounted for, Windows is down to about 10%
Gemini Links 21/08/2025: Modern Dating, Debian 13, and Apache
Links for the day
Microsoft Has Had About 10 Waves of Mass Layoffs So Far This Year (Not Two as Mainstream Media and Slopfarms Endlessly Claim)
Notice how the MSM (Mainstream Media) never mentions the debt of Microsoft. It is a conscious, deliberate decision.
Links 21/08/2025: Covid Cases on the Rise, "Social Media Trolls", Russia's Attacks Intensify
Links for the day
Links 21/08/2025: Stephanie Shirley Dies and "Groklaw Domain Hijacked?"
Links for the day
Search in 2025 (Age of DDoS Attacks Under the Guise of "AI" "Innovation")
One common concern when things go "live" is that any random bot out there can execute queries, pumping up RAM and CPU usage, as happened when we used MediaWiki and WordPress
Using Slop for Images Does Not Make Your Site Look Advanced or Witty, It Just Makes Your Whole Work Look Like Presumed Plagiarism
Lazy slobs and Serial Sloppers use the guise/excuse of "AI" to plagiarise and spam the Web
Financing of the "Hey Hi" (AI) Bubble by Those Who Profit From Planetary Destruction (Global Warming)
It's about personal gain, too
Richard Stallman Will Speak in Ethereum Cypherpunk Congress
it's good to see that the FSF pays considerable respect to it founder, who is moreover invited to speak at events
(At Least) Second Wave of Mass Layoffs in Microsoft This Month
This is not the first time this month that Microsoft has mass layoffs
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Wednesday, August 20, 2025
IRC logs for Wednesday, August 20, 2025
IBM Operatives Inside The Register MS and More Shady Money to Follow
The Register MS bites every banknote it can sink its teeth into
On the Internet, Nobody Knows Microsoft and Windows Are Becoming Niche Players Until Data is Shown Correctly, Not Microsoft-Sponsored Articles in Microsoft Publishers
Microsoft controls a lot of publishers and thus it controls information
Slopwatch: Serial Sloppers and Slopfarms in Google News (e.g. Linux Journal and WebProNews)
Google plays an active role (if not deliberately then through utter neglect and carelessness) in plagiarism
Links 20/08/2025: Mass Surveillance Framed as "Artificial Intelligence" (All Old Things Reworded to Misframe Old Computer Issues), Europe Resists Capitulation to US(SR)
Links for the day
Gemini Links 20/08/2025: Trips and Permacomputing
Links for the day
Links 20/08/2025: Oracle Layoffs in India, "AI" Scammers/Profiteers Admit It's a "Bubble", Softbank-Saudi (Oil) Control Tech Companies
Links for the day
Social Control Networks Give You False Metrics to 'Addict' You To Them
Leaving social control media may seem hard, but the same is true for any other addiction
A Lot of What Happened in Twitter Was Bots, Botfarms, and Troll Farms. It's Even Worse Now (Under X.com) and People Are Noticing.
Last month we said the same was happening in YouTube
Microsoft May Have Become - at Least Partially - Like a Boiler Room Scam
Giving imaginary salaries using imaginary tokens based on imaginary value (with restrictions on conversion to cash)
In Vietnam, Microsoft's Search Engine "Market Share" Fell to Almost 0%, CocCoc More Than 5 Times Bigger
Why are people still investing in this company?
All That's Left of MSNBC (Microsoft-NBC) is Microsoft NOW
When plutocrats and large corporations (even deep in debt) buy all the communication channels
The Register MS, Paid to Promote "AI" Hype, Does "Sez" (Says) Pieces
every bubble-funded "news" site tries to make it a story about "AI"
Many Companies Are Run by Liars Who Ride Other People's Money
Or steal it
Before CoreAI There Was Builder.ai
GitHub isn't about "AI" (just a bunch of lies and storytelling for shareholders' patience)
Microsoft Windows in Croatia at New Lows
We've been keeping track of this trend for a while
Using the Best Tool/s for the Job: RSS Feeds and RSS Readers
Use RSS feeds. Reject those "modern" Web things
Over at Tux Machines...
GNU/Linux news for the past day
IRC Proceedings: Tuesday, August 19, 2025
IRC logs for Tuesday, August 19, 2025
Gemini Links 20/08/2025: Neovim, XML, and Alhena 5.2.9
Links for the day