ised(1)

๐Ÿ“ฆ version 2.7.1, in nixos 26.05, nixpkgs unstable

๐ŸŒธ ised(1) ๐ŸŒธ

okay bestie, welcome to the General Commands Manual glow-up for ised(1) โ€” it's giving iconic Unix energy, and we're doing this in four parts. This is part 1, so get comfy ๐Ÿซถ

๐Ÿ’– NAME ๐Ÿ’–

  • ised โ€” generating integer and floating point sequences. that's the whole vibe: numbers, arrays, sequences, slay.

โœจ SYNOPSIS โœจ

ised [--m] [--p] [--n] [--f input_file] [--a load_file] [--l
apply_to_file] [--x modify_file] [--k awk_file] [--o output_file] [--t
code_line] [--d delimiter] [--D int_format] [--F float_format] code ...

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

ised processes arithmetic expressions involving arrays and returns output array of values. Options and code lines are processed in order of appearance. If ised is called without arguments, it reads from standard input. Press ^D (EOF) or enter a single q to exit when in interactive mode.

When input consists only of arrays of length one (scalars), ised behaves as an ordinary calculator.

Options can also be used from command line in interactive mode or in files, invoked by --f.

๐ŸŽ€ OPTIONS ๐ŸŽ€

  • --f input_file โ€” reads and processes input_file one line at a time, equivalent to giving every line as separate command line argument. btw ised --f - is not equivalent to running it without arguments, as the latter also invokes interactive GNU readline prompt.
  • --a load_file โ€” loads load_file into memory. Every line has its own memory slot, starting at $1. At the end, line count is saved in memory slot $0. All lines are evaluated before saving.
  • --l apply_to_file { code | --f file } โ€” code or file is applied on every line of apply_to_file. Each line is loaded into memory slot $1 while line number is in $0.
  • --x modify_file { code | --f file } โ€” similar to --l, but instead of direct evaluation of lines in modify_file, it splits the line into numbers and strings. The numbers are read and stored into $1, then the code or file is applied. The output has the same form as the input, with the numbers replaced with those returned by the code or file. The $0 memory slot contains the current line number.
  • --k awk_file { code | --f file } โ€” similar to --x, but instead of smartly finding the numbers and storing them all into the same array, it splits each input line at delimiters and stores each column into a separate memory slot, starting with $1. Non-numeric fields are preserved in the output without warning. Changes to the memory slots by the user are reflected in the output. The output is delimited by the delimiter, provided by --d. If code is not terminated by a semicolon, the return value of code or file is appended to the rest of the output.
  • --o output_file โ€” sets the file where standard output is redirected to. Everything after this call will be redirected to output_file, until the next call to --o. Calling --o - reverts back to the standard output.
  • --t code_line โ€” code_line is evaluated as usual, but results of every semicolon-terminated substatement are printed as columns. Essentially this is a transposed version of --p option. If code_line contains only one statement, the result is similar to setting delimiter to newline (\n). If code_line is to be applied line-by-line to a file, both --x and --k behave as --l.
  • --d delimiter โ€” string delimiter is used to delimit values of output array. Default is space.
  • --D int_format โ€” format for printf function for integers. Default: %d.
  • --F float_format โ€” format for printf function for floating point values. Default: %g.
  • --m โ€” dump memory page. iykyk.
  • --p, --n โ€” --p forces ised to print results even when suppressed by semicolon. Every semicolon-terminated substatement is output with terminating newline, so this can be used to split lines when in --l mode. This option persists until it is turned off with --n.
  • --v โ€” show program version and license disclaimer.

๐Ÿ‘‘ COMMANDS ๐Ÿ‘‘

ised operators all work on arrays of values. Even single values are treated as arrays with length of one. Spacing between operators and values is optional. Values can be either floating point or integers and retain information about their type unless changed. Same operators behave differently for each type.

In general, operators starting with colon (:) mean component-wise evaluation.

โš ๏ธ bestie, listen: behaviour in case of illegal arithmetic output (such as division by zero or root of negative values) is uncertain and may return either nan, zero or some other non-standard result. This should not be relied upon as it may change in future releases. The case of integer overflows is to be avoided by user as the program does not issue a warning and the output is wrong and unpredictable. The same holds for conversion of floats to integers. Since version 2.2.3, integer overflows are handled by implicit conversion into floating point type if compiled for x86-64 architecture, but caution is still advised, as the handling may not catch all the problematic cases.

๐ŸŒˆ Comments ๐ŸŒˆ

Lines are considered as comments if preceded by #!. If #! appears in the middle of the line, everything behind it is commented out. Completely blank lines are also ignored, but lines with whitespace characters will be treated normally. This way user can separate several blocks of output by empty lines.

Scripts can be made executable and evaluated without invoking ised explicitly. This is done by including declaration

#!/usr/local/bin/ised --f

in the first line of the script. This line is obviously treated as comment.

In apply-to-file mode, comments and blank lines are preserved in input, but don't count as active lines and therefore don't increment line counter. If a file contains mixed data, it can still be processed line-by-line if non-numerical data is commented out.

