Magical Functions

Dive into the enchanting world of coding with SunSed's Magical Function Generator. Leave the complexities of syntax behind as you employ Magical to create functions that heed your command with grace and efficiency.

Your Code, Your Language

Unleash the potential of SunSed's Magical Function Generator by crafting descriptions of what your code should achieve using everyday language.

Copied!
`remove last word`("hello my friend")
//=> "hello my"

A simple backtick (`) is all it takes to mold functions out of sentences. This approach helps to free your mind from the clutter of remembering library functions—draft your own with ease!

Crafting Commands in English

Copied!
`remove last word`("hello my friend")
//=> "hello my"

`capitalize each word of the arg1:str`("welcome to sunsed")
//=> "Welcome To Sunsed"

`create greeting for arg1:str (default: Guest)`()
//=> "Hello, Guest!"

`replace arg1:str with arg2:str in arg3:str`("hello", "hi", "hello world")
//=> "hi world"

`add arg1:num to arg2:num`("1", "2")
//=> 3

`multiply arg1:num with arg2:num`("1", "2")
//=> 2

`remove duplicate words from arg1:str`("hello hello world")
//=> "hello world"

`remove duplicate values from arg1:arr`([1, 2, 3, 1, 2, 3])
//=> [
//=>     1,
//=>     2,
//=>     3
//=> ]
Result

Here are a few guidelines to help you craft better commands:

Arguments and Types

Copied!
`capitalize each word of the arg1:str`("welcome to sunsed")
//=> "Welcome To Sunsed"

You can pass arguments to your functions by using the arg1, arg2, etc in your command. You can also specify the type of your arguments by using the :type syntax. For example, arg1:str specifies that the first argument is a string. If you do not specify an argument or its type in your command, SunSed will infer it from the input you provide. For example, arg1 will be inferred as a string if you pass a string to the function.

Here is a list of possible types:

Simulating Other Languages

Copied!
`ruby: squish`("  hello   world  ")
//=> "hello world"

You can simulate other languages by using the `language: ` keyword. This will allow you to instruct the magical function to mimic the behavior of a function in another language.

Testing

Copied!
`create greeting for arg1:str (default: Guest)`()
//=> "Hello, Guest"

The Run Selection Feature (⌘+enter) allows you to test your functions in real-time. You need to make sure that the auto generated function does what you want it to do.

Inspecting the Function

Copied!
`ruby: squish`
//=> [
//=>     "NOTE" => "This is not an acutal array -- it represents a function.",
//=>     "is_function_representation?" => true,
//=>     "signature" => [
//=>         "parameters" => [
//=>             [
//=>                 "name" => "str",
//=>                 "is_optional?" => false,
//=>                 "has_type?" => true,
//=>                 "type" => "string",
//=>                 "has_default_value" => false
//=>             ]
//=>         ],
//=>         "parameter_names" => [
//=>             "str"
//=>         ],
//=>         "file_name" => "853693cef6e9563482d2271147a8590486a4469527ab1340c8297a2a64c8c140--x40-20.builtins",
//=>         "line_number" => 1,
//=>         "has_return_type" => true,
//=>         "return_type" => "string"
//=>     ]
//=> ]

Pressing ⌘+Enter (or Ctrl+Enter on Linux and Windows) while focusing on the line where a magical function is defined will reveal its signature, allowing for a deeper understanding and more efficient use of the function.