bagchi@eecs.umich.edu (Ranjan Bagchi) (11/26/90)
Is there any way I can take a function, such as '+', and
modify it to apply to data-structures (Tagged, I suppose) which it
didn't previously?
I've been screwing around with simulating matrices with nested
lists, and would be much happier if I could multiply 'em with 'x', as
opposed to calling a function called 'mult'.
Ah, well...
-rj
--
--------------------------------------------------------------------------------
Ranjan Bagchi - At Large. Well Kinda. | Neat trick of the day:
bagchi@[eecs | while (1)
caen, | plaid &
math.lsa].umich.edu | end
--------------------------------------------------------------------------------wscott@en.ecn.purdue.edu (Wayne H Scott) (11/26/90)
In article <BAGCHI.90Nov25154728@snarf.eecs.umich.edu> bagchi@eecs.umich.edu (Ranjan Bagchi) writes: > > Is there any way I can take a function, such as '+', and >modify it to apply to data-structures (Tagged, I suppose) which it >didn't previously? > I've been screwing around with simulating matrices with nested >lists, and would be much happier if I could multiply 'em with 'x', as >opposed to calling a function called 'mult'. > > Ah, well... > > -rj You can write your routine called 'mult' that will handle all of the data type you want and then assign that function to the 'x' key with: << prog >> 75 ASN Then put the calculator in user mode and you are all set! -- _______________________________________________________________________________ Wayne Scott | INTERNET: wscott@ecn.purdue.edu Electrical Engineering | BITNET: wscott%ecn.purdue.edu@purccvm Purdue University | UUCP: {purdue, pur-ee}!ecn.purdue.edu!wscott
alexw@cyclops.intel.com (Alex Witkowski) (11/26/90)
In article <BAGCHI.90Nov25154728@snarf.eecs.umich.edu> bagchi@eecs.umich.edu (Ranjan Bagchi) writes: > > Is there any way I can take a function, such as '+', and >modify it to apply to data-structures (Tagged, I suppose) which it >didn't previously? > I've been screwing around with simulating matrices with nested >lists, and would be much happier if I could multiply 'em with 'x', as >opposed to calling a function called 'mult'. > I would suggest that you modify your 'mult' function to check the type of object in the stack using the built-in TYPE function. If it is a list, apply the old 'mult' function, otherwise perform the built-in 'x' function. Then assign this modified function to the 'x' key and activate user-mode. Now, whenever you type 'x' with your lists in the stack, it will perform your 'mult' function and otherwise it will perform the built-in 'x' function. Alex ------------------------------------------------------------------------------- Alex Witkowski Intel Corporation internet: alexw@t12sys.intel.com Santa Clara, CA 95051 uucp: ...!{decwrl|hplabs!oliveb}!intelca!t12sys!alexw
kanecki@vacs.uwp.wisc.edu (David Kanecki) (11/26/90)
an old way to overload operators is to setup a jump table
like in the C language example below:
aft[1]=*mat_mult();
aft[2]=*mat_add();
aft[3]=*mat_inverse();
then re assign the keys to specific locations in the jump table,
or call table. And, to access a function one would use:
aft[1](x,y) { multiply matrix x by y }
David H. Kanecki, Bio. Sci., A.C.S.
kanecki@vacs.uwp.wisc.edu
"Engage....", Capt. Picard, Star-Trek Next Generation