rust-playground icon indicating copy to clipboard operation
rust-playground copied to clipboard

Request: Support for table of content and next exercise button

Open mofosyne opened this issue 2 years ago • 2 comments

Currently going though https://github.com/rust-lang/rustlings/tree/rustlings-1 and i found that it links to play.rust-lang.org via links like below:

https://play.rust-lang.org/?code=%2F%2F+variables1.rs%0A%2F%2F+Make+me+compile%21+Scroll+down+for+hints+%3A%29%0A%0Afn+main%28%29+%7B%0A++++x+%3D+5%3B%0A++++println%21%28%22x+has+the+value+%7B%7D%22%2C+x%29%3B%0A%7D%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F+Hint%3A+The+declaration+on+line+5+is+missing+a+keyword+that+is+needed+in+Rust%0A%2F%2F+to+create+a+new+variable+binding.%0A

Where you allow for embedding code via code=.

Would it make sense to support an extra field like toc= and toc-curr-id= which may link to a json file that contains a list of each exercise and what part of the exercise we are currently at.

{
    "Title" : "Variable bindings",
    "Lesson Url":"https://github.com/rust-lang/rustlings/tree/rustlings-1#variable-bindings"
    "code":"https://play.rust-lang.org/?code=%2F%2F+variables1.rs%0A%2F%2F+Make+me+compile%21+Scroll+down+for+hints+%3A%29%0A%0Afn+main%28%29+%7B%0A++++x+%3D+5%3B%0A++++println%21%28%22x+has+the+value+%7B%7D%22%2C+x%29%3B%0A%7D%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F+Hint%3A+The+declaration+on+line+5+is+missing+a+keyword+that+is+needed+in+Rust%0A%2F%2F+to+create+a+new+variable+binding.%0A"
    "expected-output":"...expected code output..."
}

By knowing the exercise structure above, you also know whats the next exercise as well so could autogenerate a "next exercise" button as well.

It does get me thinking of there is already a standard for this, since this would be a pretty common use case for teaching multiple programming languages.

mofosyne avatar Apr 10 '23 06:04 mofosyne

Okay asked ChatGPT if there is any other metadata standards to rely on... doesn't appear to exist... but I did ask if it could provide a potential structure.

{
  "title": "Introduction to Python",
  "description": "In this tutorial, you will learn the basics of Python programming.",
  "lessons": [
    {
      "title": "Variables and Data Types",
      "description": "In this lesson, you will learn how to define variables and work with different data types in Python.",
      "exercises": [
        {
          "title": "Defining Variables",
          "description": "Define variables to store your personal information.",
          "instructions": "Define variables for your name, age, and favorite color.",
          "tests": [
            {
              "input": "name = 'Alice'\nage = 25\nfavorite_color = 'blue'",
              "expected_output": "Name: Alice\nAge: 25\nFavorite color: blue\n",
              "hint": ""
            },
            {
              "input": "name = 'Bob'\nage = 'thirty'\nfavorite_color = 'green'",
              "expected_output": "",
              "hint": "It looks like you didn't define the variables correctly. Make sure to use the correct data types for each variable."
            }
          ]
        },
        {
          "title": "Working with Strings",
          "description": "In this exercise, you will learn how to work with strings in Python.",
          "instructions": "Write a program that prints the length of a given string.",
          "tests": [
            {
              "input": "text = 'hello'",
              "expected_output": "5\n",
              "hint": ""
            },
            {
              "input": "text = [1, 2, 3]\nprint(len(text))",
              "expected_output": "TypeError: object of type 'list' has no len()\n",
              "hint": "It looks like you are trying to use the `len()` function on a list. The `len()` function works only on strings, lists, tuples, and dictionaries."
            }
          ]
        }
      ]
    }
  ]
}

So that's pretty interesting. If it doesn't exist, then I'll may see if I could create a standard using above template. But I'm pretty sure I came across something like this before... somewhere in the internet.

mofosyne avatar Apr 10 '23 12:04 mofosyne

My understanding is that the web-based version of Rustlings is effectively unmaintained, so even if someone were to add such a feature to the playground, Rustlings wouldn't be updated to use it.

I also don't really think that what you describe is the appropriate domain for the playground. We aren't a service for teaching people Rust, so concepts like "exercises" or "contents" aren't relevant. Could a service teaching Rust use something like the playground? Certainly! However, the better direction would be to better support embedding the playground into another service, not transforming the playground into that other service.

shepmaster avatar Apr 11 '23 00:04 shepmaster