Skip to content

Coincidental correspondence between variable name and string literal is confusing #3803

Closed

Description

@taitung

...if &"hello"[0] were valid code that returned the byte value, it would return 104, not h.

In chapter 8, section 8.2 shows an example of the indexing of a string as follows.

let hello = "Здравствуйте";
let answer = &hello[0];

The original example has no double quotes. However, the double quotes appear in the text like what I copied. is that on purpose for any reason? Or, is that just a typo?

Activity

  1. akauppi commented on Dec 28, 2023

    @akauppi

    It may be misleading that the string within the sentence is ”hello”. I don’t think there’s any connection between this sentence and the code sample above. The point of the sentence is that indices on string slices are not allowed.

    The string could be changed to: ”…if &”abc”[0] were valid code […]”.

  2. changed the title [-]are double quotes added on purpose?[/-] [+]Coincidental correspondence between variable name and string literal is confusing[/+] on Jan 8, 2024
  3. added a commit that references this issue on Nov 27, 2024
    daf8d82
  4. chriskrycho commented on Nov 27, 2024

    @chriskrycho
    Contributor

    This was indeed confusing, so I changed the string example to be &"hi"[0] instead of &"hello"[0], so it should no longer be an issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions