Path: news.cs.au.dk!not-for-mail From: Flemming Gram Christensen Newsgroups: comp.lang.beta Subject: Re: Function call? Date: 31 May 2000 12:54:33 +0200 Organization: University of Aarhus, Department of Computer Science (DAIMI) Lines: 138 Message-ID: References: <39350C6D.3AF68913@skynet.be> NNTP-Posting-Host: odin.mjolner.dk X-Trace: xinwen.cs.au.dk 959770476 16091911 255.255.255.255 (31 May 2000 10:54:36 GMT) X-Complaints-To: news@cs.au.dk NNTP-Posting-Date: 31 May 2000 10:54:36 GMT X-Newsreader: Gnus v5.7/Emacs 20.4 Xref: news.cs.au.dk comp.lang.beta:12371 Atle writes: > Hello, good helpers! > > I got everything so far to go OK, but I am having trouble figuring out the 'function call' syntax. > I am sure it is simpler than what I'm used to, and that is why I can't figure it out ... > > Let struct person be the way it was, name, addr, tlf. > OK: Person:(# name,addr,tlf:^Text #); > >From C > > /* > * Instantiate an object of type person. > * The name will be filled in, the rest will be default > * values (inherited?) > * The C way is to either build up structs or > * pass in a subclass pointer > */ > struct person *new_person(char* name) > { > struct person *prv; /* A dynamic reference? */ > > prv = malloc(sizeof(struct person)); /* Create a dynamic instance? */ > if ( ! prv) > { > perror("malloc"); > return(0); /* Spoiled with automatic casting, should be (struct person*) 0 */ > } > > strcpy(prv->name, name); /* Person has this name from input parm */ > strcpy(prv->addr, sc->addr); /* Don't bother with this now */ > strcpy(prv->tlf, "000"); /* Call the police */ > > return(prv); /* Imperative :-) that I understand enter and exit */ > } in BETA: new_person: (# name:^text; p:^Person; enter name[] (* this is the parameter *) do &person[]->p[]; name.copy->p.name[]; (* copy name into p.name *) ''->p.addr[]; (* empty addr *) '112'->p.tlf[]; (* call police in EU *) exit p[] #); > > void person_set(struct person *p, char *name, char *addr, char* tlf) > { > if (name) > strcpy(p->name, name); > > if (addr) > strcpy(p->addr, addr); > > if (tlf) > strcpy(p->tlf, tlf); > } person_set: (# name,addr,tlf:^text; p:^Person; enter (p[],name[],addr[],tlf[]) do (if name[]<>none then name.copy->p.name[] if); (if addr[]<>none then addr.copy->p.addr[] if); (if tlf[]<>none then tlf.copy->p.tlf[] if); #); > > int not_person_related(char *s) > { > s[0] = 'X'; > return(12); > } not_person_related: (# s:^text; enter s[]; do ('X',1)->s.inxPut (* count from 1 *); exit 12 #); > > void main(int ac, char *av[]) > { > struct person *p; > int x, y; > char s[25]; > > p = person_new("Newman"); > if ( ! p) > exit(0); > > person_set(p, 0, "Hovden", "3716 8532"); > /*-------- So far, so good. These are typically 'object' functions ---*/ > > > /* But what with this? */ > > x = not_person_related(s); > x = not_person_related(p->tlf); > } --program:descriptor-- (# p:^Person; x,y:@integer; s:@text; do 'Newman'->person_new->p[]; (p[],none,'hovden','3141 3123')->person_set; s[]->not_person_related->x; p.tlf[]->not_person_related->y; #); Regards. -- /Flemming Gram Christensen ------------------------------------------------------------------------ Mjolner Informatics ApS Phone: +45 86 20 20 00 Science Park Aarhus Fax: +45 86 20 12 22 Gustav Wieds Vej 10 DK-8000 Aarhus C Denmark E-mail: gram@mjolner.dk ------------------------------------------------------------------------