What happens when creating a string in smalltalk?

I am a Noobey in Smalltak, but I need to understand some things for my thesis. What exactly happens when creating a string or any other object? For example, let's do the following:

fruit <- 'apple'

When I try to check the fruit object, I see that it has 5 inst vars. If I prescribed a “pear” to the fruit, she would have 4 instances. Thus, the interpreter created a new instance of bytestring, added the necessary inst vars for each character and assigned them the correct values? I believe that there is something else, but I cannot find it anywhere, and I do not have time to learn smalltalk correctly. Can you explain this to me or give me a link where I can find it?

+3
source share
4 answers

- . . Smalltalk : (, Person), . .

:

fruit := String new: 5.
fruit at: 1 put: $a;
    at: 2 put: $p;
    at: 3 put: $p;
    at: 4 put: $l;
    at: 5 put: $e.

5 . fruit, . 5 . "apple" .

, .

fruit := 'apple'

"apple" . Smalltalk . , "apple" , 5 , .

+5

, , , .

, Smalltalk, , , .

, :

'Good Morning' at: 3.
#(1 'hi' $d 5.34) at: 3.

'Good Morning' fourth.
#(1 'hi' $d 5.34) fourth.

'Good Morning' reversed.
#(1 'hi' $d 5.34) reversed.

'Good Morning' select: [ :each | each ~= $d ].
#(1 'hi' $d 5.34) select: [ :each | each ~= $d ].

, - .

+4

- , , , ""...

+3

, , , . .

fruit := 'apple'

does not create a string. It assigns the existing apple string to the variable fruit. If you want to create new lines, you must use (Byte) String new: similar to Array new: ..

This is how the compiler actually creates new lines when compiling the source code.

+3
source

All Articles