键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

KSL Wiki

Welcome to the official documentation for the KSL programming language. This site provides a comprehensive reference, including:

  • The Language Specification: Detailed information on KSL’s syntax and core concepts.
  • Built-in Function Reference: A complete guide to the standard library and its functions.
  • Examples and Tutorials: Practical examples to help you get started with KSL.

Ninety-Nine Lisp Problems

This section presents KSL solutions to the classic Ninety-Nine Lisp Problems. These problems serve as an excellent exercise for learning functional programming concepts within the KSL language.

The original problem set can be found at L-99_Ninety-Nine_Lisp_Problems.

Creating Standalone Executables

KSL provides a utility script, bundle.sh, for packaging a KSL script and the interpreter into a single, standalone executable file.

Prerequisites

Before running the script, ensure the following three files are located in the same directory:

  1. The bundle.sh script itself.
  2. The ksl interpreter executable.
  3. The KSL script file you wish to bundle.

Usage

The script is invoked with the following syntax:

./bundle.sh <ksl_script_file> <output_executable_name>

Example

Consider the following script, fib10.ksl, which calculates the 10th Fibonacci number:

Let[a, 0];
Let[b, 1];
Let[m, 0];
While[Less[m, 10], {
  Let[{a, b}, {b, Add[a, b]}],
  Let[m, Add[m, 1]]
}];
Print[a];

To package this script into an executable file named fib10, run the following command:

./bundle.sh fib10.ksl fib10

This will generate a new executable file named fib10. Both the original script and the bundled executable produce the same output:

> ./ksl fib10.ksl
55

> ./fib10
55