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. IRC Proceedings: Wednesday, June 03, 2020

    IRC logs for Wednesday, June 03, 2020



  2. Social Engineering of Free Software, Based on Corporate Criteria

    What "professional" nowadays means in the context of coding and honest assessment of technical work



  3. Weakening GNU/Linux by Disempowering Its Leaders and Founders, Replacing Them With Microsoft Employees and GNU/Linux-Hostile Moles

    The coup to remove (or remove power from) Stallman and Torvalds, the GNU and Linux founders respectively, is followed by outsourcing of their work to Microsoft’s newly-acquired monopoly (GitHub) and appointment of Microsoft workers or Microsoft-friendly people, shoehorning them into top roles under the disingenuous guise of "professionalism"



  4. Sword Group Violates Its Own Commitment by Working for the EPO

    The European Patent Office (EPO) keeps outsourcing its work to outside contractors (for-profit private entities) to the tune of hundreds of millions if not billions — all this without any oversight



  5. In 2020 Canonical No Longer Fights for Freedom

    Freedom requires a GNU/Linux distro other than Ubuntu, which seems unwilling or unable/incapable of speaking about and promoting the ideals of GNU/Linux



  6. We Need to Use the F Word (Freedom) to Promote Adoption of GNU/Linux

    "People get the government their behavior deserves. People deserve better than that." -Richard Stallman



  7. People Who Want to Explore GNU/Linux With Ubuntu See This Today

    "Wait, am I in a GNU/Linux blog or another Windows blog," a visitor might think... or, is Microsoft 'taking over' messaging at Canonical? (Same with code)



  8. Links 4/6/2020: Septor 2020.3, Nextcloud and Blender 2.83

    Links for the day



  9. Hey, Where's Red Hat (IBM)?

    Red Hat is conspicuously silent at these critical times (in its home country); Must be too busy hailing and cashing in on Trump's military (state) while dishing out shallow and self-contradictory diversity PR/fluff…



  10. Microsoft's Latest Vapourware About Supercomputers

    Microsoft has spent almost two decades dropping supercomputers vapourware on the media, but those misinformation dumps always turn out to be 100% hot air, no substance



  11. 2020: A Time for Resolutions or Revolutions?

    There are nonviolent means by which the current system can be corrected; we need to convince peers and relatives to change the way they behave and not cooperate with unjust elements of the system



  12. IRC Proceedings: Tuesday, June 02, 2020

    IRC logs for Tuesday, June 02, 2020



  13. The Gates Press (GatesGate) -- Part I: Lost the Job After Writing an Article Critical of Bill Gates for Attacking Some Actual, Legitimate Charities (Because They Had Spread GNU/Linux)

    The sociopaths from the fake 'charity' of Bill Gates would go to great lengths to squash criticism and also to eliminate critics; this series tells the story of some of those personally affected



  14. Don't Fall for the Spin, Microsoft is Laying Off Workers and It's Not Just Because of the Pandemic





  15. All They Want is Litigation, Not Innovation

    It's getting difficult to ignore or to overlook the fact that the 'litigation lobby' (the likes of Team UPC and today's EPO management, guided by groups like the Licensing Executives Society International) doesn't care about innovation and is in fact looking to profit by crushing innovation



  16. Reminder: Microsoft Profits From Crushing Protesters for Donald Trump

    Don't lose sight of the fact that what's going on in the United States right now is very profitable to Microsoft



  17. No, GNU/Linux Isn't at 3% and Windows Isn't at Over 90%, Either

    This ludicrous idea that "Linux" (however one defines it) enjoys just 3% of the "market" is false and it should be treated as laughable spin (it is being widely promoted this week, often by Microsoft boosters looking to make charts where Windows stays at above 90% and Vista 10 is 'gaining'... at the expense of Windows)



  18. Links 3/6/2020: Devuan Beowulf 3.0.0 and Tails 4.7 Released

    Links for the day



  19. Links 2/6/2020: New Firefox Release (77), Debian-based MX Linux 19.2, KDevelop 5.5.2, GNU/Linux Growth on Desktops/Laptops

    Links for the day



  20. Techrights Can Figure Out Source Protection/Anonymisation Whilst Operating Very Transparently

    We're still quite radically transparent whilst at the same time enjoying 100% source protection record; we're also improving the software we use to publish more quickly and efficiently



  21. IRC Proceedings: Monday, June 01, 2020

    IRC logs for Monday, June 01, 2020



  22. This is How GNU Finally Dies

    "Brace for when GNU falls the way that OSI, FSF, FSFE, Mozilla, and the Linux Foundation did."



  23. Latest Microsoft Layoffs Spun as 'Innovation' (There's Always a Positive PR Angle)

    The public is expected to simply ignore the fact that Microsoft is laying off employees (again); instead we're expected to think it's all about Microsoft being very brilliant and innovative



  24. Microsoft Playing the Victim, Irrationally 'Hated' by Victims of Its Abuse

    We're meant to believe that those whom Microsoft bribes against are the opinionated 'haters' and Microsoft is a victim of 'hate'



  25. Links 1/6/2020: Linux 5.7, FOSSlife Born, LibreOffice 7.0 Beta1, Linux Mint 20 Making Early Promises

    Links for the day



  26. Linux Without Linus

    The Linux Foundation seems to be acting like Linus (Linux founder) is somewhat of a liability (forcing him to take a ‘break’ from his own project) while taking even the most notorious proposals from corporations, including those that called Linux a “cancer”



  27. What It Would Take for Linus Torvalds to Leave Linux Foundation Without the Linux Trademark and Without Linux

    It's nice to think that the founder of Linux can just take his project and walk away, moving elsewhere, i.e. away from the Microsoft-employed executives who now "boss" him; but it's not that simple anymore



  28. The Past Does Not Go Away, Except From Short-Term Memories

    People who are drunk on power and money (sometimes not even their own money) like to portray themselves as the very opposite of what they are; but in the age of the Internet it's difficult to make the general public simply forget the past and "move on..."



  29. IRC Proceedings: Sunday, May 31, 2020

    IRC logs for Sunday, May 31, 2020



  30. Links 1/6/2020: OpenMandriva Lx 4.1 2020.05, Linux Lite 5.0 Release, FreeBSD 11.4 RC2

    Links for the day


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