punctuation (syntax) in fig

i was thinking i should blog today, but i was stuck for a topic.

then after seeing this fun post: (via punctuation in code | code monk) i really wanted to leave a comment about punctuation in fig, but it felt too much like self-promotion. so thats what i will cover today:

for teaching purposes, im a fan of languages with minimal punctuation. but i get that some syntax can help readability, up to a point.

fig only requires “quotes for strings” and #hashes for comments. this once lead to complaints that it ran together too much, so i added colons as optional : command : separators.

then i had this crazy thought: what.(if, it.()was | more ; freeform) : and people could use the punctuation they want? then you can write examples that simulate (look more like) python, basic, or bash:

py = "hello".ucase().right(2) ; print()
basic = "hello" : ucase : right(2) : print
bash="hello"; ucase | right 2 | print

 

fig goes strictly left to right (without parentheses, i believe smalltalk does also) but you can include real python syntax this way:

py = "hello".ucase()
python
    for p in range(2):
        print(py[-2:] + py[-2:-1])
fig

 

by no means do i think every language should play fast and loose like this. fig is meant as an introduction to a number of programming concepts, and i could have decided to enforce stricter syntax. over time, the best option seemed to be to make most of it optional.

decimal points in the right place in a number do what you would think. decimal points in other places than numbers usually work, though to keep it working with numbers, fig cant let you be totally freeform with those.

allowed punctuation/syntax includes ( ) , . ; : |

in terms of line structure, fig is closest to bash one-liners, so the pipe | actually makes syntactic sense.

fig has two types of physical line-of-code:

  • a “shared” line that always starts with a “main variable.” (standard)
  • an “unshared” line that contains a single command (the exception.)

unshared lines are unshared to make them easier to find, and tend towards the level of importance of a line that wont “share” with already-used lines in python. for example:

if x > 5: # you can put python code to the right of this, but not the left.
ifmore x 5 # in fig, this line wont share with other code.

 

most lines begin with a “main variable” that is used sort of like a named pipe between commands:

x = "hello" | ucase | right 2 | print # each command sets or references x

 

the next line can reference that variable:

y = x | plus " there" | print | swap y x

thats how i explain fig to bash coders. i dont introduce inexperienced coders to “named pipes”; but if you can code in fig, then bash (with unnamed pipes) and basic and python are all reasonable next steps.

apropos of the post i linked to from this one, heres the punctuation from the above examples:

="".().();()
=""::():
="";||
="".()
():
([-:]+[-:-])
>:#
#
=""|||#
=|""||

although ive linked to another post, ive written everything contained in this one:

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s