def obj()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gert Cuykens

    #1

    def obj()

    def obj():
    return {'data':'hello' ,
    'add':add(v)}

    def add(v):
    data=data+v

    if __name__ == '__main__':
    test=obj()
    test.add('world ')
    print test.data

    I don't know why but i have one of does none class c programing style
    moods again. I was wondering if the following was possible without
    using a class ?
  • Leif K-Brooks

    #2
    Re: def obj()

    Gert Cuykens wrote:
    def obj():
    return {'data':'hello' ,
    'add':add(v)}
    >
    def add(v):
    data=data+v
    >
    if __name__ == '__main__':
    test=obj()
    test.add('world ')
    print test.data
    >
    I don't know why but i have one of does none class c programing style
    moods again. I was wondering if the following was possible without
    using a class ?
    def obj():
    result = {'data': 'hello'}
    result['add'] = adder(result)
    return result

    def adder(obj):
    def add(value):
    obj['data'] += value
    return add

    if __name__ == '__main__':
    test = obj()
    test['add']('world')
    print test['data']

    Comment

    • Gert Cuykens

      #3
      Re: def obj()

      On 2/8/07, Leif K-Brooks <eurleif@ecritt ers.bizwrote:
      def obj():
      result = {'data': 'hello'}
      result['add'] = adder(result)
      return result
      >
      def adder(obj):
      def add(value):
      obj['data'] += value
      return add
      >
      if __name__ == '__main__':
      test = obj()
      test['add']('world')
      print test['data']
      Nice :) Does anybody know how this would look in c code ?

      Comment

      • Gert Cuykens

        #4
        Re: def obj()

        #include <stdio.h>

        function hello(){
        struct obj = { char *data = 'hello'}
        obj.add = obj_add(obj);
        return obj;
        }

        function obj_add(obj){
        function add(value){
        obj.data += value;
        return obj;
        }
        }

        main(){
        test = hello();
        test.add('world ');
        printf(test.dat a);
        }

        I was thinking something like this maybe ?

        Comment

        Working...