GithubHelp home page GithubHelp logo

cs173-python's People

Contributors

jpolitz avatar nmalkin avatar sumnerwarren avatar

Watchers

 avatar  avatar  avatar

cs173-python's Issues

Store passing issue in let?

Let seems to not be producing a store with the right mutations, but maybe we can just ignore this........ I took out the thing where we use Let to pre-define a function for recursion because we can now do that with pulling up.

Prevent assignment to __class__ field

In "real" Python, it produces the error TypeError: __class__ assignment: only for heap types.

Even if we choose to represent the __class__ as a string (rather than as a Type class), we should probably disallow this assignment. (Because there's a good chance we'll be relying on __class__ for type-checking.)

Another minor exception issue and workaround

Exceptions don't seem to bust out of try blocks.
This code gives an unmatched case error when StopIteration is raised:

    try:
        if has_length and self.i >= len(self.l):
            raise StopIteration("Stop")
        ret = self.l[self.i]
    except IndexError:
         raise StopIteration("Stop")

But this fixes it:

    try:
        if has_length and self.i >= len(self.l):
            raise StopIteration("Stop")
        ret = self.l[self.i]
    except IndexError:
         raise StopIteration("Stop")
    except StopIteration:
         raise StopIteration("Stop")

I'm pretty sure exceptions are supposed to bust out of the whole block if they aren't caught.

dict.update does not raise expected error

The following assertion fails:

___assertRaises((TypeError, AttributeError), d.update, None)

(from python-reference/dict/dict-update.py)

I'm not sure why. Any thoughts?

Minor exception issue with raising from inside except + workaround

try:
     self.l[500] #raises IndexError
except IndexError:
     raise StopIteration()

Causes a contract violation from an empty list in interp-excepts at line 248 of interp because the code here assumes that the Exception has a string arg, so the workaround is:

try:
     self.l[500] #raises IndexError
except IndexError:
     raise StopIteration("Stop it!")

Mutually recursive methods

We have an issue to be figured out where methods can't seem to call eachother, but I don't know why this ought to be happening. Example:

class C:
def f(self):
self.g()
def g(self):
print("heyyy")

c = C()
c.f()

Gives the error:
AttributeError: object has no attribute 'g'

Generalizing classes vs objects

Objects and classes are the same thing-ish the main difference being what happens when they are in the function application position. With classes we want them to construct in that positions and objects we don't want anything to happen unless call is defined. To generalize this we should out object construction in the call method of a class-object.

Or we could keep them separate.

Semantics of Assign

What are the semantics of Assign?

The AST documentation lists it as

Assign(expr* targets, expr value)

But what does it mean to assign one value to multiple things?

For example, this doesn't work:

x, y = 1

The code blow works, but is this something that should happen in the core or in desugaring? And, technically, it's assigning one thing to one thing (tuple to tuple).

x, y = 1, 2

On a related note, the current desugaring of PyAssign doesn't type-check.

Discourse on the Origin of Equality

We talked about implementing comparisons such that new builtins only need to implement cmp but I want to implement eq in Object to basically call racket's eq? which means that subclasses will need to implement eq themselves to override that in addition to cmp which shouldnt be much trouble but if you have a better way let me know.

Distinguish ints and floats

Right now, there's just one num type, but int and float have a number of different behaviors (e.g., division, mod, constructors, and as arguments to sequence-multiplication).

Tuple(/list) comparisons, wtf?

class A:
    @classmethod
    def cm(cls):
        print(cls)
        return (cls, 'A')

A2=A().cm()[0]
print(A2==A) # True
print((A2)==(A)) # True
print(('A')==('A')) # True
print(('A','A')==('A','A')) # True
print(('B','A')==('B','A')) # True
print((A2,'A')==(A,'A')) # False
print((A2,A2)==(A,A)) # False

Use make-builtin-numv in primitives.rkt

Our primitive number operations in python-primitives.rkt all manually build vobjects of type num, but i've since added int/float classes. We might need to replace some of these calls with make-builtin-numv which figures out of the number is float or int and assigns the right class.

An Inconvenient Truthiness

http://docs.python.org/3/library/stdtypes.html#truth-value-testing

Interesting truths from the docs:
-Everything is true by default, so I'm making that the case for our truthy? function in interp.
-bool() is not defined in the base object, this means an object is True if it doesn't define bool or len and False otherwise. This means we need to be able to check for the presence of a field in an object, so I think I'm going to modify get-field in interp to return an optionof (yay!).

For objects this means that I'm going to write an truthiness function that checks the type of mval and treats those appropriately, if it doesn't have an mval then it's going to look for bool or len and return the results from those if it finds them, or otherwise it will just return true.

Think nonlocally, act globally

So for nonlocal and global scope modifiers:

We need separate core constructs: CId, NonLocalCId, GlobalCId. These will have different lookup and assign behaviors: CId looks through the entire Env as normal, NonLocalCId looks at everything above the current frame, and GlobalCId only looks at the topmost frame

In order to construct these during desugaring we have some procedure to descend into a PyFunc to look for nonlocal or global statements. If it finds one then it keeps track of those symbols which are to be considered nonlocal or global for the body of the FunC and when it encounters those IDs it desugars them appropriately rather than as the standard CId.

Improve check-types macro

The check-types macro in util.rkt has several issues.

  1. It spits out mval1 and mval2 which consequently appear, magically, in the body.
  2. It returns none if type-checking fails, in any of a number of cases, making it hard to find out what the actual problem is.

The latter will probably change when we introduce exceptions.

Debug macro

So we don't have to type (begin (display "blah") (dosomething)) all the time.

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.