<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<br>
<br>
<div class="moz-cite-prefix">On 6/12/24 3:56 PM, Mark Volkmann via
Cuis-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAFfRWnUUAfAuFLz4qCBxXcThXi8K+yiN4gHATpXT00Dat499OA@mail.gmail.com">
<pre class="moz-quote-pre" wrap="">I saw this example in a YouTube video about Smalltalk this morning:
(2 > 3) ifTrue: ['Yes'] ifFalse: ['No']
It seems to me that none of the parentheses or square brackets are needed
here.
The following works the same for me.
2 > 3 ifTrue: 'Yes' ifFalse: 'No'
Is it true that keyword messages that take no-arg blocks can always take a
literal value instead?
It seems this works because the `Object` class defines the `value` method
to just return `self`.
</pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
</blockquote>
You are right.<br>
<br>
AFAIK, not every Smalltalk has a Object>>#value method that
returns self.<br>
This works with Squeak, Cuis and perhaps Pharo.<br>
<br>
The byte-code generated for:<br>
<br>
<pre class="moz-quote-pre" wrap="">2 > 3 ifTrue: 'Yes' ifFalse: 'No'
57 <77> pushConstant: 2
58 <21> pushConstant: 3
59 <B3> send: >
60 <22> pushConstant: 'Yes'
61 <23> pushConstant: 'No'
62 <F0> send: ifTrue:ifFalse:
63 <7C> returnTop
</pre>
<br>
is less efficient than the byte-code for<br>
<br>
<pre class="moz-quote-pre" wrap="">2 > 3 ifTrue: [ 'Yes' ] ifFalse: [ 'No' ]</pre>
<tt>57 <77> pushConstant: 2</tt><tt><br>
</tt><tt>58 <22> pushConstant: 3</tt><tt><br>
</tt><tt>59 <B3> send: ></tt><tt><br>
</tt><tt>60 <99> jumpFalse: 63</tt><tt><br>
</tt><tt>61 <21> pushConstant: 'Yes'</tt><tt><br>
</tt><tt>62 <90> jumpTo: 64</tt><tt><br>
</tt><tt>63 <20> pushConstant: 'No'</tt><tt><br>
</tt><tt>64 <7C> returnTop</tt><br>
<br>
<br>
You might notice that sends of #ifTrue:ifFalse: are compiled<br>
to byte-code-jumps , if they contain literal blocks:<br>
<br>
<br>
<tt>| yesBlock noBlock |</tt><tt><br>
</tt><tt>yesBlock := [ 'Yes' ].</tt><tt><br>
</tt><tt>noBlock := [ 'No' ].</tt><tt><br>
</tt><tt>2 > 3 ifTrue: yesBlock ifFalse: noBlock</tt><tt><br>
</tt><tt><br>
</tt><tt>57 <8F 00 00 02> closureNumCopied: 0 numArgs: 0 bytes
61 to 62</tt><tt><br>
</tt><tt>61 <20> pushConstant: 'Yes'</tt><tt><br>
</tt><tt>62 <7D> blockReturn</tt><tt><br>
</tt><tt>63 <68> popIntoTemp: 0</tt><tt><br>
</tt><tt>64 <8F 00 00 02> closureNumCopied: 0 numArgs: 0 bytes
68 to 69</tt><tt><br>
</tt><tt>68 <21> pushConstant: 'No'</tt><tt><br>
</tt><tt>69 <7D> blockReturn</tt><tt><br>
</tt><tt>70 <69> popIntoTemp: 1</tt><tt><br>
</tt><tt>71 <77> pushConstant: 2</tt><tt><br>
</tt><tt>72 <23> pushConstant: 3</tt><tt><br>
</tt><tt>73 <B3> send: ></tt><tt><br>
</tt><tt>74 <10> pushTemp: 0</tt><tt><br>
</tt><tt>75 <11> pushTemp: 1</tt><tt><br>
</tt><tt>76 <F2> send: ifTrue:ifFalse:</tt><tt><br>
</tt><tt>77 <7C> returnTop</tt><br>
<br>
<br>
@Juan: If just found that stepping <b>through</b> this expression <br>
in the debugger does not work with Cuis/Haver version 6350.<br>
Please try it and see for yourself.<br>
<br>
<br>
HTH,<br>
<br>
Gerald<br>
<br>
<br>
<br>
</body>
</html>