From 688ade34430eb1d4d205698cae810c35c8f44d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Fri, 8 Nov 2024 15:06:17 -0300 Subject: Turn bind and one-of into macros to avoid eagerly evaluating arguments --- base.lisp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'base.lisp') diff --git a/base.lisp b/base.lisp index 61c47bc..bbfab80 100644 --- a/base.lisp +++ b/base.lisp @@ -13,18 +13,18 @@ (declare (ignore lazy)) (make-parsing :tree tree :left input))) -(defun bind (parser f) - (lambda (input &key lazy) - (let ((r (funcall parser input))) - (cond ((parsing-p r) - (if lazy - (lambda (ignored-input &key lazy) - (declare (ignore ignored-input)) - (funcall (funcall f (parsing-tree r) input) - (parsing-left r) - :lazy lazy)) - (funcall (funcall f (parsing-tree r) input) - (parsing-left r)))) - ((failure-p r) - r) - (t (error (format nil "Invalid return value: ~a" r))))))) +(defmacro bind (parser f) + `(lambda (input &key lazy) + (let ((r (funcall ,parser input))) + (cond ((parsing-p r) + (if lazy + (lambda (ignored-input &key lazy) + (declare (ignore ignored-input)) + (funcall (funcall ,f (parsing-tree r) input) + (parsing-left r) + :lazy lazy)) + (funcall (funcall ,f (parsing-tree r) input) + (parsing-left r)))) + ((failure-p r) + r) + (t (error (format nil "Invalid return value: ~a" r))))))) -- cgit v1.2.3