键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

Filter

The Filter function filters a list to include only the elements that satisfy a specific condition.

Parameters

The Filter function accepts two parameters:

  • The first parameter is the list to be filtered.
  • The second parameter is a function that defines the filtering condition.

Return Value

The Filter function returns a new list containing all the elements from the original list that satisfy the filtering condition.

Examples

Filter[Range[1, 1, 10], Fun[{x}, Greater[x, 5]]]; (* => {6, 7, 8, 9, 10} *)
Filter[{1, 2, 3, 4, 5}, Fun[{x}, Eq[Mod[x, 2], 0]]]; (* => {2, 4} *)
Filter[{#a, #b, #a, #c, #a, #d}, Fun[{x}, Not[Eq[x, #a]]]]; (* => {#b, #c, #d} *)

Find

The Find function is used to locate the index of a specified object within a list.

Parameters

The Find function accepts two parameters: the first parameter is a list, and the second parameter is the object to be searched for within the list.

Return Value

If the object is found in the list, the Find function returns its 1-based index within the list. If the object is not found, it returns 0.

Examples

Find[{1, 2, 3, 4, 5}, 3]; (* => 3 *)
Find[{"apple", "banana", "cherry"}, "banana"]; (* => 2 *)
Find[{#a, #b, #c}, #a]; (* => 1 *)
Find[{10, 20, 30}, 40]; (* => 0 *)
Find[{}, 5]; (* => 0 *)
Find[{1, 2, 3, 2, 1}, 2]; (* => 2 *)

Floor

The Floor function calculates the floor of a number, which is the largest integer that is less than or equal to the input number.

Parameters

The Floor function accepts only one numeric parameter.

Return Value

The Floor function returns the floor value of the input number.

Examples

Floor[3.7]; (* => 3 *)
Floor[-3.7]; (* => -4 *)
Floor[-5]; (* => -5 *)
Floor[0.9]; (* => 0 *)

Fun

The Fun function is used to construct anonymous functions, also known as Lambdas.

In KSL, all functions, except for built-in functions and plugin functions, are Lambdas.

Parameters

The Fun function takes two parameters: the first parameter is a list of symbols, which can be empty, indicating that the function takes no arguments; the second parameter is the function body, which is the code that the function will execute.

Return Value

The Fun function returns a Lambda function that executes the function body.

Examples

Let[f, Fun[{x}, Sin[Mul[2, x]]]]; (* sin(2 x) *)
Print[f[3]]; (* => -0.27941549819892586 *)