Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this fix suitable ? #1

Open
ponyatov opened this issue Jul 2, 2018 · 1 comment
Open

Is this fix suitable ? #1

ponyatov opened this issue Jul 2, 2018 · 1 comment

Comments

@ponyatov
Copy link

ponyatov commented Jul 2, 2018

class SimpleVariable:
    def __init__(self): self._value = ''
    def __lshift__(self,val): self._value = val
    def __repr__(self): return '<%s>' % self._value

I implemented << operator for variable class, it maybe makes code looks better:

def personWithSimpleVariable(Person):
    Person << 'Alpha' ; yield Person
    Person << 'Beta'  ; yield Person
    Person << 'Gamma' ; yield Person

I also return binded variable, not just false like it done in original -- it looks more logical.
In result prints looks like:

P = Var() ; print P
for p in Persons(P): print p
<>
<Alpha>
<Beta>
<Gamma>

First print returns unbinded variable, maybe it should looks differ then binded?

@ponyatov
Copy link
Author

ponyatov commented Jul 2, 2018

More logical, shows unbinded w/o <>:

class Var:
    def __init__(self): self._value = None
    def __repr__(self):
        if self._value: return '<%s>' % self._value
        else: return str(self._value)
None
<Alpha>
<Beta>
<Gamma>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant