-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
663 lines (632 loc) · 24.6 KB
/
index.html
File metadata and controls
663 lines (632 loc) · 24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2017-03-25 Sat 22:07 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>eliza-cl.org Eliza Tests</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="benrudgers" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">eliza-cl.org Eliza Tests</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org851dc64">Preface</a></li>
<li><a href="#org886b25b">Introduction</a></li>
<li><a href="#org53b1236">System</a>
<ul>
<li><a href="#orgd98376b">:eliza package</a></li>
</ul>
</li>
<li><a href="#orgd54c675">Pattern Matching</a>
<ul>
<li><a href="#org7101e26">simple-equal</a></li>
<li><a href="#org3f49ea2">variable-p</a></li>
<li><a href="#org3802df2">pat-match</a>
<ul>
<li><a href="#org66677a4">A naive version</a></li>
<li><a href="#orgdae65ba">A second buggy version</a></li>
<li><a href="#org66ce2a8">pattern matching constants</a></li>
<li><a href="#org057fa02">abstractions over assoc</a></li>
<li><a href="#orgb0de9aa">A third version</a></li>
<li><a href="#org6065431">Segment Pattern Matching</a></li>
<li><a href="#orgb49a2af">Final</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#org3bcc063">Tests (experimental)</a>
<ul>
<li><a href="#orgc6cb0c5">Introduction</a></li>
<li><a href="#org83a60c1">Base File</a></li>
<li><a href="#org2a5b5e7">Installing lisp-unit</a></li>
<li><a href="#org109b299">Test One</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-org851dc64" class="outline-2">
<h2 id="org851dc64">Preface</h2>
<div class="outline-text-2" id="text-org851dc64">
<p>
<b><b>The computer code here is not original to me.</b></b> and this document reflects several of my ongoing projects:
</p>
<ol class="org-ol">
<li>Learning 'classic' AI by working through Peter Norvig's <a href="http://norvig.com/paip.html"><b>Paradigms of Artificial Intelligence: Case Studies in Common Lisp</b></a>. Norvig's book is the source for the Lisp code in this project.</li>
<li>Learning more Emacs in general and org-mode in particular.</li>
<li>Developing a work process around Literate Programming.</li>
</ol>
</div>
</div>
<div id="outline-container-org886b25b" class="outline-2">
<h2 id="org886b25b">Introduction</h2>
</div>
<div id="outline-container-org53b1236" class="outline-2">
<h2 id="org53b1236">System</h2>
<div class="outline-text-2" id="text-org53b1236">
<p>
This is my first attempt at using ASDF to build a system. The system uses utility files available <a href="https://github.com/brudgers/norvig-utils">here</a>.
</p>
<div class="org-src-container">
<pre class="src src-lisp">;;; To build the system
;;; (asdf:operate 'asdf:load-op :eliza)
;;; then run
;;; (in-package :eliza)
(load "../utils/norvig-utils")
(load "../utils/norvig-debugger")
(defpackage #:eliza
(:use :common-lisp
:asdf
:norvig-utils
:norvig-debugger
:kludgecode))
(in-package :eliza)
(defsystem eliza
:serial t
:components ((:file "eliza")))
</pre>
</div>
</div>
<div id="outline-container-orgd98376b" class="outline-3">
<h3 id="orgd98376b">:eliza package</h3>
<div class="outline-text-3" id="text-orgd98376b">
<p>
As is the case with ASDF, this is also my first time developing using Common Lisp's package system.
</p>
<div class="org-src-container">
<pre class="src src-lisp" id="org3424bf9">(in-package :eliza)
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orgd54c675" class="outline-2">
<h2 id="orgd54c675">Pattern Matching</h2>
<div class="outline-text-2" id="text-orgd54c675">
</div><div id="outline-container-org7101e26" class="outline-3">
<h3 id="org7101e26">simple-equal</h3>
<div class="outline-text-3" id="text-org7101e26">
<div class="org-src-container">
<pre class="src src-lisp">(defun simple-equal (x y)
"Are x and y equal. Does not check inside strings."
(if (or (atom x) (atom y))
(eql x y)
(and (simple-equal (first x) (first y))
(simple-equal (rest x) (rest y)))))
</pre>
</div>
</div>
</div>
<div id="outline-container-org3f49ea2" class="outline-3">
<h3 id="org3f49ea2">variable-p</h3>
<div class="outline-text-3" id="text-org3f49ea2">
<p>
This function brings up two interesting aspects of Common Lisp. The first is that <code>atom</code>'s are not truely atomic. The second is that predicate syntax in Common Lisp suffers from the same big-language inconsistencies as might be found in PHP.
</p>
<div class="org-src-container">
<pre class="src src-lisp" id="orgeffa690">(defun variable-p (x)
"Is x a variable where a variable is a symbol beginning with '?'"
(and (symbolp x)
(equal (char (symbol-name x) 0)
#\?)))
</pre>
</div>
</div>
</div>
<div id="outline-container-org3802df2" class="outline-3">
<h3 id="org3802df2">pat-match</h3>
<div class="outline-text-3" id="text-org3802df2">
<p>
The naive version is so straight forward it could be template code for recursing on a list (or two lists). There is a certain concision to the first part which avoids enumerating all the cases of atoms and lists. Though it arises more from the template style than anything else.
</p>
</div>
<div id="outline-container-org66677a4" class="outline-4">
<h4 id="org66677a4">A naive version</h4>
<div class="outline-text-4" id="text-org66677a4">
<div class="org-src-container">
<pre class="src src-lisp">(defun pat-match (input pattern)
"Does pattern match input? Any variable can match anything."
(if (variable-p pattern)
t
(if (or (atom pattern) (atom input))
(eql pattern input)
(and (pat-match (first input) (first pattern))
(pat-match (rest input) (rest pattern))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-orgdae65ba" class="outline-4">
<h4 id="orgdae65ba">A second buggy version</h4>
<div class="outline-text-4" id="text-orgdae65ba">
<p>
One problem is that <code>(eql pattern input)</code> may return <code>t</code>. While <code>nil</code> is not a problem for <code>append</code>, <code>t</code> is…since <code>t</code> is not a list. Booleans are actually tough if they're overloaded as they are many languages.
</p>
<p>
The second problem is semi-boolean contexts: those in which <code>nil</code> may be returned from a successful match versus where <code>nil</code> is returned because a predicate turned out to be false. Did I say booleans are tough?
</p>
<p>
The final problem is that we want the same variable (e.g. <code>?X</code>) to consistently be bound to the same expression when it appears multiple times in an input.
</p>
<div class="org-src-container">
<pre class="src src-lisp">(defun pat-match (pattern input)
"BUGGY Second version."
(if (variable-p pattern)
(list (cons pattern input))
(if (or (atom pattern) (atom input))
(eql pattern input)
(append (pat-match (first pattern) (first input))
(pat-match (rest pattern) (rest input))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-org66ce2a8" class="outline-4">
<h4 id="org66ce2a8">pattern matching constants</h4>
<div class="outline-text-4" id="text-org66ce2a8">
<p>
The first step in the third version is to turn <code>pat-match</code> into a true predicate that only returns <code>nil</code> for failure. It's worth noting that only having a single value that indicates <code>false</code> is helpful here.
</p>
<div class="org-src-container">
<pre class="src src-lisp" id="org9641fe4">(defconstant fail nil "indicates pat-match failure.")
(defconstant no-bindings '((t . t))
"Indicates a pattern match success, with no variables.")
</pre>
</div>
</div>
</div>
<div id="outline-container-org057fa02" class="outline-4">
<h4 id="org057fa02">abstractions over assoc</h4>
<div class="outline-text-4" id="text-org057fa02">
<p>
<b>Note:</b> The ASDF build system loads these from my <a href="https://github.com/brudgers/norvig-utils">norvig-utils repository</a>. They are shown here to maintain consistency with the text.
</p>
<p>
Building abstractions over <code>assoc</code> enables using the language of variables and bindings rather than low level lisp.
</p>
<div class="org-src-container">
<pre class="src src-lisp" id="org6fb72e6">(defun get-bindings (var bindings)
"Find a (variable . value) pair in a binding list."
(assoc var bindings))
(defun binding-val (binding)
"Get the value part of a single binding."
(cdr binding))
(defun lookup (var bindings)
"Get the value part (for var) from a binding list."
(binding-val (get-bindings var bindings)))
(defun extend-bindings (var val bindings)
"Add a (var . value) pair to a binding list."
(cons (cons var val) bindings))
</pre>
</div>
</div>
</div>
<div id="outline-container-orgb0de9aa" class="outline-4">
<h4 id="orgb0de9aa">A third version</h4>
<div class="outline-text-4" id="text-orgb0de9aa">
<p>
There are five cases for <code>pat-match</code>:
</p>
<ol class="org-ol">
<li>Bindings list is <code>fail</code> and the match fails.</li>
<li>Pattern is a single variable.</li>
<li>Pattern and input are <code>eql</code>.</li>
<li>Pattern and input are both lists.</li>
<li>None of these holds and the match fails.</li>
</ol>
<div class="org-src-container">
<pre class="src src-lisp">(defun pat-match (pattern input &optional (bindings non-bindings))
"Match pattern against input in the context of bindings."
(cond ((eq bindings fail) fail)
((variable-p pattern)
(match-variable pattern input bindings))
((eql pattern input) bindings)
((and (consp pattern)
(consp input))
(pat-match (rest pattern)
(rest input)
(pat-match (first pattern)
(first input)
bindings)))
(t fail)))
</pre>
</div>
<div class="org-src-container">
<pre class="src src-lisp" id="org63ba8fc">(defun match-variable (var input bindings)
"Does var match input. Uses bindings. Returns bindings with or without an update depending on match."
(let ((binding (get-bindings var bindings)))
(cond ((not binding) (extend-bindings var input bindings))
((equal input (binding-val binding)) bindings)
(t fail))))
</pre>
</div>
</div>
</div>
<div id="outline-container-org6065431" class="outline-4">
<h4 id="org6065431">Segment Pattern Matching</h4>
<div class="outline-text-4" id="text-org6065431">
<p>
It is useful to have two types of variables, those that match individual input elements and others that behave like Lisp's <code>&rest</code> parameter. The latter can be thought of as matching segments. This would allow a syntax such as <code>(?P need . ?X)</code>.
</p>
<div class="org-src-container">
<pre class="src src-lisp">;;; Example
(pat-match '((?* ?p) need (?* ?x))
'(Mr Hulot and I need a vaction))
((?P MR HULOT AND I) (?X A VACTION))
</pre>
</div>
<p>
Updating <code>pat-match</code> for the new behavior:
</p>
<div class="org-src-container">
<pre class="src src-lisp" id="org89656e3">(defun pat-match (pattern input &optional (bindings no-bindings))
"Match pattern against input in context of the bindings."
(cond ((eq bindings fail) fail)
((variable-p pattern)
(match-variable pattern input bindings))
((eql pattern input) bindings)
((segment-pattern-p pattern)
(segment-match pattern input bindings))
((and (consp pattern) (consp input))
(pat-match (rest pattern)
(rest input)
(pat-match (first pattern)
(first input)
bindings)))
(t fail)))
</pre>
</div>
<p>
Adding the new predicate highlights Common Lisp's flexibility in regards to naming symbols by allowing a notation evocative of the kleene star.
</p>
<div class="org-src-container">
<pre class="src src-lisp" id="org3148083">(defun segment-pattern-p (pattern)
"Is this a segment matching pattern: ((?* var) . pat)"
(and (consp pattern)
(starts-with (first pattern) '?*)))
</pre>
</div>
<p>
The first pass at <code>segment-match</code> address the problems that arise when the next element of the pattern is contained in the input but there are intervening elements between what has been matched already and the match for the next element of the pattern. It allows looking further ahead in the input at the expense of requiring a segment-variable to be the last variable in a pattern.
</p>
<div class="org-src-container">
<pre class="src src-lisp" id="orge80d568">(defun segment-match (pattern input bindings &optional (start 0))
"Match the segment patter ((?* var) . pat) against input."
(let ((var (second (first pattern)))
(pat (rest pattern)))
(if (null pat)
(match-variable var input bindings)
;; We assume pat starts with a constant
;; In other words, a pattern can't have 2 consectutive vars
(let ((pos (position (first pat)
input
:start start
:test #'equal)))
(if (null pos)
fail
(let ((b2 (pat-match pat
(subseq input pos)
bindings)))
;; If this match failed try another longer one
;; If it worked, check that the variables match
(if (eq b2 fail)
(segment-match pattern input bindings (+ 1 pos))
(match-variable var
(subseq input 0 pos)
b2))))))))
</pre>
</div>
</div>
</div>
<div id="outline-container-orgb49a2af" class="outline-4">
<h4 id="orgb49a2af">Final</h4>
<div class="outline-text-4" id="text-orgb49a2af">
<div class="org-src-container">
<pre class="src src-lisp" id="org0289e77"><<eliza-package>>
<<pat-match-constants>>
<<binding-utilities>>
<<variable-p>>
<<match-variable>>
<<pat-match>>
<<segment-match>>
<<segment-pattern-p>>
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="outline-container-org3bcc063" class="outline-2">
<h2 id="org3bcc063">Tests (experimental)</h2>
<div class="outline-text-2" id="text-org3bcc063">
</div>
<div id="outline-container-orgc6cb0c5" class="outline-3">
<h3 id="orgc6cb0c5">Introduction</h3>
<div class="outline-text-3" id="text-orgc6cb0c5">
<p>
This is mostly an experiment:
</p>
<ol class="org-ol">
<li>At the emacs level it is about building compound documents using <code>#+INCLUDE:</code> to break up org documents.</li>
<li>At the literate programming level it is about beginning to incorporate testing into literate documents.</li>
<li>At the Common Lisp level is about learning <code>lisp-unit</code> for unit testing.</li>
<li>At the Common Lisp development environment level it is about learning <code>quicklisp</code>. It is good that I broke <code>quicklisp</code> and <code>ASDF</code> into seperate exercises. Without understanding a bit about <code>ASDF</code> I was confused when looking at <code>quicklisp</code> and when I looked at <code>quicklisp</code> it just made me confused about <code>ASDF</code>.</li>
</ol>
</div>
</div>
<div id="outline-container-org83a60c1" class="outline-3">
<h3 id="org83a60c1">Base File</h3>
<div class="outline-text-3" id="text-org83a60c1">
<div class="org-src-container">
<pre class="src src-lisp"><<lu-install>>
<<lu-test-one>>
</pre>
</div>
</div>
</div>
<div id="outline-container-org2a5b5e7" class="outline-3">
<h3 id="org2a5b5e7">Installing lisp-unit</h3>
<div class="outline-text-3" id="text-org2a5b5e7">
<div class="org-src-container">
<pre class="src src-lisp" id="org2300417">(ql:quickload :lisp-unit)
</pre>
</div>
</div>
</div>
<div id="outline-container-org109b299" class="outline-3">
<h3 id="org109b299">Test One</h3>
<div class="outline-text-3" id="text-org109b299">
<div class="org-src-container">
<pre class="src src-lisp" id="orgd557f07">(in-package :eliza)
(define-test test-one
(assert-equal 5 5))
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: benrudgers</p>
<p class="date">Created: 2017-03-25 Sat 22:07</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>