411 REFERENCE · Wikibooks
Plezuro/getting started
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
One of the main principles of the Plezuro programming language says the following: "The module, the function and the source file are equivalent one to each other." What does it mean exactly? So you can pass arguments to a module in the same way like to a function and also the module returns a value in the same way like a function.
Hello world
At the beginning: How can you write the Hello World script in Plezuro? It is so simply:
'Hello World!'
Of course, the design of the language could be even simpler like that:
Hello World!
But that would be much more like a mark-up language (eventually template language), not programming language. So the previous script is not correct. Moreover, there exist other possibilities to write a Hello World script, eg.:
'Hello World!'.printl;
In the first script, the module just returns a value (string 'Hello World!'), and in the last one it prints this string to the standard output, and finally returns the empty value (called just 'empty', its symbol: '()').
Comments
For simplicity, the comments are in c++/Java/c# style. Therefore, it enables commenting large blocks of code, in contrary to languages such as Python or Ruby (Of course you can use multi-line string in both cases, but in many situations it outputs an error).
// this is a comment
/*
Another comment
*/
Variables
Like any (including really bizarre ones almost any) languages, Plezuro is based on using of variables. A variable is just a container for a piece of information. So at first occurrence of a variable you should write the dollar sign ('$') immediately before the variable name. The name is in Java style (it allows using any Unicode letters, digits and underscore, but at the beginning there must not be any letter). In the next occurrences, the dollar sign is not required. Why do we write so many '$'? It seems like PHP, Perl or bash. The reason is really simple. Just to define the variable scope. It is like the 'var' keyword in JavaScript (or in c♯ in case of local variables) but in Plezuro it is just shorted (one character '$' instead of four ones 'var '). It is a really important feature in case of short anonymous functions and evaluation of code written in string.
So let us write some strange example:
$假借字=4;
假借字+假借字^2
Now, maybe a little less strange:
$x=4;
x+x^2
The nature of the language
Unlike other programming languages where there is just a list of instructions in a function, Plezuro is based on operators. Commands are separated with a semicolon (';') but it is only one of multiple operators. Even variable assignment and function call in intermediate code are translated into operators. Only brackets ('(', ')') and curly braces ('{', '}') are not translated into operators. What is their use? So brackets are used to change order of operators calculation while curly braces are used to write down code which should be executed in the future (or eventually never). That means curly braces are used to write a function definition, a conditional loop or a conditional expression (in these cases we have also some sort of functions - anonymous functions).
2*(3+4)^5.4
$x = 5;
{2<3}.if{x++}.else{x--};
x
Operators precedence
Two-arguments operators:
;
:=
=
,
<->
<<
>>
?
|
&
<=>
>=
>
<=
<
!=
==
===
=~
-
%
*
/
^
Together:
* ^^
* .
..
:
Single-argument operators (the precedence doesn't matter here; important is to just list these operators):
!
&&
**
#
--
--
@
Important issues
Moreover, you should remember about the following:
The whitespace characters are not included in the intermediate code (that means you may write any number of spaces, tabs and newlines between the tokens (a number/ string/ name/ operator...), of course you cannot write spaces in the middle of variable names or operators.
One of very important issues of Plezuro is the tuple. You can use it when passing one variable that stores all these arguments to a multiple-argument function. Moreover, you can use it in a similar way like in Python.