develooper Front page | perl.perl6.language | Postings from June 2002

what's new

Thread Next
From:
raptor
Date:
June 17, 2002 13:06
Subject:
what's new
Message ID:
20020617230217.2caadad4.raptor@unacs.bg



hi,

It is said : "if u want to understand something try to explain it to someone else".
So I tried it ... below is some preliminary result.
Let me state first that i don't try to describe everything, just things that I like :"), my second goal is eventualy to translate this to Bulgarian and post on some bg site (if the result is aprox-good)
I have some question inside if u can answer me pls do it... ok thanx here is it :

-------------------------------------------------------------------

1.) Proprietes ==============================
Every subrotine or variable or method or object can have a "notes" attached to it and they are called "property". (Internally properties are hashes --> pHash).
The proprietes can be compile time and run time proprietes.
Samples :

my $x is constant = 5;#this says that $x is constant and its value is 5

my $x is foo = 0;
Now $x.foo is equal to 1 (isnt it?), but $x is 0. In fact $x.foo is interpreted as method call i.e. $x.foo().
If there is no method with name foo() then such method is pretended to exist and it returns the value of property with that name.

$x.btw

will return hash-ref to properties hash i.e. pHash-ref.
So that :

print keys %{$x.btw}

will print "foo" (and probably if SCALAR's have some default props they will be printed too ?)
U can specify more props at once and also skip "is" keyword like this :

my $i is constant note('I use this var for loop counter') = 0;

then :

print $i.btw{note}

should print "I use this var for loop counter".
(What "btw" mean --> "By the way" ?)

(....sub-examples to be added)

2.) Multiway comparison ==============================

Now we can say :

    0 <= $x <= 10 

to check if $x is between 0 and 10 inclusive i.e. 0 <= $x && $x <= 10

3.) Hyper operators ==================================

Cool no more loop-in-loop-in-loop....:"). All operators can be hyper-ed simply prepend them with "^" - upper-cap.
Samples :

@a ^* @b 

multyplies both arrays and will return a list of ( $a[0]*$b[0], $a[1]*$b[1], ... $a[n]*$b[n] ) OR ( @a[0]*@b[0], @a[1]*@b[1], ... @a[n]*@b[n] ) if we use Perl6 notation/syntax.

@a ^+ 1

will return a list of all elements of @a increased by one. (@a stays unchanged).
Then what about this :
  @a ^&& @b
  @a ^|| @b

Here is how in one sweep we can change some text in every element-string in array :
  @foo ^=~ s/foo/bar/
  
And how to increase the elements of array with 1 but this time applying the changes to the @a   
  @a ^+= 1

Let's someone of the anti-perl camp tell me that this "upper-cap noise" makes the code hard to read and I will smash him with a hammer in the head :") and leave him to type "from here to tommorow loop after loop after loop after loop" :"). Gees those perl designers with LW in the head are mad-scientists .....


4.) Binding  ==================================

In addition to the standard assignment operator of perl5 "=" we will also have ":=" i.e. bind operator.
<snip - apo3>
If you're familiar with Prolog, you can think of it as a sort of unification operator (though without the implicit backtracking semantics). In human terms, it treats the left side as a set of formal arguments exactly as if they were in the declaration of a function, and binds a set of arguments on the right hand side as though they were being passed to a function. This is what the new := operator does.
</snip>
f.e : 

$a := $b

in pseudo-code it will be something like this :

sub xxx($a) { ..... your program here ..... };
xxx($b);

that is to say that from now on $a is $b. This operator can serve one more purpose i.e. aliasing :
$x := $ary[0]{keylevel1}{keylevel2}

Now instead of writing all those keys just use $x{keylevel3}
Perl6 syntax : 
%x := @ary[0]{keylevel1}{keylevel2};
print %x{keylevel3};
? Is this correct ?

More examples :

(@a, @b) := (@b, @a)

swap two arrays.
......more to come


----------------------------------------------------------------

raptor

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About