digital literacy for everyone
[[variables]] | /input/ | [[output]] | [[basic-math]] | [[loops]] | [[conditionals]] | [[functions]]
a prime example of this is when opening a file is as trivial as supplying the filename and a variable to store its contents in. instead of a stream of numbers, most modern languages will simply give you the letters, numbers and other characters are that are represented by the file.
for example, if you save a file that just says "hello", and the file is named text.txt, the arropen command:
now arropen "text.txt"
will open it and store each line of the file in the variable now. if you then output the contents, it will show the word "hello" on the screen.
likewise, if you use the lineinput command, and type the phrase "this is fig" into the keyboard:
the phrase "this is fig" will be stored in the variable now.
apart from introducing figs second concept of input, these commands demonstrate a convention that adds to our concept of how the language works--
in the section on variables, we learned that you could set the value of a variable by providing a number or string:
in this section, instead of setting the variable on the left to a known value, we set the variable to the value that a fig command provides-- either arropen for the contents of a file, or lineinput for a string typed on the keyboard.
textfromfile arropen "text.txt"
we learned about strings in the previous section, which is the type of value that lineinput gives. but arropen is named that because it creates an array of values, which it stores in the variable now (in our first example) or the variable textfromfile (in the second example.)
in the example of arropen, it actually sets the variable on the left to an array of strings. each string in the array is a single line of the text file.
so far, we have learned how to set a variable and how to get information from files and the keyboard. these examples create data that the program has access to, but that isnt useful to us unless the program can [[output]] information as well.
please note, that if you are reading these sections and expect to understand coding from them, you really should be typing the code into a file and running it with fig. it is possible to learn how fig works just in theory, just like you dont need to count beans or sticks to know that 2 + 2 = 4. but typing and running code is a far more powerful way to watch and learn what code does in practice, not just in theory.
when you can watch code working, it means far more to the student than "this is how a program would work, if i actually ran it." although fig is meant to be easy enough that you could learn it with pen and paper, it is best to actually run the code like you would with other programming courses. you can get fig on this page: [url]../fig/index.html[url]
back to fig concepts: [url]https://codeinfig.neocities.org/figconcepts/index.html[url]
fig main page: [url]https://codeinfig.neocities.org/fig/index.html[url]