๐Ÿ“ Arrays and Separators ๐Ÿ“

Values, separated by commas (,) or spaces ( ) are treated as components of an array. Array separation has lowest precedence, so any operators are evaluated before the array is collected. Nested arrays are flattened before further evaluation. Arrays are enclosed in braces {}, outermost braces are optional.

Output to terminal and history is suppressed by semicolon ; which can occur any number of times in every line (putting it at the end suppresses all output, but still evaluates memory operations, if they're present).

Examples:

{1 2 {3 4} 5,6} = {1 2 3 4 5 6}

{1 2+3 4 5*6+7} = {1 5 4 37}

1 5 1+1 = {1 5 2}

๐Ÿงš Array Constructors ๐Ÿงš

  • [n] โ€” generates sequence 0..n-1.
  • [n1 n2] โ€” generates sequence n1..n2 with increment 1. If n2<n1, sequence is descending.
  • [n1 m1..mi n2] โ€” generates sequence between n1, n2, but with cycling increments, given as m1..mi. Example: [0 1 2 10]={0 1 3 4 6 7 9}.
  • (x) โ€” repeats number x. This way parentheses can be used for evaluation precedence or for function arguments in scalar context.
  • (x n) โ€” generates array of n repetitions of number x.
  • (x m1..mi n) โ€” generates sequence of length n, starting at x with cycling increments m1..mi. If n is negative, the increments are used |n| times, so for i increments, the output sequence has |n|*i+1 elements. Examples: (0 1 2 10)={0 1 3 4 6 7 9 10 12 13} and (0 [1 5] -1)={0 1 3 6 10 15}.
  • {x1..xi} โ€” array grouping.

๐Ÿ’… Component-wise Operators ๐Ÿ’…

  • x:+y, x:-y, x:*y, x:/y, x:%y, x:^y โ€” result is an array, where each component is e.g. a sum (or other binary operations above) of corresponding components of x and y. In case of different lengths of arrays, smaller length is used. Operations corresponding to above operators are: addition, subtraction, multiplication, division, modulo, exponentiation. Note that modulo works for both integer and non-integer values. Modulo always satisfies this equation: i{x/dy}*y+x%y=x.

๐Ÿฆ‹ Scalar-producing Operators ๐Ÿฆ‹

  • @+x โ€” returns sum of components of x.
  • @*x โ€” returns product of components of x.
  • x+*y โ€” returns a result of alternating addition and subtraction, in the form ((x_0+y_0)*x_1+y_1)*x_2+y_2+.... If x is shorter than y, the elements of x are cyclically reused from the beginning of the array. If y is shorter than x, it is padded with zeroes. This way, a scalar x can be used to evaluate a polynomial with unit leading coefficient.
  • gcd, lcm โ€” return greatest common divisor and least common multiple of the numbers in the array, respectively. If the array includes noninteger numbers, a warning is issued and an empty array is returned. The result of gcd is negative if an odd number of the array are negative.
  • avg, var โ€” return linear average and variance (mean square dispersion). avg{x} is shorter notation for @+x/d#x and doesn't require inputting the array twice or storing it in memory. Example: avg{0 1.5 3}={1.5}.
  • nrm x y โ€” returns generalized x-norm of vector y. If x is a vector, the result contains all specified norms. x=2 corresponds to Pythagoras' theorem, which is available also as operator @=. Examples: nrm2{1 1 1}={sqrt3} and nrm{1 3}{1 1}={2. cbrt2}.

๐ŸŒธ Function Maps ๐ŸŒธ

  • sin, cos, tan, atn, asn, acs, abs, exp, sqt, cbt, log โ€” evaluates a function on every element of array, e.g. sin{1 2 3}={sin1 sin2 sin3}. Functions corresponding to above operators are sine, cosine, tangent, arc tangent, arc sine, arc cosine, magnitude, exponential, square root, cubic root, natural logarithm. Long operators atan, asin, acos, sqrt, cbrt are also valid. Exponential function is also available as e^, but has a lower precedence (the same as the operator ^). The unary / prefix is also a function map: /x=1.0/x.
  • x! โ€” evaluates factorial on every element of array x. For floating point values it evaluates gamma(x+1). For negative integers, it returns 1.
  • r, f, i, d โ€” prefixes that modify values of array elements.
    • r โ€” rounds values to closest integer.
    • f โ€” returns fractional part of values. It is always in range 0..1 and represents distance to downwards rounded integer, even for negative values.
    • i โ€” returns integer part of values. Expression fx+ix=x always holds.
    • d โ€” converts values to floating point. For example, 1/2=0 but 1/d2=0.5.
  • ran โ€” randomizes elements of array. For integers, it returns random integers strictly smaller than given value. For floating values it returns real numbers.
  • phi โ€” bestie this is the Euler totient function, but it's picky: it only does positive integers. Nonpositive and noninteger values are literally just skipped, no notes. ๐Ÿ’…
  • bj x y, by x y โ€” applies the x-th Bessel function of the first / second kind to array y. x should be one or more integers โ€” floating point values get cast to integers and a warning is issued (she will call it out, sorry ๐Ÿซถ).

โœจ Tensor Operators โœจ

Ok so this is the fun part. ๐ŸŽ€

  • x+y, x-y, x*y, x/y, x%y, x^y โ€” evaluates the corresponding operation on every possible pair between elements of x and y. This is highkey the most useful when one of the arguments is a scalar (the other one does all the work, main character energy ๐Ÿ‘‘).
Beware bestie: the division operator / acts as a unary operator (inversion) when it has no left operand, or has a space on the left, but not on the right. So like, /3 is equivalent to 1.0/3. That tiny space is doing SO much heavy lifting, do not disrespect it. ๐Ÿ˜ญ

Examples, because visuals ate:

{1 2 3 4}*{1 -1}={1 -1 2 -2 3 -3 4 -4}
{2 3 -5}*2={4 6 -10}
  • xey โ€” the operator for exponential notation. Useful mostly in scalar context (e.g. 1.3e-5), but it can be used in general for evaluating exponential notation for all combinations. Multi-tasking icon. โœจ
  • xcy โ€” evaluates the binomial symbol (x over y). It supports floating point values. Ngl that's slay.

Example:

3c{0 1 2 3}={1 3 3 1}

๐Ÿงฎ Polynomial Operators ๐Ÿงฎ

The following set of operators treat arrays as polynomial coefficients. First element corresponds to the zero-order term, and so on, e.g. {1 2 3} <=> 3x^2 + 2x + 1. So yes, the array is the polynomial, she contains multitudes. ๐Ÿ’œ

  • x++y, x--y โ€” polynomial addition and substraction. This is similar to the operators :+ :-, but the length of the output array is equal to the length of the larger array. Size queen behaviour, honestly. ๐Ÿ‘‘
  • x**y โ€” computes the product of two polynomials. In terms of arrays, this evaluates to the convolution of x and y. Cute and mathematically unhinged, we love her.
  • x//y, x%%y โ€” computes the quotient and remainder in long polynomial division. The returned arrays always contain floating point values, regardless of the input, and leading zeroes get trimmed from the output. Messy queen stays tidy. ๐ŸŽ€
  • px x y โ€” evaluates polynomial x in the points given in array y.
  • pd x โ€” computes the derivative of polynomial x. Equivalent to {x<<-1}:*[1 #x]. Look at her go. โญ
  • pz x โ€” returns all real roots of polynomial x. The resulting array is not guaranteed to be sorted in any way, so like, don't come for her about the order. ๐Ÿ™ˆ

This operator uses Sturm's sequence to isolate the roots, and then proceeds with Newton-Raphson iteration. It works quite well for well-behaved polynomials. Accuracy is questionable if there are roots with multiplicity 3 or higher โ€” so yeah, sketchy territory, be warned. ๐Ÿ’€

The algorithm outputs warning messages if the accuracy is questionable, or if the iteration fails to converge to a result. She tells you when she's not sure, that's healthy communication.

  • zp x โ€” is the inverse of the pz operator. It takes the set of roots and returns the minimal polynomial with the given roots, with the leading coefficient normalized to 1.

pzzp should return the same array as on the input, up to a reordering of elements (excepting the numerical errors in root finding, especially if there are multiple roots). Conversely, zppz does not necessarily return the initial array, because it ignores the normalization factor and irreducible factors that don't have any real roots. It's giving selective memory, and honestly? Valid. ๐Ÿ˜Œ

  • F x โ€” returns the prime factorization of x. If x has many components, the factors get concatenated in a way that makes the product of the output array equal to the product of the input array. That makes a negative integer produce an additional -1 factor, while floating point input numbers stay intact. No cap, the math checks out. ๐Ÿ”ฅ

๐Ÿฆ‹ Vector Operators ๐Ÿฆ‹

  • x@:y โ€” returns the dot product of vectors x and y. In case of different array lengths, the overhead is discarded. She's not gonna fight about the leftovers. ๐Ÿ’…
  • x@^y โ€” returns the cross product of vectors x and y, if the vectors are three-dimensional. In the general case, it returns components z_i=x_{i+1}*y_{i+2}-x_{i+2}*y_{i+1}.

This generalization is useful for polygon geometry โ€” for a polygon with coordinates {x_i,y_i}, the area of the polygon is 0.5*@+{x@^y}. Similar formulas exist for polygon center and other expressions. Geometry girlies stay winning. ๐ŸŒธ

  • @!x โ€” normalizes vector x. Glow-up operator, literally.
  • @=x โ€” returns the length of vector x. Shorter notation of the general norm: {@=x}={nrm2x}. Same vibes, less typing. ๐Ÿซถ

๐ŸŒˆ Set Operators ๐ŸŒˆ

  • x&y โ€” returns the elements that are in both x and y. Intersection besties.
  • x|y โ€” concatenates arrays x and y. Produces the same result as {x y}.
[deprecated] This operator is an unnecessary waste of notation. It should have had the interleaving effect, now represented by Y. So yeah, she's on the way out, don't get attached. ๐Ÿ’€
  • x\y โ€” returns the elements of x that are not present in y. Subtraction but make it set theory.
  • x|&y โ€” is the xor operation on arrays. Returns elements present in only one of the arrays. Pick a side, babe.
  • xYy โ€” interleaves the arrays x and y. (This is the one that stole the | job, iykyk.)
  • ~x โ€” reverses the order of array x. Backwards but make it fashion. ๐Ÿ’…
  • Sx โ€” sorts the array in ascending order.
  • #x โ€” returns the number of elements in array x.
  • #_xy โ€” counts occurences of elements of x in y. This is the selective variant of the # operator.

Example:

#_{0 1 4}{1 2 3 4 4 1}={0 2 2}
  • #__xy โ€” distributes elements of y into a histogram where elements of x divide the real numbers into bins. The size of the output is one element more than the size of x. The first bin extends from negative infinity to the first element of x and the last extends to the positive infinity. x is expected to be in ascending order โ€” so sort her first, bestie, or it's chaos. ๐Ÿ˜ญ
  • ?x โ€” returns the indices of nonzero elements of x. Only integer zero counts as zero. Yes, very particular. ๐Ÿ™ˆ

This operator is intended for use with the index operator (_), to select elements that satisfy some logical test. For example, x_?{x<1000} returns only elements smaller than 1000.

To skip an entire array if it doesn't satisfy a condition, use the ? operator in combination with +. For example, x+?{#x==3} prints x only if its length equals 3. This functionality relies on the fact that tensor summation with an empty array returns an empty array. Sneaky, clever, iconic. โญ

  • ?_x y โ€” returns the indices of elements of x in the array y. If the element is found more than once, only the first index is returned. If the element is not present in y, a value -1 is returned. She's not gonna hunt around for the rest, sorry. ๐Ÿ’…
  • S_x โ€” returns the indices that would sort the array x. It's always true that Sx=x_S_x. Always. Fr fr.
  • x=y โ€” returns 1 if the arrays are equal, 0 otherwise.

๐ŸŽ€ Element Selection Operators ๐ŸŽ€

  • x<<y โ€” for positive values of y, returns the first y values of x (like the unix utility head). For negative values, it returns everything except the first y values. If y is an array, it concatenates all the results. y should be an array of integers. Super useful for array cycling:
{1 2 3 4}<<{-2 2}={3 4 1 2}
  • x>>y โ€” same as above, except it works from the back of the array. Backwards queen. ๐Ÿ‘‘
  • x_y โ€” returns the elements of x at indices y. It interpolates for noninteger indices and wraps around for indices out of range. She's flexible like that. ๐Ÿฆ‹
  • U P N O E I D X โ€” the conditional selectors. They return elements that satisfy a certain condition.
    • U โ€” unique, deletes duplicate elements
    • P โ€” positive
    • N โ€” negative
    • O โ€” odd
    • E โ€” even
    • I โ€” integers
    • D โ€” floating point values
    • X โ€” prime numbers
  • min max โ€” return the smallest and the largest component of the array respectively. The duality of man, etc.
  • Zx โ€” zilch, returns an empty array. This operator is useful for suppressing output from functions with side-effects, such as the @ operator. She's the "no thoughts head empty" operator and we stan. ๐ŸŒธ

โญ Constants โญ

  • pi โ€” returns 3.14159265358979323846264
  • deg โ€” returns the value of the angular degree in radians, 0.017453292519943295769
  • emc โ€” returns the Euler-Mascheroni constant, 0.57721566490153286
  • pm mp โ€” plus/minus and minus/plus constants. They output the arrays {1,-1} and {-1,1} respectively. They can be used to compute results of multivalued formulas simultaneously, for example a quadratic equation. Two answers, one line, efficiency icon. ๐Ÿ’œ

๐Ÿงš Memory Operators ๐Ÿงš

Memory slots are enumerated by integers. For floating point values, the integer part is used. This may change in future versions โ€” so like, don't build your whole personality on it. ๐Ÿ™ˆ

Named variables can be used instead of integer enumeration with the use of backticks.

  • @xy โ€” puts array y into the memory slots enumerated by elements of x. x should be integers. Floating point numbers are cast to integers and a warning is issued.
  • $x โ€” concatenates arrays found at the memory slots enumerated by x. For negative values, it returns the array from history instead of memory, $-1 being the most recent entry. x should be integers.
  • @`<name>`y โ€” puts array y into the memory slot represented by the given <name>.
  • $`<name>` โ€” retrieves the variable named by the given <name>.

ised manages memory as a hashed map, so a memory position can be every positive integer. Saving an array to slot $100 doesn't allocate any more memory than saving to slot $1 โ€” she's not dramatic about it. ๐Ÿ’…

Results are added to history for input lines from files (--f option) or interactive mode, unless the line terminates with a semicolon. Negative slots are reserved for internal use by the named variable system and are not accessible by direct dereference. Instead, history is accessed by the negative arguments of the $ operator. So like, don't try to dereference them directly, that's not the vibe. ๐Ÿ˜ญ

๐Ÿ”ฅ Comparison and Equality operators ๐Ÿ”ฅ

For logical evaluation, ised provides comparison operators. The result of a comparison is 1 for true and 0 for false. Equality and inequality operators also check if the types of both values are equal โ€” she's checking your vibe and your ID. ๐Ÿซถ

For boolean analysis of resulting arrays, use multiplication for the and operator and summation for the or operator. Incorporating additional operators for this functionality would be redundant, as the result is equivalent. But beware: multiplication and summation have higher precedence than the comparison operators, so use the grouping operator {} to achieve the desirable effect. Don't get caught out bestie, the grouping braces are your besties. ๐Ÿ’€

  • x:<y x:>y x:<=y x:>=y x:==y x:<>y โ€” comparison and equality, evaluated component-wise. The result is an array with the size of the shorter of the input arrays. Short queen rights. ๐ŸŒธ
  • x<y x>y x<=y x>=y x==y x<>y โ€” same as above, but evaluated on every possible pair of values. The size of the output array is the product of the input sizes (see Tensor operators for details and example). She's thorough, okay? ๐ŸŒˆ

๐Ÿ‘‘ Function definitions ๐Ÿ‘‘

ised implements a rudimentary mechanism for function definitions. It enables storing an expression and evaluating it later upon command. The functions are stored in a map structure and are accessed via integer function ids. A function id is returned when the function is declared. No particular order of the function ids should be assumed โ€” they're not ranked, they're not in a queue, it's giving feral. ๐Ÿ’…

The zero (0) function id is reserved for an identity function (no-op). She does nothing and she does it perfectly. โœจ

okay so real talk: these functions can do memory manipulation too, which is exactly what makes them as versatile as functions in any programming language. bestie, you can design them as procedures that straight-up ignore input and output and just operate on memory, or as plain-old-functions that take an argument and return a result, or literally any combination of both. it's giving โœจrangeโœจ ๐Ÿฆ‹

  • {:expression:} โ€” function declaration, babes. The expression gets parsed, stored into the function memory, and its unique id comes right back at you. That id is guaranteed to be nonzero, no cap ๐ŸŽ€. You can stash the returned id in memory and use it later. Inside the function, operator x is what refers to the function's argument. And the function is not evaluated at this point โ€” it's just being declared, it's just sitting there being iconic.
  • f::x โ€” function evaluation. Here f is an array of function ids, and they get applied sequentially to the array x, left-to-right. Read it as composition of function: the result from the previous function gets handed to the next one as its argument. ๐Ÿฆ‹
  • f:::x โ€” function iteration. The array of function ids f gets evaluated over and over on the argument x. The iteration stops when the argument no longer changes, or when the maximum number of iterations is reached. That max is 65536 by default, but you can query and change it using system call Q{105 ...} (go peep the section on system calls). You could emulate this operator with ordinary function evaluation plus the system call for setting the instruction pointer, Q{103 ...}, but ngl that implementation is quite complex. Since functional iteration until convergence is super common in math, this operator is a valuable shortcut. ๐Ÿ’…
  • f@::x โ€” function map. The array of function ids f gets evaluated on each element of the array x. This is meant to allow creation of user functions that don't have to handle the array nature of the argument themselves. ๐Ÿซถ
  • x โ€” this bad boy evaluates to the argument supplied to the function. In case of nested functions, it refers to the innermost function's argument. Outside a function, it has the value of the current line (when used with --l or --x), or it's invalid otherwise. ๐Ÿ™ˆ

The function evaluation operator (::) is enough to implement all basic control structures. ised is therefore a Turing complete language. ๐Ÿ‘‘ likeโ€ฆ okay, main character energy.

function call:

{fun}::{arg}

conditional execution (if-statement):

{{false-fun true-fun}_{condition}}::{arg}

switch statement:

{{fun1 fun2 fun3 fun4 ...}_switch}::{arg}

static repetition (for-statement):

(fun n)::{arg}

recursion:

{@mem {:do-something-with $mem::x :}}::{arg}
The implementation of the function must be carefully devised, otherwise the execution might get stuck in an infinite recursion. ๐Ÿ˜ญ you have been warned, bestie โ€” this one does not play.

general loop (while-statement):

{ body-fun jump-test }::{arg}

Such a simple implementation has the loop contents in body-fun and implements jump-fun such that its argument stays unchanged, but sets the program counter to zero if a condition is met. The program counter is set via system call operator Q{103 n}, where n is simply which function in the left-hand side of the operator :: is evaluated next. For example, { {:x+1:} {:x Q{103 -{x>10}}:} }::{arg} increments the argument by one until it becomes greater than 10. In that case, the system call sets the program counter to -1, which is out of range, and the evaluation stops. ๐ŸŽฌ

More complex flow control is possible, because the operator Q{103 n} can be used exactly like a goto statement. Q{102} can be used to find the current program counter and calculate relative jumps. iykyk ๐Ÿ”ฅ


๐Ÿ”ฎ System calls ๐Ÿ”ฎ

The internal state of ised can be accessed and modified using the system call operator Qx. The argument x is an array, where the first component is the system call id number and the rest are optional arguments to the system call. The list of system calls will be expanded in future versions of ised, so likeโ€ฆ stay tuned, bestie. ๐Ÿ’–

Example: use ised --l load_file '$1 Q{$1>3}' to output the specified file, but terminate as soon as it encounters a number greater than 3. clean, simple, slays.

The system call ids are available as named variables, specified between the backticks as `<name>`. For instance, a call Q{`EXIT` 42} terminates the program with a return value of 42. ๐ŸŽ€

The list of system call numbers and names:

  • 0 [NOP] โ€” no-op. literally nothing. that's the whole vibe. ๐Ÿ’€
  • 1 [EXIT] โ€” exit. Exits with return value 0, or the value specified as an optional argument. say bye bestie ๐Ÿ‘‹
  • 100 [BREAK] โ€” break. Interrupts the loading of files by commands --f, --l, --a or --x, and aborts evaluation of the current line.
  • 101 [CONT] โ€” continue. Aborts evaluation of the current line and proceeds to the next line in the file. moving on ๐Ÿ’…
  • 102 [PC] โ€” get program counter. Returns the index of the currently evaluated function in the innermost evaluation operator ::.
  • 103 [PCSET] โ€” set program counter. Sets the index of the next evaluated function in the innermost operator ::. If the argument is out of bounds, it terminates the evaluation. If it's called without arguments, it does nothing. ๐Ÿซ 
  • 104 [STACKDEPTH] โ€” get stack depth. Returns the number of nested functions around the call. If you're not in a function, it returns 0.
  • 105 [MAXITER] โ€” get/set iteration limit. Without an argument, the iteration limit for operator ::: is returned. With an argument, it's changed to the given (nonnegative) value. ๐ŸŽš๏ธ
  • 1000 [HISTORY_COUNT] โ€” get history count. Returns the number of history entries, or -1 if history is disabled.
  • 1001 [HISTORY_ENABLE] โ€” disable history. Disables remembering previous results โ€” or enables it, if called with a nonzero argument. yes the name says disable and it also enables, we contain multitudes. ๐Ÿ™ˆ
  • 1002 [HISTORY_CLEAR] โ€” clear history. Clears the history. fresh start era โœจ
  • 2000 [MEM_INDEX] โ€” get/set indexing memory slot. Without arguments, it sets the memory slot where the current line number is stored (default is 0). With an argument, it sets it.
  • 2001 [MEM_INPUT] โ€” get/set input memory slot. Same as 2000, but for the memory slot where the current input line is stored (default is 1).
  • 2002 [MEM_OFFSET] โ€” get/set file loading offset. Same as 2000, but for the memory slot where --a continues loading lines to. At startup, this is 0, so the first memory slot filled is $1, and it's advanced with each loaded line. ๐Ÿ“ฅ
  • 2003 [MEM_CLEAR] โ€” delete from memory. Clears the entire contents of memory if called without arguments. The optional argument is a list of memory slots to delete. ๐Ÿงน
  • 2004 [MEM_LIST] โ€” get memory list. Lists the occupied memory slots.
  • 2050 [FUN_CLEAR] โ€” delete function. Clears all the functions if called without arguments. The optional argument is a list of function ids to delete.
  • 2051 [FUN_LIST] โ€” get function list. Lists the occupied function ids.
  • 3000 [VERSION] โ€” ised version. Returns the array containing the version number {major,minor,revision}. ๐Ÿท๏ธ
  • 3001 [SIZEOF_INT] โ€” int size. Returns the size of the integer type in bytes.
  • 3002 [SIZEOF_FLOAT] โ€” float size. Returns the size of the float type in bytes.
  • 3003 [DEBUG] โ€” debug level. Returns the debugging level, set at compile-time.
  • 3004 [READLINE_STATUS] โ€” readline status. Returns the array indicating if various libreadline functionalities are enabled (use --v for details).
  • 3005 [OVERFLOW_STATUS] โ€” overflow enabled. Returns 1 if overflow handling was enabled at compile-time, and 0 otherwise.
  • 5000 [TIME] โ€” system time. Returns unix time in seconds if called without arguments. The arguments can be a list of values, which specify the time fields to output:
    • 0 [TIME.EPOCH] = epoch
    • 1 [TIME.SEC] = sec
    • 2 [TIME.MIN] = min
    • 3 [TIME.HOUR] = hour
    • 4 [TIME.MONTHDAY] = month-day
    • 5 [TIME.MONTH] = month
    • 6 [TIME.YEAR] = year
    • 7 [TIME.WEEKDAY] = week-day
    • 8 [TIME.YEARDAY] = year-day
  • 5001 [PROCESS_TIME] โ€” process time. Returns an array containing real time, user time and system time, in seconds. โฑ๏ธ
  • 5002 [SLEEP] โ€” sleep. Sleeps for the amount of seconds specified in the argument. self care honestly ๐Ÿ˜ด
  • 5050 [PID] โ€” pid. Returns the PID of this process. ๐Ÿชช

For instance, a call Q{`TIME` `TIME.YEAR` `TIME.MONTH` `TIME.DAY`} may return the array {2013 10 31}. ๐ŸŽƒ


๐ŸŒˆ Unicode operators ๐ŸŒˆ

Since version 2.6.0, ised can be compiled to support some additional operators that include utf-8 encoded unicode characters. Mostly, these are just aliases to the existing operators. ๐Ÿ’ซ

Warning: the following table requires utf-8 support by the terminal displaying this man page. ๐Ÿ‘€ likeโ€ฆ make sure your terminal is actually invited to the party, bestie.

the table itself is coming up next, and it's gonna be a whole moment โ€” stay with me ๐ŸŽ€๐Ÿฆ‹๐Ÿ’…

Like, here's the full alias chart bestie โ€” every ASCII spelling on the left, its UTF-8 glow-up on the right. Copy these exactly, they're load-bearing ๐Ÿ’…

                               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                               โ”‚ The list of aliases โ”‚
                               โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
                               โ”‚  ASCII  โ”‚   UTF-8   โ”‚
                               โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
                               โ”‚   ::    โ”‚  โˆ˜        โ”‚
                               โ”‚   :::   โ”‚  โˆ™        โ”‚
                               โ”‚   @::   โ”‚  โˆท        โ”‚
                               โ”‚   @+    โ”‚  ฮฃ        โ”‚
                               โ”‚   @*    โ”‚  ฮ         โ”‚
                               โ”‚  sqrt   โ”‚  โˆš        โ”‚
                               โ”‚  cbrt   โ”‚  โˆ›        โ”‚
                               โ”‚    &    โ”‚  โˆฉ        โ”‚
                               โ”‚    \    โ”‚  โˆ–        โ”‚
                               โ”‚    |    โ”‚  โˆช        โ”‚
                               โ”‚   ?_    โ”‚  โˆˆ     *  โ”‚
                               โ”‚    Z    โ”‚  โˆ…        โ”‚
                               โ”‚    I    โ”‚  โ„ค        โ”‚
                               โ”‚    D    โ”‚  โ„        โ”‚
                               โ”‚    X    โ”‚  โ„™        โ”‚
                               โ”‚   <<    โ”‚  โ‰ซ        โ”‚
                               โ”‚   >>    โ”‚  โ‰ช        โ”‚
                               โ”‚   :<=   โ”‚ :โ‰ค        โ”‚
                               โ”‚   :>=   โ”‚ :โ‰ฅ        โ”‚
                               โ”‚   :==   โ”‚ :โ‰ก        โ”‚
                               โ”‚   :<>   โ”‚ :โ‰         โ”‚
                               โ”‚   <=    โ”‚  โ‰ค        โ”‚
                               โ”‚   >=    โ”‚  โ‰ฅ        โ”‚
                               โ”‚   ==    โ”‚  โ‰ก        โ”‚
                               โ”‚   <>    โ”‚  โ‰         โ”‚
                               โ”‚   pi    โ”‚  ฯ€        โ”‚
                               โ”‚   aa    โ”‚  ฮฑ        โ”‚
                               โ”‚   deg   โ”‚  ยฐ     *  โ”‚
                               โ”‚   emc   โ”‚  ฮณ        โ”‚
                               โ”‚   pm    โ”‚  ยฑ     *  โ”‚
                               โ”‚   mp    โ”‚  โˆ“     *  โ”‚
                               โ”‚   @:    โ”‚  ยท        โ”‚
                               โ”‚   @^    โ”‚  ร—        โ”‚
                               โ”‚   phi   โ”‚  ฯ†        โ”‚
                               โ”‚  {::}   โ”‚  ฮป     *  โ”‚
                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

So the operators with the lil asterisk up there? They do not behave exactly like their ASCII twins โ€” they're the โœจ spicy โœจ ones. Like, โˆˆ is infix, whereas ?_ needs both of its operands to its right. Different vibes, same idea, don't mix them up ๐Ÿซถ


the ยฐ operator, she's got range

The ยฐ operator multiplies the preceding number by the degree value, and it does it with high precedence โ€” but only if there's no space between them. An isolated ยฐ operator just behaves like a regular numerical constant, equal to deg. This is what lets sin60ยฐ replace sin{60*deg} ๐ŸŽ€ and like, note that the braces are not needed with the ยฐ operator. slay.

ยฑ and โˆ“ are built different

Same logic applies to ยฑ and โˆ“, and this is the part where people get it twisted so listen up: they are not precomputed constant arrays {1,-1} and {-1,1}. Nope. They behave more like the operators + and -. If you use them in the infix sense, they do addition and subtraction on each pair of the left and right argument, like:

{1 2 3}ยฑ{4 5}={5 -3 6 -4 6 -2 7 -3 7 -1 8 -2}

If you use them in the prefix sense, they convert each element of the following array into its positive and negative version:

ยฑ{4 5}={4 -4 5 -5}

The plus and minus here operate on the innermost level โ€” as opposed to the expression pm*{4 5}={4 5 -4 -5}. This alternative lets you pick whichever variant is better suited for the evaluation you actually have going on ๐Ÿ‘‘

ฮป said "I'll handle the function spec"

The lambda operator ฮป offers an alternative to function specification. It's a prefix operator with a very low precedence (equal to the union operator |), so the braces aren't always necessary. For instance:

(ฮปx^2 3)::[10]

that performs the squaring operation three times in succession ๐Ÿ”ฅ The space after x^2 is enough to terminate the function specification. But in a different scenario, regular braces are needed:

{ฮปx^2}::[10]

Because without the braces, the expression would be equivalent to ฮป{x^2::[10]}, which is probably not the expression you wanted, bestie ๐Ÿ˜ญ


โœจ EXAMPLES โœจ

ised '@0[2 100];$0\{$0*$0}'

returns all prime numbers up to 100. It utilises memory to prevent code repetition ๐Ÿ’–

ised '(0 (1 2 10) 10)'

generates squares of numbers up to 10, by using nested constructors. Inner constructor generates increments for outer constructor ๐Ÿงš

ised --l file '$0 ~$1'

reverses lines of file and prepends line numbers.

ised '@0 {0.5*{1+sqt5}};r{{$0^[1 20]:-(-$0)^-[1 20]}/sqt5}'

generates Fibonacci sequence using direct exponential formula โญ

ised --d '\n' '[0 1/d5 10]'

generates evenly spaced values between 0 and 10, separated by a newline. Same functionality as

seq 0 0.2 10
ised --d '\n' '[0 pi/100 pi]' | ised --F '%+12.6f' --l - 'd{$1 sin$1
cos$1 tan$1 exp$1 $1^2}'

generates nicely formatted table of several functions in range between 0 and pi. Note the use of placeholder - for standard input ๐ŸŽ€

ised --o tmp_file --t '[0 pi/100 pi]' --o - --F '%+12.6f' --l tmp_file
'd{$1 sin$1 cos$1 tan$1 exp$1 $1^2}'

previous example, achieved in one pass using a temporary intermediate file. Note the use of placeholder - for standard output ๐Ÿฆ‹

ised '{1.4^[11]}@:{1./[11]!} exp1.4'

calculation of exp(1.4) by summation of series, compared to exact value.

ised '@1 60;@2 72;@3[1 $1];{$1%$3==0}:*{$2%$3==0}:*$3\0'

returns list of common divisors of 60 and 72. Numbers 60 and 72 are first stored in memory, together with list of possible divisors, for easier readability. Note the use of multiplication for boolean and evaluation. The same can be achieved more elegantly with operator ?:

ised '@1 60;@2 72;@3[1 $1];$3_?{{$1%$3==0}:*{$2%$3==0}}'

ised '@1 60;@2 72;{$1*[1 $2]&$2*[1 $1]}_0'

returns least common multiple of 60 and 72.

ised --d '+' '2^[10]' | ised

illustration how changing output format can produce useful input for other programs, in this case, ised itself. This is useful for easier input of operator repetition, for example the power tower:

ised --d '^' '(1/sqt2 10)' | ised --l - '-$1'

this outputs solution of equation 2^x=x^2.

ised '@1{2}@2{3}@3{-5};{-$2+pm*sqt{$2^2-4*$1*$3}}/{2*$1}'

solves quadratic equation 2x^2+3x-5. Capability of handling arrays is exploited to give both solutions at once. pm operator is shorthand for array {1,-1}. In the utf-8 notation, the expression reads

ised '@1{2}@2{3}@3{-5};{-$2ยฑโˆš{$2^2-4*$1*$3}}/{2*$1}'

The same can be achieved with built-in polynomial solver:

ised '@1{2}@2{3}@3{-5};pz{$3 $2 $1}'

Note that the intermediate variables $1,$2,$3 were only used to make the expression more readable ๐Ÿ’…

yes 0 | ised '@2{145}' --l - '@2{{$2/2 3*$2+1}_{$2%2}} Q{100 $2==1}'

outputs the Hailstone sequence for the number 145. It uses GNU core utility yes to produce an infinite loop and terminates using a conditional system call 100 (break) ๐Ÿ’€

ised --D '%02d' --d ':' 'Q{5002 60-Q{5000 1}};Q{5000 3 2 1}'

Waits for the minute to change and then displays the current time, so that the seconds will be zero. It uses the time-related system call utilities 5000 (system time) and 5002 (sleep) โญ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Simon Copar

๐ŸŒธ SEE ALSO ๐ŸŒธ

seq(1)


okay that's the whole page bestie, you're officially an ised girlie now ๐Ÿซถ this iconicness is from ised(1), dated May 1, 2014 โ€” go forth and compute, periodt ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from