dir

From Esolang
Jump to navigation Jump to search

dir is an esolang made by user:CCeriseGD in 2024 based around files.

Programs

dir programs are directories with code and other files inside them. Commands start being executed from the file code.dir at the root of the directory.

Syntax

Commands have the following format:

command [file1 ...] [>[>] outputFile]

Also, anything after a # is a comment, and empty lines are ignored.

For each line, the command will be called with the contents of the files passed to it.

File paths can only have alphanumeric characters and -_./. Additionally, there are special file names starting with $; a $ followed by a number (starting at 0) is an argument passed to the interpreter (so $0 is the first argument passed). $# is the amount of arguments passed (# here doesn't start a comment).

If a line ends with > outputFile, the output of the command will be written to the output file. If it uses >> instead, the output will be appended to the end of the file. Otherwise, the output will be written to stdout.

Commands

cat <file1> ...

Concatenates all the files passed (any amount) and outputs the result.

cd <path>

If <path>/code.dir exists, goes to <path> and starts executing it, otherwise does nothing.

Note that cd some/path won't go to some/path/code.dir; it will read the file at some/path and use that as the path to go to.

rm <path>

Removes the file or directory at <path>, if it exists.

Like cd, rm some/path won't delete some/path; it will read the file at some/path and use that as the path to delete.

read

Prompts the user for input, then outputs that.

len <file>

Outputs the length of <file>. If the file doesn't exist, outputs -1.

head <size> <file>

Outputs the first <size> bytes of <file>.

tail <size> <file>

Outputs the last <size> bytes of <file>.

add <file1> ...

Outputs the sum of all the files passed (any amount).

sub <file1> <file2>

Outputs <file1> - <file2>

mul <file1> ...

Outputs the product of all the files passed (any amount).

div <file1> <file2>

Outputs <file1> / <file2>

eq <file1> <file2>

Outputs 1 if both files are the same, or 0 otherwise.

Note that the files will be parsed as numbers if possible, so if file1 is 1 and file2 is 1.0, eq file1 file2 will output 1.

lt <file1> <file2>

Outputs 1 if <file1> is less than <file2>.

gt <file1> <file2>

Outputs 1 if <file1> is greater than <file2>.

ord <char>

Outputs the Unicode codepoint for <char>.

chr <ord>

Outputs the Unicode character for codepoint <ord>.

External resources

Github repo (implementation in Python and a few example programs)