Changeset 435 in project for amb


Ignore:
Timestamp:
05/06/06 01:21:26 (14 years ago)
Author:
Thomas Chust
Message:

[amb] made the egg fit for -check-imports

Location:
amb
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • amb/Makefile

    r112 r435  
    44ENSCRIPT=enscript
    55
    6 CSCFLAGS=-O2 -d0
     6CSCFLAGS=-O2 -d0 -check-imports
    77LDLIBS=
    88
     
    1515
    1616clean:
    17         $(RM) $(addprefix $(NAME),.egg -base.so .html .setup) $(NAME)-demo.html
     17        $(RM) $(addprefix $(NAME),.egg -base.so .exports .html .setup)
     18        $(RM) $(NAME)-demo.html
    1819
    1920$(NAME).egg: $(addprefix $(NAME),-base.scm .scm .html .setup) egg.jpg doc.scm $(NAME)-demo.scm Makefile
     
    2425
    2526$(NAME).setup: Makefile
    26         echo "(compile $(CSCFLAGS) -s \"$(NAME)-base.scm\" $(LDLIBS) -o \"$(NAME)-base.so\")" >$@; \
     27        echo "(define so-file" >$@; \
     28        echo "  (string-append" >>$@; \
     29        echo "    \"$(NAME)-base.\"" >>$@; \
     30        echo "    (if (eq? (software-type) 'windows) \"dll\" \"so\")))" >>$@; \
     31        echo "(compile" >>$@; \
     32        echo "  $(CSCFLAGS) -s \"$(NAME)-base.scm\" $(LDLIBS)" >>$@; \
     33        echo "  -o ,so-file -emit-exports \"$(NAME).exports\")" >>$@; \
    2734        echo "(install-extension" >>$@; \
    28         echo " '$(NAME)" >>$@; \
    29         echo " '(\"$(NAME).scm\" \"$(NAME)-base.so\" \"$(NAME).html\" \"egg.jpg\")" >>$@; \
    30         echo " '((syntax) (require-at-runtime $(NAME)-base) (version \"$(VERSION)\") (documentation \"$(NAME).html\")))" >>$@
     35        echo "  '$(NAME)" >>$@; \
     36        echo "  \`(\"$(NAME).scm\" ,so-file" >>$@; \
     37        echo "    \"$(NAME).html\" \"egg.jpg\")" >>$@; \
     38        echo "  '((syntax) (require-at-runtime $(NAME)-base)" >>$@; \
     39        echo "    (version \"$(VERSION)\") (documentation \"$(NAME).html\")))" >>$@
    3140
    3241%.html: %.scm
  • amb/amb-demo.html

    r11 r435  
    6363</BODY>
    6464</HTML>
    65 
  • amb/amb.html

    r112 r435  
    114114<div id="header">
    115115<h2>amb</h2>
    116 <div id="eggheader">
    117 <a href="index.html">
     116<div id="eggheader"><a href="index.html">
    118117<img src="egg.jpg" alt="[Picture of an egg]" /></a></div></div>
    119118<div id="body">
     
    122121<p>The non-deterministic backtracking ambivalence operator</p></div>
    123122<div class="section">
    124 <h3>Author</h3>
    125 <a href="http://www.chust.org/">Thomas Chust</a></div>
     123<h3>Author</h3><a href="http://www.chust.org/">Thomas Chust</a></div>
    126124<div class="section">
    127125<h3>Version</h3>
     
    129127<li>1.2.0 Non-determinism now optional, better controllability of scope</li>
    130128<li>1.1.1 Fixed bug in amb.setup [Thanks to Kon Lovett]</li>
    131 <li>1.1.0 Renamed
    132 <tt>bag-of</tt> to
    133 <tt>amb-collect</tt> and added
    134 <tt>amb-assert</tt></li>
     129<li>1.1.0 Renamed <tt>bag-of</tt> to <tt>amb-collect</tt> and added <tt>amb-assert</tt></li>
    135130<li>1.0.0 Initial release</li></ul></div>
    136131<div class="section">
    137 <h3>Usage</h3>
    138 <tt>(require-extension amb)</tt></div>
    139 <div class="section">
    140 <h3>Download</h3>
    141 <a href="amb.egg">amb.egg</a></div>
     132<h3>Usage</h3><tt>(require-extension amb)</tt></div>
     133<div class="section">
     134<h3>Download</h3><a href="amb.egg">amb.egg</a></div>
    142135<div class="section">
    143136<h3>Documentation</h3>
    144 <p>The
    145 <tt>amb</tt> operator is a nice toy and sometimes a useful tool for lightweight logic programming. Its implementation is also a good exercise in the handling of continuations.</p>
     137<p>The <tt>amb</tt> operator is a nice toy and sometimes a useful tool for lightweight logic programming. Its implementation is also a good exercise in the handling of continuations.</p>
    146138<div class="subsection">
    147 <p>
    148 <b>Normal interface</b></p>
     139<p><b>Normal interface</b></p>
    149140<dl>
    150 <dt class="definition">
    151 <strong>macro:</strong> (amb expr ...) =&gt; &lt;top&gt;</dt>
    152 <dd>
    153 <p>In the form
    154 <tt>(amb)</tt> the expression always fails.</p>
    155 <p>If the expression has any parameters, the first one of them is evaluated and the result is returned. If a subsequent occurrence of
    156 <tt>amb</tt> fails, though, backtracking may cause the second of the given expressions to be selected for evaluation, then the third and so forth until the whole program does not fail if at all possible.</p>
    157 <p>The backtracking mechanism is described along with the
    158 <tt>amb-failure-continuation</tt> parameter below.</p></dd>
    159 <dt class="definition">
    160 <strong>macro:</strong> (amb/random expr ...) =&gt; &lt;top&gt;</dt>
    161 <dd>
    162 <p>Works like
    163 <tt>amb</tt> but the parameters are not selected in sequence but randomly. None of them is selected more than once, though.</p></dd>
    164 <dt class="definition">
    165 <strong>macro:</strong> (amb-find expr #!optional failure-value) =&gt; &lt;top&gt;</dt>
    166 <dd>
    167 <p>Evaluates
    168 <tt>expr</tt> returning its value if successful (possibly after backtracking).</p>
    169 <p>If
    170 <tt>expr</tt> cannot be evaluated successfully and the expression tree is exhausted,
    171 <tt>failure-value</tt> is evaluated and the result is returned instead. If no
    172 <tt>failure-value</tt> is specified, an exception occurs. See the
    173 <tt>amb-failure-continuation</tt> parameter below for a description of the exception.</p></dd>
    174 <dt class="definition">
    175 <strong>macro:</strong> (amb-collect expr) =&gt; &lt;list&gt;</dt>
    176 <dd>
    177 <p>Evaluates
    178 <tt>expr</tt> and performs backtracking repeatedly until all possible values for it have been accumulated in a list, which is returned.</p></dd>
    179 <dt class="definition">
    180 <strong>macro:</strong> (amb-assert ok?) =&gt; &lt;void&gt;</dt>
    181 <dd>
    182 <p>Evaluates
    183 <tt>ok?</tt> and fails if it is
    184 <tt>#f</tt>.</p></dd></dl></div>
     141<dt class="definition"><strong>macro:</strong> (amb expr ...) =&gt; &lt;top&gt;</dt>
     142<dd>
     143<p>In the form <tt>(amb)</tt> the expression always fails.</p>
     144<p>If the expression has any parameters, the first one of them is evaluated and the result is returned. If a subsequent occurrence of <tt>amb</tt> fails, though, backtracking may cause the second of the given expressions to be selected for evaluation, then the third and so forth until the whole program does not fail if at all possible.</p>
     145<p>The backtracking mechanism is described along with the <tt>amb-failure-continuation</tt> parameter below.</p></dd>
     146<dt class="definition"><strong>macro:</strong> (amb/random expr ...) =&gt; &lt;top&gt;</dt>
     147<dd>
     148<p>Works like <tt>amb</tt> but the parameters are not selected in sequence but randomly. None of them is selected more than once, though.</p></dd>
     149<dt class="definition"><strong>macro:</strong> (amb-find expr #!optional failure-value) =&gt; &lt;top&gt;</dt>
     150<dd>
     151<p>Evaluates <tt>expr</tt> returning its value if successful (possibly after backtracking).</p>
     152<p>If <tt>expr</tt> cannot be evaluated successfully and the expression tree is exhausted, <tt>failure-value</tt> is evaluated and the result is returned instead. If no <tt>failure-value</tt> is specified, an exception occurs. See the <tt>amb-failure-continuation</tt> parameter below for a description of the exception.</p></dd>
     153<dt class="definition"><strong>macro:</strong> (amb-collect expr) =&gt; &lt;list&gt;</dt>
     154<dd>
     155<p>Evaluates <tt>expr</tt> and performs backtracking repeatedly until all possible values for it have been accumulated in a list, which is returned.</p></dd>
     156<dt class="definition"><strong>macro:</strong> (amb-assert ok?) =&gt; &lt;void&gt;</dt>
     157<dd>
     158<p>Evaluates <tt>ok?</tt> and fails if it is <tt>#f</tt>.</p></dd></dl></div>
    185159<div class="subsection">
    186 <p>
    187 <b>Additional stuff exported by amb-base</b></p>
     160<p><b>Additional stuff exported by amb-base</b></p>
    188161<dl>
    189 <dt class="definition">
    190 <strong>parameter:</strong> amb-failure-continuation</dt>
    191 <dd>
    192 <p>Seen in a global context, the
    193 <tt>amb</tt> operator transforms the whole program that contains it into a depth first search for return values from
    194 <tt>amb</tt> forms that will not cause failure.</p>
    195 <p>This is realized using a backtracking system that invokes previously stored continuations whenever an
    196 <tt>amb</tt> expression fails. The
    197 <tt>amb-failure-continuation</tt> parameter is the status variable for this system.</p>
    198 <p>At the start of the program, or when no further backtracking options are available, this is set to a procedure of no arguments that throws an exception of the composite
    199 <tt>(exn amb)</tt> kind (except when a
    200 <tt>amb-collect</tt> statement is being processed, where the parameter will point to a procedure signalling
    201 <tt>amb-collect</tt> that there are no more backtracking options available).</p>
     162<dt class="definition"><strong>parameter:</strong> amb-failure-continuation</dt>
     163<dd>
     164<p>Seen in a global context, the <tt>amb</tt> operator transforms the whole program that contains it into a depth first search for return values from <tt>amb</tt> forms that will not cause failure.</p>
     165<p>This is realized using a backtracking system that invokes previously stored continuations whenever an <tt>amb</tt> expression fails. The <tt>amb-failure-continuation</tt> parameter is the status variable for this system.</p>
     166<p>At the start of the program, or when no further backtracking options are available, this is set to a procedure of no arguments that throws an exception of the composite <tt>(exn amb)</tt> kind (except when a <tt>amb-collect</tt> statement is being processed, where the parameter will point to a procedure signalling <tt>amb-collect</tt> that there are no more backtracking options available).</p>
    202167<p>In all other cases this parameter is set to a procedure of no arguments that causes backtracking to the next possible alternative in the &quot;tree&quot;.</p>
    203 <p>If you want to restrict the scope of backtracking to something smaller than the whole past program, use
    204 <tt>amb-find</tt> or
    205 <tt>amb-collect</tt> which restore this parameter to its original value when they are done evaluating the expressions they were given.</p></dd>
    206 <dt class="definition">
    207 <strong>procedure:</strong> (amb-thunks &lt;list of procedures&gt;) =&gt; &lt;top&gt;</dt>
    208 <dd>
    209 <p>The backend of
    210 <tt>amb</tt>.
    211 <tt>amb</tt> wraps all its parameters into thunks and passes a list of them into this procedure,
    212 <tt>amb/random</tt> shuffles the list first.</p></dd>
    213 <dt class="definition">
    214 <strong>procedure:</strong> (amb-find-thunk &lt;procedure&gt; #!optional &lt;procedure&gt;) =&gt; &lt;top&gt;</dt>
    215 <dd>
    216 <p>The backend of
    217 <tt>amb-find</tt>.
    218 <tt>amb-find</tt> wraps its parameters into thunks and passes them into this procedure.</p></dd>
    219 <dt class="definition">
    220 <strong>procedure:</strong> (amb-collect-thunk &lt;procedure&gt;) =&gt; &lt;list&gt;</dt>
    221 <dd>
    222 <p>The backend of
    223 <tt>amb-collect</tt>.
    224 <tt>amb-collect</tt> wraps its parameter into a thunk and passes it into this procedure.</p></dd></dl></div>
     168<p>If you want to restrict the scope of backtracking to something smaller than the whole past program, use <tt>amb-find</tt> or <tt>amb-collect</tt> which restore this parameter to its original value when they are done evaluating the expressions they were given.</p></dd>
     169<dt class="definition"><strong>procedure:</strong> (amb-thunks &lt;list of procedures&gt;) =&gt; &lt;top&gt;</dt>
     170<dd>
     171<p>The backend of <tt>amb</tt>. <tt>amb</tt> wraps all its parameters into thunks and passes a list of them into this procedure, <tt>amb/random</tt> shuffles the list first.</p></dd>
     172<dt class="definition"><strong>procedure:</strong> (amb-find-thunk &lt;procedure&gt; #!optional &lt;procedure&gt;) =&gt; &lt;top&gt;</dt>
     173<dd>
     174<p>The backend of <tt>amb-find</tt>. <tt>amb-find</tt> wraps its parameters into thunks and passes them into this procedure.</p></dd>
     175<dt class="definition"><strong>procedure:</strong> (amb-collect-thunk &lt;procedure&gt;) =&gt; &lt;list&gt;</dt>
     176<dd>
     177<p>The backend of <tt>amb-collect</tt>. <tt>amb-collect</tt> wraps its parameter into a thunk and passes it into this procedure.</p></dd></dl></div>
    225178<div class="section">
    226179<h3>Examples</h3>
    227180<div id="examples">
    228 <p>The following code is a rewrite of an example from the book &quot;Teach Yourself Scheme in Fixnum Days&quot; by Dorai Sitaram. The book gives the following problem setting:</p>
    229 <em>
     181<p>The following code is a rewrite of an example from the book &quot;Teach Yourself Scheme in Fixnum Days&quot; by Dorai Sitaram. The book gives the following problem setting:</p><em>
    230182<p>The Kalotans are a tribe with a peculiar quirk. Their males always tell the truth. Their females never make two consecutive true statements, or two consecutive untrue statements.</p>
    231183<p>An anthropologist (let's call him Worf) has begun to study them. Worf does not yet know the Kalotan language. One day, he meets a Kalotan (heterosexual) couple and their child Kibi. Worf asks Kibi: &quot;Are you a boy?&quot; Kibi answers in Kalotan, which of course Worf doesn't understand.</p>
     
    310262SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</pre></div></div></div>
    311263<div id="footer">
    312 <hr />
    313 <a href="index.html">&lt; Egg index</a>
     264<hr /><a href="index.html">&lt; Egg index</a>
    314265<div id="revision-history">$Revision$ $Date$</div>&nbsp;</div></body></html>
  • amb/amb.setup

    r112 r435  
    1 (compile -O2 -d0 -s "amb-base.scm"  -o "amb-base.so")
     1(define so-file
     2  (string-append
     3    "amb-base."
     4    (if (eq? (software-type) 'windows) "dll" "so")))
     5(compile
     6  -O2 -d0 -check-imports -s "amb-base.scm"
     7  -o ,so-file -emit-exports "amb.exports")
    28(install-extension
    3  'amb
    4  '("amb.scm" "amb-base.so" "amb.html" "egg.jpg")
    5  '((syntax) (require-at-runtime amb-base) (version "1.2.0") (documentation "amb.html")))
     9  'amb
     10  `("amb.scm" ,so-file
     11    "amb.html" "egg.jpg")
     12  '((syntax) (require-at-runtime amb-base)
     13    (version "1.2.0") (documentation "amb.html")))
Note: See TracChangeset for help on using the changeset viewer.