EditorsAbout the SiteComes vs. MicrosoftUsing This Web SiteSite ArchivesCredibility IndexOOXMLOpenDocumentPatentsNovellNews DigestSite NewsRSS

08.10.19

How To Write fig Programs

Posted in Free/Libre Software at 11:16 pm by Dr. Roy Schestowitz

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)

Share this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • co.mments
  • DZone
  • email
  • Google Bookmarks
  • LinkedIn
  • NewsVine
  • Print
  • Technorati
  • TwitThis
  • Facebook

If you liked this post, consider subscribing to the RSS feed or join us now at the IRC channels.

Pages that cross-reference this one

What Else is New


  1. Links 21/1/2020: EarlyOOM Fedora Decision and AMD Zen 3 Microcode

    Links for the day



  2. IRC Proceedings: Monday, January 20, 2020

    IRC logs for Monday, January 20, 2020



  3. Links 20/1/2020: MNT Reform, Linux 5.5 RC7, KMyMoney 5.0.8

    Links for the day



  4. Mansion of Pedophilia – Addendum: Accessing and Assessing Court Documents

    How anyone out there can do the job the media failed to do (after an apparently unprecedented arrest at the home of Bill Gates)



  5. Mansion of Pedophilia – Addendum: Progress on Police Request

    9 updates from the police department of Seattle but still nothing material/concrete, only promises and major delays



  6. IRC Proceedings: Sunday, January 19, 2020

    IRC logs for Sunday, January 19, 2020



  7. Mansion of Pedophilia – Part VIII: More Than 4 Months of Waiting for Police Department to Send Over the Files They Claim to Have an Issue Opening

    The police department (PD) of Seattle is unable to open its own files about arrest for pedophilia at Bill Gates' home; it has been unable to open these files for several months, it claims...



  8. Starting a GNU Replacement for GitHub, Possibly Based on GitLab

    "It might be easier if we start from the GitLab software," Stallman said



  9. European Commission Pushes for Even Greater Patent Maximalism Instead of Rationality, Patent Zealots' Site Cherry-Picks China as Whipping Boy

    Fear of China is being leveraged to promote an agenda of patent maximalists; the general idea they promote is that granting millions of low-quality patents is the only way to compete, even if in reality that merely handicaps the whole market



  10. CRISPR Patents Disallowed, But Where Are the Journalists?

    The narrative surrounding last week's decision against CRISPR patents may have been virtually monopolised by the litigation think tanks and law firms; it certainly feels like no journalism is left to rebut them, fact-check, and introspect



  11. Links 19/1/2020: Wine 5.0 RC6, Alpine 3.11.3

    Links for the day



  12. Judges Reject EPO Patents on Life as Constitutional Complaints Against the EPO Pile Up in Germany

    EPO judges throw out patents on life (CRISPR at least); there's now growing hope that they'll have the courage to do the same to patents on software



  13. IRC Proceedings: Saturday, January 18, 2020

    IRC logs for Saturday, January 18, 2020



  14. StartPage (System1) Found New Spin Allies. Some Have Been Offered StartPage Jobs. Some Might Already be Working for StartPage in Secret.

    Pro-StartPage voices appear to be paid (or have been promised pay) by StartPage; the key strategy of StartPage seems to be, attack and betray people's privacy while paying people in particular positions to pretend otherwise



  15. IRC Proceedings: Friday, January 17, 2020

    IRC logs for Friday, January 17, 2020



  16. Links 18/1/2020: Mir 1.7 and GNU Guile 3.0.0

    Links for the day



  17. IRC Proceedings: Thursday, January 16, 2020

    IRC logs for Thursday, January 16, 2020



  18. Links 16/1/2020: Mozilla Layoffs, PinePhone Braveheart Shipping, KDE Plasma 5.18 LTS Reaches Beta

    Links for the day



  19. Microsoft is a Market Leader in Lying and Corruption

    Microsoft is working hard to describe itself as the exact opposite of what it is and what it has been; ‘Internet rot’ helps a lot with this agenda, not to mention control of the media (the narrative)



  20. The European Patent Organisation Continues to 'Piss All Over' Separation of Powers

    The EPO continues to scatter invalid patents (IPs) that are European Patents (EPs) all over Europe and nobody can stop this, not even the judges of the EPO because they lack independence (by their very own admission)



  21. Zealots of Team UPC (Patent Litigation) Now Attacking the Courts and the Judges, Removing Their Mask on the Face of Things...

    The tactics of Team UPC aren't changing, only the shamelessness associated with these tactics is changing (because it looks like the end of days to them)



  22. Microsoft Now Uses or Leverages Software Freedom Against Free Software

    A reader's explanation of what Microsoft is trying to accomplish with its so-called 'embrace' and what steps will come next (how they manifest themselves)



  23. IRC Proceedings: Wednesday, January 15, 2020

    IRC logs for Wednesday, January 15, 2020



  24. Links 15/1/2020: CentOS Linux 8.1, Oracle VirtualBox 6.1.2 and GNU Sed 4.8

    Links for the day



  25. OSI Board at Microsoft: This is How Institutions Die or Completely Lose Their Purpose/Direction

    The photo (or meeting) may mark the turning point of the Openwashing as-a-Standard Initiative (OSI), which less than a year earlier took a bucket of money from Microsoft



  26. IRC Proceedings: Tuesday, January 14, 2020

    IRC logs for Tuesday, January 14, 2020



  27. When Microsoft's Actions Speak for Themselves (About Back Door Access)

    Unwittingly, people are being reminded of the 'special relationship' between Microsoft and the US Army (or government); The back doors or bug doors are still there, even 7 years after Edward Snowden's NSA leaks



  28. Why You -- Yes, You Too -- Should Consider Migrating to GNU/Linux

    The window is closing (and Windows/Vista 7 closing down); the chance to use machines that the users actually control is still there



  29. Can We Please Stop Lying for Microsoft in the Mainstream Media?

    Dishonesty for short-term financial gain (e.g. advertising money) will be a big loss in the long run. There’s a reason why so many news sites perish and Datamation (where I wrote more than a decade ago) now throws away remnants of reputation by spreading a big lie from Microsoft.



  30. It's Only Factual and Truthful to Point Out That About Half of the EPO's Management Committee Are From the President's Nation (and Many Are Underqualified Friends of His)

    The patent-granting extravaganza of what a reader and contributor of ours likes to call "Club Med" will result in great pain (not just for the Office but for Europe as a whole); pointing out who's to blame (the culprits) is an exercise in practicality


RSS 64x64RSS Feed: subscribe to the RSS feed for regular updates

Home iconSite Wiki: You can improve this site by helping the extension of the site's content

Home iconSite Home: Background about the site and some key features in the front page

Chat iconIRC Channel: Come and chat with us in real time

Recent Posts