Creating our first function
In this section, we will guide you through creating your first function in Prism. We will create a file named add.pr
and define a simple function called add
that takes two parameters and returns their sum.
Create
add.pr
file: Open your text editor of choice and create a new file namedadd.pr
. You can use the following command in the terminal:
Edit
add.pr
and define theadd
function: add the following code toadd.pr
using your text editor:
In this code, we define a function add
that takes two parameters (a
and b
) and returns their sum using the +
operator. We then test the function by calling add(1, 3).
Compile and execute the function: save the
add.pr
file and open your terminal. Navigate to the directory containingadd.pr
and execute the following command:
When compiling, a file generator.out
is generated. This file contains the binary instructions that correspond to the code contained in the file passed as an argument to the binary psc
.
This command calls the Prism Virtual Machine, which treats the generator.out
file to give the response you see in the terminal.
Congratulations! You've created and executed your first function in Prism. Feel free to explore more features and functionalities of Prism by defining and testing additional functions in your add.pr
file.
Last updated