Explorar el Código

- renamed Array 'adding' protocol to 'adding/removing'
- fixed Array >> #removeLast:

Nicolas Petton hace 11 años
padre
commit
8435eade7c
Se han modificado 3 ficheros con 49 adiciones y 18 borrados
  1. 16 5
      js/Kernel-Collections.deploy.js
  2. 26 10
      js/Kernel-Collections.js
  3. 7 3
      st/Kernel-Collections.st

+ 16 - 5
js/Kernel-Collections.deploy.js

@@ -1855,9 +1855,9 @@ selector: "removeLast",
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-self._remove_(self._last());
+self._subclassResponsibility();
 return self}, function($ctx1) {$ctx1.fill(self,"removeLast",{},smalltalk.SequenceableCollection)})},
-messageSends: ["remove:", "last"]}),
+messageSends: ["subclassResponsibility"]}),
 smalltalk.SequenceableCollection);
 
 smalltalk.addMethod(
@@ -2145,6 +2145,17 @@ return self}, function($ctx1) {$ctx1.fill(self,"removeFrom:to:",{aNumber:aNumber
 messageSends: []}),
 smalltalk.Array);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "removeLast",
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self.pop();;
+return self}, function($ctx1) {$ctx1.fill(self,"removeLast",{},smalltalk.Array)})},
+messageSends: []}),
+smalltalk.Array);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "reversed",
@@ -2443,12 +2454,12 @@ smalltalk.CharacterArray);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "remove:",
-fn: function (anObject){
+selector: "remove:ifAbsent:",
+fn: function (anObject,aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 self._errorReadOnly();
-return self}, function($ctx1) {$ctx1.fill(self,"remove:",{anObject:anObject},smalltalk.CharacterArray)})},
+return self}, function($ctx1) {$ctx1.fill(self,"remove:ifAbsent:",{anObject:anObject,aBlock:aBlock},smalltalk.CharacterArray)})},
 messageSends: ["errorReadOnly"]}),
 smalltalk.CharacterArray);
 

+ 26 - 10
js/Kernel-Collections.js

@@ -2093,7 +2093,7 @@ smalltalk.SequenceableCollection);
 smalltalk.addMethod(
 smalltalk.method({
 selector: "addLast:",
-category: 'adding',
+category: 'adding/removing',
 fn: function (anObject){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
@@ -2458,15 +2458,15 @@ smalltalk.SequenceableCollection);
 smalltalk.addMethod(
 smalltalk.method({
 selector: "removeLast",
-category: 'adding',
+category: 'adding/removing',
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-self._remove_(self._last());
+self._subclassResponsibility();
 return self}, function($ctx1) {$ctx1.fill(self,"removeLast",{},smalltalk.SequenceableCollection)})},
 args: [],
-source: "removeLast\x0a\x09self remove: self last",
-messageSends: ["remove:", "last"],
+source: "removeLast\x0a\x09self subclassResponsibility",
+messageSends: ["subclassResponsibility"],
 referencedClasses: []
 }),
 smalltalk.SequenceableCollection);
@@ -2862,6 +2862,22 @@ referencedClasses: []
 }),
 smalltalk.Array);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "removeLast",
+category: 'adding/removing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self.pop();;
+return self}, function($ctx1) {$ctx1.fill(self,"removeLast",{},smalltalk.Array)})},
+args: [],
+source: "removeLast\x0a\x09<return self.pop();>",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Array);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "reversed",
@@ -3271,15 +3287,15 @@ smalltalk.CharacterArray);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "remove:",
+selector: "remove:ifAbsent:",
 category: 'adding',
-fn: function (anObject){
+fn: function (anObject,aBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 self._errorReadOnly();
-return self}, function($ctx1) {$ctx1.fill(self,"remove:",{anObject:anObject},smalltalk.CharacterArray)})},
-args: ["anObject"],
-source: "remove: anObject\x0a\x09self errorReadOnly",
+return self}, function($ctx1) {$ctx1.fill(self,"remove:ifAbsent:",{anObject:anObject,aBlock:aBlock},smalltalk.CharacterArray)})},
+args: ["anObject", "aBlock"],
+source: "remove: anObject ifAbsent: aBlock\x0a\x09self errorReadOnly",
 messageSends: ["errorReadOnly"],
 referencedClasses: []
 }),

+ 7 - 3
st/Kernel-Collections.st

@@ -773,14 +773,14 @@ third
 	^self at: 3
 ! !
 
-!SequenceableCollection methodsFor: 'adding'!
+!SequenceableCollection methodsFor: 'adding/removing'!
 
 addLast: anObject
 	self add: anObject
 !
 
 removeLast
-	self remove: self last
+	self subclassResponsibility
 ! !
 
 !SequenceableCollection methodsFor: 'comparing'!
@@ -956,6 +956,10 @@ remove: anObject ifAbsent: aBlock
 
 removeFrom: aNumber to: anotherNumber
 	<self.splice(aNumber - 1,anotherNumber - 1)>
+!
+
+removeLast
+	<return self.pop();>
 ! !
 
 !Array methodsFor: 'converting'!
@@ -1061,7 +1065,7 @@ add: anObject
 	self errorReadOnly
 !
 
-remove: anObject
+remove: anObject ifAbsent: aBlock
 	self errorReadOnly
 ! !