Re: [Vala] what does # mean in a member method formal parameter?

On Sun, 2008-05-11 at 00:50 +0200, Maciej Piechotka wrote:
On Sun, May 11, 2008 at 12:47 AM, Yu Feng <rainwoodman gmail com> wrote:

You misunderstood me. I know what # is for but the cotext in which it is used
is to make possible writing generice.


Can you explain it in details? I didn't get it much.


(not tested - but should work):
class Test<T> {
    public void set(T #t1) {
        t = #t1;
    private T t;

Here # has to have consistent behaviour with objects and others.


Yes I agree with you. # should be consistent with objects and others. #
should be for taking ownership - or taking the obligation to dispose the
object. It is NOT taking some reference. Just taking the obligation to
dispose the object.

Look at this piece of code

class Test {
    private string t;
    public void set(string # t1){
        t = #t1;
    public static void main(string [] argv){
        Test t = new Test();
        string t1 = "a string";
        t.set(#t1); // ******

The thing confuses me is now, vala won't panic if I use t.set(t1)
instead of t.set(#t1) at the *****ed line. This is not very nice,
because if t.set is declared as 'taking the ownership' and the caller
doesn't give the ownership, vala shall panic.

Instead of a panic, what vala will do, is to
 (1) for a referable entity, obtain a new reference of it. 
 (2) for a non-referable entity, panic if it is not a string; copy it if
it is a string.

the current solution already breaks the consistency in generics. 
The rule (2) is even more inconsistent(to me). This is where I didn't
feel comfortable. And finally I find it. 

What I would suggest is to
 (a) abandon not passing ownership to a ownership taking function.
(consistent with generics)
 or (b) always panic when a non-referable entity is passed to a
ownership taking function. (avoiding the mutable string assumption)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]