Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

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 ?

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']

"Gert Cuykens" <gert.cuyk@gmail.com> wrote in message

news:ef60af090702081349t41fbf8d5h118b4851a4b5b460@mail.gmail.com...
| def obj():
|    return {'data':'hello',
|                'add':add(v)}

v is undefined

| def add(v):
|    data=data+v

data is undefined

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

test.add is undefined

|    print test.data

test.data is undefined

| 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 ?

I presume you meant 'foregoing' instead of 'following'.  You can do
something similar with nested functions.

Terry Jan Reedy

On 2/8/07, Leif K-Brooks <eurl@ecritters.biz> wrote:

> 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 ?
#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.data);

}

I was thinking something like this maybe ?
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc