Accepted update test db for error messages
[Klink.git] / debug-klink.el
blob8e57967391dd8404de13f24f050b4ec87a2ddce4
1 ;;;_ debug-klink.el --- Help debugging Klink
3 ;;;_. Headers
4 ;;;_ , License
5 ;; Copyright (C) 2010,2011 Tom Breton (Tehom)
7 ;; Author: Tom Breton (Tehom) <tehom@panix.com>
8 ;; Keywords: convenience,tools,local
10 ;; This file is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; This file is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;;_ , Commentary:
27 ;;
30 ;;;_ , Requires
32 (require 'emtest/editing/expect nil t)
33 (require 'emtest/testhelp/standard)
34 (require 'emtest/testhelp/persist)
35 (require 'emtest/main/define)
37 ;;;_. Body
38 ;;;_ , debug-klink-executable
39 (defconst debug-klink-executable
40 (emt:expand-filename-here "klink")
41 "Absolute path to the klink executable" )
42 ;;;_ , DB file
43 (defconst debug-klink:th:db
44 (emt:expand-filename-here "db")
45 "File where presisting results are stored" )
46 ;;;_ , debug-klink-insert-print-type
47 (defun debug-klink-insert-print-type (obj)
48 "Insert a statement to print an pko's type"
50 (interactive "sObject: ")
51 (insert
52 "p (enum klink_types)_get_type("obj")"))
53 ;;;_ , debug-klink-read-C-type
54 (defun debug-klink-read-C-type (prompt)
57 (completing-read
58 prompt
60 "_kt_spagstack"
61 "_kt_tag"
62 "kt_boxed_void"
63 "kt_cfunc"
64 "kt_curried"
65 "kt_encap"
66 "kt_recur_tracker"
67 "kt_recurrence_table"
68 "kt_string"
69 "kt_vec2"
70 "kt_vector"
71 "long"
72 "num"
73 "port"
75 nil
76 t))
79 ;;;_ , debug-klink-insert-print-obj
80 (defun debug-klink-insert-print-obj (obj type)
81 "Insert a statement to print an pko's value"
83 (interactive
84 (list
85 (read-string "Object: ")
86 (debug-klink-read-C-type "Type: ")))
87 (insert
88 "p *("type" *)(((enum klink_types*)"obj")+1)"))
89 ;;;_ , debug-klink-send-line
90 ;;;###autoload
91 (defun debug-klink-send-line (string)
92 "Pass a line to gdb as special input
93 For (eg) setting breakpoint commands, setting trace collects, etc"
95 (interactive "sString: ")
96 (comint-send-string (get-buffer-process (current-buffer))
97 (concat
98 string
99 "\n")))
101 ;;;_ , debug-klink-send-end
102 (defun debug-klink-send-end ()
103 "Tell gdb the current special input is done"
105 (interactive)
106 ;;$$IMPROVE ME Make sure it's gdb buffer.
107 (comint-send-string (get-buffer-process (current-buffer)) "end\n"))
109 ;;;_ , debug-klink-prompt
110 (defconst debug-klink-prompt "\nklink> "
111 "Klink's prompt" )
112 ;;;_ , Test suite
113 (emt:deftest-3
114 ((of 'klink)
115 (db-id `(persist ,debug-klink:th:db)))
116 (expect
117 ((exec+args (list debug-klink-executable))
118 (shell t)
119 (prompt "\nklink> ")
120 (timeout 10)
121 (append-newline t))
122 ;;Clean out header stuff
123 (t "")
124 (t "12"
125 (emt:doc "Communicating at all")
126 (emt:assert
127 (equal answer "12")
128 t)))
130 (expect
131 ((exec+args (list debug-klink-executable))
132 (shell t)
133 (prompt "\nklink> ")
134 (timeout 10)
135 (append-newline t))
136 ;;Clean out header stuff
137 (t "")
138 (t "(eval 12 (get-current-environment))"
139 (emt:assert
140 (equal answer "12")
142 (t "(eval 12)"
143 (emt:assert
144 (equal answer "12")
145 t))
146 (t "(eval ''(1 2 3 4)(get-current-environment))"
147 (emt:doc "Eval in current environment")
148 (emt:assert
149 (equal answer "(1 2 3 4)")
151 (t "(eval ''(1 2 . #(3 4))(get-current-environment))"
152 (emt:doc "Eval in current environment")
153 (emt:assert
154 (equal answer "(1 2 . #( 3 4))")
156 (t "(eval (get-current-environment)(get-current-environment))"
157 (emt:doc "Eval in current environment")
158 (emt:assert
159 (equal answer
160 "#<ENVIRONMENT>"
163 (t "(wrap wrap)"
164 (emt:doc "Wrap behavior")
165 (emt:assert
166 (equal answer
167 "#<APPLICATIVE>"
170 (t "($define! a 12)"
171 (emt:doc "$define! behavior")
172 (emt:assert
173 (equal answer
174 "#inert"
177 (t "a"
178 (emt:doc "Result: a is now define 12")
179 (emt:assert
180 (equal answer
181 "12"
184 (t "($define! b (eval ''(1 . #(2 3)) (get-current-environment)))"
185 (emt:doc "Define b, passing a form")
186 (emt:assert
187 (equal answer
188 "#inert"
191 (t "b"
192 (emt:doc "Result: b is now defined as what the form evaluated to")
193 (emt:assert
194 (equal answer
195 "(1 . #( 2 3))"
198 (t "($define! (c d e) '(1 2 3))"
199 (emt:doc "Define c, d, and e")
200 (emt:assert
201 (equal answer
202 "#inert"
205 (t "c"
206 (emt:doc "c is defined")
207 (emt:assert
208 (equal answer
212 (t "d"
213 (emt:doc "d is defined")
214 (emt:assert
215 (equal answer
219 (t "e"
220 (emt:doc "e is defined")
221 (emt:assert
222 (equal answer
226 (t "($set! (get-current-environment) f 14)"
227 (emt:doc "$set! behavior")
228 (emt:doc "Operation: set f in the current environment")
229 (emt:assert
230 (equal answer
231 "#inert"
234 (t "f"
235 (emt:doc "Result: f is now defined")
236 (emt:assert
237 (equal answer
238 "14"
241 (t "($set! (get-current-environment) f 15)"
242 (emt:doc "Operation: set f to something else")
243 (emt:assert
244 (equal answer
245 "#inert"
248 (t "f"
249 (emt:doc "Result: f now has the new definition")
250 (emt:assert
251 (equal answer
252 "15"
255 (t "($set! (get-current-environment) (g h) '(16 157))"
256 (emt:doc "Operation: set g and h")
257 (emt:assert
258 (equal answer
259 "#inert"
262 (t "g"
263 (emt:doc "Result: g is defined")
264 (emt:assert
265 (equal answer
266 "16"
269 (t "h"
270 (emt:doc "Result: h is defined")
271 (emt:assert
272 (equal answer
273 "157"
276 (t "($define! i ($vau (a) e (eval a e)))"
277 (emt:doc "$vau behavior")
278 (emt:assert
279 (equal answer
280 "#inert"
283 (t "(i '(12 14))"
284 (emt:doc "$vau behavior")
285 (emt:assert
286 (equal answer
287 "(12 14)"
290 (t "(i (i '(12 14)))"
291 (emt:doc "$vau behavior")
292 (emt:assert
293 (equal answer
294 "(12 14)"
297 (t "(i (car '(12 14)))"
298 (emt:doc "$vau behavior")
299 (emt:assert
300 (equal answer
301 "12"
304 (t "($define! j ($vau () e 12))"
305 (emt:doc "$vau behavior")
306 (emt:assert
307 (equal answer
308 "#inert"
311 (t "(j)"
312 (emt:doc "$vau behavior")
313 (emt:assert
314 (equal answer
315 "12"
318 (t "($define! k ($vau (a) e a))"
319 (emt:doc "$vau behavior")
320 (emt:assert
321 (equal answer
322 "#inert"
325 (t "(k 12)"
326 (emt:doc "$vau behavior")
327 (emt:assert
328 (equal answer
329 "12"
332 (t "(k '(1 2))"
333 (emt:doc "$vau behavior")
334 (emt:assert
335 (equal answer
336 "(#,$quote (1 2))")
338 (t "($define! l ($vau (a b) e a))"
339 (emt:doc "$vau behavior")
340 (emt:assert
341 (equal answer
342 "#inert"
345 (t "(l 12 13)"
346 (emt:doc "$vau behavior")
347 (emt:assert
348 (equal answer
349 "12"
352 (t "($define! (bi ac) (make-keyed-static-variable))"
353 (emt:doc "Keyed static variables")
354 (emt:assert
355 (equal answer
356 "#inert"
359 (t "ac"
360 (emt:doc "Keyed static variables")
361 (emt:assert
362 (equal answer
363 "#<APPLICATIVE>"
366 (t "(bi 4 (get-current-environment))"
367 (emt:doc "Keyed static variables")
368 (emt:assert
369 (equal answer
370 "#<ENVIRONMENT>"
373 (t "(eval '(ac) (bi 4 (get-current-environment)))"
374 (emt:doc "Keyed static variables")
375 (emt:assert
376 (equal answer
377 "4")
378 t)))
380 (expect
381 ((exec+args (list debug-klink-executable))
382 (shell t)
383 (prompt "\nklink> ")
384 (timeout 10)
385 (append-newline t))
386 ;;Clean out header stuff
387 (t "")
388 (t "(eq? () ())"
389 (emt:assert
390 (equal answer "#t")))
391 (t "(eq? '() '())"
392 (emt:assert
393 (equal answer "#t")))
394 (t "(eq? ''() ''())"
395 (emt:doc "Double-quoted nils are not `eq?' because both could \
396 conceivably be mutated")
397 (emt:assert
398 (equal answer "#f")))
399 (t "(eq? (cdr '(1)) '())"
400 (emt:doc "nil generated by finding a tail is `eq?' to explicit nil")
401 (emt:assert
402 (equal answer "#t"))))
404 ;;list-tail
405 (expect
406 ((exec+args (list debug-klink-executable))
407 (shell t)
408 (prompt "\nklink> ")
409 (timeout 10)
410 (append-newline t))
411 ;;Clean out header stuff
412 (t "")
414 (t "(list-tail '(0 1 2) 0)"
415 (emt:doc "Behavior of list-tail")
416 (emt:assert
417 (equal answer "(0 1 2)")))
418 (t "(list-tail '(0 1 2) 1)"
419 (emt:assert
420 (equal answer "(1 2)")))
421 (t "(list-tail '(0 1 2) 2)"
422 (emt:assert
423 (equal answer "(2)")))
424 (t "(list-tail '(0 1 2) 3)"
425 (emt:assert
426 (equal answer "()"))))
428 (expect
429 ((exec+args (list debug-klink-executable))
430 (shell t)
431 (prompt "\nklink> ")
432 (timeout 10)
433 (append-newline t))
434 ;;Clean out header stuff
435 (t "")
436 (t "($define! a (list 0 1 2))"
437 (emt:doc "Make a list object")
438 (emt:assert
439 (equal answer "#inert")))
440 (t "(encycle! a 0 3)"
441 (emt:doc "Encycle it, no prefix, the whole object")
442 (emt:assert
443 (equal answer "#inert")))
444 (t "a"
445 (emt:doc "Show the object")
446 (emt:assert
447 (equal answer "#0=(0 1 2 #0)")))
448 (t "($define! a (list 0 1 2))"
449 (emt:assert
450 (equal answer "#inert")))
451 (t "(encycle! a 1 2)"
452 (emt:doc "Encycle it, the whole list, with prefix")
453 (emt:assert
454 (equal answer "#inert")))
455 (t "a"
456 (emt:assert
457 (equal answer "(0 #0=1 2 #0)")))
458 (t "($define! a (list 0 1 2))"
459 (emt:assert
460 (equal answer "#inert")))
461 (t "(encycle! a 0 2)"
462 (emt:doc "Encycle it, no prefix, less than the list length")
463 (emt:assert
464 (equal answer "#inert")))
465 (t "a"
466 (emt:assert
467 (equal answer "#0=(0 1 #0)")))
468 (t "($define! a (list 0 1 2))"
469 (emt:assert
470 (equal answer "#inert")))
471 (t "(encycle! a 1 1)"
472 (emt:doc "Encycle it, less than the list length")
473 (emt:assert
474 (equal answer "#inert")))
475 (t "a"
476 (emt:assert
477 (equal answer "(0 #0=1 #0)"))))
480 ;;apply
481 (expect
482 ((exec+args (list debug-klink-executable))
483 (shell t)
484 (prompt "\nklink> ")
485 (timeout 10)
486 (append-newline t))
487 ;;Clean out header stuff
488 (t "")
489 (t "apply"
490 (emt:doc "`apply' is recognized")
491 (emt:assert
492 (equal answer "#,apply")))
493 (t "(apply list '(1 2 3) (get-current-environment))"
494 (emt:doc "Apply works on list argument")
495 (emt:assert
496 (equal answer "(1 2 3)")))
497 (t "(apply list '(1 2 3))"
498 (emt:doc "Apply with default env works on list argument,
499 evals each number")
500 (emt:assert
501 (equal answer "(1 2 3)")))
502 (t "(apply list '(a 2 3))"
503 (emt:doc "Apply doesn't re-eval args, so this works even \
504 though the symbol `a' is unbound in the empty environment.")
505 (emt:assert
506 (equal answer "(a 2 3)")))
507 (t "(apply list ''(1 2 3))"
508 (emt:doc "Double-quoted gets single-quoted")
509 (emt:assert
510 (equal answer "(#,$quote (1 2 3))")))
512 (t "(apply list '''(1 2 3))"
513 (emt:doc "Triple-quoted gets double-quoted")
514 (emt:assert
515 (equal answer "(#,$quote (#,$quote (1 2 3)))")))
517 (t "(apply (wrap list) '(list) (get-current-environment))"
518 (emt:doc "In normal environment, we see bindings such as `list'")
519 (emt:assert
520 (equal answer "(#,list)")))
521 (t "(apply (wrap list) '(list) (make-environment))"
522 (emt:doc "In blank environment, we see no bindings")
523 (emt:assert
524 (equal answer "Error: eval: unbound variable: list \n")))
525 (t "(apply (wrap $sequence) '(list) (get-current-environment))"
526 (emt:doc "In normal environment, we see bindings such as `list'")
527 (emt:assert
528 (equal answer "#,list")))
529 (t "(apply (wrap $sequence) '(list) (make-environment))"
530 (emt:doc "In blank environment, we see no bindings")
531 (emt:assert
532 (equal answer "Error: eval: unbound variable: list \n"))))
534 ;;predicates
535 (expect
536 ((exec+args (list debug-klink-executable))
537 (shell t)
538 (prompt "\nklink> ")
539 (timeout 10)
540 (append-newline t))
541 ;;Clean out header stuff
542 (t "")
543 (t "(integer? 1)"
544 (emt:doc "Predicate integer?")
545 (emt:assert
546 (equal answer
547 "#t")
549 (t "(integer? 'a)"
550 (emt:doc "Predicate integer?")
551 (emt:assert
552 (equal answer
553 "#f")
554 t)))
555 ;;null?
556 (expect
557 ((exec+args (list debug-klink-executable))
558 (shell t)
559 (prompt "\nklink> ")
560 (timeout 10)
561 (append-newline t))
562 ;;Clean out header stuff
563 (t "")
564 (t "null?"
565 (emt:doc "null? is recognized")
566 (emt:assert
567 (equal answer "#,null?")))
568 ;;Must eval, which right now we don't.
569 (t "(null? '())"
570 (emt:assert
571 (equal answer "#t")))
572 (t "(null? 13)"
573 (emt:assert
574 (equal answer "#f"))))
576 ;;make-encapsulation-type
577 (expect
578 ((exec+args (list debug-klink-executable))
579 (shell t)
580 (prompt "\nklink> ")
581 (timeout 10)
582 (append-newline t))
583 ;;Clean out header stuff
584 (t "")
585 (t "($define! (e p? d) (make-encapsulation-type))"
586 (emt:doc "Make an encapsulation type")
587 (emt:assert
588 (equal answer "#inert")))
589 (t "($define! a (e 12))"
590 (emt:doc "Make an instance of it")
591 (emt:assert
592 (equal answer "#inert")))
593 (t "(p? a)"
594 (emt:doc "The predicate returns true on the instance")
595 (emt:assert
596 (equal answer "#t")))
597 (t "(p? 12)"
598 (emt:assert
599 (equal answer "#f")))
600 (t "(p? a a)"
601 (emt:assert
602 (equal answer "#t")))
603 (t "(p? a #f a)"
604 (emt:assert
605 (equal answer "#f")))
606 (t "(d a)"
607 (emt:doc "`d' retrieves the value")
608 (emt:assert
609 (equal answer "12"))))
611 ;;$if
612 (expect
613 ((exec+args (list debug-klink-executable))
614 (shell t)
615 (prompt "\nklink> ")
616 (timeout 10)
617 (append-newline t))
618 ;;Clean out header stuff
619 (t "")
620 (t "$if"
621 (emt:doc "$if is recognized")
622 (emt:assert
623 (equal answer "#,$if")))
624 (t "($if #t '1 '2)"
625 (emt:doc "On true, evaluates the CONSEQUENT argument")
626 (emt:assert
627 (equal answer "1")))
628 (t "($if #f '1 '2)"
629 (emt:doc "On false, evaluates the ALTERNATIVE argument")
630 (emt:assert
631 (equal answer "2")))
632 (t "($if 3 1 2)"
633 (emt:doc "On non-boolean test, raises error")
634 (emt:assert
635 (emt:eq-persist-p
636 #'equal answer
637 "dbid:80eedbc8-efd5-47c4-9c3b-d0da6c48f768")))
638 (t "($if '#t '1 '2)"
639 (emt:doc "On evaluated true, evaluates the CONSEQUENT argument")
640 (emt:assert
641 (equal answer "1")))
642 (t "($if '#f '1 '2)"
643 (emt:doc "On evaluated false, evaluates the ALTERNATIVE argument")
644 (emt:assert
645 (equal answer "2"))))
646 ;;$cond
647 (expect
648 ((exec+args (list debug-klink-executable))
649 (shell t)
650 (prompt "\nklink> ")
651 (timeout 10)
652 (append-newline t))
653 ;;Clean out header stuff
654 (t "")
655 (t "($cond (#t 12)(#f 13))"
656 (emt:doc "The first true claus is evalled")
657 (emt:assert
658 (equal answer "12")))
659 (t "($cond (#f 13)(#t 12))"
660 (emt:doc "False clauses are skipped")
661 (emt:assert
662 (equal answer "12")))
663 (t "($cond ((integer? 'a) 13)(#t 12))"
664 (emt:doc "Guard clauses are evalled")
665 (emt:assert
666 (equal answer "12")))
667 (t "($cond ((integer? 'a) 13)((integer? 1) 12))"
668 (emt:doc "Guard clauses are evalled")
669 (emt:assert
670 (equal answer "12")))
671 (t "($let ((x 5)) ($cond (#t (list 1 2))))"
672 (emt:doc "The selected clause body is evalled")
673 (emt:assert
674 (equal answer "(1 2)")))
675 (t "($cond)"
676 (emt:doc "$cond with no clauses gives #inert")
677 (emt:assert
678 (equal answer "#inert")))
679 (t "($let ((x 5))
680 ($cond ((integer? x)
681 (display \"x=\")
682 (display x)
683 (newline))))"
684 (emt:doc "Variables are accessible inside clauses")
685 (emt:assert
686 (equal answer "x=5\n#inert"))))
689 (expect
690 ((exec+args (list debug-klink-executable))
691 (shell t)
692 (prompt "\nklink> ")
693 (timeout 10)
694 (append-newline t))
695 ;;Clean out header stuff
696 (t "")
697 (t "(listloop listloop-style-neighbors '(1 2 3) 2)"
698 (emt:doc "Validate that listloop normally works")
699 (emt:assert
700 (equal answer "#<OPERATIVE>")))
701 (t "(listloop listloop-style-neighbors ($lazy '(1 2 3)) #f)"
702 (emt:doc "Validate that listloop will error if it gets the wrong type")
703 (emt:assert
704 (emt:eq-persist-p #'equal answer
705 "dbid:0488e533-76ef-4720-93d5-bfab229c9079")))
706 (t "(listloop listloop-style-neighbors '(1 2 3) ($lazy 2))"
707 (emt:doc "It accepts lazy style arguments")
708 (emt:assert
709 (equal answer "#<OPERATIVE>")))
710 (t "(listloop listloop-style-neighbors ($lazy '(1 2 3)) ($lazy 2))"
711 (emt:doc "It accepts lazy lists")
712 (emt:assert
713 (equal answer "#<OPERATIVE>"))))
715 ;;$sequence
716 (expect
717 ((exec+args (list debug-klink-executable))
718 (shell t)
719 (prompt "\nklink> ")
720 (timeout 10)
721 (append-newline t))
722 ;;Clean out header stuff
723 (t "")
724 (t "($sequence)"
725 (emt:doc "$sequence with no args gives inert")
726 (emt:assert
727 (equal answer "#inert")))
728 (t "($sequence '1)"
729 (emt:doc "Sequence evaluates its args")
730 (emt:assert
731 (equal answer "1")))
732 (t "($sequence '1 '2)"
733 (emt:doc "Sequence returns the value of the last element")
734 (emt:assert
735 (equal answer "2")))
736 (t "($define! my-lam ($lambda v (write v)(newline)))"
737 (emt:doc "Define a lambda having a sequence"))
738 (t "(my-lam 12)"
739 (emt:doc "That lambda evals all the sequence")
740 (emt:assert
741 (equal answer "(12)\n#inert"))))
744 ;;write and display
745 (expect
746 ((exec+args (list debug-klink-executable))
747 (shell t)
748 (prompt "\nklink> ")
749 (timeout 10)
750 (append-newline t))
751 ;;Clean out header stuff
752 (t "")
753 (t "($sequence (write \"abc\") (newline))"
754 (emt:doc "`write' displays objects escaped for read-back")
755 (emt:assert
756 (equal answer "\"abc\"\n#inert")))
757 (t "($sequence (display \"abc\") (newline))"
758 (emt:doc "`display' displays objects unescaped")
759 (emt:assert
760 (equal answer "abc\n#inert")))
761 (t "($sequence (display '(1 2 3)) (newline))"
762 (emt:doc "`display' can display full objects")
763 (emt:assert
764 (equal answer "(1 2 3)\n#inert")))
765 (t "($sequence (write '(1 2 3)) (newline))"
766 (emt:doc "`write' can display full objects")
767 (emt:assert
768 (equal answer "(1 2 3)\n#inert"))))
770 (expect
771 ((exec+args (list debug-klink-executable))
772 (shell t)
773 (prompt "\nklink> ")
774 (timeout 10)
775 (append-newline t))
776 ;;Clean out header stuff
777 (t "")
778 (t "(read)\n12"
779 (emt:doc "Reads numbers")
780 (emt:assert
781 (equal answer "12")))
782 (t "(read)\nsym"
783 (emt:doc "Reads symbols")
784 (emt:assert
785 (equal answer "sym")))
786 (t "(read)\n(1 2 3)"
787 (emt:doc "Reads lists, no problem with nesting depth.")
788 (emt:assert
789 (equal answer "(1 2 3)"))))
792 ;;On typechecking
793 (expect
794 ((exec+args (list debug-klink-executable))
795 (shell t)
796 (prompt "\nklink> ")
797 (timeout 10)
798 (append-newline t))
799 ;;Clean out header stuff
800 (t "")
801 (t "true/o1"
802 (emt:doc "true/o1 predicate is recognized")
803 (emt:assert
804 (equal answer "#,true/o1")
807 (t "(true/o1 1)"
808 (emt:doc "true/o1 predicate gives #t")
809 (emt:assert
810 (equal answer "#t")
812 (t "type?"
813 (emt:doc "`type?' is recognized")
814 (emt:assert
815 (equal answer "#,type?")
818 (t "(type? 1 true/o1)"
819 (emt:doc "`type?' can be called")
820 (emt:assert
821 (equal answer "#t")
823 (t "listtype"
824 (emt:doc "`listtype' ctor is recognized")
825 (emt:assert
826 (equal answer "#,listtype")
828 (t "(listtype true/o1)"
829 (emt:doc "`listtype' makes an operative")
830 (emt:assert
831 (equal answer "#<OPERATIVE>")
833 (t "(listtype true/o1 true/o1)"
834 (emt:doc "`listtype' takes a list of args")
835 (emt:assert
836 (equal answer "#<OPERATIVE>")
838 (t "(type? 1 (listtype true/o1))"
839 (emt:doc "`listtype' makes one that expects a list")
840 (emt:assert
841 (equal answer "#f")
843 (t "(type? '(1) (listtype integer?))"
844 (emt:doc "Second-level listtypes work OK")
845 (emt:assert
846 (equal answer "#t")
848 (t "(type? '(#t) (listtype integer?))"
849 (emt:doc "Second-level listtype discriminate (non)match")
850 (emt:assert
851 (equal answer "#f")
853 (t "(type? '(1) (listtype true/o1 true/o1))"
854 (emt:doc "Situation: Too few elements")
855 (emt:doc "Result: false")
856 (emt:assert
857 (equal answer "#f")
859 (t "(type? '(1) (listtype))"
860 (emt:doc "Situation: Objects has too many elements")
861 (emt:doc "Result: false")
862 (emt:assert
863 (equal answer "#f")
865 (t "(type? '(1) (listtype true/o1 'optional true/o1))"
866 (emt:doc "Situation: Optional elements")
867 (emt:doc "Result: true")
868 (emt:assert
869 (equal answer "#t")
871 (t "(type? '(1 2 3) (listtype true/o1 'optional true/o1))"
872 (emt:doc "Situation: Number of items outruns number of optional elements")
873 (emt:doc "Result: false")
874 (emt:assert
875 (equal answer "#f")
877 (t "(type? '(1) (listtype true/o1 'optional 'optional))"
878 (emt:doc "Situation: Two optional keys given")
879 (emt:doc "Result: error")
880 (emt:assert
881 (emt:eq-persist-p
882 #'equal
883 answer
884 "dbid:e144f830-d6a5-4240-94f0-b0b8a9890d42")))
885 (t "(type? '(1) (listtype true/o1 'DOT))"
886 (emt:doc "Situation: Dot spec has no spec after it")
887 (emt:doc "Result: error")
888 (emt:assert
889 (emt:eq-persist-p #'equal
890 answer
891 "dbid:37a39a99-8b11-4d6f-9e31-033af8d73d41")))
892 (t "(type? '(1) (listtype true/o1 'DOT true/o1 true/o1))"
893 (emt:doc "Situation: Dot spec has more than 1 spec after it")
894 (emt:doc "Result: error")
895 (emt:assert
896 (emt:eq-persist-p #'equal
897 answer
898 "dbid:7f057673-3b94-4e4c-a25c-b09ed5239af2")))
899 (t "(type? '(1 2 3) (listtype true/o1 'DOT true/o1))"
900 (emt:doc "Situation: Dot spec is satisfied")
901 (emt:doc "Result: true")
902 (emt:assert
903 (equal answer "#t")
905 (t "(type? '(1 2 3) (listtype true/o1 'DOT integer?))"
906 (emt:doc "Situation: Dot spec is reached but doesn't match")
907 (emt:doc "Result: false")
908 (emt:assert
909 (equal answer "#f")
911 (t "(type? '(1 2 3) (listtype true/o1 'REPEAT integer?))"
912 (emt:doc "Situation: Repeat spec is used and matches")
913 (emt:doc "Result: true")
914 (emt:assert
915 (equal answer "#t")
917 (t "(type? '(1 2 #t) (listtype true/o1 'REPEAT integer?))"
918 (emt:doc "Situation: Repeat spec is used but doesn't match")
919 (emt:doc "Result: false")
920 (emt:assert
921 (equal answer "#f")
923 (t "(type? '(1 2 #t 4 #t) (listtype true/o1 'REPEAT integer? true/o1))"
924 (emt:doc "Situation: Repeat spec is used, has 2 items, matches")
925 (emt:doc "Result: true")
926 (emt:assert
927 (equal answer "#t")
929 (t "(type? '(1 2 #t 4 #t) (listtype true/o1 'REPEAT true/o1 integer?))"
930 (emt:doc "Situation: Repeat spec is used, has 2 items, but doesn't match")
931 (emt:doc "Result: false")
932 (emt:assert
933 (equal answer "#f")
935 (t "(type? '(1) (listtype true/o1 'REPEAT integer?))"
936 (emt:doc "Situation: Repeat spec is used, zero items available")
937 (emt:doc "Result: true")
938 (emt:assert
939 (equal answer "#t")
941 ;; $$IMPROVE ME Test circularity, use encycle!
944 ;;On destructuring
945 (expect
946 ((exec+args (list debug-klink-executable))
947 (shell t)
948 (prompt "\nklink> ")
949 (timeout 10)
950 (append-newline t))
951 ;;Clean out header stuff
952 (t "")
954 (t "destructure-list"
955 (emt:doc "Test `destructure-list'")
956 (emt:doc "ctor is recognized")
957 (emt:assert
958 (equal answer "#,destructure-list")
960 (t "(destructure-list true/o1)"
961 (emt:doc "It makes an operative")
962 (emt:assert
963 (equal answer "#<OPERATIVE>")
965 (t "(destructure-list true/o1 true/o1)"
966 (emt:doc "It takes a list of args")
967 (emt:assert
968 (equal answer "#<OPERATIVE>")
970 (t "(do-destructure 1 true/o1)"
971 (emt:doc "do-destructure can take just a combiner as arg")
972 (emt:assert
973 (equal answer "#( 1)")))
974 (t "(do-destructure 1 (destructure-list true/o1))"
975 (emt:doc "It makes one that expects a list")
976 (emt:doc "Result: Error")
977 (emt:assert
978 (emt:eq-persist-p #'equal
979 answer
980 "dbid:3e113873-73a0-46f5-8e14-f41034780317")))
981 (t "(do-destructure '(1) (destructure-list integer?))"
982 (emt:doc "Second-level destructures work OK")
983 (emt:assert
984 (equal answer "#( 1)")
986 (t "(do-destructure '(#t) (destructure-list integer?))"
987 (emt:doc "Second-level destructure discriminate (non)match")
988 (emt:doc "Result: Error")
989 (emt:assert
990 (emt:eq-persist-p #'equal
991 answer
992 "dbid:dc2648ef-22cb-41c2-8f9b-67548b0a3b7a")))
993 (t "(do-destructure '(1) (destructure-list true/o1 true/o1))"
994 (emt:doc "Situation: Too few elements")
995 (emt:doc "Result: Error")
996 (emt:assert
997 (emt:eq-persist-p
998 #'equal
999 answer
1000 "dbid:b50e8f78-6652-418d-9b44-1ff676946970")))
1001 (t "(do-destructure '(1) (destructure-list))"
1002 (emt:doc "Situation: Objects has too many elements")
1003 (emt:doc "Result: Error")
1004 (emt:assert
1005 (emt:eq-persist-p
1006 #'equal
1007 answer
1008 "dbid:ee168f5d-5d87-4792-9dba-0fd0ac7c14a4")))
1010 (t "(do-destructure '(1) (destructure-list true/o1 'optional true/o1))"
1011 (emt:doc "Situation: Optional elements")
1012 (emt:doc "Result: true")
1013 (emt:assert
1014 (equal answer "#( 1 #inert)")
1017 (t "(do-destructure '(1 2 3) (destructure-list true/o1 'optional true/o1))"
1018 (emt:doc "Situation: Number of items outruns number of optional elements")
1019 (emt:doc "Result: Error")
1020 (emt:assert
1021 (emt:eq-persist-p #'equal answer
1022 "dbid:a1bd1321-532e-4187-af64-278c009a7f97")))
1024 (t "(do-destructure '(1) (destructure-list true/o1 'optional 'optional))"
1025 (emt:doc "Situation: Two optional keys given")
1026 (emt:doc "Result: Error")
1027 (emt:assert
1028 (emt:eq-persist-p
1029 #'equal
1030 answer
1031 "dbid:ece901d5-4ac0-496e-a9e2-83423a933522")))
1033 (t "(do-destructure '(1) (destructure-list true/o1 'dot))"
1034 (emt:doc "Situation: Dot spec has no spec after it")
1035 (emt:doc "Result: Error")
1036 (emt:assert
1037 (emt:eq-persist-p #'equal
1038 answer
1039 "dbid:8e8711ba-bada-4223-a212-3256d6a2e497")))
1041 (t "(do-destructure '(1) (destructure-list true/o1 'dot true/o1 true/o1))"
1042 (emt:doc "Situation: Dot spec has more than 1 spec after it")
1043 (emt:doc "Result: Error")
1044 (emt:assert
1045 (emt:eq-persist-p #'equal
1046 answer
1047 "dbid:4d68ceb6-f450-4218-b222-c10019a39819")))
1049 (t "(do-destructure '(1 2 3) (destructure-list true/o1 'dot true/o1))"
1050 (emt:doc "Situation: Dot spec is satisfied")
1051 (emt:doc "Result: true")
1052 (emt:assert
1053 (equal answer "#( 1 (2 3))")
1056 (t "(do-destructure '(1 2 3) (destructure-list true/o1 'dot integer?))"
1057 (emt:doc "Situation: Dot spec is reached but doesn't match")
1058 (emt:doc "Result: Error")
1059 (emt:assert
1060 (emt:eq-persist-p #'equal answer
1061 "dbid:266cbd1e-734c-4a81-bac6-e9d9a3424e79")))
1063 (t "(do-destructure '(1) 13)"
1064 (emt:doc "Fails gracefully when given a non-combiner")
1065 (emt:assert
1066 (emt:eq-persist-p
1067 #'equal answer
1068 "dbid:2492173b-e70f-460d-87a0-da1aff73d22e")))
1069 (t "(do-destructure 1 ($lambda (x) (true/o1 x)))"
1070 (emt:doc "Accepts combiners that use the main loop")
1071 (emt:assert
1072 (equal answer "#( 1)")))
1073 (t "(do-destructure '(1) (destructure-list ($vau (x) #ignore (true/o1 x))))"
1074 (emt:assert
1075 (equal answer "#( 1)"))))
1077 ;;On define-type destructuring
1078 (expect
1079 ((exec+args (list debug-klink-executable))
1080 (shell t)
1081 (prompt "\nklink> ")
1082 (timeout 10)
1083 (append-newline t))
1084 ;;Clean out header stuff
1085 (t "")
1086 (t "($define! (a b) ($lazy '(12 144)))"
1087 (emt:doc "Define with a lazy value")
1088 (emt:assert
1089 (equal answer "#inert")))
1090 (t "a"
1091 (emt:doc "A has been defined")
1092 (emt:assert
1093 (equal answer "12")))
1094 (t "b"
1095 (emt:doc "B has been defined")
1096 (emt:assert
1097 (equal answer "144")))
1098 (t "($define! ((a b)(c d)) (list ($lazy '(20736 1728))($lazy '(144 12))))"
1099 (emt:doc "Define with multiple lazy values")
1100 (emt:assert
1101 (equal answer "#inert")))
1102 (t "a"
1103 (emt:doc "A has been changed")
1104 (emt:assert
1105 (equal answer "20736")))
1106 (t "b"
1107 (emt:assert
1108 (equal answer "1728")))
1109 (t "c"
1110 (emt:assert
1111 (equal answer "144")))
1112 (t "d"
1113 (emt:assert
1114 (equal answer "12")))
1115 (t "((wrap ($vau ((a b)) #ignore (list a b))) '(144 12))"
1116 (emt:doc "Validate: Without laziness, vau works as expected")
1117 (emt:assert
1118 (equal answer "(144 12)")))
1119 (t "((wrap ($vau ((a b)) #ignore (list a b))) ($lazy '(144 12)))"
1120 (emt:doc "Handles laziness too")
1121 (emt:assert
1122 (equal answer "(144 12)")))
1123 (t "((wrap ($vau ((a b)(c d)) #ignore (list a b c d))) '(20736 1728) '(144 12))"
1124 (emt:assert
1125 (equal answer "(20736 1728 144 12)")))
1126 (t "((wrap ($vau ((a b)(c d)) #ignore (list a b c d)))
1127 ($lazy '(20736 1728))
1128 ($lazy '(144 12)))"
1129 (emt:doc "Handles nested and double-lazy too")
1130 (emt:assert
1131 (equal answer "(20736 1728 144 12)")))
1132 (t "((wrap ($vau ((a b)) #ignore (list a b))) ($lazy 144))"
1133 (emt:doc "Error on values that don't fit even when forced")
1134 (emt:assert
1135 (emt:eq-persist-p #'equal answer
1136 "dbid:6928bebb-0876-448c-9a9b-f72410c94422")))
1137 (t "((wrap ($vau ((a b (c d))) #ignore (list a b c d)))
1138 ($lazy (list 20736 1728 ($lazy '(144 12)))))"
1139 (emt:doc "Works even on nested promises")
1140 (emt:assert
1141 (equal answer "(20736 1728 144 12)"))))
1144 ;;On where-typemiss
1145 (expect
1146 ((exec+args (list debug-klink-executable))
1147 (shell t)
1148 (prompt "\nklink> ")
1149 (timeout 10)
1150 (append-newline t))
1151 ;;Clean out header stuff
1152 (t "")
1154 (t "(where-typemiss 1 (listtype true/o1))"
1155 (emt:doc "`listtype' makes one that expects a list")
1156 (emt:assert
1157 (equal answer "(0 too-few)")
1159 (t "(where-typemiss '(#t) (listtype integer?))"
1160 (emt:doc "Second-level listtype discriminate (non)match")
1161 ;;Use persist because the form of the printout changes.
1162 (emt:assert
1163 (emt:eq-persist-p #'equal answer
1164 "dbid:cc211ae0-718b-4462-9062-7f0077cdf162")))
1165 (t "(where-typemiss '(1) (listtype true/o1 true/o1))"
1166 (emt:doc "Situation: Too few elements")
1167 (emt:assert
1168 (equal answer "(1 too-few)")
1170 (t "(where-typemiss '(1) (listtype))"
1171 (emt:doc "Situation: Objects has too many elements")
1172 (emt:assert
1173 (equal answer "(0 too-many)")
1175 (t "(where-typemiss '(1 2 3) (listtype true/o1 'optional true/o1))"
1176 (emt:doc "Situation: Number of items outruns number of optional elements")
1177 (emt:assert
1178 (equal answer "(2 too-many)")
1180 (t "(where-typemiss '(1 2 3) (listtype true/o1 'dot integer?))"
1181 (emt:doc "Situation: Dot spec is reached but doesn't match")
1182 (emt:assert
1183 (emt:eq-persist-p #'equal answer
1184 "dbid:2f83b114-6bdf-4c7d-9a76-0d3e8b43483c")))
1185 (t "(where-typemiss '(1 2 #t) (listtype true/o1 'repeat integer?))"
1186 (emt:doc "Situation: Repeat spec is used but doesn't match")
1187 (emt:assert
1188 (emt:eq-persist-p #'equal answer
1189 "dbid:f90a1f49-9180-4817-8095-6422ee058745")))
1190 (t "(where-typemiss '(1 2 #t 4 #t) (listtype true/o1 'repeat true/o1 integer?))"
1191 (emt:doc "Situation: Repeat spec is used, has 2 items, but doesn't match")
1192 (emt:assert
1193 (emt:eq-persist-p #'equal answer
1194 "dbid:374c6ab3-7907-4ff5-b14d-e41584593296")))
1195 ;; $$IMPROVE ME Test circularity, use encycle!
1198 ;;On get-list-metrics
1199 (expect
1200 ((exec+args (list debug-klink-executable))
1201 (shell t)
1202 (prompt "\nklink> ")
1203 (timeout 10)
1204 (append-newline t))
1205 ;;Clean out header stuff
1206 (t "")
1207 (t "(length '(0 1))"
1208 (emt:assert
1209 (equal answer "2")))
1210 (t "(finite-list? '(0 1))"
1211 (emt:assert
1212 (equal answer "#t")))
1213 (t "(finite-list? #f)"
1214 (emt:assert
1215 (equal answer "#f")))
1216 (t "(get-list-metrics '(0 1))"
1217 (emt:assert
1218 (equal answer "(2 1 2 0)")))
1219 (t "(get-list-metrics #f)"
1220 (emt:assert
1221 (equal answer "(0 0 0 0)")))
1222 (t "(get-list-metrics '(0 . 1))"
1223 (emt:assert
1224 (equal answer "(1 0 1 0)")))
1225 (t "($define! a (list 12))"
1226 (emt:doc "Make a circular object"))
1227 (t "(set-cdr! a a)")
1228 (t "(get-list-metrics a)"
1229 (emt:doc "List metrics of a circular object")
1230 (emt:assert
1231 (equal answer "(1 0 0 1)")))
1236 ;;On making environment
1237 (expect
1238 ((exec+args (list debug-klink-executable))
1239 (shell t)
1240 (prompt "\nklink> ")
1241 (timeout 10)
1242 (append-newline t))
1243 ;;Clean out header stuff
1244 (t "")
1245 (t "(make-environment (get-current-environment))"
1246 (emt:doc "Can make an environment")
1247 (emt:assert
1248 (equal answer "#<ENVIRONMENT>")))
1249 (t "(make-environment)"
1250 (emt:doc "Can make an empty environment")
1251 (emt:assert
1252 (equal answer "#<ENVIRONMENT>")))
1254 (t "(eval 'make-environment (make-environment))"
1255 (emt:doc "Empty environment does not bind things")
1256 (emt:assert
1257 (emt:eq-persist-p
1258 #'equal answer "dbid:930c9cb4-c8e3-446a-9d0f-80a7a01edf2e")))
1260 (t "($define! env1 (make-environment))"
1261 (emt:doc "Define example environments")
1262 (emt:assert
1263 (equal answer "#inert")))
1264 (t "($define! env2 (make-environment))"
1265 (emt:assert
1266 (equal answer "#inert")))
1267 (t "($set! env1 a 12)"
1268 (emt:doc "Define things in those example environments")
1269 (emt:assert
1270 (equal answer "#inert")))
1271 (t "($set! env2 b 144)"
1272 (emt:assert
1273 (equal answer "#inert")))
1274 (t "(eval 'a env1)"
1275 (emt:doc "The respective bindings are available in the environments")
1276 (emt:assert
1277 (equal answer "12")))
1278 (t "(eval 'b env2)"
1279 (emt:assert
1280 (equal answer "144")))
1281 (t "($define! env1+2 (make-environment env1 env2))"
1282 (emt:doc "Can make an environment from multiple parents")
1283 (emt:assert
1284 (equal answer "#inert")))
1285 (t "(eval 'a env1+2)"
1286 (emt:doc "It contains the bindings of both environments")
1287 (emt:assert
1288 (equal answer "12")))
1289 (t "(eval 'b env1+2)"
1290 (emt:assert
1291 (equal answer "144"))))
1293 (expect
1294 ((exec+args (list debug-klink-executable))
1295 (shell t)
1296 (prompt "\nklink> ")
1297 (timeout 10)
1298 (append-newline t))
1299 (t "")
1300 (t "(reverse-lookup get-current-environment (get-current-environment))"
1301 (emt:doc "Operation: look up an object we know is bound")
1302 (emt:doc "Result: We find it")
1303 (emt:assert
1304 (equal answer "get-current-environment")))
1305 (t "(reverse-lookup reverse-lookup (get-current-environment))"
1306 (emt:doc "Same on another object")
1307 (emt:assert
1308 (equal answer "reverse-lookup")))
1309 (t "(reverse-lookup 'example-unsymboled-object (get-current-environment))"
1310 (emt:doc "Operation: look up an object we know is not bound")
1311 (emt:doc "Result: Error")
1312 (emt:assert
1313 (emt:eq-persist-p #'equal answer
1314 "dbid:c3ec8dcc-39b2-4885-b4f3-f6e5f018c11e")))
1315 (t "($define! a (list))"
1316 (emt:doc "Make an object we will look for"))
1317 (t "($define! my-env (make-environment))")
1318 (t "($set! my-env b a)"
1319 (emt:doc "In my-env, define b as that object"))
1320 (t "($set! my-env b 13)"
1321 (emt:doc "Now define b as something else"))
1322 (t "(reverse-lookup a my-env)"
1323 (emt:doc "Look up the original object")
1324 (emt:assert
1325 (emt:eq-persist-p
1326 #'equal answer
1327 "dbid:673c63c9-1844-4c7f-b67d-22c6ef88fc66")))
1328 (t "($define! my-env2 (make-environment))"
1329 (emt:doc "Make another empty environment"))
1330 (t "($set! my-env2 c a)"
1331 (emt:doc "In my-env2, define c as that object"))
1332 (t "($set! my-env2 b a)"
1333 (emt:doc "In my-env2, define b as that object"))
1334 (t "($set! my-env2 b 13)"
1335 (emt:doc "Now define b as something else"))
1336 (t "(reverse-lookup a my-env2)"
1337 (emt:doc "Operation: Look up the original object")
1338 (emt:doc "Result: We find its binding, c")
1339 (emt:assert
1340 (equal answer "c")))
1341 (t "($set! my-env2 b a)"
1342 (emt:doc "Define b as that object again"))
1343 (t "($define! my-env3 (make-environment my-env2))"
1344 (emt:doc "Make an environment derived from my-env2"))
1345 (t "($set! my-env3 b 13)"
1346 (emt:doc "There set b to be something else"))
1347 (t "(reverse-lookup a my-env3)"
1348 (emt:doc "Operation: Look up the original object")
1349 (emt:doc "Result: We find its binding")
1350 (emt:assert
1351 (equal answer "c"))))
1353 ;;On printing, esp circular objects
1354 (expect
1355 ((exec+args (list debug-klink-executable))
1356 (shell t)
1357 (prompt "\nklink> ")
1358 (timeout 10)
1359 (append-newline t))
1361 (t "")
1362 (t "print-lookup-env"
1363 (emt:assert
1364 (equal answer "#,print-lookup-env"))
1366 (t "(list 1 2)"
1367 (emt:doc "Lists print OK")
1368 (emt:assert
1369 (equal answer "(1 2)")))
1370 (t "wrap"
1371 (emt:doc "Bound objects print a lowquote and their binding")
1372 (emt:assert
1373 (equal answer "#,wrap")))
1374 (t "list"
1375 (emt:assert
1376 (equal answer "#,list")))
1377 (t "(list list)"
1378 (emt:doc "These objects are actual working combiners.")
1379 (emt:assert
1380 (equal answer "(#,list)")))
1384 ;;On get-recurrences
1385 (expect
1386 ((exec+args (list debug-klink-executable))
1387 (shell t)
1388 (prompt "\nklink> ")
1389 (timeout 10)
1390 (append-newline t))
1392 (t "")
1393 (t "($define! cycles-nil (get-recurrences '()))"
1394 (emt:doc "`cycles-nil' is the recurrences of object '()"))
1395 (t "(recurrence-table? cycles-nil)"
1396 (emt:assert
1397 (equal answer "#t")))
1398 ;; $$RECONSIDER ME
1399 (t "(recurrences-get-object-count cycles-nil '())"
1400 (emt:doc "Nils are not counted")
1401 (emt:assert
1402 (equal answer "0")))
1403 (t "($define! cycles-list (get-recurrences (list 12 144)))"
1404 (emt:doc "`cycles-list' is the recurrences of an ordinary list"))
1405 (t "(recurrence-table? cycles-list)"
1406 (emt:assert
1407 (equal answer "#t")))
1408 (t "($define! cycles-many-nils (get-recurrences '()))"
1409 (emt:doc "`cycles-many-nils' is the recurrences of object of
1410 multiple nils"))
1411 (t "(recurrence-table? cycles-many-nils)"
1412 (emt:assert
1413 (equal answer "#t")))
1414 (t "(recurrences-get-object-count cycles-many-nils '())"
1415 (emt:doc "Nils do not constitute shared objects")
1416 (emt:assert
1417 (equal answer "0")))
1418 (t "($define! cycles-f (get-recurrences '(#f #f)))"
1419 (emt:doc "Get the recurrences of any object with repeated objects"))
1420 (t "(recurrence-table? cycles-f)"
1421 (emt:assert
1422 (equal answer "#t")))
1423 (t "(recurrences-get-object-count cycles-f #f)"
1424 (emt:assert
1425 (equal answer "2")))
1426 (t "($define! a (list 12))"
1427 (emt:doc "Define a circular object"))
1428 (t "(set-cdr! a a)")
1429 (t "($define! cycles-a (get-recurrences a))")
1430 (t "(recurrence-table? cycles-a)"
1431 (emt:assert
1432 (equal answer "#t")))
1433 (t "(recurrences-get-object-count cycles-a a)"
1434 (emt:assert
1435 (equal answer "2"))))
1437 ;;On lists and wrapping
1438 (expect
1439 ((exec+args (list debug-klink-executable))
1440 (shell t)
1441 (prompt "\nklink> ")
1442 (timeout 10)
1443 (append-newline t))
1444 (t "")
1445 (t "(list 1 2)"
1446 (emt:doc "List works")
1447 (emt:assert
1448 (equal answer "(1 2)")))
1449 (t "(reverse (list 1 2))"
1450 (emt:doc "Reverse works")
1451 (emt:assert
1452 (equal answer "(2 1)")))
1453 (t "((wrap list) 1 2)"
1454 (emt:doc "Wrap wrapped over an applicative works (wrap^2)")
1455 (emt:assert
1456 (equal answer "(1 2)")))
1457 (t "((wrap list) '1 '2)"
1458 (emt:doc "Wrap^2 eliminates at least one level of quoting")
1459 (emt:assert
1460 (equal answer "(1 2)")))
1461 (t "((wrap list) ''1 ''2)"
1462 (emt:doc "Wrap^2 eliminates two levels of quoting")
1463 (emt:assert
1464 (equal answer "(1 2)")))
1465 (t "((wrap list) '''1 '''2)"
1466 (emt:doc "Wrap^2 leaves one of three levels of quoting")
1467 (emt:assert
1468 (equal answer "((#,$quote 1) (#,$quote 2))")))
1469 (t "((wrap (wrap list)) '''1 '''2)"
1470 (emt:doc "Wrap^3 eliminates three levels of quoting")
1471 (emt:assert
1472 (equal answer "(1 2)"))))
1474 ;;On map, map1, counted-map/4
1475 (expect
1476 ((exec+args (list debug-klink-executable))
1477 (shell t)
1478 (prompt "\nklink> ")
1479 (timeout 10)
1480 (append-newline t))
1481 (t "")
1482 (t "(map1 list '(1 2 3))"
1483 (emt:doc "It works")
1484 (emt:assert
1485 (equal answer "((1) (2) (3))")))
1486 (t "(map1 (unwrap list) '(1 2 3))"
1487 (emt:doc "It wants an applicative argument")
1488 (emt:assert
1489 (emt:eq-persist-p #'equal
1490 answer
1491 "dbid:bf93cc1e-534c-4a1f-8762-3072e59dcb3c")))
1492 (t "(counted-map/4 2 1 list '((1 2)))"
1493 (emt:doc "Generally behaves like `map'")
1494 (emt:assert
1495 (equal answer "((1) (2))")))
1496 (t "(counted-map/4 1 1 list '((1 2)))"
1497 (emt:doc "Stops after N elements")
1498 (emt:assert
1499 (equal answer "((1))")))
1500 (t "(counted-map/4 2 2 list '((1 2) (11 12)))"
1501 (emt:doc "Can treat multiple lists")
1502 (emt:assert
1503 (equal answer "((1 11) (2 12))")))
1504 (t "(map list '(1 2))"
1505 (emt:doc "Check full `map'")
1506 (emt:assert
1507 (equal answer "((1) (2))")))
1508 (t "(map list '(1 2) '(11 12))"
1509 (emt:assert
1510 (equal answer "((1 11) (2 12))"))))
1512 ;;On continuations
1513 (expect
1514 ((exec+args (list debug-klink-executable))
1515 (shell t)
1516 (prompt "\nklink> ")
1517 (timeout 10)
1518 (append-newline t))
1519 (t "")
1520 (t "($define! my-con-list (call/cc list))"
1521 (emt:doc "Make an object containing a continuation"))
1522 (t "my-con-list"
1523 (emt:doc "Check what we got")
1524 (emt:assert
1525 (equal answer "(#<CONTINUATION>)")))
1526 (t "($define! my-con (car my-con-list))"
1527 (emt:doc "Extract that continuation"))
1528 (t "my-con"
1529 (emt:doc "Check what we got")
1530 (emt:assert
1531 (equal answer "#<CONTINUATION>")))
1532 (t "(continuation->applicative my-con)"
1533 (emt:doc "Try a simple call")
1534 (emt:assert
1535 (equal answer "#<APPLICATIVE>")))
1536 (t "((continuation->applicative my-con) 12)"
1537 (emt:doc "Use the continuation")
1538 (emt:assert
1539 (equal answer "#inert")))
1540 (t "my-con-list"
1541 (emt:doc "my-con-list got redefined by the continuation")
1542 (emt:assert
1543 (equal answer "(12)")))
1544 (t "(apply (continuation->applicative (extend-continuation my-con
1545 ($lambda v
1546 (display \"arrived at the continuation with \")
1547 (write v)
1548 (newline)))) '(144))"
1549 (emt:assert
1550 (equal answer
1551 "arrived at the continuation with (144)\n#inert")))
1552 (t "($define! my-unguarded-con (guard-continuation '() my-con '()))"
1553 (emt:doc "Make a continuation that has empty list of guards")
1554 (emt:assert
1555 (equal answer "#inert")))
1556 (t "(apply (continuation->applicative my-unguarded-con) '(145))"
1557 (emt:doc "Applies without problem")
1558 (emt:assert
1559 (equal answer "#inert")))
1560 (t "my-con-list"
1561 (emt:doc "The continuation got called")
1562 (emt:assert
1563 (equal answer "(145)")))
1565 (t "($define! my-guarded-con (guard-continuation
1566 (list (list root-continuation
1567 ($lambda (v %ignore)
1568 (display \"entering the continuation with \")
1569 (write v)
1570 (newline)
1571 v)))
1572 my-con
1573 (list (list root-continuation
1574 ($lambda (v %ignore)
1575 (display \"exiting the continuation with \")
1576 (write v)
1577 (newline)
1578 v)))))"
1579 (emt:doc "Create a guarded continuation")
1580 (emt:assert
1581 (equal answer "#inert")))
1582 (t "my-guarded-con"
1583 (emt:doc "Type is correct")
1584 (emt:assert
1585 (equal answer "#<CONTINUATION>")))
1586 (t "(continuation->applicative my-guarded-con)"
1587 (emt:doc "Type is correct")
1588 (emt:assert
1589 (equal answer "#<APPLICATIVE>")))
1590 (t "(apply (continuation->applicative my-guarded-con) '(146))"
1591 (emt:doc "We see it calls the guard and continues")
1592 (emt:assert
1593 (equal answer "entering the continuation with (146)\n#inert")))
1594 (t "my-con-list"
1595 (emt:doc "The continuation got called")
1596 (emt:assert
1597 (equal answer "(146)")))
1598 (t "(guard-dynamic-extent
1599 '()
1600 ($lambda () (display \"Got here\")(newline))
1601 '())"
1602 (emt:doc "Calls the combiner arg with no variables")
1603 (emt:assert
1604 (equal answer "Got here\n#inert")))
1605 (t "(guard-dynamic-extent
1606 (list (list root-continuation ($lambda (v %ignore)
1607 (display \"Abnormally entering dynamic extent.\")
1608 (newline)
1609 v)))
1610 ($lambda () (display \"Got here\")(newline))
1611 '())"
1612 (emt:doc "Does not initially call the entry guards")
1613 (emt:assert
1614 (equal answer "Got here\n#inert")))
1615 (t "(guard-dynamic-extent
1616 '()
1617 ($lambda () (display \"Got here\")(newline))
1618 (list (list root-continuation ($lambda (v %ignore)
1619 (display \"Abnormally entering dynamic extent.\")
1620 (newline)
1621 v))))"
1622 (emt:doc "Does not initially call the exit guards")
1623 (emt:assert
1624 (equal answer "Got here\n#inert"))))
1628 ;;On `and?' etc
1629 (expect
1630 ((exec+args (list debug-klink-executable))
1631 (shell t)
1632 (prompt "\nklink> ")
1633 (timeout 10)
1634 (append-newline t))
1635 (t "")
1636 (t "and?"
1637 (emt:doc "Is recognized")
1638 (emt:assert
1639 (equal answer "#,and?")))
1640 (t "(and?)"
1641 (emt:doc "Given no args, returns true")
1642 (emt:assert
1643 (equal answer "#t")))
1644 (t "(and? #t)"
1645 (emt:doc "Accepts 1 arg")
1646 (emt:assert
1647 (equal answer "#t")))
1648 (t "(and? #t #t)"
1649 (emt:doc "Accepts 2 args")
1650 (emt:assert
1651 (equal answer "#t")))
1652 (t "(and? #t #f)"
1653 (emt:doc "If an arg is false, returns false")
1654 (emt:assert
1655 (equal answer "#f")))
1656 (t "(and? #t (integer? 1))"
1657 (emt:doc "Arguments are evaluated")
1658 (emt:assert
1659 (equal answer "#t")))
1660 (t "(and? #t (integer? \"11\"))"
1661 (emt:doc "The evaluated value is used")
1662 (emt:assert
1663 (equal answer "#f")))
1664 (t "(or? #f)"
1665 (emt:doc "If there are only false clauses, returns false")
1666 (emt:assert
1667 (equal answer "#f")))
1668 (t "(or? #f #t)"
1669 (emt:doc "If there is any true clause, return true")
1670 (emt:assert
1671 (equal answer "#t")))
1672 (t "(or? #f #t #f)"
1673 (emt:assert
1674 (equal answer "#t")))
1675 (t "($and?)"
1676 (emt:doc "The evaluating variant")
1677 (emt:assert
1678 (equal answer "#t")))
1679 (t "($and? #t #f)"
1680 (emt:assert
1681 (equal answer "#f")))
1682 (t "($and? #f #t)"
1683 (emt:assert
1684 (equal answer "#f")))
1685 (t "($and? ($sequence (display \"One\")(newline) #f))"
1686 (emt:doc "Evaluates some of its args, at least the first one")
1687 (emt:assert
1688 (equal answer "One\n#f")))
1689 (t "($and? ($sequence (display \"One\")(newline) #t)($sequence (display \"Two\")(newline) #f))"
1690 (emt:assert
1691 (equal answer "One\nTwo\n#f")))
1692 (t "($and? ($sequence (display \"One\")(newline) #f)($sequence (display \"Two\")(newline) #f))"
1693 (emt:assert
1694 (equal answer "One\n#f")))
1695 (t "(every?/2-xary and? '())"
1696 (emt:doc "xary-1 `every?/2-xary' is available (in `simple' environment)")
1697 (emt:assert
1698 (equal answer "#t")))
1699 (t "(every?/2-xary and? '(()))"
1700 (emt:doc "No elements")
1701 (emt:assert
1702 (equal answer "#t")))
1703 (t "(every?/2-xary and? '((#f)))"
1704 (emt:doc "One element containing one element (for `and?')")
1705 (emt:assert
1706 (equal answer "#f")))
1707 (t "(every?/2-xary and? '((#t #t)))"
1708 (emt:doc "More elements")
1709 (emt:assert
1710 (equal answer "#t")))
1711 (t "(every?/2-xary and? '((#t #t)(#t)))"
1712 (emt:assert
1713 (equal answer "#t")))
1714 (t "(every?/2-xary and? '((#t #t)(#f)))"
1715 (emt:assert
1716 (equal answer "#f"))))
1719 (expect
1720 ((exec+args (list debug-klink-executable))
1721 (shell t)
1722 (prompt "\nklink> ")
1723 (timeout 10)
1724 (append-newline t))
1725 (t "")
1726 (t "(>? 1 0)"
1727 (emt:doc "Test that comparisons work as expected")
1728 (emt:assert
1729 (equal answer "#t")))
1730 (t "(>? 1 1)"
1731 (emt:assert
1732 (equal answer "#f")))
1733 (t "(>? 1 2)"
1734 (emt:assert
1735 (equal answer "#f")))
1736 (t "(<? 1 0)"
1737 (emt:assert
1738 (equal answer "#f")))
1739 (t "(<? 1 1)"
1740 (emt:assert
1741 (equal answer "#f")))
1742 (t "(<? 1 2)"
1743 (emt:assert
1744 (equal answer "#t")))
1745 (t "(>=? 1 0)"
1746 (emt:assert
1747 (equal answer "#t")))
1748 (t "(>=? 1 1)"
1749 (emt:assert
1750 (equal answer "#t")))
1751 (t "(>=? 1 2)"
1752 (emt:assert
1753 (equal answer "#f")))
1754 (t "(<=? 1 0)"
1755 (emt:assert
1756 (equal answer "#f")))
1757 (t "(<=? 1 1)"
1758 (emt:assert
1759 (equal answer "#t")))
1760 (t "(<=? 1 2)"
1761 (emt:assert
1762 (equal answer "#t")))
1763 (t "(compare-neighbors <? '(0 1 2))"
1764 (emt:assert
1765 (equal answer "#t")))
1766 (t "(compare-neighbors <? '(0))"
1767 (emt:assert
1768 (equal answer "#t")))
1769 (t "(compare-neighbors <=? '(0 1 2))"
1770 (emt:assert
1771 (equal answer "#t")))
1772 (t "(compare-neighbors <? '(0 1 1 2))"
1773 (emt:assert
1774 (equal answer "#f")))
1775 (t "(compare-neighbors <=? '(0 1 1 2))"
1776 (emt:assert
1777 (equal answer "#t"))))
1780 (expect
1781 ((exec+args (list debug-klink-executable))
1782 (shell t)
1783 (prompt "\nklink> ")
1784 (timeout 10)
1785 (append-newline t))
1786 (t "")
1787 (t "(+ 1 2 3)"
1788 (emt:doc "N-ary addition works")
1789 (emt:assert
1790 (equal answer "6")))
1791 (t "(+ 1 2 (+ 3 0))"
1792 (emt:doc "N-ary addition evaluates its arguments")
1793 (emt:assert
1794 (equal answer "6")))
1795 (t "(+)"
1796 (emt:doc "N-ary addition gives 0 on no operands")
1797 (emt:assert
1798 (equal answer "0")))
1799 (t "(+ 3)"
1800 (emt:doc "N-ary addition with 1 operand works")
1801 (emt:assert
1802 (equal answer "3")))
1804 (t "(* 1 2 30)"
1805 (emt:doc "N-ary multiplication works")
1806 (emt:assert
1807 (equal answer "60")))
1808 (t "(* 1 2 (* 3 10))"
1809 (emt:doc "N-ary multiplication evaluates its arguments")
1810 (emt:assert
1811 (equal answer "60")))
1812 (t "(*)"
1813 (emt:doc "N-ary multiplication gives 0 on no operands")
1814 (emt:assert
1815 (equal answer "1")))
1816 (t "(* 3)"
1817 (emt:doc "N-ary multiplication with 1 operand works")
1818 (emt:assert
1819 (equal answer "3")))
1820 (t "(/ 2 2)"
1821 (emt:doc "Dividing an integer by itself gives 1")
1822 (emt:assert
1823 (equal answer "1")))
1824 (t "(/ 2 1)"
1825 (emt:doc "Dividing an integer by 1 gives itself")
1826 (emt:assert
1827 (equal answer "2")))
1828 (t "(/ 1.0 2.0)"
1829 (emt:doc "For real division, it doesn't floor")
1830 (emt:assert
1831 (equal answer "0.5")))
1832 (t "(/ 6 3)"
1833 (emt:assert
1834 (equal answer "2")))
1835 (t "(/ 6 3 2)"
1836 (emt:assert
1837 (equal answer "1")))
1838 (t "(/ 6 3 2 2)"
1839 (emt:assert
1840 (equal answer "0.5")))
1841 (t "(- 100 20)"
1842 (emt:assert
1843 (equal answer "80")))
1844 (t "(- 100 20 5)"
1845 (emt:assert
1846 (equal answer "75")))
1847 (t "(- 100)"
1848 (emt:doc "`-' with no subtrahends raises error")
1849 (emt:assert
1850 (emt:eq-persist-p #'equal answer
1851 "dbid:d0afc822-58f7-4921-b37d-57d45cd6b5e0")))
1852 (t "(/ 6)"
1853 (emt:doc "`/' with no divisors raises error")
1854 (emt:assert
1855 (emt:eq-persist-p #'equal answer
1856 "dbid:2afbb9f8-3016-46a5-bb93-9d9d2fdd0e98"))))
1857 ;;equal?
1858 (expect
1859 ((exec+args (list debug-klink-executable))
1860 (shell t)
1861 (prompt "\nklink> ")
1862 (timeout 10)
1863 (append-newline t))
1864 (t "")
1865 (t "(equal?/2 3 3)"
1866 (emt:doc "Compares numbers correctly")
1867 (emt:assert
1868 (equal answer "#t")))
1869 (t "(equal?/2 3 2)"
1870 (emt:assert
1871 (equal answer "#f")))
1872 (t "(equal?/2 3 '(1 2))"
1873 (emt:assert
1874 (equal answer "#f")))
1875 (t "(equal?/2 'a 'a)"
1876 (emt:doc "Compares symbols correctly")
1877 (emt:assert
1878 (equal answer "#t")))
1879 (t "(equal?/2 'a 'b)"
1880 (emt:assert
1881 (equal answer "#f")))
1882 (t "(equal?/2 '(1 2) '(1 2))"
1883 (emt:doc "Compares lists correctly")
1884 (emt:assert
1885 (equal answer "#t")))
1886 (t "(equal?/2 '(1 2) '(1 3))"
1887 (emt:doc "Compares lists correctly")
1888 (emt:assert
1889 (equal answer "#f")))
1890 (t "(equal?/2 \"meet\" \"meet\")"
1891 (emt:doc "Compares strings correctly")
1892 (emt:assert
1893 (equal answer "#t")))
1894 (t "(equal?/2 \"meet\" \"not\")"
1895 (emt:doc "Compares strings correctly")
1896 (emt:assert
1897 (equal answer "#f")))
1898 (t "(equal?)"
1899 (emt:doc "Given the empty list, is true")
1900 (emt:assert
1901 (equal answer "#t")))
1906 ;;$provide, $binds?
1907 (expect
1908 ((exec+args (list debug-klink-executable))
1909 (shell t)
1910 (prompt "\nklink> ")
1911 (timeout 10)
1912 (append-newline t))
1913 (t "")
1914 (t "($define! a #f)")
1915 (t "($define! b #f)")
1916 (t "($provide! (b c) ($define! a 13) ($define! b 12) ($define! c 144))"
1917 (emt:doc "`$provide!' b and c but not a")
1918 (emt:assert
1919 (equal answer "#inert")))
1920 (t "a"
1921 (emt:doc "`a' is what it was")
1922 (emt:assert
1923 (equal answer "#f")))
1924 (t "b"
1925 (emt:doc "b has been changed")
1926 (emt:assert
1927 (equal answer "12")))
1928 (t "c"
1929 (emt:doc "c is available")
1930 (emt:assert
1931 (equal answer "144")))
1932 (t "((wrap $binds?/2) (get-current-environment) 'wrap)"
1933 (emt:doc "Test the simple version")
1934 (emt:doc "We know `wrap' should be bound")
1935 (emt:assert
1936 (equal answer "#t")))
1937 (t "((wrap $binds?/2) (get-current-environment) '$binds?/2)"
1938 (emt:doc "We know `$binds?/2' should be bound")
1939 (emt:assert
1940 (equal answer "#t")))
1941 (t "((wrap $binds?/2) (make-environment) '$binds?/2)"
1942 (emt:doc "`make-environment' should bind nothing.")
1943 (emt:assert
1944 (equal answer "#f")))
1945 (t "((wrap $binds?/2) (make-environment) 'unlikely-to-be-bound)"
1946 (emt:doc "In case the preceding test worked for the wrong \
1947 reason, ie that `make-environment' leaked")
1948 (emt:assert
1949 (equal answer "#f")))
1950 (t "($binds? (get-current-environment) $binds?)"
1951 (emt:doc "The N-ary version works")
1952 (emt:assert
1953 (equal answer "#t")))
1954 (t "($binds? (make-environment) $binds?)"
1955 (emt:doc "Discriminates")
1956 (emt:assert
1957 (equal answer "#f")))
1958 (t "($binds? (get-current-environment) list wrap)"
1959 (emt:doc "Takes more than 1 arg")
1960 (emt:assert
1961 (equal answer "#t"))))
1963 (expect
1964 ((exec+args (list debug-klink-executable))
1965 (shell t)
1966 (prompt "\nklink> ")
1967 (timeout 10)
1968 (append-newline t))
1969 (t "")
1970 (t "($define! a (open-input-file \"test-m1.krn\"))"
1971 (emt:doc "Open an input port from a known file")
1972 (emt:assert
1973 (equal answer "#inert")))
1974 (t "a"
1975 (emt:doc "We got a port")
1976 (emt:assert
1977 (equal answer "#<PORT>")))
1978 (t "(get-char a)"
1979 (emt:doc "Check the first few characters against known values")
1980 (emt:assert
1981 (equal answer "#\\;")))
1982 (t "(get-char a)"
1983 (emt:assert
1984 (equal answer "#\\newline")))
1985 (t "(get-char a)"
1986 (emt:assert
1987 (equal answer "#\\;"))))
1989 (expect
1990 ((exec+args (list debug-klink-executable))
1991 (shell t)
1992 (prompt "\nklink> ")
1993 (timeout 10)
1994 (append-newline t))
1995 (t "")
1996 (t "($binds? (get-current-environment) not-bound-in-ground)"
1997 (emt:doc "Validate that `not-bound-in-ground' is not already bound")
1998 (emt:assert
1999 (equal answer "#f")))
2000 (t "($define! a (make-kernel-standard-environment))"
2001 (emt:doc "Create a standard environment")
2002 (emt:assert
2003 (equal answer "#inert")))
2004 (t "($binds? a $binds?)"
2005 (emt:doc "The ground bindings are available")
2006 (emt:assert
2007 (equal answer "#t")))
2008 (t "($set! a not-bound-in-ground 12)"
2009 (emt:doc "set `not-bound-in-ground' in a")
2010 (emt:assert
2011 (equal answer "#inert")))
2012 (t "($binds? a not-bound-in-ground)"
2013 (emt:doc "It's bound in `a'")
2014 (emt:assert
2015 (equal answer "#t")))
2016 (t "(eval 'not-bound-in-ground a)"
2017 (emt:doc "It has the right value in `a'")
2018 (emt:assert
2019 (equal answer "12")))
2020 (t "($binds? (get-current-environment) not-bound-in-ground)"
2021 (emt:doc "It's not bound in current environment")
2022 (emt:assert
2023 (equal answer "#f")))
2024 (t "($define! x (get-module \"test-m1.krn\"))"
2025 (emt:doc "In `x', no parameters are defined")
2026 (emt:doc (concat "Answer: " answer)))
2027 (t "($define! y (get-module \"test-m1.krn\"
2028 ($bindings->environment (baz \"quux\"))))"
2029 (emt:doc "In `y', `baz' is defined")
2030 (emt:doc (concat "Answer: " answer)))
2031 (t "($define! z (get-module \"test-m1.krn\"
2032 ($bindings->environment (quux \"baz\"))))"
2033 (emt:doc "In `z', quux' is defined")
2034 (emt:doc (concat "Answer: " answer)))
2035 (t "(write (($remote-eval foo x)))"
2036 (emt:doc "Query `x'")
2037 (emt:assert
2038 (equal answer "no parameters\n#inert#inert")))
2039 (t "(write (($remote-eval foo y)))"
2040 (emt:doc "Query `y'")
2041 (emt:assert
2042 (equal answer "parameters, but no quux\n#inert#inert")))
2043 (t "(write (($remote-eval foo z)))"
2044 (emt:doc "Query `z'")
2045 (emt:assert
2046 (equal answer "parameters\n\"baz\"#inert"))))
2048 (expect
2049 ((exec+args (list debug-klink-executable))
2050 (shell t)
2051 (prompt "\nklink> ")
2052 (timeout 10)
2053 (append-newline t))
2054 (t "")
2055 (t "($let* ((low-promise ($lazy (cons 1 2)))(p1 ($lazy (($lambda
2056 ((x . y)) x) (force low-promise))))) (force p1))"
2057 (emt:doc "WRITE ME")
2058 (emt:assert
2059 (equal answer "1")))
2060 (t "($let* ((low-promise ($lazy (cons 1 2)))(p1 ($lazy (($lambda
2061 ((x . y)) y) (force low-promise))))) (force p1))"
2062 (emt:doc "WRITE ME")
2063 (emt:assert
2064 (equal answer "2"))))
2066 ;;Automatically forcing promises
2067 (expect
2068 ((exec+args (list debug-klink-executable))
2069 (shell t)
2070 (prompt "\nklink> ")
2071 (timeout 10)
2072 (append-newline t))
2073 (t "")
2074 (t "(car ($lazy '(1)))"
2075 (emt:doc "Car can force a promise")
2076 (emt:assert
2077 (equal answer "1")))
2078 (t "(car ($lazy '(2 3)))"
2079 (emt:assert
2080 (equal answer "2")))
2081 (t "((wrap $binds?/2) (get-current-environment) '$binds?/2)"
2082 (emt:doc "Validate that this call works")
2083 (emt:assert
2084 (equal answer "#t")))
2085 (t "((wrap $binds?/2) ($lazy (get-current-environment)) '$binds?/2)"
2086 (emt:doc "And validate that it works with one arg")
2087 (emt:assert
2088 (equal answer "#t")))
2090 (t "((wrap $binds?/2) ($lazy (get-current-environment)) ($lazy '$binds?/2))"
2091 (emt:doc "We can force two arguments")
2092 (emt:assert
2093 (equal answer "#t")))
2094 (t "(every?/2-xary integer? '((1) (2)))"
2095 (emt:doc "Validate that this call works")
2096 (emt:assert
2097 (equal answer "#t")))
2098 (t "(every?/2-xary integer? '((1) (#f)))"
2099 (emt:doc "False works too")
2100 (emt:assert
2101 (equal answer "#f")))
2103 (t "(every?/2-xary ($lazy integer?) '((1) (2)))"
2104 (emt:doc "Arguments after the forced argument work")
2105 (emt:assert
2106 (equal answer "#t")))
2108 (t "(every?/2-xary ($lazy integer?) '((1) (#f)))"
2109 (emt:assert
2110 (equal answer "#f")))
2112 (t "(every?/2-xary ($lazy integer?) ($lazy '((1) (2))))"
2113 (emt:doc "Arguments after the forced argument work")
2114 (emt:assert
2115 (equal answer "#t")))
2117 (t "(every?/2-xary ($lazy integer?) ($lazy '((1) (#f))))"
2118 (emt:assert
2119 (equal answer "#f"))))
2122 (expect
2123 ((exec+args (list debug-klink-executable))
2124 (shell t)
2125 (prompt "\nklink> ")
2126 (timeout 10)
2127 (append-newline t))
2128 (t "")
2129 (t "(profiling 1)"
2130 (emt:doc "Turn profiling on, and it should not have been on before")
2131 (emt:assert
2132 (equal answer "0")))
2133 (t "(profiling 1)"
2134 (emt:doc "Now it's on, and this is our first profiled call")
2135 (emt:assert
2136 (equal answer "1")))
2137 (t "(get-profiling-data)"
2138 (emt:doc "We see the profiling data from just the earlier call")
2139 (emt:doc "All profiling data may change, we're interested in
2140 its general behavior and in including the functions we just called")
2141 (emt:assert
2142 (emt:eq-persist-p #'equal
2143 answer
2144 "dbid:787cceb2-39a0-46c3-97a7-a23a3de3da4b")))
2145 (t "(profiling 1)"
2146 (emt:doc "Run this call again")
2147 (emt:assert
2148 (equal answer "1")))
2149 (t "(get-profiling-data)"
2150 (emt:doc "Now profiling data shows 2 calls to `profiling', 1
2151 to `get-profiling-data'")
2152 (emt:assert
2153 (emt:eq-persist-p #'equal
2154 answer
2155 "dbid:26b534dc-b589-4d2c-9026-7c5ea9b8a858")))
2156 (t "(get-profiling-data)"
2157 (emt:doc "Again")
2158 (emt:assert
2159 (emt:eq-persist-p #'equal
2160 answer
2161 "dbid:3c018d05-1938-4af6-8ad3-5325b9d16fd6"))))
2165 ;;;_ , debug-klink-capture-form
2166 ;;;###autoload
2167 (defun debug-klink-capture-form ()
2168 "Push entries for an `emtr:expect' script onto the kill ring.
2169 Basically `emtr:expect:buffer-capture-form' specialized for klink.
2171 Current buffer should contain a transcript of a klink session."
2174 (interactive)
2175 (emtr:expect:buffer-capture-form debug-klink-prompt t t))
2177 ;;;_. Footers
2178 ;;;_ , Provides
2180 (provide 'debug-klink)
2182 ;;;_ * Local emacs vars.
2183 ;;;_ + Local variables:
2184 ;;;_ + mode: allout
2185 ;;;_ + End:
2187 ;;;_ , End
2188 ;;; debug-klink.el ends here