Comparison of Scriptol, C and PHP code
The code of the Scriptol language is intuitive and simple. Instead, the PHP code is inherited from ancient languages such as C and the language of command line of UNIX, Bash, designed to limit the consumption of resources and not to simplify the task of programmers
A clear syntax
Scriptol doesn't need for semi-colon et end of statements. The end of line is also the end of statement unless several statements fits on a same line, in this case they are separated by semi-colons. If an instruction fits on two lines, the compiler recognizes the instruction.
C++ syntax
for(int x = 0; x < 10;x++)
{
printf("%d\n", x);
}
PHP syntax
for($x = 0; $x < 10; $x++)
{
echo "$x\n";
}
Scriptol syntax
for int x in 0 .. 9 print x
Objective design
Unlike C that was designed with limited hardware in mind, Perl that has
added features day after day, and other languages that depends upon the phantasy
of the author, Scriptol apply objectives rules,
and it near the more used syntax in computer world, the XML one... XML is
tagged and has as C one-line syntax.
Scriptol has one-line syntax, (see above) and is tagged:
for
...
/for
Universal operators
Scriptol doesn't use an operator for different usages, as C uses & for
deferencing or for binary and, but a same operator should have a same usage in
similar cases.
For example, in Scriptol, the range operator " .. " is used:
- as the range in the for loop (see above).
- as an interval of an array or a dictionnary.
- as a range in an expression:
if x in 0 .. 9
print "x inside range"
/if
Types from the real word
C and Pascal in the seventeens invented types that were related to hardware: char, long, short, char *, float, etc...
Scriptol use types related to the real word: text, number, integer, natural, real, array, dict, dir, etc...
Readability
A complicated and unreadable part of C++ code...
int x[] = { 1, 2, 3, 4 };
int i;
for(i = 0; i < 4; i++)
{
if(x[i] == test) std::cout << test << " found" << std::endl;
}
...may be replaced by a single and clear Scriptol statement.if test in { 1, 2, 3, 4 } print test, "found"
And a lot more...
This page and other pages on this site, show only a small part of the language. The manual describes also:
- Multiple return from a function.
- Conditional assignment.
- Simpler augmented assignment.
- More control structures, more data types.
- Etc...
Scriptol vs. PHP
The scriptol code:
text x input "Y/N?", x if x.lower() = "y" print "yes" = "n" print "no" else print "What?" /if
The PHP generated code:
<?php
echo "Y/N?";
$fp=fopen("php://stdin","r");
$x=rtrim(fgets($fp,65536));
fclose($fp);
$_I1=strtolower($x);
if($_I1==="y")
{
echo "yes", "\n";
}
else
{
if($_I1==="n")
{
echo "no", "\n";
}
else
{
echo "What?", "\n";
}
}
?>