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. “The True Hypocrite is the One Who Ceases to Perceive His Deception, the One Who Lies With Sincerity,” Said André Paul Guillaume Gide (Nobel Prize in Literature)

    Lies flow like water in the realm of EPO and its publishers, whose sole role is dissemination of deliberate falsehoods, misnomers and misinformation



  2. The EPO Cannot Guard Fake European Patents From Scrutiny (in the Long Run)

    Legal certainty associated with newly-granted European Patents is already pretty low and as long as the EPO refuses to acknowledge that its courts (or boards) lack autonomy the EPO merely brushes a growing problem under the rug



  3. Links 19/10/2019: DeX Discontinued, DXVK 1.4.3 and Wine 4.18 Released

    Links for the day



  4. 'Corporate Linux' Will Not Protect Software Freedom

    The corporate model is inherently not compatible with software that users themselves fully control (or Software Freedom in general), so we must rely on another model of sovereignty over code and compiled code (binaries)



  5. IRC Proceedings: Friday, October 18, 2019

    IRC logs for Friday, October 18, 2019



  6. 26,000 Posts

    We want to thank those who help spread the word; it gives us moral support and morale.



  7. The Myth of 'Analysts'

    People with exaggerated roles (exaggerated by corporate media and corporations that control them) distort public perceptions about their clients; they're in effect just elevated marketing or Public Relations (PR) operatives



  8. The FSF Has Two Acting Presidents Now

    Alexandre Oliva, who acted as a sort of deputy of Richard Stallman in recent weeks, sheds some much-needed light on the current situation



  9. Should Anybody Dictate the Free Software Movement?

    "There's a great myth, as Jagadees reminds us, that advocacy doesn't produce software. That myth is corporate, and proper advocacy has at times produced the greatest software in the history of computing. If we want great Free software to continue, we need advocacy more than ever."



  10. Links 18/10/2019: More KDE Events and OpenBSD 6.6

    Links for the day



  11. We Don't Know Who Will Run the Free Software Foundation, But We Know Who Will Run the GNU Project

    Software Freedom is under a heavy and perhaps unprecedented attack; some people out there are paid by the attackers to celebrate this attack and defame people (cheering for corporate takeover under the blanket of “Open Source”), but the founder of the Free software movement remains alive, well, and very much active



  12. New EPO Meme: Who Wants to Make Billions From a 'Public' Monopoly?

    What was supposed to be a cash-balanced patent office became a money-making monster that fakes ‘crises’ to attack hard-working examiners



  13. EmacsConf Without Richard Stallman

    Now that emacs is being 'rebranded' this kind of meme seems apt



  14. IRC Proceedings: Thursday, October 17, 2019

    IRC logs for Thursday, October 17, 2019



  15. Guest Article: In the Absence of Richard Stallman OEM Source Software ('Open Source') is Trying to Hijack Even Emacs

    "Now they have to create some fictional history. No need to worry."



  16. Guest Article: Techies Should Not Dictate the Free Software Movement

    "We should start a second phase of the Free software movement that's making good software and putting users at the center."



  17. Links 17/10/2019: Ubuntu Turns 15, New Codename Revealed, Ubuntu 19.10 is Out

    Links for the day



  18. Free as in Free Speech (Restrictions May Apply)

    When limits of speech are not safety-related rules but political correctness or conformism



  19. There Won't be Patent Justice Until Patent Trolling Becomes Completely and Totally Extinct

    SLAPP-like behaviour and extortion/blackmail tactics using patent monopolies are a stain on the patent system; it's time to adopt measures to stop these things once and for all, bearing in mind they're inherently antithetical to the goal/s of the patent system and therefore discourage public support for this whole system



  20. EPO Staff Union and Staff Representatives Ought to Demand EPO Stops Bullying Publishers and Censoring Their Sites

    An often neglected if not forgotten aspect of EPO tyranny is the war on information itself; EPO management continues to show hostility towards journalism and disdain for true information



  21. Bribes, Lies, Fundamental Violations of the Law and Cover-Up: This is Today's European Patent Office

    It has gotten extremely difficult to hold the conspirators accountable for turning Europe’s patent office into a ‘printing machine’ of the litigation industry and amassing vast amounts of money (to be passed to private, for-profit companies)



  22. The Free Software Foundation (FSF) Lost Almost Half (3 Out of 8) Board Members in Only One Month

    As the old saying goes, a picture (or screenshot) is worth a thousand words



  23. IRC Proceedings: Wednesday, October 16, 2019

    IRC logs for Wednesday, October 16, 2019



  24. Startpage and System1 Abuse Your Privacy Under the Guise of 'Privacy One Group'

    Startpage has sold out and may have also sold data it retained about its users to a privacy-hostile company whose entire business model is surveillance



  25. Links 16/10/2019: Halo Privacy, Ubuntu Release Imminent

    Links for the day



  26. IRC Proceedings: Tuesday, October 15, 2019

    IRC logs for Tuesday, October 15, 2019



  27. No, Microsoft is Not an 'Open Source Company' But a Lying Company

    The world’s biggest proprietary software companies want to be seen as “open”; what else is new?



  28. Meme: Setting the Record Straight

    Stallman never defended Epstein. He had called him “Serial Rapist”. It’s Bill Gates who defended Epstein and possibly participated in the same acts.



  29. EPO Staff Resolution Against Neoliberal Policies of António Campinos

    “After Campinos announced 17 financial measures,” a source told us, “staff gathered at multiple sites last week for general assemblies. The meeting halls were crowded. The resolution was passed unanimously and without abstentions.”



  30. Satya Nadella is a Distraction From Microsoft's Real Leadership and Abuses

    "I’m merely wondering if his image and accolades that we’re incessantly bombarded with by the press actually reflect his accomplishments or if they’re being aggrandized."


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