Page 1 of 1
User-defined functions
Posted: 13 Jun 2025, 22:08
by Blissful1911
Hello! I am new to polymake and I do not understand how to define a function. I tried:
Code: Select all
function double($) { return (2*$_); }
and I got:
Code: Select all
polymake: ERROR: syntax error at input line 1, near "; }"
Execution of input aborted due to compilation errors.
Can someone please let me know how to do this?
Re: User-defined functions
Posted: 14 Jun 2025, 09:20
by gawrilow
This way of defining functions is specific to rule files, which are transformed to valid perl when loaded at the start. The input in the interactive shell and scripts are not transformed, they have to be written according to perl standard. There are few extensions allowed like use of type templates, but otherwise it should be pretty much normal perl code.
If you want to introduce a subroutine, just use the `sub` keyword.
Re: User-defined functions
Posted: 15 Jun 2025, 00:27
by Blissful1911
Thank you for the quick response and for the clarification!
I had previously tried normal perl code but I could not make it work due to another issue with my code. The issue was that I had comment lines starting with # in the code of my function; after removing the comment lines the code worked.
This leads me to another question: how can I put comments in my polymake code?
Re: User-defined functions
Posted: 16 Jun 2025, 14:57
by gawrilow
As you can see in various polymake rule and script files, the comments are written in the usual fashion, starting with #.
Maybe you can post a minimal example of your input which is rejected by polymake, together with the error message you are receiving?
Re: User-defined functions
Posted: 18 Jun 2025, 15:52
by Blissful1911
Well, I am stumped! After cleaning up my code, I reintroduced comment lines preceded by # and everything appears to be working fine. This suggests I had something else that was causing issues, but I do not have the previous code anymore so I cannot say what exactly. Apologies, and thank you for your patience in addressing these basic questions.