Post Reply 
How to use Python syntax ?
12-12-2019, 05:04 AM
Post: #1
How to use Python syntax ?
Hello,

I wanted to try out the Python syntax on the Prime emulator but it's giving me syntax error (see attached image). I'm using the code from this post. I am doing the exact thing he's doing, so I don't know why I'm getting this error.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
12-12-2019, 04:28 PM
Post: #2
RE: How to use Python syntax ?
You did not indent your code correctly (good indentation is mandatory in Python because it's the way to mark programming blocs).
Find all posts by this user
Quote this message in a reply
12-12-2019, 09:33 PM
Post: #3
RE: How to use Python syntax ?
(12-12-2019 04:28 PM)parisse Wrote:  You did not indent your code correctly (good indentation is mandatory in Python because it's the way to mark programming blocs).

Thanks for your reply. The code now runs. I was a little bit skeptical initially about how much of python structures is supported, but I've been pleasantly surprised that most things work with very little tweaking. Like in some places where I need to use something from numpy or scipy, I just replace with the with the corresponding one from the calculator. Really nice.

I would like to ask you two more questions, if you don't mind:

1. Is there a document where I can know exactly which Python syntax is supported and which isn't?

2. Is it possible for me to see the code that gets generated from the python syntax ? This would enable me to see learn programming in the Prime's native language and also see if I can optimize the converted code?
Find all posts by this user
Quote this message in a reply
12-13-2019, 06:12 AM
Post: #4
RE: How to use Python syntax ?
(12-12-2019 09:33 PM)hamorabi Wrote:  I would like to ask you two more questions, if you don't mind:

1. Is there a document where I can know exactly which Python syntax is supported and which isn't?
No. The aim is to support math algorithms in the French curriculum. In short, OOP and advanced strings syntax/commands are not supported.

Quote:2. Is it possible for me to see the code that gets generated from the python syntax ? This would enable me to see learn programming in the Prime's native language and also see if I can optimize the converted code?
Not on the Prime, but you can see the conversion with the xcas(f) command inside Xcas/Xcas for Firefox. I would not recommend to spend too much time trying to optimize the converted code, instead try to optimize the algorithm, or convert it to native code in Xcas. Optimizing interpreted code is often bad because you will tend to write compact code that is difficult to read and maintain and this has sometimes the effect of degrading performances of the corresponding native code.
Find all posts by this user
Quote this message in a reply
12-14-2019, 02:23 AM
Post: #5
RE: How to use Python syntax ?
(12-13-2019 06:12 AM)parisse Wrote:  
(12-12-2019 09:33 PM)hamorabi Wrote:  I would like to ask you two more questions, if you don't mind:

1. Is there a document where I can know exactly which Python syntax is supported and which isn't?
No. The aim is to support math algorithms in the French curriculum. In short, OOP and advanced strings syntax/commands are not supported.

Quote:2. Is it possible for me to see the code that gets generated from the python syntax ? This would enable me to see learn programming in the Prime's native language and also see if I can optimize the converted code?
Not on the Prime, but you can see the conversion with the xcas(f) command inside Xcas/Xcas for Firefox. I would not recommend to spend too much time trying to optimize the converted code, instead try to optimize the algorithm, or convert it to native code in Xcas. Optimizing interpreted code is often bad because you will tend to write compact code that is difficult to read and maintain and this has sometimes the effect of degrading performances of the corresponding native code.

Thank you very much for your assistance. I have one last question if it's not already too much. How can I make some of my functions private? I am writing something that requires a lot of sub functions and I don't want them to be visible from anywhere except by other functions defined inside the same program/file.
Find all posts by this user
Quote this message in a reply
12-14-2019, 08:40 AM (This post was last modified: 12-14-2019 08:45 AM by StephenG1CMZ.)
Post: #6
RE: How to use Python syntax ?
In actual Python the syntax would be
Code:

  Def max
     def max2
       Return
      Return
So that max2 is only visible within max.

But I don't know if that would work here.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
12-15-2019, 07:02 AM
Post: #7
RE: How to use Python syntax ?
It's not supported by the parser, CAS programs are always visible. However, CAS algebraic functions can be local to another program.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)