On 24 July 2013 18:04, David Korn <[email protected]> wrote:
> cc:  [email protected]
> Subject: Re: [ast-users] _ doesn't refer to the correct object.
> --------
>
>> In this type, I can't think of any way to refer to "obj" from within "x.get".
>> _ should point to "obj" in this context, not "obj.x".
>>
>>     #!/usr/bin/env ksh
>>
>>     typeset -T Type=(
>>         typeset -h 'This will be a property.' x
>>         integer -h 'This will be the backing field for x.' y=5
>>
>>         function x.get {
>>             # Huge problem here because _ refers to x,
>>             # we can't access anything.
>>             ((.sh.value = ++_.y))
>>         }
>>     )
>>
>>     Type obj
>>     print -r "${obj.x}" "${obj.x}" # prints "1 2"
>>
>> The above should be equivalent to the follwing Python code:
>>
>>     #!/usr/bin/env python3
>>
>>     class Type(object):
>>         def __init__(self):
>>             self.y = 5
>>
>>         @property
>>         def x(self):
>>             self.y += 1
>>             return self.y
>>
>>     obj = Type()
>>     print(obj.x, obj.x) # prints "6 7"
>>
>>
>> Or the following C# code:
>>
>>     using System;
>>
>>     namespace Program {
>>         public class Type {
>>             private int y = 5;
>>             public string x {
>>                 get {
>>                     y++;
>>                     return this.y.ToString();
>>                 }
>>             }
>>         }
>>
>>         public class Program {
>>             static int Main(string[] argv) {
>>                 var obj = new Type();
>>                 Console.WriteLine("{0} {1}", obj.x, obj.x); // prints "6 7"
>>                 return 0;
>>             }
>>         }
>>     }
>>
>> --
>> Dan Douglas
>
> I think that python has this right.  This should prnt 6 7.
> I will modify _ so that for types subvariables, it will reference the type.
>
> This way neither _._ or __ is needed.

*protest*

var.__ has a different use case. var.__ is to access the parent of a
variable in a variable tree, let it be a compound variable or nested
type variables.

Ced
-- 
Cedric Blancher <[email protected]>
Institute Pasteur
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to