💾 Archived View for rawtext.club › ~sloum › nimf › guide › 02-running.gmi captured on 2023-05-24 at 18:17:24. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
____ ____ ____ ____ ||n |||i |||m |||f || ||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|
Now that you have nimf built on your system, lets jump in and run the interpreter. There are a few ways to interact with nimf. We'll go over each of them here, but the main focus of this guide will be on the interactive mode.
All commands given below assume that the nimf executable is now on your path and is called nimf (which is the default when using the Makefile)
Starting nimf in interactive mode can be done simply by typing the following in most any shell:
nimf
When nimf starts it should output the version of nimf and drop you to a prompt: `>`.
You are now in nimf's REPL (read evaluate print loop). You can type any numbers, words, or commands that nimf recognizes and nimf will process them in real time. By default, no modules from the standard library will be inlined so you will only have access to builtins.
Starting nimf in file mode is done by passing the path to a nimf code file to the interpreter. For example:
nimf ./my_nimf_code.nf
By convention, nimf files that are meant to be executed have the suffix `nf` and files that are meant to be inlined and used in other code as modules have the suffix `nh`. These are not requirements, but help make intentions clear.
When running a file nimf will parse and run the contents of the file and exit when finished, or when an error is encountered.
The nimf interpreter is able to work with the shell to run files using a shebang, for example:
#! /usr/bin/env nimf
For more info on shebangs, see:
Run mode is a special mode that takes a string at runtime, executes the contents of that string and exits. This is mainly useful for oneliners and for incorporating nimf into shell scripts. It is used like so:
nimf -run '5 7 * ,'
The above code would multiply 7 by 5, output the result, and exit.
Run mode cannot be used in conjunction with a file (file mode). If a file is passed when the -run option has been declared, the file will be ignored.
You can also set the stack depth and available memory for the nimf interpreter at runtime by using the -memory and -stack-depth options:
nimf -memory 50000 -stack-depth 100
Either option may be used with any run mode (interactive, file, or run). For most use cases these flags will be unnecessary and the default values will be fine, but it is good to know that they are there if you run into issues not having enough memory or stack depth or if you dont need as much as is provided by default and want to run lean.
________________________________________________