Added tests for stream->list
[Klink.git] / debug-klink.el
blobb2cb41bb872c22cc0f10738c2b41faf89475c8d7
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)"))))
479 ;;stream->list
480 (expect
481 ((exec+args (list debug-klink-executable))
482 (shell t)
483 (prompt "\nklink> ")
484 (timeout 10)
485 (append-newline t))
486 ;;Clean out header stuff
487 (t "")
488 (t "(stream->list '())"
489 (emt:doc "Works on null")
490 (emt:assert
491 (equal answer "()")))
492 (t "(stream->list ($lazy '()))"
493 (emt:doc "Works on promised null")
494 (emt:assert
495 (equal answer "()")))
496 (t "(stream->list ($lazy '(1)))"
497 (emt:assert
498 (equal answer "(1)")))
499 (t "(stream->list (list* 1 ($lazy '())))"
500 (emt:doc "Works on lazy empty tail")
501 (emt:assert
502 (equal answer "(1)")))
503 (t "(stream->list (list* 1 ($lazy '(2))))"
504 (emt:assert
505 (equal answer "(1 2)")))
506 (t "(stream->list (list* 1 2 ($lazy '())))"
507 (emt:assert
508 (equal answer "(1 2)"))))
511 ;;apply
512 (expect
513 ((exec+args (list debug-klink-executable))
514 (shell t)
515 (prompt "\nklink> ")
516 (timeout 10)
517 (append-newline t))
518 ;;Clean out header stuff
519 (t "")
520 (t "apply"
521 (emt:doc "`apply' is recognized")
522 (emt:assert
523 (equal answer "#,apply")))
524 (t "(apply list '(1 2 3) (get-current-environment))"
525 (emt:doc "Apply works on list argument")
526 (emt:assert
527 (equal answer "(1 2 3)")))
528 (t "(apply list '(1 2 3))"
529 (emt:doc "Apply with default env works on list argument,
530 evals each number")
531 (emt:assert
532 (equal answer "(1 2 3)")))
533 (t "(apply list '(a 2 3))"
534 (emt:doc "Apply doesn't re-eval args, so this works even \
535 though the symbol `a' is unbound in the empty environment.")
536 (emt:assert
537 (equal answer "(a 2 3)")))
538 (t "(apply list ''(1 2 3))"
539 (emt:doc "Double-quoted gets single-quoted")
540 (emt:assert
541 (equal answer "(#,$quote (1 2 3))")))
543 (t "(apply list '''(1 2 3))"
544 (emt:doc "Triple-quoted gets double-quoted")
545 (emt:assert
546 (equal answer "(#,$quote (#,$quote (1 2 3)))")))
548 (t "(apply (wrap list) '(list) (get-current-environment))"
549 (emt:doc "In normal environment, we see bindings such as `list'")
550 (emt:assert
551 (equal answer "(#,list)")))
552 (t "(apply (wrap list) '(list) (make-environment))"
553 (emt:doc "In blank environment, we see no bindings")
554 (emt:assert
555 (equal answer "Error: eval: unbound variable: list \n")))
556 (t "(apply (wrap $sequence) '(list) (get-current-environment))"
557 (emt:doc "In normal environment, we see bindings such as `list'")
558 (emt:assert
559 (equal answer "#,list")))
560 (t "(apply (wrap $sequence) '(list) (make-environment))"
561 (emt:doc "In blank environment, we see no bindings")
562 (emt:assert
563 (equal answer "Error: eval: unbound variable: list \n"))))
565 ;;predicates
566 (expect
567 ((exec+args (list debug-klink-executable))
568 (shell t)
569 (prompt "\nklink> ")
570 (timeout 10)
571 (append-newline t))
572 ;;Clean out header stuff
573 (t "")
574 (t "(integer? 1)"
575 (emt:doc "Predicate integer?")
576 (emt:assert
577 (equal answer
578 "#t")
580 (t "(integer? 'a)"
581 (emt:doc "Predicate integer?")
582 (emt:assert
583 (equal answer
584 "#f")
585 t)))
586 ;;null?
587 (expect
588 ((exec+args (list debug-klink-executable))
589 (shell t)
590 (prompt "\nklink> ")
591 (timeout 10)
592 (append-newline t))
593 ;;Clean out header stuff
594 (t "")
595 (t "null?"
596 (emt:doc "null? is recognized")
597 (emt:assert
598 (equal answer "#,null?")))
599 ;;Must eval, which right now we don't.
600 (t "(null? '())"
601 (emt:assert
602 (equal answer "#t")))
603 (t "(null? 13)"
604 (emt:assert
605 (equal answer "#f"))))
607 ;;make-encapsulation-type
608 (expect
609 ((exec+args (list debug-klink-executable))
610 (shell t)
611 (prompt "\nklink> ")
612 (timeout 10)
613 (append-newline t))
614 ;;Clean out header stuff
615 (t "")
616 (t "($define! (e p? d) (make-encapsulation-type))"
617 (emt:doc "Make an encapsulation type")
618 (emt:assert
619 (equal answer "#inert")))
620 (t "($define! a (e 12))"
621 (emt:doc "Make an instance of it")
622 (emt:assert
623 (equal answer "#inert")))
624 (t "(p? a)"
625 (emt:doc "The predicate returns true on the instance")
626 (emt:assert
627 (equal answer "#t")))
628 (t "(p? 12)"
629 (emt:assert
630 (equal answer "#f")))
631 (t "(p? a a)"
632 (emt:assert
633 (equal answer "#t")))
634 (t "(p? a #f a)"
635 (emt:assert
636 (equal answer "#f")))
637 (t "(d a)"
638 (emt:doc "`d' retrieves the value")
639 (emt:assert
640 (equal answer "12"))))
642 ;;$if
643 (expect
644 ((exec+args (list debug-klink-executable))
645 (shell t)
646 (prompt "\nklink> ")
647 (timeout 10)
648 (append-newline t))
649 ;;Clean out header stuff
650 (t "")
651 (t "$if"
652 (emt:doc "$if is recognized")
653 (emt:assert
654 (equal answer "#,$if")))
655 (t "($if #t '1 '2)"
656 (emt:doc "On true, evaluates the CONSEQUENT argument")
657 (emt:assert
658 (equal answer "1")))
659 (t "($if #f '1 '2)"
660 (emt:doc "On false, evaluates the ALTERNATIVE argument")
661 (emt:assert
662 (equal answer "2")))
663 (t "($if 3 1 2)"
664 (emt:doc "On non-boolean test, raises error")
665 (emt:assert
666 (emt:eq-persist-p
667 #'equal answer
668 "dbid:80eedbc8-efd5-47c4-9c3b-d0da6c48f768")))
669 (t "($if '#t '1 '2)"
670 (emt:doc "On evaluated true, evaluates the CONSEQUENT argument")
671 (emt:assert
672 (equal answer "1")))
673 (t "($if '#f '1 '2)"
674 (emt:doc "On evaluated false, evaluates the ALTERNATIVE argument")
675 (emt:assert
676 (equal answer "2"))))
677 ;;$cond
678 (expect
679 ((exec+args (list debug-klink-executable))
680 (shell t)
681 (prompt "\nklink> ")
682 (timeout 10)
683 (append-newline t))
684 ;;Clean out header stuff
685 (t "")
686 (t "($cond (#t 12)(#f 13))"
687 (emt:doc "The first true claus is evalled")
688 (emt:assert
689 (equal answer "12")))
690 (t "($cond (#f 13)(#t 12))"
691 (emt:doc "False clauses are skipped")
692 (emt:assert
693 (equal answer "12")))
694 (t "($cond ((integer? 'a) 13)(#t 12))"
695 (emt:doc "Guard clauses are evalled")
696 (emt:assert
697 (equal answer "12")))
698 (t "($cond ((integer? 'a) 13)((integer? 1) 12))"
699 (emt:doc "Guard clauses are evalled")
700 (emt:assert
701 (equal answer "12")))
702 (t "($let ((x 5)) ($cond (#t (list 1 2))))"
703 (emt:doc "The selected clause body is evalled")
704 (emt:assert
705 (equal answer "(1 2)")))
706 (t "($cond)"
707 (emt:doc "$cond with no clauses gives #inert")
708 (emt:assert
709 (equal answer "#inert")))
710 (t "($let ((x 5))
711 ($cond ((integer? x)
712 (display \"x=\")
713 (display x)
714 (newline))))"
715 (emt:doc "Variables are accessible inside clauses")
716 (emt:assert
717 (equal answer "x=5\n#inert"))))
720 (expect
721 ((exec+args (list debug-klink-executable))
722 (shell t)
723 (prompt "\nklink> ")
724 (timeout 10)
725 (append-newline t))
726 ;;Clean out header stuff
727 (t "")
728 (t "(listloop listloop-style-neighbors '(1 2 3) 2)"
729 (emt:doc "Validate that listloop normally works")
730 (emt:assert
731 (equal answer "#<OPERATIVE>")))
732 (t "(listloop listloop-style-neighbors ($lazy '(1 2 3)) #f)"
733 (emt:doc "Validate that listloop will error if it gets the wrong type")
734 (emt:assert
735 (emt:eq-persist-p #'equal answer
736 "dbid:0488e533-76ef-4720-93d5-bfab229c9079")))
737 (t "(listloop listloop-style-neighbors '(1 2 3) ($lazy 2))"
738 (emt:doc "It accepts lazy style arguments")
739 (emt:assert
740 (equal answer "#<OPERATIVE>")))
741 (t "(listloop listloop-style-neighbors ($lazy '(1 2 3)) ($lazy 2))"
742 (emt:doc "It accepts lazy lists")
743 (emt:assert
744 (equal answer "#<OPERATIVE>"))))
746 ;;$sequence
747 (expect
748 ((exec+args (list debug-klink-executable))
749 (shell t)
750 (prompt "\nklink> ")
751 (timeout 10)
752 (append-newline t))
753 ;;Clean out header stuff
754 (t "")
755 (t "($sequence)"
756 (emt:doc "$sequence with no args gives inert")
757 (emt:assert
758 (equal answer "#inert")))
759 (t "($sequence '1)"
760 (emt:doc "Sequence evaluates its args")
761 (emt:assert
762 (equal answer "1")))
763 (t "($sequence '1 '2)"
764 (emt:doc "Sequence returns the value of the last element")
765 (emt:assert
766 (equal answer "2")))
767 (t "($define! my-lam ($lambda v (write v)(newline)))"
768 (emt:doc "Define a lambda having a sequence"))
769 (t "(my-lam 12)"
770 (emt:doc "That lambda evals all the sequence")
771 (emt:assert
772 (equal answer "(12)\n#inert"))))
775 ;;write and display
776 (expect
777 ((exec+args (list debug-klink-executable))
778 (shell t)
779 (prompt "\nklink> ")
780 (timeout 10)
781 (append-newline t))
782 ;;Clean out header stuff
783 (t "")
784 (t "($sequence (write \"abc\") (newline))"
785 (emt:doc "`write' displays objects escaped for read-back")
786 (emt:assert
787 (equal answer "\"abc\"\n#inert")))
788 (t "($sequence (display \"abc\") (newline))"
789 (emt:doc "`display' displays objects unescaped")
790 (emt:assert
791 (equal answer "abc\n#inert")))
792 (t "($sequence (display '(1 2 3)) (newline))"
793 (emt:doc "`display' can display full objects")
794 (emt:assert
795 (equal answer "(1 2 3)\n#inert")))
796 (t "($sequence (write '(1 2 3)) (newline))"
797 (emt:doc "`write' can display full objects")
798 (emt:assert
799 (equal answer "(1 2 3)\n#inert"))))
801 (expect
802 ((exec+args (list debug-klink-executable))
803 (shell t)
804 (prompt "\nklink> ")
805 (timeout 10)
806 (append-newline t))
807 ;;Clean out header stuff
808 (t "")
809 (t "(read)\n12"
810 (emt:doc "Reads numbers")
811 (emt:assert
812 (equal answer "12")))
813 (t "(read)\nsym"
814 (emt:doc "Reads symbols")
815 (emt:assert
816 (equal answer "sym")))
817 (t "(read)\n(1 2 3)"
818 (emt:doc "Reads lists, no problem with nesting depth.")
819 (emt:assert
820 (equal answer "(1 2 3)"))))
823 ;;On typechecking
824 (expect
825 ((exec+args (list debug-klink-executable))
826 (shell t)
827 (prompt "\nklink> ")
828 (timeout 10)
829 (append-newline t))
830 ;;Clean out header stuff
831 (t "")
832 (t "true/o1"
833 (emt:doc "true/o1 predicate is recognized")
834 (emt:assert
835 (equal answer "#,true/o1")
838 (t "(true/o1 1)"
839 (emt:doc "true/o1 predicate gives #t")
840 (emt:assert
841 (equal answer "#t")
843 (t "type?"
844 (emt:doc "`type?' is recognized")
845 (emt:assert
846 (equal answer "#,type?")
849 (t "(type? 1 true/o1)"
850 (emt:doc "`type?' can be called")
851 (emt:assert
852 (equal answer "#t")
854 (t "listtype"
855 (emt:doc "`listtype' ctor is recognized")
856 (emt:assert
857 (equal answer "#,listtype")
859 (t "(listtype true/o1)"
860 (emt:doc "`listtype' makes an operative")
861 (emt:assert
862 (equal answer "#<OPERATIVE>")
864 (t "(listtype true/o1 true/o1)"
865 (emt:doc "`listtype' takes a list of args")
866 (emt:assert
867 (equal answer "#<OPERATIVE>")
869 (t "(type? 1 (listtype true/o1))"
870 (emt:doc "`listtype' makes one that expects a list")
871 (emt:assert
872 (equal answer "#f")
874 (t "(type? '(1) (listtype integer?))"
875 (emt:doc "Second-level listtypes work OK")
876 (emt:assert
877 (equal answer "#t")
879 (t "(type? '(#t) (listtype integer?))"
880 (emt:doc "Second-level listtype discriminate (non)match")
881 (emt:assert
882 (equal answer "#f")
884 (t "(type? '(1) (listtype true/o1 true/o1))"
885 (emt:doc "Situation: Too few elements")
886 (emt:doc "Result: false")
887 (emt:assert
888 (equal answer "#f")
890 (t "(type? '(1) (listtype))"
891 (emt:doc "Situation: Objects has too many elements")
892 (emt:doc "Result: false")
893 (emt:assert
894 (equal answer "#f")
896 (t "(type? '(1) (listtype true/o1 'optional true/o1))"
897 (emt:doc "Situation: Optional elements")
898 (emt:doc "Result: true")
899 (emt:assert
900 (equal answer "#t")
902 (t "(type? '(1 2 3) (listtype true/o1 'optional true/o1))"
903 (emt:doc "Situation: Number of items outruns number of optional elements")
904 (emt:doc "Result: false")
905 (emt:assert
906 (equal answer "#f")
908 (t "(type? '(1) (listtype true/o1 'optional 'optional))"
909 (emt:doc "Situation: Two optional keys given")
910 (emt:doc "Result: error")
911 (emt:assert
912 (emt:eq-persist-p
913 #'equal
914 answer
915 "dbid:e144f830-d6a5-4240-94f0-b0b8a9890d42")))
916 (t "(type? '(1) (listtype true/o1 'DOT))"
917 (emt:doc "Situation: Dot spec has no spec after it")
918 (emt:doc "Result: error")
919 (emt:assert
920 (emt:eq-persist-p #'equal
921 answer
922 "dbid:37a39a99-8b11-4d6f-9e31-033af8d73d41")))
923 (t "(type? '(1) (listtype true/o1 'DOT true/o1 true/o1))"
924 (emt:doc "Situation: Dot spec has more than 1 spec after it")
925 (emt:doc "Result: error")
926 (emt:assert
927 (emt:eq-persist-p #'equal
928 answer
929 "dbid:7f057673-3b94-4e4c-a25c-b09ed5239af2")))
930 (t "(type? '(1 2 3) (listtype true/o1 'DOT true/o1))"
931 (emt:doc "Situation: Dot spec is satisfied")
932 (emt:doc "Result: true")
933 (emt:assert
934 (equal answer "#t")
936 (t "(type? '(1 2 3) (listtype true/o1 'DOT integer?))"
937 (emt:doc "Situation: Dot spec is reached but doesn't match")
938 (emt:doc "Result: false")
939 (emt:assert
940 (equal answer "#f")
942 (t "(type? '(1 2 3) (listtype true/o1 'REPEAT integer?))"
943 (emt:doc "Situation: Repeat spec is used and matches")
944 (emt:doc "Result: true")
945 (emt:assert
946 (equal answer "#t")
948 (t "(type? '(1 2 #t) (listtype true/o1 'REPEAT integer?))"
949 (emt:doc "Situation: Repeat spec is used but doesn't match")
950 (emt:doc "Result: false")
951 (emt:assert
952 (equal answer "#f")
954 (t "(type? '(1 2 #t 4 #t) (listtype true/o1 'REPEAT integer? true/o1))"
955 (emt:doc "Situation: Repeat spec is used, has 2 items, matches")
956 (emt:doc "Result: true")
957 (emt:assert
958 (equal answer "#t")
960 (t "(type? '(1 2 #t 4 #t) (listtype true/o1 'REPEAT true/o1 integer?))"
961 (emt:doc "Situation: Repeat spec is used, has 2 items, but doesn't match")
962 (emt:doc "Result: false")
963 (emt:assert
964 (equal answer "#f")
966 (t "(type? '(1) (listtype true/o1 'REPEAT integer?))"
967 (emt:doc "Situation: Repeat spec is used, zero items available")
968 (emt:doc "Result: true")
969 (emt:assert
970 (equal answer "#t")
972 ;; $$IMPROVE ME Test circularity, use encycle!
975 ;;On destructuring
976 (expect
977 ((exec+args (list debug-klink-executable))
978 (shell t)
979 (prompt "\nklink> ")
980 (timeout 10)
981 (append-newline t))
982 ;;Clean out header stuff
983 (t "")
985 (t "destructure-list"
986 (emt:doc "Test `destructure-list'")
987 (emt:doc "ctor is recognized")
988 (emt:assert
989 (equal answer "#,destructure-list")
991 (t "(destructure-list true/o1)"
992 (emt:doc "It makes an operative")
993 (emt:assert
994 (equal answer "#<OPERATIVE>")
996 (t "(destructure-list true/o1 true/o1)"
997 (emt:doc "It takes a list of args")
998 (emt:assert
999 (equal answer "#<OPERATIVE>")
1001 (t "(do-destructure 1 true/o1)"
1002 (emt:doc "do-destructure can take just a combiner as arg")
1003 (emt:assert
1004 (equal answer "#( 1)")))
1005 (t "(do-destructure 1 (destructure-list true/o1))"
1006 (emt:doc "It makes one that expects a list")
1007 (emt:doc "Result: Error")
1008 (emt:assert
1009 (emt:eq-persist-p #'equal
1010 answer
1011 "dbid:3e113873-73a0-46f5-8e14-f41034780317")))
1012 (t "(do-destructure '(1) (destructure-list integer?))"
1013 (emt:doc "Second-level destructures work OK")
1014 (emt:assert
1015 (equal answer "#( 1)")
1017 (t "(do-destructure '(#t) (destructure-list integer?))"
1018 (emt:doc "Second-level destructure discriminate (non)match")
1019 (emt:doc "Result: Error")
1020 (emt:assert
1021 (emt:eq-persist-p #'equal
1022 answer
1023 "dbid:dc2648ef-22cb-41c2-8f9b-67548b0a3b7a")))
1024 (t "(do-destructure '(1) (destructure-list true/o1 true/o1))"
1025 (emt:doc "Situation: Too few elements")
1026 (emt:doc "Result: Error")
1027 (emt:assert
1028 (emt:eq-persist-p
1029 #'equal
1030 answer
1031 "dbid:b50e8f78-6652-418d-9b44-1ff676946970")))
1032 (t "(do-destructure '(1) (destructure-list))"
1033 (emt:doc "Situation: Objects has too many elements")
1034 (emt:doc "Result: Error")
1035 (emt:assert
1036 (emt:eq-persist-p
1037 #'equal
1038 answer
1039 "dbid:ee168f5d-5d87-4792-9dba-0fd0ac7c14a4")))
1041 (t "(do-destructure '(1) (destructure-list true/o1 'optional true/o1))"
1042 (emt:doc "Situation: Optional elements")
1043 (emt:doc "Result: true")
1044 (emt:assert
1045 (equal answer "#( 1 #inert)")
1048 (t "(do-destructure '(1 2 3) (destructure-list true/o1 'optional true/o1))"
1049 (emt:doc "Situation: Number of items outruns number of optional elements")
1050 (emt:doc "Result: Error")
1051 (emt:assert
1052 (emt:eq-persist-p #'equal answer
1053 "dbid:a1bd1321-532e-4187-af64-278c009a7f97")))
1055 (t "(do-destructure '(1) (destructure-list true/o1 'optional 'optional))"
1056 (emt:doc "Situation: Two optional keys given")
1057 (emt:doc "Result: Error")
1058 (emt:assert
1059 (emt:eq-persist-p
1060 #'equal
1061 answer
1062 "dbid:ece901d5-4ac0-496e-a9e2-83423a933522")))
1064 (t "(do-destructure '(1) (destructure-list true/o1 'dot))"
1065 (emt:doc "Situation: Dot spec has no spec after it")
1066 (emt:doc "Result: Error")
1067 (emt:assert
1068 (emt:eq-persist-p #'equal
1069 answer
1070 "dbid:8e8711ba-bada-4223-a212-3256d6a2e497")))
1072 (t "(do-destructure '(1) (destructure-list true/o1 'dot true/o1 true/o1))"
1073 (emt:doc "Situation: Dot spec has more than 1 spec after it")
1074 (emt:doc "Result: Error")
1075 (emt:assert
1076 (emt:eq-persist-p #'equal
1077 answer
1078 "dbid:4d68ceb6-f450-4218-b222-c10019a39819")))
1080 (t "(do-destructure '(1 2 3) (destructure-list true/o1 'dot true/o1))"
1081 (emt:doc "Situation: Dot spec is satisfied")
1082 (emt:doc "Result: true")
1083 (emt:assert
1084 (equal answer "#( 1 (2 3))")
1087 (t "(do-destructure '(1 2 3) (destructure-list true/o1 'dot integer?))"
1088 (emt:doc "Situation: Dot spec is reached but doesn't match")
1089 (emt:doc "Result: Error")
1090 (emt:assert
1091 (emt:eq-persist-p #'equal answer
1092 "dbid:266cbd1e-734c-4a81-bac6-e9d9a3424e79")))
1094 (t "(do-destructure '(1) 13)"
1095 (emt:doc "Fails gracefully when given a non-combiner")
1096 (emt:assert
1097 (emt:eq-persist-p
1098 #'equal answer
1099 "dbid:2492173b-e70f-460d-87a0-da1aff73d22e")))
1100 (t "(do-destructure 1 ($lambda (x) (true/o1 x)))"
1101 (emt:doc "Accepts combiners that use the main loop")
1102 (emt:assert
1103 (equal answer "#( 1)")))
1104 (t "(do-destructure '(1) (destructure-list ($vau (x) #ignore (true/o1 x))))"
1105 (emt:assert
1106 (equal answer "#( 1)"))))
1108 ;;On define-type destructuring
1109 (expect
1110 ((exec+args (list debug-klink-executable))
1111 (shell t)
1112 (prompt "\nklink> ")
1113 (timeout 10)
1114 (append-newline t))
1115 ;;Clean out header stuff
1116 (t "")
1117 (t "($define! (a b) ($lazy '(12 144)))"
1118 (emt:doc "Define with a lazy value")
1119 (emt:assert
1120 (equal answer "#inert")))
1121 (t "a"
1122 (emt:doc "A has been defined")
1123 (emt:assert
1124 (equal answer "12")))
1125 (t "b"
1126 (emt:doc "B has been defined")
1127 (emt:assert
1128 (equal answer "144")))
1129 (t "($define! ((a b)(c d)) (list ($lazy '(20736 1728))($lazy '(144 12))))"
1130 (emt:doc "Define with multiple lazy values")
1131 (emt:assert
1132 (equal answer "#inert")))
1133 (t "a"
1134 (emt:doc "A has been changed")
1135 (emt:assert
1136 (equal answer "20736")))
1137 (t "b"
1138 (emt:assert
1139 (equal answer "1728")))
1140 (t "c"
1141 (emt:assert
1142 (equal answer "144")))
1143 (t "d"
1144 (emt:assert
1145 (equal answer "12")))
1146 (t "((wrap ($vau ((a b)) #ignore (list a b))) '(144 12))"
1147 (emt:doc "Validate: Without laziness, vau works as expected")
1148 (emt:assert
1149 (equal answer "(144 12)")))
1150 (t "((wrap ($vau ((a b)) #ignore (list a b))) ($lazy '(144 12)))"
1151 (emt:doc "Handles laziness too")
1152 (emt:assert
1153 (equal answer "(144 12)")))
1154 (t "((wrap ($vau ((a b)(c d)) #ignore (list a b c d))) '(20736 1728) '(144 12))"
1155 (emt:assert
1156 (equal answer "(20736 1728 144 12)")))
1157 (t "((wrap ($vau ((a b)(c d)) #ignore (list a b c d)))
1158 ($lazy '(20736 1728))
1159 ($lazy '(144 12)))"
1160 (emt:doc "Handles nested and double-lazy too")
1161 (emt:assert
1162 (equal answer "(20736 1728 144 12)")))
1163 (t "((wrap ($vau ((a b)) #ignore (list a b))) ($lazy 144))"
1164 (emt:doc "Error on values that don't fit even when forced")
1165 (emt:assert
1166 (emt:eq-persist-p #'equal answer
1167 "dbid:6928bebb-0876-448c-9a9b-f72410c94422")))
1168 (t "((wrap ($vau ((a b (c d))) #ignore (list a b c d)))
1169 ($lazy (list 20736 1728 ($lazy '(144 12)))))"
1170 (emt:doc "Works even on nested promises")
1171 (emt:assert
1172 (equal answer "(20736 1728 144 12)"))))
1175 ;;On where-typemiss
1176 (expect
1177 ((exec+args (list debug-klink-executable))
1178 (shell t)
1179 (prompt "\nklink> ")
1180 (timeout 10)
1181 (append-newline t))
1182 ;;Clean out header stuff
1183 (t "")
1185 (t "(where-typemiss 1 (listtype true/o1))"
1186 (emt:doc "`listtype' makes one that expects a list")
1187 (emt:assert
1188 (equal answer "(0 too-few)")
1190 (t "(where-typemiss '(#t) (listtype integer?))"
1191 (emt:doc "Second-level listtype discriminate (non)match")
1192 ;;Use persist because the form of the printout changes.
1193 (emt:assert
1194 (emt:eq-persist-p #'equal answer
1195 "dbid:cc211ae0-718b-4462-9062-7f0077cdf162")))
1196 (t "(where-typemiss '(1) (listtype true/o1 true/o1))"
1197 (emt:doc "Situation: Too few elements")
1198 (emt:assert
1199 (equal answer "(1 too-few)")
1201 (t "(where-typemiss '(1) (listtype))"
1202 (emt:doc "Situation: Objects has too many elements")
1203 (emt:assert
1204 (equal answer "(0 too-many)")
1206 (t "(where-typemiss '(1 2 3) (listtype true/o1 'optional true/o1))"
1207 (emt:doc "Situation: Number of items outruns number of optional elements")
1208 (emt:assert
1209 (equal answer "(2 too-many)")
1211 (t "(where-typemiss '(1 2 3) (listtype true/o1 'dot integer?))"
1212 (emt:doc "Situation: Dot spec is reached but doesn't match")
1213 (emt:assert
1214 (emt:eq-persist-p #'equal answer
1215 "dbid:2f83b114-6bdf-4c7d-9a76-0d3e8b43483c")))
1216 (t "(where-typemiss '(1 2 #t) (listtype true/o1 'repeat integer?))"
1217 (emt:doc "Situation: Repeat spec is used but doesn't match")
1218 (emt:assert
1219 (emt:eq-persist-p #'equal answer
1220 "dbid:f90a1f49-9180-4817-8095-6422ee058745")))
1221 (t "(where-typemiss '(1 2 #t 4 #t) (listtype true/o1 'repeat true/o1 integer?))"
1222 (emt:doc "Situation: Repeat spec is used, has 2 items, but doesn't match")
1223 (emt:assert
1224 (emt:eq-persist-p #'equal answer
1225 "dbid:374c6ab3-7907-4ff5-b14d-e41584593296")))
1226 ;; $$IMPROVE ME Test circularity, use encycle!
1229 ;;On get-list-metrics
1230 (expect
1231 ((exec+args (list debug-klink-executable))
1232 (shell t)
1233 (prompt "\nklink> ")
1234 (timeout 10)
1235 (append-newline t))
1236 ;;Clean out header stuff
1237 (t "")
1238 (t "(length '(0 1))"
1239 (emt:assert
1240 (equal answer "2")))
1241 (t "(finite-list? '(0 1))"
1242 (emt:assert
1243 (equal answer "#t")))
1244 (t "(finite-list? #f)"
1245 (emt:assert
1246 (equal answer "#f")))
1247 (t "(get-list-metrics '(0 1))"
1248 (emt:assert
1249 (equal answer "(2 1 2 0)")))
1250 (t "(get-list-metrics #f)"
1251 (emt:assert
1252 (equal answer "(0 0 0 0)")))
1253 (t "(get-list-metrics '(0 . 1))"
1254 (emt:assert
1255 (equal answer "(1 0 1 0)")))
1256 (t "($define! a (list 12))"
1257 (emt:doc "Make a circular object"))
1258 (t "(set-cdr! a a)")
1259 (t "(get-list-metrics a)"
1260 (emt:doc "List metrics of a circular object")
1261 (emt:assert
1262 (equal answer "(1 0 0 1)")))
1267 ;;On making environment
1268 (expect
1269 ((exec+args (list debug-klink-executable))
1270 (shell t)
1271 (prompt "\nklink> ")
1272 (timeout 10)
1273 (append-newline t))
1274 ;;Clean out header stuff
1275 (t "")
1276 (t "(make-environment (get-current-environment))"
1277 (emt:doc "Can make an environment")
1278 (emt:assert
1279 (equal answer "#<ENVIRONMENT>")))
1280 (t "(make-environment)"
1281 (emt:doc "Can make an empty environment")
1282 (emt:assert
1283 (equal answer "#<ENVIRONMENT>")))
1285 (t "(eval 'make-environment (make-environment))"
1286 (emt:doc "Empty environment does not bind things")
1287 (emt:assert
1288 (emt:eq-persist-p
1289 #'equal answer "dbid:930c9cb4-c8e3-446a-9d0f-80a7a01edf2e")))
1291 (t "($define! env1 (make-environment))"
1292 (emt:doc "Define example environments")
1293 (emt:assert
1294 (equal answer "#inert")))
1295 (t "($define! env2 (make-environment))"
1296 (emt:assert
1297 (equal answer "#inert")))
1298 (t "($set! env1 a 12)"
1299 (emt:doc "Define things in those example environments")
1300 (emt:assert
1301 (equal answer "#inert")))
1302 (t "($set! env2 b 144)"
1303 (emt:assert
1304 (equal answer "#inert")))
1305 (t "(eval 'a env1)"
1306 (emt:doc "The respective bindings are available in the environments")
1307 (emt:assert
1308 (equal answer "12")))
1309 (t "(eval 'b env2)"
1310 (emt:assert
1311 (equal answer "144")))
1312 (t "($define! env1+2 (make-environment env1 env2))"
1313 (emt:doc "Can make an environment from multiple parents")
1314 (emt:assert
1315 (equal answer "#inert")))
1316 (t "(eval 'a env1+2)"
1317 (emt:doc "It contains the bindings of both environments")
1318 (emt:assert
1319 (equal answer "12")))
1320 (t "(eval 'b env1+2)"
1321 (emt:assert
1322 (equal answer "144"))))
1324 (expect
1325 ((exec+args (list debug-klink-executable))
1326 (shell t)
1327 (prompt "\nklink> ")
1328 (timeout 10)
1329 (append-newline t))
1330 (t "")
1331 (t "(reverse-lookup get-current-environment (get-current-environment))"
1332 (emt:doc "Operation: look up an object we know is bound")
1333 (emt:doc "Result: We find it")
1334 (emt:assert
1335 (equal answer "get-current-environment")))
1336 (t "(reverse-lookup reverse-lookup (get-current-environment))"
1337 (emt:doc "Same on another object")
1338 (emt:assert
1339 (equal answer "reverse-lookup")))
1340 (t "(reverse-lookup 'example-unsymboled-object (get-current-environment))"
1341 (emt:doc "Operation: look up an object we know is not bound")
1342 (emt:doc "Result: Error")
1343 (emt:assert
1344 (emt:eq-persist-p #'equal answer
1345 "dbid:c3ec8dcc-39b2-4885-b4f3-f6e5f018c11e")))
1346 (t "($define! a (list))"
1347 (emt:doc "Make an object we will look for"))
1348 (t "($define! my-env (make-environment))")
1349 (t "($set! my-env b a)"
1350 (emt:doc "In my-env, define b as that object"))
1351 (t "($set! my-env b 13)"
1352 (emt:doc "Now define b as something else"))
1353 (t "(reverse-lookup a my-env)"
1354 (emt:doc "Look up the original object")
1355 (emt:assert
1356 (emt:eq-persist-p
1357 #'equal answer
1358 "dbid:673c63c9-1844-4c7f-b67d-22c6ef88fc66")))
1359 (t "($define! my-env2 (make-environment))"
1360 (emt:doc "Make another empty environment"))
1361 (t "($set! my-env2 c a)"
1362 (emt:doc "In my-env2, define c as that object"))
1363 (t "($set! my-env2 b a)"
1364 (emt:doc "In my-env2, define b as that object"))
1365 (t "($set! my-env2 b 13)"
1366 (emt:doc "Now define b as something else"))
1367 (t "(reverse-lookup a my-env2)"
1368 (emt:doc "Operation: Look up the original object")
1369 (emt:doc "Result: We find its binding, c")
1370 (emt:assert
1371 (equal answer "c")))
1372 (t "($set! my-env2 b a)"
1373 (emt:doc "Define b as that object again"))
1374 (t "($define! my-env3 (make-environment my-env2))"
1375 (emt:doc "Make an environment derived from my-env2"))
1376 (t "($set! my-env3 b 13)"
1377 (emt:doc "There set b to be something else"))
1378 (t "(reverse-lookup a my-env3)"
1379 (emt:doc "Operation: Look up the original object")
1380 (emt:doc "Result: We find its binding")
1381 (emt:assert
1382 (equal answer "c"))))
1384 ;;On printing, esp circular objects
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 "print-lookup-env"
1394 (emt:assert
1395 (equal answer "#,print-lookup-env"))
1397 (t "(list 1 2)"
1398 (emt:doc "Lists print OK")
1399 (emt:assert
1400 (equal answer "(1 2)")))
1401 (t "wrap"
1402 (emt:doc "Bound objects print a lowquote and their binding")
1403 (emt:assert
1404 (equal answer "#,wrap")))
1405 (t "list"
1406 (emt:assert
1407 (equal answer "#,list")))
1408 (t "(list list)"
1409 (emt:doc "These objects are actual working combiners.")
1410 (emt:assert
1411 (equal answer "(#,list)")))
1415 ;;On get-recurrences
1416 (expect
1417 ((exec+args (list debug-klink-executable))
1418 (shell t)
1419 (prompt "\nklink> ")
1420 (timeout 10)
1421 (append-newline t))
1423 (t "")
1424 (t "($define! cycles-nil (get-recurrences '()))"
1425 (emt:doc "`cycles-nil' is the recurrences of object '()"))
1426 (t "(recurrence-table? cycles-nil)"
1427 (emt:assert
1428 (equal answer "#t")))
1429 ;; $$RECONSIDER ME
1430 (t "(recurrences-get-object-count cycles-nil '())"
1431 (emt:doc "Nils are not counted")
1432 (emt:assert
1433 (equal answer "0")))
1434 (t "($define! cycles-list (get-recurrences (list 12 144)))"
1435 (emt:doc "`cycles-list' is the recurrences of an ordinary list"))
1436 (t "(recurrence-table? cycles-list)"
1437 (emt:assert
1438 (equal answer "#t")))
1439 (t "($define! cycles-many-nils (get-recurrences '()))"
1440 (emt:doc "`cycles-many-nils' is the recurrences of object of
1441 multiple nils"))
1442 (t "(recurrence-table? cycles-many-nils)"
1443 (emt:assert
1444 (equal answer "#t")))
1445 (t "(recurrences-get-object-count cycles-many-nils '())"
1446 (emt:doc "Nils do not constitute shared objects")
1447 (emt:assert
1448 (equal answer "0")))
1449 (t "($define! cycles-f (get-recurrences '(#f #f)))"
1450 (emt:doc "Get the recurrences of any object with repeated objects"))
1451 (t "(recurrence-table? cycles-f)"
1452 (emt:assert
1453 (equal answer "#t")))
1454 (t "(recurrences-get-object-count cycles-f #f)"
1455 (emt:assert
1456 (equal answer "2")))
1457 (t "($define! a (list 12))"
1458 (emt:doc "Define a circular object"))
1459 (t "(set-cdr! a a)")
1460 (t "($define! cycles-a (get-recurrences a))")
1461 (t "(recurrence-table? cycles-a)"
1462 (emt:assert
1463 (equal answer "#t")))
1464 (t "(recurrences-get-object-count cycles-a a)"
1465 (emt:assert
1466 (equal answer "2"))))
1468 ;;On lists and wrapping
1469 (expect
1470 ((exec+args (list debug-klink-executable))
1471 (shell t)
1472 (prompt "\nklink> ")
1473 (timeout 10)
1474 (append-newline t))
1475 (t "")
1476 (t "(list 1 2)"
1477 (emt:doc "List works")
1478 (emt:assert
1479 (equal answer "(1 2)")))
1480 (t "(reverse (list 1 2))"
1481 (emt:doc "Reverse works")
1482 (emt:assert
1483 (equal answer "(2 1)")))
1484 (t "((wrap list) 1 2)"
1485 (emt:doc "Wrap wrapped over an applicative works (wrap^2)")
1486 (emt:assert
1487 (equal answer "(1 2)")))
1488 (t "((wrap list) '1 '2)"
1489 (emt:doc "Wrap^2 eliminates at least one level of quoting")
1490 (emt:assert
1491 (equal answer "(1 2)")))
1492 (t "((wrap list) ''1 ''2)"
1493 (emt:doc "Wrap^2 eliminates two levels of quoting")
1494 (emt:assert
1495 (equal answer "(1 2)")))
1496 (t "((wrap list) '''1 '''2)"
1497 (emt:doc "Wrap^2 leaves one of three levels of quoting")
1498 (emt:assert
1499 (equal answer "((#,$quote 1) (#,$quote 2))")))
1500 (t "((wrap (wrap list)) '''1 '''2)"
1501 (emt:doc "Wrap^3 eliminates three levels of quoting")
1502 (emt:assert
1503 (equal answer "(1 2)"))))
1505 ;;On map, map1, counted-map/4
1506 (expect
1507 ((exec+args (list debug-klink-executable))
1508 (shell t)
1509 (prompt "\nklink> ")
1510 (timeout 10)
1511 (append-newline t))
1512 (t "")
1513 (t "(map1 list '(1 2 3))"
1514 (emt:doc "It works")
1515 (emt:assert
1516 (equal answer "((1) (2) (3))")))
1517 (t "(map1 (unwrap list) '(1 2 3))"
1518 (emt:doc "It wants an applicative argument")
1519 (emt:assert
1520 (emt:eq-persist-p #'equal
1521 answer
1522 "dbid:bf93cc1e-534c-4a1f-8762-3072e59dcb3c")))
1523 (t "(counted-map/4 2 1 list '((1 2)))"
1524 (emt:doc "Generally behaves like `map'")
1525 (emt:assert
1526 (equal answer "((1) (2))")))
1527 (t "(counted-map/4 1 1 list '((1 2)))"
1528 (emt:doc "Stops after N elements")
1529 (emt:assert
1530 (equal answer "((1))")))
1531 (t "(counted-map/4 2 2 list '((1 2) (11 12)))"
1532 (emt:doc "Can treat multiple lists")
1533 (emt:assert
1534 (equal answer "((1 11) (2 12))")))
1535 (t "(map list '(1 2))"
1536 (emt:doc "Check full `map'")
1537 (emt:assert
1538 (equal answer "((1) (2))")))
1539 (t "(map list '(1 2) '(11 12))"
1540 (emt:assert
1541 (equal answer "((1 11) (2 12))"))))
1543 ;;On continuations
1544 (expect
1545 ((exec+args (list debug-klink-executable))
1546 (shell t)
1547 (prompt "\nklink> ")
1548 (timeout 10)
1549 (append-newline t))
1550 (t "")
1551 (t "($define! my-con-list (call/cc list))"
1552 (emt:doc "Make an object containing a continuation"))
1553 (t "my-con-list"
1554 (emt:doc "Check what we got")
1555 (emt:assert
1556 (equal answer "(#<CONTINUATION>)")))
1557 (t "($define! my-con (car my-con-list))"
1558 (emt:doc "Extract that continuation"))
1559 (t "my-con"
1560 (emt:doc "Check what we got")
1561 (emt:assert
1562 (equal answer "#<CONTINUATION>")))
1563 (t "(continuation->applicative my-con)"
1564 (emt:doc "Try a simple call")
1565 (emt:assert
1566 (equal answer "#<APPLICATIVE>")))
1567 (t "((continuation->applicative my-con) 12)"
1568 (emt:doc "Use the continuation")
1569 (emt:assert
1570 (equal answer "#inert")))
1571 (t "my-con-list"
1572 (emt:doc "my-con-list got redefined by the continuation")
1573 (emt:assert
1574 (equal answer "(12)")))
1575 (t "(apply (continuation->applicative (extend-continuation my-con
1576 ($lambda v
1577 (display \"arrived at the continuation with \")
1578 (write v)
1579 (newline)))) '(144))"
1580 (emt:assert
1581 (equal answer
1582 "arrived at the continuation with (144)\n#inert")))
1583 (t "($define! my-unguarded-con (guard-continuation '() my-con '()))"
1584 (emt:doc "Make a continuation that has empty list of guards")
1585 (emt:assert
1586 (equal answer "#inert")))
1587 (t "(apply (continuation->applicative my-unguarded-con) '(145))"
1588 (emt:doc "Applies without problem")
1589 (emt:assert
1590 (equal answer "#inert")))
1591 (t "my-con-list"
1592 (emt:doc "The continuation got called")
1593 (emt:assert
1594 (equal answer "(145)")))
1596 (t "($define! my-guarded-con (guard-continuation
1597 (list (list root-continuation
1598 ($lambda (v %ignore)
1599 (display \"entering the continuation with \")
1600 (write v)
1601 (newline)
1602 v)))
1603 my-con
1604 (list (list root-continuation
1605 ($lambda (v %ignore)
1606 (display \"exiting the continuation with \")
1607 (write v)
1608 (newline)
1609 v)))))"
1610 (emt:doc "Create a guarded continuation")
1611 (emt:assert
1612 (equal answer "#inert")))
1613 (t "my-guarded-con"
1614 (emt:doc "Type is correct")
1615 (emt:assert
1616 (equal answer "#<CONTINUATION>")))
1617 (t "(continuation->applicative my-guarded-con)"
1618 (emt:doc "Type is correct")
1619 (emt:assert
1620 (equal answer "#<APPLICATIVE>")))
1621 (t "(apply (continuation->applicative my-guarded-con) '(146))"
1622 (emt:doc "We see it calls the guard and continues")
1623 (emt:assert
1624 (equal answer "entering the continuation with (146)\n#inert")))
1625 (t "my-con-list"
1626 (emt:doc "The continuation got called")
1627 (emt:assert
1628 (equal answer "(146)")))
1629 (t "(guard-dynamic-extent
1630 '()
1631 ($lambda () (display \"Got here\")(newline))
1632 '())"
1633 (emt:doc "Calls the combiner arg with no variables")
1634 (emt:assert
1635 (equal answer "Got here\n#inert")))
1636 (t "(guard-dynamic-extent
1637 (list (list root-continuation ($lambda (v %ignore)
1638 (display \"Abnormally entering dynamic extent.\")
1639 (newline)
1640 v)))
1641 ($lambda () (display \"Got here\")(newline))
1642 '())"
1643 (emt:doc "Does not initially call the entry guards")
1644 (emt:assert
1645 (equal answer "Got here\n#inert")))
1646 (t "(guard-dynamic-extent
1647 '()
1648 ($lambda () (display \"Got here\")(newline))
1649 (list (list root-continuation ($lambda (v %ignore)
1650 (display \"Abnormally entering dynamic extent.\")
1651 (newline)
1652 v))))"
1653 (emt:doc "Does not initially call the exit guards")
1654 (emt:assert
1655 (equal answer "Got here\n#inert"))))
1659 ;;On `and?' etc
1660 (expect
1661 ((exec+args (list debug-klink-executable))
1662 (shell t)
1663 (prompt "\nklink> ")
1664 (timeout 10)
1665 (append-newline t))
1666 (t "")
1667 (t "and?"
1668 (emt:doc "Is recognized")
1669 (emt:assert
1670 (equal answer "#,and?")))
1671 (t "(and?)"
1672 (emt:doc "Given no args, returns true")
1673 (emt:assert
1674 (equal answer "#t")))
1675 (t "(and? #t)"
1676 (emt:doc "Accepts 1 arg")
1677 (emt:assert
1678 (equal answer "#t")))
1679 (t "(and? #t #t)"
1680 (emt:doc "Accepts 2 args")
1681 (emt:assert
1682 (equal answer "#t")))
1683 (t "(and? #t #f)"
1684 (emt:doc "If an arg is false, returns false")
1685 (emt:assert
1686 (equal answer "#f")))
1687 (t "(and? #t (integer? 1))"
1688 (emt:doc "Arguments are evaluated")
1689 (emt:assert
1690 (equal answer "#t")))
1691 (t "(and? #t (integer? \"11\"))"
1692 (emt:doc "The evaluated value is used")
1693 (emt:assert
1694 (equal answer "#f")))
1695 (t "(or? #f)"
1696 (emt:doc "If there are only false clauses, returns false")
1697 (emt:assert
1698 (equal answer "#f")))
1699 (t "(or? #f #t)"
1700 (emt:doc "If there is any true clause, return true")
1701 (emt:assert
1702 (equal answer "#t")))
1703 (t "(or? #f #t #f)"
1704 (emt:assert
1705 (equal answer "#t")))
1706 (t "($and?)"
1707 (emt:doc "The evaluating variant")
1708 (emt:assert
1709 (equal answer "#t")))
1710 (t "($and? #t #f)"
1711 (emt:assert
1712 (equal answer "#f")))
1713 (t "($and? #f #t)"
1714 (emt:assert
1715 (equal answer "#f")))
1716 (t "($and? ($sequence (display \"One\")(newline) #f))"
1717 (emt:doc "Evaluates some of its args, at least the first one")
1718 (emt:assert
1719 (equal answer "One\n#f")))
1720 (t "($and? ($sequence (display \"One\")(newline) #t)($sequence (display \"Two\")(newline) #f))"
1721 (emt:assert
1722 (equal answer "One\nTwo\n#f")))
1723 (t "($and? ($sequence (display \"One\")(newline) #f)($sequence (display \"Two\")(newline) #f))"
1724 (emt:assert
1725 (equal answer "One\n#f")))
1726 (t "(every?/2-xary and? '())"
1727 (emt:doc "xary-1 `every?/2-xary' is available (in `simple' environment)")
1728 (emt:assert
1729 (equal answer "#t")))
1730 (t "(every?/2-xary and? '(()))"
1731 (emt:doc "No elements")
1732 (emt:assert
1733 (equal answer "#t")))
1734 (t "(every?/2-xary and? '((#f)))"
1735 (emt:doc "One element containing one element (for `and?')")
1736 (emt:assert
1737 (equal answer "#f")))
1738 (t "(every?/2-xary and? '((#t #t)))"
1739 (emt:doc "More elements")
1740 (emt:assert
1741 (equal answer "#t")))
1742 (t "(every?/2-xary and? '((#t #t)(#t)))"
1743 (emt:assert
1744 (equal answer "#t")))
1745 (t "(every?/2-xary and? '((#t #t)(#f)))"
1746 (emt:assert
1747 (equal answer "#f"))))
1750 (expect
1751 ((exec+args (list debug-klink-executable))
1752 (shell t)
1753 (prompt "\nklink> ")
1754 (timeout 10)
1755 (append-newline t))
1756 (t "")
1757 (t "(>? 1 0)"
1758 (emt:doc "Test that comparisons work as expected")
1759 (emt:assert
1760 (equal answer "#t")))
1761 (t "(>? 1 1)"
1762 (emt:assert
1763 (equal answer "#f")))
1764 (t "(>? 1 2)"
1765 (emt:assert
1766 (equal answer "#f")))
1767 (t "(<? 1 0)"
1768 (emt:assert
1769 (equal answer "#f")))
1770 (t "(<? 1 1)"
1771 (emt:assert
1772 (equal answer "#f")))
1773 (t "(<? 1 2)"
1774 (emt:assert
1775 (equal answer "#t")))
1776 (t "(>=? 1 0)"
1777 (emt:assert
1778 (equal answer "#t")))
1779 (t "(>=? 1 1)"
1780 (emt:assert
1781 (equal answer "#t")))
1782 (t "(>=? 1 2)"
1783 (emt:assert
1784 (equal answer "#f")))
1785 (t "(<=? 1 0)"
1786 (emt:assert
1787 (equal answer "#f")))
1788 (t "(<=? 1 1)"
1789 (emt:assert
1790 (equal answer "#t")))
1791 (t "(<=? 1 2)"
1792 (emt:assert
1793 (equal answer "#t")))
1794 (t "(compare-neighbors <? '(0 1 2))"
1795 (emt:assert
1796 (equal answer "#t")))
1797 (t "(compare-neighbors <? '(0))"
1798 (emt:assert
1799 (equal answer "#t")))
1800 (t "(compare-neighbors <=? '(0 1 2))"
1801 (emt:assert
1802 (equal answer "#t")))
1803 (t "(compare-neighbors <? '(0 1 1 2))"
1804 (emt:assert
1805 (equal answer "#f")))
1806 (t "(compare-neighbors <=? '(0 1 1 2))"
1807 (emt:assert
1808 (equal answer "#t"))))
1811 (expect
1812 ((exec+args (list debug-klink-executable))
1813 (shell t)
1814 (prompt "\nklink> ")
1815 (timeout 10)
1816 (append-newline t))
1817 (t "")
1818 (t "(+ 1 2 3)"
1819 (emt:doc "N-ary addition works")
1820 (emt:assert
1821 (equal answer "6")))
1822 (t "(+ 1 2 (+ 3 0))"
1823 (emt:doc "N-ary addition evaluates its arguments")
1824 (emt:assert
1825 (equal answer "6")))
1826 (t "(+)"
1827 (emt:doc "N-ary addition gives 0 on no operands")
1828 (emt:assert
1829 (equal answer "0")))
1830 (t "(+ 3)"
1831 (emt:doc "N-ary addition with 1 operand works")
1832 (emt:assert
1833 (equal answer "3")))
1835 (t "(* 1 2 30)"
1836 (emt:doc "N-ary multiplication works")
1837 (emt:assert
1838 (equal answer "60")))
1839 (t "(* 1 2 (* 3 10))"
1840 (emt:doc "N-ary multiplication evaluates its arguments")
1841 (emt:assert
1842 (equal answer "60")))
1843 (t "(*)"
1844 (emt:doc "N-ary multiplication gives 0 on no operands")
1845 (emt:assert
1846 (equal answer "1")))
1847 (t "(* 3)"
1848 (emt:doc "N-ary multiplication with 1 operand works")
1849 (emt:assert
1850 (equal answer "3")))
1851 (t "(/ 2 2)"
1852 (emt:doc "Dividing an integer by itself gives 1")
1853 (emt:assert
1854 (equal answer "1")))
1855 (t "(/ 2 1)"
1856 (emt:doc "Dividing an integer by 1 gives itself")
1857 (emt:assert
1858 (equal answer "2")))
1859 (t "(/ 1.0 2.0)"
1860 (emt:doc "For real division, it doesn't floor")
1861 (emt:assert
1862 (equal answer "0.5")))
1863 (t "(/ 6 3)"
1864 (emt:assert
1865 (equal answer "2")))
1866 (t "(/ 6 3 2)"
1867 (emt:assert
1868 (equal answer "1")))
1869 (t "(/ 6 3 2 2)"
1870 (emt:assert
1871 (equal answer "0.5")))
1872 (t "(- 100 20)"
1873 (emt:assert
1874 (equal answer "80")))
1875 (t "(- 100 20 5)"
1876 (emt:assert
1877 (equal answer "75")))
1878 (t "(- 100)"
1879 (emt:doc "`-' with no subtrahends raises error")
1880 (emt:assert
1881 (emt:eq-persist-p #'equal answer
1882 "dbid:d0afc822-58f7-4921-b37d-57d45cd6b5e0")))
1883 (t "(/ 6)"
1884 (emt:doc "`/' with no divisors raises error")
1885 (emt:assert
1886 (emt:eq-persist-p #'equal answer
1887 "dbid:2afbb9f8-3016-46a5-bb93-9d9d2fdd0e98"))))
1888 ;;equal?
1889 (expect
1890 ((exec+args (list debug-klink-executable))
1891 (shell t)
1892 (prompt "\nklink> ")
1893 (timeout 10)
1894 (append-newline t))
1895 (t "")
1896 (t "(equal?/2 3 3)"
1897 (emt:doc "Compares numbers correctly")
1898 (emt:assert
1899 (equal answer "#t")))
1900 (t "(equal?/2 3 2)"
1901 (emt:assert
1902 (equal answer "#f")))
1903 (t "(equal?/2 3 '(1 2))"
1904 (emt:assert
1905 (equal answer "#f")))
1906 (t "(equal?/2 'a 'a)"
1907 (emt:doc "Compares symbols correctly")
1908 (emt:assert
1909 (equal answer "#t")))
1910 (t "(equal?/2 'a 'b)"
1911 (emt:assert
1912 (equal answer "#f")))
1913 (t "(equal?/2 '(1 2) '(1 2))"
1914 (emt:doc "Compares lists correctly")
1915 (emt:assert
1916 (equal answer "#t")))
1917 (t "(equal?/2 '(1 2) '(1 3))"
1918 (emt:doc "Compares lists correctly")
1919 (emt:assert
1920 (equal answer "#f")))
1921 (t "(equal?/2 \"meet\" \"meet\")"
1922 (emt:doc "Compares strings correctly")
1923 (emt:assert
1924 (equal answer "#t")))
1925 (t "(equal?/2 \"meet\" \"not\")"
1926 (emt:doc "Compares strings correctly")
1927 (emt:assert
1928 (equal answer "#f")))
1929 (t "(equal?)"
1930 (emt:doc "Given the empty list, is true")
1931 (emt:assert
1932 (equal answer "#t")))
1937 ;;$provide, $binds?
1938 (expect
1939 ((exec+args (list debug-klink-executable))
1940 (shell t)
1941 (prompt "\nklink> ")
1942 (timeout 10)
1943 (append-newline t))
1944 (t "")
1945 (t "($define! a #f)")
1946 (t "($define! b #f)")
1947 (t "($provide! (b c) ($define! a 13) ($define! b 12) ($define! c 144))"
1948 (emt:doc "`$provide!' b and c but not a")
1949 (emt:assert
1950 (equal answer "#inert")))
1951 (t "a"
1952 (emt:doc "`a' is what it was")
1953 (emt:assert
1954 (equal answer "#f")))
1955 (t "b"
1956 (emt:doc "b has been changed")
1957 (emt:assert
1958 (equal answer "12")))
1959 (t "c"
1960 (emt:doc "c is available")
1961 (emt:assert
1962 (equal answer "144")))
1963 (t "((wrap $binds?/2) (get-current-environment) 'wrap)"
1964 (emt:doc "Test the simple version")
1965 (emt:doc "We know `wrap' should be bound")
1966 (emt:assert
1967 (equal answer "#t")))
1968 (t "((wrap $binds?/2) (get-current-environment) '$binds?/2)"
1969 (emt:doc "We know `$binds?/2' should be bound")
1970 (emt:assert
1971 (equal answer "#t")))
1972 (t "((wrap $binds?/2) (make-environment) '$binds?/2)"
1973 (emt:doc "`make-environment' should bind nothing.")
1974 (emt:assert
1975 (equal answer "#f")))
1976 (t "((wrap $binds?/2) (make-environment) 'unlikely-to-be-bound)"
1977 (emt:doc "In case the preceding test worked for the wrong \
1978 reason, ie that `make-environment' leaked")
1979 (emt:assert
1980 (equal answer "#f")))
1981 (t "($binds? (get-current-environment) $binds?)"
1982 (emt:doc "The N-ary version works")
1983 (emt:assert
1984 (equal answer "#t")))
1985 (t "($binds? (make-environment) $binds?)"
1986 (emt:doc "Discriminates")
1987 (emt:assert
1988 (equal answer "#f")))
1989 (t "($binds? (get-current-environment) list wrap)"
1990 (emt:doc "Takes more than 1 arg")
1991 (emt:assert
1992 (equal answer "#t"))))
1994 (expect
1995 ((exec+args (list debug-klink-executable))
1996 (shell t)
1997 (prompt "\nklink> ")
1998 (timeout 10)
1999 (append-newline t))
2000 (t "")
2001 (t "($define! a (open-input-file \"test-m1.krn\"))"
2002 (emt:doc "Open an input port from a known file")
2003 (emt:assert
2004 (equal answer "#inert")))
2005 (t "a"
2006 (emt:doc "We got a port")
2007 (emt:assert
2008 (equal answer "#<PORT>")))
2009 (t "(get-char a)"
2010 (emt:doc "Check the first few characters against known values")
2011 (emt:assert
2012 (equal answer "#\\;")))
2013 (t "(get-char a)"
2014 (emt:assert
2015 (equal answer "#\\newline")))
2016 (t "(get-char a)"
2017 (emt:assert
2018 (equal answer "#\\;"))))
2020 (expect
2021 ((exec+args (list debug-klink-executable))
2022 (shell t)
2023 (prompt "\nklink> ")
2024 (timeout 10)
2025 (append-newline t))
2026 (t "")
2027 (t "($binds? (get-current-environment) not-bound-in-ground)"
2028 (emt:doc "Validate that `not-bound-in-ground' is not already bound")
2029 (emt:assert
2030 (equal answer "#f")))
2031 (t "($define! a (make-kernel-standard-environment))"
2032 (emt:doc "Create a standard environment")
2033 (emt:assert
2034 (equal answer "#inert")))
2035 (t "($binds? a $binds?)"
2036 (emt:doc "The ground bindings are available")
2037 (emt:assert
2038 (equal answer "#t")))
2039 (t "($set! a not-bound-in-ground 12)"
2040 (emt:doc "set `not-bound-in-ground' in a")
2041 (emt:assert
2042 (equal answer "#inert")))
2043 (t "($binds? a not-bound-in-ground)"
2044 (emt:doc "It's bound in `a'")
2045 (emt:assert
2046 (equal answer "#t")))
2047 (t "(eval 'not-bound-in-ground a)"
2048 (emt:doc "It has the right value in `a'")
2049 (emt:assert
2050 (equal answer "12")))
2051 (t "($binds? (get-current-environment) not-bound-in-ground)"
2052 (emt:doc "It's not bound in current environment")
2053 (emt:assert
2054 (equal answer "#f")))
2055 (t "($define! x (get-module \"test-m1.krn\"))"
2056 (emt:doc "In `x', no parameters are defined")
2057 (emt:doc (concat "Answer: " answer)))
2058 (t "($define! y (get-module \"test-m1.krn\"
2059 ($bindings->environment (baz \"quux\"))))"
2060 (emt:doc "In `y', `baz' is defined")
2061 (emt:doc (concat "Answer: " answer)))
2062 (t "($define! z (get-module \"test-m1.krn\"
2063 ($bindings->environment (quux \"baz\"))))"
2064 (emt:doc "In `z', quux' is defined")
2065 (emt:doc (concat "Answer: " answer)))
2066 (t "(write (($remote-eval foo x)))"
2067 (emt:doc "Query `x'")
2068 (emt:assert
2069 (equal answer "no parameters\n#inert#inert")))
2070 (t "(write (($remote-eval foo y)))"
2071 (emt:doc "Query `y'")
2072 (emt:assert
2073 (equal answer "parameters, but no quux\n#inert#inert")))
2074 (t "(write (($remote-eval foo z)))"
2075 (emt:doc "Query `z'")
2076 (emt:assert
2077 (equal answer "parameters\n\"baz\"#inert"))))
2079 (expect
2080 ((exec+args (list debug-klink-executable))
2081 (shell t)
2082 (prompt "\nklink> ")
2083 (timeout 10)
2084 (append-newline t))
2085 (t "")
2086 (t "($let* ((low-promise ($lazy (cons 1 2)))(p1 ($lazy (($lambda
2087 ((x . y)) x) (force low-promise))))) (force p1))"
2088 (emt:doc "WRITE ME")
2089 (emt:assert
2090 (equal answer "1")))
2091 (t "($let* ((low-promise ($lazy (cons 1 2)))(p1 ($lazy (($lambda
2092 ((x . y)) y) (force low-promise))))) (force p1))"
2093 (emt:doc "WRITE ME")
2094 (emt:assert
2095 (equal answer "2"))))
2097 ;;Automatically forcing promises
2098 (expect
2099 ((exec+args (list debug-klink-executable))
2100 (shell t)
2101 (prompt "\nklink> ")
2102 (timeout 10)
2103 (append-newline t))
2104 (t "")
2105 (t "(car ($lazy '(1)))"
2106 (emt:doc "Car can force a promise")
2107 (emt:assert
2108 (equal answer "1")))
2109 (t "(car ($lazy '(2 3)))"
2110 (emt:assert
2111 (equal answer "2")))
2112 (t "((wrap $binds?/2) (get-current-environment) '$binds?/2)"
2113 (emt:doc "Validate that this call works")
2114 (emt:assert
2115 (equal answer "#t")))
2116 (t "((wrap $binds?/2) ($lazy (get-current-environment)) '$binds?/2)"
2117 (emt:doc "And validate that it works with one arg")
2118 (emt:assert
2119 (equal answer "#t")))
2121 (t "((wrap $binds?/2) ($lazy (get-current-environment)) ($lazy '$binds?/2))"
2122 (emt:doc "We can force two arguments")
2123 (emt:assert
2124 (equal answer "#t")))
2125 (t "(every?/2-xary integer? '((1) (2)))"
2126 (emt:doc "Validate that this call works")
2127 (emt:assert
2128 (equal answer "#t")))
2129 (t "(every?/2-xary integer? '((1) (#f)))"
2130 (emt:doc "False works too")
2131 (emt:assert
2132 (equal answer "#f")))
2134 (t "(every?/2-xary ($lazy integer?) '((1) (2)))"
2135 (emt:doc "Arguments after the forced argument work")
2136 (emt:assert
2137 (equal answer "#t")))
2139 (t "(every?/2-xary ($lazy integer?) '((1) (#f)))"
2140 (emt:assert
2141 (equal answer "#f")))
2143 (t "(every?/2-xary ($lazy integer?) ($lazy '((1) (2))))"
2144 (emt:doc "Arguments after the forced argument work")
2145 (emt:assert
2146 (equal answer "#t")))
2148 (t "(every?/2-xary ($lazy integer?) ($lazy '((1) (#f))))"
2149 (emt:assert
2150 (equal answer "#f"))))
2153 (expect
2154 ((exec+args (list debug-klink-executable))
2155 (shell t)
2156 (prompt "\nklink> ")
2157 (timeout 10)
2158 (append-newline t))
2159 (t "")
2160 (t "(profiling 1)"
2161 (emt:doc "Turn profiling on, and it should not have been on before")
2162 (emt:assert
2163 (equal answer "0")))
2164 (t "(profiling 1)"
2165 (emt:doc "Now it's on, and this is our first profiled call")
2166 (emt:assert
2167 (equal answer "1")))
2168 (t "(get-profiling-data)"
2169 (emt:doc "We see the profiling data from just the earlier call")
2170 (emt:doc "All profiling data may change, we're interested in
2171 its general behavior and in including the functions we just called")
2172 (emt:assert
2173 (emt:eq-persist-p #'equal
2174 answer
2175 "dbid:787cceb2-39a0-46c3-97a7-a23a3de3da4b")))
2176 (t "(profiling 1)"
2177 (emt:doc "Run this call again")
2178 (emt:assert
2179 (equal answer "1")))
2180 (t "(get-profiling-data)"
2181 (emt:doc "Now profiling data shows 2 calls to `profiling', 1
2182 to `get-profiling-data'")
2183 (emt:assert
2184 (emt:eq-persist-p #'equal
2185 answer
2186 "dbid:26b534dc-b589-4d2c-9026-7c5ea9b8a858")))
2187 (t "(get-profiling-data)"
2188 (emt:doc "Again")
2189 (emt:assert
2190 (emt:eq-persist-p #'equal
2191 answer
2192 "dbid:3c018d05-1938-4af6-8ad3-5325b9d16fd6"))))
2196 ;;;_ , debug-klink-capture-form
2197 ;;;###autoload
2198 (defun debug-klink-capture-form ()
2199 "Push entries for an `emtr:expect' script onto the kill ring.
2200 Basically `emtr:expect:buffer-capture-form' specialized for klink.
2202 Current buffer should contain a transcript of a klink session."
2205 (interactive)
2206 (emtr:expect:buffer-capture-form debug-klink-prompt t t))
2208 ;;;_. Footers
2209 ;;;_ , Provides
2211 (provide 'debug-klink)
2213 ;;;_ * Local emacs vars.
2214 ;;;_ + Local variables:
2215 ;;;_ + mode: allout
2216 ;;;_ + End:
2218 ;;;_ , End
2219 ;;; debug-klink.el ends here