ASPL لباتASPL 0.7.0

Search documentation

Search starts with current English documentation · ASPL 0.7.0

Enter a complete name such as read_line, or words about a topic.

    العربية
    Source files

    Open one UTF-8 .aspl or .لبات file, up to 1 MiB, in a new draft. It stays in this browser and does not run automatically.

    Strings

    ASPL 0.7.0 · Current release

    Join a name and a formatted number, then predict Arabic scalar length and slices.

    On this page

    What you will learn

    Join a greeting and a submitted name, include an explicitly formatted integer, and predict the length and a slice of a short Arabic string using Unicode scalar positions.

    Before you begin

    Read text input for unchanged replies and bindings for integer arithmetic and formatting. This independent program supplies its own entry. Open it as a new Home draft, then choose Run explicitly. Earlier drafts remain available. Lists have their own later lesson.

    Join text and format a number

    string / نص is immutable text stored as UTF-8. let / دع binds the submitted name, the integer next, and the string greeting. print / اطبع writes Name: before read_line / اقرأ_سطر reads the reply without its line terminator. The string operator + concatenates text in the order written; it preserves spaces and does not translate or normalize the contents.

    Browser and native · ASPL 0.7.0 · English source

    Execution: Browser and native · ASPL 0.7.0

    Prerequisites:
    • Read the example explanation in its lesson before running.

    Input lines: ["سلمى"]

    fn start_main() -> i64 {
        print("Name: ");
        let name: string = read_line();
        let next: i64 = 41 + 1;
        let greeting: string = "Hello, " + name + "! Next: " + format_i64(next);
        print(greeting + "\n");
        let text: string = "مرحبا";
        print(format_i64(length(text)) + "\n");
        print(slice(text, 1, 3) + "\n");
        return 0;
    }
    
    Download lesson-strings.aspl

    Expected outcomes
    {
      "browser": {
        "check": "success",
        "class": "success",
        "output": "Name: Hello, سلمى! Next: 42\n5\nرح\n",
        "processStatus": 0
      },
      "native": {
        "check": 0,
        "status": 0,
        "output": "Name: Hello, سلمى! Next: 42\n5\nرح\n"
      }
    }

    41 + 1 is integer arithmetic, giving next the value 42. format_i64(next) / نسق_ص64(التالي) explicitly converts that integer into the ASCII string "42". The greeting expression joins strings. A string cannot be concatenated directly with an integer; keep the formatting call. Each print needs the explicit \n to end its line.

    The last two prints use length / طول and slice / اقتطع. Length returns an i64 scalar count, so it also needs formatting for output. Slice takes the text, an included start position and an excluded end position, and returns a string. The reserved start_main() -> i64 / ابدأ_الرئيسية() -> ص64 entry ends with return 0 / أرجع 0, separately from printed data.

    Predict Arabic length and a slice

    Before Run, predict length("مرحبا") and slice("مرحبا", 1, 3). Positions start at zero and count Unicode scalar values, not UTF-8 bytes or screen positions. Read the stored logical order below, even when the source is displayed in another direction.

    Scalar position Stored scalar
    0 م
    1 ر
    2 ح
    3 ب
    4 ا

    The length is 5. The slice includes positions 1 and 2, stopping before 3, so it is "رح". These five Arabic scalars occupy ten UTF-8 bytes, but slice arguments are scalar positions. A combining mark counts separately; a visible character or emoji sequence can contain several scalars. This example has no combining marks.

    Submit سلمى. Exact output is Name: Hello, سلمى! Next: 42\n5\nرح\n, with normal status 0. An empty reply leaves the name empty while the number, length and slice stay the same. Changing documentation language or supplied source vocabulary does not translate "مرحبا", the greeting, runtime input, identifiers, or an existing draft.

    Include one more scalar

    Change only the slice end from 3 to 4. Predict which scalar is added. With the same name, expected output is exactly Name: Hello, سلمى! Next: 42\n5\nرحب\n, with status 0.

    Keep the greeting and length. Change the slice's excluded end to 4 and predict the new last line.

    Hint: Keep the start at 1. The end position is excluded, so an end of 4 includes positions 1, 2 and 3.

    Show worked answer

    The slice now keeps ر, ح and ب at scalar positions 1, 2 and 3. It stops before ا at position 4, giving رحب. The unchanged greeting still formats the integer 42 explicitly, and length still prints 5. Each output line ends with its explicit newline. The entry returns normal status 0.

    Browser and native · ASPL 0.7.0 · English source

    Execution: Browser and native · ASPL 0.7.0

    Prerequisites:
    • Read the example explanation in its lesson before running.

    Input lines: ["سلمى"]

    fn start_main() -> i64 {
        print("Name: ");
        let name: string = read_line();
        let next: i64 = 41 + 1;
        let greeting: string = "Hello, " + name + "! Next: " + format_i64(next);
        print(greeting + "\n");
        let text: string = "مرحبا";
        print(format_i64(length(text)) + "\n");
        print(slice(text, 1, 4) + "\n");
        return 0;
    }
    
    Download lesson-strings-solution.aspl

    Expected outcomes
    {
      "browser": {
        "check": "success",
        "class": "success",
        "output": "Name: Hello, سلمى! Next: 42\n5\nرحب\n",
        "processStatus": 0
      },
      "native": {
        "check": 0,
        "status": 0,
        "output": "Name: Hello, سلمى! Next: 42\n5\nرحب\n"
      }
    }

    Check your understanding

    Explain the difference between integer + and string +, why formatting is explicit, and why the slice end is excluded. Valid slices obey 0 <= start <= end <= length(text). An invalid slice traps with string-slice-out-of-bounds; byte offsets do not replace scalar positions. No grade or progress is stored, and navigation stays open. Return to the Tutorial path or read the strings reference.

    Browse pages