Pharo: #( $H $e $l $l $o ).'Hello' has no example in Finder

Viewed 78

When I go to the finder and select "Examples" then I can't figure out how to find a method that turns #( $H $e $l $l $o ). into 'Hello'. Nor does MethodFinder new findMethodsByExampleInput: #( $H $e $l $l $o ) andExpectedResult: 'Hello'. work.

know how to do it(*), but I want to know how to utilize the Finder.

I guess the Finder simply can't find it? Am I missing something?

(*) For example, one way to do it i: String newFrom: #( $H $e $l $l $o ).. Another way would be: #($H $e $l $l $o) inject: '' into: [ :acc :el | acc, (el asString) ]. (though I would not expect the second way to be found by the Finder)

enter image description here

2 Answers

If you think about it like adding a collection of characters to a string rather than converting a collection to a string you can search for:

'' . #( $H $e $l $l $o ) . 'Hello'

in the Finder and you will get the results:

#( $H $e $l $l $o ) joinUsing: '' -> 'Hello'
'' , #( $H $e $l $l $o ) -> 'Hello'
'' join: #( $H $e $l $l $o ) -> 'Hello'

It can't find it.

Note however that there isn't a method that sent to #($H $e $l $l $o) would answer with 'Hello'. What there exists is a method that sent to String with argument #($H $e $l $l $o) will answer 'Hello'. So, the proper way to using MethodFinder in this case would have been

MethodFinder new
  findMethodsByExampleInput: {String. #( $H $e $l $l $o )}
  andExpectedResult: 'Hello'.

Unfortunately, the #newFrom: method is not explored (most class side methods aren't).

Related