TheTrowser
TheTrowser

Reputation: 383

smalltalk returning string from block in VisualWorks

I want to return the value, that was passed int to the block. If it's a number, everything works great, but If I put in a String or boolean value, I get a "Message not understand".

q := [ :a | a].
Transcript show: ((q value:'123') value) printString.

I thought everything is treated the same, so I'm confused. But I guess I'm just missing something.

edit: it seem to work under Pharo...

Upvotes: 0

Views: 321

Answers (3)

Sean DeNigris
Sean DeNigris

Reputation: 6390

Remove the send of #value. It is not necessary for your example as you described it. #value: is sent to the Block, which returns the argument, as you wanted. You then send #value to the argument, which works in Pharo because it returns self and is essentially a non-op.

This fixes your error because, as I suspected and David verified, VisualWorks Strings DNU #value.

n.b. As Bob said, the key missing info in your question is "Which object DNU which message?" In general, the more specific you are about your errors, the better the answers can be.

Upvotes: 1

David Buck
David Buck

Reputation: 2847

The message "value" isn't implemented for Object in VisualWorks. Some applications add it in but it's not in the base class library. In some versions of VisualWorks it slipped into the base class library and was later taken out.

If you write your code like this it will work:

q := [ :a | a].
Transcript show: (q value:'123') printString.

Upvotes: 2

Bob Nemec
Bob Nemec

Reputation: 511

Works fine for me.

| q |
q := [ :a | a].
Transcript show: ((q value: true) value) printString.

| q |
q := [ :a | a].
Transcript show: ((q value: 123) value) printString.

If you have a DNU exception you will be able to see which object is receiving the message that is not understood. Post that information.

Upvotes: 0

Related Questions