Amend: Difference between revisions

From The K Language Wiki
Content added Content deleted
No edit summary
("Add category")
Line 26: Line 26:
== ngn/k ==
== ngn/k ==
ngn/k's amend has <code>z</code> as the optional argument, instead of having <code>f</code> as an optional argument.
ngn/k's amend has <code>z</code> as the optional argument, instead of having <code>f</code> as an optional argument.

[[Category:Special forms]]

Revision as of 02:41, 9 July 2022

Amend
@[x;y[;f];z]
@[x;y;f[;z]]

Amend is a special form of the @ verb which takes multiple arguments.

Amend takes 3 or 4 arguments, where:

  • x is an array to amend
  • y is the index(or indices) to amend
  • f(optional), is the function to apply to those indices
  • z is the second argument to z

3 argument amend always acts as an element replacement function, since z is : if it is omitted.

x can be a value or a symbol. If given a symbol, amend will modify the variable that is indicated by the symbol.

 v:1 2 3
 v
1 2 3
 @[v;1;3]
1 3 3
 v
1 2 3
 @[`v;1;3];
 v
1 3 3

ngn/k

ngn/k's amend has z as the optional argument, instead of having f as an optional argument.