Interactive REPL

Interactive REPL sessions

Nift vaporwave artwork

There are two modes in which you can run an interactive REPL session with Nift, interpreter mode interp and shell mode sh. The only difference between the two modes is that interpreter mode just has the language in the prompt, whereas shell mode has both the language and the present working directory in the prompt.

[contents]

Contents

Interpreter mode

An interpreter REPL session can be started with either of:

nsm interp -lang
nift interp -lang

Note: f++ is the default language used when no language option is specified.

In the interpreter mode the prompt will just tell you which language you are using. If you would like the prompt to also display the present working directory (up to using half the width of the console) you can switch to shell mode using nsm_mode("sh"). You can switch back again with nsm_mode("interp").

Shell mode

A shell REPL session can be started with either of:

nsm sh -lang
nift sh -lang

Note: f++ is the default language used when no language option is specified.

The f++ shell, also called FLASHELL or FLASH (fla-sh) or even FSH if people want to be even more succinct (and helps cover for F++ who also use FSH), or make up your own names for the binaries and other parts if you need to hide things better, attempts to work as an extension of the default shell for c++ system calls, which is likely to remain always being bash on posix compliant platforms, it does also work on Windows and I am unsure whether you can change the shell anywhere on Windows that modifies the shell used by c++ system calls.

FLASH for example can often do many things faster than the shell being used for c++ system calls. For example on my machine (which is quite old) this FNSTEIN script runs in ~3s whereas this bash script runs in more like ~3m.

Note: To get the FNSTEIN script to work you will need to add a $ before the ``'s for the ExprTk expression as the syntax has changed. Also be weary that if downloading the FNSTEIN script it has a .cpp extension for syntax highlighting purposes on pastebin. Also you do DO NOT want to leave the directory open in your file browser (the gui) when running either script.

One major limitation is not being able to define bash variables and have them exist beyond the c++ system call they are used for. There is however access to the type systems and everything else for all of FLASH/FNSTEIN, TMPLTSTEIN, Lua(JIT) and ExprTk, you can write blocks of code at a time for sys/system calls where variable definitions etc. carry over and you can parse the block first with any of the languages in-built or embedded in to Nift. You can also run scripts that exist, or are contained in a block of code following the script function call.

In the shell mode the prompt will tell you which language you are using and the present working directory (up to using half the width of the console). If you would like the prompt to just display the language you can switch to interpreter mode using nsm_mode("interp"). You can switch back again with nsm_mode("sh").

RC Scripts

You can have a global script titled similar to niftrc.f but for the exec name you use in the same directory as your global config file (try opening up a shell or interpreter from outside any Nift projects to find the location of the global config file).

Alternatively, you can do project specific "run commands" scripts for the language being used following the naming structure [interp/sh].langChar, eg. sh.f and interp.l.

You can also name the global and project "run commands" scripts with the language as the extension rather than just the first letter, for example niftrc.lua or interp.exprtk or sh.f++, etc..

Languages

The following language options are available:

  • exprtk
  • f++ (default)
  • lua
  • n++

You can switch to one of the other languages available during an interactive REPL session using nsm_lang(langStr) where langStr is one of f++, n++, lua or exprtk.

Multi-line input

The are various ways to achieve multi-line input during an interactive REPL session, when reading additional lines of input before parsing the end of the prompt changes to > instead of its normal $. The following table lists the shortcuts on different platforms to input another line before parsing (including ending a line with \):

FreeBSD Linux OSX Windows
alt enter
ctrl r
\ enter
alt enter
ctrl r
\ enter
ctrl r
\ enter
ctrl enter
ctrl r
\ enter
FreeBSD Linux OSX Windows

Note: An interactive REPL session will continue to input lines before parsing until the input to be parsed has an equal number of open and close brackets. To override this put an = at the end of an input line with no whitespace following. A couple of f++ examples follow:

int x=10
if(x == 10) {
	console("code-blocks in interactive REPL sessions")
}

console("example with ( and { not closed") =

Shortcuts

The following shortcuts are available during interactive REPL sessions:

Description FreeBSD Linux OSX Windows
go to start of line ctrl a ctrl a ctrl a ctrl a
go to end of line ctrl e ctrl e ctrl e ctrl e
move cursor forwards one position
ctrl f

ctrl f

ctrl f

ctrl f
move cursor backwards one position
ctrl b

ctrl b

ctrl b

ctrl b
move cursor forwards to next space alt f alt →
alt f
ctrl →
alt → ctrl →
move cursor backwards to previous space alt b alt ←
alt b
ctrl ←
alt ← ctrl ←
delete from cursor to end of line ctrl d ctrl d ctrl d ctrl d
delete from cursor to start of previous word ctrl delete
ctrl shift -
ctrl -
ctrl delete
ctrl shift -
ctrl shift -
ctrl -
ctrl delete
ctrl [
delete from cursor to start of next word ctrl ] ctrl ] ctrl ] ctrl ]
line break (input another line before parsing) alt enter
ctrl r
\ enter
alt enter
ctrl r
\ enter
ctrl r
\ enter
ctrl enter
ctrl r
\ enter
Description FreeBSD Linux OSX Windows