| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<html> |
| 3 |
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ --> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 |
<title>Return Values (GCL TK Manual)</title> |
| 7 |
|
| 8 |
<meta name="description" content="Return Values (GCL TK Manual)"> |
| 9 |
<meta name="keywords" content="Return Values (GCL TK Manual)"> |
| 10 |
<meta name="resource-type" content="document"> |
| 11 |
<meta name="distribution" content="global"> |
| 12 |
<meta name="Generator" content="makeinfo"> |
| 13 |
<link href="index.html" rel="start" title="Top"> |
| 14 |
<link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| 15 |
<link href="General.html" rel="up" title="General"> |
| 16 |
<link href="Argument-Lists.html" rel="next" title="Argument Lists"> |
| 17 |
<link href="Common-Features-of-Widgets.html" rel="prev" title="Common Features of Widgets"> |
| 18 |
<style type="text/css"> |
| 19 |
<!-- |
| 20 |
a.summary-letter {text-decoration: none} |
| 21 |
blockquote.indentedblock {margin-right: 0em} |
| 22 |
div.display {margin-left: 3.2em} |
| 23 |
div.example {margin-left: 3.2em} |
| 24 |
div.lisp {margin-left: 3.2em} |
| 25 |
kbd {font-style: oblique} |
| 26 |
pre.display {font-family: inherit} |
| 27 |
pre.format {font-family: inherit} |
| 28 |
pre.menu-comment {font-family: serif} |
| 29 |
pre.menu-preformatted {font-family: serif} |
| 30 |
span.nolinebreak {white-space: nowrap} |
| 31 |
span.roman {font-family: initial; font-weight: normal} |
| 32 |
span.sansserif {font-family: sans-serif; font-weight: normal} |
| 33 |
ul.no-bullet {list-style: none} |
| 34 |
--> |
| 35 |
</style> |
| 36 |
|
| 37 |
|
| 38 |
</head> |
| 39 |
|
| 40 |
<body lang="en"> |
| 41 |
<span id="Return-Values"></span><div class="header"> |
| 42 |
<p> |
| 43 |
Next: <a href="Argument-Lists.html" accesskey="n" rel="next">Argument Lists</a>, Previous: <a href="Common-Features-of-Widgets.html" accesskey="p" rel="prev">Common Features of Widgets</a>, Up: <a href="General.html" accesskey="u" rel="up">General</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 44 |
</div> |
| 45 |
<hr> |
| 46 |
<span id="Return-Values-1"></span><h3 class="section">1.4 Return Values</h3> |
| 47 |
|
| 48 |
<span id="Widget-Constructor-Return-Values"></span><h4 class="subsection">1.4.1 Widget Constructor Return Values</h4> |
| 49 |
|
| 50 |
<p>On successful completion, the widget constructor functions return the |
| 51 |
symbol passed in as the first argument. It will now have a functional |
| 52 |
binding. It is an error to pass in a symbol which already corresponds |
| 53 |
to a widget, without first calling the <code>destroy</code> command. On failure, |
| 54 |
an error is signalled. |
| 55 |
</p> |
| 56 |
<span id="Widget-Return-Values"></span><h4 class="subsection">1.4.2 Widget Return Values</h4> |
| 57 |
|
| 58 |
<p>The <i>widget</i> functions themselves, do not normally return any value. |
| 59 |
Indeed the lisp process does not wait for them to return, but merely |
| 60 |
dispatches the commands, such as to change the text in themselves. |
| 61 |
Sometimes however you either wish to wait, in order to synchronize, or |
| 62 |
you wish to see if your command fails or succeeds. You request values |
| 63 |
by passing the keyword :return and a value indicating the type. |
| 64 |
</p> |
| 65 |
<div class="example"> |
| 66 |
<pre class="example">(.hello :configure :text "Bye World" :return 'string) |
| 67 |
==> "" |
| 68 |
==> T |
| 69 |
</pre></div> |
| 70 |
<p>the empty string is returned as first value, and the second value |
| 71 |
<code>T</code> indicates that the new text value was successfully set. LISP |
| 72 |
will not continue until the tkclsrv process indicates back that the |
| 73 |
function call has succeeded. While waiting of course LISP will continue |
| 74 |
to process other graphics events which arrive, since otherwise a |
| 75 |
deadlock would arise: the user for instance might click on a mouse, just after |
| 76 |
we had decided to wait for a return value from the <code>.hello</code> function. |
| 77 |
More generally a user program may be running in <b>GCL</b> and be interrupted |
| 78 |
to receive and act on communications from the <samp>gcltksrv</samp> |
| 79 |
process. If an error occurred then the second return value of the |
| 80 |
lisp function will be NIL. In this case the first value, the string |
| 81 |
is usually an informative message about the type of error. |
| 82 |
</p> |
| 83 |
<p>A special variable <code>tk::*break-on-errors*</code> which if not |
| 84 |
<code>nil</code>, requests that that <b>LISP</b> signal an error when a message |
| 85 |
is received indicating a function failed. Whenever a command fails, |
| 86 |
whether a return value was requested or not, <samp>gcltksrv</samp> returns a |
| 87 |
message indicating failure. The default is to not go into the |
| 88 |
debugger. When debugging your windows it may be convenient however to |
| 89 |
set this variable to <code>T</code> to track down incorrect messages. |
| 90 |
</p> |
| 91 |
<p>The <samp>gcltksrv</samp> process always returns strings as values. |
| 92 |
If <code>:return</code> <i>type</i> is specified, then conversion to <i>type</i> |
| 93 |
is accomplished by calling |
| 94 |
</p> |
| 95 |
<div class="example"> |
| 96 |
<pre class="example">(coerce-result <i>return-string</i> <i>type</i>) |
| 97 |
</pre></div> |
| 98 |
|
| 99 |
<p>Here <i>type</i> must be a symbol with a <code>coercion-functions</code> |
| 100 |
property. |
| 101 |
The builtin return types which may be requested are: |
| 102 |
</p> |
| 103 |
<dl compact="compact"> |
| 104 |
<dt><code>T</code></dt> |
| 105 |
<dd><p>in which case |
| 106 |
the string passed back from the <samp>gcltksrv</samp> process, will be read by the |
| 107 |
lisp reader. |
| 108 |
</p></dd> |
| 109 |
<dt><code>number</code></dt> |
| 110 |
<dd><p>the string is converted to a number using the current *read-base* |
| 111 |
</p></dd> |
| 112 |
<dt><code>list-strings</code></dt> |
| 113 |
<dd> |
| 114 |
<div class="example"> |
| 115 |
<pre class="example">(coerce-result "a b {c d} e" 'list-strings) |
| 116 |
==> ("a" "b" "c d" "e") |
| 117 |
</pre></div> |
| 118 |
</dd> |
| 119 |
<dt><code>boolean</code></dt> |
| 120 |
<dd><p>(coerce-result "1" ’boolean) |
| 121 |
==> T |
| 122 |
(coerce-result "0" ’boolean) |
| 123 |
==> NIL |
| 124 |
</p></dd> |
| 125 |
</dl> |
| 126 |
|
| 127 |
<p>The above symbols are in the <code>TK</code> or <code>LISP</code> package. |
| 128 |
It would be possible to add new types just as the <code>:return t</code> |
| 129 |
is done: |
| 130 |
</p> |
| 131 |
<div class="example"> |
| 132 |
<pre class="example">(setf (get 't 'coercion-functions) |
| 133 |
(cons #'(lambda (x) (our-read-from-string x 0)) |
| 134 |
#'(lambda (x) (format nil "~s" x)))) |
| 135 |
</pre></div> |
| 136 |
|
| 137 |
<p>The <code>coercion-functions</code> property of a symbol, is a cons whose |
| 138 |
<code>car</code> is the coercion form from a string to some possibly different |
| 139 |
lisp object, and whose <code>cdr</code> is a function which builds a string |
| 140 |
to send to the graphics server. Often the two functions are inverse |
| 141 |
functions one of the other up to equal. |
| 142 |
</p> |
| 143 |
<span id="Control-Function-Return-Values"></span><h4 class="subsection">1.4.3 Control Function Return Values</h4> |
| 144 |
|
| 145 |
<p>The <i>control</i> functions (see <a href="Control.html">Control</a>) do not return a value |
| 146 |
or wait unless requested to do so, using the <code>:return</code> keyword. |
| 147 |
The types and method of specification are the same as for the |
| 148 |
Widget Functions in the previous section. |
| 149 |
</p> |
| 150 |
<div class="example"> |
| 151 |
<pre class="example">(winfo :width '.hello :return 'number) |
| 152 |
==> 120 |
| 153 |
</pre></div> |
| 154 |
<p>indicates that the <code>.hello</code> button is actually 120 pixels |
| 155 |
wide. |
| 156 |
</p> |
| 157 |
<hr> |
| 158 |
<div class="header"> |
| 159 |
<p> |
| 160 |
Next: <a href="Argument-Lists.html" accesskey="n" rel="next">Argument Lists</a>, Previous: <a href="Common-Features-of-Widgets.html" accesskey="p" rel="prev">Common Features of Widgets</a>, Up: <a href="General.html" accesskey="u" rel="up">General</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 161 |
</div> |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
</body> |
| 166 |
</html> |