GithubHelp home page GithubHelp logo

Comments (4)

maor10 avatar maor10 commented on May 8, 2024

It's a bit problematic to override __eq__, because of the in keyword.
If I do:

a = iquib(3)
b = [a]
5 in b

I'll receive True- list_contains is a method implemented in C that must return a boolean, and it simply calls __eq__ over and over for its elements with the given argument (in our case 5).
We could do some nasty stuff and forcefully override list's contain method, but as we spoke previously this is essentially different from the overriding we do today- Python purposefully does not allow this. I suggest we use a helper method here.

For reference, the C method:

static int list_contains(PyListObject *a, PyObject *el)
{
	Py_ssize_t i;
	int cmp;

	for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
		cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i), Py_EQ);
	return cmp;
}

from quibbler.

rkishony avatar rkishony commented on May 8, 2024

ok. so no overriding of eq

so, if the user wants to do Q==3 they will do something like:
q(lambda x: x==3, Q)

right? or is there a simpler syntax?

from quibbler.

maor10 avatar maor10 commented on May 8, 2024

We could add a simpler syntax if you'd like- maybe qe(Q, 3) or something of the like (maybe Q.equals(3))? Wdyt?

from quibbler.

rkishony avatar rkishony commented on May 8, 2024

i'm not sure which one is best. and i trust that you know better the python-way of thinking

in general, there are already several functions that we decided not to override, including eq, len, str, ...

so we need some generic way

what I did in Matlab is taking all the problematic-to-overload functions and provide their quib-implementation with a new name starting quib...
for example, I couldn't overload size(), numel(), isempty() because Matlab expects them to return real values, so I offered new functions quibsize(), quibnumel(), quibisempty()

maybe we can do something like that?

note also that right now q(...) is interpreted as a graphic quib (evaluates immediately), so we need some alternative when we would like to apply a user function as a non-graphical functional quib

from quibbler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.