Closed porcuquine closed 2 weeks ago
Here is the function:
!(defrec match-star (lambda (matcher s) (let ((first-match (matcher s))) (if first-match (let ((rest-match (match-star matcher (cdr s)))) (cons (cons (car first-match) (car rest-match)) (cdr rest-match))) (cons nil s)))))
This leads to the following error:
!(def match-char (lambda (c s) (if (eq c (car s)) (cons (car s) (cdr s))))) !(assert-eq '(('a' 'a' 'a') . "b") (match-star (match-char 'a') "aaab")) => Error: loop detcted
I expect this to succeed. As a sanity check, I ported to Common Lisp:
(defun match-char (c s) (if (eql c (car s)) (cons (car s) (cdr s)))) (defun match-star (matcher s) (let ((first-match (funcall matcher s))) (if first-match (let ((rest-match (match-star matcher (cdr s)))) (cons (cons (car first-match) (car rest-match)) (cdr rest-match))) (cons nil s)))) (match-star (lambda (x) (match-char 'a x)) '(a a a b)) => ((A A A) B)
The above report is actually not reproducible. I traced the actual error to a different piece of code in a longer source file.
Here is the function:
This leads to the following error:
I expect this to succeed. As a sanity check, I ported to Common Lisp: