Re: Question about Check[]
- To: mathgroup
- Subject: Re: Question about Check[]
- From: sdoyle at fed.frb.gov
- Date: Tue, 2 May 89 09:52:32 CDT
[Third in the series on Check[]. -smc] Steve: Do you have any information on when 1.2 is coming out? I don't want to ask you anything for which you would have to break a non-disclosure agreement, but I'm leaving here June 1 and I'd like to know if 1.2 for the Sun might be here before then... You can forward the problem below to the list if you want. If it is fixed in 1.2 please let me know. The two most serious problems (for me) in 1.1 are that CForm[] wasn't working correctly with user-defined objects and that I get segmentation violations when performing assigments " := " nested deeply within large programs. While I can't pin down the latter for a simple example (yet), the formatting problem is reproduced below. The basic problems are: (a) When CForm distributes down the list, it doesn't apply the CForm rule that I defined. (Out[5]) (b) If I use rules to replace the objects, the resulting output doesn't completely evaluate. While Out[6] appears as I desire, FullForm[] shows that the SequenceForm[] expressions have not evaluated. (c) The problem in (b) becomes serious if (for example) I have exponents in the expression. Then I have to evaluate the expression once for my objects, and then once again for the operators surrounding the objects. A workaround for the problem of (c) is to use the function ToString[] in the user-specified CForm rules. This forces these sub-expressions to evaluate the SequenceForm[] function. After CForm is applied to the entire expression there may be embedded quotation (") characters... so I convert the entire statement to a string and then strip out all of the quotation characters. This is slow, and it won't work if one wants to generate C expressions that contain quotation characters..... I'm also curious.... the evaluation problem mentioned in (b) seems to be a violation of the rule that evaluation takes place until there is no change in the expression... but the *Form[] commands operate by different rules than other functions. If this is fixed in 1.2, or if there is a better workaround, please let me know. Thanks! Sean Doyle Board of Governors of the Federal Reserve System 20 and Constitution, NW Mail Stop 76 Washington, DC 20551 (202) 452-2352 uucp: uunet!fed!m1swd00 , internet: sdoyle at fed.frb.gov *************** Session below. *************************** SunMathematica (sun4) 1.1 (September 17, 1988) [With pre-loaded data] by S. Wolfram, D. Grayson, R. Maeder, H. Cejtin, S. Omohundro, D. Ballman and J. Keiper Copyright 1988 Wolfram Research Inc. -- Terminal graphics initialized -- In[1]:= foo/: CForm[foo[x_,y_]]:= SequenceForm[ "readdata( foo,", x , ",", y,")"] In[2]:= foo[1,2] Out[2]= foo[1, 2] In[3]:= CForm[%] Out[3]= readdata( foo,1,2) In[4]:= temp = foo[1,2] + foo[2,3] + foo[3,4] Out[4]= foo[1, 2] + foo[2, 3] + foo[3, 4] In[5]:= CForm[temp] Out[5]//CForm= foo(1,2) + foo(2,3) + foo(3,4) In[6]:= temp /. {foo[x___] -> CForm[foo[x]]} Out[6]= readdata( foo,1,2) + readdata( foo,2,3) + readdata( foo,3,4) In[7]:= FullForm[%] Out[7]//FullForm= > Plus[SequenceForm[readdata( foo,, 1, ,, 2, )], > SequenceForm[readdata( foo,, 2, ,, 3, )], > SequenceForm[readdata( foo,, 3, ,, 4, )]] (* Here's the `fix' to force the SequenceForm[] statements to evaluate *) In[8]:= foo/: CForm[foo[x_,y_]]:= ToString[SequenceForm[ "readdata( foo,", x , ",", y,")"]]