You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


fig feature: main variable instead of option explicit
06-08-2017, 09:31 AM (This post was last modified: 06-08-2017 09:32 AM by figosdev.)
Post: #1
 (Print Post)
fig feature: main variable instead of option explicit
"main variable" wasnt intended to create a stricter basic, it was intended to make an aspect of python easier and more natural.

"main variable" just means "most lines begin with a variable":

x "this is a variable"
p print #### prints 0
p 15 print #### prints 15
p plus 10 print #### prints 10
now x print #### prints "this is a variable"


a main variable is actually a little like a named pipe, but thats a coincidence.

if you put an equals sign in for assignment, fig works exactly the same as without it:

x = "this is a variable"
p = print #### prints 0
p = 15 print #### prints 15
p = plus 10 print #### prints 10
now = x print #### prints "this is a variable"


but for that line the variable is on, functions can write to and read from the main variable, saving a parameter:

x = "hello" : ucase : left 2 : plus "Y" : print
x="hello":ucase:left 2:plus "Y":print


instead of option explicit, python requires that each variable be set to something before its use. so this will not work:

while 1: x += 1 ; print x


unless you do this first:

x = 0
while 1: x += 1 ; print x


i could have made it so that in fig, any unset variable referenced simply returns 0, instead of an error like in python. i couldve made it give every unset variable an undefined status.

considering how visual basic coders and other basic coders (and most languages) handle unset/undeclared variables these days, that felt like too much of a step backwards-- and ultimately i want fig users to be able to use python *if they want to.*

so i decided to build setting a variable into the syntax of the language, and have every line start with a variable.

you will still get an error if you reference an unset variable, just like in python (or basic with option explicit):

y = x : print # x is not set, will error


but if you start each line with a variable, it will at least zero the variable for you:

x
y = x : print # x is 0


block commands (and one or two others, like textmode) do not start with a main variable.

most commands in fig are known as "shared-line" commands, because they share a line with the main variable (and each other.)

block commands (and one or two others) are known as "own-line" commands, because they have their own line:

for x = 1 15 1
now = x : print
next


i couldve held the block commands to the same standard, which i suppose would make sense for the for block. but while?

p while
now "hello" print
x wend
#### ???????


the point of the main variable is to keep variable conventions in the rules in a way that seems natural.

in most languages, when you have learned "hello, world" youve only learned how to do a string and an output command.

in fig, setting variables is the most natural thing you can do:

x = 5
phone = 5551212
cheese = "ring ring ring ring ring" # ?


then because fig goes left to right, you simply add a print statement:

p "hello world" print


i often use the "now" variable as an unimportant in examples, at the risk of making it look like a command.

now "hello!" print


although its not best practice to use single-letter variables (even though the original basic only allowed one letter and one digit) i think its fairly clear that p is not a command:

p cls
p "hello, world" print


so thats the "main variable" in fig: most lines start with a "main variable" that many fig commands can share as an implicit parameter.

oh, and an implicit parameter! i know, thats not python at all. or is it? its right on the left. oh, i dont care. python doesnt have a monopoly on design, and a lot of people would be unhappy if they did. sometimes i wonder if the official term for a python coder should be "hipster."


#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/

^ in case anyone decides to do another book on fig
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Kings Court
QB64 Member Project - Input
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Quarto
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Touche
QB64 Member Project - Point Blank
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Pivet version one
QB64 Member Project - Algeria Weather
QB64 Member Project - Inside Moves
QB64 Member Project - Bowditch curve
QB64 Member Project - Rubix's Magic
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Spiro Roses
QB64 Member Project - Color Triangles
QB64 Member Project - Line Thickness
QB64 Member Project - Kings Valley verion one
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Amazon
QB64 Member Project - Rotating Background
QB64 Member Project - Connect Four
QB64 Member Project - Overboard
QB64 Member Project - 9 Board
QB64 Member Project - Splatter
QB64 Member Project - Qubic
QB64 Member Project - Swirl
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Sabotage
QB64 Member Project - Color Rotating Text
QB64 Member Project - Basic Dithering
QB64 Member Project - Dakapo
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Isolation
QB64 Member Project - Exit
QB64 Member Project - Score 4
QB64 Member Project - ARB Checkers
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Dreamy Clock
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Domain
QB64 Member Project - Othello
QB64 Member Project - Pivot version two
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Foursight
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Blokus