On Wed, 20 Jan 2010, Viktor Kerkez wrote:

Hi,

Since this is my first post on the list, first I want to thank you all for
the great job you're doing on Pharo :) It was a real revelation when I
discovered it :)

Now to the question:

I'm reading the Pharo by Example, and came to this part:

The problem with deepCopy is that it will not terminate when applied to a
mutually recursive structure:
a1 := { 'harry' }.
a2 := { a1 }.
a1 at: 1 put: a2.
a1 deepCopy ˙˙! ... does not terminate!

Use #veryDeepCopy. #deepCopy doesn't support object graphs with circles. Note that you can't use objects with recursive graphs in an environment which sends #hash to the objects (like sets, dictionaries, or a workspaces), because collections' hash calculation doesn't work if the object graph is recursive.
Example:
This works in a workspace:

| a b c |
a := { 1 }.
b := { a }.
a at: 1 put: b.
c := a veryDeepCopy.

But this doesn't:

a := { 1 }.
b := { a }.
a at: 1 put: b.
c := a veryDeepCopy.

There are other things you can't do with such objects, like printing.


(Pharo actually get stuck at the step: a1 at: 1 put: a2. but that's not the
question :) )

1. Isn't this behaviour (the complete environment get stuck and there is no
way to unfreeze it) considered a bug? I mean the environment shouldn't let
you shoot yourself in the foot (at least not so easily). Actually the same
behaviour can be created just doing: [true] whileTrue: []...

2. Shouldn't Pharo recognize recursive structures in some way?


I'm asking because I'm coming from a Python world, which is very similar to
smalltalk in some manners and I'm trying to make a big picture comparison in
my head.

1. I know that this doesn't really compares to Pharo which is a graphical
environment, but in python you can always hit Ctrl-C and break the
statements that block...

If Alt/Cmd + . doesn't work, then something went really wrong.


while True:
...     pass
...
^CTraceback (most recent call last):
 File "<stdin>", line 1, in <module>
KeyboardInterrupt


Shouldn't the UI thread always be responsive?


No.

2. And Python recognizes recursive structures:

a = []
a
[]
a.append(5
...
KeyboardInterrupt
a = []
a
[]
a.append(5)
a
[5]
a.append(a)
a
[5, [...]]
a[0]
5
a[1]
[5, [...]]
a[1][1][1][1][0]
5



Don't get me wrong, I'm not trying to start a language war :) I wouldn't got
to page 171 if I'm not really interested in Smalltalk :-D I'm just trying to
get a clearer vision if these are some things that are there for some reason
(design decision), or they are just not yet implemented, or they cannot be
implemented for some other reasons?


Since the current code doesn't handle recursive structures, there's
probably none in the image, and it still works. This makes me think that recursive structures are not that important in smalltalk. Fixing all the issues properly and without performance penalty may take a lot of effort.


Levente


Thank you in advance for your time :),
Viktor
_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to