Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!usc!cs.utexas.edu!uunet!ficc!cliff From: cliff@ficc.uu.net (cliff click) Newsgroups: comp.lang.misc Subject: Re: Language Tenets Summary: Forth & structs Message-ID: <5221@ficc.uu.net> Date: 24 Jul 89 15:51:47 GMT References: <57125@linus.UUCP> <1989Jun24.230056.27774@utzoo.uucp> <1430@l.cc.purdue.edu> Organization: Ferranti International Controls Lines: 45 In article <1430@l.cc.purdue.edu>, cik@l.cc.purdue.edu (Herman Rubin) writes: > I know of no language produced with the idea of even > reasonably efficient code which will allow me to add new operator symbols-- > I see now more reason why I should have to write pow(x,y) for x to the y-th > power than you should have to write diff(x,y) for x-y. Even Fortran found > it necessary to invent an infix notation for that. Forth can do this fairly simply. In fact, a great deal of the flexability of Forth stems from it's "roll-your-own" syntax abilities. Forget trying to add infix operators to C or Fortran; they have *way* to much momentum. I think Ada allows you to define new (or redefine existing) infix operators. > A replacement procedure takes the quantities on the right side, performs > the indicated manipulations, and replaces the variables on the left side > by the appropriate values. There is no specification of the order of the > replacement, that the quantities are in any way to have any more cohesion > than just a list, or that at any time there is to be a single machine > entity (other than scattered registers and memory locations) containing > the results. I've posted this idea in comp.lang.c and gotten some good feedback. Maybe you need to hire some compiler writer to stuff this into gnu C. If the people of the C world find this handy, maybe it will start creeping into commercial C compilers. The idea is to basically build a psuedo-structure from disjoint variables, to be structure-assigned from a function (infix or otherwise) which returns a structure. For example, we have: struct foobar { double quo, rem }; struct foobar divrem( double num, denom ); double a, b, c, d; ... struct foobar { a, b } = divrem( c, d ); Here a and b can be replaced with the lvalue of any expression yielding a double, and thus can be used to step through arrays. In my example no foobar structure has storage defined for it. The final usage is merely a language convention to lump together the list of variables that are the result of the divrem function. -- Cliff Click, Software Contractor at Large Business: uunet.uu.net!ficc!cliff, cliff@ficc.uu.net, +1 713 274 5368 (w). Disclaimer: lost in the vortices of nilspace... +1 713 568 3460 (h).