From: Lakshya A A. <lak...@gm...> - 2019-06-22 17:06:24
|
I have added support for the following forms of "for" loops(at Sourceforge Fork <https://sourceforge.net/u/philomath/maxima_translate/ci/translation/tree/share/pytranslate/> ): 1. for variable: initial_value step increment thru limit do body2. for variable: initial_value step increment while condition do body3. for variable: initial_value step increment unless condition do body4. for variable in list do body The form with limit specified is converted to a Python-for loop with range() function. The loop with condition specified is converted to a while loop, and the loop through list is converted to a Python for loop. Example conversions(from rtest_pytranslate.mac <https://sourceforge.net/u/philomath/maxima_translate/ci/translation/tree/share/pytranslate/rtest_pytranslate.mac> ): /*for loop*//* In List */for i in [1,2,3] do print(i)"for i in [1, 2, 3]: print(i)"$ for i in [1,2,3] do (print(i), print(i*2))"for i in [1, 2, 3]: print(i) print((2 * i))"$ /* Initial, increment and limit values specified */for i from 1 step 3 thru 5 do print(i)"for i in range(1, (5 + 1), 3): print(i)"$for i from 1 step 3 thru 5 do (print(i), a:20+i, print(i*a))"for i in range(1, (5 + 1), 3): print(i) a = (20 + i) print((a * i))"$ /* Initial, increment and condition specified *//* while condition */for i:10 step 5 while i*5<70 do (print(i), print(5*i))"i = 10 while not(((5 * i) >= 70)): print(i) print((5 * i)) i = (i + 5) del i"$/* unless condition */ for i:8 step -1 unless i<3 do (print(i))"i = 8 while not((i < 3)): print(i) i = (i + -1) del i"$for i:8 step -1 unless i<3 do print(i)"i = 8 while not((i < 3)): print(i) i = (i + -1) del i"$ Looking forward to the community's guidance and feedback. Regards Lakshya A Agrawal On Thu, 13 Jun 2019 at 14:24, Lakshya A Agrawal <lak...@gm...> wrote: > pytranslate(' (for i:1 thru 10 do f(i)) ); >> does not work. returns >> "DO(I, 1, None, None, 10, None, F(I))" > > Sir, I have not yet implemented translation for loops. I will post an > update once that is done. > > It would be interesting to me if one could do this in Maxima... >> >> say P is a string that is a Python function definition for >> a function F that takes particular arguments , does some >> computation (perhaps with side effects) and returns >> a value. Then to have a maxima command >> > Regarding this, and the discussion about CL-Python, maybe, if there is a > consensus in the community, I could explore it upon the completion of the > current project, i.e., to make a Maxima to Python Translator. > > I appreciate everyone's feedback and look forward to further guidance. > > Regards > Lakshya A Agrawal > > On Thu, 13 Jun 2019 at 11:58, Elias Mårtenson <lo...@gm...> wrote: > >> On Thu, 13 Jun 2019 at 12:01, Richard Fateman <fa...@be...> >> wrote: >> >>> >>> = >>> According to the documentation, CLPython works in many >>> different lisps... maybe running arbitrary Python code >>> without leaving Maxima can be simply achieved. >>> >>> Lots of neat code is in the Python world. >>> >> >> I'm sure there is. I personally am not a huge fan of Python (to say the >> least) so I leave that for others. >> >> I think my original reply was based on a misunderstanding about what >> Richard was asking about. >> >> Regards, >> Elias >> > |