nimpy icon indicating copy to clipboard operation
nimpy copied to clipboard

Mark `callMethod` as `discardable`

Open LemonBoy opened this issue 7 years ago • 6 comments

In order to avoid a slew of useless discard I'd suggest to mark the callMethod returning a PyObject as discardable.

LemonBoy avatar Aug 08 '18 10:08 LemonBoy

I'd really try to avoid discardable as long as possible and would welcome other solutions, like passing ret typedesc to the function. I'd like to hear more complaints before adding discardable to the public interface about which I will regret after some time but will not be able to revert it without breaking.

yglukhov avatar Aug 08 '18 11:08 yglukhov

Hmm, what I really meant was to have .() as discardable since that'd be a great improvement from an ergonomic point of view.

I wholeheartedly agree that putting discardable is a code smell.

LemonBoy avatar Aug 10 '18 14:08 LemonBoy

what I really meant was...

Yes, that's precisely how I understood it. But is this a real problem though? Why would anyone want to call lots of python from nim?

yglukhov avatar Aug 14 '18 15:08 yglukhov

I implement some python code using nimpy e.g. https://github.com/explosion/spaCy to support and test my nim code. Also other modules which are not available in nim I call from python. I think it's not a real problem but would be nice to have.

ghost avatar Aug 14 '18 16:08 ghost

Why would anyone want to call lots of python from nim

Because of Matplotlib and Seaborn :)

LemonBoy avatar Aug 14 '18 16:08 LemonBoy

I hope the it is discardable, so the code in nim is just as same as in python.

proc plot_data(data: HistData) =
   if not init_python(): return

   plt.rcParams["font.sans-serif"]=["SimHei"]
   plt.rcParams["axes.unicode_minus"] = false

   plt.title(data.code)
   let vtime = map(0..<data.len, i -> data.get_small_time(i))
   set_xaxis(vtime, 8)
   let fig = plt.figure(data.code)
   fig.autofmt_xdate()
   plt.plot(data.vclose)

slangmgh avatar Jan 31 '19 11:01 slangmgh