smalltalk - Transcript show doesn't work -
i'm making linked list structure pharo smalltalk , , i'm trying print list have overview , used 'transcript show:' method doesn't work prints "an element" (the name of objects in list) on transcript , , when use separately on workspace print '3' or 'hello' example it's works perfectly. have read lot of similar topics , not resolve problem: here code :
printlist |current| current := element newelement: first. [ current == nil ] whilefalse: [ transcript show: (current getvalue); cr. current := current getnext ].
thanks ! :)
it looks code working , tries print element transcript calls elmement>>asstring. since object doesn't implement method, falls inherited object>>asstring method tries clever , uses default pattern generates 'an element'.
the solution simple - implement asstring method in element class:
asstring ^'hello element'
you can smarter this. want make output uniquely identifiable. if element class has 'name' instance variable can use example:
asstring ^(name ifnil: ['(empty)']), ' element'
this print like:
aymane bo element
Comments
Post a Comment