Skip to content

Commit

Permalink
fixed order of iterator.coffee placement in Makefile, added __le__, _…
Browse files Browse the repository at this point in the history
…_lt__, and __iter__ to List
  • Loading branch information
Onur Karaman committed Mar 31, 2012
1 parent dd8a614 commit 498ef56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ doc:
docco src/node/*.py src/builtin/*.coffee

subset:
coffee -cpbj $(BASE) $(BUILTIN)/number.coffee $(BUILTIN)/float.coffee $(BUILTIN)/integer.coffee $(BUILTIN)/bool.coffee $(BUILTIN)/iterable.coffee $(BUILTIN)/sequence.coffee $(BUILTIN)/string.coffee $(BUILTIN)/list.coffee $(BUILTIN)/mapping.coffee $(BUILTIN)/set.coffee $(BUILTIN)/iterator.coffee $(BUILTIN)/dictionary-keyiterator.coffee $(BUILTIN)/dictionary-valueiterator.coffee $(BUILTIN)/dict.coffee > $(PERSEUS)
coffee -cpbj $(BASE) $(BUILTIN)/number.coffee $(BUILTIN)/float.coffee $(BUILTIN)/integer.coffee $(BUILTIN)/bool.coffee $(BUILTIN)/iterable.coffee $(BUILTIN)/sequence.coffee $(BUILTIN)/string.coffee $(BUILTIN)/list.coffee $(BUILTIN)/mapping.coffee $(BUILTIN)/set.coffee $(BUILTIN)/iterator.coffee $(BUILTIN)/listiterator.coffee $(BUILTIN)/dictionary-keyiterator.coffee $(BUILTIN)/dictionary-valueiterator.coffee $(BUILTIN)/dict.coffee > $(PERSEUS)

setset:
coffee -cpbj $(BASE) $(BUILTIN)/iterable.coffee $(BUILTIN)/sequence.coffee $(BUILTIN)/list.coffee $(BUILTIN)/mapping.coffee $(BUILTIN)/set.coffee $(BUILTIN)/iterator.coffee $(BUILTIN)/dictionary-keyiterator.coffee $(BUILTIN)/dictionary-valueiterator.coffee $(BUILTIN)/dict.coffee > $(PERSEUS)
Expand Down
23 changes: 21 additions & 2 deletions src/builtin/list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,38 @@ class List extends Sequence
# **Unimplemented**
__getslice__: (leftIndex, rightIndex) ->

# http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch14s04.html
# REFERENCE: list_richcompare in http://hg.python.org/cpython/file/387dcd8d7dec/Objects/listobject.c
__gt__: (otherList) ->
minLength = Math.min(len(@).value, len(otherList).value)
for index in [0...minLength]
element = @__getitem__(new Int(index))
otherElement = otherList.__getitem__(new Int(index))
if (type(element) != type(otherElement))
if (type(element) != type(otherElement)) #should really be issubclass(broken)
nameIsGreater = element.__class__().__name__() > otherElement.__class__().__name__() # if types don't match, compare type names
return new Bool(nameIsGreater)
else if element.__ne__(otherElement).value
return element.__gt__(otherElement)
return len(@).__gt__(len(otherList))

__le__: (otherList) ->
return new Bool(not @__gt__(otherList).value)

# REFERENCE: list_richcompare in http://hg.python.org/cpython/file/387dcd8d7dec/Objects/listobject.c
__lt__: (otherList) ->
minLength = Math.min(len(@).value, len(otherList).value)
for index in [0...minLength]
element = @__getitem__(new Int(index))
otherElement = otherList.__getitem__(new Int(index))
if (type(element) != type(otherElement)) #should really be issubclass(broken)
nameIsLess = element.__class__().__name__() < otherElement.__class__().__name__() # if types don't match, compare type names
return new Bool(nameIsLess)
else if element.__ne__(otherElement).value
return element.__lt__(otherElement)
return len(@).__lt__(len(otherList))

__iter__: ->
return new ListIterator(@)

__ne__: (otherList) ->
return new Bool(not @__eq__(otherList).value)

Expand Down

0 comments on commit 498ef56

Please sign in to comment.