bendudson / py4cl

Call python from Common Lisp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to send float as Decimal

sebasmonia opened this issue · comments

I use py4cl to communicate with AWS' boto3, and for float numbers they expect Decimal, not float.

A way to override some data types in general could be useful, although I would only use it for this case, and no one else has asked for it, so maybe there is no demand...

One way I imagine you could achieve that is by implementing a custom lisp class/structure and extend py4cl::pythonize method on that structure; some examples in writer.lisp could be helpful. That can handle sending the correct data from lisp to python.

However, from python to lisp, if this is needed, one needs to convert the python object to the appropriate lisp object. On py4cl2, I recently implemented *lispifiers* and with-lispifiers that use typep checks to do the lispification; so one can define a satisfies type and proceed accordingly. However, because this is a recently added feature, I make no claims about its long-term stability. This might also be portable to py4cl once it is deemed stable.

Thanks to your comments @digikar99 I made a couple changes in a fork that cover my use case: https://github.com/sebasmonia/py4cl/commits/master

Thank you for your help!

Thanks to you too! That looks like a good way to introduce customizable pythonizers. I hope to write the generic version some time. These could perhaps be pulled into py4cl once tested for a while.