What’s involved here amounts to rather more than just throwing in an explicit ‘get’, Adam (although that can sometimes help).
Compound, single-line statements demand even greater care and understanding than more conventional syntax forms. One common cause of confusion is to do with different AppleScript classes and whether or not they’re evaluated implicitly (through, for example, attributing them to a variable - or performing a supplementary operation, such as concatenation).
In this case, the expression partone’s name actually refers to a property (of the alias represented by the variable partone) - rather than to a text value. It needs to be evaluated before a meaningful text comparison can be made. How that evaluation is best invoked can depend on the context of the comparison[s] involved.
Had my example been written more conventionally, it might have looked something like this:
tell application "Finder"
set nameone to partone's name
set parttwo to first folder of partone's container whose name contains "%" and name contains nameone
end tell
This works, because the act of setting the variable nameone results in the evaluation of partone’s name property. So the one-line version, which omits the ‘set’ (and therefore the implicit ‘get’), requires an explicit ‘get’.
Some initial confusion may also have arisen about the phrasing of multiple comparisons. I suppose the English-like nature of the language can sometimes lead us to assume that AppleScript might actually understand statements like [x is y or z] or [x contains y or z] - when we really need to supply two values for each comparison: [x is y or x is z] or [x contains y or x contains z].
That aside, you were all very close to coming up with a cleaner solution.
My suggestion would, of course, return the first item of folders with names like “%somename”, “somename%”, “% a variation of somename”, “another variation of somename%” - or even “These versions of somename don’t work 100% yet…”. However, if Parrot wanted to find only a folder named either “%somename” or “somename%”, then your suggestions were on the right track - except that they could work (as a one-liner) like this:
tell application "Finder" to set parttwo to first folder of partone's container whose name is "%" & partone's name or name is partone's name & "%"
So how does that get around the need for an explicit ‘get’?
Simply because both comparisons involve the concatenation of a text value (“%”) with the property partone’s name - which must therefore be evaluated to complete the operation.
Note, though, that this form makes more than one external Finder call, just to get the same value (partone’s name). A more efficient method would be to make just one call - and then store the result in another variable:
tell application "Finder"
set nameone to partone's name
set parttwo to first folder of partone's container whose name is "%" & nameone or name is nameone & "%"
end tell
As anyone who knows me can attest, I love a good one-liner. But sometimes, they can be more trouble than they’re really worth…
If in doubt, break it down.