<div dir="ltr">Yes. I first tried to subclass LinkedList, but I had some trouble with funny behaviours turning up in <span style="font-family: georgia,serif;">do:,</span> although I suppose that has probably been eliminated here by using not trying to use <span style="font-family: georgia,serif;">super do:</span> as I did. (By "funny" I mean ending up calling element on the result of element).<br>
<br><div class="gmail_quote">On Mon, Jul 28, 2008 at 10:04 PM, nicolas cellier <span dir="ltr"><<a href="mailto:ncellier@ifrance.com">ncellier@ifrance.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Marcin Tustin a écrit :<div class="Ih2E3d"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am aware of LinkedList. It does not meet the criterion of accepting items whatever their protocol.<br>
<br>
</blockquote>
<br></div>
You are right, current implementation of LinkedList is very specialized and restricted.<br>
Creating Links transparently would be a plus.<br>
Hey, we can use a Dictionary without being aware of Association!<br>
<br>
I am not aware of such implementation, but wouldn't be surprised it already exists. Rather than a long research, it is easier to DIY.<br>
<br>
I provide an untested quick first implementation as an example.<br>
This implementation uses already existing StackLink transparently.<br>
This could of course be completed with addLink: removeLink: etc...<br>
<br>
Reading code enabled me finding <a href="http://bugs.squeak.org/view.php?id=7136" target="_blank">http://bugs.squeak.org/view.php?id=7136</a><br>
<br>
So a prerequisite is:<br>
Installer mantis ensureFix: 7136.<br>
<br>
Last, as all code I publicly released in Squeak until now, consider this code as MIT. Change it, republish it, sell it or throw it away at will.<br>
<br>
Cheers<br><font color="#888888">
<br>
Nicolas<br>
</font><br>'From Squeak3.10beta of 22 July 2007 [latest update: #7159] on 28 July 2008 at 10:48:46 pm'!<br>
LinkedList subclass: #TransparentLinkedList<br>
instanceVariableNames: ''<br>
classVariableNames: ''<br>
poolDictionaries: ''<br>
category: 'Collections-Sequenceable'!<br>
!TransparentLinkedList commentStamp: 'nice 7/28/2008 21:47' prior: 0!<br>
I represent a collection of links, which are containers for other objects. Using the message sequence addFirst:/removeLast causes the receiver to behave as a stack; using addLast:/removeFirst causes the receiver to behave as a queue.<br>
<br>
Unlike super, users won't see the Link objects, like users of Dictionary do not need to know about Association.<br>
That's why i am called TransparentLinkedList.!<br>
<br>
<br>
!TransparentLinkedList methodsFor: 'adding' stamp: 'nice 7/28/2008 22:47'!<br>
add: anObject after: otherObject<br>
"Add anObject after otherObject in the list. Answer anObject.<br>
If otherObject is not in the list, then raise an error."<br>
<br>
| otherLink |<br>
otherLink := self findLinkFor: otherObject ifAbsent: [^self error: 'otherObject is not in this list'].<br>
super add: (StackLink with: anObject) after: otherLink.<br>
^anObject! !<br>
<br>
!TransparentLinkedList methodsFor: 'adding' stamp: 'nice 7/28/2008 22:47'!<br>
add: anObject before: otherObject<br>
"Add anObject after otherObject in the list. Answer anObject.<br>
If otherObject is not in the list, then raise an error."<br>
<br>
| otherLink |<br>
otherLink := self findLinkFor: otherObject ifAbsent: [^self error: 'otherObject is not in this list'].<br>
super add: (StackLink with: anObject) before: otherLink.<br>
^anObject! !<br>
<br>
!TransparentLinkedList methodsFor: 'adding' stamp: 'nice 7/28/2008 21:54'!<br>
addFirst: anObject<br>
"Add anObject to the beginning of the receiver's list. Answer anObject."<br>
<br>
super addFirst: (StackLink with: anObject).<br>
^anObject! !<br>
<br>
!TransparentLinkedList methodsFor: 'adding' stamp: 'nice 7/28/2008 21:53'!<br>
addLast: anObject<br>
"Add anObject to the end of the receiver's list. Answer anObject."<br>
<br>
super addLast: (StackLink with: anObject).<br>
^anObject! !<br>
<br>
<br>
!TransparentLinkedList methodsFor: 'removing' stamp: 'nice 7/28/2008 22:11'!<br>
remove: anObject ifAbsent: aBlock<br>
"Remove anObject from the receiver. If it is not there, answer the result of<br>
evaluating aBlock."<br>
<br>
| aLink |<br>
aLink := self findLinkFor: anObject ifAbsent: [^aBlock value].<br>
super remove: aLink ifAbsent: aBlock.<br>
^anObject ! !<br>
<br>
!TransparentLinkedList methodsFor: 'removing' stamp: 'nice 7/28/2008 21:55'!<br>
removeFirst<br>
"Remove the first element and answer it. If the receiver is empty, create<br>
an error notification."<br>
<br>
^super removeFirst element! !<br>
<br>
!TransparentLinkedList methodsFor: 'removing' stamp: 'nice 7/28/2008 21:55'!<br>
removeLast<br>
"Remove the first element and answer it. If the receiver is empty, create<br>
an error notification."<br>
<br>
^super removeLast element! !<br>
<br>
<br>
!TransparentLinkedList methodsFor: 'enumerating' stamp: 'nice 7/28/2008 22:12'!<br>
do: aBlock<br>
<br>
self linkDo: [:aLink | aBlock value: aLink element]! !<br>
<br>
!TransparentLinkedList methodsFor: 'enumerating' stamp: 'nice 7/28/2008 22:10'!<br>
findLinkFor: anObject ifAbsent: aBlock<br>
self linkDo: [:aLink | aLink element = anObject ifTrue: [^aLink]].<br>
^aBlock value! !<br>
<br>
!TransparentLinkedList methodsFor: 'enumerating' stamp: 'nice 7/28/2008 22:15'!<br>
linkDo: aBlock<br>
"this could be ^super do: but I dislike sending super with a different message selector"<br>
<br>
| aLink |<br>
aLink := firstLink.<br>
[aLink == nil] whileFalse:<br>
[aBlock value: aLink.<br>
aLink := aLink nextLink]! !<br>
<br>
!TransparentLinkedList methodsFor: 'enumerating' stamp: 'nice 7/28/2008 21:57'!<br>
reverseDo: aBlock<br>
<br>
super reverseDo: [:aLink | aBlock value: aLink element]! !<br>
<br>
!TransparentLinkedList methodsFor: 'enumerating' stamp: 'nice 7/28/2008 21:58'!<br>
species<br>
<br>
^ self class! !<br>
<br>
<br>
!TransparentLinkedList methodsFor: 'accessing' stamp: 'nice 7/28/2008 21:58'!<br>
first<br>
^super first element! !<br>
<br>
!TransparentLinkedList methodsFor: 'accessing' stamp: 'nice 7/28/2008 21:58'!<br>
last<br>
^super last element! !<br>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>