diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 38d7639..ad433c4 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -28,7 +28,7 @@ jobs: - name: Check for changes in docs/ or mkdocs.yml id: check_changes run: | - git diff --name-only > changed_files.txt + git diff --name-only origin/master -- > changed_files.txt if grep -qE '(^docs/|^mkdocs.yml)' changed_files.txt; then echo "changes_detected=true" >> $GITHUB_ENV else diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a12fcbd..6a8deaf 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,6 +1,6 @@ name: tests -on: [push, pull_request] +on: [push] jobs: build_and_test: @@ -25,11 +25,13 @@ jobs: - name: Check for changes in docs/ or mkdocs.yml id: check_changes run: | - git diff --name-only > changed_files.txt - if grep -qE '(^docs/|^mkdocs.yml)' changed_files.txt; then - echo "changes_detected=true" >> $GITHUB_ENV - else + if [ "$(git diff --quiet origin/master -- docs/ mkdocs.yml; echo $?)" -eq 0 ]; + then echo "changes_detected=false" >> $GITHUB_ENV + echo "No changes to docs/ and mkdocs.yml - exiting the build."; + else + echo "changes_detected=true" >> $GITHUB_ENV + echo "Changes detected in docs/ or mkdocs.yml - continuing the build."; fi - name: Set up Node.js @@ -50,9 +52,15 @@ jobs: if: env.changes_detected == 'true' run: mkdocs build - - name: Install Ruby and Bundler + - name: Install Ruby + if: env.changes_detected == 'true' + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.1' + + - name: Install Bundler if: env.changes_detected == 'true' - run: sudo apt-get install -y ruby-full + run: gem install bundler - name: Install HTML Proofer if: env.changes_detected == 'true' diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..f68555c --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,12 @@ +{ + "MD033": { + "allowed_elements": [ + "figure", + "figcaption", + "a", + "strong", + "center" + ] + }, + "MD036": false +} diff --git a/docs/arrays.md b/docs/arrays.md index 36191a1..d512f22 100644 --- a/docs/arrays.md +++ b/docs/arrays.md @@ -6,12 +6,14 @@ - `arr_push(array, item)` - adds an item to the end of the array - `arr_pop(array, index)` - removes an item from the end of the array - `arr_append(array, item)` - adds an item to the end of the array -- `arr_extend(array1, array2)` - adds all the items of an array to the end of the array +- `arr_extend(array1, array2)` - adds all the items of an array to + the end of the array - `arr_find(array, index)` - returns the item at the specified index -- `arr_slice(array, start, end)` - returns the items from the specified start index to the specified end index - +- `arr_slice(array, start, end)` - returns the items from the specified + start index to the specified end index + ```py linenums="1" title="methods.rn" -var arr = [1, 2, 3, 4, 5] +arr = [1, 2, 3, 4, 5] print(arr_len(arr)) # 5 arr_push(arr, 6) @@ -38,8 +40,8 @@ print(arr_slice(arr, 0, 5)) # [1, 2, 3, 4, 5] - `*` (repetition) ```py linenums="1" title="operators.rn" -var arr1 = [1, 2, 3] -var arr2 = [4, 5, 6] +arr1 = [1, 2, 3] +arr2 = [4, 5, 6] print(arr1 + arr2) # [1, 2, 3, 4, 5, 6] print(arr1 * 2) # [1, 2, 3, 1, 2, 3] @@ -47,23 +49,24 @@ print(arr1 * 2) # [1, 2, 3, 1, 2, 3] ## Array standard library -- `map(func)` - returns a new array with the result of calling the specified function on each item of the array +- `map(func)` - returns a new array with the result of calling the specified + function on each item of the array - `append(item)` - adds an item to the end of the array - `pop(index)` - removes an item from the end of the array - `extend(list)` - adds all the items of an array to the end of the array - `find(index)` - returns the item at the specified index -- `slice(start, end)` - returns the items from the specified start index to the specified end index +- `slice(start, end)` - returns the items from the specified start index to + the specified end index - `len()` - returns the length of the array - `is_empty()` - returns `true` if the array is empty, otherwise `false` - `to_string()` - returns the string representation of the array - `is_array()` - returns `true` if the value is an array, otherwise `false` - ```py linenums="1" title="array-standard-library.rn" include Array # Include the Array standard library # Create an array instance using the Array class -var arr = Array([1, 2, 3, 4, 5]) +arr = Array([1, 2, 3, 4, 5]) print(arr.len()) # 5 print(arr.is_empty()) # false diff --git a/docs/blog/hello-world.md b/docs/blog/hello-world.md index f76c6da..b39b2df 100644 --- a/docs/blog/hello-world.md +++ b/docs/blog/hello-world.md @@ -1,16 +1,25 @@ # Hello World -*Date: 12 Sep 2023* - -*Time: 2:39 AM (GMT+6)* - ## Introduction -We are excited to announce the launch **Radon** - a new open source programming language for the modern world. The language is designed to be simple, fast, and safe while incorporating modern language features such as type inference, pattern matching, and more. A key goal of the language is to be easy to learn and use, while still being powerful enough to build complex applications. It is also designed to be easy to embed in other applications, and to be used as a scripting language. The language is currently in the early stages of development, and we are looking for contributors to help us build the language. +We are excited to announce the launch **Radon** - +a new open source programming language for the modern world. +The language is designed to be simple, fast, and safe while incorporating modern +language features such as type inference, pattern matching, and more. +A key goal of the language is to be easy to learn and use, while still being +powerful enough to build complex applications. It is also designed to be easy +to embed in other applications, and to be used as a scripting language. +The language is currently in the early stages of development, and we are +looking for contributors to help us build the language. ## About the author -[**Md. Almas Ali**][almas] is a software engineer and a programming language enthusiast. He is the creator of the Radon programming language. He has a lot of projects in his GitHub profile. Checkout his [GitHub profile][almas_github] for more information. +[**Md. Almas Ali**][almas] is a software engineer and a programming language +enthusiast. He is the creator of the Radon programming language. He has a lot +of projects in his GitHub profile. Checkout his [GitHub profile][almas_github] +for more information. + +Created on: 12 Sep 2023 - 2:39 AM (GMT+6) [almas]: https://almasali.net "Md. Almas Ali - Software Engineer" [almas_github]: https://github.com/Almas-Ali "Md. Almas Ali on GitHub" diff --git a/docs/built-in-functions.md b/docs/built-in-functions.md index 28881f3..6799611 100644 --- a/docs/built-in-functions.md +++ b/docs/built-in-functions.md @@ -2,63 +2,73 @@ ## Types of built-in functions -Built-in functions are the functions that are built into the language. They are used to perform common tasks. In Radon, there are a list of built-in functions that are available to use. They are: +Built-in functions are the functions that are built into the language. +They are used to perform common tasks. In Radon, there are a list of +built-in functions that are available to use. + +They are: ### Utility methods -- `cls()` - clears the screen -- `clear()` - clears the screen -- `exit()` - exits the program +- `cls()` - clears the screen. +- `clear()` - clears the screen. +- `exit()` - exits the program. -### same as include statement +### Same as include statement -- `require()` - same as include statement to include a file or library in the current program +- `require()` - same as include statement to include a file or + library in the current program. ### Command line arguments -- `sys_args()` - returns the command line arguments +- `sys_args()` - returns the command line arguments. ### API methods -- `pyapi(string)` - A high-level Python API for Radon. It is used to call Python functions from Radon. (Development) +- `pyapi(string)` - A high-level Python API for Radon. + It is used to call Python functions from Radon. (Development) ### Typecase methods -- `int()` - converts any value to an integer -- `float()` - converts any value to a float -- `str()` - converts any value to a string -- `bool()` - converts any value to a boolean -- `type()` - returns the type of the value +- `int()` - converts any value to an integer. +- `float()` - converts any value to a float. +- `str()` - converts any value to a string. +- `bool()` - converts any value to a boolean. +- `type()` - returns the type of the value. ### Type checker methods -- `is_num()` - returns `true` if the value is a number, otherwise `false` -- `is_int()` - returns `true` if the value is an integer, otherwise `false` -- `is_float()` - returns `true` if the value is a float, otherwise `false` -- `is_str()` - returns `true` if the value is a string, otherwise `false` -- `is_bool()` - returns `true` if the value is a boolean, otherwise `false` -- `is_array()` - returns `true` if the value is an array, otherwise `false` -- `is_fun()` - returns `true` if the value is a function, otherwise `false` +- `is_num()` - returns `true` if the value is a number, otherwise `false`. +- `is_int()` - returns `true` if the value is an integer, otherwise `false`. +- `is_float()` - returns `true` if the value is a float, otherwise `false`. +- `is_str()` - returns `true` if the value is a string, otherwise `false`. +- `is_bool()` - returns `true` if the value is a boolean, otherwise `false`. +- `is_array()` - returns `true` if the value is an array, otherwise `false`. +- `is_fun()` - returns `true` if the value is a function, otherwise `false`. ### String methods -- `str_len()` - returns the length of the string -- `str_find(string, index)` - returns the character at the specified index -- `str_slice(string, start, end)` - returns the substring from the specified start index to the specified end index +- `str_len()` - returns the length of the string. +- `str_find(string, index)` - returns the character at the specified index. +- `str_slice(string, start, end)` - returns the substring from the specified + start index to the specified end index. ### I/O methods -- `print()` - prints the specified value to the console -- `print_ret()` - prints the specified value to the console and returns the value -- `input()` - reads a line from the console -- `input_int()` - reads an integer from the console +- `print()` - prints the specified value to the console. +- `print_ret()` - prints the specified value to the console + and returns the value. +- `input()` - reads a line from the console. +- `input_int()` - reads an integer from the console. ### Array methods -- `arr_len()` - returns the length of the array -- `arr_push(array, item)` - adds an item to the end of the array -- `arr_pop(array, index)` - removes an item from the end of the array -- `arr_append(array, item)` - adds an item to the end of the array -- `arr_extend(array1, array2)` - adds all the items of an array to the end of the array -- `arr_find(array, index)` - returns the item at the specified index -- `arr_slice(array, start, end)` - returns the items from the specified start index to the specified end index +- `arr_len()` - returns the length of the array. +- `arr_push(array, item)` - adds an item to the end of the array. +- `arr_pop(array, index)` - removes an item from the end of the array. +- `arr_append(array, item)` - adds an item to the end of the array. +- `arr_extend(array1, array2)` - adds all the items of an array to the end + of the array. +- `arr_find(array, index)` - returns the item at the specified index. +- `arr_slice(array, start, end)` - returns the items from the specified start + index to the specified end index. diff --git a/docs/classes.md b/docs/classes.md index 1830007..cf5e6e4 100644 --- a/docs/classes.md +++ b/docs/classes.md @@ -1,14 +1,23 @@ -# Classes +# Classes and Objects ## Object Oriented Programming -Object Oriented Programming (OOP) is a programming paradigm that uses objects and their interactions to design and program applications. It is based on the concept of objects rather than just functions and procedures. These objects are organized into classes, which allow individual objects to be grouped together. Most modern programming languages including Java, C/C++, and Python are object-oriented languages, and many older programming languages now have object-oriented versions. +Object Oriented Programming (OOP) is a programming paradigm that uses objects +and their interactions to design and program applications. It is based on the +concept of objects rather than just functions and procedures. These objects +are organized into classes, which allow individual objects to be grouped +together. Most modern programming languages including Java, C/C++, and Python +are object-oriented languages, and many older programming languages now have +object-oriented versions. -In Radon, we also have support for OOP. We can create classes and objects. We can also create methods and fields. +In Radon, we also have support for OOP. We can create classes and objects. +We can also create methods and fields. ## Classes -Let's start by creating a class. We can create a class using the `class` keyword. It is followed by the name of the class and the body of the class. The body of the class is enclosed in curly braces. +Let's start by creating a class. We can create a class using the `class` +keyword. It is followed by the name of the class and the body of the class. +The body of the class is enclosed in curly braces. ```py linenums="1" title="classes.rn" class Person { @@ -18,47 +27,59 @@ class Person { ## Objects -Now that we have created a class, we can create an object. We can create an object by simply calling the class like as a function. It is followed by the name of the class and the arguments in parentheses. The arguments are optional. +Now that we have created a class, we can create an object. We can create an +object by simply calling the class like as a function. It is followed by the +name of the class and the arguments in parentheses. The arguments are optional. ```js linenums="1" title="objects.rn" -var person = Person() +person = Person(); ``` ## Fields -Fields are the variables that are declared inside a class. They are used to store data. They are also called instance variables because they are unique to each instance of the class. They are declared using the `var` keyword. It is followed by the name of the field and the type of the field. The type of the field is optional. +Fields are the variables that are declared inside a class. They are used to +store data. They are also called instance variables because they are unique +to each instance of the class. They are declared using the `var` keyword. It +is followed by the name of the field and the type of the field. +The type of the field is optional. ```js linenums="1" title="fields.rn" class Person { - var name = "John" - var age = 20 + name = "John" + age = 20 } ``` ## Constructors -Constructors are special methods that are used to initialize the fields of a class. They are called when an object is created. They are declared using the `fun` keyword. It is followed by the name (class name) of the constructor and the parameters in parentheses. The parameters are optional. +Constructors are special methods that are used to initialize the fields of a +class. They are called when an object is created. They are declared using the +`fun` keyword. It is followed by the name (class name) of the constructor and +the parameters in parentheses. The parameters are optional. ```js linenums="1" title="constructors.rn" class Person { fun Person(name, age) { - var this.name = name - var this.age = age + this.name = name + this.age = age } } -var person = Person("John", 20) +person = Person("John", 20) ``` ## Methods -Methods are the functions that are declared inside a class. They are used to define the behavior of the class. They are declared using the `fun` keyword. It is followed by the name of the method, the parameters in parentheses, and the return type. The parameters and the return type are optional. +Methods are the functions that are declared inside a class. They are used to +define the behavior of the class. They are declared using the `fun` keyword. +It is followed by the name of the method, the parameters in parentheses, and +the return type. The parameters and the return type are optional. ```py linenums="1" title="methods.rn" class Person { fun Person(name, age) { - var this.name = name - var this.age = age + this.name = name + this.age = age } fun sayHello() { @@ -66,7 +87,6 @@ class Person { } } -var person = Person("John", 20) +person = Person("John", 20) person.sayHello() # Output: Hello, John! - ``` diff --git a/docs/contribution.md b/docs/contribution.md index 78b77c0..a8dd14c 100644 --- a/docs/contribution.md +++ b/docs/contribution.md @@ -2,16 +2,18 @@ ## How to contribute -We need contributors to help us build the language. If you are interested, please make contributions to the `radon-project/radon` repository. +We need contributors to help us build the language. If you are interested, +please make contributions to the `radon-project/radon` repository. Steps to contribute: -1. Fork the repository -2. Clone the repository -3. Create a new branch -4. Make changes -5. Commit changes -6. Push to the branch -7. Create a pull request +1. Fork the repository. +2. Clone the repository. +3. Create a new branch. +4. Make changes. +5. Commit changes. +6. Push to the branch. +7. Create a pull request. -Before making a pull request create an issue and discuss the changes you want to make. If you have any questions, feel free to ask in the issues section. +Before making a pull request create an issue and discuss the changes you want to +make. If you have any questions, feel free to ask in the issues section. diff --git a/docs/control-flow.md b/docs/control-flow.md index b14081a..4422509 100644 --- a/docs/control-flow.md +++ b/docs/control-flow.md @@ -2,12 +2,16 @@ ## Conditional statements -Conditional statements are used to execute code based on a condition. In Rain, the `if` statement is used to execute code if a condition is true. The `else` statement is used to execute code if the condition is false. The `elif` statement is used to execute code if the condition is false and another condition is true. The `else` statement is optional. +Conditional statements are used to execute code based on a condition. In Rain, +the `if` statement is used to execute code if a condition is true. The `else` +statement is used to execute code if the condition is false. The `elif` +statement is used to execute code if the condition is false and another +condition is true. The `else` statement is optional. ```js linenums="1" title="conditional-statements.rn" if true { print("true") - + } else { print("false") } diff --git a/docs/data-types.md b/docs/data-types.md index c5f5979..07a8d19 100644 --- a/docs/data-types.md +++ b/docs/data-types.md @@ -4,39 +4,49 @@ The basic types are: -- `int` - integer number -- `float` - floating point number -- `bool` - boolean value -- `string` - string of characters +- `int` - integer number. +- `float` - floating point number. +- `bool` - boolean value. +- `string` - string of characters. ## Arrays -Arrays are declared using the `[]` syntax. The type of the array is the type of the elements it contains. +Arrays are declared using the `[]` syntax. The type of the array is the type +of the elements it contains. ```js linenums="1" title="arrays.rn" -var a = [1, 2, 3] // a is an array of ints -var b = [1.0, 2.0, 3.0] // b is an array of floats -var c = ["a", "b", "c"] // c is an array of strings +a = [1, 2, 3]; // a is an array of ints +b = [1.0, 2.0, 3.0]; // b is an array of floats +c = ["a", "b", "c"]; // c is an array of strings // Arrays can be nested -var d = [[1, 2], [3, 4]] // d is an array of arrays of ints +d = [ + [1, 2], + [3, 4], +]; // d is an array of arrays of ints // Arrays can be empty -var e = [] // e is an empty array of unknown type +e = []; // e is an empty array of unknown type ``` ## Objects (Development) -Objects are declared using the `{}` syntax. The type of the object is the type of the fields it contains. +Objects are declared using the `{}` syntax. The type of the object is the +type of the fields it contains. ```js linenums="1" title="objects.rn" -var a = {x: 1, y: 2} // a is an object with fields x and y of type int -var b = {x: 1.0, y: 2.0} // b is an object with fields x and y of type float -var c = {x: "a", y: "b"} // c is an object with fields x and y of type string +// a is an object with fields x and y of type int +a = { x: 1, y: 2 }; +// b is an object with fields x and y of type float +b = { x: 1.0, y: 2.0 }; +// c is an object with fields x and y of type string +c = { x: "a", y: "b" }; // Objects can be nested -var d = {x: {y: 1, z: 2}, w: {y: 3, z: 4}} // d is an object with fields x and w of type object +// d is an object with fields x and w of type object +d = { x: { y: 1, z: 2 }, w: { y: 3, z: 4 } }; // Objects can be empty -var e = {} // e is an empty object of unknown type +// e is an empty object of unknown type +e = {}; ``` diff --git a/docs/exceptions.md b/docs/exceptions.md new file mode 100644 index 0000000..a1f3702 --- /dev/null +++ b/docs/exceptions.md @@ -0,0 +1,77 @@ +# Exceptions + +Radon has a powerfull exception handler. It can handle exceptions and errors in +the program. It can also throw exceptions and errors. + +## Handling exceptions + +To handle exceptions, we use the `try` and `catch` blocks. The `try` block +contains the code that may throw an exception. The `catch` block contains +the code that handles the exception. + +```js linenums="1" title="exceptions.rn" +try { + // code that may throw an exception + a = 1 / 0 +} catch as err { + // code that handles the exception + print("Exception caught: " + err) +} +``` + +**Output:** + +```bash +Exception caught: Division by zero +``` + +Don't forget to use the `as` keyword to assign the exception to a variable. +The variable can be used to get the exception message. If you don't want to +use the exception message, you can omit the variable. + +```js linenums="1" title="exceptions.rn" +try { + // code that may throw an exception + a = 1 / 0 +} catch as _ { + // code that handles the exception + print("Exception caught") +} +``` + +**Output:** + +```bash +Exception caught +``` + +## Raise exceptions + +To raise an exception, we use the `raise` keyword followed by the exception +type and the message. We have builtin exceptions in `radiation` module. We can +use them to raise exceptions. + +```js linenums="1" title="exceptions.rn" +import radiation + +if 2 != 4 { + raise radiation.ValueError("2 != 4") +} +``` + +**Output:** + +```py +Radiation (most recent call last): + File , line 2 +ValueError: 2 + 2 != 4 + + raise radiation.ValueError("2 + 2 != 4") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``` + +When the exception is raised, the program stops executing and the exception is +propagated up the call stack. The exception can be caught by a `try` block. If +the exception is not caught, the program stops executing and the exception +is printed to the console. diff --git a/docs/file-handling.md b/docs/file-handling.md new file mode 100644 index 0000000..74f053b --- /dev/null +++ b/docs/file-handling.md @@ -0,0 +1,84 @@ +# File handling + +File handling is an essential part of any programming language. Radon provides +a simple way to read and write files. In this section, we will learn how to +read and write files in Radon. + +## File modes + +When opening a file, we can specify the mode in which we want to open the file. + +The modes are: + +- `r`: Read mode. Opens the file for reading. The file must exist. +- `w`: Write mode. Opens the file for writing. If the file does not exist, + it creates a new file. If the file exists, it truncates the file. +- `a`: Append mode. Opens the file for writing. If the file does not exist, + it creates a new file. If the file exists, it appends the content to the file. +- `r+`: Read and write mode. Opens the file for reading and writing. + The file must exist. +- `w+`: Write and read mode. Opens the file for reading and writing. + If the file does not exist, it creates a new file. If the file exists, + it truncates the file. +- `a+`: Append and read mode. Opens the file for reading and writing. + If the file does not exist, it creates a new file. If the file exists, + it appends the content to the file. + +By default, the file is opened in read mode. + +## Reading from a file + +To manipulate files in Radon, we use built-in `File` class. We can create a new +instance of `File` class by passing the file path to the constructor. We can +then use the `read` method to read the contents of the file. + +```py linenums="1" title="file-handling.rn" +file = File("file.txt") +content = file.read() +print(content) +``` + +You can also read the file line by line using the `readline` method. + +```py linenums="1" title="file-handling.rn" +file = File("file.txt") +line = file.readline() +print(line) +``` + +You can also read all the lines of the file using the `readlines` method. + +```py linenums="1" title="file-handling.rn" +file = File("file.txt") +lines = file.readlines() +print(lines) +``` + +## Writing to a file + +To write to a file, we use the `write` method. We can pass the content to the +`write` method to write to the file. + +```py linenums="1" title="file-handling.rn" +file = File("file.txt") +file.write("Hello, World!") +``` + +## Closing a file + +After reading or writing to a file, it is important to close the file. We can +use the `close` method to close the file. + +```py linenums="1" title="file-handling.rn" +file = File("file.txt") +# code that reads or writes to the file +file.close() +``` + +Check the file is closed or not using the `is_closed` method. + +```py linenums="1" title="file-handling.rn" +file.is_closed() +``` + +That's it! You now know how to read and write files in Radon. diff --git a/docs/functions.md b/docs/functions.md index 7c66e11..043f93d 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -2,7 +2,10 @@ ## Types of functions -Functions are the building blocks of a task. They are used to define the behavior of the program. In Radon, we declare functions using the `fun` keyword. It is followed by the name of the function, the parameters, and the return type. The body of the function is enclosed in curly braces. +Functions are the building blocks of a task. They are used to define the +behavior of the program. In Radon, we declare functions using the `fun` keyword. +It is followed by the name of the function, the parameters, and the return type. +The body of the function is enclosed in curly braces. In Radon, there are three types of functions: @@ -21,7 +24,7 @@ fun add(a, b) { ### Anonymous functions ```js linenums="1" title="anonymous_functions.rn" -fun add = (a, b) { +add = fun (a, b) { return a + b } ``` @@ -34,7 +37,8 @@ fun add(a, b) -> a + b ## Calling functions -Calling a function is done by using the function name followed by the arguments in parentheses. +Calling a function is done by using the function name followed by the arguments +in parentheses. ```py linenums="1" title="calling_functions.rn" add(1, 2) # Output: 3 @@ -44,14 +48,30 @@ That's it! You now know how to call functions in Radon. ## Function parameters -Function parameters are the names listed in the function definition. They are used to pass values into the function. The parameters are separated by commas. The parameters are optional. +Function parameters are the names listed in the function definition. They are +used to pass values into the function. The parameters are separated by commas. +The parameters are optional. We can also leave out the parentheses if there are no parameters. ```py linenums="1" title="function_parameters.rn" -fun sayHello(name) { +fun say_hello(name) { print("Hello, " + name + "!") } -sayHello("World") # Output: Hello, World! +say_hello("World") # Output: Hello, World! +``` + +## Default parameters + +Default parameters are used to assign a default value to a parameter. If the +parameter is not passed, the default value is used. + +```py linenums="1" title="default_parameters.rn" +fun new_user(name="Guest") { + print("Hello, " + name + "!") +} + +new_user() # Output: Hello, Guest! +new_user("World") # Output: Hello, World! ``` diff --git a/docs/index.md b/docs/index.md index 5bbcfc4..034bb6e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,12 +1,15 @@ # The Radon Programming Language -[![Radon Logo](./assets/images/radon.png "Radon Logo")][website] +
+ ![Radon Logo](./assets/images/radon.png "Radon Logo"){ width="300" } +
+ + Radon + is a programming language that is designed to be easy to learn and use. +
+
-
- **The Radon Programming Language** -
- -Created by [Md. Almas Ali][almas] +Maintained by [Md. Almas Ali][almas] [![Hits](https://hits.sh/radon-project.github.io/radon.svg)](https://hits.sh/radon-project.github.io/radon/) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/radon-project/radon?style=flat-square)][github] @@ -30,7 +33,12 @@ Created by [Md. Almas Ali][almas] ## Introduction -Radon is a programming language that is designed to be easy to learn and use. It is a high-level language intended to be used for general purpose programming. It is designed to be easy to learn and use, while still being powerful enough to be used for most tasks. Some of the features of Radon include: +Radon is a programming language that is designed to be easy to learn and use. +It is a high-level language intended to be used for general purpose programming. +It is designed to be easy to learn and use, +while still being powerful enough to be used for most tasks. + +Some of the features of Radon include: - A simple syntax that is easy to learn and use - Dynamic typing so that you don't have to worry about types @@ -52,36 +60,36 @@ Radon is a programming language that is designed to be easy to learn and use. It # This is a Radon test file for the Radon Programming Language. class Network { - fun Network(username, password) { - var this.username = username - var this.password = password - } - - fun login() { - if this.username == "radon" { - if this.password == "password" { - print("Log in successful") - } - } else { - print("Invalid credentials") - } - } + fun __constructor__(username, password) { + this.username = username + this.password = password + } + + fun login() { + if this.username == "radon" { + if this.password == "password" { + print("Log in successful") + } + } else { + print("Invalid credentials") + } + } } -var username = input("Enter you username: ") -var password = input("Enter your password: ") +username = input("Enter you username: ") +password = input("Enter your password: ") -var network = Network(username, password) +network = Network(username, password) network.login() ``` ## Sponsors -No sponsors yet. Be the first one to sponsor this project. [Become a sponsor][contact]{:target="\_blank"} +No sponsors yet. Be the first one to sponsor this project. +[Become a sponsor][contact]{:target="\_blank"} [almas]: https://github.com/Almas-Ali "Md. Almas Ali" [github]: https://github.com/radon-project/radon "Radon" -[website]: https://radon-project.github.io/ "Website" [web]: https://radon-project.github.io/ "web" [docs]: https://radon-project.github.io/docs "Docs" [contact]: https://linkedin.com/in/md-almasali "Contact the author" diff --git a/docs/input-output.md b/docs/input-output.md index cecfca4..40222d3 100644 --- a/docs/input-output.md +++ b/docs/input-output.md @@ -2,7 +2,9 @@ ## Printing to the console -In Radon, we can print to the console using the `print` function. It is followed by the argument in parentheses. The argument are mandatory. It takes only one argument. We can concatenate data types using the `+` operator. +In Radon, we can print to the console using the `print` function. +It is followed by the argument in parentheses. The argument are mandatory. +It takes only one argument. We can concatenate data types using the `+` operator. ```py linenums="1" title="print.rn" print("Hello" + ", " + "World!") # Output: Hello, World! @@ -10,9 +12,11 @@ print("Hello" + ", " + "World!") # Output: Hello, World! ## Input from the console -In Radon, we can take input from the console using the `input` function. It is followed by the argument in parentheses. The argument are mandatory. It takes only one argument. We can concatenate data types using the `+` operator. +In Radon, we can take input from the console using the `input` function. It is +followed by the argument in parentheses. The argument are mandatory. It takes +only one argument. We can concatenate data types using the `+` operator. ```py linenums="1" title="input.rn" -var name = input("Enter your name: ") +name = input("Enter your name: ") print("Hello, " + name + "!") # Output: Hello, World! ``` diff --git a/docs/installation.md b/docs/installation.md index 306d26e..0913221 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,28 +1,47 @@ # Installation -It's easy to install Radon on your computer. Just go to the [downloads page](https://radon-project.github.io "Downloads") and download the latest version for your operating system. Then, follow the instructions below for your operating system. If you have any problems, please [contact us](https://github.com/radon-project/radon/issues "Issues") and we'll help you out. +It's easy to install Radon on your computer. Just go to the +[downloads page](https://radon-project.github.io "Downloads") +and download the latest version for your operating system. Then, follow the +instructions below for your operating system. If you have any problems, please +[contact us](https://github.com/radon-project/radon/issues "Issues") +and we'll help you out. ## Windows -To install Radon on Windows, just download the installer from the [downloads page](https://radon-project.github.io/#download "Downloads") and run it. Then, follow the instructions on the screen to install Radon on your computer. +To install Radon on Windows, just download the installer from the +[downloads page](https://radon-project.github.io/#download "Downloads") +and run it. Then, follow the instructions on the screen to install +Radon on your computer. -After setup you need to manually configure the PATH environment variable. To do this, open the Control Panel and go to System and Security > System > Advanced system settings > Environment Variables. Then, select the PATH variable and click Edit. Add the path to the Radon bin directory to the end of the variable value. For example, if you installed Radon in **C:\Program Files (x86)\Radon**, you would add **C:\Program Files (x86)\Radon** to the end of the variable value. Then, click OK to save the changes. +After setup you need to manually configure the PATH environment variable. +To do this, open the Control Panel and go to System and +Security > System > Advanced system settings > Environment Variables. +Then, select the PATH variable and click Edit. Add the path to the Radon bin +directory to the end of the variable value. For example, if you installed +Radon in **C:\Program Files (x86)\Radon**, you would add +**C:\Program Files (x86)\Radon** to the end of the variable value. +Then, click OK to save the changes. -**Quick tip:** You can also set the PATH variable from the command line. Just open a command prompt and type the following command: +**Quick tip:** You can also set the PATH variable from the command line. +Just open a command prompt and type the following command: ```bat linenums="1" title="Command prompt (Windows)" setx PATH "%PATH%;C:\Program Files (x86)\Radon" ``` -Now, you can open a command prompt and type **radon** to run Radon. If you get an error message, try restarting your computer and trying again. +Now, you can open a command prompt and type **radon** to run Radon. +If you get an error message, try restarting your computer and trying again. ## macOS -Mac installer is not available yet. You can download the source code and build it yourself. +Mac installer is not available yet. +You can download the source code and build it yourself. ## Linux -Linux installer is not available yet. You can download the source code and build it yourself. +Linux installer is not available yet. +You can download the source code and build it yourself.
***Linux users don't need any instructions!!*** diff --git a/docs/language-reference.md b/docs/language-reference.md index 2edb990..efdd34a 100644 --- a/docs/language-reference.md +++ b/docs/language-reference.md @@ -1,7 +1,7 @@ # Language Reference -## Under Maintenance +## Under Maintenance -The language reference is currently under maintenance. Please check back later. +The language reference is currently under maintenance. Please check back later. Thank you for your patience. diff --git a/docs/loops.md b/docs/loops.md index 2db931d..98da8a3 100644 --- a/docs/loops.md +++ b/docs/loops.md @@ -1,6 +1,8 @@ # Loops -Loops are used to execute a block of code multiple times. The block of code will be executed until the condition is true. This help us to reduce the code and execute the same block of code multiple times. +Loops are used to execute a block of code multiple times. The block of code will +be executed until the condition is true. This help us to reduce the code and +execute the same block of code multiple times. In Radon we have 2 types of loops. @@ -16,7 +18,8 @@ In for loop we have 2 varients. ### For loop with range -With range we can specify the start, end and step value. If step value is not provided then it will be 1. +With range we can specify the start, end and step value. +If step value is not provided then it will be 1. ```py for i=0 to 10 { @@ -26,7 +29,7 @@ for i=0 to 10 { **Output:** -``` +```py 0 1 2 @@ -49,7 +52,7 @@ for i=0 to 10 step 2 { **Output:** -``` +```py 0 2 4 @@ -59,9 +62,11 @@ for i=0 to 10 step 2 { ### For loop with sequence of elements -With sequence of elements we can specify the elements in the loop. The loop will run for each element. +With sequence of elements we can specify the elements in the loop. +The loop will run for each element. -Here we are using `Array` of elements. The loop will run for each element in the `Array`. +Here we are using `Array` of elements. +The loop will run for each element in the `Array`. ```py for i in [1, 2, 3, 4, 5] { @@ -71,7 +76,7 @@ for i in [1, 2, 3, 4, 5] { **Output** -``` +```py 1 2 3 @@ -89,7 +94,7 @@ for i in "Hello" { **Output:** -``` +```py H e l @@ -109,7 +114,7 @@ for i in hash { **Output:** -``` +```py Key: name Value: John Key: age @@ -118,7 +123,8 @@ Value: 30 ## While loop -With while loop we can specify the condition. The loop will run until the condition is true. +With while loop we can specify the condition. +The loop will run until the condition is true. ```py i = 0 @@ -130,7 +136,7 @@ while i < 5 { **Output:** -``` +```py 0 1 2 @@ -138,7 +144,8 @@ while i < 5 { 4 ``` -We have used `nonlocal` keyword to update the value of `i` in the loop. If we don't use `nonlocal` then it will run into infinite loop. +We have used `nonlocal` keyword to update the value of `i` in the loop. +If we don't use `nonlocal` then it will run into infinite loop. ## Loop control statements @@ -164,7 +171,7 @@ for i=0 to 10 { **Output:** -``` +```py 0 1 2 @@ -187,7 +194,7 @@ while i < 10 { **Output:** -``` +```py 0 1 2 @@ -212,7 +219,7 @@ for i=0 to 5 { **Output:** -``` +```py 0 1 2 @@ -235,7 +242,7 @@ while i < 5 { **Output:** -``` +```py 0 1 2 diff --git a/docs/modules.md b/docs/modules.md index 53de393..b1108b4 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -2,11 +2,19 @@ ## Introduction to Modules -Modules are a way to organize code in a way that is easy to reuse, test, and debug. Modules are also called packages, libraries, or frameworks. Modules are used to group related code together. For example, a module can be used to group code that is related to a specific task, such as sending an email. Modules are also used to group code that is related to a specific feature, such as a user interface. +Modules are a way to organize code in a way that is easy to reuse, test, +and debug. Modules are also called packages, libraries, or frameworks. +Modules are used to group related code together. For example, a module can +be used to group code that is related to a specific task, such as sending +an email. Modules are also used to group code that is related to a specific +feature, such as a user interface. ## Creating a Module -A module is created by creating a file with the `.rn` extension. The file name is the name of the module. The name should have to be in Pascal Case `PascalCase`. The module have to implement the same name class as the file name. The class name should have to be in Pascal Case `PascalCase`. +A module is created by creating a file with the `.rn` extension. The file name +is the name of the module. The name should have to be in Pascal Case `PascalCase`. +The module have to implement the same name class as the file name. The class +name should have to be in Pascal Case `PascalCase`. ```py linenums="1" title="Hello.rn" class Hello { @@ -18,9 +26,9 @@ class Hello { ## Importing a Module -A module is imported by using the `include` keyword. It is followed by the name of the module. The name of the module should have to be in Pascal Case `PascalCase`. +A module is imported by using the `include` keyword. It is followed by the name +of the module. The name of the module should have to be in Pascal Case `PascalCase`. ```py linenums="1" title="importing.rn" include Hello ``` - diff --git a/docs/quick-start.md b/docs/quick-start.md index 97b5b23..93c182a 100644 --- a/docs/quick-start.md +++ b/docs/quick-start.md @@ -1,16 +1,23 @@ # Quick start -To get started with Radon language you can use the built-in REPL or just run the Radon file. Run a Radon file by typing `radon -s .rn` in the command line. For example, if you have a file named `hello.rn` you can run it by typing `radon -s hello.rn` in the command line. +To get started with Radon language you can use the built-in REPL or just run +the Radon file. Run a Radon file by typing `radon -s .rn` in the +command line. For example, if you have a file named `hello.rn` you can run it +by typing `radon -s hello.rn` in the command line. ## REPL -The REPL is a command line interface that allows you to run Radon code interactively. To start the REPL, just type `radon` in the command line. You can then type Radon code and it will be executed immediately. To exit the REPL, just type `exit()` or press `Ctrl + Z`. - +The REPL is a command line interface that allows you to run Radon code +interactively. To start the REPL, just type `radon` in the command line. +You can then type Radon code and it will be executed immediately. To exit the +REPL, just type `exit()` or press `Ctrl + Z`. ## Hello World -The first program that most people write in a new language is the "Hello World" program. This program simply prints the words "Hello World" to the screen. Here is the "Hello World" program in Radon: +The first program that most people write in a new language is the "Hello World" +program. This program simply prints the words "Hello World" to the screen. Here +is the "Hello World" program in Radon: ```py linenums="1" title="HelloWorld.rn" print("Hello World") -``` \ No newline at end of file +``` diff --git a/docs/standard-library.md b/docs/standard-library.md index 5a15027..98d28c3 100644 --- a/docs/standard-library.md +++ b/docs/standard-library.md @@ -1,6 +1,6 @@ # Standard Library -## List of Standard Libraries +## List of Standard Libraries ```text * @@ -13,4 +13,4 @@ │ └── Winlib.rn ``` -... and more to come! Under development. \ No newline at end of file +... and more to come! Under development. diff --git a/docs/strings.md b/docs/strings.md index a354ff2..1073073 100644 --- a/docs/strings.md +++ b/docs/strings.md @@ -2,12 +2,13 @@ ## String methods -- `str_len()` - returns the length of the string -- `str_find(string, index)` - returns the character at the specified index -- `str_slice(string, start, end)` - returns the substring from the specified start index to the specified end index +- `str_len()` - returns the length of the string. +- `str_find(string, index)` - returns the character at the specified index. +- `str_slice(string, start, end)` - returns the substring from the specified + start index to the specified end index ```py linenums="1" title="methods.rn" -var str = "Hello, World!" +str = "Hello, World!" print(str_len(str)) # 13 print(str_find(str, 0)) # H @@ -22,7 +23,7 @@ print(str_slice(str, 0, 5)) # Hello - `*` (repetition) ```py linenums="1" title="operators.rn" -var str = "Hello, World!" +str = "Hello, World!" print(str + " " + "Hello, World!") # Hello, World! Hello, World! print(str * 2) # Hello, World!Hello, World! diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index b630980..e69de29 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -1,9 +0,0 @@ -a[title=Website] { - display: flex; - justify-content: center; -} - -a[title=Website] img { - height: 250px; - width: 250px; -} \ No newline at end of file diff --git a/docs/theme/main.html b/docs/theme/main.html index 41af1c4..57d218c 100644 --- a/docs/theme/main.html +++ b/docs/theme/main.html @@ -5,6 +5,6 @@ {% endblock %} {% block content %} + {{ super() }} - {% endblock %} \ No newline at end of file diff --git a/docs/tools.md b/docs/tools.md index b410c0f..40986fa 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -1,2 +1 @@ # Tools - diff --git a/mkdocs.yml b/mkdocs.yml index 942569f..2cf3f75 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -112,8 +112,8 @@ nav: - Classes: classes.md - Modules: modules.md - Input/Output: input-output.md - # - Exceptions: exceptions.md - # - File Handling: file-handling.md + - Exceptions: exceptions.md + - File Handling: file-handling.md - Strings: strings.md - Arrays: arrays.md - Built-in Functions: built-in-functions.md