Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,7 @@
% declare some variables %
integer a1, a2; real b; long real c; complex d; long complex f;
logical g; bits h; string(32) j;
% assign "initial values" %
f := d := c := b := a2 := a1 := 0; % multiple assignment %
g := false; h := #a0; j := "Hello, World!";

View file

@ -0,0 +1,2 @@
record R1 ( integer length; string(256) text );
reference(R1) ref1, ref2;

View file

@ -0,0 +1,3 @@
record person( string(32) name; integer age );
record date( integer day, month, year );
reference(person, date) ref3;

View file

@ -0,0 +1 @@
reference(integer) refInt; % an illegal declaration %

View file

@ -0,0 +1,2 @@
record INT_VALUE ( integer val );
reference(INT_VALUE) refInt;

View file

@ -0,0 +1,7 @@
% using the person record defined above...%
reference (person) someone;
someone := person % create a new person structure with uninitialised fields %
name(someone) := "Fred"; % initialise the fields %
age(someone) := 27;
% could also initialise the fields when the record is created: %
someone := person( "Harry", 32 );

View file

@ -0,0 +1,3 @@
set MyStr = "A string"
set MyInt = 4
set MyFloat = 1.3

View file

@ -0,0 +1,5 @@
set MyArray(1) = "element 1"
set MyArray(2) = "element 2"
set MyArray(2,1) = "sub element 1 of element 2"
set MyArray("Element 3") "element indexed by a string"
set MyArray = "Root element"

View file

@ -0,0 +1 @@
set ^MyGlobal("a subscript") = "My Value"

View file

@ -0,0 +1 @@
set ^||MyProcessPrivateGlobal("subscript 1") = "value"

View file

@ -1,5 +1,19 @@
my @y = <A B C D>; #Array of strings 'A', 'B', 'C', and 'D'
my @y = <A B C D>; # Array of strings 'A', 'B', 'C', and 'D'
say @y[2]; # the @-sigil requires the container to implement the role Positional
@y[1,2] = 'x','y'; # that's where subscripts and many other things come from
say @y; # OUTPUT«[A x y D]␤» # we start to count at 0 btw.
my $x = @y; # $x is now a reference for the array @y
say $x[1]; # prints 'B' follow by a newline character
say $x[1]; # prints 'x' followed by a newline character
my Int $with-type-check; # type checks are enforced by the compiler
my Int:D $defined-i = 10; # definedness can also be asked for and default values are required in that case
my Int:D $after-midnight where * > 24 = 25; # SQL is fun and so is Perl 6
my \bad = 'good'; # if you don't like sigils
say bad; # you don't have to use them
say "this is quite bad"; # but then string interpolation
say "this is quite {bad}" # becomes more wordy

View file

@ -1,14 +1,6 @@
# $x can contain only Int objects
my Int $x;
say ++$; # this is an anonymous state variable
say ++$; # this is a different anonymous state variable, prefix:<++> forces it into numerical context and defaults it to 0
say $+=2 for 1..10 # here we do something useful with another anonymous variable
# $x can only contain native integers (not integer objects)
my int $x;
#A variable may itself be bound to a container type that specifies how the container works, without specifying what kinds of things it contains.
# $x is implemented by the MyScalar class
my $x is MyScalar;
#Constraints and container types can be used together:
# $x can contain only Int objects,
# and is implemented by the MyScalar class
my Int $x is MyScalar;
sub foo { $^a * $^b } # for positional arguments we often can't be bothered to declare them or to give them fancy names
say foo 3, 4;

View file

@ -1,10 +1,10 @@
aa = 10 /*assigns chars 10 ───► AA */
bb = '' /*assigns a null value ───► BB */
cc = 2*10 /*assigns charser 20 ───► CC */
cc = 2*10 /*assigns chars 20 ───► CC */
dd = 'Adam' /*assigns chars Adam ───► DD */
ee = "Adam" /*same as above ───► EE */
ff = 10. /*assigns chars 10. ───► FF */
gg='10.' /*same as above ───► GG */
hh = "+10" /*assigns chars +10 ───► hh */
ii = 1e1 /*assigns chars 1e1 ───► ii */
jj = +.1e+2 /*assigns chars +.1e+2 ───► jj */
jj = +.1e+2 /*assigns chars .1e+2 ───► jj */