💾 Archived View for gemlog.blue › users › codeinfig › 1614019970.gmi captured on 2022-06-12 at 01:13:58. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-04)
-=-=-=-=-=-=-
although fig was designed to teach 7 programming concepts, these concepts are common or illustrative to some degree in many, if not all programming languages. learning these concepts will help you understand python, bash, javascript and many others.
input refers to any task where data outside the program can get into the running program. commands can retrieve data from the keyboard, mouse, files, the network, or other peripheral devices. although every form of input (and every form of output) ultimately consists of numeric values, higher level languages like python, fig and javascript can sometimes make it much easier for the coder to deal with such data.
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:
now lineinput
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:
height 5 firstname "alan"
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" textfromkeyboard lineinput
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:
gemini://gemlog.blue/users/codeinfig/1613812161.gmi
- license: creative commons cc0 1.0 (public domain)