{"instruction": "Generate a defmacro form that transforms code like this:\n(make-name-transformer name \"-ZORK\")\n\nPattern to recognize: Macro call that should be transformed by make-name-transformer", "input": "(make-name-transformer name \"-ZORK\")", "output": "(defmacro make-name-transformer (&rest elements)\n \"Return an accessor name transformer.\nThe unquoted `name' symbol argument is substituted for the slot name.\nClass option examples:\n\n :accessor-name-transformer (make-name-transformer \\\"FOO-\\\" name \\\"-BAR\\\")\n\nUse the slot name directly:\n\n :accessor-name-transformer (make-name-transformer name)\"\n `(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol ,@(mapcar (lambda (el)\n (if (and (symbolp el)\n (string= (symbol-name el) \"NAME\"))\n 'name\n el))\n elements))))", "macroexpand": "(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol name \"-ZORK\"))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(check-cursor-attached cluffer:beginning-of-line-p (cursor))\n\nIssue: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:beginning-of-line-p (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:beginning-of-line-p :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(letrec-syntax common-lisp:nil (common-lisp:progn))\n\nWrite a macro that addresses: Macro call that should be transformed by LETREC-SYNTAX", "input": "(letrec-syntax common-lisp:nil (common-lisp:progn))", "output": "(defmacro LETREC-SYNTAX ...)", "macroexpand": "(common-lisp:macrolet ()\n (common-lisp:progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(augment init-code `((setq ,extra-save-var ,(save-info-iv-ref s-i))))\n\nWrite a macro that addresses: Macro call that should be transformed by augment", "input": "(augment init-code `((setq ,extra-save-var ,(save-info-iv-ref s-i))))", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf init-code (nconc init-code (sb-int:quasiquote ((setq #S(sb-impl::comma :expr extra-save-var :kind 0) #S(sb-impl::comma :expr (save-info-iv-ref s-i) :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-quote-char (map nil (lambda (ex) (format out \"~&~A;~%~A\" (sxql:yield ex) statement-separator)) expressions))\n\nPattern to recognize: Macro call that should be transformed by with-quote-char", "input": "(with-quote-char (map nil (lambda (ex) (format out \"~&~A;~%~A\" (sxql:yield ex) statement-separator)) expressions))", "output": "(defmacro with-quote-char (&body body)\n `(let ((sxql:*quote-character* (or sxql:*quote-character*\n (connection-quote-character *connection*))))\n ,@body))", "macroexpand": "(let ((sxql/sql-type:*quote-character* (or sxql/sql-type:*quote-character* (connection-quote-character *connection*)))) (map nil (lambda (ex) (format out \"~&~A;~%~A\" (sxql/sql-type:yield ex) statement-separator)) expressions))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(count-of nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by COUNT-OF", "input": "(count-of nil\n :key\n nil)", "output": "(defmacro COUNT-OF ...)", "macroexpand": "(lc (nil :key nil) count)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-custom-var (:array-scope *array-scope-variables*) '(*internal-decoder*) \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON Array.\")\n\nWhat needs to change: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:array-scope *array-scope-variables*) '(*internal-decoder*) \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON Array.\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*array-scope-variables* . :array-scope)) *custom-vars* :test (function equal)) (defvar *array-scope-variables* (quote (*internal-decoder*)) \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON Array.\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-collectors nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-COLLECTORS", "input": "(with-collectors nil\n nil)", "output": "(defmacro WITH-COLLECTORS ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lambda-match0 ((cons key pattern) `(assoc ,key ,pattern)))\n\nIssue: Macro call that should be transformed by lambda-match0", "input": "(lambda-match0 ((cons key pattern) `(assoc ,key ,pattern)))", "output": "(defmacro lambda-match0 (&body clauses)\n (alexandria:with-gensyms (arg)\n `(lambda (,arg)\n (match0 ,arg\n ,@clauses))))", "macroexpand": "(lambda (#:arg165) (match0 #:arg165 ((cons key pattern) (sb-int:quasiquote (assoc #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr pattern :kind 0))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defmacro-driver 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DEFMACRO-DRIVER", "input": "(defmacro-driver 'some-name)", "output": "(defmacro DEFMACRO-DRIVER ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defmacro clause-quote-2 (&key ((:quote some-name)) generate))\n (iterate::install-clause-info '(quote) '(quote) 'clause-quote-2 nil t)\n ''some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(check-cursor-attached cluffer:items (cursor &key start end))\n\nWhat needs to change: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:items (cursor &key start end))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:items :before ((cursor cluffer:cursor) &key start end) (declare (ignore end start)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(none-of nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by NONE-OF", "input": "(none-of nil\n :key\n nil)", "output": "(defmacro NONE-OF ...)", "macroexpand": "(lc (nil :key nil) never)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(collect-max nil :key nil)\n\nIssue: Macro call that should be transformed by COLLECT-MAX", "input": "(collect-max nil :key nil)", "output": "(defmacro COLLECT-MAX ...)", "macroexpand": "(common-lisp:let* ((#:generator-379 (generator :key))\n #:items-369\n (#:generator-377 (generator nil))\n #:numbers-368\n (#:number-371 nil)\n #:result-372)\n (declare (type generator #:generator-379)\n (type generator #:generator-377)\n (type (null-or t) #:result-372))\n (tagbody\n #:ll-380\n (setq #:items-369 (next-in #:generator-379 (go end)))\n (setq #:numbers-368 (next-in #:generator-377 (go end)))\n (if (or (null #:number-371) (< #:number-371 #:numbers-368))\n (setq #:number-371 #:numbers-368\n #:result-372 #:items-369))\n (go #:ll-380)\n end)\n (if (null #:number-371)\n (setq #:result-372 nil))\n #:result-372)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(is-false t)\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is-false t)", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:value201 t)) (if #:value201 (process-failure (quote t) \"~S returned the value ~S, which is true\" (quote t) #:value201) (add-result (quote test-passed) :test-expr (quote t))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-shell-component roy :input-type \"roy\" :output-type \"js\" :shell-command (\"roy\" \"-r\"))\n\nWhat needs to change: Macro call that should be transformed by define-shell-component", "input": "(define-shell-component roy :input-type \"roy\" :output-type \"js\" :shell-command (\"roy\" \"-r\"))", "output": "(defmacro define-shell-component (name &key input-type output-type shell-command)\n \"Define an ASDF component that's compiled by running a shell command.\"\n `(define-component ,name\n :input-type ,input-type\n :output-type ,output-type\n :compile-function (lambda (input-pathname output-pathname)\n (inferior-shell:run (list ,@(ensure-list shell-command)\n input-pathname\n output-pathname)\n :show t))))", "macroexpand": "(define-component roy :input-type \"roy\" :output-type \"js\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run (list \"roy\" \"-r\" input-pathname output-pathname) :show t)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-modf-rewrite cddr (expr) `(cdr (cdr ,(second expr))))\n\nProblem: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cddr (expr) `(cdr (cdr ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cddr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cdr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-rewrite cdaaar (expr) `(cdr (caaar ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cdaaar (expr) `(cdr (caaar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdaaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (caaar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when ret-body (setf body (rest ret-body)) (setf type (first ret-body)))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when ret-body (setf body (rest ret-body)) (setf type (first ret-body)))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if ret-body (progn (setf body (rest ret-body)) (setf type (first ret-body))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun/1 getc (fd) (fgetc fd))\n\nWhat needs to change: Macro call that should be transformed by defun/1", "input": "(defun/1 getc (fd) (fgetc fd))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun getc (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (fgetc fd)) (defparameter getc (vacietis.c:mkptr& (symbol-function (quote getc)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error unable-to-resolve-func-type () (func-name args) \"Unable to resolve the result type of function '~a' when called~%with the argument types:~%~a~%\" func-name (mapcar #'type->type-spec (mapcar #'primary-type args)))\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error unable-to-resolve-func-type () (func-name args) \"Unable to resolve the result type of function '~a' when called~%with the argument types:~%~a~%\" func-name (mapcar #'type->type-spec (mapcar #'primary-type args)))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition unable-to-resolve-func-type (:error-type varjo-error :prefix \"Varjo\") (func-name args) \"Unable to resolve the result type of function '~a' when called~%with the argument types:~%~a~%\" func-name (mapcar (function type->type-spec) (mapcar (function primary-type) args)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-dynenv-macro nil\n (progn))\n\nProblem: Macro call that should be transformed by DEF-DYNENV-MACRO", "input": "(def-dynenv-macro nil\n (progn))", "output": "(defmacro DEF-DYNENV-MACRO ...)", "macroexpand": "(defmacro nil (progn &environment #:env175) (with-dynenv #:env175))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-shell-component sass-strict :input-type \"sass\" :output-type \"css\" :shell-command \"sass\")\n\nProblem: Macro call that should be transformed by define-shell-component", "input": "(define-shell-component sass-strict :input-type \"sass\" :output-type \"css\" :shell-command \"sass\")", "output": "(defmacro define-shell-component (name &key input-type output-type shell-command)\n \"Define an ASDF component that's compiled by running a shell command.\"\n `(define-component ,name\n :input-type ,input-type\n :output-type ,output-type\n :compile-function (lambda (input-pathname output-pathname)\n (inferior-shell:run (list ,@(ensure-list shell-command)\n input-pathname\n output-pathname)\n :show t))))", "macroexpand": "(define-component sass-strict :input-type \"sass\" :output-type \"css\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run (list \"sass\" input-pathname output-pathname) :show t)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(do+ (accumulating-to foo) (stop-when (> (length foo) 10)) (returning foo) (do+ (for x (in '(1 2 3))) (do+ (for y (in '(a b))) (collect (list x y) :into foo))))\n\nPattern to recognize: Macro call that should be transformed by do+", "input": "(do+ (accumulating-to foo) (stop-when (> (length foo) 10)) (returning foo) (do+ (for x (in '(1 2 3))) (do+ (for y (in '(a b))) (collect (list x y) :into foo))))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (accumulating-to foo) (stop-when (> (length foo) 10)) (returning foo) (do+ (for x (in (quote (1 2 3)))) (do+ (for y (in (quote (a b)))) (collect (list x y) :into foo))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(disable-quasiquote-2.0)\n\nProblem: Macro call that should be transformed by DISABLE-QUASIQUOTE-2.0", "input": "(disable-quasiquote-2.0)", "output": "(defmacro DISABLE-QUASIQUOTE-2.0 ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (%disable-quasiquote-2.0))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(ematch0 args (nil nil) ((list* '&key rest) (list* '&key (process-keyword-args rest))) ((list* '&rest rest) (list* '&rest (process-rest-args rest))) ((list* '&aux rest) args) ((list* (list name) rest) (list* (list name ''_) (process-optional-args rest))) ((list* (list name default) rest) (list* (list name default) (process-optional-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-optional-args rest))) ((list* name rest) (list* (list name ''_) (process-optional-args rest))))\n\nPattern to recognize: Macro call that should be transformed by ematch0", "input": "(ematch0 args (nil nil) ((list* '&key rest) (list* '&key (process-keyword-args rest))) ((list* '&rest rest) (list* '&rest (process-rest-args rest))) ((list* '&aux rest) args) ((list* (list name) rest) (list* (list name ''_) (process-optional-args rest))) ((list* (list name default) rest) (list* (list name default) (process-optional-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-optional-args rest))) ((list* name rest) (list* (list name ''_) (process-optional-args rest))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 args (nil nil) ((list* (quote &key) rest) (list* (quote &key) (process-keyword-args rest))) ((list* (quote &rest) rest) (list* (quote &rest) (process-rest-args rest))) ((list* (quote &aux) rest) args) ((list* (list name) rest) (list* (list name (quote (quote _))) (process-optional-args rest))) ((list* (list name default) rest) (list* (list name default) (process-optional-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-optional-args rest))) ((list* name rest) (list* (list name (quote (quote _))) (process-optional-args rest))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(slet 42 (alet 43 (slet it it)))\n\nIssue: Macro call that should be transformed by slet", "input": "(slet 42 (alet 43 (slet it it)))", "output": "(defmacro slet (form &body body)\n \"Binds the FORM to IT (via SYMBOL-MACROLET) in the scope of the BODY. IT can\nbe set with SETF.\"\n `(symbolic ignore-first ,form (progn ,@body)))", "macroexpand": "(symbolic ignore-first 42 (progn (alet 43 (slet it it))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-alias-binding sum summing)\n\nProblem: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding sum summing)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote sum)) (quote summing)) (quote sum))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error flow-ids-mandatory (:error-type varjo-critical-error) (for primary-type) \"~a must be given flow id/s when created: type - ~s\" for primary-type)\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error flow-ids-mandatory (:error-type varjo-critical-error) (for primary-type) \"~a must be given flow id/s when created: type - ~s\" for primary-type)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition flow-ids-mandatory (:error-type varjo-critical-error :prefix \"Varjo\") (for primary-type) \"~a must be given flow id/s when created: type - ~s\" for primary-type)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-compile-time magic-continuation-argument (continuation) (if (or (eq (first (second (second continuation))) '&optional) (eq (first (second (second continuation))) '&rest)) (second (second (second continuation))) (first (second (second continuation)))))\n\nWhat needs to change: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time magic-continuation-argument (continuation) (if (or (eq (first (second (second continuation))) '&optional) (eq (first (second (second continuation))) '&rest)) (second (second (second continuation))) (first (second (second continuation)))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun magic-continuation-argument (continuation) (if (or (eq (first (second (second continuation))) (quote &optional)) (eq (first (second (second continuation))) (quote &rest))) (second (second (second continuation))) (first (second (second continuation))))) (eval-when (:compile-toplevel) (compile (quote magic-continuation-argument))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(product-of 'some-name)\n\nIssue: Macro call that should be transformed by PRODUCT-OF", "input": "(product-of 'some-name)", "output": "(defmacro PRODUCT-OF ...)", "macroexpand": "(lc ('some-name) multiply)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(peek-char*)\n\nWrite a macro that addresses: Macro call that should be transformed by peek-char*", "input": "(peek-char*)", "output": "(defmacro peek-char* ()\n \"Convenience macro because we always peek at the same string with\nthe same arguments.\"\n `(peek-char nil *stream* t nil t))", "macroexpand": "(peek-char nil *stream* t nil t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do+ (for s (symbols-in :doplus-tests :internal)) (for l (maximizing (length (symbol-name s)) :saving s :in symbol-with-longest-name)) (returning symbol-with-longest-name))\n\nProblem: Macro call that should be transformed by do+", "input": "(do+ (for s (symbols-in :doplus-tests :internal)) (for l (maximizing (length (symbol-name s)) :saving s :in symbol-with-longest-name)) (returning symbol-with-longest-name))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for s (symbols-in :doplus-tests :internal)) (for l (maximizing (length (symbol-name s)) :saving s :in symbol-with-longest-name)) (returning symbol-with-longest-name))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ematch0 pattern ((list 'guard1 sym test) (pushnew (first (ensure-list sym)) syms)) ((list* 'guard1 sym test more-patterns) (pushnew (first (ensure-list sym)) syms) (analyze-more-patterns more-patterns)) ((list* 'or1 or-subpatterns) (map nil #'analyze-pattern or-subpatterns)))\n\nWrite a macro that addresses: Macro call that should be transformed by ematch0", "input": "(ematch0 pattern ((list 'guard1 sym test) (pushnew (first (ensure-list sym)) syms)) ((list* 'guard1 sym test more-patterns) (pushnew (first (ensure-list sym)) syms) (analyze-more-patterns more-patterns)) ((list* 'or1 or-subpatterns) (map nil #'analyze-pattern or-subpatterns)))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 pattern ((list (quote guard1) sym test) (pushnew (first (ensure-list sym)) syms)) ((list* (quote guard1) sym test more-patterns) (pushnew (first (ensure-list sym)) syms) (analyze-more-patterns more-patterns)) ((list* (quote or1) or-subpatterns) (map nil (function analyze-pattern) or-subpatterns)) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(drelet nil)\n\nIssue: Macro call that should be transformed by DRELET", "input": "(drelet nil)", "output": "(defmacro DRELET ...)", "macroexpand": "(dynamic-relet nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-condition/a dbi-error (simple-error) () (:documentation \"Base class of all other error exceptions. Use this to catch all DBI errors.\"))\n\nPattern to recognize: Macro call that should be transformed by define-condition/a", "input": "(define-condition/a dbi-error (simple-error) () (:documentation \"Base class of all other error exceptions. Use this to catch all DBI errors.\"))", "output": "(defmacro define-condition/a (name parent-types slots &body options)\n `(progn\n (define-condition ,name ,parent-types ,slots ,@options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (define-condition dbi-error (simple-error) nil (:documentation \"Base class of all other error exceptions. Use this to catch all DBI errors.\")) (deftype nil (quote dbi-error)) (setf (find-class (quote )) (find-class (quote dbi-error))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-cruft %readtable-name (readtable) \"Return the name associated with READTABLE.\" #+ :common-lisp (values (gethash readtable *readtable-names*)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-cruft", "input": "(define-cruft %readtable-name (readtable) \"Return the name associated with READTABLE.\" #+ :common-lisp (values (gethash readtable *readtable-names*)))", "output": "(defmacro define-cruft (name lambda-list &body (docstring . alternatives))\n (assert (typep docstring 'string) (docstring) \"Docstring missing!\")\n (assert (not (null alternatives)))\n `(progn\n (declaim (inline ,name))\n (defun ,name ,lambda-list ,docstring ,(first alternatives))))", "macroexpand": "(progn (declaim (inline %readtable-name)) (defun %readtable-name (readtable) \"Return the name associated with READTABLE.\" (values (gethash readtable *readtable-names*))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n;; Conditional logic with different variable bindings per branch\n;; requires deeply nested lets inside each cond clause\n(cond ((> x 0)\n (let ((order :ascending)\n (bound (sqrt x)))\n (process order bound)))\n ((< x 0)\n (let ((order :descending)\n (bound (sqrt (- x))))\n (process order bound)))\n (t\n (let ((order :zero)\n (bound 0))\n (process order bound))))\n\n;; Repetitive: same body structure, different bindings per branch\n\nWrite a macro that addresses: Cond with per-branch variable bindings leads to duplicated body code \u2014 want shared body with branch-specific bindings", "input": ";; Conditional logic with different variable bindings per branch\n;; requires deeply nested lets inside each cond clause\n(cond ((> x 0)\n (let ((order :ascending)\n (bound (sqrt x)))\n (process order bound)))\n ((< x 0)\n (let ((order :descending)\n (bound (sqrt (- x))))\n (process order bound)))\n (t\n (let ((order :zero)\n (bound 0))\n (process order bound))))\n\n;; Repetitive: same body structure, different bindings per branch", "output": "(defmacro condlet (clauses &body body)\n (let ((bodfn (gensym))\n (vars (mapcar #'(lambda (v) (cons v (gensym)))\n (remove-duplicates\n (mapcar #'car\n (mappend #'cdr clauses))))))\n `(labels ((,bodfn ,(mapcar #'car vars)\n ,@body))\n (cond ,@(mapcar #'(lambda (cl)\n (condlet-clause vars cl bodfn))\n clauses)))))", "macroexpand": ";; (condlet (((= x 0) (order :zero) (bound 0))\n;; ((> x 0) (order :ascending) (bound (sqrt x)))\n;; ((< x 0) (order :descending) (bound (sqrt (- x)))))\n;; (process order bound))\n;;\n;; Each cond clause specifies test + bindings.\n;; The body (process order bound) is shared across all clauses.\n;; Variables from ALL clauses are recognized and gensym'd.", "category": "control-flow", "technique": "gensym,nested-backquote", "complexity": "intermediate", "quality_score": 0.9625} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-hamt dict (:test test :hash hash :table table) (flet ((%insert (table key value) (%dict-insert table key value (funcall hash key) 0 test))) (make-instance 'hash-dict :test test :hash hash :table (labels ((f (table args) (if args (let ((key (car args)) (value (cadr args))) (f (%insert table key value) (cddr args))) table))) (f table args)))))\n\nIssue: Macro call that should be transformed by with-hamt", "input": "(with-hamt dict (:test test :hash hash :table table) (flet ((%insert (table key value) (%dict-insert table key value (funcall hash key) 0 test))) (make-instance 'hash-dict :test test :hash hash :table (labels ((f (table args) (if args (let ((key (car args)) (value (cadr args))) (f (%insert table key value) (cddr args))) table))) (f table args)))))", "output": "(defmacro with-hamt (hamt (&key test hash table) &body body)\n \"Accessing HAMT slots\"\n `(with-accessors ((,test hamt-test)\n (,hash hamt-hash)\n (,table hamt-table))\n ,hamt\n ,@body))", "macroexpand": "(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) dict (flet ((%insert (table key value) (%dict-insert table key value (funcall hash key) 0 test))) (make-instance (quote hash-dict) :test test :hash hash :table (labels ((f (table args) (if args (let ((key (car args)) (value (cadr args))) (f (%insert table key value) (cddr args))) table))) (f table args)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lret* () 1)\n\nIssue: Macro call that should be transformed by lret*", "input": "(lret* () 1)", "output": "(defmacro lret* ((&rest bindings) &body body)\n \"Cf. `lret'.\"\n `(lret-aux let* ,bindings\n ,@body))", "macroexpand": "(lret-aux let* nil 1)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dynamic-let* nil\n nil)\n\nProblem: Macro call that should be transformed by DYNAMIC-LET*", "input": "(dynamic-let* nil\n nil)", "output": "(defmacro DYNAMIC-LET* ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defproto nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFPROTO", "input": "(defproto nil)", "output": "(defmacro DEFPROTO ...)", "macroexpand": "(progn\n (declaim (special nil))\n (eval-when (:compile-toplevel))\n (setf (symbol-value 'nil)\n (ensure-object (when (boundp 'nil) (symbol-value 'nil)) (list)\n :properties (list) :nickname 'nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(or nil nil)\n\nProblem: Macro call that should be transformed by OR", "input": "(or nil nil)", "output": "(defmacro OR ...)", "macroexpand": "(let ((#:g201 nil))\n (if #:g201\n #:g201\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-shadowed-custom-vars (let ((tricky-json \"{\\\"start_XPos\\\":98,\\\"start_YPos\\\":4}\") (*json-symbols-package* (find-package :keyword))) (set-decoder-simple-list-semantics) (is (equal '((:START--*X-POS . 98) (:START--*Y-POS . 4)) (decode-json-from-string tricky-json)))))\n\nIssue: Macro call that should be transformed by with-shadowed-custom-vars", "input": "(with-shadowed-custom-vars (let ((tricky-json \"{\\\"start_XPos\\\":98,\\\"start_YPos\\\":4}\") (*json-symbols-package* (find-package :keyword))) (set-decoder-simple-list-semantics) (is (equal '((:START--*X-POS . 98) (:START--*Y-POS . 4)) (decode-json-from-string tricky-json)))))", "output": "(defmacro with-shadowed-custom-vars (&body body)\n `(let ,(loop for (var) in *custom-vars*\n collect `(,var (if (boundp ',var) ,var)))\n ,@body))", "macroexpand": "(let ((*aggregate-scope-variables* (if (boundp (quote *aggregate-scope-variables*)) *aggregate-scope-variables*)) (*string-scope-variables* (if (boundp (quote *string-scope-variables*)) *string-scope-variables*)) (*array-scope-variables* (if (boundp (quote *array-scope-variables*)) *array-scope-variables*)) (*object-scope-variables* (if (boundp (quote *object-scope-variables*)) *object-scope-variables*)) (*internal-decoder* (if (boundp (quote *internal-decoder*)) *internal-decoder*)) (*end-of-object-handler* (if (boundp (quote *end-of-object-handler*)) *end-of-object-handler*)) (*object-value-handler* (if (boundp (quote *object-value-handler*)) *object-value-handler*)) (*object-key-handler* (if (boundp (quote *object-key-handler*)) *object-key-handler*)) (*beginning-of-object-handler* (if (boundp (quote *beginning-of-object-handler*)) *beginning-of-object-handler*)) (*json-array-type* (if (boundp (quote *json-array-type*)) *json-array-type*)) (*end-of-array-handler* (if (boundp (quote *end-of-array-handler*)) *end-of-array-handler*)) (*array-member-handler* (if (boundp (quote *array-member-handler*)) *array-member-handler*)) (*beginning-of-array-handler* (if (boundp (quote *beginning-of-array-handler*)) *beginning-of-array-handler*)) (*end-of-string-handler* (if (boundp (quote *end-of-string-handler*)) *end-of-string-handler*)) (*string-char-handler* (if (boundp (quote *string-char-handler*)) *string-char-handler*)) (*beginning-of-string-handler* (if (boundp (quote *beginning-of-string-handler*)) *beginning-of-string-handler*)) (*boolean-handler* (if (boundp (quote *boolean-handler*)) *boolean-handler*)) (*real-handler* (if (boundp (quote *real-handler*)) *real-handler*)) (*integer-handler* (if (boundp (quote *integer-handler*)) *integer-handler*))) (let ((tricky-json \"{\\\"start_XPos\\\":98,\\\"start_YPos\\\":4}\") (*json-symbols-package* (find-package :keyword))) (set-decoder-simple-list-semantics) (is (equal (quote ((:start--*x-pos . 98) (:start--*y-pos . 4))) (decode-json-from-string tricky-json)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-generic generic ((a a) (b b)) (+ a b))\n\nPattern to recognize: Macro call that should be transformed by define-generic", "input": "(define-generic generic ((a a) (b b)) (+ a b))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b) (:method ((a a) (b b)) (+ a b))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with nil\n (progn))\n\nProblem: Macro call that should be transformed by WITH", "input": "(with nil\n (progn))", "output": "(defmacro WITH ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ok t)\n\nWrite a macro that addresses: Macro call that should be transformed by ok", "input": "(ok t)", "output": "(defmacro ok (test &optional desc)\n (with-gensyms (duration result)\n (once-only (test desc)\n `(with-catching-errors (:expected T :description ,desc)\n (with-duration ((,duration ,result) ,test)\n (test ,result t ,desc\n :duration ,duration\n :test-fn (lambda (x y)\n (eq (not (null x)) y))\n :got-form ,test))))))", "macroexpand": "(let ((#:test142 t) (#:desc143 nil)) (with-catching-errors (:expected t :description #:desc143) (with-duration ((#:duration140 #:result141) #:test142) (test #:result141 t #:desc143 :duration #:duration140 :test-fn (lambda (x y) (eq (not (null x)) y)) :got-form #:test142))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(->> nil (progn))\n\nIssue: Macro call that should be transformed by ->>", "input": "(->> nil (progn))", "output": "(defmacro ->> ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect-max nil)\n\nWhat needs to change: Macro call that should be transformed by COLLECT-MAX", "input": "(collect-max nil)", "output": "(defmacro COLLECT-MAX ...)", "macroexpand": "(common-lisp:let* ((#:generator-340 (generator nil))\n #:numbers-334\n (#:number-336 nil))\n (declare (type generator #:generator-340))\n (tagbody\n #:ll-341\n (setq #:numbers-334 (next-in #:generator-340 (go end)))\n (if (or (null #:number-336) (< #:number-336 #:numbers-334))\n (setq #:number-336 #:numbers-334))\n (go #:ll-341)\n end)\n (if (null #:number-336)\n (setq #:number-336 nil))\n #:number-336)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(all-of nil)\n\nPattern to recognize: Macro call that should be transformed by ALL-OF", "input": "(all-of nil)", "output": "(defmacro ALL-OF ...)", "macroexpand": "(lc (nil) always)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(quasiquote-unexpand-1 #-quasiquote-strict-append 'unquote-splicing #+quasiquote-strict-append 'x-unquote (car (last x)))\n\nIssue: Macro call that should be transformed by quasiquote", "input": "(quasiquote-unexpand-1 #-quasiquote-strict-append 'unquote-splicing #+quasiquote-strict-append 'x-unquote (car (last x)))", "output": "(defmacro quasiquote (x) (quasiquote-expand x))", "macroexpand": "(quasiquote-unexpand-1 (quote unquote-splicing) (car (last x)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(pop-preprocessor-directive-token token-list directive-symbol)\n\nIssue: Macro call that should be transformed by pop-preprocessor-directive-token", "input": "(pop-preprocessor-directive-token token-list directive-symbol)", "output": "(defmacro pop-preprocessor-directive-token (token-list directive-name &key (errorp t))\n \"Pops the next token in TOKEN-LIST ignoring `+whitespace-marker+'\"\n (with-gensyms (head_)\n `(let ((,head_\n (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)))\n (if (eq +whitespace-marker+ ,head_)\n (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)\n ,head_))))", "macroexpand": "(let ((#:head_264 (check-and-pop-pp-directive-token-1 token-list directive-symbol t))) (if (eq +whitespace-marker+ #:head_264) (check-and-pop-pp-directive-token-1 token-list directive-symbol t) #:head_264))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-op (:+ conjunctive-op))\n\nProblem: Macro call that should be transformed by define-op", "input": "(define-op (:+ conjunctive-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (+-op (:include conjunctive-op (name \"+\")) (:constructor make-+-op (&rest expressions))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(inext-or-error nil)\n\nIssue: Macro call that should be transformed by INEXT-OR-ERROR", "input": "(inext-or-error nil)", "output": "(defmacro INEXT-OR-ERROR ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro nil) nil))))\n (if (not vals)\n (error 'stop-iteration)\n (values (car vals) t)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(def-neo4j-fun add-to-index ((type :node) name key value object-id) :post (:uri-spec (format nil \"index/~A/~A\" (string-downcase (symbol-name type)) name)) (:encode (list (list (cons :uri object-id) (case type (:node :node-url) (:relationship :relationship-url))) (list (cons :key key)) (list (cons :value value))) :object) (:status-handlers (201 (decode-neo4j-json-output body))))\n\nWrite a macro that addresses: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun add-to-index ((type :node) name key value object-id) :post (:uri-spec (format nil \"index/~A/~A\" (string-downcase (symbol-name type)) name)) (:encode (list (list (cons :uri object-id) (case type (:node :node-url) (:relationship :relationship-url))) (list (cons :key key)) (list (cons :value value))) :object) (:status-handlers (201 (decode-neo4j-json-output body))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun add-to-index (&key (type :node) name key value object-id) (let ((uri (format nil \"index/~A/~A\" (string-downcase (symbol-name type)) name)) (json (encode-neo4j-json-payload (list (list (cons :uri object-id) (case type (:node :node-url) (:relationship :relationship-url))) (list (cons :key key)) (list (cons :value value))) :object))) (make-neo4j-request :post uri json (list (list 201 (lambda (body uri json) (decode-neo4j-json-output body))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(*> +opt-fws+ +sliding-quoted-pairs+)\n\nPattern to recognize: Macro call that should be transformed by *>", "input": "(*> +opt-fws+ +sliding-quoted-pairs+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset149) (multiple-value-bind (#:*>-res150 #:*>-next151) (funcall +opt-fws+ #:*>-offset149) (if (ok? #:*>-res150) (funcall +sliding-quoted-pairs+ #:*>-next151) (fail #:*>-next151))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(resolve\n nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by RESOLVE", "input": "(resolve\n nil\n :key\n nil)", "output": "(defmacro RESOLVE ...)", "macroexpand": "(locally\n (declare)\n (multiple-value-bind (#:assignment153 #:unified-p154)\n (type-unify 'nil 'nil (list))\n (assert #:unified-p154 nil 'simple-type-error :format-control\n \"gtypes failed to unify to the actual types:~% ~a~% against~% ~a\"\n :format-arguments (list 'nil (list)))\n (let ()\n (declare (ignorable))\n nil\n :key\n nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-template nil (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFINE-TEMPLATE", "input": "(define-template nil (progn))", "output": "(defmacro DEFINE-TEMPLATE ...)", "macroexpand": "(defmacro define-nil (&optional (#:name127))\n (flet ((template-unfulfillable ()\n (error 'template-unfulfillable :template 'nil :arguments (list))))\n (declare (ignorable (function template-unfulfillable)))\n (let ((body (progn)) (name (or #:name127 (compose-name #\\SOLIDUS 'nil))))\n `(progn\n (declaim\n (ftype\n (function\n ,(loop with types = (declared-variable-types body)\n for arg in (quote (progn))\n collect (or (second (assoc arg types)) (quote t)))\n ,(declared-return-type body))\n ,name)\n ,@(when (find (quote inline) (declarations body)) `((inline ,name))))\n (defun ,name ,'(progn)\n (declare (optimize speed (safety 0) (debug 0) (compilation-speed 0))\n ,@(remove (quote inline) (declarations body)))\n ,@(remove-if #'declaration-p body))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(as->* nil)\n\nPattern to recognize: Macro call that should be transformed by AS->*", "input": "(as->* nil)", "output": "(defmacro AS->* ...)", "macroexpand": "(as-> nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclass/std default () ((with-std)))\n\nProblem: Macro call that should be transformed by defclass/std", "input": "(defclass/std default () ((with-std)))", "output": "(defmacro defclass/std (name direct-superclasses direct-slots &rest options\n &environment env)\n \"Shortcut macro to the DEFCLASS macro.\n\n (defclass/std example ()\n ((slot1 slot2 slot3)))\n\n expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\n Each slot definition accepts options:\n\n :std 1 => changes the :initform to 1. It can be :unbound.\n :with or :with-prefix => creates accessors with the class name as prefix.\n\n See the README for more.\n\n See also `class/std' and `print-object/std'.\n \"\n `(defclass ,name ,direct-superclasses\n ,(process-slots env direct-slots name)\n ,@options))", "macroexpand": "(defclass default nil ((with-std :accessor with-std :initarg :with-std :initform nil)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(inext-noexit nil)\n\nWhat needs to change: Macro call that should be transformed by INEXT-NOEXIT", "input": "(inext-noexit nil)", "output": "(defmacro INEXT-NOEXIT ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro nil) nil))))\n (if (not vals)\n (values nil nil)\n (values (car vals) t)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(make-obsolete mustache-render-to-string render* \"0.10.0\")\n\nPattern to recognize: Macro call that should be transformed by make-obsolete", "input": "(make-obsolete mustache-render-to-string render* \"0.10.0\")", "output": "(defmacro make-obsolete (obsolete-name current-name when)\n `(defun ,obsolete-name (&rest args)\n ,(documentation current-name 'function)\n (warn 'deprecation-warning\n :name ',obsolete-name :replacement ',current-name :since ,when)\n (apply ',current-name args)))", "macroexpand": "(defun mustache-render-to-string (&rest args) #A((48) base-char . \"Render TEMPLATE with optional CONTEXT to string.\") (warn (quote deprecation-warning) :name (quote mustache-render-to-string) :replacement (quote render*) :since \"0.10.0\") (apply (quote render*) args))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (not (< 1 0)))\n\nIssue: Macro call that should be transformed by is", "input": "(is (not (< 1 0)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e185 1) (#:a186 0)) (if (progn (not (< #:e185 #:a186))) (add-result (quote test-passed) :test-expr (quote (not (< 1 0)))) (process-failure (quote (not (< 1 0))) \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\" (quote 0) #:a186 (quote <) #:e185)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(undefmessage nil)\n\nWhat needs to change: Macro call that should be transformed by UNDEFMESSAGE", "input": "(undefmessage nil)", "output": "(defmacro UNDEFMESSAGE ...)", "macroexpand": "(fmakunbound 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-assert-observers (\"deleting bar\" bar bar-1 baz) (store-remove :bar store))\n\nProblem: Macro call that should be transformed by with-assert-observers", "input": "(with-assert-observers (\"deleting bar\" bar bar-1 baz) (store-remove :bar store))", "output": "(defmacro with-assert-observers ((desc &rest asserted-observers) &body body) \n `(let ((*observers* nil))\n (trc ,desc \" -- checking observers\")\n ,@body\n (let ((superfluous-observers (loop for run in *observers* if (not (member run (list ,@asserted-observers))) collect run))\n\t (failed-observers (loop for asserted in (list ,@asserted-observers) if (not (member asserted *observers*)) collect asserted)))\n (trc \"called observers on\" *observers* :superflous superfluous-observers :failed failed-observers)\n (assert (not superfluous-observers))\n (assert (not failed-observers)))))", "macroexpand": "(let ((*observers* nil)) (trc \"deleting bar\" \" -- checking observers\") (store-remove :bar store) (let ((superfluous-observers (loop for run in *observers* if (not (member run (list bar bar-1 baz))) collect run)) (failed-observers (loop for asserted in (list bar bar-1 baz) if (not (member asserted *observers*)) collect asserted))) (trc \"called observers on\" *observers* :superflous superfluous-observers :failed failed-observers) (assert (not superfluous-observers)) (assert (not failed-observers))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do-matches (s e regex target-string count :start start :end end) (incf count))\n\nWrite a macro that addresses: Macro call that should be transformed by do-matches", "input": "(do-matches (s e regex target-string count :start start :end end) (incf count))", "output": "(defmacro do-matches ((match-start match-end regex\n target-string\n &optional result-form\n &key start end)\n &body body)\n \"Iterates over TARGET-STRING and tries to match REGEX as often as\npossible evaluating BODY with MATCH-START and MATCH-END bound to the\nstart/end positions of each match in turn. After the last match,\nreturns RESULT-FORM if provided or NIL otherwise. An implicit block\nnamed NIL surrounds DO-MATCHES; RETURN may be used to terminate the\nloop immediately. If REGEX matches an empty string the scan is\ncontinued one position behind this match. BODY may start with\ndeclarations.\"\n ;; this is a simplified form of DO-SCANS - we just provide two dummy\n ;; vars and ignore them\n (with-unique-names (reg-starts reg-ends)\n `(do-scans (,match-start ,match-end\n ,reg-starts ,reg-ends\n ,regex ,target-string\n ,result-form\n :start ,start :end ,end)\n ,@body)))", "macroexpand": "(do-scans (s e #:reg-starts137 #:reg-ends138 regex target-string count :start start :end end) (incf count))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(incf nil)\n\nWrite a macro that addresses: Macro call that should be transformed by INCF", "input": "(incf nil)", "output": "(defmacro INCF ...)", "macroexpand": "(setq nil (+ 1 nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-html-string (:p (values \"foo\") \"bar\" \"baz\"))\n\nWrite a macro that addresses: Macro call that should be transformed by with-html", "input": "(with-html-string (:p (values \"foo\") \"bar\" \"baz\"))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:p (values \"foo\") \"bar\" \"baz\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(ematch0 accessor ((list 'function name) name) ((list 'quote name) name) (_ (error \"[access] 1st arg is not a function designator\")))\n\nPattern to recognize: Macro call that should be transformed by ematch0", "input": "(ematch0 accessor ((list 'function name) name) ((list 'quote name) name) (_ (error \"[access] 1st arg is not a function designator\")))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 accessor ((list (quote function) name) name) ((list (quote quote) name) name) (_ (error \"[access] 1st arg is not a function designator\")) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defmethod nil)\n\nWhat needs to change: Macro call that should be transformed by DEFMETHOD", "input": "(defmethod nil)", "output": "(defmacro DEFMETHOD ...)", "macroexpand": "(common-lisp:defmethod nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(case 'some-name)\n\nProblem: Macro call that should be transformed by CASE", "input": "(case 'some-name)", "output": "(defmacro CASE ...)", "macroexpand": "(let ((#:g196 'some-name))\n (declare (ignorable #:g196))\n (cond))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(all-of nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by ALL-OF", "input": "(all-of nil\n (progn))", "output": "(defmacro ALL-OF ...)", "macroexpand": "(lc (nil (progn)) always)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(continue-whopper 'some-name)\n\nPattern to recognize: Macro call that should be transformed by CONTINUE-WHOPPER", "input": "(continue-whopper 'some-name)", "output": "(defmacro CONTINUE-WHOPPER ...)", "macroexpand": "(call-next-method-fn self class-env inst-env mcs%caller mcs%next-methods\n (list 'some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(set-bop nil nil)\n\nIssue: Macro call that should be transformed by SET-BOP", "input": "(set-bop nil nil)", "output": "(defmacro SET-BOP ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn\n (save-binfix)\n (mapc\n (lambda (ops)\n (mapc\n (lambda (op1)\n (when (eq (car op1) 'nil)\n (setf (cadr op1) 'nil)\n (unless t (setf (cddr op1) 'nil))))\n ops))\n *binfix*)\n (assign-properties)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(mvlet* (x) x)\n\nProblem: Macro call that should be transformed by mvlet*", "input": "(mvlet* (x) x)", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(let* (x) x)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when (not (node-slot body)) (format stream \";\"))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when (not (node-slot body)) (format stream \";\"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (not (node-slot body)) (format stream \";\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ematch0 clause ((list* patterns body) (list* (expand-multipatterns patterns) body)))\n\nWhat needs to change: Macro call that should be transformed by ematch0", "input": "(ematch0 clause ((list* patterns body) (list* (expand-multipatterns patterns) body)))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 clause ((list* patterns body) (list* (expand-multipatterns patterns) body)) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(make-simple-collector-to-place nil)\n\nWrite a macro that addresses: Macro call that should be transformed by MAKE-SIMPLE-COLLECTOR-TO-PLACE", "input": "(make-simple-collector-to-place nil)", "output": "(defmacro MAKE-SIMPLE-COLLECTOR-TO-PLACE ...)", "macroexpand": "(progn\n (setf nil (alexandria:ensure-list nil))\n (let* ((#:tail123 (last nil)))\n (lambda (&rest values) (collect-at-end nil #:tail123 values) nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (setf query (execute-with-retry query binds)) (query-row-count query))\n\nWhat needs to change: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (setf query (execute-with-retry query binds)) (query-row-count query))", "output": "(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)\n `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))", "macroexpand": "(call-with-prepared-query *connection* sql (lambda (query) (setf query (execute-with-retry query binds)) (query-row-count query)) :use-prepare-cached *use-prepare-cached*)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is (= a (dummy-add a 0)))\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is (= a (dummy-add a 0)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e155 a) (#:a156 (dummy-add a 0))) (if (progn (= #:e155 #:a156)) (add-result (quote test-passed) :test-expr (quote (= a (dummy-add a 0)))) (process-failure (quote (= a (dummy-add a 0))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (dummy-add a 0)) #:a156 (quote =) #:e155)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-script-symbol-macro nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEFINE-SCRIPT-SYMBOL-MACRO", "input": "(define-script-symbol-macro nil\n nil)", "output": "(defmacro DEFINE-SCRIPT-SYMBOL-MACRO ...)", "macroexpand": "(define-ps-symbol-macro nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is-print (princ \"ABCDEFGH\") \"ABCDEFGHIJKLMNO\")\n\nProblem: Macro call that should be transformed by is-print", "input": "(is-print (princ \"ABCDEFGH\") \"ABCDEFGHIJKLMNO\")", "output": "(defmacro is-print (got expected &optional desc)\n (with-gensyms (output duration duration-inner)\n (once-only (expected desc)\n `(with-catching-errors (:description ,desc :expected ,expected)\n (let* (,duration\n (,output (with-output-to-string (*standard-output*)\n (with-duration ((,duration-inner ,output) ,got)\n (declare (ignore ,output))\n (setq ,duration ,duration-inner)))))\n (test ,output ,expected ,desc\n :duration ,duration\n :got-form ',got\n :test-fn #'string=\n :report-expected-label \"output\"))))))", "macroexpand": "(let ((#:expected203 \"ABCDEFGHIJKLMNO\") (#:desc204 nil)) (with-catching-errors (:description #:desc204 :expected #:expected203) (let* (#:duration201 (#:output200 (with-output-to-string (*standard-output*) (with-duration ((#:duration-inner202 #:output200) (princ \"ABCDEFGH\")) (declare (ignore #:output200)) (setq #:duration201 #:duration-inner202))))) (test #:output200 #:expected203 #:desc204 :duration #:duration201 :got-form (quote (princ \"ABCDEFGH\")) :test-fn (function string=) :report-expected-label \"output\"))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-hook-type string->string (function (string) string) \"Hook that takes a string and produces a new one.\")\n\nIssue: Macro call that should be transformed by define-hook-type", "input": "(define-hook-type string->string (function (string) string) \"Hook that takes a string and produces a new one.\")", "output": "(defmacro define-hook-type (name type &optional documentation)\n \"Define hook class.\nType must be something like:\n\n (function (string) (values integer t))\n\nThe `handler-type' of the defined hook class has `:class' allocation\ntype, so that all hooks of such class have the same `handler-type'.\"\n (let* ((name (string name))\n (hook-class-name (intern (serapeum:concat \"HOOK-\" name))))\n `(defclass ,hook-class-name (hook)\n ((handler-type :initform ',type :allocation :class))\n (:metaclass closer-mop:funcallable-standard-class)\n ,@(when documentation\n `((:documentation ,documentation))))))", "macroexpand": "(defclass hook-string->string (hook) ((handler-type :initform (quote (function (string) string)) :allocation :class)) (:metaclass sb-mop:funcallable-standard-class) (:documentation \"Hook that takes a string and produces a new one.\"))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-<> -<>> some-<> some-<>>)\n\nWrite a macro that addresses: Macro call that should be transformed by -<>", "input": "(-<> -<>> some-<> some-<>>)", "output": "(defmacro -<> (init &body exps) (diamond-wand init exps))", "macroexpand": "(block #:g122 (block #:g121 -<>>))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defclass/std example () ((slot1 slot2 slot3)))\n\nPattern to recognize: Macro call that should be transformed by defclass/std", "input": "(defclass/std example () ((slot1 slot2 slot3)))", "output": "(defmacro defclass/std (name direct-superclasses direct-slots &rest options\n &environment env)\n \"Shortcut macro to the DEFCLASS macro.\n\n (defclass/std example ()\n ((slot1 slot2 slot3)))\n\n expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\n Each slot definition accepts options:\n\n :std 1 => changes the :initform to 1. It can be :unbound.\n :with or :with-prefix => creates accessors with the class name as prefix.\n\n See the README for more.\n\n See also `class/std' and `print-object/std'.\n \"\n `(defclass ,name ,direct-superclasses\n ,(process-slots env direct-slots name)\n ,@options))", "macroexpand": "(defclass example nil ((slot1 :accessor slot1 :initarg :slot1 :initform nil) (slot2 :accessor slot2 :initarg :slot2 :initform nil) (slot3 :accessor slot3 :initarg :slot3 :initform nil)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-> :g () 2)\n\nWhat needs to change: Macro call that should be transformed by ->", "input": "(-> :g () 2)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g nil 2)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-log-error-handling () (with-wcs-math-error-handling (ret (log1+ x)) (check-wcs-math-result)))\n\nIssue: Macro call that should be transformed by with-log-error-handling", "input": "(with-log-error-handling () (with-wcs-math-error-handling (ret (log1+ x)) (check-wcs-math-result)))", "output": "(defmacro with-log-error-handling (() &body body)\n `(handler-case\n (progn ,@body)\n #+allegro\n ;; TODO: rewrite other `simple-error' handler to use arithmetic-error.\n (arithmetic-error (e)\n (let ((operands (arithmetic-error-operands e)))\n (cond ((zerop (first operands))\n (wcs-raise-fe-exception FE_DIVBYZERO :errno ERANGE)\n (- HUGE_VAL))\n (t\n (error e)))))))", "macroexpand": "(handler-case (progn (with-wcs-math-error-handling (ret (log1+ x)) (check-wcs-math-result))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(signal-reader-error \"Could not find character with name '~A'\" name)\n\nProblem: Macro call that should be transformed by signal-reader-error", "input": "(signal-reader-error \"Could not find character with name '~A'\" name)", "output": "(defmacro signal-reader-error (format-control &rest format-arguments)\n \"Like ERROR but signals a SIMPLE-READER-ERROR for the stream\n*STREAM*.\"\n `(error 'simple-reader-error\n :stream *stream*\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote simple-reader-error) :stream *stream* :format-control \"Could not find character with name '~A'\" :format-arguments (list name))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-class some-class (some super classes) ((slot1 :unbound)) (1 2) (:accessor-name-transformer (make-name-transformer name \"-ZORK\")) (3 4))\n\nWrite a macro that addresses: Macro call that should be transformed by define-class", "input": "(define-class some-class (some super classes) ((slot1 :unbound)) (1 2) (:accessor-name-transformer (make-name-transformer name \"-ZORK\")) (3 4))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass some-class (some super classes) ((slot1 :accessor slot1-zork :initarg :slot1)) (1 2) (3 4)) (unless (fboundp (quote some-class-p)) (define-generic some-class-p (object) #A((75) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `some-class'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote some-class)))) (setf (documentation (quote slot1-zork) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\")) (ignore-errors (setf (documentation (fdefinition (quote slot1-zork)) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf slot1-zork))) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\"))) (find-class (quote some-class) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclass/std unknown () ((slot :wi :unknown keywords :and values)))\n\nIssue: Macro call that should be transformed by defclass/std", "input": "(defclass/std unknown () ((slot :wi :unknown keywords :and values)))", "output": "(defmacro defclass/std (name direct-superclasses direct-slots &rest options\n &environment env)\n \"Shortcut macro to the DEFCLASS macro.\n\n (defclass/std example ()\n ((slot1 slot2 slot3)))\n\n expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\n Each slot definition accepts options:\n\n :std 1 => changes the :initform to 1. It can be :unbound.\n :with or :with-prefix => creates accessors with the class name as prefix.\n\n See the README for more.\n\n See also `class/std' and `print-object/std'.\n \"\n `(defclass ,name ,direct-superclasses\n ,(process-slots env direct-slots name)\n ,@options))", "macroexpand": "(defclass unknown nil ((slot :writer slot :initarg :slot :initform nil :unknown keywords :and values)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(def-dynenv-fun nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DEF-DYNENV-FUN", "input": "(def-dynenv-fun nil\n (progn))", "output": "(defmacro DEF-DYNENV-FUN ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun nil (&rest #:args) (apply (dynenv-function nil) #:args))\n (defvar #:nil144 (lambda (progn)))\n (setf (get 'nil 'dynenv-fun) '#:nil144))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(mapping nil (progn))\n\nProblem: Macro call that should be transformed by MAPPING", "input": "(mapping nil (progn))", "output": "(defmacro MAPPING ...)", "macroexpand": "(mapping-mac nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsyntax nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFSYNTAX", "input": "(defsyntax nil\n nil)", "output": "(defmacro defsyntax (name &body options)\n `(progn\n (setf (get ',name :options) ',options)\n (defvar ,name (defreadtable ,name ,@options))))", "macroexpand": "(progn\n (setf (get 'nil :options) '(nil))\n (defvar nil\n (defreadtable nil\n nil)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(builder (:auth-basic :authenticator (lambda (user pass) (declare (ignore user pass)) t)) *app*)\n\nProblem: Macro call that should be transformed by builder", "input": "(builder (:auth-basic :authenticator (lambda (user pass) (declare (ignore user pass)) t)) *app*)", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app174) (funcall (find-middleware :auth-basic) #:app174 :authenticator (lambda (user pass) (declare (ignore user pass)) t))))) :initial-value (to-app *app*) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclass/a dbi-connection () ((auto-commit :type boolean :initarg :auto-commit :initform t) (database-name :initarg :database-name :accessor connection-database-name) (%handle :initarg :handle :accessor connection-handle) (query-cache :initform (make-hash-table :test 'equal) :accessor connection-query-cache) (established-at :initarg :established-at :initform (get-internal-real-time) :accessor connection-established-at)) (:documentation \"Base class for managing DB connection.\"))\n\nIssue: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbi-connection () ((auto-commit :type boolean :initarg :auto-commit :initform t) (database-name :initarg :database-name :accessor connection-database-name) (%handle :initarg :handle :accessor connection-handle) (query-cache :initform (make-hash-table :test 'equal) :accessor connection-query-cache) (established-at :initarg :established-at :initform (get-internal-real-time) :accessor connection-established-at)) (:documentation \"Base class for managing DB connection.\"))", "output": "(defmacro defclass/a (name superclasses slots &rest class-options)\n `(progn\n (defclass ,name ,superclasses ,slots ,@class-options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (defclass dbi-connection nil ((auto-commit :type boolean :initarg :auto-commit :initform t) (database-name :initarg :database-name :accessor connection-database-name) (%handle :initarg :handle :accessor connection-handle) (query-cache :initform (make-hash-table :test (quote equal)) :accessor connection-query-cache) (established-at :initarg :established-at :initform (get-internal-real-time) :accessor connection-established-at)) (:documentation \"Base class for managing DB connection.\")) (deftype nil (quote dbi-connection)) (setf (find-class (quote )) (find-class (quote dbi-connection))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-cached-reader-conditionals\n nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-CACHED-READER-CONDITIONALS", "input": "(with-cached-reader-conditionals\n nil\n (progn))", "output": "(defmacro WITH-CACHED-READER-CONDITIONALS ...)", "macroexpand": "(call-with-cached-reader-conditionals (lambda () nil (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield-binds (format nil \"~A(~{~A~^, ~})\" (sql-op-name op) (mapcar #'yield (function-op-expressions op))))\n\nWhat needs to change: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~A(~{~A~^, ~})\" (sql-op-name op) (mapcar #'yield (function-op-expressions op))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~A(~{~A~^, ~})\" (sql-op-name op) (mapcar (function yield) (function-op-expressions op)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when-let ((x 1) (y nil) (z 3)) :oops)\n\nWhat needs to change: Macro call that should be transformed by when-let", "input": "(when-let ((x 1) (y nil) (z 3)) :oops)", "output": "(defmacro when-let (bindings &body forms)\n \"Creates new variable bindings, and conditionally executes FORMS.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nAll initial-forms are executed sequentially in the specified order. Then all\nthe variables are bound to the corresponding values.\n\nIf all variables were bound to true values, then FORMS are executed as an\nimplicit PROGN.\"\n (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings))\n (variables (mapcar #'car binding-list)))\n `(let ,binding-list\n (when (and ,@variables)\n ,@forms))))", "macroexpand": "(let ((x 1) (y nil) (z 3)) (when (and x y z) :oops))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-quote-char (sxql:yield sql))\n\nWhat needs to change: Macro call that should be transformed by with-quote-char", "input": "(with-quote-char (sxql:yield sql))", "output": "(defmacro with-quote-char (&body body)\n `(let ((sxql:*quote-character* (or sxql:*quote-character*\n (connection-quote-character))))\n ,@body))", "macroexpand": "(let ((*quote-character* (or *quote-character* (connection-quote-character)))) (sxql/sql-type:yield sql))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-fixtures (fixtures test) (call-next-method))\n\nProblem: Macro call that should be transformed by with-fixtures", "input": "(with-fixtures (fixtures test) (call-next-method))", "output": "(defmacro with-fixtures (fixtures &body body)\n `(call-with-fixtures (lambda () ,@body) ,fixtures))", "macroexpand": "(call-with-fixtures (lambda nil (call-next-method)) (fixtures test))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> nil () 0)\n\nProblem: Macro call that should be transformed by ->", "input": "(-> nil () 0)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically nil nil 0)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when-let* ((x 2) (y x)) (+ x y))\n\nWhat needs to change: Macro call that should be transformed by when-let", "input": "(when-let* ((x 2) (y x)) (+ x y))", "output": "(defmacro when-let (bindings &body forms)\n \"Creates new variable bindings, and conditionally executes FORMS.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nAll initial-forms are executed sequentially in the specified order. Then all\nthe variables are bound to the corresponding values.\n\nIf all variables were bound to true values, then FORMS are executed as an\nimplicit PROGN.\"\n (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings))\n (variables (mapcar #'car binding-list)))\n `(let ,binding-list\n (when (and ,@variables)\n ,@forms))))", "macroexpand": "(let ((x 2)) (when x (let ((y x)) (when y (progn (+ x y))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defpsmacro nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFPSMACRO", "input": "(defpsmacro nil\n (progn))", "output": "(defmacro DEFPSMACRO ...)", "macroexpand": "(progn\n nil\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash 'nil *macro-toplevel*)\n (lambda (#:|ps-macro-form-arg-195|)\n (destructuring-bind (progn) (cdr #:|ps-macro-form-arg-195|))))\n (setf (gethash 'nil *macro-toplevel-lambda-list*) '(progn))\n 'nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-error duplicate-name () (name) \"This name appears more than once in this form list ~a\" name)\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error duplicate-name () (name) \"This name appears more than once in this form list ~a\" name)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition duplicate-name (:error-type varjo-error :prefix \"Varjo\") (name) \"This name appears more than once in this form list ~a\" name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defgenerator compress (data selectors) \"Moves through the data and selectors generators in parallel, only yielding elements of data that are paired with a value from selectors that evaluates to true. Eg: (compress (list->generator '(a b c d e f)) (list->generator '(t nil t nil t t))) -> a c e f\" (do-generator (d s (izip data selectors)) (when s (yield d))))\n\nWhat needs to change: Macro call that should be transformed by defgenerator", "input": "(defgenerator compress (data selectors) \"Moves through the data and selectors generators in parallel, only yielding elements of data that are paired with a value from selectors that evaluates to true. Eg: (compress (list->generator '(a b c d e f)) (list->generator '(t nil t nil t t))) -> a c e f\" (do-generator (d s (izip data selectors)) (when s (yield d))))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun compress (data selectors) \"Moves through the data and selectors generators in parallel, only yielding elements of data that are paired with a value from selectors that evaluates to true. Eg: (compress (list->generator '(a b c d e f)) (list->generator '(t nil t nil t t))) -> a c e f\" (with-yield (do-generator (d s (izip data selectors)) (when s (yield d)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defcategory :error (or :error :critical))\n\nProblem: Macro call that should be transformed by defcategory", "input": "(defcategory :error (or :error :critical))", "output": "(defmacro defcategory (category &optional expands-as set)\n `(defcategory-fn ',category ',expands-as ,set))", "macroexpand": "(defcategory-fn (quote :error) (quote (or :error :critical)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7925} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(match list ((list x) (if (evenp x) (fail) x)))\n\nProblem: Macro call that should be transformed by match", "input": "(match list ((list x) (if (evenp x) (fail) x)))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(%or (%if (consp list) (let ((#:g146 (car list)) (#:g147 (cdr list))) (declare (ignorable #:g146 #:g147)) (%if (%equals #:g147 nil) (%or (let ((x #:g146)) (if (evenp x) (fail) x)) (fail)) (fail))) (fail)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(destructuring-bind* nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DESTRUCTURING-BIND*", "input": "(destructuring-bind* nil\n nil)", "output": "(defmacro DESTRUCTURING-BIND* ...)", "macroexpand": "(let (#:in-body126)\n (flet ((#:handle127 (#:condition128)\n (unless #:in-body126\n (error\n (make-condition 'destructuring-error :lambda-list 'nil\n :expression 'nil :reason #:condition128)))))\n (declare (ignorable (function #:handle127)))\n (let ((#:value129 nil))\n (handler-bind ((error #'#:handle127))\n (destructuring-bind () #:value129 (setf #:in-body126 t) (locally))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do-matches-as-strings (match regex target-string (nreverse result-list) :start start :end end :sharedp sharedp) (push match result-list))\n\nWrite a macro that addresses: Macro call that should be transformed by do-matches-as-strings", "input": "(do-matches-as-strings (match regex target-string (nreverse result-list) :start start :end end :sharedp sharedp) (push match result-list))", "output": "(defmacro do-matches-as-strings ((match-var regex\n target-string\n &optional result-form\n &key start end sharedp)\n &body body)\n \"Iterates over TARGET-STRING and tries to match REGEX as often as\npossible evaluating BODY with MATCH-VAR bound to the substring of\nTARGET-STRING corresponding to each match in turn. After the last\nmatch, returns RESULT-FORM if provided or NIL otherwise. An implicit\nblock named NIL surrounds DO-MATCHES-AS-STRINGS; RETURN may be used to\nterminate the loop immediately. If REGEX matches an empty string the\nscan is continued one position behind this match. If SHAREDP is true,\nthe substrings may share structure with TARGET-STRING. BODY may start\nwith declarations.\"\n (with-rebinding (target-string)\n (with-unique-names (match-start match-end substr-fn)\n `(let ((,substr-fn (if ,sharedp #'nsubseq #'subseq)))\n ;; simple use DO-MATCHES to extract the substrings\n (do-matches (,match-start ,match-end ,regex ,target-string\n ,result-form :start ,start :end ,end)\n (let ((,match-var\n (funcall ,substr-fn\n ,target-string ,match-start ,match-end)))\n ,@body))))))", "macroexpand": "(let ((#:target-string145 target-string)) (let ((#:substr-fn148 (if sharedp (function nsubseq) (function subseq)))) (do-matches (#:match-start146 #:match-end147 regex #:target-string145 (nreverse result-list) :start start :end end) (let ((match (funcall #:substr-fn148 #:target-string145 #:match-start146 #:match-end147))) (push match result-list)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(lret ((out (serapeum::make-sequence-like array len))) (replace* out array))\n\nPattern to recognize: Macro call that should be transformed by lret", "input": "(lret ((out (serapeum::make-sequence-like array len))) (replace* out array))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let ((out (serapeum::make-sequence-like array len))) (replace* out array))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-took-usec took-usec (query (funcall (query-prepared query) params) :database (connection-handle conn) :store nil))\n\nProblem: Macro call that should be transformed by with-took-usec", "input": "(with-took-usec took-usec (query (funcall (query-prepared query) params) :database (connection-handle conn) :store nil))", "output": "(defmacro with-took-usec (var &body body)\n (let ((before (gensym \"BEFORE\")))\n `(let ((,before (get-internal-real-time)))\n (multiple-value-prog1 (progn ,@body)\n (setf ,var (ceiling\n (* (- (get-internal-real-time) ,before)\n #.(/ 1000000 internal-time-units-per-second))))))))", "macroexpand": "(multiple-value-bind (#:before-unixtime163 #:before-usec164) (sb-ext:get-time-of-day) (multiple-value-prog1 (progn (query (funcall (query-prepared query) params) :database (connection-handle conn) :store nil)) (multiple-value-bind (#:after-unixtime165 #:after-usec166) (sb-ext:get-time-of-day) (setf took-usec (+ (* (- #:after-unixtime165 #:before-unixtime163) 1000000) (- #:after-usec166 #:before-usec164))))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun-compile-time walk-lambda-list (map-function reduce-function screamer? partial? nested? lambda-list environment) (check-lambda-list lambda-list) (if reduce-function (funcall reduce-function (funcall map-function lambda-list 'lambda-list) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? lambda-list environment)) (funcall map-function lambda-list 'lambda-list)))\n\nIssue: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-lambda-list (map-function reduce-function screamer? partial? nested? lambda-list environment) (check-lambda-list lambda-list) (if reduce-function (funcall reduce-function (funcall map-function lambda-list 'lambda-list) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? lambda-list environment)) (funcall map-function lambda-list 'lambda-list)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-lambda-list (map-function reduce-function screamer? partial? nested? lambda-list environment) (check-lambda-list lambda-list) (if reduce-function (funcall reduce-function (funcall map-function lambda-list (quote lambda-list)) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? lambda-list environment)) (funcall map-function lambda-list (quote lambda-list)))) (eval-when (:compile-toplevel) (compile (quote walk-lambda-list))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lret ((x 1) (y 2)) x)\n\nIssue: Macro call that should be transformed by lret", "input": "(lret ((x 1) (y 2)) x)", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let ((x 1) (y 2)) x)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Generate a defmacro form that transforms code like this:\n(defconstant +spaces+ (make-string 2000 :initial-element #\\Space :element-type 'base-char) \"Used for indentation.\")\n\nPattern to recognize: Macro call that should be transformed by defconstant", "input": "(defconstant +spaces+ (make-string 2000 :initial-element #\\Space :element-type 'base-char) \"Used for indentation.\")", "output": "(defmacro defconstant (name value &optional doc)\n \"Make sure VALUE is evaluated only once \\(to appease SBCL & clasp).\"\n `(cl:defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value)\n ,@(when doc (list doc))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (sb-impl::%defconstant (quote +spaces+) (make-string 2000 :initial-element #\\Space :element-type (quote base-char)) (sb-c:source-location) (quote \"Used for indentation.\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(bind (((:labels doit (x)) \"whatever\" (declare (type fixnum x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))\n\nWrite a macro that addresses: Macro call that should be transformed by bind", "input": "(bind (((:labels doit (x)) \"whatever\" (declare (type fixnum x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(labels ((doit (x) \"whatever\" (declare (type fixnum x)) (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym step :step)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym step :step)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote step) (quote synonym)) (quote :step)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun/1 toupper (c) (char-upcase (code-char c)))\n\nWrite a macro that addresses: Macro call that should be transformed by defun/1", "input": "(defun/1 toupper (c) (char-upcase (code-char c)))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun toupper (c) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (char-upcase (code-char c))) (defparameter toupper (vacietis.c:mkptr& (symbol-function (quote toupper)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lambda+ nil\n (progn))\n\nProblem: Macro call that should be transformed by LAMBDA+", "input": "(lambda+ nil\n (progn))", "output": "(defmacro LAMBDA+ ...)", "macroexpand": "(lambda ()\n (let+ nil\n (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(fgatherlet nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by FGATHERLET", "input": "(fgatherlet nil\n (progn))", "output": "(defmacro FGATHERLET ...)", "macroexpand": "(flet ()\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-custom-var (:beginning-of-object *beginning-of-object-handler*))\n\nWhat needs to change: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:beginning-of-object *beginning-of-object-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*beginning-of-object-handler* . :beginning-of-object)) *custom-vars* :test (function equal)) (defvar *beginning-of-object-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(var nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by VAR", "input": "(var nil :key nil)", "output": "(defmacro VAR ...)", "macroexpand": "(defparameter nil :key)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-error clone-global-env-error () () \"Cannot clone the global environment\")\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error clone-global-env-error () () \"Cannot clone the global environment\")", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition clone-global-env-error (:error-type varjo-error :prefix \"Varjo\") nil \"Cannot clone the global environment\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-quasi-quoted-list-to-list-emitting-form-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-LIST-TO-LIST-EMITTING-FORM-SYNTAX", "input": "(enable-quasi-quoted-list-to-list-emitting-form-syntax)", "output": "(defmacro ENABLE-QUASI-QUOTED-LIST-TO-LIST-EMITTING-FORM-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-list-to-list-emitting-form-syntax-in-readtable\n :start-character #\\GRAVE_ACCENT :end-character nil :unquote-character\n #\\COMMA :splice-character #\\COMMERCIAL_AT :destructive-splice-character\n #\\FULL_STOP :dispatched-quasi-quote-name nil)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-layered-class 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DEFINE-LAYERED-CLASS", "input": "(define-layered-class 'some-name)", "output": "(defmacro DEFINE-LAYERED-CLASS ...)", "macroexpand": "(defclass 'some-name nil nil (:metaclass layered-class) (:in-layer . t))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(enable-quasi-quote-syntax nil (progn))\n\nWhat needs to change: Macro call that should be transformed by ENABLE-QUASI-QUOTE-SYNTAX", "input": "(enable-quasi-quote-syntax nil (progn))", "output": "(defmacro ENABLE-QUASI-QUOTE-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quote-syntax-in-readtable nil (progn) :nested-quasi-quote-wrapper\n quasi-quote-wrapper :start-character nil\n :dispatch-character nil :end-character\n nil :unquote-character #\\COMMA\n :splice-character #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP :dispatched-quasi-quote-name\n nil :toplevel-reader-wrapper #'identity\n :unquote-readtable-case nil :body-reader\n nil :readtable-case nil)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause finding (var condition) \"Same as FOR, but perhaps nicer to read when used in conjunction with macros like MAXIMIZING.\" `(for ,var ,condition))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause finding (var condition) \"Same as FOR, but perhaps nicer to read when used in conjunction with macros like MAXIMIZING.\" `(for ,var ,condition))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro finding (var condition) \"Same as FOR, but perhaps nicer to read when used in conjunction with macros like MAXIMIZING.\" (sb-int:quasiquote (for #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr condition :kind 0)))) (pushnew (quote finding) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ematch0 clause ((list* patterns body) (let ((patterns (ensure-list patterns))) (list* (if (zerop max) nil (append patterns (make-list (- max (length patterns)) :initial-element '_))) body))))\n\nWrite a macro that addresses: Macro call that should be transformed by ematch0", "input": "(ematch0 clause ((list* patterns body) (let ((patterns (ensure-list patterns))) (list* (if (zerop max) nil (append patterns (make-list (- max (length patterns)) :initial-element '_))) body))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 clause ((list* patterns body) (let ((patterns (ensure-list patterns))) (list* (if (zerop max) nil (append patterns (make-list (- max (length patterns)) :initial-element (quote _)))) body))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym minimizing :min)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym minimizing :min)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote minimizing) (quote synonym)) (quote :min)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some-<>\n nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by SOME-<>", "input": "(some-<>\n nil\n :key\n nil)", "output": "(defmacro SOME-<> ...)", "macroexpand": "(let* ((#:var180 nil)\n (#:var181\n (if #:var180\n (:key #:var180)\n nil))\n (#:var182\n (if #:var181\n (nil #:var181)\n nil)))\n #:var182)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(setdocs (type environment \"Container class for a current \\\"environment\\\". An instance of this class is intended to represent most of the runtime environment present at a particular point. It is useful for stashing away debug information for inspection at a later date. See CAPTURE-ENVIRONMENT See ENVIRONMENT-CONDITION See ENVIRONMENT-STACK See ENVIRONMENT-RESTARTS See ENVIRONMENT-THREAD\") (function environment-condition \"Returns the condition stored in the environment (if any). See CL:CONDITION See ENVIRONMENT\") (function environment-stack \"Returns a list of calls stored in the environment (if any). See CALL See ENVIRONMENT\") (function environment-restarts \"Returns a list of restarts stored in the environment (if any). See CL:RESTART See ENVIRONMENT\") (function environment-thread \"Returns the thread stored in the environment (if any). See SB-THREAD:THREAD See THREADS:THREAD See MP:PROCESS See MT:THREAD See CCL:PROCESS See PROCESS:PROCESS See THREAD:THREAD See ENVIRONMENT\") (function capture-environment \"Capture the current environment into an environment object. See ENVIRONMENT\"))\n\nWhat needs to change: Macro call that should be transformed by setdocs", "input": "(setdocs (type environment \"Container class for a current \\\"environment\\\". An instance of this class is intended to represent most of the runtime environment present at a particular point. It is useful for stashing away debug information for inspection at a later date. See CAPTURE-ENVIRONMENT See ENVIRONMENT-CONDITION See ENVIRONMENT-STACK See ENVIRONMENT-RESTARTS See ENVIRONMENT-THREAD\") (function environment-condition \"Returns the condition stored in the environment (if any). See CL:CONDITION See ENVIRONMENT\") (function environment-stack \"Returns a list of calls stored in the environment (if any). See CALL See ENVIRONMENT\") (function environment-restarts \"Returns a list of restarts stored in the environment (if any). See CL:RESTART See ENVIRONMENT\") (function environment-thread \"Returns the thread stored in the environment (if any). See SB-THREAD:THREAD See THREADS:THREAD See MP:PROCESS See MT:THREAD See CCL:PROCESS See PROCESS:PROCESS See THREAD:THREAD See ENVIRONMENT\") (function capture-environment \"Capture the current environment into an environment object. See ENVIRONMENT\"))", "output": "(defmacro setdocs (&body pairs)\n `(progn\n ,@(loop for (type var doc) in pairs\n collect `(setf (documentation ',var ',type) ,doc))))", "macroexpand": "(progn (setf (documentation (quote environment) (quote type)) \"Container class for a current \\\"environment\\\". An instance of this class is intended to represent most of the runtime environment present at a particular point. It is useful for stashing away debug information for inspection at a later date. See CAPTURE-ENVIRONMENT See ENVIRONMENT-CONDITION See ENVIRONMENT-STACK See ENVIRONMENT-RESTARTS See ENVIRONMENT-THREAD\") (setf (documentation (quote environment-condition) (quote function)) \"Returns the condition stored in the environment (if any). See CL:CONDITION See ENVIRONMENT\") (setf (documentation (quote environment-stack) (quote function)) \"Returns a list of calls stored in the environment (if any). See CALL See ENVIRONMENT\") (setf (documentation (quote environment-restarts) (quote function)) \"Returns a list of restarts stored in the environment (if any). See CL:RESTART See ENVIRONMENT\") (setf (documentation (quote environment-thread) (quote function)) \"Returns the thread stored in the environment (if any). See SB-THREAD:THREAD See THREADS:THREAD See MP:PROCESS See MT:THREAD See CCL:PROCESS See PROCESS:PROCESS See THREAD:THREAD See ENVIRONMENT\") (setf (documentation (quote capture-environment) (quote function)) \"Capture the current environment into an environment object. See ENVIRONMENT\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(select-dao class (where-and fields-and-values class))\n\nProblem: Macro call that should be transformed by select-dao", "input": "(select-dao class (where-and fields-and-values class))", "output": "(defmacro select-dao (class &body clauses)\n \"Build custom queries with SxQL.\n\nExample:\n\n (select-dao 'tweet\n (where (:like :status \\\"%Japan%\\\")))\n\nYou can use \\\"includes\\\" to eagerly load another table and prevent the \\\"N+1 query\\\" performance problem:\n\n (select-dao 'tweet\n (includes 'user)\n (where (:like :status \\\"%Japan%\\\")))\n\nYou can use \\\"joins\\\" to add JOIN clauses for filtering by related table columns.\nNote: \\\"joins\\\" does NOT automatically load foreign objects. Use \\\"includes\\\" if you need the ghost slots populated:\n\n ;; Filter by related table - ghost slot NOT populated\n (select-dao 'blog\n (joins 'user)\n (where (:= :user.status \\\"active\\\")))\n\n ;; Filter AND load foreign objects\n (select-dao 'blog\n (joins 'user)\n (includes 'user)\n (where (:= :user.status \\\"active\\\")))\n\nSee the SxQL documentation for the available clauses and operators.\"\n (with-gensyms (sql clause results include-classes foreign-class)\n (once-only (class)\n `(#+sb-package-locks locally #+sb-package-locks (declare (sb-ext:disable-package-locks sxql:where))\n #-sb-package-locks cl-package-locks:with-packages-unlocked #-sb-package-locks (sxql)\n (progn\n (setf ,class (ensure-class ,class))\n (let* ((sxql:*sql-symbol-conversion* #'unlispify)\n (,sql\n (sxql:select :*\n (sxql:from (sxql:make-sql-symbol (table-name ,class)))))\n (,include-classes '()))\n (macrolet ((where (expression)\n `(sxql:make-clause :where ,(expand-op expression ',class))))\n ;; ignore compiler-note when includes is not used\n #+sbcl (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note))\n (flet ((includes (&rest classes)\n (appendf ,include-classes (mapcar #'ensure-class classes))\n nil)\n (joins (foreign-class &key (type :inner))\n (let ((foreign-class (ensure-class foreign-class)))\n (add-child ,sql\n (ecase type\n (:inner (sxql:inner-join\n (sxql:make-sql-symbol (table-name foreign-class))\n :on (make-join-condition ,class foreign-class)))\n (:left (sxql:left-join\n (sxql:make-sql-symbol (table-name foreign-class))\n :on (make-join-condition ,class foreign-class)))))\n nil)))\n (dolist (,clause (list ,@clauses))\n (when ,clause\n (add-child ,sql ,clause)))\n (let ((,results (select-by-sql ,class ,sql)))\n (unless *want-cursor*\n (dolist (,foreign-class (remove-duplicates ,include-classes))\n (include-foreign-objects ,foreign-class ,results)))\n (values ,results ,sql))))))))))", "macroexpand": "(let ((#:class259 class)) (locally (declare (sb-ext:disable-package-locks where)) (progn (setf #:class259 (ensure-class #:class259)) (let* ((*sql-symbol-conversion* (function unlispify)) (#:sql254 (select :* (from (make-sql-symbol (table-name #:class259))))) (#:include-classes257 (quote nil))) (macrolet ((where (expression) (sb-int:quasiquote (make-clause :where #S(sb-impl::comma :expr (expand-op expression (quote #:class259)) :kind 0))))) (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note)) (flet ((includes (&rest classes) (appendf #:include-classes257 (mapcar (function ensure-class) classes)) nil) (joins (foreign-class &key (type :inner)) (let ((foreign-class (ensure-class foreign-class))) (add-child #:sql254 (ecase type (:inner (inner-join (make-sql-symbol (table-name foreign-class)) :on (make-join-condition #:class259 foreign-class))) (:left (left-join (make-sql-symbol (table-name foreign-class)) :on (make-join-condition #:class259 foreign-class))))) nil))) (dolist (#:clause255 (list (where-and fields-and-values class))) (when #:clause255 (add-child #:sql254 #:clause255))) (let ((#:results256 (select-by-sql #:class259 #:sql254))) (unless *want-cursor* (dolist (#:foreign-class258 (remove-duplicates #:include-classes257)) (include-foreign-objects #:foreign-class258 #:results256))) (values #:results256 #:sql254))))))))", "category": "capture-management", "technique": "macrolet,once-only,gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.9624999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-destructured-lambda-form nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-DESTRUCTURED-LAMBDA-FORM", "input": "(with-destructured-lambda-form nil\n :key\n nil)", "output": "(defmacro WITH-DESTRUCTURED-LAMBDA-FORM ...)", "macroexpand": "(destructuring-bind\n (#:function135 #:name136 #:qualifiers137 #:lambda-list138 #:docstring139\n #:declarations140 #:forms141)\n (split-lambda-form :key)\n (declare\n (ignore #:function135 #:name136 #:qualifiers137 #:lambda-list138\n #:docstring139 #:declarations140 #:forms141))\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda-ignoring-_ (_ exp) `(,op ,exp))\n\nWrite a macro that addresses: Macro call that should be transformed by lambda-ignoring-_", "input": "(lambda-ignoring-_ (_ exp) `(,op ,exp))", "output": "(defmacro lambda-ignoring-_ (lambda-list &body body)\n \"Works like `cl:lambda' macro except automatically `declare's\n `ignore' for parameters beginning with '_' character.\"\n (let ((ignored-parameters\n (collect-_-symbol-in-lambda-list lambda-list)))\n (unless ignored-parameters\n (warn \"No ignored parameters in: ~A\" lambda-list))\n (multiple-value-bind (body decls doc)\n (parse-body body :documentation t)\n `(lambda ,lambda-list\n ,@ (if doc `(,doc))\n (declare (ignore ,@ignored-parameters))\n ,@decls\n ,@body))))", "macroexpand": "(lambda (_ exp) (declare (ignore _)) (sb-int:quasiquote (#S(sb-impl::comma :expr op :kind 0) #S(sb-impl::comma :expr exp :kind 0))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-neo4j-fun create-node (properties) :post (:uri-spec (format nil \"node\")) (:encode properties :string) (:status-handlers (201 (decode-neo4j-json-output body)) (400 (error 'invalid-data-sent-error :uri uri :json json))))\n\nPattern to recognize: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun create-node (properties) :post (:uri-spec (format nil \"node\")) (:encode properties :string) (:status-handlers (201 (decode-neo4j-json-output body)) (400 (error 'invalid-data-sent-error :uri uri :json json))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun create-node (&key properties) (let ((uri (format nil \"node\")) (json (encode-neo4j-json-payload properties :string))) (make-neo4j-request :post uri json (list (list 201 (lambda (body uri json) (decode-neo4j-json-output body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(match0 (find v1 seq2 :key #'car) ((list* _ o2) (cons (list v1 :type `(or ,(getf o1 :type) ,(getf o2 :type)) :place (or (getf o1 :place) (getf o2 :place)) :ignorable (or (getf o1 :ignorable) (getf o2 :ignorable))) (merge-variables rest seq2))))\n\nPattern to recognize: Macro call that should be transformed by match0", "input": "(match0 (find v1 seq2 :key #'car) ((list* _ o2) (cons (list v1 :type `(or ,(getf o1 :type) ,(getf o2 :type)) :place (or (getf o1 :place) (getf o2 :place)) :ignorable (or (getf o1 :ignorable) (getf o2 :ignorable))) (merge-variables rest seq2))))", "output": "(defmacro match0 (*what* &body clauses &environment *env*)\n (once-only (*what*)\n (parse-patterns clauses)))", "macroexpand": "(let ((#:*what*146 (find v1 seq2 :key (function car)))) (declare (ignorable #:*what*146)) (if (and (consp #:*what*146) (let ((#:*what*147 (car #:*what*146))) (declare (ignorable #:*what*147)) t) (let ((#:*what*148 (cdr #:*what*146))) (declare (ignorable #:*what*148)) t)) (let* ((#:*what*147 (car #:*what*146)) (#:*what*148 (cdr #:*what*146)) (o2 #:*what*148)) (declare (ignorable o2 #:*what*148 #:*what*147)) (cons (list v1 :type (sb-int:quasiquote (or #S(sb-impl::comma :expr (getf o1 :type) :kind 0) #S(sb-impl::comma :expr (getf o2 :type) :kind 0))) :place (or (getf o1 :place) (getf o2 :place)) :ignorable (or (getf o1 :ignorable) (getf o2 :ignorable))) (merge-variables rest seq2))) nil))", "category": "control-flow", "technique": "once-only", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lret ((start 0) (result (make-array len :element-type 'character))) (declare (array-index start) ((simple-array character (*)) result)) (do-strings (s more?) (nlet rec (s) (etypecase s (string (with-string-dispatch () s (replace result s :start1 start) (incf start (length s)))) (character (setf (schar result start) s) (incf start)) (symbol (rec (symbol-name s))))) (boolean-when separator? (when more? (replace result separator :start1 start) (incf start sep-len)))) (boolean-when separator? (when end (replace result separator :start1 start))))\n\nWhat needs to change: Macro call that should be transformed by lret", "input": "(lret ((start 0) (result (make-array len :element-type 'character))) (declare (array-index start) ((simple-array character (*)) result)) (do-strings (s more?) (nlet rec (s) (etypecase s (string (with-string-dispatch () s (replace result s :start1 start) (incf start (length s)))) (character (setf (schar result start) s) (incf start)) (symbol (rec (symbol-name s))))) (boolean-when separator? (when more? (replace result separator :start1 start) (incf start sep-len)))) (boolean-when separator? (when end (replace result separator :start1 start))))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let ((start 0) (result (make-array len :element-type (quote character)))) (declare (array-index start) ((simple-array character (*)) result)) (do-strings (s more?) (nlet rec (s) (etypecase s (string (with-string-dispatch nil s (replace result s :start1 start) (incf start (length s)))) (character (setf (schar result start) s) (incf start)) (symbol (rec (symbol-name s))))) (boolean-when separator? (when more? (replace result separator :start1 start) (incf start sep-len)))) (boolean-when separator? (when end (replace result separator :start1 start))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do-generators ((a (repeat 2)) (:list b '(4 5 6)) (c (list->generator '(8 9)) :fill-value 30)) (print (* a (+ b c))))\n\nWrite a macro that addresses: Macro call that should be transformed by do-generator", "input": "(do-generators ((a (repeat 2)) (:list b '(4 5 6)) (c (list->generator '(8 9)) :fill-value 30)) (print (* a (+ b c))))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g153 (multi-gen (repeat 2) (list->generator (quote (4 5 6))) (list (list->generator (quote (8 9))) :fill-value 30)))) (loop do (destructuring-bind (#:g155 . #:g154) (multiple-value-list (next-generator-value #:g153)) (unless #:g155 (return)) (let ((a (elt (elt #:g154 0) 0)) (b (elt (elt #:g154 1) 0)) (c (elt (elt #:g154 2) 0))) (print (* a (+ b c)))))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(yield-all (flatten (cdr list)))\n\nProblem: Macro call that should be transformed by yield-all", "input": "(yield-all (flatten (cdr list)))", "output": "(defmacro yield-all (generator)\n \"Walks through generator, re-yielding all of the items in it. Only meant for use inside of a defgenerator or with-yield block.\"\n (let ((x (gensym)))\n `(do-generator (,x ,generator)\n (yield ,x))))", "macroexpand": "(do-generator (#:g185 (flatten (cdr list))) (yield #:g185))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.8125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-component-testers (a b #'pathname-name) (components-are-member '(nil :wild :unspecific)) (components-are-string=))\n\nWhat needs to change: Macro call that should be transformed by with-component-testers", "input": "(with-component-testers (a b #'pathname-name) (components-are-member '(nil :wild :unspecific)) (components-are-string=))", "output": "(defmacro with-component-testers ((a b key) &body body)\n (let ((k (gensym)))\n `(let* ((,k ,key)\n (,a (funcall ,k ,a))\n (,b (funcall ,k ,b)))\n (labels ((components-are (test)\n (and (funcall test ,a) (funcall test ,b)))\n (components-are-member (values)\n (and (member ,a values :test #'eql)\n (member ,b values :test #'eql)\n (eql ,a ,b)))\n (components-are-string= ()\n (and (stringp ,a) (stringp ,b) (string= ,a ,b)))\n (components-are-every (test)\n (and (consp ,a)\n (consp ,b)\n (every test ,a ,b))))\n (declare (ignorable #'components-are #'components-are-member\n #'components-are-string= #'components-are-every))\n (if (or ,@body)\n (values t ,a ,b)\n nil)))))", "macroexpand": "(let* ((#:g146 (function pathname-name)) (a (funcall #:g146 a)) (b (funcall #:g146 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (components-are-member (quote (nil :wild :unspecific))) (components-are-string=)) (values t a b) nil)))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(and nil)\n\nPattern to recognize: Macro call that should be transformed by AND", "input": "(and nil)", "output": "(defmacro AND ...)", "macroexpand": "(the t nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-xml-group-element (s (element-name e) (element-attributes e)) (loop for sub-element across (element-contents e) do (stream-out s sub-element)))\n\nProblem: Macro call that should be transformed by with-xml-group-element", "input": "(with-xml-group-element (s (element-name e) (element-attributes e)) (loop for sub-element across (element-contents e) do (stream-out s sub-element)))", "output": "(defmacro with-xml-group-element ((stream element properties) &body body)\n (let ((s (gensym \"stream\"))\n (e (gensym \"element\")))\n `(let ((,s ,stream)\n (,e ,element))\n (begin-group->xml ,s ,e ,properties)\n (with-indentation \n ,@body)\n (end-group->xml ,s ,e))))", "macroexpand": "(let ((#:|stream132| s) (#:|element133| (element-name e))) (begin-group->xml #:|stream132| #:|element133| (element-attributes e)) (with-indentation (loop for sub-element across (element-contents e) do (stream-out s sub-element))) (end-group->xml #:|stream132| #:|element133|))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(when val (cond ((stringp val) (format stream \"\\\"~a\\\"\" val)) ((characterp val) (cond ((eql val #\\tab) (format stream \"'\\\\t'\")) ((or (eql val #\\nul) (eql val #\\null)) (format stream \"'\\\\0'\")) ((eql val #\\return) (format stream \"'\\\\r'\")) ((eql val #\\newline) (format stream \"'\\\\n'\")) ((eql val #\\') (format stream \"'\\\\''\")) (t (format stream \"'~a'\" val)))) ((floatp val) (format stream \"~a\" (substitute #\\e #\\d (format nil \"~,8e\" val)))) (t (format stream \"~a\" val))) )\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when val (cond ((stringp val) (format stream \"\\\"~a\\\"\" val)) ((characterp val) (cond ((eql val #\\tab) (format stream \"'\\\\t'\")) ((or (eql val #\\nul) (eql val #\\null)) (format stream \"'\\\\0'\")) ((eql val #\\return) (format stream \"'\\\\r'\")) ((eql val #\\newline) (format stream \"'\\\\n'\")) ((eql val #\\') (format stream \"'\\\\''\")) (t (format stream \"'~a'\" val)))) ((floatp val) (format stream \"~a\" (substitute #\\e #\\d (format nil \"~,8e\" val)))) (t (format stream \"~a\" val))) )", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if val (cond ((stringp val) (format stream \"\\\"~a\\\"\" val)) ((characterp val) (cond ((eql val #\\Tab) (format stream \"'\\\\t'\")) ((or (eql val #\\Nul) (eql val #\\Nul)) (format stream \"'\\\\0'\")) ((eql val #\\Return) (format stream \"'\\\\r'\")) ((eql val #\\Newline) (format stream \"'\\\\n'\")) ((eql val #\\APOSTROPHE) (format stream \"'\\\\''\")) (t (format stream \"'~a'\" val)))) ((floatp val) (format stream \"~a\" (substitute #\\LATIN_SMALL_LETTER_E #\\LATIN_SMALL_LETTER_D (format nil \"~,8e\" val)))) (t (format stream \"~a\" val))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(drelet* nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DRELET*", "input": "(drelet* nil\n :key\n nil)", "output": "(defmacro DRELET* ...)", "macroexpand": "(dynamic-relet* nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defhandler go (go tag) `(list ',go ',tag))\n\nProblem: Macro call that should be transformed by defhandler", "input": "(defhandler go (go tag) `(list ',go ',tag))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-go (go tag) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr go :kind 0)) (quote #S(sb-impl::comma :expr tag :kind 0))))) (setf (gethash (quote go) *form-handler*) (quote hander-go)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun-compile-time indirect-callers (function-name) (indirect-callers-internal (callers function-name) '()))\n\nPattern to recognize: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time indirect-callers (function-name) (indirect-callers-internal (callers function-name) '()))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun indirect-callers (function-name) (indirect-callers-internal (callers function-name) (quote nil))) (eval-when (:compile-toplevel) (compile (quote indirect-callers))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is 1 1)\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is 1 1)", "output": "(defmacro is (got expected &rest args)\n (with-gensyms (duration result new-args desc)\n (once-only (expected)\n `(let* ((,new-args (list ,@args))\n (,desc (parse-description-and-test ,new-args)))\n (with-catching-errors (:description ,desc :expected ,expected)\n (with-duration ((,duration ,result) ,got)\n (test ,result ,expected ,new-args\n :duration ,duration)))))))", "macroexpand": "(let ((#:expected156 1)) (let* ((#:new-args154 (list)) (#:desc155 (parse-description-and-test #:new-args154))) (with-catching-errors (:description #:desc155 :expected #:expected156) (with-duration ((#:duration152 #:result153) 1) (test #:result153 #:expected156 #:new-args154 :duration #:duration152)))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do-instance-combinations 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by DO-INSTANCE-COMBINATIONS", "input": "(do-instance-combinations 'some-name)", "output": "(defmacro DO-INSTANCE-COMBINATIONS ...)", "macroexpand": "(do-combinations 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-mocks () (if-called 'foo (constantly 42)) (is (eql 42 (foo))))\n\nWhat needs to change: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (if-called 'foo (constantly 42)) (is (eql 42 (foo))))", "output": "(defmacro with-mocks ((&key (recordp T)) &body body)\n \"Execute BODY in a new mocking context. Invocations will be recorded\nif RECORDP is set (default true).\"\n `(call-with-mocks\n (lambda () ,@body)\n :recordp ,recordp))", "macroexpand": "(call-with-mocks (lambda nil (if-called (quote foo) (constantly 42)) (is (eql 42 (foo)))) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-c-compilation-unit (:return-last-statement (eql (first body) '{)) (parse-with-lexer (list-lexer body) *c-parser*))\n\nProblem: Macro call that should be transformed by with-c-compilation-unit", "input": "(with-c-compilation-unit (:return-last-statement (eql (first body) '{)) (parse-with-lexer (list-lexer body) *c-parser*))", "output": "(defmacro with-c-compilation-unit ((&key return-last-statement)\n\t\t\t\t &body body)\n \"Establishes variable bindings for a new compilation.\"\n `(let ((*struct-specs* (copy-hash-table *struct-specs*))\n (*typedef-names* (copy-hash-table *typedef-names*))\n\t (*return-last-statement* ,return-last-statement)\n (*function-pointer-ids* nil))\n ,@body))", "macroexpand": "(let ((*struct-specs* (copy-hash-table *struct-specs*)) (*typedef-names* (copy-hash-table *typedef-names*)) (*return-last-statement* (eql (first body) (quote {))) (*function-pointer-ids* nil)) (parse-with-lexer (list-lexer body) *c-parser*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(multiple-value-match (values 1 2) ((2) 1) ((1 y) y))\n\nPattern to recognize: Macro call that should be transformed by multiple-value-match", "input": "(multiple-value-match (values 1 2) ((2) 1) ((1 y) y))", "output": "(defmacro multiple-value-match (values-form &body clauses)\n \"Matches the multiple values of VALUES-FORM with CLAUSES. Unlike\nMATCH, CLAUSES have to have the form of (PATTERNS . BODY), where\nPATTERNS is a list of patterns. The number of values that will be used\nto match is determined by the maximum arity of PATTERNS among CLAUSES.\n\nExamples:\n\n (multiple-value-match (values 1 2)\n ((2) 1)\n ((1 y) y))\n => 2\"\n (compile-multiple-value-match values-form clauses nil))", "macroexpand": "(multiple-value-bind (#:var156 #:var157) (values 1 2) (declare (ignorable #:var156 #:var157)) (%or (%if (%equals #:var156 2) (%or 1 (fail)) (fail)) (%or (%if (%equals #:var156 1) (%or (let ((y #:var157)) y) (fail)) (fail)) nil)))", "category": "dsl", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(action (:after node-direct-application) #'direct-application-better-infer-types)\n\nPattern to recognize: Macro call that should be transformed by action", "input": "(action (:after node-direct-application) #'direct-application-better-infer-types)", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-direct-application) (function direct-application-better-infer-types))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> +colon+ #'2-digits)\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> +colon+ #'2-digits)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset125) (multiple-value-bind (#:*>-res126 #:*>-next127) (funcall +colon+ #:*>-offset125) (if (ok? #:*>-res126) (funcall (function 2-digits) #:*>-next127) (fail #:*>-next127))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-store-entry (key store :quiet quiet) (setf (item key store) nil))\n\nWhat needs to change: Macro call that should be transformed by with-store-entry", "input": "(with-store-entry (key store :quiet quiet) (setf (item key store) nil))", "output": "(defmacro with-store-entry ((key store &key quiet) &body body)\n `(prog1\n (progn\n\t ,@body)\n (unless ,quiet\n (kick-c-link ,key ,store))))", "macroexpand": "(prog1 (progn (setf (item key store) nil)) (unless quiet (kick-c-link key store)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-table-name nil (yield (when-op-right op)))\n\nProblem: Macro call that should be transformed by with-table-name", "input": "(with-table-name nil (yield (when-op-right op)))", "output": "(defmacro with-table-name (table-name &body body)\n `(let ((*table-name-scope* ,table-name))\n ,@body))", "macroexpand": "(let ((*table-name-scope* nil)) (yield (when-op-right op)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-package (package) (loop for (option . args) in definition-options do (ecase option (:nicknames (loop for nick in args do (add-package-nickname package nick))) (:documentation (setf (documentation package T) (format NIL \"~a -- ~a\" (documentation package T) (car args)))) (:use (use-package args package)) (:shadow (shadow args package)) (:shadowing-import-from (shadowing-import (collect-symbols-from (car args) (cdr args)) package)) (:import-from (import (collect-symbols-from (car args) (cdr args)) package)) (:export (export args package)) (:intern (loop for symbol in args do (intern (symbol-name symbol) package))) (:local-nicknames (loop for (nickname name) in args do (trivial-package-local-nicknames:add-package-local-nickname nickname name package))) (:size (error \"SIZE option not applicable to EXTEND-PACKAGE.\")))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-package", "input": "(with-package (package) (loop for (option . args) in definition-options do (ecase option (:nicknames (loop for nick in args do (add-package-nickname package nick))) (:documentation (setf (documentation package T) (format NIL \"~a -- ~a\" (documentation package T) (car args)))) (:use (use-package args package)) (:shadow (shadow args package)) (:shadowing-import-from (shadowing-import (collect-symbols-from (car args) (cdr args)) package)) (:import-from (import (collect-symbols-from (car args) (cdr args)) package)) (:export (export args package)) (:intern (loop for symbol in args do (intern (symbol-name symbol) package))) (:local-nicknames (loop for (nickname name) in args do (trivial-package-local-nicknames:add-package-local-nickname nickname name package))) (:size (error \"SIZE option not applicable to EXTEND-PACKAGE.\")))))", "output": "(defmacro with-package ((var &optional (package var)) &body body)\n `(let ((,var (ensure-package ,package)))\n ,@body))", "macroexpand": "(let ((package (ensure-package package))) (loop for (option . args) in definition-options do (ecase option (:nicknames (loop for nick in args do (add-package-nickname package nick))) (:documentation (setf (documentation package t) (format nil \"~a -- ~a\" (documentation package t) (car args)))) (:use (use-package args package)) (:shadow (shadow args package)) (:shadowing-import-from (shadowing-import (collect-symbols-from (car args) (cdr args)) package)) (:import-from (import (collect-symbols-from (car args) (cdr args)) package)) (:export (export args package)) (:intern (loop for symbol in args do (intern (symbol-name symbol) package))) (:local-nicknames (loop for (nickname name) in args do (sb-ext:add-package-local-nickname nickname name package))) (:size (error \"SIZE option not applicable to EXTEND-PACKAGE.\")))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(match 1 (x (if (eql x 1) (fail) x)) (_ 'ok))\n\nWrite a macro that addresses: Macro call that should be transformed by match", "input": "(match 1 (x (if (eql x 1) (fail) x)) (_ 'ok))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(let ((#:var139 1)) (declare (ignorable #:var139)) (%or (%or (let ((x #:var139)) (if (eql x 1) (fail) x)) (quote ok) (fail)) nil))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defsynonym :maximize :max)\n\nIssue: Macro call that should be transformed by defsynonym", "input": "(defsynonym :maximize :max)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :maximize) (quote synonym)) (quote :max)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> nil nil)", "output": "(defmacro -> ...)", "macroexpand": "(nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-color (:red :stream stream) (format/indent reporter stream \"\u00d7 ~D of ~D test~:*~P failed\" failed-count count))\n\nPattern to recognize: Macro call that should be transformed by with-color", "input": "(with-color (:red :stream stream) (format/indent reporter stream \"\u00d7 ~D of ~D test~:*~P failed\" failed-count count))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq :red :gray) (eq :red :grey) (eq :red +gray+) (eq :red +grey+)) (with-gray stream (format/indent reporter stream \"\u00d7 ~D of ~D test~:*~P failed\" failed-count count)) (cl-ansi-text:with-color (:red :stream stream) (format/indent reporter stream \"\u00d7 ~D of ~D test~:*~P failed\" failed-count count))) (progn (format/indent reporter stream \"\u00d7 ~D of ~D test~:*~P failed\" failed-count count)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect-max nil nil)\n\nWhat needs to change: Macro call that should be transformed by COLLECT-MAX", "input": "(collect-max nil nil)", "output": "(defmacro COLLECT-MAX ...)", "macroexpand": "(common-lisp:let* ((#:generator-353 (generator nil))\n #:items-343\n (#:generator-351 (generator nil))\n #:numbers-342\n (#:number-345 nil)\n #:result-346)\n (declare (type generator #:generator-353)\n (type generator #:generator-351)\n (type (null-or t) #:result-346))\n (tagbody\n #:ll-354\n (setq #:items-343 (next-in #:generator-353 (go end)))\n (setq #:numbers-342 (next-in #:generator-351 (go end)))\n (if (or (null #:number-345) (< #:number-345 #:numbers-342))\n (setq #:number-345 #:numbers-342\n #:result-346 #:items-343))\n (go #:ll-354)\n end)\n (if (null #:number-345)\n (setq #:result-346 nil))\n #:result-346)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun-speedy make-random-string (&optional (length 12)) (declare (type fixnum length)) (let ((result (make-string length))) (declare (type simple-string result)) (dotimes (i length result) (setf (aref result i) (ecase (random 5) ((0 1) (code-char (+ #.(char-code #\\a) (random 26)))) ((2 3) (code-char (+ #.(char-code #\\A) (random 26)))) ((4) (code-char (+ #.(char-code #\\0) (random 10)))))))))\n\nWrite a macro that addresses: Macro call that should be transformed by defun-speedy", "input": "(defun-speedy make-random-string (&optional (length 12)) (declare (type fixnum length)) (let ((result (make-string length))) (declare (type simple-string result)) (dotimes (i length result) (setf (aref result i) (ecase (random 5) ((0 1) (code-char (+ #.(char-code #\\a) (random 26)))) ((2 3) (code-char (+ #.(char-code #\\A) (random 26)))) ((4) (code-char (+ #.(char-code #\\0) (random 10)))))))))", "output": "(defmacro defun-speedy (name lambda-list &body body)\n `(progn\n (declaim (notinline ,name))\n (defun ,name ,lambda-list\n ,*speedy-declaration*\n ,@body)))", "macroexpand": "(progn (declaim (notinline make-random-string)) (defun make-random-string (&optional (length 12)) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (declare (type fixnum length)) (let ((result (make-string length))) (declare (type simple-string result)) (dotimes (i length result) (setf (aref result i) (ecase (random 5) ((0 1) (code-char (+ 97 (random 26)))) ((2 3) (code-char (+ 65 (random 26)))) ((4) (code-char (+ 48 (random 10))))))))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(subtest \"Subtest\" (diag \"in subtest\") (is #\\a #\\a) (like \"truth\" \"^true\"))\n\nIssue: Macro call that should be transformed by subtest", "input": "(subtest \"Subtest\" (diag \"in subtest\") (is #\\a #\\a) (like \"truth\" \"^true\"))", "output": "(defmacro subtest (desc &body body)\n `(%subtest ,desc (lambda () ,@body)))", "macroexpand": "(%subtest \"Subtest\" (lambda nil (diag \"in subtest\") (is #\\LATIN_SMALL_LETTER_A #\\LATIN_SMALL_LETTER_A) (like \"truth\" \"^true\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-symbol-access\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-SYMBOL-ACCESS", "input": "(with-symbol-access\n 'some-name)", "output": "(defmacro WITH-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* t))\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-relet* nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-RELET*", "input": "(dynamic-relet* nil\n nil)", "output": "(defmacro DYNAMIC-RELET* ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclass/a dbd-null-query (cl-dbi:dbi-query) ())\n\nProblem: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbd-null-query (cl-dbi:dbi-query) ())", "output": "(defmacro defclass/a (name superclasses slots &rest class-options)\n `(progn\n (defclass ,name ,superclasses ,slots ,@class-options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (defclass dbd-null-query (dbi.driver:dbi-query) nil) (deftype nil (quote dbd-null-query)) (setf (find-class (quote )) (find-class (quote dbd-null-query))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (and (node-slot type) (not (eql info 'cast-expression)) (not (eql info 'funcall)) (not (eql info 'declaration-item))) (format stream \" \"))\n\nProblem: Macro call that should be transformed by when", "input": "(when (and (node-slot type) (not (eql info 'cast-expression)) (not (eql info 'funcall)) (not (eql info 'declaration-item))) (format stream \" \"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (and (node-slot type) (not (eql info (quote cast-expression))) (not (eql info (quote funcall))) (not (eql info (quote declaration-item)))) (format stream \" \"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(iterate nil nil)\n\nProblem: Macro call that should be transformed by ITERATE", "input": "(iterate nil nil)", "output": "(defmacro ITERATE ...)", "macroexpand": "(progn (tagbody #:ll-249 ((lambda () nil)) (go #:ll-249)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(class/std employee name id salary)\n\nPattern to recognize: Macro call that should be transformed by class/std", "input": "(class/std employee name id salary)", "output": "(defmacro class/std (name &body defaulted-slots)\n \"The most concise shortcut macro to DEFCLASS.\n\n (class/std example slot1 slot2 slot3)\n\n expands to:\n\n (DEFCLASS/STD EXAMPLE ()\n ((SLOT1 SLOT2 SLOT3)))\n\n which expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\"\n `(defclass/std ,name ()\n ((,@defaulted-slots))))", "macroexpand": "(defclass/std employee nil ((name id salary)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(action (:after node-lisp node bound-variables) (when (and (member target bound-variables :test #'eq) (loop :for (_ . coalton-var) :in (node-lisp-vars node) :thereis (and (eq name coalton-var) (not (member name bound-variables :test #'eq))))) (setf unsafe? t)) (values))\n\nPattern to recognize: Macro call that should be transformed by action", "input": "(action (:after node-lisp node bound-variables) (when (and (member target bound-variables :test #'eq) (loop :for (_ . coalton-var) :in (node-lisp-vars node) :thereis (and (eq name coalton-var) (not (member name bound-variables :test #'eq))))) (setf unsafe? t)) (values))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-lisp) (lambda (node bound-variables) (declare (type node-lisp node)) (when (and (member target bound-variables :test (function eq)) (loop :for (_ . coalton-var) :in (node-lisp-vars node) :thereis (and (eq name coalton-var) (not (member name bound-variables :test (function eq)))))) (setf unsafe? t)) (values)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error merge-env-parent-mismatch () (env-a env-b) \"Attempting to merge two environments with different parent environments ~s~%~s~%~s\" (cons (v-parent-env env-a) (v-parent-env env-b)) env-a env-b)\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error merge-env-parent-mismatch () (env-a env-b) \"Attempting to merge two environments with different parent environments ~s~%~s~%~s\" (cons (v-parent-env env-a) (v-parent-env env-b)) env-a env-b)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition merge-env-parent-mismatch (:error-type varjo-error :prefix \"Varjo\") (env-a env-b) \"Attempting to merge two environments with different parent environments ~s~%~s~%~s\" (cons (v-parent-env env-a) (v-parent-env env-b)) env-a env-b)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(->*\n 'some-name)\n\nIssue: Macro call that should be transformed by ->*", "input": "(->*\n 'some-name)", "output": "(defmacro ->* ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(bind (((:plist a (b _) (c _ 2) (dd d)) '(:b \"B\" :a \"A\" :d \"D\"))) (list a b c dd))\n\nProblem: Macro call that should be transformed by bind", "input": "(bind (((:plist a (b _) (c _ 2) (dd d)) '(:b \"B\" :a \"A\" :d \"D\"))) (list a b c dd))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-164| (quote (:b \"B\" :a \"A\" :d \"D\"))) (a (getf #:|values-164| :a)) (b (getf #:|values-164| :b)) (c (getf #:|values-164| :c 2)) (dd (getf #:|values-164| :d))) (declare (ignorable #:|values-164|)) (progn (list a b c dd)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-active-layers* nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by WITH-ACTIVE-LAYERS*", "input": "(with-active-layers* nil\n nil)", "output": "(defmacro WITH-ACTIVE-LAYERS* ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(builder (:session :store (make-dbi-store :connector (lambda () *conn*))) (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session))))))))\n\nProblem: Macro call that should be transformed by builder", "input": "(builder (:session :store (make-dbi-store :connector (lambda () *conn*))) (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session))))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app234) (funcall (find-middleware :session) #:app234 :store (make-dbi-store :connector (lambda nil *conn*)))))) :initial-value (to-app (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (#S(sb-impl::comma :expr (format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-test failing (true (< 8 5)) (fail 'happy) (true (= 5 (read-from-string \"OH-SHIT\"))))\n\nWhat needs to change: Macro call that should be transformed by define-test", "input": "(define-test failing (true (< 8 5)) (fail 'happy) (true (= 5 (read-from-string \"OH-SHIT\"))))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote failing) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote failing) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (true (< 8 5))) (lambda nil (fail (quote happy))) (lambda nil (true (= 5 (read-from-string \"OH-SHIT\"))))) :parent (quote nil))) (quote failing))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(newq nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by NEWQ", "input": "(newq nil :key nil)", "output": "(defmacro NEWQ ...)", "macroexpand": "(new 'nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cond->> nil)\n\nIssue: Macro call that should be transformed by COND->>", "input": "(cond->> nil)", "output": "(defmacro COND->> ...)", "macroexpand": "(let* ((#:|cond135| nil))\n #:|cond135|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-generic generic ((a a) (b b) &key (c nil)))\n\nProblem: Macro call that should be transformed by define-generic", "input": "(define-generic generic ((a a) (b b) &key (c nil)))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-first nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-FIRST", "input": "(collect-first nil (progn))", "output": "(defmacro COLLECT-FIRST ...)", "macroexpand": "(common-lisp:let* ((#:generator-632 (generator nil))\n #:items-626\n (#:item-628 (progn)))\n (declare (type generator #:generator-632)\n (type (null-or t) #:item-628))\n (tagbody\n #:ll-633\n (setq #:items-626 (next-in #:generator-632 (go end)))\n (setq #:item-628 #:items-626)\n end)\n #:item-628)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-generic generic (a b &key c) (declare (optimize speed)) (+ a b c))\n\nWrite a macro that addresses: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c) (declare (optimize speed)) (+ a b c))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (declare (optimize speed)) (:method (a b &key c) (declare (optimize speed)) (+ a b c))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when-let (previous *log-manager*) (dolist (messenger (log-manager-messengers previous)) (stop-messenger messenger)))\n\nWhat needs to change: Macro call that should be transformed by when-let", "input": "(when-let (previous *log-manager*) (dolist (messenger (log-manager-messengers previous)) (stop-messenger messenger)))", "output": "(defmacro when-let (binding &body body)\n (destructuring-bind (var val) binding\n `(let ((,var ,val))\n (when ,var\n\t ,@body))))", "macroexpand": "(let ((previous *log-manager*)) (when previous (dolist (messenger (log-manager-messengers previous)) (stop-messenger messenger))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun/1 fmod (x y) (mod x y))\n\nWhat needs to change: Macro call that should be transformed by defun/1", "input": "(defun/1 fmod (x y) (mod x y))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun fmod (x y) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (mod x y)) (defparameter fmod (vacietis.c:mkptr& (symbol-function (quote fmod)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-condition/a dbi-integrity-error (dbi-database-error) () (:documentation \"Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.\"))\n\nWrite a macro that addresses: Macro call that should be transformed by define-condition/a", "input": "(define-condition/a dbi-integrity-error (dbi-database-error) () (:documentation \"Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.\"))", "output": "(defmacro define-condition/a (name parent-types slots &body options)\n `(progn\n (define-condition ,name ,parent-types ,slots ,@options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (define-condition dbi-integrity-error (dbi-database-error) nil (:documentation \"Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.\")) (deftype nil (quote dbi-integrity-error)) (setf (find-class (quote )) (find-class (quote dbi-integrity-error))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(product-of nil\n (progn))\n\nProblem: Macro call that should be transformed by PRODUCT-OF", "input": "(product-of nil\n (progn))", "output": "(defmacro PRODUCT-OF ...)", "macroexpand": "(lc (nil (progn)) multiply)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-element-maker :line \"line\" '(:x1 :y1 :x2 :y2))\n\nWrite a macro that addresses: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :line \"line\" '(:x1 :y1 :x2 :y2))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :line)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:x1 :y1 :x2 :y2)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :line missing))))) (defmethod make-svg-element ((element (eql :line)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"line\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(make-$instance nil (progn))\n\nPattern to recognize: Macro call that should be transformed by MAKE-$INSTANCE", "input": "(make-$instance nil (progn))", "output": "(defmacro MAKE-$INSTANCE ...)", "macroexpand": "(let ((class (symbol-value nil)))\n (funcall (mcs-slot-value class (index-of-basicnew-fn)) class (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(fn nil)\n\nIssue: Macro call that should be transformed by FN", "input": "(fn nil)", "output": "(defmacro FN ...)", "macroexpand": "(lambda () nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-rewrite cddar (expr) `(cdr (cdar ,(second expr))))\n\nPattern to recognize: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cddar (expr) `(cdr (cdar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cddar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cdar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-iter iterator-islice (base-iter start stop delta curr) (islice (iterable start stop delta) \"Works like Python's [islice](https://docs.python.org/3.8/library/itertools.html#itertools.islice)\" (unless (and (>= start 0) (>= stop 0) (> delta 0)) (error (format nil \"Args must all be positive~%\"))) (init-state (base-iter (make-iterator iterable)) start stop delta (curr 0))) (if (< curr start) (progn (loop for _ below start for (__ base-alive) = (multiple-value-list (next base-iter)) when (not base-alive) do (return-from self (values nil nil)) do (incf curr)) (when (< curr stop) (incf curr) (next base-iter))) (loop with base-item with base-alive = t for i below delta do (when (or (not base-alive) (>= curr stop)) (return (values nil nil))) (multiple-value-setq (base-item base-alive) (next base-iter)) (incf curr) finally (return-from self (values base-item t)))))\n\nIssue: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-islice (base-iter start stop delta curr) (islice (iterable start stop delta) \"Works like Python's [islice](https://docs.python.org/3.8/library/itertools.html#itertools.islice)\" (unless (and (>= start 0) (>= stop 0) (> delta 0)) (error (format nil \"Args must all be positive~%\"))) (init-state (base-iter (make-iterator iterable)) start stop delta (curr 0))) (if (< curr start) (progn (loop for _ below start for (__ base-alive) = (multiple-value-list (next base-iter)) when (not base-alive) do (return-from self (values nil nil)) do (incf curr)) (when (< curr stop) (incf curr) (next base-iter))) (loop with base-item with base-alive = t for i below delta do (when (or (not base-alive) (>= curr stop)) (return (values nil nil))) (multiple-value-setq (base-item base-alive) (next base-iter)) (incf curr) finally (return-from self (values base-item t)))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname141 (&key base-iter start stop delta curr) (labels ((self nil (if (< curr start) (progn (loop for _ below start for (__ base-alive) = (multiple-value-list (next base-iter)) when (not base-alive) do (return-from self (values nil nil)) do (incf curr)) (when (< curr stop) (incf curr) (next base-iter))) (loop with base-item with base-alive = t for i below delta do (when (or (not base-alive) (>= curr stop)) (return (values nil nil))) (multiple-value-setq (base-item base-alive) (next base-iter)) (incf curr) finally (return-from self (values base-item t)))))) (function self)))) (defun islice (iterable start stop delta) \"Works like Python's [islice](https://docs.python.org/3.8/library/itertools.html#itertools.islice)\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname141)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (unless (and (>= start 0) (>= stop 0) (> delta 0)) (error (format nil \"Args must all be positive~%\"))) (init-state (base-iter (make-iterator iterable)) start stop delta (curr 0)))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(cond->>\n nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by COND->>", "input": "(cond->>\n nil\n (progn))", "output": "(defmacro COND->> ...)", "macroexpand": "(let* ((#:var164 nil)\n (#:var165\n (if progn\n (->>\n #:var164)\n #:var164)))\n #:var165)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(some-<> nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by SOME-<>", "input": "(some-<> nil :key nil)", "output": "(defmacro SOME-<> ...)", "macroexpand": "(let* ((#:g123 nil)\n (#:g123\n (if (null #:g123)\n nil\n (:key #:g123))))\n (if (null #:g123)\n nil\n (-> #:g123 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ignore-errors 'some-name)\n\nWhat needs to change: Macro call that should be transformed by IGNORE-ERRORS", "input": "(ignore-errors 'some-name)", "output": "(defmacro IGNORE-ERRORS ...)", "macroexpand": "(handler-case (progn 'some-name) (error (condition) (values nil condition)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-element-maker :pattern \"pattern\" '(:id))\n\nProblem: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :pattern \"pattern\" '(:id))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :pattern)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:id)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :pattern missing))))) (defmethod make-svg-element ((element (eql :pattern)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"pattern\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda () :key nil)\n\nWhat needs to change: Macro call that should be transformed by LAMBDA", "input": "(lambda () :key nil)", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda () :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(sum-of 'some-name)\n\nPattern to recognize: Macro call that should be transformed by SUM-OF", "input": "(sum-of 'some-name)", "output": "(defmacro SUM-OF ...)", "macroexpand": "(lc ('some-name) sum)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(c? (* 2 (or (^m-ephem-a) 0)))\n\nWrite a macro that addresses: Macro call that should be transformed by c?", "input": "(c? (* 2 (or (^m-ephem-a) 0)))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((* 2 (or (^m-ephem-a) 0)))) :value-state :unevaluated :rule (c-lambda (* 2 (or (^m-ephem-a) 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(match0 form ((cons a b) `(cons ,(type-of-quoted-form a) ,(type-of-quoted-form b))) (_ (typecase form ((or symbol number character) `(eql ,form)) (t (type-of form)))))\n\nPattern to recognize: Macro call that should be transformed by match0", "input": "(match0 form ((cons a b) `(cons ,(type-of-quoted-form a) ,(type-of-quoted-form b))) (_ (typecase form ((or symbol number character) `(eql ,form)) (t (type-of form)))))", "output": "(defmacro match0 (*what* &body clauses &environment *env*)\n (once-only (*what*)\n (parse-patterns clauses)))", "macroexpand": "(let ((#:*what*161 form)) (declare (ignorable #:*what*161)) (if (and (consp #:*what*161) (let ((#:*what*162 (car #:*what*161))) (declare (ignorable #:*what*162)) t) (let ((#:*what*163 (cdr #:*what*161))) (declare (ignorable #:*what*163)) t)) (let* ((#:*what*162 (car #:*what*161)) (a #:*what*162) (#:*what*163 (cdr #:*what*161)) (b #:*what*163)) (declare (ignorable b #:*what*163 a #:*what*162)) (sb-int:quasiquote (cons #S(sb-impl::comma :expr (type-of-quoted-form a) :kind 0) #S(sb-impl::comma :expr (type-of-quoted-form b) :kind 0)))) (if t (let* nil (declare (ignorable)) (typecase form ((or symbol number character) (sb-int:quasiquote (eql #S(sb-impl::comma :expr form :kind 0)))) (t (type-of form)))) nil)))", "category": "control-flow", "technique": "once-only", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ifmatch nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by IFMATCH", "input": "(ifmatch nil\n :key\n nil)", "output": "(defmacro IFMATCH ...)", "macroexpand": "(match :key (nil nil) (_))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-wcs-math-error-handling (ret (fround x)) (check-wcs-math-result))\n\nProblem: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (fround x)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g248 x) (#:g249 nil) (#:g250 (list #:g248))) (declare (ignorable #:g249) (type list #:g250) (dynamic-extent #:g250)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote fround) #:g250) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g250)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-component-testers (a b #'pathname-version) (and (null a) (null b)) (components-are-member '(:wild :newest :unspecific)) (and (integerp a) (integerp b) (= a b)))\n\nIssue: Macro call that should be transformed by with-component-testers", "input": "(with-component-testers (a b #'pathname-version) (and (null a) (null b)) (components-are-member '(:wild :newest :unspecific)) (and (integerp a) (integerp b) (= a b)))", "output": "(defmacro with-component-testers ((a b key) &body body)\n (let ((k (gensym)))\n `(let* ((,k ,key)\n (,a (funcall ,k ,a))\n (,b (funcall ,k ,b)))\n (labels ((components-are (test)\n (and (funcall test ,a) (funcall test ,b)))\n (components-are-member (values)\n (and (member ,a values :test #'eql)\n (member ,b values :test #'eql)\n (eql ,a ,b)))\n (components-are-string= ()\n (and (stringp ,a) (stringp ,b) (string= ,a ,b)))\n (components-are-every (test)\n (and (consp ,a)\n (consp ,b)\n (every test ,a ,b))))\n (declare (ignorable #'components-are #'components-are-member\n #'components-are-string= #'components-are-every))\n (if (or ,@body)\n (values t ,a ,b)\n nil)))))", "macroexpand": "(let* ((#:g148 (function pathname-version)) (a (funcall #:g148 a)) (b (funcall #:g148 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (and (null a) (null b)) (components-are-member (quote (:wild :newest :unspecific))) (and (integerp a) (integerp b) (= a b))) (values t a b) nil)))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-bug return-set-mismatch () (form) \"Type & Return sets don't match Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: ~s\" form)\n\nIssue: Macro call that should be transformed by define-bug", "input": "(define-bug return-set-mismatch () (form) \"Type & Return sets don't match Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: ~s\" form)", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition return-set-mismatch (:error-type varjo-error :prefix \"Varjo Bug\") (form) \"Type & Return sets don't match Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: ~s\" form)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(js-inline 'some-name)\n\nPattern to recognize: Macro call that should be transformed by JS-INLINE", "input": "(js-inline 'some-name)", "output": "(defmacro JS-INLINE ...)", "macroexpand": "(js-inline* '(progn 'some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-symbol-macro nil (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFINE-SYMBOL-MACRO", "input": "(define-symbol-macro nil (progn))", "output": "(defmacro DEFINE-SYMBOL-MACRO ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c::%define-symbol-macro 'nil '(progn) (sb-c:source-location)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-hook (:build finalize-clos -10000000000) () (labels ((finalize-function (fun) (when (and (typep fun 'generic-function) (not (sb-pcl::special-case-for-compute-discriminating-function-p fun))) (multiple-value-bind (dfun cache info) (sb-pcl::make-final-dfun-internal fun) (sb-pcl::update-dfun fun dfun cache info)))) (finalize-class (class) (unless (sb-mop:class-finalized-p class) (sb-mop:finalize-inheritance class) (dolist (class (sb-mop:class-direct-subclasses class)) (finalize-class class))) (when (typep class 'standard-class) (sb-mop:compute-slots class)))) (do-all-symbols (symbol) (when (find-class symbol NIL) (handler-case (finalize-class (find-class symbol)) (error () (status 3 \"Failed to finalize class ~a\" symbol))))) (do-all-symbols (symbol) (when (fboundp symbol) (handler-case (finalize-function (fdefinition symbol)) (error () (status 3 \"Failed to finalize function ~a\" symbol)))) (when (fboundp `(setf ,symbol)) (handler-case (finalize-function (fdefinition `(setf ,symbol))) (error () (status 3 \"Failed to finalize function ~a\" `(setf ,symbol)))))) (loop for v being the hash-values of sb-pcl::*all-ctors* do (sb-pcl::install-initial-constructor v) (ignore-errors (ecase (sb-pcl::ctor-type v) (sb-pcl::ctor (sb-pcl::install-optimized-constructor v)) (sb-pcl::allocator (sb-pcl::install-optimized-allocator v)))))))\n\nIssue: Macro call that should be transformed by define-hook", "input": "(define-hook (:build finalize-clos -10000000000) () (labels ((finalize-function (fun) (when (and (typep fun 'generic-function) (not (sb-pcl::special-case-for-compute-discriminating-function-p fun))) (multiple-value-bind (dfun cache info) (sb-pcl::make-final-dfun-internal fun) (sb-pcl::update-dfun fun dfun cache info)))) (finalize-class (class) (unless (sb-mop:class-finalized-p class) (sb-mop:finalize-inheritance class) (dolist (class (sb-mop:class-direct-subclasses class)) (finalize-class class))) (when (typep class 'standard-class) (sb-mop:compute-slots class)))) (do-all-symbols (symbol) (when (find-class symbol NIL) (handler-case (finalize-class (find-class symbol)) (error () (status 3 \"Failed to finalize class ~a\" symbol))))) (do-all-symbols (symbol) (when (fboundp symbol) (handler-case (finalize-function (fdefinition symbol)) (error () (status 3 \"Failed to finalize function ~a\" symbol)))) (when (fboundp `(setf ,symbol)) (handler-case (finalize-function (fdefinition `(setf ,symbol))) (error () (status 3 \"Failed to finalize function ~a\" `(setf ,symbol)))))) (loop for v being the hash-values of sb-pcl::*all-ctors* do (sb-pcl::install-initial-constructor v) (ignore-errors (ecase (sb-pcl::ctor-type v) (sb-pcl::ctor (sb-pcl::install-optimized-constructor v)) (sb-pcl::allocator (sb-pcl::install-optimized-allocator v)))))))", "output": "(defmacro define-hook ((type name &optional (priority 0)) args &body body)\n (ecase type (:pre-load) (:load) (:build) (:deploy) (:boot) (:quit))\n (check-type name symbol)\n `(let ((,name (or (hook ,type ',name)\n (make-instance 'hook :name ',name :type ,type))))\n (setf (hook-priority ,name) ,priority)\n (setf (hook-function ,name) (flet ((,name (&key ,@args &allow-other-keys)\n ,@body))\n #',name))\n (setf (hook ,type ',name) ,name)\n (setf (docstring ,name) ,(if (stringp (car body)) (car body)))\n ',name))", "macroexpand": "(let ((finalize-clos (or (hook :build (quote finalize-clos)) (make-instance (quote hook) :name (quote finalize-clos) :type :build)))) (setf (hook-priority finalize-clos) -10000000000) (setf (hook-function finalize-clos) (flet ((finalize-clos (&key &allow-other-keys) (labels ((finalize-function (fun) (when (and (typep fun (quote generic-function)) (not (sb-pcl::special-case-for-compute-discriminating-function-p fun))) (multiple-value-bind (dfun cache info) (sb-pcl::make-final-dfun-internal fun) (sb-pcl::update-dfun fun dfun cache info)))) (finalize-class (class) (unless (sb-mop:class-finalized-p class) (sb-mop:finalize-inheritance class) (dolist (class (sb-mop:class-direct-subclasses class)) (finalize-class class))) (when (typep class (quote standard-class)) (sb-mop:compute-slots class)))) (do-all-symbols (symbol) (when (find-class symbol nil) (handler-case (finalize-class (find-class symbol)) (error nil (status 3 \"Failed to finalize class ~a\" symbol))))) (do-all-symbols (symbol) (when (fboundp symbol) (handler-case (finalize-function (fdefinition symbol)) (error nil (status 3 \"Failed to finalize function ~a\" symbol)))) (when (fboundp (sb-int:quasiquote (setf #S(sb-impl::comma :expr symbol :kind 0)))) (handler-case (finalize-function (fdefinition (sb-int:quasiquote (setf #S(sb-impl::comma :expr symbol :kind 0))))) (error nil (status 3 \"Failed to finalize function ~a\" (sb-int:quasiquote (setf #S(sb-impl::comma :expr symbol :kind 0)))))))) (loop for v being the hash-values of sb-pcl::*all-ctors* do (sb-pcl::install-initial-constructor v) (ignore-errors (ecase (sb-pcl::ctor-type v) (sb-pcl::ctor (sb-pcl::install-optimized-constructor v)) (sb-pcl::allocator (sb-pcl::install-optimized-allocator v)))))))) (function finalize-clos))) (setf (hook :build (quote finalize-clos)) finalize-clos) (setf (docstring finalize-clos) nil) (quote finalize-clos))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(augment-lexenv! :variable environment-var lexenv)\n\nPattern to recognize: Macro call that should be transformed by augment-lexenv!", "input": "(augment-lexenv! :variable environment-var lexenv)", "output": "(defmacro augment-lexenv! (kind name env &rest other-datum)\n `(setf ,env (augment-lexenv ,kind ,name ,env ,@other-datum)))", "macroexpand": "(setf lexenv (augment-lexenv :variable environment-var lexenv))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(ps-inline 'some-name)\n\nPattern to recognize: Macro call that should be transformed by PS-INLINE", "input": "(ps-inline 'some-name)", "output": "(defmacro PS-INLINE ...)", "macroexpand": "(concatenate 'string \"javascript:\" \"\\\"someName\\\"\")", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(sif (car x) (setf it :yes!) (setf it :oops))\n\nProblem: Macro call that should be transformed by sif", "input": "(sif (car x) (setf it :yes!) (setf it :oops))", "output": "(defmacro sif (test then &optional else)\n \"Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for\nthe scope of the then and else expressions. IT can be set with SETF\"\n `(symbolic if ,test ,then ,else))", "macroexpand": "(symbolic if (car x) (setf it :yes!) (setf it :oops))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-type-map macro cl:macro-function)\n\nPattern to recognize: Macro call that should be transformed by define-simple-type-map", "input": "(define-simple-type-map macro cl:macro-function)", "output": "(defmacro define-simple-type-map (class type)\n `(defmethod type ((,class ,class))\n ',type))", "macroexpand": "(defmethod type ((macro macro)) (quote macro-function))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(none-of nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by NONE-OF", "input": "(none-of nil\n nil)", "output": "(defmacro NONE-OF ...)", "macroexpand": "(lc (nil nil) never)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(gather-result 'some-name)\n\nProblem: Macro call that should be transformed by GATHER-RESULT", "input": "(gather-result 'some-name)", "output": "(defmacro GATHER-RESULT ...)", "macroexpand": "(common-lisp:funcall 'some-name nil t)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-preprocessor-state-slots (state) (unless if-section-stack (error 'preprocess-error :format-control \"#~A appeared outside of #if section.\" :format-arguments (list (symbol-name directive-symbol)))))\n\nWhat needs to change: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (unless if-section-stack (error 'preprocess-error :format-control \"#~A appeared outside of #if section.\" :format-arguments (list (symbol-name directive-symbol)))))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (unless if-section-stack (error (quote preprocess-error) :format-control \"#~A appeared outside of #if section.\" :format-arguments (list (symbol-name directive-symbol)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g)))\n\nPattern to recognize: Macro call that should be transformed by do-generators", "input": "(do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g)))", "output": "(defmacro do-generators (genspecs &body body)\n \"Simultaneously iterate through multiple generators at once. By default \ndo-generators terminates when the shortest generator ends, but individual \ngenerators can be padded out with the :fill-value keyword. Do-generators can \nalso iterate over lists in parallel with generators. To use lists, start the genspec with the :list keyword. Eg:\n (do-generators ((a (repeat 2))\n\t\t\t (:list b '(4 5 6))\n\t\t\t (c (list->generator '(8 9)) :fill-value 30))\n\t (print (* a (+ b c))))\n24 \n28 \n72 \nNIL\"\n (let ((genspecs (mapcar #'proc-list-spec genspecs))\n\t(genr (gensym))\n\t(data (gensym))\n\t(sig (gensym)))\n (multiple-value-bind (varnames specs)\n\t(process-genspecs genspecs)\n \n `(let ((,genr (multi-gen ,@specs)))\n\t (loop do\n\t (destructuring-bind (,sig . ,data) \n\t (multiple-value-list (next-generator-value ,genr))\n\t (unless ,sig\n\t (return))\n\t ,(bind-clause data varnames body)))))))", "macroexpand": "(let ((#:g129 (multi-gen (some-numbers) (list->generator data)))) (loop do (destructuring-bind (#:g131 . #:g130) (multiple-value-list (next-generator-value #:g129)) (unless #:g131 (return)) (let ((g (elt (elt #:g130 0) 0)) (l (elt (elt #:g130 1) 0))) (yield (+ l g))))))", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda () (progn))\n\nPattern to recognize: Macro call that should be transformed by LAMBDA", "input": "(lambda () (progn))", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda () (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-bug nil-emit-set () (form possible-set) \"Could not establish emit-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a\" form possible-set)\n\nWrite a macro that addresses: Macro call that should be transformed by define-bug", "input": "(define-bug nil-emit-set () (form possible-set) \"Could not establish emit-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a\" form possible-set)", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition nil-emit-set (:error-type varjo-error :prefix \"Varjo Bug\") (form possible-set) \"Could not establish emit-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a\" form possible-set)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-api copy-named-readtable (named-readtable) (named-readtable-designator => readtable) \"Like COPY-READTABLE but takes a NAMED-READTABLE-DESIGNATOR as argument.\" (copy-readtable (ensure-readtable named-readtable)))\n\nProblem: Macro call that should be transformed by define-api", "input": "(define-api copy-named-readtable (named-readtable) (named-readtable-designator => readtable) \"Like COPY-READTABLE but takes a NAMED-READTABLE-DESIGNATOR as argument.\" (copy-readtable (ensure-readtable named-readtable)))", "output": "(defmacro define-api (name lambda-list type-list &body body)\n (flet ((parse-type-list (type-list)\n (let ((pos (position '=> type-list)))\n (assert pos () \"You forgot to specify return type (`=>' missing.)\")\n (values (subseq type-list 0 pos)\n `(values ,@(nthcdr (1+ pos) type-list) &optional)))))\n (multiple-value-bind (body decls docstring)\n (parse-body body :documentation t :whole `(define-api ,name))\n (multiple-value-bind (arg-typespec value-typespec)\n (parse-type-list type-list)\n (multiple-value-bind (reqs opts rest keys)\n (parse-ordinary-lambda-list lambda-list)\n (declare (ignorable reqs opts rest keys))\n `(progn\n (declaim (ftype (function ,arg-typespec ,value-typespec) ,name))\n (locally\n ;; Muffle the annoying \"&OPTIONAL and &KEY found in\n ;; the same lambda list\" style-warning\n #+sbcl (declare (sb-ext:muffle-conditions style-warning))\n (defun ,name ,lambda-list\n ,docstring\n ,@decls\n (locally\n #+sbcl (declare (sb-ext:unmuffle-conditions style-warning))\n\n ;; SBCL will interpret the ftype declaration as\n ;; assertion and will insert type checks for us.\n #-sbcl\n (progn\n ;; CHECK-TYPE required parameters\n ,@(loop for req-arg in reqs\n for req-type = (pop type-list)\n do (assert req-type)\n collect `(check-type ,req-arg ,req-type))\n\n ;; CHECK-TYPE optional parameters\n ,@(progn\n (assert (or (null opts)\n (eq (pop type-list) '&optional)))\n (loop for (opt-arg . nil) in opts\n for opt-type = (pop type-list)\n do (assert opt-type)\n collect `(check-type ,opt-arg ,opt-type)))\n\n ;; CHECK-TYPE rest parameter\n ,@(when rest\n (assert (eq (pop type-list) '&rest))\n (let ((rest-type (pop type-list)))\n (assert rest-type)\n `((dolist (x ,rest)\n (check-type x ,rest-type)))))\n\n ;; CHECK-TYPE key parameters\n ,@(progn\n (assert (or (null keys)\n (eq (pop type-list) '&key)))\n (loop for ((keyword key-arg) . nil) in keys\n for (nil key-type) = (find keyword type-list\n :key #'car)\n collect `(check-type ,key-arg ,key-type))))\n\n ,@body)))))))))", "macroexpand": "(progn (declaim (ftype (function (named-readtable-designator) (values readtable &optional)) copy-named-readtable)) (locally (declare (sb-ext:muffle-conditions style-warning)) (defun copy-named-readtable (named-readtable) \"Like COPY-READTABLE but takes a NAMED-READTABLE-DESIGNATOR as argument.\" (locally (declare (sb-ext:unmuffle-conditions style-warning)) (copy-readtable (ensure-readtable named-readtable))))))", "category": "efficiency", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defmacro nil (progn))\n\nIssue: Macro call that should be transformed by DEFMACRO", "input": "(defmacro nil (progn))", "output": "(defmacro DEFMACRO ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel)\n (sb-c::%compiler-defmacro :macro-function 'nil))\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c::%defmacro 'nil\n (sb-int:named-lambda (macro-function nil)\n (#:expr #:env)\n (declare (sb-c::lambda-list (progn)))\n (declare (ignore #:env))\n (sb-int:named-ds-bind (:macro nil . defmacro)\n (progn)\n (cdr #:expr)\n (declare (sb-c::constant-value progn))))\n (sb-c:source-location))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(who-ps-html nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by WHO-PS-HTML", "input": "(who-ps-html nil :key nil)", "output": "(defmacro WHO-PS-HTML ...)", "macroexpand": "(stringify nil #A((11) base-char . \"\") nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(fgatherlet nil)\n\nProblem: Macro call that should be transformed by FGATHERLET", "input": "(fgatherlet nil)", "output": "(defmacro FGATHERLET ...)", "macroexpand": "(flet nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error setq-readonly () (var-name code) \"You cannot setq ~a as it is readonly ~%This was attempted as follows ~a\" var-name code)\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error setq-readonly () (var-name code) \"You cannot setq ~a as it is readonly ~%This was attempted as follows ~a\" var-name code)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition setq-readonly (:error-type varjo-error :prefix \"Varjo\") (var-name code) \"You cannot setq ~a as it is readonly ~%This was attempted as follows ~a\" var-name code)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(->>\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by ->>", "input": "(->>\n 'some-name)", "output": "(defmacro ->> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> #'space #'rest)\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> #'space #'rest)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset218) (multiple-value-bind (#:*>-res219 #:*>-next220) (funcall (function space) #:*>-offset218) (if (ok? #:*>-res219) (funcall (function rest) #:*>-next220) (fail #:*>-next220))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(let-syntax common-lisp:nil common-lisp:nil)\n\nIssue: Macro call that should be transformed by LET-SYNTAX", "input": "(let-syntax common-lisp:nil common-lisp:nil)", "output": "(defmacro LET-SYNTAX ...)", "macroexpand": "(common-lisp:progn common-lisp:nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is (test-failure-p (first results)))\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is (test-failure-p (first results)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:v216 (first results))) (if (test-failure-p #:v216) (add-result (quote test-passed) :test-expr (quote (test-failure-p (first results)))) (process-failure (quote (test-failure-p (first results))) \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\" (quote (first results)) #:v216 (quote test-failure-p))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(aand (incf x) t t (values t it))\n\nPattern to recognize: Macro call that should be transformed by aand", "input": "(aand (incf x) t t (values t it))", "output": "(defmacro aand (first &rest rest)\n \"Like AND, except binds the first argument to IT (via LET) for the\nscope of the rest of the arguments.\"\n `(anaphoric and ,first ,@rest))", "macroexpand": "(anaphoric and (incf x) t t (values t it))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defclause-sequence nil nil)\n\nPattern to recognize: Macro call that should be transformed by DEFCLAUSE-SEQUENCE", "input": "(defclause-sequence nil nil)", "output": "(defmacro DEFCLAUSE-SEQUENCE ...)", "macroexpand": "(progn nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dlet 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DLET", "input": "(dlet 'some-name)", "output": "(defmacro DLET ...)", "macroexpand": "(dynamic-let 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(signal-syntax-error \"Invalid range from ~S to ~S in char-class.\" from to)\n\nWrite a macro that addresses: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Invalid range from ~S to ~S in char-class.\" from to)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Invalid range from ~S to ~S in char-class.\" from to)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(m nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by M", "input": "(m nil\n nil)", "output": "(defmacro M ...)", "macroexpand": "(lambda (&rest #:|macro-lambda-list121|)\n (destructuring-bind () #:|macro-lambda-list121| nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(quasiquote-expand (progn (unread-char #\\( stream) (read-preserving-whitespace stream t nil t))))\n\nProblem: Macro call that should be transformed by quasiquote", "input": "(quasiquote-expand (progn (unread-char #\\( stream) (read-preserving-whitespace stream t nil t))))", "output": "(defmacro quasiquote (x) (quasiquote-expand x))", "macroexpand": "(quasiquote-expand (progn (unread-char #\\LEFT_PARENTHESIS stream) (read-preserving-whitespace stream t nil t)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-unique-names (value) (values `((,name (,value) (incf ,var ,value))) `((inline ,name))))\n\nIssue: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (value) (values `((,name (,value) (incf ,var ,value))) `((inline ,name))))", "output": "(defmacro with-unique-names (names &body body)\n `(let ,(mapcar (lambda (sym)\n `(,sym (gensym ,(symbol-name sym))))\n names)\n ,@body))", "macroexpand": "(let ((value (gensym #A((5) base-char . \"VALUE\")))) (values (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (incf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr value :kind 0))))) (quasiquote ((inline #S(sb-impl::comma :expr name :kind 0))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dynamic-relet nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DYNAMIC-RELET", "input": "(dynamic-relet nil\n nil)", "output": "(defmacro DYNAMIC-RELET ...)", "macroexpand": "(dynamic-wind\n :proceed\n #:proceed189\n (let ()\n (declare (special))\n (#:proceed189 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"08004\" sqlserver-rejected-establishment-of-sqlconnection)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"08004\" sqlserver-rejected-establishment-of-sqlconnection)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition sqlserver-rejected-establishment-of-sqlconnection (database-error) nil) (setf (gethash \"08004\" *error-table*) (quote sqlserver-rejected-establishment-of-sqlconnection)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-$instance 'some-name)\n\nWhat needs to change: Macro call that should be transformed by MAKE-$INSTANCE", "input": "(make-$instance 'some-name)", "output": "(defmacro MAKE-$INSTANCE ...)", "macroexpand": "(let ((class (symbol-value 'some-name)))\n (funcall (mcs-slot-value class (index-of-basicnew-fn)) class))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(eswitch ((first feature-expression) :test 'string=) (:and (every #'featurep (rest feature-expression))) (:or (some #'featurep (rest feature-expression))) (:not (assert (= 2 (length feature-expression))) (not (featurep (second feature-expression)))))\n\nProblem: Macro call that should be transformed by eswitch", "input": "(eswitch ((first feature-expression) :test 'string=) (:and (every #'featurep (rest feature-expression))) (:or (some #'featurep (rest feature-expression))) (:not (assert (= 2 (length feature-expression))) (not (featurep (second feature-expression)))))", "output": "(defmacro eswitch (&whole whole (object &key (test 'eql) (key 'identity))\n &body clauses)\n \"Like SWITCH, but signals an error if no key matches.\"\n (generate-switch-body whole object clauses test key '(error)))", "macroexpand": "(let ((#:value131 (identity (first feature-expression)))) (cond ((string= #:value131 :and) (every (function featurep) (rest feature-expression))) ((string= #:value131 :or) (some (function featurep) (rest feature-expression))) ((string= #:value131 :not) (assert (= 2 (length feature-expression))) (not (featurep (second feature-expression)))) (t (error \"No keys match in SWITCH. Testing against ~S with ~S.\" #:value131 (quote string=)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-rewrite cdddar (expr) `(cdr (cddar ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cdddar (expr) `(cdr (cddar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdddar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cddar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-output-to-temporary-file (f) (write-string \"hello\" f))\n\nWhat needs to change: Macro call that should be transformed by with-output-to-temporary-file", "input": "(with-output-to-temporary-file (f) (write-string \"hello\" f))", "output": "(defmacro with-output-to-temporary-file ((stream &rest args) &body body)\n \"Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY\n with STREAM bound to the temporary file stream. Returns the\n pathname of the file that has been created. See OPEN-TEMPORARY for\n permitted options.\"\n `(with-open-stream (,stream (open-temporary ,@args))\n ,@body\n (pathname ,stream)))", "macroexpand": "(with-open-stream (f (open-temporary)) (write-string \"hello\" f) (pathname f))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-cache (\"foo\" :expire 2 :store storage) (error \"MUST NOT BE ERROR\"))\n\nWhat needs to change: Macro call that should be transformed by with-cache", "input": "(with-cache (\"foo\" :expire 2 :store storage) (error \"MUST NOT BE ERROR\"))", "output": "(defmacro with-cache ((key &key store expire) &body body)\n \"If a cache indicated by KEY exists, this just returns the cache\nvalue without evaluating BODY. Otherwise, this evaluates BODY and\nstores the evaluated value into STORE with KEY and EXPIRE. KEY is a\nform that an evaluated value indicates the cache key.\n\nExample:\n\n (defun f (x)\n (with-cache (x *store*)\n (very-complex-computation x)))\"\n (once-only (key store expire)\n (with-gensyms (value exists-p)\n `(multiple-value-bind (,value ,exists-p)\n (getcache ,key ,store)\n (if ,exists-p\n ,value\n (let ((,value (progn ,@body)))\n (setcache ,key ,value ,store :expire ,expire)\n ,value))))))", "macroexpand": "(let ((#:key252 \"foo\") (#:store253 storage) (#:expire254 2)) (multiple-value-bind (#:value255 #:exists-p256) (getcache #:key252 #:store253) (if #:exists-p256 #:value255 (let ((#:value255 (progn (error \"MUST NOT BE ERROR\")))) (setcache #:key252 #:value255 #:store253 :expire #:expire254) #:value255))))", "category": "anaphoric", "technique": "once-only,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(draw scene (:rect :x 0 :y 0 :height \"100%\" :width \"100%\") :fill (xlink-href rg))\n\nWhat needs to change: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x 0 :y 0 :height \"100%\" :width \"100%\") :fill (xlink-href rg))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g160 (funcall (function make-svg-element) :rect (append (list :x 0 :y 0 :height \"100%\" :width \"100%\") (list :fill (xlink-href rg)))))) (add-element scene #:g160) #:g160)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define FOPEN_MAX 1024)\n\nWrite a macro that addresses: Macro call that should be transformed by define", "input": "(define FOPEN_MAX 1024)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote fopen_max) *preprocessor-defines*) #A((4) base-char . \"1024\"))) (defparameter fopen_max 1024))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-object-lookup macro macro-function)\n\nPattern to recognize: Macro call that should be transformed by define-simple-object-lookup", "input": "(define-simple-object-lookup macro macro-function)", "output": "(defmacro define-simple-object-lookup (class lookup-function &body body)\n `(defmethod object ((,class ,class))\n ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function (designator ,class)))))", "macroexpand": "(defmethod object ((macro macro)) (macro-function (designator macro)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n($ nil nil)\n\nWhat needs to change: Macro call that should be transformed by $", "input": "($ nil nil)", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(kv nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dletf* nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by DLETF*", "input": "(dletf* nil\n :key\n nil)", "output": "(defmacro DLETF* ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-binary-op-mapping-definer define-comparison-ops `(progn (defmethod ,op ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (,cl (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod ,op ((x number) (y number)) (if (,cl x y) 1 0))))\n\nPattern to recognize: Macro call that should be transformed by define", "input": "(define-binary-op-mapping-definer define-comparison-ops `(progn (defmethod ,op ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (,cl (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod ,op ((x number) (y number)) (if (,cl x y) 1 0))))", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(defmacro define-comparison-ops (&rest map) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (loop for (vacietis cl) on map by (function cddr) collect (let ((op (find-symbol (symbol-name vacietis) (quote #:vacietis.c)))) (sb-int:quasiquote (progn (defmethod #S(sb-impl::comma :expr op :kind 0) ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (#S(sb-impl::comma :expr cl :kind 0) (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod #S(sb-impl::comma :expr op :kind 0) ((x number) (y number)) (if (#S(sb-impl::comma :expr cl :kind 0) x y) 1 0)))))) :kind 2))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-unique-js-names nil nil)\n\nProblem: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES", "input": "(with-unique-js-names nil nil)", "output": "(defmacro WITH-UNIQUE-JS-NAMES ...)", "macroexpand": "(with-ps-gensyms nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(yield-for-union-ops \"UNION\")\n\nProblem: Macro call that should be transformed by yield-for-union-ops", "input": "(yield-for-union-ops \"UNION\")", "output": "(defmacro yield-for-union-ops (keyword)\n `(multiple-value-bind (statements others)\n (loop for obj in (conjunctive-op-expressions op)\n if (sql-statement-p obj)\n collecting obj into statements\n else\n collecting obj into others\n finally (return (values statements others)))\n (with-yield-binds\n (format nil (if *inside-select*\n \"(~{~A~^ ~})\"\n \"~{~A~^ ~}\")\n (append (list (format nil ,(format nil \"~~{~~A~~^ ~a ~~}\" keyword)\n (mapcar #'yield statements)))\n (when others\n (list (format nil \"~{~A~^ ~}\"\n (mapcar #'yield others)))))))))", "macroexpand": "(multiple-value-bind (statements others) (loop for obj in (conjunctive-op-expressions op) if (sql-statement-p obj) collecting obj into statements else collecting obj into others finally (return (values statements others))) (with-yield-binds (format nil (if *inside-select* \"(~{~A~^ ~})\" \"~{~A~^ ~}\") (append (list (format nil #A((15) base-char . \"~{~A~^ UNION ~}\") (mapcar (function yield) statements))) (when others (list (format nil \"~{~A~^ ~}\" (mapcar (function yield) others))))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defgenerator combinations (list r) \"Emits every possible combination of the items in list in sets of size r. Eg: (combinations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b c) (b d) (c d)\" (labels ((proc (data output r) (if (zerop r) (apply #'yield (reverse output)) (loop for d on data do (proc (cdr d) (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda () 'generator-stop) (proc list nil r))))\n\nProblem: Macro call that should be transformed by defgenerator", "input": "(defgenerator combinations (list r) \"Emits every possible combination of the items in list in sets of size r. Eg: (combinations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b c) (b d) (c d)\" (labels ((proc (data output r) (if (zerop r) (apply #'yield (reverse output)) (loop for d on data do (proc (cdr d) (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda () 'generator-stop) (proc list nil r))))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun combinations (list r) \"Emits every possible combination of the items in list in sets of size r. Eg: (combinations '(a b c d) 2) -(values)-> (a b) (a c) (a d) (b c) (b d) (c d)\" (with-yield (labels ((proc (data output r) (if (zerop r) (apply (function yield) (reverse output)) (loop for d on data do (proc (cdr d) (cons (car d) output) (1- r)))))) (if (< (length list) r) (lambda nil (quote generator-stop)) (proc list nil r)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-simple-appender-to-place 'some-name)\n\nWhat needs to change: Macro call that should be transformed by MAKE-SIMPLE-APPENDER-TO-PLACE", "input": "(make-simple-appender-to-place 'some-name)", "output": "(defmacro MAKE-SIMPLE-APPENDER-TO-PLACE ...)", "macroexpand": "(progn\n (setf 'some-name (alexandria:ensure-list 'some-name))\n (let ((#:tail132 (last 'some-name)))\n (lambda (&rest values)\n (append-at-end 'some-name #:tail132 values)\n 'some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-documentation-lookup package T)\n\nPattern to recognize: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup package T)", "output": "(defmacro define-simple-documentation-lookup (class documentation-type)\n `(defmethod documentation ((,class ,class))\n ,(if (eql documentation-type T)\n `(cl:documentation (object ,class) 'T)\n `(cl:documentation (designator ,class) ',documentation-type))))", "macroexpand": "(defmethod documentation ((package package)) (common-lisp:documentation (object package) (quote t)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(special-symbol-reprogv nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by SPECIAL-SYMBOL-REPROGV", "input": "(special-symbol-reprogv nil\n :key\n nil)", "output": "(defmacro SPECIAL-SYMBOL-REPROGV ...)", "macroexpand": "(let (#:symbol-list209)\n (tagbody\n #:retry210\n (setq #:symbol-list209 nil)\n (unless (every #'special-symbol-p #:symbol-list209)\n (cerror \"Retry to rebind the place(s).\"\n \"Attempt at rebinding one or more non-special places: ~S\" 'nil)\n (go #:retry210)))\n (dynamic-reprogv #:symbol-list209\n :key\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defmacro-clause 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFMACRO-CLAUSE", "input": "(defmacro-clause 'some-name)", "output": "(defmacro DEFMACRO-CLAUSE ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defmacro clause-quote-1 (&key ((:quote some-name))))\n (iterate::install-clause-info '(quote) '(quote) 'clause-quote-1 nil nil)\n ''some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-rewrite cdaar (expr) `(cdr (caar ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cdaar (expr) `(cdr (caar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (caar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(trace$method 'some-name)\n\nIssue: Macro call that should be transformed by TRACE$METHOD", "input": "(trace$method 'some-name)", "output": "(defmacro TRACE$METHOD ...)", "macroexpand": "(mcs-trace quote some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(bind (((:slots-r/o a c) (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3))) (list a c))\n\nProblem: Macro call that should be transformed by bind", "input": "(bind (((:slots-r/o a c) (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3))) (list a c))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-172| (make-instance (quote metabang-bind-class-1) :a 1 :b 2 :c 3)) (a (slot-value #:|values-172| (quote a))) (c (slot-value #:|values-172| (quote c)))) (declare (ignorable #:|values-172|)) (progn (list a c)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-error invalid-context-symbol () (context-symb) \"Sorry but the symbol '~a' is not valid as a context specifier\" context-symb)\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error invalid-context-symbol () (context-symb) \"Sorry but the symbol '~a' is not valid as a context specifier\" context-symb)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition invalid-context-symbol (:error-type varjo-error :prefix \"Varjo\") (context-symb) \"Sorry but the symbol '~a' is not valid as a context specifier\" context-symb)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(cswitch (13 :key 1-) (12 :yay) (13.0 :oops))\n\nPattern to recognize: Macro call that should be transformed by cswitch", "input": "(cswitch (13 :key 1-) (12 :yay) (13.0 :oops))", "output": "(defmacro cswitch (&whole whole (object &key (test 'eql) (key 'identity))\n &body clauses)\n \"Like SWITCH, but signals a continuable error if no key matches.\"\n (generate-switch-body whole object clauses test key '(cerror \"Return NIL from CSWITCH.\")))", "macroexpand": "(let ((#:value135 (1- 13))) (cond ((eql #:value135 12) :yay) ((eql #:value135 13.0) :oops) (t (cerror \"Return NIL from CSWITCH.\" \"No keys match in SWITCH. Testing against ~S with ~S.\" #:value135 (quote eql)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(signal-syntax-error* (lexer-pos lexer) \"Invalid character in named register group.\")\n\nWhat needs to change: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (lexer-pos lexer) \"Invalid character in named register group.\")", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos (lexer-pos lexer) :format-control \"Invalid character in named register group.\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-path-instruction-pair curve-to \"C\" (control-x1 control-y1 control-x2 control-y2 x y))\n\nWrite a macro that addresses: Macro call that should be transformed by define-path-instruction-pair", "input": "(define-path-instruction-pair curve-to \"C\" (control-x1 control-y1 control-x2 control-y2 x y))", "output": "(defmacro define-path-instruction-pair (name instruction (&rest args))\n (let ((draw-relative (intern (concatenate 'string (string name) \"-R\"))))\n `(progn\n (defun ,name (,@args)\n (format-instruction ,instruction ,@args))\n (defun ,draw-relative (,@args)\n (format-instruction ,(string-downcase instruction) ,@args)))))", "macroexpand": "(progn (defun curve-to (control-x1 control-y1 control-x2 control-y2 x y) (format-instruction \"C\" control-x1 control-y1 control-x2 control-y2 x y)) (defun curve-to-r (control-x1 control-y1 control-x2 control-y2 x y) (format-instruction \"c\" control-x1 control-y1 control-x2 control-y2 x y)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dlet nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DLET", "input": "(dlet nil\n :key\n nil)", "output": "(defmacro DLET ...)", "macroexpand": "(dynamic-let nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(mvlet* ((form exp? (expand-in-env-1 self form env)) (exps? (or exps? exp?))) (if (not exp?) (values form exps?) (rec form exps?)))\n\nWhat needs to change: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((form exp? (expand-in-env-1 self form env)) (exps? (or exps? exp?))) (if (not exp?) (values form exps?) (rec form exps?)))", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(multiple-value-bind (form exp?) (expand-in-env-1 self form env) (mvlet* ((exps? (or exps? exp?))) (if (not exp?) (values form exps?) (rec form exps?))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dict-of nil)\n\nWhat needs to change: Macro call that should be transformed by DICT-OF", "input": "(dict-of nil)", "output": "(defmacro DICT-OF ...)", "macroexpand": "(let ((#:dict122 (make-hash-table :test 'equal)))\n (do-for nil\n (multiple-value-call\n (lambda (#:k123 #:v124) (setf (gethash #:k123 #:dict122) #:v124))\n nil))\n #:dict122)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(mapping 'some-name)\n\nProblem: Macro call that should be transformed by MAPPING", "input": "(mapping 'some-name)", "output": "(defmacro MAPPING ...)", "macroexpand": "(mapping-mac 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dotable (item _ set1) (unless (gethash item set2) (add# item set)))\n\nProblem: Macro call that should be transformed by dotable", "input": "(dotable (item _ set1) (unless (gethash item set2) (add# item set)))", "output": "(defmacro dotable ((k v table &optional rez) &body body)\n \"Like DOLIST but iterates over key-value pairs (K V) in anything, that can be\n viewed as a table (hash-table, alist, plist, object).\n Autodeclares variables named _ as ignored.\"\n (with-gensyms (pair)\n (once-only (table)\n (let ((_ (find \"_\" (list k v)\n :test 'string=\n :key 'symbol-name)))\n `(block nil\n (etypecase ,table\n (hash-table (maphash (lambda (,k ,v)\n ,(when _ `(declare (ignore rutils.bind:_)))\n ,@body)\n ,table))\n\n (list (if (rutils.list:alistp ,table)\n (dolist (,pair ,table)\n (destructuring-bind (,k . ,v) ,pair\n ,@(when _ `((declare (ignore ,_))))\n ,@body))\n (error 'simple-type-error\n :format-control \"Can't iterate over proper list ~\n in DOTABLE: need an alist\"))))\n ,rez)))))", "macroexpand": "(let ((#:table168 set1)) (block nil (etypecase #:table168 (hash-table (maphash (lambda (item _) (declare (ignore rutils.bind:_)) (unless (gethash item set2) (|ADD#| item set))) #:table168)) (list (if (alistp #:table168) (dolist (#:g167 #:table168) (destructuring-bind (item . _) #:g167 (declare (ignore _)) (unless (gethash item set2) (|ADD#| item set)))) (error (quote simple-type-error) :format-control \"Can't iterate over proper list ~\n in DOTABLE: need an alist\")))) nil))", "category": "anaphoric", "technique": "once-only,gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym :multiply :mult)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym :multiply :mult)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :multiply) (quote synonym)) (quote :mult)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-custom-var (:boolean *boolean-handler*))\n\nIssue: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:boolean *boolean-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*boolean-handler* . :boolean)) *custom-vars* :test (function equal)) (defvar *boolean-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(->> nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by ->>", "input": "(->> nil :key nil)", "output": "(defmacro ->> ...)", "macroexpand": "((:key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(without-symbol-access\n 'some-name)\n\nWhat needs to change: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS", "input": "(without-symbol-access\n 'some-name)", "output": "(defmacro WITHOUT-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* nil))\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(mvlet 'some-name)\n\nWhat needs to change: Macro call that should be transformed by MVLET", "input": "(mvlet 'some-name)", "output": "(defmacro MVLET ...)", "macroexpand": "(progn (let ((quote) (some-name))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-preprocessor-state-slots (state) (let ((removed-if-section (pop if-section-stack))) (when (eq if-section-skip-reason removed-if-section) (setf if-section-skip-reason nil))))\n\nWhat needs to change: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (let ((removed-if-section (pop if-section-stack))) (when (eq if-section-skip-reason removed-if-section) (setf if-section-skip-reason nil))))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (let ((removed-if-section (pop if-section-stack))) (when (eq if-section-skip-reason removed-if-section) (setf if-section-skip-reason nil))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ok nil \"This supposed to be failed\")\n\nIssue: Macro call that should be transformed by ok", "input": "(ok nil \"This supposed to be failed\")", "output": "(defmacro ok (test &optional desc)\n (with-gensyms (duration result)\n (once-only (test desc)\n `(with-catching-errors (:expected T :description ,desc)\n (with-duration ((,duration ,result) ,test)\n (test ,result t ,desc\n :duration ,duration\n :test-fn (lambda (x y)\n (eq (not (null x)) y))\n :got-form ,test))))))", "macroexpand": "(let ((#:test150 nil) (#:desc151 \"This supposed to be failed\")) (with-catching-errors (:expected t :description #:desc151) (with-duration ((#:duration148 #:result149) #:test150) (test #:result149 t #:desc151 :duration #:duration148 :test-fn (lambda (x y) (eq (not (null x)) y)) :got-form #:test150))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(vect-of 'some-name)\n\nIssue: Macro call that should be transformed by VECT-OF", "input": "(vect-of 'some-name)", "output": "(defmacro VECT-OF ...)", "macroexpand": "(let ((#:vect141 (make-array 10 :adjustable t :fill-pointer 0)))\n (do-for nil\n (vector-push-extend 'some-name #:vect141))\n #:vect141)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when nil :key nil)\n\nIssue: Macro call that should be transformed by WHEN", "input": "(when nil :key nil)", "output": "(defmacro WHEN ...)", "macroexpand": "(if nil\n (progn :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-advisable nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFUN-ADVISABLE", "input": "(defun-advisable nil\n :key\n nil)", "output": "(defmacro DEFUN-ADVISABLE ...)", "macroexpand": "(let ((#:oldfn136\n (handler-case (symbol-function 'nil) (undefined-function nil nil))))\n (defun nil :key nil)\n (make-advisable 'nil :arguments ':key)\n (when\n (and #:oldfn136\n (not (eql (advisable-function-arguments #:oldfn136) :not-provided))\n (equal (advisable-function-arguments #:oldfn136) ':key))\n (copy-advice #:oldfn136 (symbol-function 'nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (every (curry #'char= #\\Null) s))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (every (curry #'char= #\\Null) s))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e262 (curry (function char=) #\\Nul)) (#:a263 s)) (if (progn (every #:e262 #:a263)) (add-result (quote test-passed) :test-expr (quote (every (curry (function char=) #\\Nul) s))) (process-failure (quote (every (curry (function char=) #\\Nul) s)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote s) #:a263 (quote every) #:e262)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-compile-time walk-progn (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper PROGN: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'progn) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'progn)))\n\nWhat needs to change: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-progn (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper PROGN: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'progn) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'progn)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-progn (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper PROGN: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote progn)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote progn)))) (eval-when (:compile-toplevel) (compile (quote walk-progn))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(count-of nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by COUNT-OF", "input": "(count-of nil\n nil)", "output": "(defmacro COUNT-OF ...)", "macroexpand": "(lc (nil nil) count)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclause accumulating-to-and-returning (vars &rest args &key initially by finally) \"Same as accumulating-into, but also returns the value of each at the end of the loop.\" (declare (ignore initially by finally)) `((accumulating-to ,vars ,@args) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))\n\nIssue: Macro call that should be transformed by defclause", "input": "(defclause accumulating-to-and-returning (vars &rest args &key initially by finally) \"Same as accumulating-into, but also returns the value of each at the end of the loop.\" (declare (ignore initially by finally)) `((accumulating-to ,vars ,@args) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro accumulating-to-and-returning (vars &rest args &key initially by finally) \"Same as accumulating-into, but also returns the value of each at the end of the loop.\" (declare (ignore initially by finally)) (sb-int:quasiquote ((accumulating-to #S(sb-impl::comma :expr vars :kind 0) #S(sb-impl::comma :expr args :kind 2)) #S(sb-impl::comma :expr (mapcar (lambda (var) (sb-int:quasiquote (returning #S(sb-impl::comma :expr var :kind 0)))) (ensure-list vars)) :kind 2)))) (pushnew (quote accumulating-to-and-returning) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defstruct*)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFSTRUCT*", "input": "(defstruct*)", "output": "(defmacro DEFSTRUCT* ...)", "macroexpand": "(progn\n (defclass nil nil nil)\n (defun make-nil (&rest structure-ext.as-class::args)\n (apply #'make-instance 'nil structure-ext.as-class::args))\n (defgeneric copy-nil\n (structure-ext.as-class::arg))\n (defmethod copy-nil ((structure-ext.as-class::arg nil))\n (let ((structure-ext.as-class::obj\n (make-instance (class-of structure-ext.as-class::arg))))\n (dolist\n (structure-ext.as-class::slot\n (structure-ext.as-class::slots<=obj structure-ext.as-class::arg))\n (if (slot-boundp structure-ext.as-class::arg\n structure-ext.as-class::slot)\n (setf (slot-value structure-ext.as-class::obj\n structure-ext.as-class::slot)\n (slot-value structure-ext.as-class::arg\n structure-ext.as-class::slot))\n (slot-makunbound structure-ext.as-class::obj\n structure-ext.as-class::slot)))\n structure-ext.as-class::obj))\n (defun nil-p (structure-ext.as-class::arg)\n (typep structure-ext.as-class::arg 'nil))\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-hamt dict (:test test :hash hash :table table) (%hamt-lookup table key (funcall hash key) 0 test))\n\nProblem: Macro call that should be transformed by with-hamt", "input": "(with-hamt dict (:test test :hash hash :table table) (%hamt-lookup table key (funcall hash key) 0 test))", "output": "(defmacro with-hamt (hamt (&key test hash table) &body body)\n \"Accessing HAMT slots\"\n `(with-accessors ((,test hamt-test)\n (,hash hamt-hash)\n (,table hamt-table))\n ,hamt\n ,@body))", "macroexpand": "(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) dict (%hamt-lookup table key (funcall hash key) 0 test))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(match 'some-name)\n\nProblem: Macro call that should be transformed by MATCH", "input": "(match 'some-name)", "output": "(defmacro MATCH ...)", "macroexpand": "(block #:match131\n (let ((#:var130 'some-name))\n (declare (ignorable #:var130))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(next)\n\nPattern to recognize: Macro call that should be transformed by next", "input": "(next)", "output": "(defmacro next () `(return-from clause nil))", "macroexpand": "(common-lisp:return-from trivia.level1.impl::clause common-lisp:nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-name-transformer name)\n\nIssue: Macro call that should be transformed by make-name-transformer", "input": "(make-name-transformer name)", "output": "(defmacro make-name-transformer (&rest elements)\n \"Return an accessor name transformer.\nThe unquoted `name' symbol argument is substituted for the slot name.\nClass option examples:\n\n :accessor-name-transformer (make-name-transformer \\\"FOO-\\\" name \\\"-BAR\\\")\n\nUse the slot name directly:\n\n :accessor-name-transformer (make-name-transformer name)\"\n `(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol ,@(mapcar (lambda (el)\n (if (and (symbolp el)\n (string= (symbol-name el) \"NAME\"))\n 'name\n el))\n elements))))", "macroexpand": "(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol name))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-path-instruction-pair quadratic-curve-to \"Q\" (control-x1 control-y1 x y))\n\nProblem: Macro call that should be transformed by define-path-instruction-pair", "input": "(define-path-instruction-pair quadratic-curve-to \"Q\" (control-x1 control-y1 x y))", "output": "(defmacro define-path-instruction-pair (name instruction (&rest args))\n (let ((draw-relative (intern (concatenate 'string (string name) \"-R\"))))\n `(progn\n (defun ,name (,@args)\n (format-instruction ,instruction ,@args))\n (defun ,draw-relative (,@args)\n (format-instruction ,(string-downcase instruction) ,@args)))))", "macroexpand": "(progn (defun quadratic-curve-to (control-x1 control-y1 x y) (format-instruction \"Q\" control-x1 control-y1 x y)) (defun quadratic-curve-to-r (control-x1 control-y1 x y) (format-instruction \"q\" control-x1 control-y1 x y)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some->>\n nil\n (progn))\n\nProblem: Macro call that should be transformed by SOME->>", "input": "(some->>\n nil\n (progn))", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:var199 nil)\n (#:var200\n (if #:var199\n (progn #:var199)\n nil)))\n #:var200)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-documentation-lookup setf-expander cl:setf)\n\nIssue: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup setf-expander cl:setf)", "output": "(defmacro define-simple-documentation-lookup (class documentation-type)\n `(defmethod documentation ((,class ,class))\n ,(if (eql documentation-type T)\n `(cl:documentation (object ,class) 'T)\n `(cl:documentation (designator ,class) ',documentation-type))))", "macroexpand": "(defmethod documentation ((setf-expander setf-expander)) (common-lisp:documentation (designator setf-expander) (quote setf)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(collect-append nil nil)\n\nPattern to recognize: Macro call that should be transformed by COLLECT-APPEND", "input": "(collect-append nil nil)", "output": "(defmacro COLLECT-APPEND ...)", "macroexpand": "(common-lisp:let* ((#:generator-215 (generator nil))\n #:items-210\n (#:seq-211 nil))\n (declare (type generator #:generator-215))\n (tagbody\n #:ll-216\n (setq #:items-210 (next-in #:generator-215 (go end)))\n (setq #:seq-211 (cons #:items-210 #:seq-211))\n (go #:ll-216)\n end)\n (apply #'concatenate nil (nreverse #:seq-211)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-preprocessor-state-slots (state) (when if-section-skip-reason (begin-if-section state '(:skipped :ifdef) nil) (return-from process-preprocessing-directive nil)) (let* ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol)) (condition `(:ifdef ,identifier)) (result (preprocessor-macro-exists-p macro-alist identifier))) (begin-if-section state condition result)))\n\nPattern to recognize: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (when if-section-skip-reason (begin-if-section state '(:skipped :ifdef) nil) (return-from process-preprocessing-directive nil)) (let* ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol)) (condition `(:ifdef ,identifier)) (result (preprocessor-macro-exists-p macro-alist identifier))) (begin-if-section state condition result)))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (when if-section-skip-reason (begin-if-section state (quote (:skipped :ifdef)) nil) (return-from process-preprocessing-directive nil)) (let* ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol)) (condition (sb-int:quasiquote (:ifdef #S(sb-impl::comma :expr identifier :kind 0)))) (result (preprocessor-macro-exists-p macro-alist identifier))) (begin-if-section state condition result)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-type-map method cl:method)\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-type-map", "input": "(define-simple-type-map method cl:method)", "output": "(defmacro define-simple-type-map (class type)\n `(defmethod type ((,class ,class))\n ',type))", "macroexpand": "(defmethod type ((method method)) (quote common-lisp:method))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time quotify (thing) (if (self-evaluating? thing) thing `',thing))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time quotify (thing) (if (self-evaluating? thing) thing `',thing))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun quotify (thing) (if (self-evaluating? thing) thing (sb-int:quasiquote (quote #S(sb-impl::comma :expr thing :kind 0))))) (eval-when (:compile-toplevel) (compile (quote quotify))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(bind (((:plist a (b _) (c _ 2) (dd d)) '(:b #\\b :a #\\a :d #\\d))) (list a b c dd))\n\nProblem: Macro call that should be transformed by bind", "input": "(bind (((:plist a (b _) (c _ 2) (dd d)) '(:b #\\b :a #\\a :d #\\d))) (list a b c dd))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-187| (quote (:b #\\LATIN_SMALL_LETTER_B :a #\\LATIN_SMALL_LETTER_A :d #\\LATIN_SMALL_LETTER_D))) (a (getf #:|values-187| :a)) (b (getf #:|values-187| :b)) (c (getf #:|values-187| :c 2)) (dd (getf #:|values-187| :d))) (declare (ignorable #:|values-187|)) (progn (list a b c dd)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defstore example (a))\n\nIssue: Macro call that should be transformed by defstore", "input": "(defstore example (a))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote example) (quote (a)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(dynenv-macrolet nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by DYNENV-MACROLET", "input": "(dynenv-macrolet nil\n :key\n nil)", "output": "(defmacro DYNENV-MACROLET ...)", "macroexpand": "(macrolet ()\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-compile-time check-lambda-list (lambda-list) (unless (null (rest (last lambda-list))) (error \"Improper lambda-list: ~S\" lambda-list)) (let ((rest (member '&rest lambda-list :test #'eq))) (if rest (let ((rest (rest rest))) (unless (not (member '&rest rest :test #'eq)) (error \"&REST cannot appear more than once: ~S\" lambda-list)) (unless (and (not (null rest)) (not (member (first rest) lambda-list-keywords :test #'eq)) (or (null (rest rest)) (member (first (rest rest)) lambda-list-keywords :test #'eq))) (error \"&REST must be followed by exactly one variable: ~S\" lambda-list))))) (let ((allow-other-keys (member '&allow-other-keys lambda-list :test #'eq))) (if allow-other-keys (unless (or (null (rest allow-other-keys)) (member (first (rest allow-other-keys)) lambda-list-keywords :test #'eq)) (error \"&ALLOW-OTHER-KEYS must not be followed by a parameter: ~S\" lambda-list)))) (let ((keywords (remove-if-not #'(lambda (argument) (member argument lambda-list-keywords :test #'eq)) lambda-list))) (unless (every #'(lambda (keyword) (member keyword *ordered-lambda-list-keywords* :test #'eq)) keywords) (error \"Invalid lambda list keyword: ~S\" lambda-list)) (unless (every #'(lambda (x y) (member y (member x *ordered-lambda-list-keywords* :test #'eq) :test #'eq)) keywords (rest keywords)) (error \"Invalid order for lambda list keywords: ~S\" lambda-list))) (check-lambda-list-internal lambda-list))\n\nWhat needs to change: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time check-lambda-list (lambda-list) (unless (null (rest (last lambda-list))) (error \"Improper lambda-list: ~S\" lambda-list)) (let ((rest (member '&rest lambda-list :test #'eq))) (if rest (let ((rest (rest rest))) (unless (not (member '&rest rest :test #'eq)) (error \"&REST cannot appear more than once: ~S\" lambda-list)) (unless (and (not (null rest)) (not (member (first rest) lambda-list-keywords :test #'eq)) (or (null (rest rest)) (member (first (rest rest)) lambda-list-keywords :test #'eq))) (error \"&REST must be followed by exactly one variable: ~S\" lambda-list))))) (let ((allow-other-keys (member '&allow-other-keys lambda-list :test #'eq))) (if allow-other-keys (unless (or (null (rest allow-other-keys)) (member (first (rest allow-other-keys)) lambda-list-keywords :test #'eq)) (error \"&ALLOW-OTHER-KEYS must not be followed by a parameter: ~S\" lambda-list)))) (let ((keywords (remove-if-not #'(lambda (argument) (member argument lambda-list-keywords :test #'eq)) lambda-list))) (unless (every #'(lambda (keyword) (member keyword *ordered-lambda-list-keywords* :test #'eq)) keywords) (error \"Invalid lambda list keyword: ~S\" lambda-list)) (unless (every #'(lambda (x y) (member y (member x *ordered-lambda-list-keywords* :test #'eq) :test #'eq)) keywords (rest keywords)) (error \"Invalid order for lambda list keywords: ~S\" lambda-list))) (check-lambda-list-internal lambda-list))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun check-lambda-list (lambda-list) (unless (null (rest (last lambda-list))) (error \"Improper lambda-list: ~S\" lambda-list)) (let ((rest (member (quote &rest) lambda-list :test (function eq)))) (if rest (let ((rest (rest rest))) (unless (not (member (quote &rest) rest :test (function eq))) (error \"&REST cannot appear more than once: ~S\" lambda-list)) (unless (and (not (null rest)) (not (member (first rest) lambda-list-keywords :test (function eq))) (or (null (rest rest)) (member (first (rest rest)) lambda-list-keywords :test (function eq)))) (error \"&REST must be followed by exactly one variable: ~S\" lambda-list))))) (let ((allow-other-keys (member (quote &allow-other-keys) lambda-list :test (function eq)))) (if allow-other-keys (unless (or (null (rest allow-other-keys)) (member (first (rest allow-other-keys)) lambda-list-keywords :test (function eq))) (error \"&ALLOW-OTHER-KEYS must not be followed by a parameter: ~S\" lambda-list)))) (let ((keywords (remove-if-not (function (lambda (argument) (member argument lambda-list-keywords :test (function eq)))) lambda-list))) (unless (every (function (lambda (keyword) (member keyword *ordered-lambda-list-keywords* :test (function eq)))) keywords) (error \"Invalid lambda list keyword: ~S\" lambda-list)) (unless (every (function (lambda (x y) (member y (member x *ordered-lambda-list-keywords* :test (function eq)) :test (function eq)))) keywords (rest keywords)) (error \"Invalid order for lambda list keywords: ~S\" lambda-list))) (check-lambda-list-internal lambda-list)) (eval-when (:compile-toplevel) (compile (quote check-lambda-list))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when nil)\n\nWhat needs to change: Macro call that should be transformed by WHEN", "input": "(when nil)", "output": "(defmacro WHEN ...)", "macroexpand": "(if nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-package-syntax\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-PACKAGE-SYNTAX", "input": "(define-package-syntax\n 'some-name)", "output": "(defmacro define-package-syntax (&body (package . options))\n (unless (typep package 'package-designator)\n (push package options)\n (setq package *package*))\n `(defsyntax ,(package-syntax-name package)\n ,@options))", "macroexpand": "(defsyntax syntax\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n($+ result)\n\nPattern to recognize: Macro call that should be transformed by $", "input": "($+ result)", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(construct-$+- 1 result)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cond->>\n nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by COND->>", "input": "(cond->>\n nil\n :key\n nil)", "output": "(defmacro COND->> ...)", "macroexpand": "(let* ((#:var166 nil)\n (#:var167\n (if :key\n (->>\n #:var166)\n #:var166))\n (#:var168\n (if nil\n (->>\n #:var167)\n #:var167)))\n #:var168)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(min-of 'some-name)\n\nPattern to recognize: Macro call that should be transformed by MIN-OF", "input": "(min-of 'some-name)", "output": "(defmacro MIN-OF ...)", "macroexpand": "(lc ('some-name) minimize)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error if-test-type-mismatch (:error-type varjo-critical-error) (test-obj) \"The result of the test must be a bool.~%~s\" (primary-type test-obj))\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error if-test-type-mismatch (:error-type varjo-critical-error) (test-obj) \"The result of the test must be a bool.~%~s\" (primary-type test-obj))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition if-test-type-mismatch (:error-type varjo-critical-error :prefix \"Varjo\") (test-obj) \"The result of the test must be a bool.~%~s\" (primary-type test-obj))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(sif it it)\n\nPattern to recognize: Macro call that should be transformed by sif", "input": "(sif it it)", "output": "(defmacro sif (test then &optional else)\n \"Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for\nthe scope of the then and else expressions. IT can be set with SETF\"\n `(symbolic if ,test ,then ,else))", "macroexpand": "(symbolic if it it nil)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(macroexpand-convention (form) (if (consp form) (expand-add-declaration-using-head (first form) decl-specifier form) form))\n\nPattern to recognize: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (if (consp form) (expand-add-declaration-using-head (first form) decl-specifier form) form))", "output": "(defmacro macroexpand-convention ((original-form) &body body)\n \"Executes BODY as like `progn' and return the result as the first\nvalue. As the second value, returns a boolean whether the result is\nnot same with ORIGINAL-FORM or not.\nThis macro is designed to follow the `macroexpand' convention.\"\n `(multiple-value-bind (result expanded-p)\n (progn ,@body)\n (values result\n (or expanded-p\n (not (eq result ,original-form))))))", "macroexpand": "(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-add-declaration-using-head (first form) decl-specifier form) form)) (values result (or expanded-p (not (eq result form)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defgeneric nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DEFGENERIC", "input": "(defgeneric nil\n (progn))", "output": "(defmacro DEFGENERIC ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel)\n (common-lisp:defgeneric nil\n (progn)))\n (eval-when (:load-toplevel :execute)\n (common-lisp:defgeneric nil\n (progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(alist-bind (name fields) form (let ((sym (foreign-type-symbol name :cstruct *package*))) (let ((cstruct-fields (parse-fields fields))) (when (symbol-package sym) (pushnew `(:struct (,sym)) *foreign-record-list* :test #'equal)) `(define-foreign-record ',sym :struct ,(aval :bit-size form) ,(aval :bit-alignment form) ',cstruct-fields))))\n\nIssue: Macro call that should be transformed by alist-bind", "input": "(alist-bind (name fields) form (let ((sym (foreign-type-symbol name :cstruct *package*))) (let ((cstruct-fields (parse-fields fields))) (when (symbol-package sym) (pushnew `(:struct (,sym)) *foreign-record-list* :test #'equal)) `(define-foreign-record ',sym :struct ,(aval :bit-size form) ,(aval :bit-alignment form) ',cstruct-fields))))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist241 form)) (let ((name (aval :name #:alist241)) (fields (aval :fields #:alist241))) (let ((sym (foreign-type-symbol name :cstruct *package*))) (let ((cstruct-fields (parse-fields fields))) (when (symbol-package sym) (pushnew (sb-int:quasiquote (:struct (#S(sb-impl::comma :expr sym :kind 0)))) *foreign-record-list* :test (function equal))) (sb-int:quasiquote (define-foreign-record (quote #S(sb-impl::comma :expr sym :kind 0)) :struct #S(sb-impl::comma :expr (aval :bit-size form) :kind 0) #S(sb-impl::comma :expr (aval :bit-alignment form) :kind 0) (quote #S(sb-impl::comma :expr cstruct-fields :kind 0))))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-> :g ((a (b))) (put a) (put b) (mt:open-latch latch))\n\nWhat needs to change: Macro call that should be transformed by ->", "input": "(-> :g ((a (b))) (put a) (put b) (mt:open-latch latch))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g ((a (b))) (put a) (put b) (cl-muth:open-latch latch))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(asif (car x) (setf x :oops) (setf it :yes!))\n\nIssue: Macro call that should be transformed by asif", "input": "(asif (car x) (setf x :oops) (setf it :yes!))", "output": "(defmacro asif (test then &optional else)\n \"Like IF, except binds the result of the test to IT (via LET) for\nthe the scope of the then-expression, and the test form to IT (via\nSYMBOL-MACROLET) for the scope of the else-expression. Within scope of\nthe else-expression, IT can be set with SETF.\"\n `(let ((it ,test))\n (if it\n\t ,then\n\t (symbolic ignore-first ,test ,else))))", "macroexpand": "(let ((it (car x))) (if it (setf x :oops) (symbolic ignore-first (car x) (setf it :yes!))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-documentation-lookup variable cl:variable)\n\nWhat needs to change: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup variable cl:variable)", "output": "(defmacro define-simple-documentation-lookup (class documentation-type)\n `(defmethod documentation ((,class ,class))\n ,(if (eql documentation-type T)\n `(cl:documentation (object ,class) 'T)\n `(cl:documentation (designator ,class) ',documentation-type))))", "macroexpand": "(defmethod documentation ((variable variable)) (common-lisp:documentation (designator variable) (quote common-lisp:variable)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-test dependency (false (sleep 1)))\n\nWhat needs to change: Macro call that should be transformed by define-test", "input": "(define-test dependency (false (sleep 1)))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote dependency) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote dependency) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (false (sleep 1)))) :parent (quote nil))) (quote dependency))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(bind (((:labels my-oddp (x)) (cond ((<= x 0) nil) ((= x 1) t) (t (my-oddp (- x 2)))))) (ensure (my-oddp 1)) (ensure (my-oddp 7)) (ensure-null (my-oddp 2)))\n\nWrite a macro that addresses: Macro call that should be transformed by bind", "input": "(bind (((:labels my-oddp (x)) (cond ((<= x 0) nil) ((= x 1) t) (t (my-oddp (- x 2)))))) (ensure (my-oddp 1)) (ensure (my-oddp 7)) (ensure-null (my-oddp 2)))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(labels ((my-oddp (x) (progn (cond ((<= x 0) nil) ((= x 1) t) (t (my-oddp (- x 2))))))) (progn (ensure (my-oddp 1)) (ensure (my-oddp 7)) (ensure-null (my-oddp 2))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n;; Closure variables are opaque - can't inspect or modify them\n(let ((acc 0) (mul 1))\n (lambda (n)\n (incf acc n)\n (setf mul (* mul n))))\n\n;; To access acc/mul: must add specific getter/setter methods\n;; This doesn't scale - every variable needs its own accessor\n\nProblem: Closure internals are opaque \u2014 want a general protocol for reading/writing any closed-over variable", "input": ";; Closure variables are opaque - can't inspect or modify them\n(let ((acc 0) (mul 1))\n (lambda (n)\n (incf acc n)\n (setf mul (* mul n))))\n\n;; To access acc/mul: must add specific getter/setter methods\n;; This doesn't scale - every variable needs its own accessor", "output": "(defun pandoriclet-get (letargs)\n `(case sym\n ,@(mapcar #`((,(car a1)) ,(car a1))\n letargs)\n (t (error\n \"Unknown pandoric get: ~a\"\n sym))))\n\n(defun pandoriclet-set (letargs)\n `(case sym\n ,@(mapcar #`((,(car a1))\n (setq ,(car a1) val))\n letargs)\n (t (error\n \"Unknown pandoric set: ~a\"\n sym val))))\n\n(defmacro pandoriclet (letargs &rest body)\n (let ((letargs (cons\n '(this)\n (let-binding-transform\n letargs))))\n `(let (,@letargs)\n (setq this ,@(last body))\n ,@(butlast body)\n (dlambda\n (:pandoric-get (sym)\n ,(pandoriclet-get letargs))\n (:pandoric-set (sym val)\n ,(pandoriclet-set letargs))\n (t (&rest args)\n (apply this args))))))", "macroexpand": ";; (pandoriclet ((acc 0) (mul 1))\n;; (lambda (n) (incf acc n) (setf mul (* mul n))))\n;;\n;; Now:\n;; (closure :pandoric-get 'acc) => value of acc\n;; (closure :pandoric-set 'acc 100) => sets acc to 100\n;; (closure 5) => normal call\n;;\n;; with-pandoric makes them look like regular variables:\n;; (with-pandoric (acc mul) closure\n;; (setf acc (+ acc 10)))", "category": "dispatch", "technique": "dlambda,nested-backquote,anaphor", "complexity": "advanced", "quality_score": 0.975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defmethod nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DEFMETHOD", "input": "(defmethod nil\n (progn))", "output": "(defmacro DEFMETHOD ...)", "macroexpand": "(common-lisp:defmethod nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(whichever (1+ x))\n\nProblem: Macro call that should be transformed by whichever", "input": "(whichever (1+ x))", "output": "(defmacro whichever (&rest possibilities &environment env)\n \"Evaluates exactly one of POSSIBILITIES, chosen at random.\"\n (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities))\n (let ((length (length possibilities)))\n (cond\n ((= 1 length)\n (first possibilities))\n ((every #'constantp possibilities)\n `(svref (load-time-value (vector ,@possibilities)) \n (random ,length)))\n (T\n (labels ((expand (possibilities position random-number)\n (if (null (cdr possibilities))\n (car possibilities)\n (let* ((length (length possibilities))\n (half (truncate length 2))\n (second-half (nthcdr half possibilities))\n (first-half (butlast possibilities (- length half))))\n `(if (< ,random-number ,(+ position half))\n ,(expand first-half position random-number)\n ,(expand second-half (+ position half) random-number))))))\n (with-gensyms (random-number)\n `(let ((,random-number (random ,length)))\n ,(expand possibilities 0 random-number))))))))", "macroexpand": "(1+ x)", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8025} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-special-initargs* nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-SPECIAL-INITARGS*", "input": "(with-special-initargs* nil)", "output": "(defmacro WITH-SPECIAL-INITARGS* ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-class some-class (some super classes) () (1 2) (3 4))\n\nWrite a macro that addresses: Macro call that should be transformed by define-class", "input": "(define-class some-class (some super classes) () (1 2) (3 4))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass some-class (some super classes) nil (1 2) (3 4)) (unless (fboundp (quote some-class-p)) (define-generic some-class-p (object) #A((75) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `some-class'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote some-class)))) (find-class (quote some-class) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-special-initargs* nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by WITH-SPECIAL-INITARGS*", "input": "(with-special-initargs* nil\n :key\n nil)", "output": "(defmacro WITH-SPECIAL-INITARGS* ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-dynenv-var nil nil)\n\nIssue: Macro call that should be transformed by DEF-DYNENV-VAR", "input": "(def-dynenv-var nil nil)", "output": "(defmacro DEF-DYNENV-VAR ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar #:nil172 (load-time-value nil))\n (setf (get 'nil 'dynenv-var) '#:nil172)\n (define-symbol-macro nil (get-dynenv-var 'nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-table node hash depth (bitmap array bits index hit) (flet ((%insert (table) (%set-insert table key hash (1+ depth) test))) (let ((new-node (cond (hit (%insert (aref array index))) ((= depth 6) (make-instance 'set-leaf :key key)) (t (%insert (make-instance 'set-table)))))) (make-instance 'set-table :bitmap (logior bitmap (ash 1 bits)) :table (funcall (if hit #'vec-update #'vec-insert) array index new-node)))))\n\nProblem: Macro call that should be transformed by with-table", "input": "(with-table node hash depth (bitmap array bits index hit) (flet ((%insert (table) (%set-insert table key hash (1+ depth) test))) (let ((new-node (cond (hit (%insert (aref array index))) ((= depth 6) (make-instance 'set-leaf :key key)) (t (%insert (make-instance 'set-table)))))) (make-instance 'set-table :bitmap (logior bitmap (ash 1 bits)) :table (funcall (if hit #'vec-update #'vec-insert) array index new-node)))))", "output": "(defmacro with-table (node hash depth\n (bitmap array bits index hit)\n &body body)\n \"Bitshifting in HAMT tables\"\n `(let* ((,bitmap (table-bitmap ,node))\n (,array (table-array ,node))\n (,bits (get-bits ,hash ,depth))\n (,index (get-index ,bits ,bitmap))\n (,hit (logbitp ,bits ,bitmap)))\n ,@body))", "macroexpand": "(let* ((bitmap (table-bitmap node)) (array (table-array node)) (bits (get-bits hash depth)) (index (get-index bits bitmap)) (hit (logbitp bits bitmap))) (flet ((%insert (table) (%set-insert table key hash (1+ depth) test))) (let ((new-node (cond (hit (%insert (aref array index))) ((= depth 6) (make-instance (quote set-leaf) :key key)) (t (%insert (make-instance (quote set-table))))))) (make-instance (quote set-table) :bitmap (logior bitmap (ash 1 bits)) :table (funcall (if hit (function vec-update) (function vec-insert)) array index new-node)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(dletf* 'some-name)\n\nPattern to recognize: Macro call that should be transformed by DLETF*", "input": "(dletf* 'some-name)", "output": "(defmacro DLETF* ...)", "macroexpand": "(dlet ('nil)\n (dlet ((some-name nil))\n (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(bind (((:labels constant (x)) (declare (ignore x)) 42)) (ensure-same (constant 1) 42))\n\nIssue: Macro call that should be transformed by bind", "input": "(bind (((:labels constant (x)) (declare (ignore x)) 42)) (ensure-same (constant 1) 42))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(labels ((constant (x) (declare (ignore x)) (progn 42))) (progn (ensure-same (constant 1) 42)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(fgathering nil)\n\nWhat needs to change: Macro call that should be transformed by FGATHERING", "input": "(fgathering nil)", "output": "(defmacro FGATHERING ...)", "macroexpand": "(flet ()\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-wrap-attempt () name (let ((extern (make-instance 'foreign-extern :name name :c-symbol c-symbol :type (ensure-type type \"extern ~S of type ~S\" name type)))) (setf (gethash name *foreign-externs*) extern)))\n\nPattern to recognize: Macro call that should be transformed by with-wrap-attempt", "input": "(with-wrap-attempt () name (let ((extern (make-instance 'foreign-extern :name name :c-symbol c-symbol :type (ensure-type type \"extern ~S of type ~S\" name type)))) (setf (gethash name *foreign-externs*) extern)))", "output": "(defmacro with-wrap-attempt ((&optional format-control &rest format-args) wrappable-name &body body)\n `(call-with-wrap-attempt ,wrappable-name (lambda () ,@body) ,format-control (list ,@format-args)))", "macroexpand": "(call-with-wrap-attempt name (lambda nil (let ((extern (make-instance (quote foreign-extern) :name name :c-symbol c-symbol :type (ensure-type type \"extern ~S of type ~S\" name type)))) (setf (gethash name *foreign-externs*) extern))) nil (list))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defmethod* nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil\n :key\n nil)", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(defmethod nil :key (with-yield ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-unbound-dynenv-fun nil)\n\nProblem: Macro call that should be transformed by DEF-UNBOUND-DYNENV-FUN", "input": "(def-unbound-dynenv-fun nil)", "output": "(defmacro DEF-UNBOUND-DYNENV-FUN ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun nil (&rest #:args) (apply (dynenv-function nil) #:args))\n (defvar #:nil142)\n (setf (get 'nil 'dynenv-fun) '#:nil142))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-yield-binds (let ((when-else (loop for obj in (conjunctive-op-expressions op) collect (with-table-name nil (yield obj))))) (format nil \"CASE ~{~A~^ ~} END\" when-else)))\n\nIssue: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (let ((when-else (loop for obj in (conjunctive-op-expressions op) collect (with-table-name nil (yield obj))))) (format nil \"CASE ~{~A~^ ~} END\" when-else)))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (let ((when-else (loop for obj in (conjunctive-op-expressions op) collect (with-table-name nil (yield obj))))) (format nil \"CASE ~{~A~^ ~} END\" when-else))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (find (subseq arg 2) *clon-shuffle-opts-long* :test #'string-equal) (setf expecting-arg t))\n\nProblem: Macro call that should be transformed by when", "input": "(when (find (subseq arg 2) *clon-shuffle-opts-long* :test #'string-equal) (setf expecting-arg t))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (find (subseq arg 2) *clon-shuffle-opts-long* :test (function string-equal)) (setf expecting-arg t))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(make-name-transformer nil (progn))\n\nPattern to recognize: Macro call that should be transformed by MAKE-NAME-TRANSFORMER", "input": "(make-name-transformer nil (progn))", "output": "(defmacro MAKE-NAME-TRANSFORMER ...)", "macroexpand": "(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol nil (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-custom-var (:object-key *object-key-handler*))\n\nWrite a macro that addresses: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:object-key *object-key-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*object-key-handler* . :object-key)) *custom-vars* :test (function equal)) (defvar *object-key-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder :session :csrf #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type \"text/html\") (,(if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test #'string=)) (cdr (assoc \"name\" (request-body-parameters req) :test #'string=)) (html-form env)))))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder :session :csrf #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type \"text/html\") (,(if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test #'string=)) (cdr (assoc \"name\" (request-body-parameters req) :test #'string=)) (html-form env)))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (find-middleware :session) (find-middleware :csrf))) :initial-value (to-app (function (lambda (env) (let ((req (make-request env))) (sb-int:quasiquote (200 (:content-type \"text/html\") (#S(sb-impl::comma :expr (if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test (function string=))) (cdr (assoc \"name\" (request-body-parameters req) :test (function string=))) (html-form env)) :kind 0)))))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-mustache-character #\\# (make-instance 'section-start-tag :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*))\n\nIssue: Macro call that should be transformed by define", "input": "(define-mustache-character #\\# (make-instance 'section-start-tag :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*))", "output": "(defmacro define (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "macroexpand": "(set-mustache-character #\\NUMBER_SIGN (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-start-tag) :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-decoder-simple-list-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :keyword))))\n\nIssue: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :keyword))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :keyword))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-op (:is-distinct-from infix-op))\n\nProblem: Macro call that should be transformed by define-op", "input": "(define-op (:is-distinct-from infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (is-distinct-from-op (:include infix-op (name \"IS DISTINCT FROM\")) (:constructor make-is-distinct-from-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defrule nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFRULE", "input": "(defrule nil\n (progn))", "output": "(defmacro DEFRULE ...)", "macroexpand": "(setf (gethash #A((3) base-char . \"NIL\") cl-rules.core::*rules*)\n '#S(cl-rules.core::rule\n :name #A((3) base-char . \"NIL\")\n :conditions (#S(cl-rules.core::condn\n :name #A((5) base-char . \"PROGN\")\n :args nil))\n :actions nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun* nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFUN*", "input": "(defun* nil\n nil)", "output": "(defmacro DEFUN* ...)", "macroexpand": "(defun nil () (with-yield))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-rewrite caadr (expr) `(car (cadr ,(second expr))))\n\nIssue: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite caadr (expr) `(car (cadr ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote caadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cadr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda-coro\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by LAMBDA-CORO", "input": "(lambda-coro\n 'some-name)", "output": "(defmacro LAMBDA-CORO ...)", "macroexpand": "(progn\n (defcoroutine #:name133\n (#:arg134)\n (macrolet ((yield (form)\n (let ((g!-it (gensym \"IT\")))\n `(progn\n (let ((,g!-it ,form))\n (cl-coroutine:yield ,g!-it))\n ,'#:arg134)))\n (last-yield-value ()\n '#:arg134))\n 'some-name\n (coexit!)))\n (make-coroutine '#:name133))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(unless nil)\n\nIssue: Macro call that should be transformed by UNLESS", "input": "(unless nil)", "output": "(defmacro UNLESS ...)", "macroexpand": "(if nil\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (let* ((query (with-trace-sql (execute-with-retry query binds))) (format (or format :plist)) (*plist-row-lispify* (if lispify-specified lispify (case format (:plist t) (otherwise nil))))) (retrieve-from-query query format)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (let* ((query (with-trace-sql (execute-with-retry query binds))) (format (or format :plist)) (*plist-row-lispify* (if lispify-specified lispify (case format (:plist t) (otherwise nil))))) (retrieve-from-query query format)))", "output": "(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)\n `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))", "macroexpand": "(call-with-prepared-query *connection* sql (lambda (query) (let* ((query (with-trace-sql (execute-with-retry query binds))) (format (or format :plist)) (*plist-row-lispify* (if lispify-specified lispify (case format (:plist t) (otherwise nil))))) (retrieve-from-query query format))) :use-prepare-cached *use-prepare-cached*)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(letv*)\n\nWrite a macro that addresses: Macro call that should be transformed by LETV*", "input": "(letv*)", "output": "(defmacro LETV* ...)", "macroexpand": "(block nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do+ (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y) y))))\n\nIssue: Macro call that should be transformed by do+", "input": "(do+ (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y) y))))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y) y))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(terminate-producing)\n\nWhat needs to change: Macro call that should be transformed by TERMINATE-PRODUCING", "input": "(terminate-producing)", "output": "(defmacro TERMINATE-PRODUCING ...)", "macroexpand": "(go end)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(defstore example (a b c))\n\nPattern to recognize: Macro call that should be transformed by defstore", "input": "(defstore example (a b c))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote example) (quote (a b c)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(doseq (item seq) (when (cl:zerop n) (return)) (accumulate c item) (cl:decf n))\n\nPattern to recognize: Macro call that should be transformed by doseq", "input": "(doseq (item seq) (when (cl:zerop n) (return)) (accumulate c item) (cl:decf n))", "output": "(defmacro doseq (name/seq &body body)\n \"Iterate over the elements of a single sequence SEQUENCE.\n\n Same as DO-SEQUENCES but for the special case of iterating over a\n single sequence.\n\n The macro arguments can be in one of the following two forms:\n\n 1. (NAME (ELEMENT SEQUENCE &REST ARGS) &BODY BODY)\n\n 2. ((ELEMENT SEQUENCE &REST ARGS) &BODY BODY)\n\n NAME is the block name, NIL if not given.\n\n ELEMENT is the variable to which each element of the sequence is\n bound.\n\n SEQUENCE is the sequence, with ARGS being the remaining arguments\n passed to the ITERATOR function.\n\n BODY is the list of forms evaluated on each iteration.\"\n\n (let-if ((name name/seq)\n (seq (first body) name/seq)\n (body (rest body) body))\n (symbolp name/seq)\n\n (destructuring-bind (element sequence &rest args) seq\n `(do-sequences ,name\n ((,element ,sequence ,@args))\n ,@body))))", "macroexpand": "(do-sequences nil ((item seq)) (when (zerop n) (return)) (accumulate c item) (decf n))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(match nil)\n\nProblem: Macro call that should be transformed by MATCH", "input": "(match nil)", "output": "(defmacro MATCH ...)", "macroexpand": "(match* (nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(macroexpand-convention (form) (if (consp form) (expand-metaclass-using-head (first form) metaclass form) form))\n\nPattern to recognize: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (if (consp form) (expand-metaclass-using-head (first form) metaclass form) form))", "output": "(defmacro macroexpand-convention ((original-form) &body body)\n \"Executes BODY as like `progn' and return the result as the first\nvalue. As the second value, returns a boolean whether the result is\nnot same with ORIGINAL-FORM or not.\nThis macro is designed to follow the `macroexpand' convention.\"\n `(multiple-value-bind (result expanded-p)\n (progn ,@body)\n (values result\n (or expanded-p\n (not (eq result ,original-form))))))", "macroexpand": "(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-metaclass-using-head (first form) metaclass form) form)) (values result (or expanded-p (not (eq result form)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-<>> nil :key nil)\n\nIssue: Macro call that should be transformed by -<>>", "input": "(-<>> nil :key nil)", "output": "(defmacro -<>> ...)", "macroexpand": "(->> (:key nil) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defstore naxpy (a x y))\n\nPattern to recognize: Macro call that should be transformed by defstore", "input": "(defstore naxpy (a x y))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote naxpy) (quote (a x y)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(switch (13) ((+ 12 2) :oops) ((- 13 1) :oops2) (t :yay))\n\nIssue: Macro call that should be transformed by switch", "input": "(switch (13) ((+ 12 2) :oops) ((- 13 1) :oops2) (t :yay))", "output": "(defmacro switch (&whole whole (object &key (test 'eql) (key 'identity))\n &body clauses)\n \"Evaluates first matching clause, returning its values, or evaluates and\nreturns the values of T or OTHERWISE if no keys match.\"\n (generate-switch-body whole object clauses test key))", "macroexpand": "(let ((#:value130 (identity 13))) (cond ((eql #:value130 (+ 12 2)) :oops) ((eql #:value130 (- 13 1)) :oops2) (nil) (t (progn :yay))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(while nil\n nil)\n\nProblem: Macro call that should be transformed by WHILE", "input": "(while nil\n nil)", "output": "(defmacro WHILE ...)", "macroexpand": "(loop while nil\n do (progn nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-slots nil\n nil)\n\nIssue: Macro call that should be transformed by WITH-SLOTS", "input": "(with-slots nil\n nil)", "output": "(defmacro WITH-SLOTS ...)", "macroexpand": "(let ((#:g178 nil))\n (declare (ignorable #:g178))\n (declare (sb-pcl::%variable-rebinding #:g178 nil))\n (symbol-macrolet ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defstore foo (a b))\n\nWrite a macro that addresses: Macro call that should be transformed by defstore", "input": "(defstore foo (a b))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote foo) (quote (a b)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define L_tmpnam 16)\n\nIssue: Macro call that should be transformed by define", "input": "(define L_tmpnam 16)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote l_tmpnam) *preprocessor-defines*) #A((2) base-char . \"16\"))) (defparameter l_tmpnam 16))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-fixture-restore variable (symbol value) (setf (symbol-value symbol) value))\n\nIssue: Macro call that should be transformed by define-fixture-restore", "input": "(define-fixture-restore variable (symbol value) (setf (symbol-value symbol) value))", "output": "(defmacro define-fixture-restore (name args &body body)\n `(progn (setf (gethash ',name *fixture-restores*)\n (lambda ,args ,@body))\n ',name))", "macroexpand": "(progn (setf (gethash (quote variable) *fixture-restores*) (lambda (symbol value) (setf (symbol-value symbol) value))) (quote variable))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(sum-of nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by SUM-OF", "input": "(sum-of nil\n (progn))", "output": "(defmacro SUM-OF ...)", "macroexpand": "(lc (nil (progn)) sum)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defgeneric nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFGENERIC", "input": "(defgeneric nil\n nil)", "output": "(defmacro DEFGENERIC ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel)\n (common-lisp:defgeneric nil\n nil))\n (eval-when (:load-toplevel :execute)\n (common-lisp:defgeneric nil\n nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defstore example (x &rest args))\n\nPattern to recognize: Macro call that should be transformed by defstore", "input": "(defstore example (x &rest args))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote example) (quote (x &rest args)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(compile-$flavor-$methods nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS", "input": "(compile-$flavor-$methods nil :key nil)", "output": "(defmacro COMPILE-$FLAVOR-$METHODS ...)", "macroexpand": "(eval-when (:load-toplevel) (combine-class-methods nil :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defstore example (object &rest args))\n\nWhat needs to change: Macro call that should be transformed by defstore", "input": "(defstore example (object &rest args))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote example) (quote (object &rest args)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(keep-bops)\n\nIssue: Macro call that should be transformed by KEEP-BOPS", "input": "(keep-bops)", "output": "(defmacro KEEP-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn\n (init-binfix)\n (unless t\n (setq *binfix*\n (delete nil\n (mapcar\n (lambda (bs)\n (setq bs\n (delete-if\n (lambda (b)\n (unless (member (car b) 'nil)\n (remprop (car b) 'properties)\n t))\n bs)))\n *binfix*)))\n (assign-properties))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-global-var* nil :key nil)\n\nProblem: Macro call that should be transformed by DEFINE-GLOBAL-VAR*", "input": "(define-global-var* nil :key nil)", "output": "(defmacro DEFINE-GLOBAL-VAR* ...)", "macroexpand": "(sb-ext:define-load-time-global nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(next-in 'some-name)\n\nPattern to recognize: Macro call that should be transformed by NEXT-IN", "input": "(next-in 'some-name)", "output": "(defmacro NEXT-IN ...)", "macroexpand": "(do-next-in 'some-name #'(lambda ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-quasi-quoted-string-to-string-emitting-form-syntax nil)\n\nPattern to recognize: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-STRING-EMITTING-FORM-SYNTAX", "input": "(enable-quasi-quoted-string-to-string-emitting-form-syntax nil)", "output": "(defmacro ENABLE-QUASI-QUOTED-STRING-TO-STRING-EMITTING-FORM-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-string-to-string-emitting-form-syntax-in-readtable nil\n :with-inline-emitting\n nil\n :declarations\n 'nil\n :start-character\n nil\n :end-character\n nil\n :unquote-character\n #\\COMMA\n :splice-character\n #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP\n :dispatched-quasi-quote-name\n \"str\")\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-mustache-character #\\/ (make-instance 'section-end-tag :text arg-text :start start))\n\nProblem: Macro call that should be transformed by define-mustache-character", "input": "(define-mustache-character #\\/ (make-instance 'section-end-tag :text arg-text :start start))", "output": "(defmacro define-mustache-character (char &body body)\n `(set-mustache-character\n ,char (lambda (raw-text arg-text escapep start end)\n (declare (ignorable raw-text arg-text escapep start end)\n (type simple-string raw-text arg-text)\n (boolean escapep)\n (offset start end))\n ,@body)))", "macroexpand": "(set-mustache-character #\\SOLIDUS (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-end-tag) :text arg-text :start start)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(alter nil nil)\n\nIssue: Macro call that should be transformed by ALTER", "input": "(alter nil nil)", "output": "(defmacro ALTER ...)", "macroexpand": "(compiler-let ((*optimize-series-expressions* nil)) (alter nil nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n($> \"l\" -9)\n\nPattern to recognize: Macro call that should be transformed by $>", "input": "($> \"l\" -9)", "output": "(defmacro $> (&rest args)\n `($op \"$gt\" ,@args))", "macroexpand": "($op \"$gt\" \"l\" -9)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-name-transformer)\n\nWhat needs to change: Macro call that should be transformed by MAKE-NAME-TRANSFORMER", "input": "(make-name-transformer)", "output": "(defmacro MAKE-NAME-TRANSFORMER ...)", "macroexpand": "(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(pop-preprocessor-directive-token token-list \"\")\n\nProblem: Macro call that should be transformed by pop-preprocessor-directive-token", "input": "(pop-preprocessor-directive-token token-list \"\")", "output": "(defmacro pop-preprocessor-directive-token (token-list directive-name &key (errorp t))\n \"Pops the next token in TOKEN-LIST ignoring `+whitespace-marker+'\"\n (with-gensyms (head_)\n `(let ((,head_\n (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)))\n (if (eq +whitespace-marker+ ,head_)\n (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)\n ,head_))))", "macroexpand": "(let ((#:head_267 (check-and-pop-pp-directive-token-1 token-list \"\" t))) (if (eq +whitespace-marker+ #:head_267) (check-and-pop-pp-directive-token-1 token-list \"\" t) #:head_267))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(action (:after node-variable node) (when (eq name (node-variable-value node)) (incf count)) (values))\n\nPattern to recognize: Macro call that should be transformed by action", "input": "(action (:after node-variable node) (when (eq name (node-variable-value node)) (incf count)) (values))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-variable) (lambda (node) (declare (type node-variable node)) (when (eq name (node-variable-value node)) (incf count)) (values)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defjs reduce6(k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))\n\nWhat needs to change: Macro call that should be transformed by defjs", "input": "(defjs reduce6(k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))", "output": "(defmacro defjs (name args &body body)\n \"Define client side javascript. Works like defun; body is in lisp, with parenscript\n additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. \n macro creates a lisp function which sends the javascript function over to the mongo \n server to be evaluated. Result is processed and returned to the reader. \n This will execute 10 times on the server :\n (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))\"\n `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))\n (setf (gethash ',name *js-definitions*) js-body)\n (defun ,name ,args\n (get-element \"retval\" (car (docs (db.eval js-body ,@args)))))))", "macroexpand": "(let* ((js-body (parenscript:ps (lambda (k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))))) (setf (gethash (quote reduce6) *js-definitions*) js-body) (defun reduce6 (k vals) (get-element \"retval\" (car (docs (db.eval js-body k vals))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-sharp-comment-syntax)\n\nPattern to recognize: Macro call that should be transformed by ENABLE-SHARP-COMMENT-SYNTAX", "input": "(enable-sharp-comment-syntax)", "output": "(defmacro ENABLE-SHARP-COMMENT-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-sharp-comment-syntax-in-readtable)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(decf 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DECF", "input": "(decf 'some-name)", "output": "(defmacro DECF ...)", "macroexpand": "(let* ((#:some-name177 some-name)\n (#:new176 (sb-impl::xsubtract 1 '#:some-name177)))\n (funcall #'(setf quote) #:new176 #:some-name177))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun* nil\n (progn))\n\nProblem: Macro call that should be transformed by DEFUN*", "input": "(defun* nil\n (progn))", "output": "(defmacro DEFUN* ...)", "macroexpand": "(progn (declaim (ftype (function (t) t) nil)) (defun (progn) (the t ())))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym :counting :count)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym :counting :count)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :counting) (quote synonym)) (quote :count)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-relet* nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-RELET*", "input": "(dynamic-relet* nil\n (progn))", "output": "(defmacro DYNAMIC-RELET* ...)", "macroexpand": "(progn (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(collect-last nil nil)\n\nIssue: Macro call that should be transformed by COLLECT-LAST", "input": "(collect-last nil nil)", "output": "(defmacro COLLECT-LAST ...)", "macroexpand": "(common-lisp:let* ((#:generator-517 (generator nil))\n #:items-511\n (#:item-513 nil))\n (declare (type generator #:generator-517)\n (type (null-or t) #:item-513))\n (tagbody\n #:ll-518\n (setq #:items-511 (next-in #:generator-517 (go end)))\n (setq #:item-513 #:items-511)\n (go #:ll-518)\n end)\n #:item-513)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-assert-observers (\"changing bar to 2\" bar bar-1) (setf (value (store-lookup :bar store)) 2))\n\nProblem: Macro call that should be transformed by with-assert-observers", "input": "(with-assert-observers (\"changing bar to 2\" bar bar-1) (setf (value (store-lookup :bar store)) 2))", "output": "(defmacro with-assert-observers ((desc &rest asserted-observers) &body body) \n `(let ((*observers* nil))\n (trc ,desc \" -- checking observers\")\n ,@body\n (let ((superfluous-observers (loop for run in *observers* if (not (member run (list ,@asserted-observers))) collect run))\n\t (failed-observers (loop for asserted in (list ,@asserted-observers) if (not (member asserted *observers*)) collect asserted)))\n (trc \"called observers on\" *observers* :superflous superfluous-observers :failed failed-observers)\n (assert (not superfluous-observers))\n (assert (not failed-observers)))))", "macroexpand": "(let ((*observers* nil)) (trc \"changing bar to 2\" \" -- checking observers\") (setf (value (store-lookup :bar store)) 2) (let ((superfluous-observers (loop for run in *observers* if (not (member run (list bar bar-1))) collect run)) (failed-observers (loop for asserted in (list bar bar-1) if (not (member asserted *observers*)) collect asserted))) (trc \"called observers on\" *observers* :superflous superfluous-observers :failed failed-observers) (assert (not superfluous-observers)) (assert (not failed-observers))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-condition/a dbi-internal-error (dbi-database-error) () (:documentation \"Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync.\"))\n\nProblem: Macro call that should be transformed by define-condition/a", "input": "(define-condition/a dbi-internal-error (dbi-database-error) () (:documentation \"Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync.\"))", "output": "(defmacro define-condition/a (name parent-types slots &body options)\n `(progn\n (define-condition ,name ,parent-types ,slots ,@options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (define-condition dbi-internal-error (dbi-database-error) nil (:documentation \"Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync.\")) (deftype nil (quote dbi-internal-error)) (setf (find-class (quote )) (find-class (quote dbi-internal-error))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (is (equalp '((:hello-key . \"hej\") (:hi-starts-with-upper-case . \"tjena\") (:jsonall-capitals . \"totae majusculae\") (:two_words . \"duo verba\") (:camel-case_mixed_4_parts . \"partes miscella quatuor\")) (decode-json-from-string \" { \\\"helloKey\\\" : \\\"hej\\\" , \\\"HiStartsWithUpperCase\\\" : \\\"tjena\\\", \\\"JSONAllCapitals\\\": \\\"totae majusculae\\\", \\\"TWO_WORDS\\\": \\\"duo verba\\\", \\\"camelCase_Mixed_4_PARTS\\\": \\\"partes miscella quatuor\\\" }\")))))\n\nWhat needs to change: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (is (equalp '((:hello-key . \"hej\") (:hi-starts-with-upper-case . \"tjena\") (:jsonall-capitals . \"totae majusculae\") (:two_words . \"duo verba\") (:camel-case_mixed_4_parts . \"partes miscella quatuor\")) (decode-json-from-string \" { \\\"helloKey\\\" : \\\"hej\\\" , \\\"HiStartsWithUpperCase\\\" : \\\"tjena\\\", \\\"JSONAllCapitals\\\": \\\"totae majusculae\\\", \\\"TWO_WORDS\\\": \\\"duo verba\\\", \\\"camelCase_Mixed_4_PARTS\\\": \\\"partes miscella quatuor\\\" }\")))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (let ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* (function simplified-camel-case-to-lisp))) (is (equalp (quote ((:hello-key . \"hej\") (:hi-starts-with-upper-case . \"tjena\") (:jsonall-capitals . \"totae majusculae\") (:two_words . \"duo verba\") (:camel-case_mixed_4_parts . \"partes miscella quatuor\"))) (decode-json-from-string \" { \\\"helloKey\\\" : \\\"hej\\\" , \\\"HiStartsWithUpperCase\\\" : \\\"tjena\\\", \\\"JSONAllCapitals\\\": \\\"totae majusculae\\\", \\\"TWO_WORDS\\\": \\\"duo verba\\\", \\\"camelCase_Mixed_4_PARTS\\\": \\\"partes miscella quatuor\\\" }\")))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(check-cursor-attached cluffer:delete-item (cursor))\n\nIssue: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:delete-item (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:delete-item :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-standard-readtable\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-STANDARD-READTABLE", "input": "(with-standard-readtable\n nil)", "output": "(defmacro WITH-STANDARD-READTABLE ...)", "macroexpand": "(bind ((*readtable* (with-standard-io-syntax (copy-readtable *readtable*))))\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(decf nil (progn))\n\nWhat needs to change: Macro call that should be transformed by DECF", "input": "(decf nil (progn))", "output": "(defmacro DECF ...)", "macroexpand": "(setq nil (sb-impl::xsubtract (progn) nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(draw scene (:circle :cx (random 500) :cy (random 500) :r (+ 10 (random 45))) :stroke \"rgb(232, 229, 148)\" :fill (one-of *groovy-test-colors*))\n\nProblem: Macro call that should be transformed by draw", "input": "(draw scene (:circle :cx (random 500) :cy (random 500) :r (+ 10 (random 45))) :stroke \"rgb(232, 229, 148)\" :fill (one-of *groovy-test-colors*))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g145 (funcall (function make-svg-element) :circle (append (list :cx (random 500) :cy (random 500) :r (+ 10 (random 45))) (list :stroke \"rgb(232, 229, 148)\" :fill (one-of *groovy-test-colors*)))))) (add-element scene #:g145) #:g145)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-cruft dispatch-macro-char-p (char rt) \"Is CHAR a dispatch macro character in RT?\" #+ :common-lisp (handler-case (locally #+clisp (declare (notinline get-dispatch-macro-character)) (get-dispatch-macro-character char #\\x rt) t) (error () nil)))\n\nIssue: Macro call that should be transformed by define-cruft", "input": "(define-cruft dispatch-macro-char-p (char rt) \"Is CHAR a dispatch macro character in RT?\" #+ :common-lisp (handler-case (locally #+clisp (declare (notinline get-dispatch-macro-character)) (get-dispatch-macro-character char #\\x rt) t) (error () nil)))", "output": "(defmacro define-cruft (name lambda-list &body (docstring . alternatives))\n (assert (typep docstring 'string) (docstring) \"Docstring missing!\")\n (assert (not (null alternatives)))\n `(progn\n (declaim (inline ,name))\n (defun ,name ,lambda-list ,docstring ,(first alternatives))))", "macroexpand": "(progn (declaim (inline dispatch-macro-char-p)) (defun dispatch-macro-char-p (char rt) \"Is CHAR a dispatch macro character in RT?\" (handler-case (locally (get-dispatch-macro-character char #\\LATIN_SMALL_LETTER_X rt) t) (error nil nil))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-documentation-lookup structure cl:structure)\n\nWhat needs to change: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup structure cl:structure)", "output": "(defmacro define-simple-documentation-lookup (class documentation-type)\n `(defmethod documentation ((,class ,class))\n ,(if (eql documentation-type T)\n `(cl:documentation (object ,class) 'T)\n `(cl:documentation (designator ,class) ',documentation-type))))", "macroexpand": "(defmethod documentation ((structure structure)) (common-lisp:documentation (designator structure) (quote common-lisp:structure)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(collect-length 'some-name)\n\nPattern to recognize: Macro call that should be transformed by COLLECT-LENGTH", "input": "(collect-length 'some-name)", "output": "(defmacro COLLECT-LENGTH ...)", "macroexpand": "(common-lisp:let* ((#:generator-468 (generator 'some-name)) (#:number-465 0))\n (declare (type generator #:generator-468)\n (type fixnum #:number-465))\n (tagbody\n #:ll-469\n (next-in #:generator-468 (go end))\n (incf #:number-465)\n (go #:ll-469)\n end)\n #:number-465)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-symbol-access)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-SYMBOL-ACCESS", "input": "(with-symbol-access)", "output": "(defmacro WITH-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* t)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-window-or-instance 'some-name)\n\nIssue: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE", "input": "(make-window-or-instance 'some-name)", "output": "(defmacro MAKE-WINDOW-OR-INSTANCE ...)", "macroexpand": "(make-$instance 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dreletf nil)\n\nWhat needs to change: Macro call that should be transformed by DRELETF", "input": "(dreletf nil)", "output": "(defmacro DRELETF ...)", "macroexpand": "(let ((#:symbol-store231\n (with-symbol-access\n (list))))\n (special-symbol-reprogv #:symbol-store231\n (list)\n (locally (declare (special)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-readtable (char readtable readtable) (set-syntax-from-char char #\\A readtable))\n\nWhat needs to change: Macro call that should be transformed by do-readtable", "input": "(do-readtable (char readtable readtable) (set-syntax-from-char char #\\A readtable))", "output": "(defmacro do-readtable ((entry-designator readtable &optional result)\n &body body)\n \"Iterate through a readtable's macro characters, and dispatch macro characters.\"\n (destructuring-bind (char &optional reader-fn non-terminating-p disp? table)\n (if (symbolp entry-designator)\n (list entry-designator)\n entry-designator)\n (let ((iter (gensym \"ITER+\"))\n (more? (gensym \"MORE?+\"))\n (rt (gensym \"READTABLE+\")))\n `(let ((,rt ,readtable))\n (with-readtable-iterator (,iter ,rt)\n (loop\n (multiple-value-bind (,more?\n ,char\n ,@(when reader-fn (list reader-fn))\n ,@(when disp? (list disp?))\n ,@(when table (list table)))\n (,iter)\n (unless ,more? (return ,result))\n (let ,(when non-terminating-p\n ;; FIXME: N-T-P should be incorporated in iterators.\n `((,non-terminating-p\n (nth-value 1 (get-macro-character ,char ,rt)))))\n ,@body))))))))", "macroexpand": "(let ((#:readtable+146 readtable)) (with-readtable-iterator (#:iter+144 #:readtable+146) (loop (multiple-value-bind (#:more?+145 char) (#:iter+144) (unless #:more?+145 (return readtable)) (let nil (set-syntax-from-char char #\\LATIN_CAPITAL_LETTER_A readtable))))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defobject nil (progn))\n\nProblem: Macro call that should be transformed by DEFOBJECT", "input": "(defobject nil (progn))", "output": "(defmacro DEFOBJECT ...)", "macroexpand": "(object :parents (list) :properties (list (list 'progn nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dynenv-function nil)\n\nProblem: Macro call that should be transformed by DYNENV-FUNCTION", "input": "(dynenv-function nil)", "output": "(defmacro DYNENV-FUNCTION ...)", "macroexpand": "(dynenv-function% 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-path-instruction-pair line-to \"L\" (x y))\n\nWhat needs to change: Macro call that should be transformed by define-path-instruction-pair", "input": "(define-path-instruction-pair line-to \"L\" (x y))", "output": "(defmacro define-path-instruction-pair (name instruction (&rest args))\n (let ((draw-relative (intern (concatenate 'string (string name) \"-R\"))))\n `(progn\n (defun ,name (,@args)\n (format-instruction ,instruction ,@args))\n (defun ,draw-relative (,@args)\n (format-instruction ,(string-downcase instruction) ,@args)))))", "macroexpand": "(progn (defun line-to (x y) (format-instruction \"L\" x y)) (defun line-to-r (x y) (format-instruction \"l\" x y)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-unique-js-names nil)\n\nPattern to recognize: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES", "input": "(with-unique-js-names nil)", "output": "(defmacro WITH-UNIQUE-JS-NAMES ...)", "macroexpand": "(with-ps-gensyms nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is-true t)\n\nWhat needs to change: Macro call that should be transformed by is-true", "input": "(is-true t)", "output": "(defmacro is-true (condition &rest reason-args)\n \"Like IS this check generates a pass if CONDITION returns true\n and a failure if CONDITION returns false. Unlike IS this check\n does not inspect CONDITION to determine how to report the\n failure.\"\n `(if ,condition\n (add-result 'test-passed :test-expr ',condition)\n (process-failure ',condition\n ,@(or reason-args\n `(\"~S did not return a true value\" ',condition)))))", "macroexpand": "(if t (add-result (quote test-passed) :test-expr (quote t)) (process-failure (quote t) \"~S did not return a true value\" (quote t)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(or nil)\n\nPattern to recognize: Macro call that should be transformed by OR", "input": "(or nil)", "output": "(defmacro OR ...)", "macroexpand": "(the t nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is (= 0 (dummy-add a (- a))))\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is (= 0 (dummy-add a (- a))))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e158 0) (#:a159 (dummy-add a (- a)))) (if (progn (= #:e158 #:a159)) (add-result (quote test-passed) :test-expr (quote (= 0 (dummy-add a (- a))))) (process-failure (quote (= 0 (dummy-add a (- a)))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (dummy-add a (- a))) #:a159 (quote =) #:e158)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is (some #'test-passed-p results))\n\nProblem: Macro call that should be transformed by is", "input": "(is (some #'test-passed-p results))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e226 (function test-passed-p)) (#:a227 results)) (if (progn (some #:e226 #:a227)) (add-result (quote test-passed) :test-expr (quote (some (function test-passed-p) results))) (process-failure (quote (some (function test-passed-p) results)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote results) #:a227 (quote some) #:e226)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when (node-slot identifier) (del-proxy identifier))\n\nIssue: Macro call that should be transformed by when", "input": "(when (node-slot identifier) (del-proxy identifier))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (node-slot identifier) (del-proxy identifier))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-let+-expansion 'some-name)\n\nIssue: Macro call that should be transformed by DEFINE-LET+-EXPANSION", "input": "(define-let+-expansion 'some-name)", "output": "(defmacro DEFINE-LET+-EXPANSION ...)", "macroexpand": "(progn\n (defmacro quote (&whole #:whole126 &rest some-name)\n #A((16) base-char . \"LET+ form QUOTE.\")\n (declare (ignore some-name))\n #:whole126)\n (defmethod let+-expansion-for-list\n ((first (eql 'quote)) #:arguments125 value body)\n (assert value nil \"Missing value form in ~A.\" 'quote)\n (let ((#:value-once-var127 (gensym \"VALUE\")))\n `(let ((,#:value-once-var127 ,value))\n (declare (ignorable ,#:value-once-var127))\n ,(let ((value #:value-once-var127))\n (destructuring-bind (&rest some-name) #:arguments125))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lret* ((type `(integer 0 (,end))) (vector (make-array end :element-type type :initial-element 0))) (nlet lp ((i 0)) (declare (type array-index i)) (if (= i end) vector (progn (setf (aref vector i) i) (lp (1+ i))))))\n\nProblem: Macro call that should be transformed by lret*", "input": "(lret* ((type `(integer 0 (,end))) (vector (make-array end :element-type type :initial-element 0))) (nlet lp ((i 0)) (declare (type array-index i)) (if (= i end) vector (progn (setf (aref vector i) i) (lp (1+ i))))))", "output": "(defmacro lret* ((&rest bindings) &body body)\n \"Cf. `lret'.\"\n `(lret-aux let* ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((type (sb-int:quasiquote (integer 0 (#S(sb-impl::comma :expr end :kind 0))))) (vector (make-array end :element-type type :initial-element 0))) (nlet lp ((i 0)) (declare (type array-index i)) (if (= i end) vector (progn (setf (aref vector i) i) (lp (1+ i))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(def-iter iterator-enumerate (iterator curr) (enumerate (iterable &optional (curr 0)) \"Yield two-element lists of indices (beginning at curr) and their corresponding elements in `iterable` ``` (enumerate '(a b c d)) ;; (0 a), (1 b), (2 c), (3 d) (enumerate '(a b c d) 3) ;; (3 a), (4 b), (5 c), (6 d) ```\" (init-state (iterator (make-iterator iterable)) curr)) (multiple-value-bind (item alive) (next iterator) (if alive (multiple-value-prog1 (values (list curr item) t) (incf curr)) (values nil nil))))\n\nWrite a macro that addresses: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-enumerate (iterator curr) (enumerate (iterable &optional (curr 0)) \"Yield two-element lists of indices (beginning at curr) and their corresponding elements in `iterable` ``` (enumerate '(a b c d)) ;; (0 a), (1 b), (2 c), (3 d) (enumerate '(a b c d) 3) ;; (3 a), (4 b), (5 c), (6 d) ```\" (init-state (iterator (make-iterator iterable)) curr)) (multiple-value-bind (item alive) (next iterator) (if alive (multiple-value-prog1 (values (list curr item) t) (incf curr)) (values nil nil))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname132 (&key iterator curr) (labels ((self nil (multiple-value-bind (item alive) (next iterator) (if alive (multiple-value-prog1 (values (list curr item) t) (incf curr)) (values nil nil))))) (function self)))) (defun enumerate (iterable &optional (curr 0)) \"Yield two-element lists of indices (beginning at curr) and their corresponding elements in `iterable` ``` (enumerate '(a b c d)) ;; (0 a), (1 b), (2 c), (3 d) (enumerate '(a b c d) 3) ;; (3 a), (4 b), (5 c), (6 d) ```\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname132)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (init-state (iterator (make-iterator iterable)) curr))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-custom-var (:end-of-object *end-of-object-handler*))\n\nWhat needs to change: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:end-of-object *end-of-object-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*end-of-object-handler* . :end-of-object)) *custom-vars* :test (function equal)) (defvar *end-of-object-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(acond ((null 1) (list :no it)) ((+ 1 2) (list :yes it)) (t :nono))\n\nIssue: Macro call that should be transformed by acond", "input": "(acond ((null 1) (list :no it)) ((+ 1 2) (list :yes it)) (t :nono))", "output": "(defmacro acond (&body clauses)\n \"Like COND, except result of each test-form is bound to IT (via LET) for the\nscope of the corresponding clause.\"\n (labels ((rec (clauses)\n\t (if clauses\n\t\t (destructuring-bind ((test &body body) . rest) clauses\n\t\t (if body\n\t\t `(anaphoric if ,test (progn ,@body) ,(rec rest))\n\t\t `(anaphoric if ,test it ,(rec rest))))\n\t\t nil)))\n (rec clauses)))", "macroexpand": "(let ((#:it (null 1))) (if #:it (let ((it #:it)) (declare (ignorable it)) (list :no it)) (acond ((+ 1 2) (list :yes it)) (t :nono))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> (from :users) (when active-only (where (:= :active 1))) (when sort-by-name (order-by :name)))\n\nIssue: Macro call that should be transformed by ->", "input": "(-> (from :users) (when active-only (where (:= :active 1))) (when sort-by-name (order-by :name)))", "output": "(defmacro -> (value &rest forms)\n \"Smart threading macro that dispatches based on clause types returned by forms.\n\n This macro enables immutable query composition by threading clauses through\n query-state objects. Creates a single copy at the beginning, then destructively\n adds clauses for efficiency. Supports both v1 select-statements and composer query-states.\n\n Forms that evaluate to NIL are skipped, enabling conditional composition:\n (-> (from :users)\n (when active-only (where (:= :active 1)))\n (when sort-by-name (order-by :name)))\n\n Examples:\n ;; With composer clause\n (-> (from :users)\n (where (:= :active 1))\n (order-by :name))\n\n ;; With v1 select-statement (backward compatible)\n (-> (select (:id :name) (from :users))\n (where (:= :active 1))\n (order-by :name))\n\n ;; Conditional composition\n (-> (from :users)\n (when include-inactive (where (:= :active 0)))\n (when sort-by-date (order-by :created_at)))\"\n (a:with-gensyms (threaded-var clause-var)\n `(let* ((,threaded-var ,value)\n ;; Convert to query-state and copy once at the beginning\n (,threaded-var\n (typecase ,threaded-var\n (query-state-base (copy-query-state-immutable ,threaded-var))\n (stmt:select-statement (select-statement-to-query-state ,threaded-var))\n (stmt:insert-into-statement (insert-statement-to-query-state ,threaded-var))\n (stmt:update-statement (update-statement-to-query-state ,threaded-var))\n (stmt:delete-from-statement (delete-statement-to-query-state ,threaded-var))\n (otherwise (add-clause (make-select-query-state) ,threaded-var)))))\n ;; Now destructively add clauses (no more copying), skipping NILs\n ,@(loop for form in forms\n collect `(let ((,clause-var ,(if (listp form)\n ;; For list forms, call the function with its arguments (no threading)\n `(,(car form) ,@(cdr form))\n ;; For symbol forms, call the function with no arguments\n `(,form))))\n (when ,clause-var\n (add-clause ,threaded-var ,clause-var))))\n ,threaded-var)))", "macroexpand": "(let* ((#:threaded-var141 (from :users)) (#:threaded-var141 (typecase #:threaded-var141 (query-state-base (copy-query-state-immutable #:threaded-var141)) (stmt:select-statement (select-statement-to-query-state #:threaded-var141)) (stmt:insert-into-statement (insert-statement-to-query-state #:threaded-var141)) (stmt:update-statement (update-statement-to-query-state #:threaded-var141)) (stmt:delete-from-statement (delete-statement-to-query-state #:threaded-var141)) (otherwise (add-clause (make-select-query-state) #:threaded-var141))))) (let ((#:clause-var142 (when active-only (where (:= :active 1))))) (when #:clause-var142 (add-clause #:threaded-var141 #:clause-var142))) (let ((#:clause-var142 (when sort-by-name (order-by :name)))) (when #:clause-var142 (add-clause #:threaded-var141 #:clause-var142))) #:threaded-var141)", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-iterator 'some-name)\n\nPattern to recognize: Macro call that should be transformed by DO-ITERATOR", "input": "(do-iterator 'some-name)", "output": "(defmacro DO-ITERATOR ...)", "macroexpand": "(block nil\n (let ((#:g407 (iterator some-name)))\n (unwind-protect\n (loop named #:g410\n for (#:g408 #:g409) = (multiple-value-list\n (iterator-next! #:g407))\n while #:g409\n for quote = #:g408\n do (progn))\n (iterator-finish! #:g407))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(as-> nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by AS->", "input": "(as-> nil\n nil)", "output": "(defmacro AS-> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(declare-unary-operator nil)\n\nPattern to recognize: Macro call that should be transformed by DECLARE-UNARY-OPERATOR", "input": "(declare-unary-operator nil)", "output": "(defmacro DECLARE-UNARY-OPERATOR ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (infix-math/data::save-unary-operator 'nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n($send nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by $SEND", "input": "($send nil :key nil)", "output": "(defmacro $SEND ...)", "macroexpand": "(send-message nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ensure-getf options :binder binder)\n\nWhat needs to change: Macro call that should be transformed by ensure-getf", "input": "(ensure-getf options :binder binder)", "output": "(defmacro ensure-getf (place key &optional default)\n (once-only (key default)\n `(setf (getf ,place ,key) (getf ,place ,key ,default))))", "macroexpand": "(let ((#:key171 :binder) (#:default172 binder)) (setf (getf options #:key171) (getf options #:key171 #:default172)))", "category": "control-flow", "technique": "once-only", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:is-not-distinct-from infix-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:is-not-distinct-from infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (is-not-distinct-from-op (:include infix-op (name \"IS NOT DISTINCT FROM\")) (:constructor make-is-not-distinct-from-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(mapcar 'e list)\n\nIssue: Macro call that should be transformed by m", "input": "(mapcar 'e list)", "output": "(defmacro m (form &environment *env*)\n (e form))", "macroexpand": "(mapcar (quote e) list)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lret ((out (make-array len :element-type (array-element-type array)))) (replace* out (%flatten array)))\n\nWrite a macro that addresses: Macro call that should be transformed by lret", "input": "(lret ((out (make-array len :element-type (array-element-type array)))) (replace* out (%flatten array)))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let ((out (make-array len :element-type (array-element-type array)))) (replace* out (%flatten array)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(defclause (maximize expr &optional into var) \"Maximize value of an expression\" (return-extremum-code expr var 'max))\n\nPattern to recognize: Macro call that should be transformed by defclause", "input": "(defclause (maximize expr &optional into var) \"Maximize value of an expression\" (return-extremum-code expr var 'max))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-maximize-12 (&key ((:maximize expr)) ((:into var))) \"Maximize value of an expression\" (return-extremum-code expr var (quote max))) (install-clause-info (quote (maximize)) (quote (maximize &optional :into)) (quote clause-maximize-12) \"Maximize value of an expression\" nil) (quote (maximize expr &optional into var)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defvar-unbound *term-char* \"Bound to the closing outer delimiter while parsing a string.\")\n\nWrite a macro that addresses: Macro call that should be transformed by defvar-unbound", "input": "(defvar-unbound *term-char* \"Bound to the closing outer delimiter while parsing a string.\")", "output": "(defmacro defvar-unbound (variable-name documentation)\n \"Like DEFVAR, but the variable will be unbound rather than getting\nan initial value. This is useful for variables which should have no\nglobal value but might have a dynamically bound value.\"\n ;; stolen from comp.lang.lisp article by\n ;; \"prunesquallor@comcast.net\"\n `(eval-when (:load-toplevel :compile-toplevel :execute)\n (defvar ,variable-name)\n (setf (documentation ',variable-name 'variable)\n ,documentation)))", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *term-char*) (setf (documentation (quote *term-char*) (quote variable)) \"Bound to the closing outer delimiter while parsing a string.\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-cfun __errno_location)\n\nPattern to recognize: Macro call that should be transformed by define-cfun", "input": "(define-cfun __errno_location)", "output": "(defmacro define-cfun (name-or-function &optional (package *package*))\n (when-let ((fun (find-function name-or-function)))\n (with-wrap-attempt (\"function ~S\" name-or-function) name-or-function\n (with-slots (name type c-symbol fields) fun\n (let* ((fun-name (intern (symbol-name name) package))\n (param-names (mapcar #'foreign-type-name fields))\n (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))\n (make-function-p (not (foreign-function-variadic-p fun)))\n (maybe-cbv-return\n (when (cbv-return-p fun)\n (list 'return-value))))\n (with-gensyms (!fun !fields rest)\n (let ((form\n (if make-function-p\n `(defun ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n ,(let ((!fun (find-function name-or-function)))\n (with-slots ((!fields fields)) !fun\n (foreign-to-ffi\n (and (car !fields) (foreign-type (car !fields)))\n param-syms\n param-names\n !fields\n (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)\n param-syms (when (foreign-function-variadic-p fun) rest))))))\n `(defmacro ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n (let ((,!fun (find-function ',name-or-function)))\n (with-slots ((,!fields fields)) ,!fun\n (foreign-to-ffi\n (and (car ,!fields) (foreign-type (car ,!fields)))\n ',param-syms\n (list ,@param-names)\n ,!fields\n (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)\n ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))\n `(progn\n ,@(when (foreign-function-cbv-p fun)\n (list (funcall *build-libffi-definition* fun)))\n ,form))))))))", "macroexpand": "nil", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8025} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(action (:after node-variable node) (setf node-vars (adjoin (node-variable-value node) node-vars)) (values))\n\nWrite a macro that addresses: Macro call that should be transformed by action", "input": "(action (:after node-variable node) (setf node-vars (adjoin (node-variable-value node) node-vars)) (values))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-variable) (lambda (node) (declare (type node-variable node)) (setf node-vars (adjoin (node-variable-value node) node-vars)) (values)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(adding-smart-slot-methods obj slot (slot-value obj slot))\n\nWhat needs to change: Macro call that should be transformed by adding-smart-slot-methods", "input": "(adding-smart-slot-methods obj slot (slot-value obj slot))", "output": "(defmacro adding-smart-slot-methods (obj slot expr)\n (with-gensyms (err class name alt args val)\n `(handler-case ,expr\n (simple-error (,err)\n (let ((,class (class-of ,obj))\n (,name (symbol-name ,slot)))\n (dolist (,alt (c2mop:class-slots ,class)\n (error ,err))\n (let ((,alt (c2mop:slot-definition-name ,alt)))\n (when (string= ,name (symbol-name ,alt))\n (add-method (ensure-generic-function 'smart-slot-value)\n (make-instance\n 'standard-method\n :specializers\n (list ,class\n (c2mop:intern-eql-specializer ,slot))\n :lambda-list '(,obj ,slot)\n :function\n (lambda (,args _)\n (declare (ignorable _))\n (slot-value (first ,args) ,alt))))\n (add-method (ensure-generic-function 'smart-set-slot-value)\n (make-instance\n 'standard-method\n :specializers\n (list ,class\n (c2mop:intern-eql-specializer ,slot)\n (find-class 't))\n :lambda-list '(,obj ,slot ,val)\n :function\n (lambda (,args _)\n (declare (ignorable _))\n (:= (slot-value (first ,args) ,alt)\n (third ,args)))))\n (let ((,slot ,alt))\n (return ,expr))))))))))", "macroexpand": "(handler-case (slot-value obj slot) (simple-error (#:g149) (let ((#:g150 (class-of obj)) (#:g151 (symbol-name slot))) (dolist (#:g152 (sb-mop:class-slots #:g150) (error #:g149)) (let ((#:g152 (sb-mop:slot-definition-name #:g152))) (when (string= #:g151 (symbol-name #:g152)) (add-method (ensure-generic-function (quote smart-slot-value)) (make-instance (quote standard-method) :specializers (list #:g150 (sb-mop:intern-eql-specializer slot)) :lambda-list (quote (obj slot)) :function (lambda (#:g153 _) (declare (ignorable _)) (slot-value (first #:g153) #:g152)))) (add-method (ensure-generic-function (quote smart-set-slot-value)) (make-instance (quote standard-method) :specializers (list #:g150 (sb-mop:intern-eql-specializer slot) (find-class (quote t))) :lambda-list (quote (obj slot #:g154)) :function (lambda (#:g153 _) (declare (ignorable _)) (:= (slot-value (first #:g153) #:g152) (third #:g153))))) (let ((slot #:g152)) (return (slot-value obj slot)))))))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-condition/a dbi-unimplemented-error (dbi-interface-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation \"Exception raised if the DBD driver has not specified a mandatory method.\") (:report (lambda (condition stream) (format stream \"`~A' must be implemented.\" (slot-value condition 'method-name)))))\n\nPattern to recognize: Macro call that should be transformed by define-condition/a", "input": "(define-condition/a dbi-unimplemented-error (dbi-interface-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation \"Exception raised if the DBD driver has not specified a mandatory method.\") (:report (lambda (condition stream) (format stream \"`~A' must be implemented.\" (slot-value condition 'method-name)))))", "output": "(defmacro define-condition/a (name parent-types slots &body options)\n `(progn\n (define-condition ,name ,parent-types ,slots ,@options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (define-condition dbi-unimplemented-error (dbi-interface-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation \"Exception raised if the DBD driver has not specified a mandatory method.\") (:report (lambda (condition stream) (format stream \"`~A' must be implemented.\" (slot-value condition (quote method-name)))))) (deftype nil (quote dbi-unimplemented-error)) (setf (find-class (quote )) (find-class (quote dbi-unimplemented-error))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(max-of nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by MAX-OF", "input": "(max-of nil\n nil)", "output": "(defmacro MAX-OF ...)", "macroexpand": "(lc (nil nil) maximize)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time check-function-name (function-name) (unless (valid-function-name? function-name) (error \"Invalid function name: ~S\" function-name)))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time check-function-name (function-name) (unless (valid-function-name? function-name) (error \"Invalid function name: ~S\" function-name)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun check-function-name (function-name) (unless (valid-function-name? function-name) (error \"Invalid function name: ~S\" function-name))) (eval-when (:compile-toplevel) (compile (quote check-function-name))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(js nil)\n\nWrite a macro that addresses: Macro call that should be transformed by JS", "input": "(js nil)", "output": "(defmacro JS ...)", "macroexpand": "(ps\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(true (< 8 5))\n\nPattern to recognize: Macro call that should be transformed by true", "input": "(true (< 8 5))", "output": "(defmacro true (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(true ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected 'T\n :comparison 'geq\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (true (< 8 5))) :value-form (quote (< 8 5)) :body (lambda nil (< 8 5)) :expected (quote t) :comparison (quote geq)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(subtest \"Inner testcase with multiline description.\" (is 'foo 'foo \"Foo with multiline description!\"))\n\nWrite a macro that addresses: Macro call that should be transformed by subtest", "input": "(subtest \"Inner testcase with multiline description.\" (is 'foo 'foo \"Foo with multiline description!\"))", "output": "(defmacro subtest (desc &body body)\n `(%subtest ,desc (lambda () ,@body)))", "macroexpand": "(%subtest \"Inner testcase with multiline description.\" (lambda nil (is (quote foo) (quote foo) \"Foo with multiline description!\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(augment decls decs)\n\nPattern to recognize: Macro call that should be transformed by augment", "input": "(augment decls decs)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf decls (nconc decls decs))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-html-string (let ((*print-pretty*)) (:div (:textarea \"123\"))))\n\nPattern to recognize: Macro call that should be transformed by with-html", "input": "(with-html-string (let ((*print-pretty*)) (:div (:textarea \"123\"))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (let ((*print-pretty*)) (:div (:textarea \"123\")))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-generator (x (list->generator data)) (yield x))\n\nPattern to recognize: Macro call that should be transformed by do-generator", "input": "(do-generator (x (list->generator data)) (yield x))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g170 (list->generator data))) (loop do (if-generator ((x) #:g170) (progn (yield x)) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-op (:as infix-splicing-op))\n\nIssue: Macro call that should be transformed by define-op", "input": "(define-op (:as infix-splicing-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (as-op (:include infix-splicing-op (name \"AS\")) (:constructor make-as-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-option-expander size (package n) (declare (ignore n)) (error \"SIZE option not applicable.\"))\n\nWrite a macro that addresses: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander size (package n) (declare (ignore n)) (error \"SIZE option not applicable.\"))", "output": "(defmacro define-option-expander (name (package &rest arguments) &body body)\n (let ((args (gensym \"ARGS\")))\n `(defmethod expand-option ((,(gensym \"TYPE\") (eql ,(intern (string name) \"KEYWORD\"))) ,package ,args)\n (destructuring-bind ,arguments ,args\n ,@body))))", "macroexpand": "(defmethod expand-option ((#:type138 (eql :size)) package #:args137) (destructuring-bind (n) #:args137 (declare (ignore n)) (error \"SIZE option not applicable.\")))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(cond-<>>\n 'some-name)\n\nPattern to recognize: Macro call that should be transformed by COND-<>>", "input": "(cond-<>>\n 'some-name)", "output": "(defmacro COND-<>> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(compile-$flavor-$methods nil nil)\n\nWhat needs to change: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS", "input": "(compile-$flavor-$methods nil nil)", "output": "(defmacro COMPILE-$FLAVOR-$METHODS ...)", "macroexpand": "(eval-when (:load-toplevel) (combine-class-methods nil nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is (= 2 b))\n\nProblem: Macro call that should be transformed by is", "input": "(is (= 2 b))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e271 2) (#:a272 b)) (if (progn (= #:e271 #:a272)) (add-result (quote test-passed) :test-expr (quote (= 2 b))) (process-failure (quote (= 2 b)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote b) #:a272 (quote =) #:e271)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-header-output (buffer) (let ((cookies (cookie-jar-host-cookies cookie-jar (uri-host uri) (or (uri-path uri) \"/\") :securep (string= (uri-scheme uri) \"https\")))) (when cookies (fast-write-sequence (ascii-string-to-octets \"Cookie: \") buffer) (fast-write-sequence (ascii-string-to-octets (write-cookie-header cookies)) buffer) (fast-write-sequence +crlf+ buffer))))\n\nWhat needs to change: Macro call that should be transformed by with-header-output", "input": "(with-header-output (buffer) (let ((cookies (cookie-jar-host-cookies cookie-jar (uri-host uri) (or (uri-path uri) \"/\") :securep (string= (uri-scheme uri) \"https\")))) (when cookies (fast-write-sequence (ascii-string-to-octets \"Cookie: \") buffer) (fast-write-sequence (ascii-string-to-octets (write-cookie-header cookies)) buffer) (fast-write-sequence +crlf+ buffer))))", "output": "(defmacro with-header-output ((buffer &optional output) &body body)\n `(with-fast-output (,buffer ,output)\n (declare (ignorable ,buffer))\n (let ((*header-buffer* ,buffer))\n ,@body)))", "macroexpand": "(with-fast-output (buffer nil) (declare (ignorable buffer)) (let ((*header-buffer* buffer)) (let ((cookies (cookie-jar-host-cookies cookie-jar (uri-host uri) (or (uri-path uri) \"/\") :securep (string= (uri-scheme uri) \"https\")))) (when cookies (fast-write-sequence (ascii-string-to-octets \"Cookie: \") buffer) (fast-write-sequence (ascii-string-to-octets (write-cookie-header cookies)) buffer) (fast-write-sequence +crlf+ buffer)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-generator-value-list (vars (apply #'multi-gen (loop for g in gens collect (list g :fill-value fillspec)))) (apply #'yield (mapcar #'car vars)))\n\nPattern to recognize: Macro call that should be transformed by do-generator", "input": "(do-generator-value-list (vars (apply #'multi-gen (loop for g in gens collect (list g :fill-value fillspec)))) (apply #'yield (mapcar #'car vars)))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g158 (apply (function multi-gen) (loop for g in gens collect (list g :fill-value fillspec))))) (loop do (if-generator (vars #:g158) (progn (apply (function yield) (mapcar (function car) vars))) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Generate a defmacro form that transforms code like this:\n(signal-syntax-error \"Variable length look-behind not implemented \\(yet): ~S.\" parse-tree)\n\nPattern to recognize: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Variable length look-behind not implemented \\(yet): ~S.\" parse-tree)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Variable length look-behind not implemented (yet): ~S.\" parse-tree)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun/1 freopen (filename mode fd) (handler-case (progn (fclose fd) (clearerr fd) (setf (fd-stream fd) (open-stream filename mode))) (error () (setf errno EIO) NULL)))\n\nWrite a macro that addresses: Macro call that should be transformed by defun/1", "input": "(defun/1 freopen (filename mode fd) (handler-case (progn (fclose fd) (clearerr fd) (setf (fd-stream fd) (open-stream filename mode))) (error () (setf errno EIO) NULL)))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun freopen (filename mode fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (progn (fclose fd) (clearerr fd) (setf (fd-stream fd) (open-stream filename mode))) (error nil (setf errno eio) null))) (defparameter freopen (vacietis.c:mkptr& (symbol-function (quote freopen)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(->* nil)\n\nIssue: Macro call that should be transformed by ->*", "input": "(->* nil)", "output": "(defmacro ->* ...)", "macroexpand": "(-> nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(defgenerator imap (function &rest generators) \"The generator equivalent of the mapcar function. Applies function to the values of the supplied generators, emitting the result. Eg: (imap #'* (list->generator '(2 3 4)) (list->generator '(4 5 6))) -> 8 15 24\" (do-generator-value-list (vals (apply #'multi-gen generators)) (yield (apply function (mapcar #'car vals)))))\n\nPattern to recognize: Macro call that should be transformed by defgenerator", "input": "(defgenerator imap (function &rest generators) \"The generator equivalent of the mapcar function. Applies function to the values of the supplied generators, emitting the result. Eg: (imap #'* (list->generator '(2 3 4)) (list->generator '(4 5 6))) -> 8 15 24\" (do-generator-value-list (vals (apply #'multi-gen generators)) (yield (apply function (mapcar #'car vals)))))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun imap (function &rest generators) \"The generator equivalent of the mapcar function. Applies function to the values of the supplied generators, emitting the result. Eg: (imap #'* (list->generator '(2 3 4)) (list->generator '(4 5 6))) -> 8 15 24\" (with-yield (do-generator-value-list (vals (apply (function multi-gen) generators)) (yield (apply function (mapcar (function car) vals))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(count-of 'some-name)\n\nProblem: Macro call that should be transformed by COUNT-OF", "input": "(count-of 'some-name)", "output": "(defmacro COUNT-OF ...)", "macroexpand": "(lc ('some-name) count)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (= 1 (length results)))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (= 1 (length results)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e211 1) (#:a212 (length results))) (if (progn (= #:e211 #:a212)) (add-result (quote test-passed) :test-expr (quote (= 1 (length results)))) (process-failure (quote (= 1 (length results))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (length results)) #:a212 (quote =) #:e211)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dletf* nil\n nil)\n\nProblem: Macro call that should be transformed by DLETF*", "input": "(dletf* nil\n nil)", "output": "(defmacro DLETF* ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda-ematch (PATTERN BODY...))\n\nWrite a macro that addresses: Macro call that should be transformed by lambda-ematch", "input": "(lambda-ematch (PATTERN BODY...))", "output": "(defmacro lambda-ematch (&body clauses)\n \"Equivalent to (lambda (arg) (ematch arg CLAUSES...)).\"\n (with-unique-names (arg)\n `(lambda (,arg) (ematch ,arg ,@clauses))))", "macroexpand": "(lambda (#:arg123) (ematch #:arg123 (pattern body...)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(*let 'some-name)\n\nPattern to recognize: Macro call that should be transformed by *LET", "input": "(*let 'some-name)", "output": "(defmacro *LET ...)", "macroexpand": "(let* ((quote nil) (some-name nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defpackage nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFPACKAGE", "input": "(defpackage nil)", "output": "(defmacro DEFPACKAGE ...)", "macroexpand": "(prog1 (common-lisp:defpackage nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-local-readtable\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-LOCAL-READTABLE", "input": "(with-local-readtable\n 'some-name)", "output": "(defmacro WITH-LOCAL-READTABLE ...)", "macroexpand": "(bind ((*readtable* (copy-readtable *readtable*)))\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-method-combination% min :operator min :identity-with-one-argument t)\n\nProblem: Macro call that should be transformed by define-method-combination%", "input": "(define-method-combination% min :operator min :identity-with-one-argument t)", "output": "(defmacro define-method-combination% (name &rest args)\n \"Define a method-combination for the static-dispatch system only.\n\n Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION.\"\n\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf\n (combination-function ',name)\n ,(match args\n ((or nil\n (list* (and (type symbol) (not nil)) _))\n\n (destructuring-bind (&key (operator name) (identity-with-one-argument nil))\n args\n\n `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))\n\n (_\n `(method-combination-function ,name ,@args))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote min)) (method-combination-function-short min min t)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(builder nil (if t nil nil) nil *app*)\n\nIssue: Macro call that should be transformed by builder", "input": "(builder nil (if t nil nil) nil *app*)", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (let ((#:res171 (if t nil nil))) (typecase #:res171 (keyword (find-middleware #:res171)) (cons (if (keywordp (car #:res171)) (let ((#:res-mw170 (find-middleware (car #:res171)))) (lambda (#:app169) (apply #:res-mw170 #:app169 (cdr #:res171)))) #:res171)) (standard-object (lambda (#:app169) (funcall (intern (string :wrap) :clack.middleware) #:res171 #:app169))) (otherwise #:res171))))) :initial-value (to-app *app*) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(->*)\n\nPattern to recognize: Macro call that should be transformed by ->*", "input": "(->*)", "output": "(defmacro ->* ...)", "macroexpand": "(->)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(make-instance* 'class ())\n\nProblem: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class ())", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(apply (function make-instance) (quote class) nil)", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9099999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(fmap (lambda (s) (let ((*read-default-float-format* 'double-float)) (cl:float (read-from-string s) 1.0d0))) (funcall (recognize (*> #'integer (opt (*> (char #\\.) (take-while1 #'digit?))))) offset))\n\nIssue: Macro call that should be transformed by fmap", "input": "(fmap (lambda (s) (let ((*read-default-float-format* 'double-float)) (cl:float (read-from-string s) 1.0d0))) (funcall (recognize (*> #'integer (opt (*> (char #\\.) (take-while1 #'digit?))))) offset))", "output": "(defmacro fmap (f thing)\n \"Apply a pure function to the inner contents of some parsing operation, if the\nparsing itself was successful.\"\n `(multiple-value-bind (res next) ,thing\n (if (failure? res)\n (fail next)\n (values (funcall ,f res) next))))", "macroexpand": "(multiple-value-bind (res next) (funcall (recognize (*> (function integer) (opt (*> (char #\\FULL_STOP) (take-while1 (function digit?)))))) offset) (if (failure? res) (fail next) (values (funcall (lambda (s) (let ((*read-default-float-format* (quote double-float))) (common-lisp:float (read-from-string s) 1.0d0))) res) next)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-generic name (arg1 arg2) \\\"Docstring\\\" (:documentation \\\"Real docstring\\\"))\" (first body))\n\nProblem: Macro call that should be transformed by define-generic", "input": "(define-generic name (arg1 arg2) \\\"Docstring\\\" (:documentation \\\"Real docstring\\\"))\" (first body))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric name (arg1 arg2) (:method (arg1 arg2) |\"DOCSTRING\"|) (:documentation |\"REAL| |DOCSTRING\"|)) (setf (documentation (quote name) (quote function)) |\"REAL|) (setf (documentation (fdefinition (quote name)) (quote function)) |\"REAL|))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-definition-resolver method (designator package) (when (designator-generic-function-p designator) (loop for method in (sb-mop:generic-function-methods (fdefinition designator)) collect (make-instance 'method :designator designator :package package :method method))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-definition-resolver", "input": "(define-definition-resolver method (designator package) (when (designator-generic-function-p designator) (loop for method in (sb-mop:generic-function-methods (fdefinition designator)) collect (make-instance 'method :designator designator :package package :method method))))", "output": "(defmacro define-definition-resolver (name args &body body)\n `(progn (setf (definition-resolver ',name)\n (lambda ,args ,@body))\n ',name))", "macroexpand": "(progn (setf (definition-resolver (quote method)) (lambda (designator package) (when (designator-generic-function-p designator) (loop for method in (sb-mop:generic-function-methods (fdefinition designator)) collect (make-instance (quote method) :designator designator :package package :method method))))) (quote method))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-documentation-lookup macro cl:function)\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup macro cl:function)", "output": "(defmacro define-simple-documentation-lookup (class documentation-type)\n `(defmethod documentation ((,class ,class))\n ,(if (eql documentation-type T)\n `(cl:documentation (object ,class) 'T)\n `(cl:documentation (designator ,class) ',documentation-type))))", "macroexpand": "(defmethod documentation ((macro macro)) (common-lisp:documentation (designator macro) (quote common-lisp:function)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defmethod* nil\n nil)\n\nProblem: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil\n nil)", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(defmethod nil nil (with-yield))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-dynenv nil)\n\nProblem: Macro call that should be transformed by WITH-DYNENV", "input": "(with-dynenv nil)", "output": "(defmacro WITH-DYNENV ...)", "macroexpand": "(multiple-value-bind (#:var-expansion122 #:var-expanded-p123)\n (macroexpand-1 'var-space nil)\n (multiple-value-bind (#:fun-expansion124 #:fun-expanded-p125)\n (macroexpand-1 'fun-space nil)\n (let ((*var-space* (when #:var-expanded-p123 #:var-expansion122))\n (*fun-space* (when #:fun-expanded-p125 #:fun-expansion124))\n (*within-captured-dynenv* t)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(bind (((:flet doit (x)) \"if I knew how to get the docstring out of flet, I'd test it.\" (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))\n\nProblem: Macro call that should be transformed by bind", "input": "(bind (((:flet doit (x)) \"if I knew how to get the docstring out of flet, I'd test it.\" (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(flet ((doit (x) \"if I knew how to get the docstring out of flet, I'd test it.\" (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(as->* nil\n (progn))\n\nProblem: Macro call that should be transformed by AS->*", "input": "(as->* nil\n (progn))", "output": "(defmacro AS->* ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-disable-handler-restart (handler) (with-hook-restart (apply handler args)))\n\nPattern to recognize: Macro call that should be transformed by with-disable-handler-restart", "input": "(with-disable-handler-restart (handler) (with-hook-restart (apply handler args)))", "output": "(defmacro with-disable-handler-restart ((handler) &body body)\n \"This is intended to wrap all handler executions.\"\n `(restart-case\n (progn ,@body)\n (disable-handler ()\n :report\n (lambda (stream)\n (format stream \"Disable handler ~a which causes the error.\" ,handler))\n (disable-hook *hook* ,handler))))", "macroexpand": "(restart-case (progn (with-hook-restart (apply handler args))) (disable-handler nil :report (lambda (stream) (format stream \"Disable handler ~a which causes the error.\" handler)) (disable-hook *hook* handler)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-temp (d :directory t :debug (<= 1 *debug-prolog*)) (with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(,*yap* \"-l\" ,input-file ,@args) :input input :output output :error error)))\n\nPattern to recognize: Macro call that should be transformed by with-temp", "input": "(with-temp (d :directory t :debug (<= 1 *debug-prolog*)) (with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(,*yap* \"-l\" ,input-file ,@args) :input input :output output :error error)))", "output": "(defmacro with-temp ((var &key directory template (tmpdir \"/tmp/\") debug) &body body)\n \"Create a temporary file, then remove the file by unwind-protect.\nMost arguments are analogous to mktemp.\nWhen DIRECTORY is non-nil, creates a directory instead.\nDEBUG is a form.\nWhen evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.\nIt may be evaluated multiple times.\"\n (with-gensyms (command)\n `(let ((,var (uiop:run-program\n (let ((,command (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\"\n ,tmpdir ,directory ,template)))\n (when ,debug\n (format *error-output* \"~&; ~a~%\" ,command))\n ,command)\n :output '(:string :stripped t))))\n (unwind-protect\n (progn ,@body)\n (if ,debug\n (format *error-output* \"~&; not removing ~a for debugging~%\" ,var)\n (uiop:run-program (format nil \"rm -rf ~a\" (namestring ,var)) :ignore-error-status t))))))", "macroexpand": "(let ((d (uiop/run-program:run-program (let ((#:command179 (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\" \"/tmp/\" t nil))) (when (<= 1 *debug-prolog*) (format *error-output* \"~&; ~a~%\" #:command179)) #:command179) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print (sb-int:quasiquote (#S(sb-impl::comma :expr *yap* :kind 0) \"-l\" #S(sb-impl::comma :expr input-file :kind 0) #S(sb-impl::comma :expr args :kind 2))) :input input :output output :error error))) (if (<= 1 *debug-prolog*) (format *error-output* \"~&; not removing ~a for debugging~%\" d) (uiop/run-program:run-program (format nil \"rm -rf ~a\" (namestring d)) :ignore-error-status t))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(set-arg-list-key-value! nil :key nil)\n\nProblem: Macro call that should be transformed by SET-ARG-LIST-KEY-VALUE!", "input": "(set-arg-list-key-value! nil :key nil)", "output": "(defmacro set-arg-list-key-value! (new ids place &key (test '#'equalper) (key '#'identity))\n `(progn\n (iter (for id in (ensure-list ,ids))\n (setf ,place (set-arg-list-key-value ,new id ,place :test ,test :key ,key)))\n ,place))", "macroexpand": "(progn\n (iter\n (for id in (ensure-list :key))\n (setf nil\n (set-arg-list-key-value nil id nil :test #'equalper :key\n #'identity)))\n nil)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-<> 'some-name)\n\nWhat needs to change: Macro call that should be transformed by -<>", "input": "(-<> 'some-name)", "output": "(defmacro -<> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-method-combination% standard () ((around (:around)) (before (:before)) (primary () :required t) (after (:after) :order :most-specific-last)) (labels ((call-methods (methods) (mapcar (curry #'list 'call-method) methods)) (call-primary (primary) `(call-method ,(first primary) ,(rest primary))) (call-before (before form) (if before `(progn ,@(call-methods before) ,form) form)) (call-after (after form) (if after `(multiple-value-prog1 ,form ,@(call-methods after)) form)) (call-around (around form) (if around `(call-method ,(first around) (,@(rest around) (make-method ,form))) form))) (->> (call-primary primary) (call-before before) (call-after after) (call-around around))))\n\nPattern to recognize: Macro call that should be transformed by define-method-combination%", "input": "(define-method-combination% standard () ((around (:around)) (before (:before)) (primary () :required t) (after (:after) :order :most-specific-last)) (labels ((call-methods (methods) (mapcar (curry #'list 'call-method) methods)) (call-primary (primary) `(call-method ,(first primary) ,(rest primary))) (call-before (before form) (if before `(progn ,@(call-methods before) ,form) form)) (call-after (after form) (if after `(multiple-value-prog1 ,form ,@(call-methods after)) form)) (call-around (around form) (if around `(call-method ,(first around) (,@(rest around) (make-method ,form))) form))) (->> (call-primary primary) (call-before before) (call-after after) (call-around around))))", "output": "(defmacro define-method-combination% (name &rest args)\n \"Define a method-combination for the static-dispatch system only.\n\n Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION.\"\n\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf\n (combination-function ',name)\n ,(match args\n ((or nil\n (list* (and (type symbol) (not nil)) _))\n\n (destructuring-bind (&key (operator name) (identity-with-one-argument nil))\n args\n\n `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))\n\n (_\n `(method-combination-function ,name ,@args))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote standard)) (method-combination-function standard nil ((around (:around)) (before (:before)) (primary nil :required t) (after (:after) :order :most-specific-last)) (labels ((call-methods (methods) (mapcar (curry (function list) (quote call-method)) methods)) (call-primary (primary) (sb-int:quasiquote (call-method #S(sb-impl::comma :expr (first primary) :kind 0) #S(sb-impl::comma :expr (rest primary) :kind 0)))) (call-before (before form) (if before (sb-int:quasiquote (progn #S(sb-impl::comma :expr (call-methods before) :kind 2) #S(sb-impl::comma :expr form :kind 0))) form)) (call-after (after form) (if after (sb-int:quasiquote (multiple-value-prog1 #S(sb-impl::comma :expr form :kind 0) #S(sb-impl::comma :expr (call-methods after) :kind 2))) form)) (call-around (around form) (if around (sb-int:quasiquote (call-method #S(sb-impl::comma :expr (first around) :kind 0) (#S(sb-impl::comma :expr (rest around) :kind 2) (make-method #S(sb-impl::comma :expr form :kind 0))))) form))) (->> (call-primary primary) (call-before before) (call-after after) (call-around around))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(macroexpand-convention (form) (destructuring-case form ((progn &body body) `(progn ,@(apply-at-macro-to-multiple-forms at-macro-form body))) ((eval-when situations &body body) `(eval-when ,situations ,@(apply-at-macro-to-multiple-forms at-macro-form body))) ((locally &body body) (multiple-value-bind (body declarations) (parse-body body) `(locally ,@declarations ,@(apply-at-macro-to-multiple-forms at-macro-form body)))) (((macrolet symbol-macrolet) bindings &body body) (multiple-value-bind (body declarations) (parse-body body) `(,(first form) ,bindings ,@declarations ,@(apply-at-macro-to-multiple-forms at-macro-form body)))) ((otherwise &rest _) (declare (ignore _)) form)))\n\nIssue: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (destructuring-case form ((progn &body body) `(progn ,@(apply-at-macro-to-multiple-forms at-macro-form body))) ((eval-when situations &body body) `(eval-when ,situations ,@(apply-at-macro-to-multiple-forms at-macro-form body))) ((locally &body body) (multiple-value-bind (body declarations) (parse-body body) `(locally ,@declarations ,@(apply-at-macro-to-multiple-forms at-macro-form body)))) (((macrolet symbol-macrolet) bindings &body body) (multiple-value-bind (body declarations) (parse-body body) `(,(first form) ,bindings ,@declarations ,@(apply-at-macro-to-multiple-forms at-macro-form body)))) ((otherwise &rest _) (declare (ignore _)) form)))", "output": "(defmacro macroexpand-convention ((original-form) &body body)\n \"Executes BODY as like `progn' and return the result as the first\nvalue. As the second value, returns a boolean whether the result is\nnot same with ORIGINAL-FORM or not.\nThis macro is designed to follow the `macroexpand' convention.\"\n `(multiple-value-bind (result expanded-p)\n (progn ,@body)\n (values result\n (or expanded-p\n (not (eq result ,original-form))))))", "macroexpand": "(multiple-value-bind (result expanded-p) (progn (destructuring-case form ((progn &body body) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (apply-at-macro-to-multiple-forms at-macro-form body) :kind 2)))) ((eval-when situations &body body) (sb-int:quasiquote (eval-when #S(sb-impl::comma :expr situations :kind 0) #S(sb-impl::comma :expr (apply-at-macro-to-multiple-forms at-macro-form body) :kind 2)))) ((locally &body body) (multiple-value-bind (body declarations) (parse-body body) (sb-int:quasiquote (locally #S(sb-impl::comma :expr declarations :kind 2) #S(sb-impl::comma :expr (apply-at-macro-to-multiple-forms at-macro-form body) :kind 2))))) (((macrolet symbol-macrolet) bindings &body body) (multiple-value-bind (body declarations) (parse-body body) (sb-int:quasiquote (#S(sb-impl::comma :expr (first form) :kind 0) #S(sb-impl::comma :expr bindings :kind 0) #S(sb-impl::comma :expr declarations :kind 2) #S(sb-impl::comma :expr (apply-at-macro-to-multiple-forms at-macro-form body) :kind 2))))) ((otherwise &rest _) (declare (ignore _)) form))) (values result (or expanded-p (not (eq result form)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(builder (:session :store (make-redis-store :namespace *namespace* :connection *connection*)) (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session))))))))\n\nProblem: Macro call that should be transformed by builder", "input": "(builder (:session :store (make-redis-store :namespace *namespace* :connection *connection*)) (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session))))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app240) (funcall (find-middleware :session) #:app240 :store (make-redis-store :namespace *namespace* :connection *connection*))))) :initial-value (to-app (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (#S(sb-impl::comma :expr (format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defmethod* 'some-name)\n\nProblem: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* 'some-name)", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(let* ((#:some-name131 (ensure-generic*-function ''some-name))\n (temp-method (defmethod #:some-name130))\n (actual-gf\n (ensure-generic*-function ''some-name :lambda-list\n (sb-mop:generic-function-lambda-list\n (symbol-function '#:some-name130))\n :special-variables 'nil))\n (actual-method\n (add-method* #:some-name131\n (make-instance 'method* :special-variables (list)\n :qualifiers 'nil :specializers\n (sb-mop:method-specializers temp-method)\n :lambda-list\n (sb-mop:method-lambda-list temp-method)\n :documentation\n (documentation temp-method t) :function\n (sb-mop:method-function temp-method)))))\n (declare (ignorable #:some-name131)\n (ignore actual-gf))\n (setf (documentation actual-method t) (documentation temp-method t))\n actual-method)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(var 'some-name)\n\nProblem: Macro call that should be transformed by VAR", "input": "(var 'some-name)", "output": "(defmacro VAR ...)", "macroexpand": "(defparameter 'some-name nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(continue-whopper nil (progn))\n\nIssue: Macro call that should be transformed by CONTINUE-WHOPPER", "input": "(continue-whopper nil (progn))", "output": "(defmacro CONTINUE-WHOPPER ...)", "macroexpand": "(call-next-method-fn self class-env inst-env mcs%caller mcs%next-methods\n (list nil (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n;; eval loses lexical environment - can't access surrounding bindings\n(let ((x 1))\n (eval '(+ 1 x))) ;; Error: X is unbound!\n\n;; Need: way to tunnel lexical variables into eval\n\nWhat needs to change: eval cannot access lexical environment \u2014 want a 'tunnel' that bridges lexical scope into eval's dynamic world", "input": ";; eval loses lexical environment - can't access surrounding bindings\n(let ((x 1))\n (eval '(+ 1 x))) ;; Error: X is unbound!\n\n;; Need: way to tunnel lexical variables into eval", "output": "(defvar pandoric-eval-tunnel)\n\n(defmacro pandoric-eval (vars expr)\n `(let ((pandoric-eval-tunnel\n (plambda () ,vars t)))\n (eval `(with-pandoric\n ,',vars pandoric-eval-tunnel\n ,,expr))))", "macroexpand": ";; (let ((x 1))\n;; (pandoric-eval (x)\n;; '(+ 1 x)))\n;; => 2\n;;\n;; (let ((x 1))\n;; (pandoric-eval (x)\n;; '(incf x))\n;; x)\n;; => 2 ;; modifications persist!\n;;\n;; Builds a plambda capturing x, then eval-with-pandoric\n;; reconstructs x as symbol-macrolet inside eval", "category": "scope", "technique": "dlambda,symbol-macrolet", "complexity": "advanced", "quality_score": 0.9824999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(without-c-dependency (tv))\n\nProblem: Macro call that should be transformed by without-c-dependency", "input": "(without-c-dependency (tv))", "output": "(defmacro without-c-dependency (&body body)\n ` (let (*depender*)\n ,@body))", "macroexpand": "(let (*depender*) (tv))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Generate a defmacro form that transforms code like this:\n(js nil nil)\n\nPattern to recognize: Macro call that should be transformed by JS", "input": "(js nil nil)", "output": "(defmacro JS ...)", "macroexpand": "(ps\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(ematch0 args (nil nil) ((list* '&optional rest) (list* '&optional (process-optional-args rest))) ((list* '&key rest) (list* '&key (process-keyword-args rest))) ((list* '&rest rest) (list* '&rest (process-rest-args rest))) ((list* '&aux rest) args) ((list* thing rest) (list* thing (process-lambda-args rest))))\n\nPattern to recognize: Macro call that should be transformed by ematch0", "input": "(ematch0 args (nil nil) ((list* '&optional rest) (list* '&optional (process-optional-args rest))) ((list* '&key rest) (list* '&key (process-keyword-args rest))) ((list* '&rest rest) (list* '&rest (process-rest-args rest))) ((list* '&aux rest) args) ((list* thing rest) (list* thing (process-lambda-args rest))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 args (nil nil) ((list* (quote &optional) rest) (list* (quote &optional) (process-optional-args rest))) ((list* (quote &key) rest) (list* (quote &key) (process-keyword-args rest))) ((list* (quote &rest) rest) (list* (quote &rest) (process-rest-args rest))) ((list* (quote &aux) rest) args) ((list* thing rest) (list* thing (process-lambda-args rest))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-special-initargs 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-SPECIAL-INITARGS", "input": "(with-special-initargs 'some-name)", "output": "(defmacro WITH-SPECIAL-INITARGS ...)", "macroexpand": "(funcall-with-special-initargs (list (list . quote) (list . some-name))\n (lambda ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defproto nil (progn))\n\nIssue: Macro call that should be transformed by DEFPROTO", "input": "(defproto nil (progn))", "output": "(defmacro DEFPROTO ...)", "macroexpand": "(progn\n (declaim (special nil))\n (eval-when (:compile-toplevel))\n (setf (symbol-value 'nil)\n (ensure-object (when (boundp 'nil) (symbol-value 'nil)) (list progn)\n :properties (list) :nickname 'nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (eql (top-sign) 'skip-first-list-init) (pop-sign))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (eql (top-sign) 'skip-first-list-init) (pop-sign))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql (top-sign) (quote skip-first-list-init)) (pop-sign))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-active-layers 'some-name)\n\nPattern to recognize: Macro call that should be transformed by WITH-ACTIVE-LAYERS", "input": "(with-active-layers 'some-name)", "output": "(defmacro WITH-ACTIVE-LAYERS ...)", "macroexpand": "(dynamic-wind\n :proceed\n #:proceed182\n (%with-active-layers 'some-name\n (#:proceed182)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-definition-resolver symbol-macro (designator) (sb-int:info :variable :macro-expansion designator))\n\nWhat needs to change: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver symbol-macro (designator) (sb-int:info :variable :macro-expansion designator))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver symbol-macro (symbol-macro #:package146) (when (ignore-errors (let ((designator symbol-macro)) (sb-int:info :variable :macro-expansion designator))) (list (make-instance (quote symbol-macro) :designator symbol-macro :package #:package146))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(deferror \"42704\" unrecognized-configuration-parameter data-exception)\n\nWhat needs to change: Macro call that should be transformed by deferror", "input": "(deferror \"42704\" unrecognized-configuration-parameter data-exception)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition unrecognized-configuration-parameter (data-exception) nil) (setf (gethash \"42704\" *error-table*) (quote unrecognized-configuration-parameter)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(answer foo 23)\n\nWrite a macro that addresses: Macro call that should be transformed by answer", "input": "(answer foo 23)", "output": "(defmacro answer (call &body forms)\n (let ((name (if (listp call) (car call) call))\n (sym (gensym)))\n `(if-called\n ',name\n (let ((,sym (fdefinition ',name)))\n (declare (ignorable ,sym))\n (let ((times 0))\n (lambda (&rest args)\n (declare (ignorable args))\n ,(let ((cases\n `(case (prog1 times (incf times))\n ,.(loop\n for i from 0\n for (form . rest) on forms\n collect `(,(if rest i T) ,form)))))\n (if (listp call)\n `(trivia:match args\n ((list . ,(cdr call)) ,cases)\n (_ (unhandled)))\n cases))))))))", "macroexpand": "(if-called (quote foo) (let ((#:g159 (fdefinition (quote foo)))) (declare (ignorable #:g159)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (case (prog1 times (incf times)) (t 23))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(dreletf nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DRELETF", "input": "(dreletf nil\n nil)", "output": "(defmacro DRELETF ...)", "macroexpand": "(let ((#:symbol-store232\n (with-symbol-access\n (list))))\n (special-symbol-reprogv #:symbol-store232\n (list)\n (locally (declare (special)) nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:like infix-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:like infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (like-op (:include infix-op (name \"LIKE\")) (:constructor make-like-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(make-simple-collector-to-place 'some-name)\n\nProblem: Macro call that should be transformed by MAKE-SIMPLE-COLLECTOR-TO-PLACE", "input": "(make-simple-collector-to-place 'some-name)", "output": "(defmacro MAKE-SIMPLE-COLLECTOR-TO-PLACE ...)", "macroexpand": "(progn\n (setf 'some-name (alexandria:ensure-list 'some-name))\n (let* ((#:tail124 (last 'some-name)))\n (lambda (&rest values)\n (collect-at-end 'some-name #:tail124 values)\n 'some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(any-of nil\n (progn))\n\nIssue: Macro call that should be transformed by ANY-OF", "input": "(any-of nil\n (progn))", "output": "(defmacro ANY-OF ...)", "macroexpand": "(lc (nil (progn)) thereis)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'init-accumulator :array-member #'accumulator-add :end-of-array #'accumulator-get-sequence :array-type 'list :beginning-of-object #'init-accumulator :object-key #'accumulator-add-key :object-value #'accumulator-add-value :end-of-object #'accumulator-get :beginning-of-string #'init-string-stream-accumulator :string-char #'string-stream-accumulator-add :end-of-string #'string-stream-accumulator-get :aggregate-scope (union *aggregate-scope-variables* '(*accumulator* *accumulator-last*)) :internal-decoder #'decode-json)\n\nWhat needs to change: Macro call that should be transformed by set-custom-vars", "input": "(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'init-accumulator :array-member #'accumulator-add :end-of-array #'accumulator-get-sequence :array-type 'list :beginning-of-object #'init-accumulator :object-key #'accumulator-add-key :object-value #'accumulator-add-value :end-of-object #'accumulator-get :beginning-of-string #'init-string-stream-accumulator :string-char #'string-stream-accumulator-add :end-of-string #'string-stream-accumulator-get :aggregate-scope (union *aggregate-scope-variables* '(*accumulator* *accumulator-last*)) :internal-decoder #'decode-json)", "output": "(defmacro set-custom-vars (&rest key-args)\n `(setq\n ,@(loop for (supplied-key value) on key-args by #'cddr\n append (loop for (var . var-key) in *custom-vars*\n thereis (if (eql var-key supplied-key)\n (list var value))))))", "macroexpand": "(setq *integer-handler* (function parse-number) *real-handler* (function parse-number) *boolean-handler* (function json-boolean-to-lisp) *beginning-of-array-handler* (function init-accumulator) *array-member-handler* (function accumulator-add) *end-of-array-handler* (function accumulator-get-sequence) *json-array-type* (quote list) *beginning-of-object-handler* (function init-accumulator) *object-key-handler* (function accumulator-add-key) *object-value-handler* (function accumulator-add-value) *end-of-object-handler* (function accumulator-get) *beginning-of-string-handler* (function init-string-stream-accumulator) *string-char-handler* (function string-stream-accumulator-add) *end-of-string-handler* (function string-stream-accumulator-get) *aggregate-scope-variables* (union *aggregate-scope-variables* (quote (*accumulator* *accumulator-last*))) *internal-decoder* (function decode-json))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(dynamic-let* nil)\n\nIssue: Macro call that should be transformed by DYNAMIC-LET*", "input": "(dynamic-let* nil)", "output": "(defmacro DYNAMIC-LET* ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(parse-conjunctive-clauses client instance t :var (parse-d-spec client :type-spec *placeholder-result*))\n\nProblem: Macro call that should be transformed by parse-conjunctive-clauses", "input": "(parse-conjunctive-clauses client instance t :var (parse-d-spec client :type-spec *placeholder-result*))", "output": "(defmacro parse-conjunctive-clauses (client region read-name-p &rest args)\n (with-unique-names (clauses next)\n `(prog (,clauses)\n ,next\n (push (do-parse-clause ,client ,region *index* ,read-name-p ,@args)\n ,clauses)\n (when (maybe-parse-token :keywords '(:and))\n (go ,next))\n (return (nreverse ,clauses)))))", "macroexpand": "(prog (#:clauses124) #:next125 (push (do-parse-clause client instance *index* t :var (parse-d-spec client :type-spec *placeholder-result*)) #:clauses124) (when (maybe-parse-token :keywords (quote (:and))) (go #:next125)) (return (nreverse #:clauses124)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-type-dispatch nil\n (progn))\n\nProblem: Macro call that should be transformed by DEFINE-TYPE-DISPATCH", "input": "(define-type-dispatch nil\n (progn))", "output": "(defmacro DEFINE-TYPE-DISPATCH ...)", "macroexpand": "(progn\n (defun nil (progn)\n (declare (optimize speed (debug 1) (safety 1) (compilation-speed 0)))\n (etypecase progn))\n (sb-c:defknown nil\n ((or))\n (or)\n (sb-c:any)\n :overwrite-fndb-silently\n t))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(quasiquote-unexpand-1 'unquote-splicing el)\n\nProblem: Macro call that should be transformed by quasiquote", "input": "(quasiquote-unexpand-1 'unquote-splicing el)", "output": "(defmacro quasiquote (x) (quasiquote-expand x))", "macroexpand": "(quasiquote-unexpand-1 (quote unquote-splicing) el)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7925} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(aecase (car x) (:y :no) (:x (list it :yes)))\n\nProblem: Macro call that should be transformed by aecase", "input": "(aecase (car x) (:y :no) (:x (list it :yes)))", "output": "(defmacro aecase (keyform &body cases)\n \"Like ECASE, except binds the result of the keyform to IT (via LET) for the\nscope of the cases.\"\n `(anaphoric ecase ,keyform ,@cases))", "macroexpand": "(anaphoric ecase (car x) (:y :no) (:x (list it :yes)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(collect-and 'some-name)\n\nIssue: Macro call that should be transformed by COLLECT-AND", "input": "(collect-and 'some-name)", "output": "(defmacro COLLECT-AND ...)", "macroexpand": "(common-lisp:let* ((#:generator-501 (generator 'some-name))\n #:bools-497\n (#:bool-498 t))\n (declare (type generator #:generator-501))\n (tagbody\n #:ll-502\n (setq #:bools-497 (next-in #:generator-501 (go end)))\n (if (null (setq #:bool-498 #:bools-497))\n (go end))\n (go #:ll-502)\n end)\n #:bool-498)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(cache-dir #p\"/tmp/clache-test/\")\n\nWhat needs to change: Macro call that should be transformed by cache", "input": "(cache-dir #p\"/tmp/clache-test/\")", "output": "(defmacro cache ((keyargs &key store expire) function-definition-form)\n \"Annotation for caching functions with their arguments. This should\nbe used with CL-ANNOT. KEYARGS is a form or a list of form for making\na cache key. To make cache keys distinct as to the function, you may\nadd a keyword or a symbol into KEYARGS. See also WITH-CACHE.\n\nExample:\n\n @cache ((:f x y z))\n (defun f (x y z)\n ...)\n \n ;; Remove a cache of F\n (remcache '(:f 1 2 3))\"\n (replace-function-body\n (lambda (name lambda-list body)\n @ignore name\n @ignore lambda-list\n (let ((key (if (listp keyargs)\n `(list ,@keyargs)\n keyargs)))\n `(with-cache (,key :store ,store :expire ,expire)\n ,@body)))\n function-definition-form))", "macroexpand": "(cache-dir #P\"/tmp/clache-test/\")", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ps-html nil nil)\n\nProblem: Macro call that should be transformed by PS-HTML", "input": "(ps-html nil nil)", "output": "(defmacro PS-HTML ...)", "macroexpand": "(stringify nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-syntax-error* error-pos \"Comment group not closed.\")\n\nIssue: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* error-pos \"Comment group not closed.\")", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos error-pos :format-control \"Comment group not closed.\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dynamic-wind\n nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DYNAMIC-WIND", "input": "(dynamic-wind\n nil\n :key\n nil)", "output": "(defmacro DYNAMIC-WIND ...)", "macroexpand": "(flet ((#:dynamic-wind-thunk225 (#:proceed-thunk226)\n (macrolet ((proceed (&body #:proceed-body227)\n `(if ,'#:proceed-thunk226\n (funcall (the function ,'#:proceed-thunk226))\n (progn ,@#:proceed-body227))))\n nil\n :key\n nil)))\n (declare (inline #:dynamic-wind-thunk225))\n (let ((*dynamic-wind-stack*\n (cons #'#:dynamic-wind-thunk225 *dynamic-wind-stack*)))\n (#:dynamic-wind-thunk225 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-path-instruction-pair move-to \"M\" (x y))\n\nPattern to recognize: Macro call that should be transformed by define-path-instruction-pair", "input": "(define-path-instruction-pair move-to \"M\" (x y))", "output": "(defmacro define-path-instruction-pair (name instruction (&rest args))\n (let ((draw-relative (intern (concatenate 'string (string name) \"-R\"))))\n `(progn\n (defun ,name (,@args)\n (format-instruction ,instruction ,@args))\n (defun ,draw-relative (,@args)\n (format-instruction ,(string-downcase instruction) ,@args)))))", "macroexpand": "(progn (defun move-to (x y) (format-instruction \"M\" x y)) (defun move-to-r (x y) (format-instruction \"m\" x y)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-port-value-slot nil nil)\n\nProblem: Macro call that should be transformed by DEFINE-PORT-VALUE-SLOT", "input": "(define-port-value-slot nil nil)", "output": "(defmacro DEFINE-PORT-VALUE-SLOT ...)", "macroexpand": "(progn\n (defmethod port-value ((nil nil)) (slot-value nil nil))\n (defmethod (setf port-value) (value (nil nil))\n (setf (slot-value nil nil) value))\n (defmethod port-value-boundp ((nil nil)) (slot-boundp nil 'nil))\n (defmethod port-value-makunbound ((nil nil)) (slot-makunbound nil 'nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(defcategory-fn (my-category-keyword) '(or :debug :info))\n\nPattern to recognize: Macro call that should be transformed by defcategory", "input": "(defcategory-fn (my-category-keyword) '(or :debug :info))", "output": "(defmacro defcategory (category &optional expands-as set)\n `(defcategory-fn ',category ',expands-as ,set))", "macroexpand": "(defcategory-fn (my-category-keyword) (quote (or :debug :info)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (and (not (equal identifier name-string)) (find :hyphen *enabled-warnings*)) (warn \"Possible ambiguity through hyphen override of ~s\" check-name))\n\nProblem: Macro call that should be transformed by when", "input": "(when (and (not (equal identifier name-string)) (find :hyphen *enabled-warnings*)) (warn \"Possible ambiguity through hyphen override of ~s\" check-name))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (and (not (equal identifier name-string)) (find :hyphen *enabled-warnings*)) (warn \"Possible ambiguity through hyphen override of ~s\" check-name))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-error no-function-returns () (name return-set) \"Function '~a' did not specify any return types\" name)\n\nPattern to recognize: Macro call that should be transformed by define-error", "input": "(define-error no-function-returns () (name return-set) \"Function '~a' did not specify any return types\" name)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition no-function-returns (:error-type varjo-error :prefix \"Varjo\") (name return-set) \"Function '~a' did not specify any return types\" name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defexpander nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFEXPANDER", "input": "(defexpander nil)", "output": "(defmacro DEFEXPANDER ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (get 'nil +expander-prop+) (gensym #A((3) base-char . \"NIL\")))\n (defmethod (setf documentation)\n (#:docstring122 #:sym-obj123 (#:doc-type124 (eql 'nil)))\n (declare (ignore #:doc-type124))\n (setf (expander-info-docstring\n (get #:sym-obj123 (get 'nil +expander-prop+)))\n #:docstring122))\n (defmethod documentation (#:sym-obj123 (#:doc-type124 (eql 'nil)))\n (declare (ignore #:doc-type124))\n (expander-info-docstring (get #:sym-obj123 (get 'nil +expander-prop+))))\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defvar-compile-time *local?* nil \"This must be globally NIL.\")\n\nWrite a macro that addresses: Macro call that should be transformed by defvar-compile-time", "input": "(defvar-compile-time *local?* nil \"This must be globally NIL.\")", "output": "(defmacro defvar-compile-time (name &optional initial-value documentation)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,name ,initial-value ,documentation)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *local?* nil \"This must be globally NIL.\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(make-obsolete mustache-compile compile-template \"0.10.0\")\n\nPattern to recognize: Macro call that should be transformed by make-obsolete", "input": "(make-obsolete mustache-compile compile-template \"0.10.0\")", "output": "(defmacro make-obsolete (obsolete-name current-name when)\n `(defun ,obsolete-name (&rest args)\n ,(documentation current-name 'function)\n (warn 'deprecation-warning\n :name ',obsolete-name :replacement ',current-name :since ,when)\n (apply ',current-name args)))", "macroexpand": "(defun mustache-compile (&rest args) \"Return a compiled rendering function.\" (warn (quote deprecation-warning) :name (quote mustache-compile) :replacement (quote compile-template) :since \"0.10.0\") (apply (quote compile-template) args))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defguarantee add (&rest addends) \"result < 20\" (declare (ignore addends)) (< (results) 20))\n\nWhat needs to change: Macro call that should be transformed by defguarantee", "input": "(defguarantee add (&rest addends) \"result < 20\" (declare (ignore addends)) (< (results) 20))", "output": "(defmacro defguarantee (name (&rest lambda-list) &body body)\n \"Adds a postcondition to the NAMEd function. It can be either a generic or\n non-generic function. If it's the former, then use a specialized lambda list,\n otherwise use an ordinary lambda list. The docstring, if any, will be used in\n failure reports.\"\n #+qpq-postcondition-checks-disabled\n (declare (ignore name lambda-list body))\n #+qpq-postcondition-checks-disabled\n (values)\n #-qpq-postcondition-checks-disabled\n (multiple-value-bind (remaining-forms declarations doc-string)\n (parse-body body :documentation t)\n (declare (ignore declarations))\n (let* ((stripped-ll (strip-lambda-list lambda-list))\n (lambda-vars (remove-if (rcurry #'member\n '(&optional &rest\n &key &allow-other-keys &aux))\n stripped-ll))\n (method `(progn\n (ensure-contracted-function ',name ',stripped-ll)\n (defmethod ,name\n :guarantee\n ,(or doc-string\n (format nil \"~A\"\n (description<-remaining-forms\n remaining-forms)))\n ,lambda-list\n (declare (ignorable ,@lambda-vars))\n ,@body))))\n (if (every #'symbolp lambda-list)\n `(if (and (fboundp ',name)\n (not (typep (fdefinition ',name) 'generic-function)))\n (defcontract ,name :guarantee ,lambda-list\n (declare (ignorable ,@lambda-vars))\n ,@body)\n ,method)\n method))))", "macroexpand": "(if (and (fboundp (quote add)) (not (typep (fdefinition (quote add)) (quote generic-function)))) (defcontract add :guarantee (&rest addends) (declare (ignorable addends)) \"result < 20\" (declare (ignore addends)) (< (results) 20)) (progn (ensure-contracted-function (quote add) (quote (&rest addends))) (defmethod add :guarantee \"result < 20\" (&rest addends) (declare (ignorable addends)) \"result < 20\" (declare (ignore addends)) (< (results) 20))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-html-string (:tag :name \"x-y\" \"Hello\"))\n\nWhat needs to change: Macro call that should be transformed by with-html", "input": "(with-html-string (:tag :name \"x-y\" \"Hello\"))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:tag :name \"x-y\" \"Hello\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(lexpr-$send nil nil)\n\nPattern to recognize: Macro call that should be transformed by LEXPR-$SEND", "input": "(lexpr-$send nil nil)", "output": "(defmacro LEXPR-$SEND ...)", "macroexpand": "(apply #'send-message nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(fgatherlet nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by FGATHERLET", "input": "(fgatherlet nil\n :key\n nil)", "output": "(defmacro FGATHERLET ...)", "macroexpand": "(flet ()\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defjs reduce4(k vals) (return (ps:create :vals vals)))\n\nProblem: Macro call that should be transformed by defjs", "input": "(defjs reduce4(k vals) (return (ps:create :vals vals)))", "output": "(defmacro defjs (name args &body body)\n \"Define client side javascript. Works like defun; body is in lisp, with parenscript\n additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. \n macro creates a lisp function which sends the javascript function over to the mongo \n server to be evaluated. Result is processed and returned to the reader. \n This will execute 10 times on the server :\n (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))\"\n `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))\n (setf (gethash ',name *js-definitions*) js-body)\n (defun ,name ,args\n (get-element \"retval\" (car (docs (db.eval js-body ,@args)))))))", "macroexpand": "(let* ((js-body (parenscript:ps (lambda (k vals) (return (parenscript:create :vals vals)))))) (setf (gethash (quote reduce4) *js-definitions*) js-body) (defun reduce4 (k vals) (get-element \"retval\" (car (docs (db.eval js-body k vals))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (plusp a))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (plusp a))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:v127 a)) (if (plusp #:v127) (add-result (quote test-passed) :test-expr (quote (plusp a))) (process-failure (quote (plusp a)) \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\" (quote a) #:v127 (quote plusp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-neo4j-fun delete-relationship (relationship-id) :delete (:uri-spec (format nil \"relationship/~A\" relationship-id)) (:status-handlers (204 (values t body)) (404 (error 'relationship-not-found-error :uri uri))))\n\nPattern to recognize: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun delete-relationship (relationship-id) :delete (:uri-spec (format nil \"relationship/~A\" relationship-id)) (:status-handlers (204 (values t body)) (404 (error 'relationship-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun delete-relationship (&key relationship-id) (let ((uri (format nil \"relationship/~A\" relationship-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :delete uri json (list (list 204 (lambda (body uri json) (values t body))) (list 404 (lambda (body uri json) (error (quote relationship-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun nil :key nil)\n\nProblem: Macro call that should be transformed by DEFUN", "input": "(defun nil :key nil)", "output": "(defmacro DEFUN ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel) (sb-c:%compiler-defun 'nil t nil nil))\n (sb-impl::%defun 'nil\n (sb-int:named-lambda nil\n :key\n (block nil nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-let nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-LET", "input": "(dynamic-let nil\n nil)", "output": "(defmacro DYNAMIC-LET ...)", "macroexpand": "(let ()\n (dynamic-wind\n :proceed\n #:g193\n (let ()\n (declare (special))\n (#:g193 nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(funcall (dispatch-function (dispatch-for-qualifier ',qualifier)) (list ,@vanilla-lambda-list) (mapcar #'hook-name (specific-hooks-for-generic ',type-list ',generic-function ',qualifier))))\n\nProblem: Macro call that should be transformed by destructure-specialized-lambda-list", "input": "(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(funcall (dispatch-function (dispatch-for-qualifier ',qualifier)) (list ,@vanilla-lambda-list) (mapcar #'hook-name (specific-hooks-for-generic ',type-list ',generic-function ',qualifier))))", "output": "(defmacro destructure-specialized-lambda-list (descriptive-lambda-list-sym vanilla-lambda-list-sym type-list-sym specialized-lambda-list &body body)\n \"if specialized-lambda-list is ((a integer) b):\ndescriptive-lambda-list will be ((x integer) (x t))\ntype-list will be (integer t) and vanilla-lambda-list is (a b)\"\n (let ((item (gensym)))\n `(let* ((,descriptive-lambda-list-sym\n (loop :for ,item :in ,specialized-lambda-list\n :if (listp ,item)\n :collect ,item\n :else :collect (list ,item t)))\n (,vanilla-lambda-list-sym (mapcar #'first ,descriptive-lambda-list-sym))\n (,type-list-sym (mapcar #'second ,descriptive-lambda-list-sym)))\n (declare (ignorable ,descriptive-lambda-list-sym ,vanilla-lambda-list-sym ,type-list-sym))\n ,@body)))", "macroexpand": "(let* ((descriptive-lambda-list (loop :for #:g124 :in specialized-lambda-list :if (listp #:g124) :collect #:g124 :else :collect (list #:g124 t))) (vanilla-lambda-list (mapcar (function first) descriptive-lambda-list)) (type-list (mapcar (function second) descriptive-lambda-list))) (declare (ignorable descriptive-lambda-list vanilla-lambda-list type-list)) (sb-int:quasiquote (funcall (dispatch-function (dispatch-for-qualifier (quote #S(sb-impl::comma :expr qualifier :kind 0)))) (list #S(sb-impl::comma :expr vanilla-lambda-list :kind 2)) (mapcar (function hook-name) (specific-hooks-for-generic (quote #S(sb-impl::comma :expr type-list :kind 0)) (quote #S(sb-impl::comma :expr generic-function :kind 0)) (quote #S(sb-impl::comma :expr qualifier :kind 0)))))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-cached-reader-conditionals\n 'some-name)\n\nWhat needs to change: Macro call that should be transformed by WITH-CACHED-READER-CONDITIONALS", "input": "(with-cached-reader-conditionals\n 'some-name)", "output": "(defmacro WITH-CACHED-READER-CONDITIONALS ...)", "macroexpand": "(call-with-cached-reader-conditionals (lambda () 'some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(matrix-typecase 'some-name)\n\nWhat needs to change: Macro call that should be transformed by MATRIX-TYPECASE", "input": "(matrix-typecase 'some-name)", "output": "(defmacro MATRIX-TYPECASE ...)", "macroexpand": "(let ((#:g245 quote))\n (typecase #:g245))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(inext-or-error 'some-name)\n\nProblem: Macro call that should be transformed by INEXT-OR-ERROR", "input": "(inext-or-error 'some-name)", "output": "(defmacro INEXT-OR-ERROR ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro 'some-name) nil))))\n (if (not vals)\n (error 'stop-iteration)\n (values (car vals) t)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-direct-binding = (var form &key then) (let* ((undef '#.(gensym \"UNDEF\")) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect `(,var ',undef)))) (if then (values `(let ,vars) `(if (eq ,(caar vars) ,undef) (update ,var ,form) (update ,var ,then))) (values `(let ,vars) `(update ,var ,form)))))\n\nIssue: Macro call that should be transformed by define-direct-binding", "input": "(define-direct-binding = (var form &key then) (let* ((undef '#.(gensym \"UNDEF\")) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect `(,var ',undef)))) (if then (values `(let ,vars) `(if (eq ,(caar vars) ,undef) (update ,var ,form) (update ,var ,then))) (values `(let ,vars) `(update ,var ,form)))))", "output": "(defmacro define-direct-binding (name args &body body)\n (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym \"ENVIRONMENT\"))))\n `(progn (setf (binding ',name)\n (lambda ,(lambda-fiddle:remove-environment-part args)\n (let ((,env *environment*))\n (declare (ignorable ,env))\n ,@body)))\n ',name)))", "macroexpand": "(progn (setf (binding (quote =)) (lambda (var form &key then) (let ((#:environment130 *environment*)) (declare (ignorable #:environment130)) (let* ((undef (quote #:undef129)) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (sb-int:quasiquote (#S(sb-impl::comma :expr var :kind 0) (quote #S(sb-impl::comma :expr undef :kind 0))))))) (if then (values (sb-int:quasiquote (let #S(sb-impl::comma :expr vars :kind 0))) (sb-int:quasiquote (if (eq #S(sb-impl::comma :expr (caar vars) :kind 0) #S(sb-impl::comma :expr undef :kind 0)) (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr form :kind 0)) (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr then :kind 0))))) (values (sb-int:quasiquote (let #S(sb-impl::comma :expr vars :kind 0))) (sb-int:quasiquote (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr form :kind 0))))))))) (quote =))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defreply nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFREPLY", "input": "(defreply nil\n (progn))", "output": "(defmacro DEFREPLY ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel)\n (unless (fboundp 'nil)\n (warn 'automatic-message-creation :message-name 'nil)\n (ensure-message 'nil :lambda-list '(progn))))\n (ensure-reply 'nil :qualifiers 'nil :lambda-list '(progn) :participants\n (list =t=) :documentation nil :function\n (lambda (#:args140 #:next-replies141 &rest #:more-args143)\n (declare\n (ignorable #:args140 #:next-replies141 #:more-args143))\n (flet ((next-reply-p ()\n (not (null #:next-replies141)))\n (call-next-reply (&rest args)\n (if (null #:next-replies141)\n (apply 'no-next-reply\n (getf #:more-args143 :message)\n (getf #:more-args143 :reply)\n (or args #:args140))\n (apply (reply-function (car #:next-replies141))\n (or args #:args140)\n (cdr #:next-replies141) #:more-args143))))\n (declare\n (ignorable (function next-reply-p)\n (function call-next-reply)))\n (flet ((#:reply-function142 (progn)\n (declare (ignorable))\n (block nil)))\n (declare (inline #:reply-function142))\n (apply #'#:reply-function142 #:args140))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym mult :mult)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym mult :mult)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote mult) (quote synonym)) (quote :mult)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(answer (foo 2) 3)\n\nWhat needs to change: Macro call that should be transformed by answer", "input": "(answer (foo 2) 3)", "output": "(defmacro answer (call &body forms)\n (let ((name (if (listp call) (car call) call))\n (sym (gensym)))\n `(if-called\n ',name\n (let ((,sym (fdefinition ',name)))\n (declare (ignorable ,sym))\n (let ((times 0))\n (lambda (&rest args)\n (declare (ignorable args))\n ,(let ((cases\n `(case (prog1 times (incf times))\n ,.(loop\n for i from 0\n for (form . rest) on forms\n collect `(,(if rest i T) ,form)))))\n (if (listp call)\n `(trivia:match args\n ((list . ,(cdr call)) ,cases)\n (_ (unhandled)))\n cases))))))))", "macroexpand": "(if-called (quote foo) (let ((#:g161 (fdefinition (quote foo)))) (declare (ignorable #:g161)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (trivia.level2:match args ((list 2) (case (prog1 times (incf times)) (t 3))) (_ (unhandled)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"40\" transaction-rollback)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"40\" transaction-rollback)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition transaction-rollback (database-error) nil) (setf (gethash \"40\" *error-table*) (quote transaction-rollback)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:p :class :foo))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:p :class :foo))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:p :class :foo)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lambda (quote some-name))\n\nIssue: Macro call that should be transformed by LAMBDA", "input": "(lambda (quote some-name))", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda (quote some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(the-part nil (progn))\n\nPattern to recognize: Macro call that should be transformed by THE-PART", "input": "(the-part nil (progn))", "output": "(defmacro THE-PART ...)", "macroexpand": "(send part nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-connection (let ((user (retrieve-one :user :by :name := \"nitro_idiot\" :as 'user))) (is-type (user-created-at user) 'local-time:timestamp) (is (user-updated-at user) nil) (is (user-status user) :normal) (is (length (user-tweets user)) 2) (is (tweet-id (car (user-tweets user :limit 1))) 2) (is (tweet-id (car (user-tweets user :limit 1 :offset 1))) 1) (is (length (user-tweets user :limit 2)) 2) (ok (every (lambda (tweet) (typep tweet 'tweet)) (user-tweets user))) (execute (insert-into :tweet (set= :id 3 :user_id 1 :body \"Looks good.\" :created_at (princ-to-string *now*)))) (is (length (user-tweets user)) 2 \"Result cached\") (let ((test-val '#:test-val)) (setf (user-tweets user) test-val) (is (user-tweets user) test-val :test #'eq \"Set cache value\")) (datafly.cache:clear-object-caches user) (is (length (user-tweets user)) 3)))\n\nPattern to recognize: Macro call that should be transformed by with-connection", "input": "(with-connection (let ((user (retrieve-one :user :by :name := \"nitro_idiot\" :as 'user))) (is-type (user-created-at user) 'local-time:timestamp) (is (user-updated-at user) nil) (is (user-status user) :normal) (is (length (user-tweets user)) 2) (is (tweet-id (car (user-tweets user :limit 1))) 2) (is (tweet-id (car (user-tweets user :limit 1 :offset 1))) 1) (is (length (user-tweets user :limit 2)) 2) (ok (every (lambda (tweet) (typep tweet 'tweet)) (user-tweets user))) (execute (insert-into :tweet (set= :id 3 :user_id 1 :body \"Looks good.\" :created_at (princ-to-string *now*)))) (is (length (user-tweets user)) 2 \"Result cached\") (let ((test-val '#:test-val)) (setf (user-tweets user) test-val) (is (user-tweets user) test-val :test #'eq \"Set cache value\")) (datafly.cache:clear-object-caches user) (is (length (user-tweets user)) 3)))", "output": "(defmacro with-connection (&body body)\n `(let ((*connection* (connect-cached :sqlite3 :database-name *db-path*)))\n ,@body))", "macroexpand": "(let ((let (connect ((user (retrieve-one :user :by :name := \"nitro_idiot\" :as (quote user)))) (is-type (user-created-at user) (quote local-time:timestamp)) (is (user-updated-at user) nil) (is (user-status user) :normal) (is (length (user-tweets user)) 2) (is (tweet-id (car (user-tweets user :limit 1))) 2) (is (tweet-id (car (user-tweets user :limit 1 :offset 1))) 1) (is (length (user-tweets user :limit 2)) 2) (ok (every (lambda (tweet) (typep tweet (quote tweet))) (user-tweets user))) (execute (insert-into :tweet (set= :id 3 :user_id 1 :body \"Looks good.\" :created_at (princ-to-string *now*)))) (is (length (user-tweets user)) 2 \"Result cached\") (let ((test-val (quote #:test-val))) (setf (user-tweets user) test-val) (is (user-tweets user) test-val :test (function eq) \"Set cache value\")) (datafly.cache:clear-object-caches user) (is (length (user-tweets user)) 3)))) (unwind-protect (progn) (disconnect let)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (symbolp x) (equal (symbol-name x) (string-upcase symbol)))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (symbolp x) (equal (symbol-name x) (string-upcase symbol)))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (symbolp x) (equal (symbol-name x) (string-upcase symbol)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when name `(make-node ,name))\n\nIssue: Macro call that should be transformed by when", "input": "(when name `(make-node ,name))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if name (sb-int:quasiquote (make-node #S(sb-impl::comma :expr name :kind 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(letrec-syntax common-lisp:nil :key common-lisp:nil)\n\nWhat needs to change: Macro call that should be transformed by LETREC-SYNTAX", "input": "(letrec-syntax common-lisp:nil :key common-lisp:nil)", "output": "(defmacro LETREC-SYNTAX ...)", "macroexpand": "(common-lisp:macrolet ()\n :key\n common-lisp:nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-bug with-fresh-env-scope-missing-env () () \"with-fresh-env-scope expects a code object & an environment to be returned from it's body. However there was no environment returned.\")\n\nIssue: Macro call that should be transformed by define-bug", "input": "(define-bug with-fresh-env-scope-missing-env () () \"with-fresh-env-scope expects a code object & an environment to be returned from it's body. However there was no environment returned.\")", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition with-fresh-env-scope-missing-env (:error-type varjo-error :prefix \"Varjo Bug\") nil \"with-fresh-env-scope expects a code object & an environment to be returned from it's body. However there was no environment returned.\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym generating :generate)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym generating :generate)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote generating) (quote synonym)) (quote :generate)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ematch0 args (nil nil) ((list* '&aux rest) args) ((list* (list name) rest) (list* (list name ''_) (process-keyword-args rest))) ((list* (list name default) rest) (list* (list name default) (process-keyword-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-keyword-args rest))) ((list* name rest) (list* (list name ''_) (process-keyword-args rest))))\n\nWrite a macro that addresses: Macro call that should be transformed by ematch0", "input": "(ematch0 args (nil nil) ((list* '&aux rest) args) ((list* (list name) rest) (list* (list name ''_) (process-keyword-args rest))) ((list* (list name default) rest) (list* (list name default) (process-keyword-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-keyword-args rest))) ((list* name rest) (list* (list name ''_) (process-keyword-args rest))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 args (nil nil) ((list* (quote &aux) rest) args) ((list* (list name) rest) (list* (list name (quote (quote _))) (process-keyword-args rest))) ((list* (list name default) rest) (list* (list name default) (process-keyword-args rest))) ((list* (list name default pred) rest) (list* (list name default pred) (process-keyword-args rest))) ((list* name rest) (list* (list name (quote (quote _))) (process-keyword-args rest))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-wcs-math-error-handling (ret (cos x)) (check-wcs-math-result))\n\nPattern to recognize: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (cos x)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g209 x) (#:g210 nil) (#:g211 (list #:g209))) (declare (ignorable #:g210) (type list #:g211) (dynamic-extent #:g211)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote cos) #:g211) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g211)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dlet nil)\n\nWhat needs to change: Macro call that should be transformed by DLET", "input": "(dlet nil)", "output": "(defmacro DLET ...)", "macroexpand": "(dynamic-let nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defmethod nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by DEFMETHOD", "input": "(defmethod nil\n :key\n nil)", "output": "(defmacro DEFMETHOD ...)", "macroexpand": "(common-lisp:defmethod nil :key ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(xor nil nil 1 nil)\n\nWhat needs to change: Macro call that should be transformed by xor", "input": "(xor nil nil 1 nil)", "output": "(defmacro xor (&rest datums)\n \"Evaluates its arguments one at a time, from left to right. If more than one\nargument evaluates to a true value no further DATUMS are evaluated, and NIL is\nreturned as both primary and secondary value. If exactly one argument\nevaluates to true, its value is returned as the primary value after all the\narguments have been evaluated, and T is returned as the secondary value. If no\narguments evaluate to true NIL is returned as primary, and T as secondary\nvalue.\"\n (with-gensyms (xor tmp true)\n `(let (,tmp ,true)\n (declare (ignorable ,tmp))\n (block ,xor\n ,@(mapcar (lambda (datum)\n `(if (setf ,tmp ,datum)\n (if ,true\n (return-from ,xor (values nil nil))\n (setf ,true ,tmp))))\n datums)\n (return-from ,xor (values ,true t))))))", "macroexpand": "(let (#:tmp141 #:true142) (declare (ignorable #:tmp141)) (block #:xor140 (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 1) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (if (setf #:tmp141 nil) (if #:true142 (return-from #:xor140 (values nil nil)) (setf #:true142 #:tmp141))) (return-from #:xor140 (values #:true142 t))))", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.835} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defstruct*\n 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DEFSTRUCT*", "input": "(defstruct*\n 'some-name)", "output": "(defmacro DEFSTRUCT* ...)", "macroexpand": "(progn\n (defclass quote nil nil)\n (defun make-quote (&rest structure-ext.as-class::args)\n (apply #'make-instance 'quote structure-ext.as-class::args))\n (defgeneric copy-quote\n (structure-ext.as-class::arg))\n (defmethod copy-quote ((structure-ext.as-class::arg quote))\n (let ((structure-ext.as-class::obj\n (make-instance (class-of structure-ext.as-class::arg))))\n (dolist\n (structure-ext.as-class::slot\n (structure-ext.as-class::slots<=obj structure-ext.as-class::arg))\n (if (slot-boundp structure-ext.as-class::arg\n structure-ext.as-class::slot)\n (setf (slot-value structure-ext.as-class::obj\n structure-ext.as-class::slot)\n (slot-value structure-ext.as-class::arg\n structure-ext.as-class::slot))\n (slot-makunbound structure-ext.as-class::obj\n structure-ext.as-class::slot)))\n structure-ext.as-class::obj))\n (defun quote-p (structure-ext.as-class::arg)\n (typep structure-ext.as-class::arg 'quote))\n 'quote)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclause summing-to (vars &optional result-processor) \"Specifies an accumulation strategy with 0 as the default value and + as the accumulator function.\" `(accumulating-to ,vars :initially 0 :by #'+ :finally ,result-processor))\n\nProblem: Macro call that should be transformed by defclause", "input": "(defclause summing-to (vars &optional result-processor) \"Specifies an accumulation strategy with 0 as the default value and + as the accumulator function.\" `(accumulating-to ,vars :initially 0 :by #'+ :finally ,result-processor))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro summing-to (vars &optional result-processor) \"Specifies an accumulation strategy with 0 as the default value and + as the accumulator function.\" (sb-int:quasiquote (accumulating-to #S(sb-impl::comma :expr vars :kind 0) :initially 0 :by (function +) :finally #S(sb-impl::comma :expr result-processor :kind 0)))) (pushnew (quote summing-to) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(fgathering nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by FGATHERING", "input": "(fgathering nil\n (progn))", "output": "(defmacro FGATHERING ...)", "macroexpand": "(flet ()\n (progn)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defcell a 0)\n\nWrite a macro that addresses: Macro call that should be transformed by defcell", "input": "(defcell a 0)", "output": "(defmacro defcell (name value-form &environment env)\n \"Define a global cell identified by NAME.\n\nThis macro defines a cell identified by NAME with its value computed\nby VALUE-FORM. The value of the cell can be referenced by the symbol\nNAME following the DEFCELL form.\n\nIf VALUE-FORM is a constant, by CONSTANTP, a mutable cell is defined\nwhich can have its value set directly using SETF or SETQ on the symbol\nNAME.\n\nIf VALUE-FORM is not a constant a computed cell is created. A computed\ncell may reference one or more argument cells in VALUE-FORM or a\nfunction called during the evaluation of VALUE-FORM. When the values\nof any of the argument cells change, the value of the computed cell is\nrecomputed by evaluating VALUE-FORM again. The referenced argument\ncells are determined automatically when the VALUE-FORM is evaluated.\n\nThis macro creates a cell definition that is visible globally to all\nforms unless it is lexically shadowed by a definition with the same\nNAME using CELL-LET. Note that despite being visible globally, the\ncell definition is still lexically scoped and not dynamically scoped\nlike global variables defined with DEFVAR or DEFPARAMETER.\"\n\n (if (constantp value-form env)\n `(define-mutable-cell% ,name ,value-form)\n `(define-computed-cell% ,name ,value-form)))", "macroexpand": "(define-mutable-cell% a 0)", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(or 'some-name)\n\nWhat needs to change: Macro call that should be transformed by OR", "input": "(or 'some-name)", "output": "(defmacro OR ...)", "macroexpand": "(the t 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-package (package) (let ((nicks (package-nicknames package))) (unless (member nickname nicks :test #'string=) (rename-package package (package-name package) (cons nickname nicks)))))\n\nWhat needs to change: Macro call that should be transformed by with-package", "input": "(with-package (package) (let ((nicks (package-nicknames package))) (unless (member nickname nicks :test #'string=) (rename-package package (package-name package) (cons nickname nicks)))))", "output": "(defmacro with-package ((var &optional (package var)) &body body)\n `(let ((,var (ensure-package ,package)))\n ,@body))", "macroexpand": "(let ((package (ensure-package package))) (let ((nicks (package-nicknames package))) (unless (member nickname nicks :test (function string=)) (rename-package package (package-name package) (cons nickname nicks)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-generic name (arg1 arg2) \\\"Docstring\\\" 'body-form) If you meant it as a body form, do nothing, or provide explicit documentation or any other option: (define-generic name (arg1 arg2) \\\"Docstring\\\" (:documentation \\\"Real docstring\\\"))\" (first body))\n\nProblem: Macro call that should be transformed by define-generic", "input": "(define-generic name (arg1 arg2) \\\"Docstring\\\" 'body-form) If you meant it as a body form, do nothing, or provide explicit documentation or any other option: (define-generic name (arg1 arg2) \\\"Docstring\\\" (:documentation \\\"Real docstring\\\"))\" (first body))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric name (arg1 arg2) (:method (arg1 arg2) |\"DOCSTRING\"| (quote body-form))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-and nil)\n\nProblem: Macro call that should be transformed by COLLECT-AND", "input": "(collect-and nil)", "output": "(defmacro COLLECT-AND ...)", "macroexpand": "(common-lisp:let* ((#:generator-495 (generator nil)) #:bools-491 (#:bool-492 t))\n (declare (type generator #:generator-495))\n (tagbody\n #:ll-496\n (setq #:bools-491 (next-in #:generator-495 (go end)))\n (if (null (setq #:bool-492 #:bools-491))\n (go end))\n (go #:ll-496)\n end)\n #:bool-492)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(fgather-result 'some-name)\n\nPattern to recognize: Macro call that should be transformed by FGATHER-RESULT", "input": "(fgather-result 'some-name)", "output": "(defmacro FGATHER-RESULT ...)", "macroexpand": "('some-name nil t)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-method-combination% list)\n\nPattern to recognize: Macro call that should be transformed by define-method-combination%", "input": "(define-method-combination% list)", "output": "(defmacro define-method-combination% (name &rest args)\n \"Define a method-combination for the static-dispatch system only.\n\n Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION.\"\n\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf\n (combination-function ',name)\n ,(match args\n ((or nil\n (list* (and (type symbol) (not nil)) _))\n\n (destructuring-bind (&key (operator name) (identity-with-one-argument nil))\n args\n\n `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))\n\n (_\n `(method-combination-function ,name ,@args))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote list)) (method-combination-function-short list list nil)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-option-expander export (package &rest symbols) (export (mapcar #'(lambda (s) (intern (string s) package)) symbols) package))\n\nWhat needs to change: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander export (package &rest symbols) (export (mapcar #'(lambda (s) (intern (string s) package)) symbols) package))", "output": "(defmacro define-option-expander (name (package &rest arguments) &body body)\n (let ((args (gensym \"ARGS\")))\n `(defmethod expand-option ((,(gensym \"TYPE\") (eql ,(intern (string name) \"KEYWORD\"))) ,package ,args)\n (destructuring-bind ,arguments ,args\n ,@body))))", "macroexpand": "(defmethod expand-option ((#:type134 (eql :export)) package #:args133) (destructuring-bind (&rest symbols) #:args133 (export (mapcar (function (lambda (s) (intern (string s) package))) symbols) package)))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-definition-resolver compiler-macro compiler-macro-function)\n\nPattern to recognize: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver compiler-macro compiler-macro-function)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver compiler-macro (compiler-macro #:package135) (when (ignore-errors (compiler-macro-function compiler-macro)) (list (make-instance (quote compiler-macro) :designator compiler-macro :package #:package135))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(iterate nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ITERATE", "input": "(iterate nil :key nil)", "output": "(defmacro ITERATE ...)", "macroexpand": "(progn (tagbody #:ll-255 ((lambda () :key nil)) (go #:ll-255)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defalias path:relative-p (pathname) cl-fad:pathname-relative-p)\n\nWrite a macro that addresses: Macro call that should be transformed by defalias", "input": "(defalias path:relative-p (pathname) cl-fad:pathname-relative-p)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:relative-p (pathname) (pathname-relative-p pathname)) (define-compiler-macro path:relative-p (&rest args) (list* (quote pathname-relative-p) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.945} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> +any-crlf+ +skipws1+)\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> +any-crlf+ +skipws1+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset134) (multiple-value-bind (#:*>-res135 #:*>-next136) (funcall +any-crlf+ #:*>-offset134) (if (ok? #:*>-res135) (funcall +skipws1+ #:*>-next136) (fail #:*>-next136))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-decoder-simple-list-semantics (is (equalp '((:hello . \"hej\") (:hi . \"tjena\")) (decode-json-from-string input))) (is-false (decode-json-from-string \" { } \")) (is-false (decode-json-from-string \"{}\")))\n\nProblem: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (is (equalp '((:hello . \"hej\") (:hi . \"tjena\")) (decode-json-from-string input))) (is-false (decode-json-from-string \" { } \")) (is-false (decode-json-from-string \"{}\")))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (is (equalp (quote ((:hello . \"hej\") (:hi . \"tjena\"))) (decode-json-from-string input))) (is-false (decode-json-from-string \" { } \")) (is-false (decode-json-from-string \"{}\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-method-combination% append :operator append :identity-with-one-argument t)\n\nProblem: Macro call that should be transformed by define-method-combination%", "input": "(define-method-combination% append :operator append :identity-with-one-argument t)", "output": "(defmacro define-method-combination% (name &rest args)\n \"Define a method-combination for the static-dispatch system only.\n\n Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION.\"\n\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf\n (combination-function ',name)\n ,(match args\n ((or nil\n (list* (and (type symbol) (not nil)) _))\n\n (destructuring-bind (&key (operator name) (identity-with-one-argument nil))\n args\n\n `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))\n\n (_\n `(method-combination-function ,name ,@args))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote append)) (method-combination-function-short append append t)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-test bad-var (is eql a 'c))\n\nIssue: Macro call that should be transformed by define-test", "input": "(define-test bad-var (is eql a 'c))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote bad-var) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote bad-var) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (is eql a (quote c)))) :parent (quote nil))) (quote bad-var))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(rte-case nil)\n\nWrite a macro that addresses: Macro call that should be transformed by RTE-CASE", "input": "(rte-case nil)", "output": "(defmacro RTE-CASE ...)", "macroexpand": "(let ((#:rte169 nil))\n (typecase #:rte169\n ((not sequence) nil)\n (t\n (funcall\n (lambda (#:rte169)\n (declare (optimize (speed 3) (debug 0) (safety 0)))\n (block check\n (typecase #:rte169\n (list nil)\n (simple-vector\n (let ((i 0) (len (length #:rte169)))\n (declare (type (and unsigned-byte fixnum) i len)\n (ignorable len))\n nil))\n (vector\n (let ((i 0) (len (length #:rte169)))\n (declare (type (and fixnum unsigned-byte) i len)\n (ignorable len))\n nil))\n (sequence\n (let ((i 0) (len (sb-sequence:length #:rte169)))\n (declare (type (and fixnum unsigned-byte) i len)\n (ignorable len))\n nil))\n (t nil))))\n #:rte169))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dynamic-progv nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by DYNAMIC-PROGV", "input": "(dynamic-progv nil\n nil)", "output": "(defmacro DYNAMIC-PROGV ...)", "macroexpand": "(let* ((#:fixed-symbols235 nil)\n (#:fixed-bindings236 (compute-bindings #:fixed-symbols235 nil)))\n (dynamic-wind\n :proceed\n #:proceed237\n (progv #:fixed-symbols235 #:fixed-bindings236 (#:proceed237))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(if-let ((x 2) (y x)) (+ x y) :oops)\n\nPattern to recognize: Macro call that should be transformed by if-let", "input": "(if-let ((x 2) (y x)) (+ x y) :oops)", "output": "(defmacro if-let (bindings &body (then-form &optional else-form))\n \"Creates new variable bindings, and conditionally executes either\nTHEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nAll initial-forms are executed sequentially in the specified order. Then all\nthe variables are bound to the corresponding values.\n\nIf all variables were bound to true values, the THEN-FORM is executed with the\nbindings in effect, otherwise the ELSE-FORM is executed with the bindings in\neffect.\"\n (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings))\n (variables (mapcar #'car binding-list)))\n `(let ,binding-list\n (if (and ,@variables)\n ,then-form\n ,else-form))))", "macroexpand": "(let ((x 2) (y x)) (if (and x y) (+ x y) :oops))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-special-initargs nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by WITH-SPECIAL-INITARGS", "input": "(with-special-initargs nil\n :key\n nil)", "output": "(defmacro WITH-SPECIAL-INITARGS ...)", "macroexpand": "(funcall-with-special-initargs (list) (lambda () :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(assert-values (\"added foo = nil\") (foo nil) (foo+1 nil) (bar 'nothing) (bar-1 'nothing))\n\nWhat needs to change: Macro call that should be transformed by assert-values", "input": "(assert-values (\"added foo = nil\") (foo nil) (foo+1 nil) (bar 'nothing) (bar-1 'nothing))", "output": "(defmacro assert-values ((desc) &body objects-and-values)\n `(progn\n (trc ,desc)\n ,@(loop for (obj val) in objects-and-values\n\t collect `(assert (eql (value ,obj) ,val)))))", "macroexpand": "(progn (trc \"added foo = nil\") (assert (eql (value foo) nil)) (assert (eql (value foo+1) nil)) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(->> 'some-name)\n\nPattern to recognize: Macro call that should be transformed by ->>", "input": "(->> 'some-name)", "output": "(defmacro ->> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-object-lookup function fdefinition)\n\nPattern to recognize: Macro call that should be transformed by define-simple-object-lookup", "input": "(define-simple-object-lookup function fdefinition)", "output": "(defmacro define-simple-object-lookup (class lookup-function &body body)\n `(defmethod object ((,class ,class))\n ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function (designator ,class)))))", "macroexpand": "(defmethod object ((function function)) (fdefinition (designator function)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun+ nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DEFUN+", "input": "(defun+ nil\n (progn))", "output": "(defmacro DEFUN+ ...)", "macroexpand": "(defun nil (#:g128) (let+ ((progn #:g128))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defhandler declare (declare &rest body) `(list ',declare ,@(mapcar (lambda (f) `',f) body)))\n\nWhat needs to change: Macro call that should be transformed by defhandler", "input": "(defhandler declare (declare &rest body) `(list ',declare ,@(mapcar (lambda (f) `',f) body)))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-declare (declare &rest body) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr declare :kind 0)) #S(sb-impl::comma :expr (mapcar (lambda (f) (sb-int:quasiquote (quote #S(sb-impl::comma :expr f :kind 0)))) body) :kind 2)))) (setf (gethash (quote declare) *form-handler*) (quote hander-declare)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defalias path:-e (pathname) cl-fad:file-exists-p)\n\nWhat needs to change: Macro call that should be transformed by defalias", "input": "(defalias path:-e (pathname) cl-fad:file-exists-p)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:-e (pathname) (file-exists-p pathname)) (define-compiler-macro path:-e (&rest args) (list* (quote file-exists-p) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.9075} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-custom-var (:end-of-string *end-of-string-handler*))\n\nWrite a macro that addresses: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:end-of-string *end-of-string-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*end-of-string-handler* . :end-of-string)) *custom-vars* :test (function equal)) (defvar *end-of-string-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defhandler progv (progv symbols values &rest body) `(list ',progv (list ,@(e-list symbols)) (list ,@(e-list values)) ,@(e-list body)))\n\nWrite a macro that addresses: Macro call that should be transformed by defhandler", "input": "(defhandler progv (progv symbols values &rest body) `(list ',progv (list ,@(e-list symbols)) (list ,@(e-list values)) ,@(e-list body)))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-progv (progv symbols values &rest body) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr progv :kind 0)) (list #S(sb-impl::comma :expr (e-list symbols) :kind 2)) (list #S(sb-impl::comma :expr (e-list values) :kind 2)) #S(sb-impl::comma :expr (e-list body) :kind 2)))) (setf (gethash (quote progv) *form-handler*) (quote hander-progv)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(advisable-lambda 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by ADVISABLE-LAMBDA", "input": "(advisable-lambda 'some-name)", "output": "(defmacro ADVISABLE-LAMBDA ...)", "macroexpand": "(make-instance 'advisable-function :main #'(lambda (quote some-name))\n :arguments ''some-name :dispatcher-generator\n #'(lambda (#:fobj130)\n #'(lambda (quote some-name)\n #A((29) base-char . \"Advisable function dispatcher\")\n (let ((#:fixed131\n (append (list quote) (list some-name))))\n (apply-before #:fobj130 #:fixed131)\n (multiple-value-prog1\n (apply-around #:fobj130 #:fixed131)\n (apply-after #:fobj130 #:fixed131))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deferror \"42P04\" duplicate-database syntax-error-or-access-violation)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"42P04\" duplicate-database syntax-error-or-access-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition duplicate-database (syntax-error-or-access-violation) nil) (setf (gethash \"42P04\" *error-table*) (quote duplicate-database)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when (eql (top-sign) 'skip-first) (pop-sign))\n\nIssue: Macro call that should be transformed by when", "input": "(when (eql (top-sign) 'skip-first) (pop-sign))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql (top-sign) (quote skip-first)) (pop-sign))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-html-string (:div :class \"status col-xs-2 col-md-1\" (:span :class \"text-success\" (:a :href \"https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200\" 200))))\n\nWhat needs to change: Macro call that should be transformed by with-html", "input": "(with-html-string (:div :class \"status col-xs-2 col-md-1\" (:span :class \"text-success\" (:a :href \"https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200\" 200))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:div :class \"status col-xs-2 col-md-1\" (:span :class \"text-success\" (:a :href \"https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200\" 200)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(c? (incf plus-ct) (trc nil \"m-plus rule firing!!!!!!!!!!!!!!\" plus-ct) (f-plusp :syna-2 (- 2 (^m-syn-a))))\n\nPattern to recognize: Macro call that should be transformed by c?", "input": "(c? (incf plus-ct) (trc nil \"m-plus rule firing!!!!!!!!!!!!!!\" plus-ct) (f-plusp :syna-2 (- 2 (^m-syn-a))))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((incf plus-ct) (trc nil \"m-plus rule firing!!!!!!!!!!!!!!\" plus-ct) (f-plusp :syna-2 (- 2 (^m-syn-a))))) :value-state :unevaluated :rule (c-lambda (incf plus-ct) (trc nil \"m-plus rule firing!!!!!!!!!!!!!!\" plus-ct) (f-plusp :syna-2 (- 2 (^m-syn-a)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(alet (1+ 1) it (1+ it))\n\nPattern to recognize: Macro call that should be transformed by alet", "input": "(alet (1+ 1) it (1+ it))", "output": "(defmacro alet (form &body body)\n \"Binds the FORM to IT (via LET) in the scope of the BODY.\"\n `(anaphoric ignore-first ,form (progn ,@body)))", "macroexpand": "(anaphoric ignore-first (1+ 1) (progn it (1+ it)))", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.8225} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (slot-value parent 'tail-qualifiers) (format stream \" \"))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (slot-value parent 'tail-qualifiers) (format stream \" \"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (slot-value parent (quote tail-qualifiers)) (format stream \" \"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do () (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DO", "input": "(do () (progn))", "output": "(defmacro DO ...)", "macroexpand": "(block nil\n (let ()\n (declare (ignorable))\n (tagbody\n (go #:g193)\n #:g192\n (tagbody)\n (psetq)\n #:g193\n (unless progn (go #:g192))\n (return-from nil (progn)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(collect-first nil)\n\nIssue: Macro call that should be transformed by COLLECT-FIRST", "input": "(collect-first nil)", "output": "(defmacro COLLECT-FIRST ...)", "macroexpand": "(common-lisp:let* ((#:generator-616 (generator nil))\n #:items-610\n (#:item-612 nil))\n (declare (type generator #:generator-616)\n (type (null-or t) #:item-612))\n (tagbody\n #:ll-617\n (setq #:items-610 (next-in #:generator-616 (go end)))\n (setq #:item-612 #:items-610)\n end)\n #:item-612)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-html-string (:p \"foo\" \"bar\" (values \"baz\")))\n\nWrite a macro that addresses: Macro call that should be transformed by with-html", "input": "(with-html-string (:p \"foo\" \"bar\" (values \"baz\")))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:p \"foo\" \"bar\" (values \"baz\"))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-path-instruction-pair smooth-quadratic-curve-to \"T\" (x y))\n\nIssue: Macro call that should be transformed by define-path-instruction-pair", "input": "(define-path-instruction-pair smooth-quadratic-curve-to \"T\" (x y))", "output": "(defmacro define-path-instruction-pair (name instruction (&rest args))\n (let ((draw-relative (intern (concatenate 'string (string name) \"-R\"))))\n `(progn\n (defun ,name (,@args)\n (format-instruction ,instruction ,@args))\n (defun ,draw-relative (,@args)\n (format-instruction ,(string-downcase instruction) ,@args)))))", "macroexpand": "(progn (defun smooth-quadratic-curve-to (x y) (format-instruction \"T\" x y)) (defun smooth-quadratic-curve-to-r (x y) (format-instruction \"t\" x y)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(list-of nil\n nil)\n\nIssue: Macro call that should be transformed by LIST-OF", "input": "(list-of nil\n nil)", "output": "(defmacro LIST-OF ...)", "macroexpand": "(lc (nil nil) collect)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-html-string (:p \"foo\" \"bar\" \"baz\"))\n\nWrite a macro that addresses: Macro call that should be transformed by with-html", "input": "(with-html-string (:p \"foo\" \"bar\" \"baz\"))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:p \"foo\" \"bar\" \"baz\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (not (some #'test-failure-p results)))\n\nIssue: Macro call that should be transformed by is", "input": "(is (not (some #'test-failure-p results)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e244 (function test-failure-p)) (#:a245 results)) (if (progn (not (some #:e244 #:a245))) (add-result (quote test-passed) :test-expr (quote (not (some (function test-failure-p) results)))) (process-failure (quote (not (some (function test-failure-p) results))) \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\" (quote results) #:a245 (quote some) #:e244)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun-speedy ascii-string-to-octets (string) (%ascii-string-to-octets string))\n\nIssue: Macro call that should be transformed by defun-speedy", "input": "(defun-speedy ascii-string-to-octets (string) (%ascii-string-to-octets string))", "output": "(defmacro defun-speedy (name lambda-list &body body)\n `(progn\n (declaim (notinline ,name))\n (defun ,name ,lambda-list\n ,*speedy-declaration*\n ,@body)))", "macroexpand": "(progn (declaim (notinline ascii-string-to-octets)) (defun ascii-string-to-octets (string) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (%ascii-string-to-octets string)))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun-compile-time walk-function-call (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper function call form: ~S\" form)) (cond ((lambda-expression? (first form)) (if reduce-function (funcall reduce-function (funcall map-function form 'lambda-call) (funcall reduce-function (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form))) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (first form)) environment) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (peal-off-documentation-string-and-declarations (rest (rest (first form))) t)))))) (funcall map-function form 'lambda-call))) ((valid-function-name? (first form)) (if (symbolp (first form)) (if reduce-function (funcall reduce-function (funcall map-function form 'symbol-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'symbol-call)) (if reduce-function (funcall reduce-function (funcall map-function form 'setf-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'setf-call)))) (t (error \"CAR of form ~S is not a valid function\" form))))\n\nPattern to recognize: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-function-call (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper function call form: ~S\" form)) (cond ((lambda-expression? (first form)) (if reduce-function (funcall reduce-function (funcall map-function form 'lambda-call) (funcall reduce-function (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form))) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (first form)) environment) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (peal-off-documentation-string-and-declarations (rest (rest (first form))) t)))))) (funcall map-function form 'lambda-call))) ((valid-function-name? (first form)) (if (symbolp (first form)) (if reduce-function (funcall reduce-function (funcall map-function form 'symbol-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'symbol-call)) (if reduce-function (funcall reduce-function (funcall map-function form 'setf-call) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'setf-call)))) (t (error \"CAR of form ~S is not a valid function\" form))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-function-call (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper function call form: ~S\" form)) (cond ((lambda-expression? (first form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote lambda-call)) (funcall reduce-function (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form))) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (first form)) environment) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (peal-off-documentation-string-and-declarations (rest (rest (first form))) t)))))) (funcall map-function form (quote lambda-call)))) ((valid-function-name? (first form)) (if (symbolp (first form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote symbol-call)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote symbol-call))) (if reduce-function (funcall reduce-function (funcall map-function form (quote setf-call)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote setf-call))))) (t (error \"CAR of form ~S is not a valid function\" form)))) (eval-when (:compile-toplevel) (compile (quote walk-function-call))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lret* ((shape (ensure-shape shape)) (array (make-array shape))) (loop for i from 0 below (array-total-size array) do (setf (row-major-aref array i) (array-index-row-major array i))))\n\nWrite a macro that addresses: Macro call that should be transformed by lret", "input": "(lret* ((shape (ensure-shape shape)) (array (make-array shape))) (loop for i from 0 below (array-total-size array) do (setf (row-major-aref array i) (array-index-row-major array i))))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((shape (ensure-shape shape)) (array (make-array shape))) (loop for i from 0 below (array-total-size array) do (setf (row-major-aref array i) (array-index-row-major array i))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-immutable-map (_ value object) (declare (ignore _)) (scan value))\n\nProblem: Macro call that should be transformed by do-immutable-map", "input": "(do-immutable-map (_ value object) (declare (ignore _)) (scan value))", "output": "(defmacro do-immutable-map ((key value map &optional result) &body body)\n \"Iterate over MAP in ascending key order, binding KEY and VALUE.\"\n `(avl:do-avl (,key ,value (immutable-map-data ,map) ,result)\n ,@body))", "macroexpand": "(avl:do-avl (_ value (immutable-map-data object) nil) (declare (ignore _)) (scan value))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-lock (lru-pool-lock pool) (add-to-lru-pool pool host-port stream eviction-callback))\n\nIssue: Macro call that should be transformed by with-lock", "input": "(with-lock (lru-pool-lock pool) (add-to-lru-pool pool host-port stream eviction-callback))", "output": "(defmacro with-lock (lock &body body)\n (declare (ignorable lock))\n #+thread-support `(bt2:with-lock-held (,lock)\n ,@body)\n #-thread-support `(progn ,@body))", "macroexpand": "(bt2:with-lock-held ((lru-pool-lock pool)) (add-to-lru-pool pool host-port stream eviction-callback))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield-binds (format nil (if (sql-statement-p (statement-clause-statement clause)) \"~:[~A ~;~*~](~A)\" \"~:[~A ~;~*~]~A\") (string= (sql-clause-name clause) \"\") (sql-clause-name clause) (yield (statement-clause-statement clause))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil (if (sql-statement-p (statement-clause-statement clause)) \"~:[~A ~;~*~](~A)\" \"~:[~A ~;~*~]~A\") (string= (sql-clause-name clause) \"\") (sql-clause-name clause) (yield (statement-clause-statement clause))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil (if (sql-statement-p (statement-clause-statement clause)) \"~:[~A ~;~*~](~A)\" \"~:[~A ~;~*~]~A\") (string= (sql-clause-name clause) \"\") (sql-clause-name clause) (yield (statement-clause-statement clause)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-decoder-simple-list-semantics (let (result) (setf result (json-rpc:invoke-rpc (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"method\\\":\\\"~a\\\",\\\"params\\\":[1,2],\\\"id\\\":999}\" (json-rpc-2-p) method-name))) (is (string= result (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"result\\\":{\\\"digits\\\":3,\\\"letters\\\":\\\"three\\\"},~@[~*\\\"error\\\":null,~]\\\"id\\\":999}\" (json-rpc-2-p) (not (json-rpc-2-p)))))))\n\nIssue: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (let (result) (setf result (json-rpc:invoke-rpc (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"method\\\":\\\"~a\\\",\\\"params\\\":[1,2],\\\"id\\\":999}\" (json-rpc-2-p) method-name))) (is (string= result (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"result\\\":{\\\"digits\\\":3,\\\"letters\\\":\\\"three\\\"},~@[~*\\\"error\\\":null,~]\\\"id\\\":999}\" (json-rpc-2-p) (not (json-rpc-2-p)))))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (let (result) (setf result (json-rpc:invoke-rpc (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"method\\\":\\\"~a\\\",\\\"params\\\":[1,2],\\\"id\\\":999}\" (json-rpc-2-p) method-name))) (is (string= result (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"result\\\":{\\\"digits\\\":3,\\\"letters\\\":\\\"three\\\"},~@[~*\\\"error\\\":null,~]\\\"id\\\":999}\" (json-rpc-2-p) (not (json-rpc-2-p)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-avl-map ('foo val1) ('bar val2))\n\nIssue: Macro call that should be transformed by make-avl-map", "input": "(make-avl-map ('foo val1) ('bar val2))", "output": "(defmacro make-avl-map (&rest pairs)\n \"Construct an AVL tree from literal (key-expr value-expr) pairs.\nUsage: (make-avl-map ('foo val1) ('bar val2))\"\n (let ((tree (gensym \"TREE\")))\n `(let ((,tree (empty-avl-tree)))\n ,@(loop :for (k v) :in pairs\n :collect `(setf ,tree (avl-set ,tree ,k ,v)))\n ,tree)))", "macroexpand": "(let ((#:tree162 (empty-avl-tree))) (setf #:tree162 (avl-set #:tree162 (quote foo) val1)) (setf #:tree162 (avl-set #:tree162 (quote bar) val2)) #:tree162)", "category": "control-flow", "technique": "gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defalias path:root-p (pathname) cl-fad:pathname-root-p)\n\nPattern to recognize: Macro call that should be transformed by defalias", "input": "(defalias path:root-p (pathname) cl-fad:pathname-root-p)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:root-p (pathname) (pathname-root-p pathname)) (define-compiler-macro path:root-p (&rest args) (list* (quote pathname-root-p) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.945} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-modf-rewrite rest (expr) `(cdr ,(second expr)))\n\nProblem: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite rest (expr) `(cdr ,(second expr)))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote rest) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr #S(sb-impl::comma :expr (second expr) :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(as->* nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by AS->*", "input": "(as->* nil :key nil)", "output": "(defmacro AS->* ...)", "macroexpand": "(as-> nil nil :key)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error for-loop-simple-expression () () \"Only simple expressions are allowed in the condition and update slots of a for loop\")\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error for-loop-simple-expression () () \"Only simple expressions are allowed in the condition and update slots of a for loop\")", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition for-loop-simple-expression (:error-type varjo-error :prefix \"Varjo\") nil \"Only simple expressions are allowed in the condition and update slots of a for loop\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define HUGE_VAL most-positive-double-float)\n\nProblem: Macro call that should be transformed by define", "input": "(define HUGE_VAL most-positive-double-float)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote huge_val) *preprocessor-defines*) #A((26) base-char . \"MOST-POSITIVE-DOUBLE-FLOAT\"))) (defparameter huge_val most-positive-double-float))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-direct-binding being (var &rest sub-bindings) (let ((bindings (loop for bind in sub-bindings collect (list* var bind))) (being-counter (gensym (string 'being-counter))) (being-tag (gensym (string 'being-tag))) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect `(,var NIL)))) (multiple-value-bind (bind-init bind-forms) (convert-bindings bindings) (values `(with-interleaving (let ((,being-counter 0) ,@vars)) ,@(loop for bind in bind-init collect (remove-bindings vars bind))) `(tagbody ,being-tag (case ,being-counter ,@(loop for form in (butlast bind-forms) for i from 0 collect `(,i (macrolet ((end-for () `(progn (incf ,',being-counter) (go ,',being-tag)))) ,form))) (T ,@(last bind-forms))))))))\n\nPattern to recognize: Macro call that should be transformed by define-direct-binding", "input": "(define-direct-binding being (var &rest sub-bindings) (let ((bindings (loop for bind in sub-bindings collect (list* var bind))) (being-counter (gensym (string 'being-counter))) (being-tag (gensym (string 'being-tag))) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect `(,var NIL)))) (multiple-value-bind (bind-init bind-forms) (convert-bindings bindings) (values `(with-interleaving (let ((,being-counter 0) ,@vars)) ,@(loop for bind in bind-init collect (remove-bindings vars bind))) `(tagbody ,being-tag (case ,being-counter ,@(loop for form in (butlast bind-forms) for i from 0 collect `(,i (macrolet ((end-for () `(progn (incf ,',being-counter) (go ,',being-tag)))) ,form))) (T ,@(last bind-forms))))))))", "output": "(defmacro define-direct-binding (name args &body body)\n (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym \"ENVIRONMENT\"))))\n `(progn (setf (binding ',name)\n (lambda ,(lambda-fiddle:remove-environment-part args)\n (let ((,env *environment*))\n (declare (ignorable ,env))\n ,@body)))\n ',name)))", "macroexpand": "(progn (setf (binding (quote being)) (lambda (var &rest sub-bindings) (let ((#:environment124 *environment*)) (declare (ignorable #:environment124)) (let ((bindings (loop for bind in sub-bindings collect (list* var bind))) (being-counter (gensym (string (quote being-counter)))) (being-tag (gensym (string (quote being-tag)))) (vars (loop for var in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (sb-int:quasiquote (#S(sb-impl::comma :expr var :kind 0) nil))))) (multiple-value-bind (bind-init bind-forms) (convert-bindings bindings) (values (sb-int:quasiquote (with-interleaving (let ((#S(sb-impl::comma :expr being-counter :kind 0) 0) #S(sb-impl::comma :expr vars :kind 2))) #S(sb-impl::comma :expr (loop for bind in bind-init collect (remove-bindings vars bind)) :kind 2))) (sb-int:quasiquote (tagbody #S(sb-impl::comma :expr being-tag :kind 0) (case #S(sb-impl::comma :expr being-counter :kind 0) #S(sb-impl::comma :expr (loop for form in (butlast bind-forms) for i from 0 collect (sb-int:quasiquote (#S(sb-impl::comma :expr i :kind 0) (macrolet ((end-for nil (sb-int:quasiquote (progn (incf #S(sb-impl::comma :expr (quote #S(sb-impl::comma :expr being-counter :kind 0)) :kind 0)) (go #S(sb-impl::comma :expr (quote #S(sb-impl::comma :expr being-tag :kind 0)) :kind 0)))))) #S(sb-impl::comma :expr form :kind 0))))) :kind 2) (t #S(sb-impl::comma :expr (last bind-forms) :kind 2))))))))))) (quote being))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(gatherer nil)\n\nProblem: Macro call that should be transformed by GATHERER", "input": "(gatherer nil)", "output": "(defmacro GATHERER ...)", "macroexpand": "(common-lisp:let ((#:lastcons-445 (list nil)) #:lst-446)\n (declare (type cons #:lastcons-445)\n (type list #:lst-446))\n (setq #:lst-446 #:lastcons-445)\n (common-lisp:let (#:out-448)\n #'(lambda (#:items-444 result-p)\n (cond\n ((null result-p)\n (tagbody\n (setq #:lastcons-445\n (setf (cdr #:lastcons-445) (cons #:items-444 nil)))))\n (t\n (progn\n (setq #:lst-446 (cdr #:lst-446))\n (setq #:out-448\n (common-lisp:funcall nil\n (common-lisp:funcall #'scan\n #:lst-446))))\n #:out-448)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-dynenv-fun nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEF-DYNENV-FUN", "input": "(def-dynenv-fun nil\n nil)", "output": "(defmacro DEF-DYNENV-FUN ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun nil (&rest #:args) (apply (dynenv-function nil) #:args))\n (defvar #:nil143 (lambda ()))\n (setf (get 'nil 'dynenv-fun) '#:nil143))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-additional-indent (reporter stream \"\u00d7 \") (when (slot-value report 'description) (format/indent reporter stream \"~A~%\" (slot-value report 'description))) (format/indent reporter stream \"Raised an error ~A (expected: ~S)\" (slot-value report 'got) (slot-value report 'expected)))\n\nIssue: Macro call that should be transformed by with-additional-indent", "input": "(with-additional-indent (reporter stream \"\u00d7 \") (when (slot-value report 'description) (format/indent reporter stream \"~A~%\" (slot-value report 'description))) (format/indent reporter stream \"Raised an error ~A (expected: ~S)\" (slot-value report 'got) (slot-value report 'expected)))", "output": "(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)\n (declare (ignorable reporter stream control-string))\n (let* ((need-new-line (ppcre:scan \"^~&\" control-string))\n (string (apply #'format nil control-string format-arguments))\n (increment (length string)))\n `(with-slots (indent-space) reporter\n (let* ((first-line-indent (indent indent-space))\n (*additional-indent* ,(if need-new-line\n increment\n `(+ *additional-indent*\n ,increment))))\n (declare (ignorable first-line-indent))\n ,(if need-new-line\n `(progn (fresh-line stream)\n (write-string first-line-indent ,stream)\n ;; because we just started a new line, we\n ;; should use format/indent to write string\n ;; taking into account a main indentation level\n (format/indent ,reporter ,stream ,string))\n ;; otherwise, just output our prefix\n `(write-string ,string ,stream))\n \n \n ,@body))))", "macroexpand": "(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* (+ *additional-indent* 2))) (declare (ignorable first-line-indent)) (write-string \"\u00d7 \" stream) (when (slot-value report (quote description)) (format/indent reporter stream \"~A~%\" (slot-value report (quote description)))) (format/indent reporter stream \"Raised an error ~A (expected: ~S)\" (slot-value report (quote got)) (slot-value report (quote expected)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(node 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by NODE", "input": "(node 'some-name)", "output": "(defmacro NODE ...)", "macroexpand": "(make+finish-node+relations quote some-name 'nil 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(-<> nil nil)\n\nPattern to recognize: Macro call that should be transformed by -<>", "input": "(-<> nil nil)", "output": "(defmacro -<> ...)", "macroexpand": "(-> nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(slet it it)\n\nProblem: Macro call that should be transformed by slet", "input": "(slet it it)", "output": "(defmacro slet (form &body body)\n \"Binds the FORM to IT (via SYMBOL-MACROLET) in the scope of the BODY. IT can\nbe set with SETF.\"\n `(symbolic ignore-first ,form (progn ,@body)))", "macroexpand": "(symbolic ignore-first it (progn it))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-neo4j-fun traverse (node-id (return-type :node) (max-depth 1) (order :depth-first) uniqueness relationships prune-evaluator return-filter) :post (:uri-spec (format nil \"node/~A/traverse/~A\" node-id (string-downcase (symbol-name return-type)))) (:encode (list (cons \"order\" (case order (:depth-first \"depth_first\") (:breadth-first \"breadth_first\"))) (cons \"uniqueness\" uniqueness) (cons \"relationships\" relationships) (cons \"prune_evaluator\" prune-evaluator) (cons \"return_filter\" return-filter) (cons \"max_depth\" max-depth)) :string) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))\n\nProblem: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun traverse (node-id (return-type :node) (max-depth 1) (order :depth-first) uniqueness relationships prune-evaluator return-filter) :post (:uri-spec (format nil \"node/~A/traverse/~A\" node-id (string-downcase (symbol-name return-type)))) (:encode (list (cons \"order\" (case order (:depth-first \"depth_first\") (:breadth-first \"breadth_first\"))) (cons \"uniqueness\" uniqueness) (cons \"relationships\" relationships) (cons \"prune_evaluator\" prune-evaluator) (cons \"return_filter\" return-filter) (cons \"max_depth\" max-depth)) :string) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun traverse (&key node-id (return-type :node) (max-depth 1) (order :depth-first) uniqueness relationships prune-evaluator return-filter) (let ((uri (format nil \"node/~A/traverse/~A\" node-id (string-downcase (symbol-name return-type)))) (json (encode-neo4j-json-payload (list (cons \"order\" (case order (:depth-first \"depth_first\") (:breadth-first \"breadth_first\"))) (cons \"uniqueness\" uniqueness) (cons \"relationships\" relationships) (cons \"prune_evaluator\" prune-evaluator) (cons \"return_filter\" return-filter) (cons \"max_depth\" max-depth)) :string))) (make-neo4j-request :post uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(matrix-etypecase nil)\n\nWhat needs to change: Macro call that should be transformed by MATRIX-ETYPECASE", "input": "(matrix-etypecase nil)", "output": "(defmacro MATRIX-ETYPECASE ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym next-iteration :next-iteration)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym next-iteration :next-iteration)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote next-iteration) (quote synonym)) (quote :next-iteration)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym first-iteration-p :first-iteration-p)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym first-iteration-p :first-iteration-p)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote first-iteration-p) (quote synonym)) (quote :first-iteration-p)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-env [plist :c])\n\nWhat needs to change: Macro call that should be transformed by with-env", "input": "(with-env [plist :c])", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g129) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g129 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [plist :c])) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g129)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(keep-bops nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by KEEP-BOPS", "input": "(keep-bops nil nil)", "output": "(defmacro KEEP-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn\n (init-binfix)\n (unless nil\n (setq *binfix*\n (delete nil\n (mapcar\n (lambda (bs)\n (setq bs\n (delete-if\n (lambda (b)\n (unless (member (car b) '(nil nil))\n (remprop (car b) 'properties)\n t))\n bs)))\n *binfix*)))\n (assign-properties))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(f_%\n nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by F_%", "input": "(f_%\n nil\n (progn))", "output": "(defmacro F_% ...)", "macroexpand": "(lambda (&rest #:|ignore128|) (declare (ignore #:|ignore128|)) nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defsyntax nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by DEFSYNTAX", "input": "(defsyntax nil\n :key\n nil)", "output": "(defmacro defsyntax (name &body options)\n `(progn\n (setf (get ',name :options) ',options)\n (defvar ,name (defreadtable ,name ,@options))))", "macroexpand": "(progn\n (setf (get 'nil :options) '(:key nil))\n (defvar nil\n (defreadtable nil\n :key\n nil)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(as-> nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by AS->", "input": "(as-> nil (progn))", "output": "(defmacro AS-> ...)", "macroexpand": "(let* (((progn) nil))\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(when (cdr clauses) `(cond ,@(cdr clauses)))\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when (cdr clauses) `(cond ,@(cdr clauses)))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (cdr clauses) (sb-int:quasiquote (cond #S(sb-impl::comma :expr (cdr clauses) :kind 2))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(gathering nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by GATHERING", "input": "(gathering nil\n (progn))", "output": "(defmacro GATHERING ...)", "macroexpand": "(common-lisp:let ()\n (progn)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun-compile-time is-magic-declaration? (form) (and (consp form) (eq (first form) 'declare) (consp (rest form)) (consp (second form)) (eq (first (second form)) 'magic)))\n\nPattern to recognize: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time is-magic-declaration? (form) (and (consp form) (eq (first form) 'declare) (consp (rest form)) (consp (second form)) (eq (first (second form)) 'magic)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun is-magic-declaration? (form) (and (consp form) (eq (first form) (quote declare)) (consp (rest form)) (consp (second form)) (eq (first (second form)) (quote magic)))) (eval-when (:compile-toplevel) (compile (quote is-magic-declaration?))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lret* () 1)\n\nProblem: Macro call that should be transformed by lret", "input": "(lret* () 1)", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let* nil 1)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-declaration nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFINE-DECLARATION", "input": "(define-declaration nil\n (progn))", "output": "(defmacro DEFINE-DECLARATION ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (proclaim '(declaration nil))\n (flet ((sb-cltl2::func (progn)\n ))\n (setf (sb-int:info :declaration :known 'nil)\n (lambda\n (sb-kernel:lexenv sb-cltl2::spec sb-cltl2::pd-vars\n sb-cltl2::pd-fvars)\n (multiple-value-bind (sb-cltl2::kind sb-cltl2::data)\n (sb-cltl2::func sb-cltl2::spec sb-kernel:lexenv)\n (sb-cltl2::update-lexenv-user-data sb-kernel:lexenv\n sb-cltl2::kind\n sb-cltl2::data\n sb-cltl2::pd-vars\n sb-cltl2::pd-fvars))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ps-html nil (progn))\n\nProblem: Macro call that should be transformed by PS-HTML", "input": "(ps-html nil (progn))", "output": "(defmacro PS-HTML ...)", "macroexpand": "(stringify nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defclass/a dbd-postgres-query (dbi-query) ((name :initarg :name) (freedp :initform nil :accessor query-freed-p)) (:default-initargs :fields nil))\n\nPattern to recognize: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbd-postgres-query (dbi-query) ((name :initarg :name) (freedp :initform nil :accessor query-freed-p)) (:default-initargs :fields nil))", "output": "(defmacro defclass/a (name superclasses slots &rest class-options)\n `(progn\n (defclass ,name ,superclasses ,slots ,@class-options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (defclass dbd-postgres-query (dbi-query) ((name :initarg :name) (freedp :initform nil :accessor query-freed-p)) (:default-initargs :fields nil)) (deftype nil (quote dbd-postgres-query)) (setf (find-class (quote )) (find-class (quote dbd-postgres-query))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) (1- val)))\n\nWrite a macro that addresses: Macro call that should be transformed by c?", "input": "(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) (1- val)))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(c? (bwhen-c-stored (v :bar store (quote nothing)) (bwhen (val (value v)) (1- val))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(make-window-or-instance nil)\n\nProblem: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE", "input": "(make-window-or-instance nil)", "output": "(defmacro MAKE-WINDOW-OR-INSTANCE ...)", "macroexpand": "(make-$instance nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-iter-value (value it) value)\n\nWrite a macro that addresses: Macro call that should be transformed by with-iter-value", "input": "(with-iter-value (value it) value)", "output": "(defmacro with-iter-value ((pattern iter) &body body)\n \"Bind the current element of a sequence, pointed to by a static iterator, to a variable.\n\n This macro may only be used within the body of a WITH-ITERATORS\n macro.\n\n The current value of the sequence, with iterator ITER, is bound to\n the variable(s) specified by PATTERN, with the bindings visible to\n FORMS.\n\n If the iterator is already at the end of the sequence a non-local\n jump, to the end of the enclosing WITH-ITERATORS form, is\n performed.\n\n After binding, the iterator is advanced to the next element of the\n sequence.\n\n PATTERN:\n\n A binding pattern specifying the variable(s) to which the current\n element of the sequence is bound.\n\n This may either be a symbol, naming a variable, or a list which\n is interpreted as a pattern to `destructuring-bind`.\n\n ITER:\n\n Symbol identifying the iterator, as established by the\n WITH-ITERATORS form.\n\n This must name an iterator introduced in a parent WITH-ITERATORS\n form.\n\n BODY:\n\n The body of the WITH-ITER-VALUE form:\n\n (DECLARATION* FORM*)\n\n The body consists of a list of forms evaluated in an implicit\n PROGN, with the value of the last form returned from the\n WITH-ITER-VALUE form. The binding(s) introduced by PATTERN are\n visible to forms.\n\n The forms may be preceded by declaration expressions, which may\n apply to the variables introduced in PATTERN.\n\n NOTE: If there are no more elements in the sequence, the forms\n are not evaluated and a non-local jump to the end of the\n enclosing WITH-ITERATORS form is performed.\"\n\n `(with-iter-values ((,pattern ,iter)) ,@body))", "macroexpand": "(with-iter-values ((value it)) value)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(%escape-string-form form)\n\nWhat needs to change: Macro call that should be transformed by %escape-string-form", "input": "(%escape-string-form form)", "output": "(defmacro %escape-string-form (val)\n (let ((val2 (gensym)))\n `(let ((,val2 ,val))\n (if (should-escape-p ,val2)\n `(escape-string ,,val2)\n ,val2))))", "macroexpand": "(let ((#:g122 form)) (if (should-escape-p #:g122) (sb-int:quasiquote (escape-string #S(sb-impl::comma :expr #:g122 :kind 0))) #:g122))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(undefreply nil :key nil)\n\nProblem: Macro call that should be transformed by UNDEFREPLY", "input": "(undefreply nil :key nil)", "output": "(defmacro UNDEFREPLY ...)", "macroexpand": "(undefine-reply 'nil :qualifiers '(:key) :participants `nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(action (:after node-lisp node bound-variables) (let ((new-vars (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for target := (and (not (member coalton-var bound-variables :test #'eq)) (alias-substitution-target coalton-var aliases)) :collect (cons lisp-var (if target (node-variable-value target) coalton-var))))) (unless (equal new-vars (node-lisp-vars node)) (make-node-lisp :type (node-type node) :vars new-vars :form (node-lisp-form node)))))\n\nProblem: Macro call that should be transformed by action", "input": "(action (:after node-lisp node bound-variables) (let ((new-vars (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for target := (and (not (member coalton-var bound-variables :test #'eq)) (alias-substitution-target coalton-var aliases)) :collect (cons lisp-var (if target (node-variable-value target) coalton-var))))) (unless (equal new-vars (node-lisp-vars node)) (make-node-lisp :type (node-type node) :vars new-vars :form (node-lisp-form node)))))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-lisp) (lambda (node bound-variables) (declare (type node-lisp node)) (let ((new-vars (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for target := (and (not (member coalton-var bound-variables :test (function eq))) (alias-substitution-target coalton-var aliases)) :collect (cons lisp-var (if target (node-variable-value target) coalton-var))))) (unless (equal new-vars (node-lisp-vars node)) (make-node-lisp :type (node-type node) :vars new-vars :form (node-lisp-form node))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-class some-class (some super classes) ((slot1)) (:accessor-name-package (find-package :nclasses/test.dummy)))\n\nIssue: Macro call that should be transformed by define-class", "input": "(define-class some-class (some super classes) ((slot1)) (:accessor-name-package (find-package :nclasses/test.dummy)))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass some-class (some super classes) ((slot1 :initform nil :accessor slot1 :initarg :slot1))) (unless (fboundp (quote some-class-p)) (define-generic some-class-p (object) #A((75) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `some-class'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote some-class)))) (setf (documentation (quote slot1) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\")) (ignore-errors (setf (documentation (fdefinition (quote slot1)) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf slot1))) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\"))) (find-class (quote some-class) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclass/std test () ((a b)))\n\nProblem: Macro call that should be transformed by defclass/std", "input": "(defclass/std test () ((a b)))", "output": "(defmacro defclass/std (name direct-superclasses direct-slots &rest options\n &environment env)\n \"Shortcut macro to the DEFCLASS macro.\n\n (defclass/std example ()\n ((slot1 slot2 slot3)))\n\n expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\n Each slot definition accepts options:\n\n :std 1 => changes the :initform to 1. It can be :unbound.\n :with or :with-prefix => creates accessors with the class name as prefix.\n\n See the README for more.\n\n See also `class/std' and `print-object/std'.\n \"\n `(defclass ,name ,direct-superclasses\n ,(process-slots env direct-slots name)\n ,@options))", "macroexpand": "(defclass test nil ((a :accessor a :initarg :a :initform nil) (b :accessor b :initarg :b :initform nil)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(\u0192\u2192 nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by \u0191\u2192", "input": "(\u0192\u2192 nil (progn))", "output": "(defmacro \u0191\u2192 ...)", "macroexpand": "(defn nil (progn) (&optional \u03b1)\n (let ((\u03b1 (or \u03b1 t)))\n (cond)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-window-or-instance nil (progn))\n\nIssue: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE", "input": "(make-window-or-instance nil (progn))", "output": "(defmacro MAKE-WINDOW-OR-INSTANCE ...)", "macroexpand": "(make-$instance nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(assoc-cdr \"oauth_verifier\" parameters #'equal)\n\nPattern to recognize: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr \"oauth_verifier\" parameters #'equal)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc \"oauth_verifier\" parameters :test (function equal)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some-<> nil)\n\nProblem: Macro call that should be transformed by SOME-<>", "input": "(some-<> nil)", "output": "(defmacro SOME-<> ...)", "macroexpand": "(let* ((#:g120 nil))\n #:g120)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (= 2 (length s)))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (= 2 (length s)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e259 2) (#:a260 (length s))) (if (progn (= #:e259 #:a260)) (add-result (quote test-passed) :test-expr (quote (= 2 (length s)))) (process-failure (quote (= 2 (length s))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (length s)) #:a260 (quote =) #:e259)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(some-> nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by SOME->", "input": "(some-> nil :key nil)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:|some128| nil)\n (#:|some128| (when #:|some128| (:key #:|some128|)))\n (#:|some128| (when #:|some128| (nil #:|some128|))))\n #:|some128|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-cfun c-realloc)\n\nPattern to recognize: Macro call that should be transformed by define-cfun", "input": "(define-cfun c-realloc)", "output": "(defmacro define-cfun (name-or-function &optional (package *package*))\n (when-let ((fun (find-function name-or-function)))\n (with-wrap-attempt (\"function ~S\" name-or-function) name-or-function\n (with-slots (name type c-symbol fields) fun\n (let* ((fun-name (intern (symbol-name name) package))\n (param-names (mapcar #'foreign-type-name fields))\n (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))\n (make-function-p (not (foreign-function-variadic-p fun)))\n (maybe-cbv-return\n (when (cbv-return-p fun)\n (list 'return-value))))\n (with-gensyms (!fun !fields rest)\n (let ((form\n (if make-function-p\n `(defun ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n ,(let ((!fun (find-function name-or-function)))\n (with-slots ((!fields fields)) !fun\n (foreign-to-ffi\n (and (car !fields) (foreign-type (car !fields)))\n param-syms\n param-names\n !fields\n (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)\n param-syms (when (foreign-function-variadic-p fun) rest))))))\n `(defmacro ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n (let ((,!fun (find-function ',name-or-function)))\n (with-slots ((,!fields fields)) ,!fun\n (foreign-to-ffi\n (and (car ,!fields) (foreign-type (car ,!fields)))\n ',param-syms\n (list ,@param-names)\n ,!fields\n (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)\n ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))\n `(progn\n ,@(when (foreign-function-cbv-p fun)\n (list (funcall *build-libffi-definition* fun)))\n ,form))))))))", "macroexpand": "(progn (defun c-realloc (ptr size) (let ((#:ptr213 ptr)) (declare (ignorable #:ptr213)) (let ((#:size214 size)) (declare (ignorable #:size214)) (cffi-sys:%foreign-funcall \"realloc\" (:pointer #:ptr213 :unsigned-long-long #:size214 :pointer) :convention :cdecl)))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(validate-superclass*)\n\nProblem: Macro call that should be transformed by VALIDATE-SUPERCLASS*", "input": "(validate-superclass*)", "output": "(defmacro VALIDATE-SUPERCLASS* ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-custom-var (:integer *integer-handler*) (constantly 0) \"Designator for a function of 1 string argument (integer token).\")\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:integer *integer-handler*) (constantly 0) \"Designator for a function of 1 string argument (integer token).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*integer-handler* . :integer)) *custom-vars* :test (function equal)) (defvar *integer-handler* (constantly 0) \"Designator for a function of 1 string argument (integer token).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-inference-rule nil\n (progn))\n\nProblem: Macro call that should be transformed by DEFINE-INFERENCE-RULE", "input": "(define-inference-rule nil\n (progn))", "output": "(defmacro DEFINE-INFERENCE-RULE ...)", "macroexpand": "(setf (symbol-inference-rules 'nil)\n (sb-int:named-lambda 'nil\n (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(aif (incf x) it :never)\n\nProblem: Macro call that should be transformed by aif", "input": "(aif (incf x) it :never)", "output": "(defmacro aif (test then &optional else)\n \"Like IF, except binds the result of the test to IT (via LET) for\nthe scope of the then and else expressions.\" \n `(anaphoric if ,test ,then ,else))", "macroexpand": "(anaphoric if (incf x) it :never)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defmethod nil nil)\n\nIssue: Macro call that should be transformed by DEFMETHOD", "input": "(defmethod nil nil)", "output": "(defmacro DEFMETHOD ...)", "macroexpand": "(common-lisp:defmethod nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-condition/a dbi-notsupported-error (dbi-database-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation \"Exception raised if e.g. commit() is called for a database which do not support transactions.\") (:report (lambda (condition stream) (format stream \"`~A' isn't supported on the current driver.\" (slot-value condition 'method-name)))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-condition/a", "input": "(define-condition/a dbi-notsupported-error (dbi-database-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation \"Exception raised if e.g. commit() is called for a database which do not support transactions.\") (:report (lambda (condition stream) (format stream \"`~A' isn't supported on the current driver.\" (slot-value condition 'method-name)))))", "output": "(defmacro define-condition/a (name parent-types slots &body options)\n `(progn\n (define-condition ,name ,parent-types ,slots ,@options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (define-condition dbi-notsupported-error (dbi-database-error) ((method-name :initarg :method-name :type (or symbol string))) (:documentation \"Exception raised if e.g. commit() is called for a database which do not support transactions.\") (:report (lambda (condition stream) (format stream \"`~A' isn't supported on the current driver.\" (slot-value condition (quote method-name)))))) (deftype nil (quote dbi-notsupported-error)) (setf (find-class (quote )) (find-class (quote dbi-notsupported-error))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(@ nil (progn))\n\nPattern to recognize: Macro call that should be transformed by @", "input": "(@ nil (progn))", "output": "(defmacro @ ...)", "macroexpand": "(message-oo.mangle::|PROGN:| nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-prepared-query query (conn (format nil \"SELECT 1 FROM sqlite_master WHERE tbl_name = '~A' AND sql LIKE '%AUTOINCREMENT%'\" table-name)) (and (first (dbi:fetch (dbi:execute query) :format :values)) t))\n\nPattern to recognize: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (conn (format nil \"SELECT 1 FROM sqlite_master WHERE tbl_name = '~A' AND sql LIKE '%AUTOINCREMENT%'\" table-name)) (and (first (dbi:fetch (dbi:execute query) :format :values)) t))", "output": "(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)\n `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))", "macroexpand": "(call-with-prepared-query conn (format nil \"SELECT 1 FROM sqlite_master WHERE tbl_name = '~A' AND sql LIKE '%AUTOINCREMENT%'\" table-name) (lambda (query) (and (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)) t)) :use-prepare-cached nil)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(c-assert (eq :nascent (c-state c)))\n\nWrite a macro that addresses: Macro call that should be transformed by c-assert", "input": "(c-assert (eq :nascent (c-state c)))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (eq :nascent (c-state c)) (c-break \"failed assertion: ~a\" (quote (eq :nascent (c-state c))))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-disable-handler-restart (handler) (with-hook-restart (setf result (multiple-value-list (apply handler result)))))\n\nPattern to recognize: Macro call that should be transformed by with-disable-handler-restart", "input": "(with-disable-handler-restart (handler) (with-hook-restart (setf result (multiple-value-list (apply handler result)))))", "output": "(defmacro with-disable-handler-restart ((handler) &body body)\n \"This is intended to wrap all handler executions.\"\n `(restart-case\n (progn ,@body)\n (disable-handler ()\n :report\n (lambda (stream)\n (format stream \"Disable handler ~a which causes the error.\" ,handler))\n (disable-hook *hook* ,handler))))", "macroexpand": "(restart-case (progn (with-hook-restart (setf result (multiple-value-list (apply handler result))))) (disable-handler nil :report (lambda (stream) (format stream \"Disable handler ~a which causes the error.\" handler)) (disable-hook *hook* handler)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(caching-types\n nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by CACHING-TYPES", "input": "(caching-types\n nil\n :key\n nil)", "output": "(defmacro CACHING-TYPES ...)", "macroexpand": "(call-with-disjoint-hash\n (lambda ()\n (call-with-subtype-hash\n (lambda ()\n (call-with-equiv-hash\n (lambda () (call-with-subtypep-cache (lambda () nil :key nil))))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(answer (foo 1) 2)\n\nWhat needs to change: Macro call that should be transformed by answer", "input": "(answer (foo 1) 2)", "output": "(defmacro answer (call &body forms)\n (let ((name (if (listp call) (car call) call))\n (sym (gensym)))\n `(if-called\n ',name\n (let ((,sym (fdefinition ',name)))\n (declare (ignorable ,sym))\n (let ((times 0))\n (lambda (&rest args)\n (declare (ignorable args))\n ,(let ((cases\n `(case (prog1 times (incf times))\n ,.(loop\n for i from 0\n for (form . rest) on forms\n collect `(,(if rest i T) ,form)))))\n (if (listp call)\n `(trivia:match args\n ((list . ,(cdr call)) ,cases)\n (_ (unhandled)))\n cases))))))))", "macroexpand": "(if-called (quote foo) (let ((#:g160 (fdefinition (quote foo)))) (declare (ignorable #:g160)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (trivia.level2:match args ((list 1) (case (prog1 times (incf times)) (t 2))) (_ (unhandled)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-element-maker :text \"text\" '(:x :y))\n\nWrite a macro that addresses: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :text \"text\" '(:x :y))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :text)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:x :y)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :text missing))))) (defmethod make-svg-element ((element (eql :text)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"text\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n($/ \"[_]*.mr.\" \"i\")\n\nWrite a macro that addresses: Macro call that should be transformed by $", "input": "($/ \"[_]*.mr.\" \"i\")", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(make-bson-regex (empty-str \"[_]*.mr.\") \"i\")", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-value-binding symbols (var package &rest status &aux (iterator (package-iterator package (or status '(:internal :external :inherited)))) next symbol) (declare (type function iterator)) `(multiple-value-bind (,next ,symbol) (funcall ,iterator) (if ,next (setf ,var ,symbol) (end-for))))\n\nWhat needs to change: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding symbols (var package &rest status &aux (iterator (package-iterator package (or status '(:internal :external :inherited)))) next symbol) (declare (type function iterator)) `(multiple-value-bind (,next ,symbol) (funcall ,iterator) (if ,next (setf ,var ,symbol) (end-for))))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding symbols (var package &rest status) (let ((#:iterator164 (gensym #A((8) base-char . \"ITERATOR\"))) (#:next165 (gensym #A((4) base-char . \"NEXT\"))) (#:symbol166 (gensym #A((6) base-char . \"SYMBOL\"))) (#:package162 (gensym #A((7) base-char . \"PACKAGE\"))) (#:status163 (gensym #A((6) base-char . \"STATUS\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:package162 package) (list #:status163 (list* (quote list) status)) (list #:iterator164 (list (quote package-iterator) #:package162 (list (quote or) #:status163 (quote (:internal :external :inherited))))) (list #:next165 nil) (list #:symbol166 nil) (loop for #:var161 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var161 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:iterator164 :kind 0) #S(sb-impl::comma :expr #:next165 :kind 0) #S(sb-impl::comma :expr #:symbol166 :kind 0) #S(sb-impl::comma :expr #:package162 :kind 0) #S(sb-impl::comma :expr #:status163 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote function) :kind 0) #S(sb-impl::comma :expr #:iterator164 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((iterator #:iterator164) (next #:next165) (symbol #:symbol166) (package #:package162) (status #:status163)) (declare (ignorable iterator next symbol package status)) (sb-int:quasiquote (multiple-value-bind (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr symbol :kind 0)) (funcall #S(sb-impl::comma :expr iterator :kind 0)) (if #S(sb-impl::comma :expr next :kind 0) (setf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr symbol :kind 0)) (end-for))))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda-ematch0 ((list* pattern body) (list* (list pattern) body)))\n\nWrite a macro that addresses: Macro call that should be transformed by lambda-ematch0", "input": "(lambda-ematch0 ((list* pattern body) (list* (list pattern) body)))", "output": "(defmacro lambda-ematch0 (&body clauses)\n (alexandria:with-gensyms (arg)\n `(lambda (,arg)\n (ematch0 ,arg\n ,@clauses))))", "macroexpand": "(lambda (#:arg168) (ematch0 #:arg168 ((list* pattern body) (list* (list pattern) body))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-hamt set (:test test :hash hash :table table) (flet ((%insert (table x) (%set-insert table x (funcall hash x) 0 test))) (make-instance 'hash-set :test test :hash hash :table (reduce #'%insert xs :initial-value table))))\n\nProblem: Macro call that should be transformed by with-hamt", "input": "(with-hamt set (:test test :hash hash :table table) (flet ((%insert (table x) (%set-insert table x (funcall hash x) 0 test))) (make-instance 'hash-set :test test :hash hash :table (reduce #'%insert xs :initial-value table))))", "output": "(defmacro with-hamt (hamt (&key test hash table) &body body)\n \"Accessing HAMT slots\"\n `(with-accessors ((,test hamt-test)\n (,hash hamt-hash)\n (,table hamt-table))\n ,hamt\n ,@body))", "macroexpand": "(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) set (flet ((%insert (table x) (%set-insert table x (funcall hash x) 0 test))) (make-instance (quote hash-set) :test test :hash hash :table (reduce (function %insert) xs :initial-value table))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause in (&whole form seq &rest args &key &allow-other-keys &environment env) \"Iterates over a sequence. IN must be used in combination with FOR, GENERATING and similar macros (those that bind *ITERATION-VARIABLE*). In implementations with extensible sequences (currently ABCL and SBCL), native sequence iterators are used, and all sequence types are supported, not just lists and vectors. In other implementations, an iterator specialized for lists or vectors is used depending on the type of sequence. All `args` are passed down to make-sequence-iterator (see the extensible sequences API paper for details [Rhodes2007]). IN can perform destructuring.\" (if (symbolp *iteration-variable*) (let ((state (gensym \"STATE\")) (limit (gensym \"LIMIT\")) (from-end (gensym \"FROM-END\")) (step (gensym \"STEP\")) (endp (gensym \"ENDP\")) (elt (gensym \"ELT\")) (sequence (gensym \"SEQUENCE\"))) `((with (,sequence ,seq) ,state ,limit ,from-end ,step ,endp ,elt) (initially (multiple-value-setq (,state ,limit ,from-end ,step ,endp ,elt) (make-sequence-iterator ,sequence ,@args))) ,(make-step :form `(setf ,state (funcall ,step ,sequence ,state ,from-end))) ,(make-simple-iteration :precondition `(not (funcall ,endp ,sequence ,state ,limit ,from-end)) :init `(funcall ,elt ,sequence ,state) :step `(funcall ,elt ,sequence ,state)))) (expand-with-simple-destructuring form env)))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause in (&whole form seq &rest args &key &allow-other-keys &environment env) \"Iterates over a sequence. IN must be used in combination with FOR, GENERATING and similar macros (those that bind *ITERATION-VARIABLE*). In implementations with extensible sequences (currently ABCL and SBCL), native sequence iterators are used, and all sequence types are supported, not just lists and vectors. In other implementations, an iterator specialized for lists or vectors is used depending on the type of sequence. All `args` are passed down to make-sequence-iterator (see the extensible sequences API paper for details [Rhodes2007]). IN can perform destructuring.\" (if (symbolp *iteration-variable*) (let ((state (gensym \"STATE\")) (limit (gensym \"LIMIT\")) (from-end (gensym \"FROM-END\")) (step (gensym \"STEP\")) (endp (gensym \"ENDP\")) (elt (gensym \"ELT\")) (sequence (gensym \"SEQUENCE\"))) `((with (,sequence ,seq) ,state ,limit ,from-end ,step ,endp ,elt) (initially (multiple-value-setq (,state ,limit ,from-end ,step ,endp ,elt) (make-sequence-iterator ,sequence ,@args))) ,(make-step :form `(setf ,state (funcall ,step ,sequence ,state ,from-end))) ,(make-simple-iteration :precondition `(not (funcall ,endp ,sequence ,state ,limit ,from-end)) :init `(funcall ,elt ,sequence ,state) :step `(funcall ,elt ,sequence ,state)))) (expand-with-simple-destructuring form env)))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro in (&whole form seq &rest args &key &allow-other-keys &environment env) \"Iterates over a sequence. IN must be used in combination with FOR, GENERATING and similar macros (those that bind *ITERATION-VARIABLE*). In implementations with extensible sequences (currently ABCL and SBCL), native sequence iterators are used, and all sequence types are supported, not just lists and vectors. In other implementations, an iterator specialized for lists or vectors is used depending on the type of sequence. All `args` are passed down to make-sequence-iterator (see the extensible sequences API paper for details [Rhodes2007]). IN can perform destructuring.\" (if (symbolp *iteration-variable*) (let ((state (gensym \"STATE\")) (limit (gensym \"LIMIT\")) (from-end (gensym \"FROM-END\")) (step (gensym \"STEP\")) (endp (gensym \"ENDP\")) (elt (gensym \"ELT\")) (sequence (gensym \"SEQUENCE\"))) (sb-int:quasiquote ((with (#S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr seq :kind 0)) #S(sb-impl::comma :expr state :kind 0) #S(sb-impl::comma :expr limit :kind 0) #S(sb-impl::comma :expr from-end :kind 0) #S(sb-impl::comma :expr step :kind 0) #S(sb-impl::comma :expr endp :kind 0) #S(sb-impl::comma :expr elt :kind 0)) (initially (multiple-value-setq (#S(sb-impl::comma :expr state :kind 0) #S(sb-impl::comma :expr limit :kind 0) #S(sb-impl::comma :expr from-end :kind 0) #S(sb-impl::comma :expr step :kind 0) #S(sb-impl::comma :expr endp :kind 0) #S(sb-impl::comma :expr elt :kind 0)) (make-sequence-iterator #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr args :kind 2)))) #S(sb-impl::comma :expr (make-step :form (sb-int:quasiquote (setf #S(sb-impl::comma :expr state :kind 0) (funcall #S(sb-impl::comma :expr step :kind 0) #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr state :kind 0) #S(sb-impl::comma :expr from-end :kind 0))))) :kind 0) #S(sb-impl::comma :expr (make-simple-iteration :precondition (sb-int:quasiquote (not (funcall #S(sb-impl::comma :expr endp :kind 0) #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr state :kind 0) #S(sb-impl::comma :expr limit :kind 0) #S(sb-impl::comma :expr from-end :kind 0)))) :init (sb-int:quasiquote (funcall #S(sb-impl::comma :expr elt :kind 0) #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr state :kind 0))) :step (sb-int:quasiquote (funcall #S(sb-impl::comma :expr elt :kind 0) #S(sb-impl::comma :expr sequence :kind 0) #S(sb-impl::comma :expr state :kind 0)))) :kind 0)))) (expand-with-simple-destructuring form env))) (pushnew (quote in) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-min nil nil)\n\nProblem: Macro call that should be transformed by COLLECT-MIN", "input": "(collect-min nil nil)", "output": "(defmacro COLLECT-MIN ...)", "macroexpand": "(common-lisp:let* ((#:generator-286 (generator nil))\n #:items-276\n (#:generator-284 (generator nil))\n #:numbers-275\n (#:number-278 nil)\n #:result-279)\n (declare (type generator #:generator-286)\n (type generator #:generator-284)\n (type (null-or t) #:result-279))\n (tagbody\n #:ll-287\n (setq #:items-276 (next-in #:generator-286 (go end)))\n (setq #:numbers-275 (next-in #:generator-284 (go end)))\n (if (or (null #:number-278) (> #:number-278 #:numbers-275))\n (setq #:number-278 #:numbers-275\n #:result-279 #:items-276))\n (go #:ll-287)\n end)\n (if (null #:number-278)\n (setq #:result-279 nil))\n #:result-279)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-definition-resolver generic-function designator-generic-function-p)\n\nPattern to recognize: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver generic-function designator-generic-function-p)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver generic-function (generic-function #:package136) (when (ignore-errors (designator-generic-function-p generic-function)) (list (make-instance (quote generic-function) :designator generic-function :package #:package136))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dynamic-relet nil)\n\nProblem: Macro call that should be transformed by DYNAMIC-RELET", "input": "(dynamic-relet nil)", "output": "(defmacro DYNAMIC-RELET ...)", "macroexpand": "(dynamic-wind\n :proceed\n #:proceed188\n (let ()\n (declare (special))\n (#:proceed188)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(between (char #\\!) (string \"Salv\u0113\") (char #\\!))\n\nProblem: Macro call that should be transformed by between", "input": "(between (char #\\!) (string \"Salv\u0113\") (char #\\!))", "output": "(defmacro between (a parser b &key (id nil))\n \"A main parser flanked by two other ones. Only the value of the main parser is\nkept. Good for parsing backets, parentheses, etc.\"\n (declare (ignore id))\n `(*> ,a (<* ,parser ,b)))", "macroexpand": "(*> (char #\\EXCLAMATION_MARK) (<* (string \"Salv\u0113\") (char #\\EXCLAMATION_MARK)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-decoder-simple-clos-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :keyword))))\n\nIssue: Macro call that should be transformed by with-decoder-simple-clos-semantics", "input": "(with-decoder-simple-clos-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :keyword))))", "output": "(defmacro with-decoder-simple-clos-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-CLOS-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-clos-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-clos-semantics) (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :keyword))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-let nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-LET", "input": "(dynamic-let nil\n :key\n nil)", "output": "(defmacro DYNAMIC-LET ...)", "macroexpand": "(let ()\n (dynamic-wind\n :proceed\n #:g195\n (let ()\n (declare (special))\n (#:g195 :key nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(max-of nil)\n\nIssue: Macro call that should be transformed by MAX-OF", "input": "(max-of nil)", "output": "(defmacro MAX-OF ...)", "macroexpand": "(lc (nil) maximize)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defhandler let (let bindings &rest body) (let ((names (loop for binding in bindings collect (force-first binding)))) `(list* ',let (list ,@(loop for binding in bindings collect (if (symbolp binding) `',binding `(list ',(first binding) ,@(e-list (rest binding)))))) (with-imposed-bindings (,let ,names (declare (ignorable ,@names)) (m-list ,@body))))))\n\nPattern to recognize: Macro call that should be transformed by defhandler", "input": "(defhandler let (let bindings &rest body) (let ((names (loop for binding in bindings collect (force-first binding)))) `(list* ',let (list ,@(loop for binding in bindings collect (if (symbolp binding) `',binding `(list ',(first binding) ,@(e-list (rest binding)))))) (with-imposed-bindings (,let ,names (declare (ignorable ,@names)) (m-list ,@body))))))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-let (let bindings &rest body) (let ((names (loop for binding in bindings collect (force-first binding)))) (sb-int:quasiquote (list* (quote #S(sb-impl::comma :expr let :kind 0)) (list #S(sb-impl::comma :expr (loop for binding in bindings collect (if (symbolp binding) (sb-int:quasiquote (quote #S(sb-impl::comma :expr binding :kind 0))) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr (first binding) :kind 0)) #S(sb-impl::comma :expr (e-list (rest binding)) :kind 2))))) :kind 2)) (with-imposed-bindings (#S(sb-impl::comma :expr let :kind 0) #S(sb-impl::comma :expr names :kind 0) (declare (ignorable #S(sb-impl::comma :expr names :kind 2))) (m-list #S(sb-impl::comma :expr body :kind 2)))))))) (setf (gethash (quote let) *form-handler*) (quote hander-let)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(asynchronously (val) (put 2) (flet ((%continue () (continue-flow (+ 1 val)))) (run-it (-> :heh () (funcall #'%continue)))))\n\nProblem: Macro call that should be transformed by asynchronously", "input": "(asynchronously (val) (put 2) (flet ((%continue () (continue-flow (+ 1 val)))) (run-it (-> :heh () (funcall #'%continue)))))", "output": "(defmacro asynchronously (lambda-list &body body)\n \"Splits current flow allowing manually managing its execution via #'continue-flow and\n#'interrupt-flow functions. Consing: ~32 bytes per invocation\"\n (with-gensyms (continue-arg condi)\n (flow-lambda-macro (flow-context)\n (let ((fu-body `((flet ((continue-flow (&optional ,continue-arg)\n (capture-flow-value ,flow-context ,continue-arg)\n (dispatch-rest ,flow-context))\n (interrupt-flow (&optional ,condi)\n (error ,condi)))\n (declare (ignorable (function continue-flow)\n (function interrupt-flow)))\n ,@body))))\n (with-flow-function-macro (body-fu lambda-list fu-body)\n `(dispatch-asynchronously ,flow-context #',body-fu))))))", "macroexpand": "(%flow-lambda (#:flow-context151) (%with-flow-function (#:body-fu152 (val) (flet ((continue-flow (&optional #:continue-arg149) (capture-flow-value #:flow-context151 #:continue-arg149) (dispatch-rest #:flow-context151)) (interrupt-flow (&optional #:condi150) (error #:condi150))) (declare (ignorable (function continue-flow) (function interrupt-flow))) (put 2) (flet ((%continue nil (continue-flow (+ 1 val)))) (run-it (-> :heh nil (funcall (function %continue))))))) (dispatch-asynchronously #:flow-context151 (function #:body-fu152))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun-compile-time indirect-callees-internal (function-names callees) (if (null function-names) callees (let ((function-name (first function-names))) (if (member function-name callees :test #'equal) (indirect-callees-internal (rest function-names) callees) (indirect-callees-internal (rest function-names) (indirect-callees-internal (callees function-name) (cons function-name callees)))))))\n\nWrite a macro that addresses: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time indirect-callees-internal (function-names callees) (if (null function-names) callees (let ((function-name (first function-names))) (if (member function-name callees :test #'equal) (indirect-callees-internal (rest function-names) callees) (indirect-callees-internal (rest function-names) (indirect-callees-internal (callees function-name) (cons function-name callees)))))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun indirect-callees-internal (function-names callees) (if (null function-names) callees (let ((function-name (first function-names))) (if (member function-name callees :test (function equal)) (indirect-callees-internal (rest function-names) callees) (indirect-callees-internal (rest function-names) (indirect-callees-internal (callees function-name) (cons function-name callees))))))) (eval-when (:compile-toplevel) (compile (quote indirect-callees-internal))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-compile-struct sql-statement)\n\nWrite a macro that addresses: Macro call that should be transformed by define-compile-struct", "input": "(define-compile-struct sql-statement)", "output": "(defmacro define-compile-struct (structure-name &rest defstruct-options)\n (flet ((symbolcat (&rest symbols)\n (intern (format nil \"~{~A~^-~}\" symbols) #.*package*)))\n (let ((compiled-name (symbolcat structure-name :compiled)))\n `(progn\n (defstruct (,compiled-name (:include ,structure-name ,@defstruct-options))\n (sql nil :type string)\n (bind nil :type list))\n\n (defmethod find-compile-function ((object ,structure-name))\n (function ,(symbolcat :make compiled-name)))\n\n (defmethod print-object ((object ,compiled-name) stream)\n (format stream \"#\"\n (,(symbolcat compiled-name :sql) object)\n (,(symbolcat compiled-name :bind) object)))\n\n (defmethod yield ((object ,compiled-name))\n (values\n (,(symbolcat compiled-name :sql) object)\n (,(symbolcat compiled-name :bind) object)))))))", "macroexpand": "(progn (defstruct (sql-statement-compiled (:include sql-statement)) (sql nil :type string) (bind nil :type list)) (defmethod find-compile-function ((object sql-statement)) (function make-sql-statement-compiled)) (defmethod print-object ((object sql-statement-compiled) stream) (format stream \"#\" (sql-statement-compiled-sql object) (sql-statement-compiled-bind object))) (defmethod yield ((object sql-statement-compiled)) (values (sql-statement-compiled-sql object) (sql-statement-compiled-bind object))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defalias path:-d (directory) cl-fad:directory-exists-p)\n\nWrite a macro that addresses: Macro call that should be transformed by defalias", "input": "(defalias path:-d (directory) cl-fad:directory-exists-p)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:-d (directory) (directory-exists-p directory)) (define-compiler-macro path:-d (&rest args) (list* (quote directory-exists-p) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.945} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(builder :session (:csrf :form-token \"test_input_name\") #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type \"text/html\") (,(if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test #'string=)) (cdr (assoc \"name\" (request-body-parameters req) :test #'string=)) (html-form env)))))))\n\nIssue: Macro call that should be transformed by builder", "input": "(builder :session (:csrf :form-token \"test_input_name\") #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type \"text/html\") (,(if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test #'string=)) (cdr (assoc \"name\" (request-body-parameters req) :test #'string=)) (html-form env)))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (find-middleware :session) (lambda (#:app210) (funcall (find-middleware :csrf) #:app210 :form-token \"test_input_name\")))) :initial-value (to-app (function (lambda (env) (let ((req (make-request env))) (sb-int:quasiquote (200 (:content-type \"text/html\") (#S(sb-impl::comma :expr (if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test (function string=))) (cdr (assoc \"name\" (request-body-parameters req) :test (function string=))) (html-form env)) :kind 0)))))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defstore add (&rest args))\n\nWhat needs to change: Macro call that should be transformed by defstore", "input": "(defstore add (&rest args))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote add) (quote (&rest args)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-test capture (fail-compile (defun foo () (frob)) style-warning))\n\nIssue: Macro call that should be transformed by define-test", "input": "(define-test capture (fail-compile (defun foo () (frob)) style-warning))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote capture) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote capture) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (fail-compile (defun foo nil (frob)) style-warning))) :parent (quote nil))) (quote capture))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun-compile-time cps-convert-if (antecedent consequent alternate continuation types value? environment) (let ((c (gensym \"CONTINUATION-\")) (dummy-argument (gensym \"DUMMY-\")) (other-arguments (gensym \"OTHER-\"))) (possibly-beta-reduce-funcall `#'(lambda (,c) (declare (magic)) ,(cps-convert antecedent `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) (if ,dummy-argument ,(cps-convert consequent c types value? environment) ,(cps-convert alternate c types value? environment))) '() t environment)) '() continuation t)))\n\nIssue: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time cps-convert-if (antecedent consequent alternate continuation types value? environment) (let ((c (gensym \"CONTINUATION-\")) (dummy-argument (gensym \"DUMMY-\")) (other-arguments (gensym \"OTHER-\"))) (possibly-beta-reduce-funcall `#'(lambda (,c) (declare (magic)) ,(cps-convert antecedent `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) (if ,dummy-argument ,(cps-convert consequent c types value? environment) ,(cps-convert alternate c types value? environment))) '() t environment)) '() continuation t)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun cps-convert-if (antecedent consequent alternate continuation types value? environment) (let ((c (gensym \"CONTINUATION-\")) (dummy-argument (gensym \"DUMMY-\")) (other-arguments (gensym \"OTHER-\"))) (possibly-beta-reduce-funcall (sb-int:quasiquote (function (lambda (#S(sb-impl::comma :expr c :kind 0)) (declare (magic)) #S(sb-impl::comma :expr (cps-convert antecedent (sb-int:quasiquote (function (lambda (&optional #S(sb-impl::comma :expr dummy-argument :kind 0) &rest #S(sb-impl::comma :expr other-arguments :kind 0)) (declare (magic) (ignore #S(sb-impl::comma :expr other-arguments :kind 0))) (if #S(sb-impl::comma :expr dummy-argument :kind 0) #S(sb-impl::comma :expr (cps-convert consequent c types value? environment) :kind 0) #S(sb-impl::comma :expr (cps-convert alternate c types value? environment) :kind 0))))) (quote nil) t environment) :kind 0)))) (quote nil) continuation t))) (eval-when (:compile-toplevel) (compile (quote cps-convert-if))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause collecting-into (vars &rest args &key initially by finally) \"Synonym for accumulating-to.\" (declare (ignore initially by finally)) `(accumulating-to ,vars ,@args))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause collecting-into (vars &rest args &key initially by finally) \"Synonym for accumulating-to.\" (declare (ignore initially by finally)) `(accumulating-to ,vars ,@args))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro collecting-into (vars &rest args &key initially by finally) \"Synonym for accumulating-to.\" (declare (ignore initially by finally)) (sb-int:quasiquote (accumulating-to #S(sb-impl::comma :expr vars :kind 0) #S(sb-impl::comma :expr args :kind 2)))) (pushnew (quote collecting-into) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-language-macro nil)\n\nPattern to recognize: Macro call that should be transformed by DEFINE-LANGUAGE-MACRO", "input": "(define-language-macro nil)", "output": "(defmacro DEFINE-LANGUAGE-MACRO ...)", "macroexpand": "(defmacro nil (&whole whole &body body)\n (declare (ignore body))\n `(macrolet ((,(car whole) (&body body)\n (let* ((lang (make-instance ',(car whole)))\n (env (top-level-environment lang)))\n (codegen-text (sexp->ops lang body env) ,*pretty*))))\n ,@(if *pretty*\n `((let ((*text-pretty-printer* (get-pretty-printer)))\n ,whole))\n `(,whole))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder (:static :path nil :root (asdf:system-relative-pathname :lack #P\"data/\")) (lambda (env) (declare (ignore env)) `(200 (:content-type \"text/plain\") (\"ok\"))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder (:static :path nil :root (asdf:system-relative-pathname :lack #P\"data/\")) (lambda (env) (declare (ignore env)) `(200 (:content-type \"text/plain\") (\"ok\"))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app228) (funcall (find-middleware :static) #:app228 :path nil :root (asdf/system:system-relative-pathname :lack #P\"data/\"))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (\"ok\"))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(and nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by AND", "input": "(and nil :key nil)", "output": "(defmacro AND ...)", "macroexpand": "(if (if nil\n :key)\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(fnn nil (progn))\n\nWhat needs to change: Macro call that should be transformed by FNN", "input": "(fnn nil (progn))", "output": "(defmacro FNN ...)", "macroexpand": "(lambda () (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(->* 'some-name)\n\nProblem: Macro call that should be transformed by ->*", "input": "(->* 'some-name)", "output": "(defmacro ->* ...)", "macroexpand": "(-> 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with nil)\n\nIssue: Macro call that should be transformed by WITH", "input": "(with nil)", "output": "(defmacro WITH ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword))) (is (equalp '((:hello-key . \"hej\") (:*hi-starts-with-upper-case . \"tjena\") (:+json+-all-capitals . \"totae majusculae\") (:+two-words+ . \"duo verba\") (:camel-case--*mixed--+4-parts+ . \"partes miscella quatuor\")) (decode-json-from-string \" { \\\"helloKey\\\" : \\\"hej\\\" , \\\"HiStartsWithUpperCase\\\" : \\\"tjena\\\", \\\"JSONAllCapitals\\\": \\\"totae majusculae\\\", \\\"TWO_WORDS\\\": \\\"duo verba\\\", \\\"camelCase_Mixed_4_PARTS\\\": \\\"partes miscella quatuor\\\" }\")))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword))) (is (equalp '((:hello-key . \"hej\") (:*hi-starts-with-upper-case . \"tjena\") (:+json+-all-capitals . \"totae majusculae\") (:+two-words+ . \"duo verba\") (:camel-case--*mixed--+4-parts+ . \"partes miscella quatuor\")) (decode-json-from-string \" { \\\"helloKey\\\" : \\\"hej\\\" , \\\"HiStartsWithUpperCase\\\" : \\\"tjena\\\", \\\"JSONAllCapitals\\\": \\\"totae majusculae\\\", \\\"TWO_WORDS\\\": \\\"duo verba\\\", \\\"camelCase_Mixed_4_PARTS\\\": \\\"partes miscella quatuor\\\" }\")))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (let ((*json-symbols-package* (find-package :keyword))) (is (equalp (quote ((:hello-key . \"hej\") (:*hi-starts-with-upper-case . \"tjena\") (:+json+-all-capitals . \"totae majusculae\") (:+two-words+ . \"duo verba\") (:camel-case--*mixed--+4-parts+ . \"partes miscella quatuor\"))) (decode-json-from-string \" { \\\"helloKey\\\" : \\\"hej\\\" , \\\"HiStartsWithUpperCase\\\" : \\\"tjena\\\", \\\"JSONAllCapitals\\\": \\\"totae majusculae\\\", \\\"TWO_WORDS\\\": \\\"duo verba\\\", \\\"camelCase_Mixed_4_PARTS\\\": \\\"partes miscella quatuor\\\" }\")))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-alist-cache content-encoding-cache)\n\nPattern to recognize: Macro call that should be transformed by define-alist-cache", "input": "(define-alist-cache content-encoding-cache)", "output": "(defmacro define-alist-cache (cache-name)\n (let ((var (intern (format nil \"*~A*\" cache-name))))\n `(progn\n (defvar ,var)\n (defun ,(intern (format nil \"LOOKUP-IN-~A\" cache-name)) (elt)\n (when (boundp ',var)\n (alexandria:assoc-value ,var elt)))\n (defun (setf ,(intern (format nil \"LOOKUP-IN-~A\" cache-name))) (val elt)\n (when (boundp ',var)\n (setf (alexandria:assoc-value ,var elt) val))\n val))))", "macroexpand": "(progn (defvar *content-encoding-cache*) (defun lookup-in-content-encoding-cache (elt) (when (boundp (quote *content-encoding-cache*)) (assoc-value *content-encoding-cache* elt))) (defun (setf lookup-in-content-encoding-cache) (val elt) (when (boundp (quote *content-encoding-cache*)) (setf (assoc-value *content-encoding-cache* elt) val)) val))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-unique-names (value) (values `((,name (,value) (when ,value (incf ,var)))) `((inline ,name))))\n\nPattern to recognize: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (value) (values `((,name (,value) (when ,value (incf ,var)))) `((inline ,name))))", "output": "(defmacro with-unique-names (names &body body)\n `(let ,(mapcar (lambda (sym)\n `(,sym (gensym ,(symbol-name sym))))\n names)\n ,@body))", "macroexpand": "(let ((value (gensym #A((5) base-char . \"VALUE\")))) (values (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (when #S(sb-impl::comma :expr value :kind 0) (incf #S(sb-impl::comma :expr var :kind 0)))))) (quasiquote ((inline #S(sb-impl::comma :expr name :kind 0))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(js-inline)\n\nWrite a macro that addresses: Macro call that should be transformed by JS-INLINE", "input": "(js-inline)", "output": "(defmacro JS-INLINE ...)", "macroexpand": "(js-inline* '(progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(->>)\n\nIssue: Macro call that should be transformed by ->>", "input": "(->>)", "output": "(defmacro ->> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(in-package nil)\n\nProblem: Macro call that should be transformed by IN-PACKAGE", "input": "(in-package nil)", "output": "(defmacro IN-PACKAGE ...)", "macroexpand": "(common-lisp:in-package #A((3) base-char . \"NIL\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(signals circular-dependency (run 'circular-0))\n\nPattern to recognize: Macro call that should be transformed by signals", "input": "(signals circular-dependency (run 'circular-0))", "output": "(defmacro signals (condition-spec\n &body body)\n \"Generates a pass if BODY signals a condition of type\nCONDITION. BODY is evaluated in a block named NIL, CONDITION is\nnot evaluated.\"\n (let ((block-name (gensym)))\n (destructuring-bind (condition &optional reason-control &rest reason-args)\n (ensure-list condition-spec)\n `(block ,block-name\n (handler-bind ((,condition (lambda (c)\n (declare (ignore c))\n ;; ok, body threw condition\n (add-result 'test-passed\n :test-expr ',condition)\n (return-from ,block-name t))))\n (block nil\n ,@body))\n (process-failure\n ',condition\n ,@(if reason-control\n `(,reason-control ,@reason-args)\n `(\"Failed to signal a ~S\" ',condition)))\n (return-from ,block-name nil)))))", "macroexpand": "(block #:g287 (handler-bind ((circular-dependency (lambda (c) (declare (ignore c)) (add-result (quote test-passed) :test-expr (quote circular-dependency)) (return-from #:g287 t)))) (block nil (run (quote circular-0)))) (process-failure (quote circular-dependency) \"Failed to signal a ~S\" (quote circular-dependency)) (return-from #:g287 nil))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-api merge-readtables-into (result-readtable &rest named-readtables) (named-readtable-designator &rest named-readtable-designator => readtable) \"Copy macro character definitions of each readtable in NAMED-READTABLES into RESULT-READTABLE. If a macro character appears in more than one of the readtables, i.e. if a conflict is discovered during the merge, an error of type READER-MACRO-CONFLICT is signaled. The copied options are :DISPATCH-MACRO-CHAR, :MACRO-CHAR and :SYNTAX-FROM, but not READTABLE-CASE.\" (flet ((merge-into (to from) (do-readtable ((char reader-fn non-terminating-p disp? table) from) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to))))) to)) (let ((result-table (ensure-readtable result-readtable))) (dolist (table (mapcar #'ensure-readtable named-readtables)) (merge-into result-table table)) result-table)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-api", "input": "(define-api merge-readtables-into (result-readtable &rest named-readtables) (named-readtable-designator &rest named-readtable-designator => readtable) \"Copy macro character definitions of each readtable in NAMED-READTABLES into RESULT-READTABLE. If a macro character appears in more than one of the readtables, i.e. if a conflict is discovered during the merge, an error of type READER-MACRO-CONFLICT is signaled. The copied options are :DISPATCH-MACRO-CHAR, :MACRO-CHAR and :SYNTAX-FROM, but not READTABLE-CASE.\" (flet ((merge-into (to from) (do-readtable ((char reader-fn non-terminating-p disp? table) from) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to))))) to)) (let ((result-table (ensure-readtable result-readtable))) (dolist (table (mapcar #'ensure-readtable named-readtables)) (merge-into result-table table)) result-table)))", "output": "(defmacro define-api (name lambda-list type-list &body body)\n (flet ((parse-type-list (type-list)\n (let ((pos (position '=> type-list)))\n (assert pos () \"You forgot to specify return type (`=>' missing.)\")\n (values (subseq type-list 0 pos)\n `(values ,@(nthcdr (1+ pos) type-list) &optional)))))\n (multiple-value-bind (body decls docstring)\n (parse-body body :documentation t :whole `(define-api ,name))\n (multiple-value-bind (arg-typespec value-typespec)\n (parse-type-list type-list)\n (multiple-value-bind (reqs opts rest keys)\n (parse-ordinary-lambda-list lambda-list)\n (declare (ignorable reqs opts rest keys))\n `(progn\n (declaim (ftype (function ,arg-typespec ,value-typespec) ,name))\n (locally\n ;; Muffle the annoying \"&OPTIONAL and &KEY found in\n ;; the same lambda list\" style-warning\n #+sbcl (declare (sb-ext:muffle-conditions style-warning))\n (defun ,name ,lambda-list\n ,docstring\n ,@decls\n (locally\n #+sbcl (declare (sb-ext:unmuffle-conditions style-warning))\n\n ;; SBCL will interpret the ftype declaration as\n ;; assertion and will insert type checks for us.\n #-sbcl\n (progn\n ;; CHECK-TYPE required parameters\n ,@(loop for req-arg in reqs\n for req-type = (pop type-list)\n do (assert req-type)\n collect `(check-type ,req-arg ,req-type))\n\n ;; CHECK-TYPE optional parameters\n ,@(progn\n (assert (or (null opts)\n (eq (pop type-list) '&optional)))\n (loop for (opt-arg . nil) in opts\n for opt-type = (pop type-list)\n do (assert opt-type)\n collect `(check-type ,opt-arg ,opt-type)))\n\n ;; CHECK-TYPE rest parameter\n ,@(when rest\n (assert (eq (pop type-list) '&rest))\n (let ((rest-type (pop type-list)))\n (assert rest-type)\n `((dolist (x ,rest)\n (check-type x ,rest-type)))))\n\n ;; CHECK-TYPE key parameters\n ,@(progn\n (assert (or (null keys)\n (eq (pop type-list) '&key)))\n (loop for ((keyword key-arg) . nil) in keys\n for (nil key-type) = (find keyword type-list\n :key #'car)\n collect `(check-type ,key-arg ,key-type))))\n\n ,@body)))))))))", "macroexpand": "(progn (declaim (ftype (function (named-readtable-designator &rest named-readtable-designator) (values readtable &optional)) merge-readtables-into)) (locally (declare (sb-ext:muffle-conditions style-warning)) (defun merge-readtables-into (result-readtable &rest named-readtables) \"Copy macro character definitions of each readtable in NAMED-READTABLES into RESULT-READTABLE. If a macro character appears in more than one of the readtables, i.e. if a conflict is discovered during the merge, an error of type READER-MACRO-CONFLICT is signaled. The copied options are :DISPATCH-MACRO-CHAR, :MACRO-CHAR and :SYNTAX-FROM, but not READTABLE-CASE.\" (locally (declare (sb-ext:unmuffle-conditions style-warning)) (flet ((merge-into (to from) (do-readtable ((char reader-fn non-terminating-p disp? table) from) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to))))) to)) (let ((result-table (ensure-readtable result-readtable))) (dolist (table (mapcar (function ensure-readtable) named-readtables)) (merge-into result-table table)) result-table))))))", "category": "efficiency", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-rewrite cddddr (expr) `(cdr (cdddr ,(second expr))))\n\nPattern to recognize: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cddddr (expr) `(cdr (cdddr ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cddddr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cdddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n($map-reduce \"foo\" m r :out \"testit\" :query ($> \"l\" -900) :limit 2)\n\nIssue: Macro call that should be transformed by $map-reduce", "input": "($map-reduce \"foo\" m r :out \"testit\" :query ($> \"l\" -900) :limit 2)", "output": "(defmacro $map-reduce (collection map reduce &key (query nil) (limit 0) (out nil) \n\t\t (keeptemp nil) (finalize nil) (verbose t))\n \"Run map reduce on the mongo server. map and reduce are either the names of the \njavascript functions, created with defjs or defsrvjs or are function definitions in javascript.\nThe keywords refer to option available for map reduce in mongo. This returns a result summary document.\nWhen using :keeptemp t without specificing :out the collection is mr. \"\n `(db.find \"$cmd\" (kv (kv \"mapreduce\" ,collection) \n\t\t\t (kv \"map\" (or (jsdef ,map) ',map))\n\t\t\t (kv \"reduce\" (or (jsdef ,reduce) ',reduce))\n\t\t\t (when ,finalize (kv \"finalize\" (jsdef ,finalize)))\n\t\t\t (kv \"out\" (if ,out ,out (concatenate 'string \"mr.\" ,collection))) \n\t\t\t (kv \"verbose\" ,verbose)\n\t\t\t (kv \"limit\" ,limit)\n\t\t\t (kv \"keeptemp\" ,keeptemp)\n\t\t\t (kv \"query\" ,query))))", "macroexpand": "(db.find \"$cmd\" (kv (kv \"mapreduce\" \"foo\") (kv \"map\" (or (jsdef m) (quote m))) (kv \"reduce\" (or (jsdef r) (quote r))) (when nil (kv \"finalize\" (jsdef nil))) (kv \"out\" (if \"testit\" \"testit\" (concatenate (quote string) \"mr.\" \"foo\"))) (kv \"verbose\" t) (kv \"limit\" 2) (kv \"keeptemp\" nil) (kv \"query\" ($> \"l\" -900))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ct-let* nil)\n\nIssue: Macro call that should be transformed by CT-LET*", "input": "(ct-let* nil)", "output": "(defmacro CT-LET* ...)", "macroexpand": "(cond (*within-captured-dynenv* (progn))\n (t\n (error\n \"No macrodynamic environment has been captured to establish CT-LET* bindings.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defmacro* nil\n nil)\n\nProblem: Macro call that should be transformed by DEFMACRO*", "input": "(defmacro* nil\n nil)", "output": "(defmacro DEFMACRO* ...)", "macroexpand": "(defmacro nil () `(with-yield))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defvar-unbound *saw-backslash* \"Whether we have to re-process an \\L or \\U because it closes several scopes.\")\n\nWrite a macro that addresses: Macro call that should be transformed by defvar-unbound", "input": "(defvar-unbound *saw-backslash* \"Whether we have to re-process an \\L or \\U because it closes several scopes.\")", "output": "(defmacro defvar-unbound (variable-name documentation)\n \"Like DEFVAR, but the variable will be unbound rather than getting\nan initial value. This is useful for variables which should have no\nglobal value but might have a dynamically bound value.\"\n ;; stolen from comp.lang.lisp article by\n ;; \"prunesquallor@comcast.net\"\n `(eval-when (:load-toplevel :compile-toplevel :execute)\n (defvar ,variable-name)\n (setf (documentation ',variable-name 'variable)\n ,documentation)))", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *saw-backslash*) (setf (documentation (quote *saw-backslash*) (quote variable)) \"Whether we have to re-process an L or U because it closes several scopes.\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(check-cursor-attached cluffer:forward-item (cursor))\n\nWrite a macro that addresses: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:forward-item (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:forward-item :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect-sum nil)\n\nWhat needs to change: Macro call that should be transformed by COLLECT-SUM", "input": "(collect-sum nil)", "output": "(defmacro COLLECT-SUM ...)", "macroexpand": "(common-lisp:let* ((#:generator-236 (generator nil))\n #:numbers-232\n (#:sum-233 0))\n (declare (type generator #:generator-236)\n (type number #:sum-233))\n (tagbody\n #:ll-237\n (setq #:numbers-232 (next-in #:generator-236 (go end)))\n (setq #:sum-233 (+ #:sum-233 #:numbers-232))\n (go #:ll-237)\n end)\n #:sum-233)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defsynonym always :always)\n\nWrite a macro that addresses: Macro call that should be transformed by defsynonym", "input": "(defsynonym always :always)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote always) (quote synonym)) (quote :always)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun* nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFUN*", "input": "(defun* nil\n nil)", "output": "(defmacro DEFUN* ...)", "macroexpand": "(progn (declaim (ftype (function nil t) nil)) (defun nil (the t ())))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(dict-of nil nil)\n\nPattern to recognize: Macro call that should be transformed by DICT-OF", "input": "(dict-of nil nil)", "output": "(defmacro DICT-OF ...)", "macroexpand": "(let ((#:dict125 (make-hash-table :test 'equal)))\n (do-for (nil)\n (multiple-value-call\n (lambda (#:k126 #:v127) (setf (gethash #:k126 #:dict125) #:v127))\n nil))\n #:dict125)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"42703\" undefined-column syntax-error-or-access-violation)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"42703\" undefined-column syntax-error-or-access-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition undefined-column (syntax-error-or-access-violation) nil) (setf (gethash \"42703\" *error-table*) (quote undefined-column)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-compile-time cps-convert-let* (bindings body declarations continuation types value? environment) (if (null bindings) (if (null declarations) (cps-convert-progn body continuation types value? environment) `(let () ,@declarations ,(cps-convert-progn body continuation types value? environment))) (let* ((binding (first bindings)) (binding-variable (if (symbolp binding) binding (first binding))) (binding-form (if (and (consp binding) (= (length binding) 2)) (second binding) nil)) (other-arguments (gensym \"OTHER-\"))) (cps-convert binding-form `#'(lambda (&optional ,binding-variable &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) ,(cps-convert-let* (rest bindings) body declarations continuation types value? environment)) '() t environment))))\n\nWhat needs to change: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time cps-convert-let* (bindings body declarations continuation types value? environment) (if (null bindings) (if (null declarations) (cps-convert-progn body continuation types value? environment) `(let () ,@declarations ,(cps-convert-progn body continuation types value? environment))) (let* ((binding (first bindings)) (binding-variable (if (symbolp binding) binding (first binding))) (binding-form (if (and (consp binding) (= (length binding) 2)) (second binding) nil)) (other-arguments (gensym \"OTHER-\"))) (cps-convert binding-form `#'(lambda (&optional ,binding-variable &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) ,(cps-convert-let* (rest bindings) body declarations continuation types value? environment)) '() t environment))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun cps-convert-let* (bindings body declarations continuation types value? environment) (if (null bindings) (if (null declarations) (cps-convert-progn body continuation types value? environment) (sb-int:quasiquote (let nil #S(sb-impl::comma :expr declarations :kind 2) #S(sb-impl::comma :expr (cps-convert-progn body continuation types value? environment) :kind 0)))) (let* ((binding (first bindings)) (binding-variable (if (symbolp binding) binding (first binding))) (binding-form (if (and (consp binding) (= (length binding) 2)) (second binding) nil)) (other-arguments (gensym \"OTHER-\"))) (cps-convert binding-form (sb-int:quasiquote (function (lambda (&optional #S(sb-impl::comma :expr binding-variable :kind 0) &rest #S(sb-impl::comma :expr other-arguments :kind 0)) (declare (magic) (ignore #S(sb-impl::comma :expr other-arguments :kind 0))) #S(sb-impl::comma :expr (cps-convert-let* (rest bindings) body declarations continuation types value? environment) :kind 0)))) (quote nil) t environment)))) (eval-when (:compile-toplevel) (compile (quote cps-convert-let*))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-op (:* conjunctive-op))\n\nWrite a macro that addresses: Macro call that should be transformed by define-op", "input": "(define-op (:* conjunctive-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (*-op (:include conjunctive-op (name \"*\")) (:constructor make-*-op (&rest expressions))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-syntax)\n\nPattern to recognize: Macro call that should be transformed by enable-syntax", "input": "(enable-syntax)", "output": "(defmacro enable-syntax ()\n '(in-readtable datafly-syntax))", "macroexpand": "(in-readtable datafly-syntax)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(bind (((:plist (start _ 0) end (fuzz fuzziness 'no)) plist)) (list start end fuzz))\n\nWhat needs to change: Macro call that should be transformed by bind", "input": "(bind (((:plist (start _ 0) end (fuzz fuzziness 'no)) plist)) (list start end fuzz))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-163| plist) (start (getf #:|values-163| :start 0)) (end (getf #:|values-163| :end)) (fuzz (getf #:|values-163| :fuzziness (quote no)))) (declare (ignorable #:|values-163|)) (progn (list start end fuzz)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is eql a 'c)\n\nProblem: Macro call that should be transformed by is", "input": "(is eql a 'c)", "output": "(defmacro is (comp expected form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(is ,comp ,expected ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected ,expected\n :comparison ,(maybe-quote comp)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is eql a (quote c))) :value-form (quote (quote c)) :body (lambda nil (quote c)) :expected a :comparison (quote eql)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-custom-var (:internal-decoder *internal-decoder*) 'decode-json \"Designator for a function of 1 stream argument called (instead of DECODE-JSON) to decode a member of an Array or of an Object.\")\n\nProblem: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:internal-decoder *internal-decoder*) 'decode-json \"Designator for a function of 1 stream argument called (instead of DECODE-JSON) to decode a member of an Array or of an Object.\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*internal-decoder* . :internal-decoder)) *custom-vars* :test (function equal)) (defvar *internal-decoder* (quote decode-json) \"Designator for a function of 1 stream argument called (instead of DECODE-JSON) to decode a member of an Array or of an Object.\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-quasi-quoted-string-to-binary-emitting-form-syntax 'some-name)\n\nProblem: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX", "input": "(enable-quasi-quoted-string-to-binary-emitting-form-syntax 'some-name)", "output": "(defmacro ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-string-to-binary-emitting-form-syntax-in-readtable\n 'some-name :with-inline-emitting nil :declarations 'nil :start-character nil\n :end-character nil :unquote-character #\\COMMA :splice-character\n #\\COMMERCIAL_AT :destructive-splice-character #\\FULL_STOP\n :dispatched-quasi-quote-name \"str\" :encoding *default-character-encoding*)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defpackage nil (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFPACKAGE", "input": "(defpackage nil (progn))", "output": "(defmacro DEFPACKAGE ...)", "macroexpand": "(common-lisp:defpackage nil\n (:use :adhoc :closer-mop :cl)\n (:shadowing-import-from :closer-mop\n #:defmethod\n #:standard-generic-function\n #:defgeneric\n #:standard-method\n #:standard-class)\n (:shadowing-import-from :adhoc #:defpackage #:variable #:the)\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-rules nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by WITH-RULES", "input": "(with-rules nil\n :key\n nil)", "output": "(defmacro WITH-RULES ...)", "macroexpand": "(dolist (nil (alexandria:hash-table-keys cl-rules.core::*rules*)) :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(some->>\n nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by SOME->>", "input": "(some->>\n nil\n :key\n nil)", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:var201 nil)\n (#:var202\n (if #:var201\n (:key #:var201)\n nil))\n (#:var203\n (if #:var202\n (nil #:var202)\n nil)))\n #:var203)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun/1 putchar (c) (fputc c stdout))\n\nProblem: Macro call that should be transformed by defun/1", "input": "(defun/1 putchar (c) (fputc c stdout))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun putchar (c) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (fputc c stdout)) (defparameter putchar (vacietis.c:mkptr& (symbol-function (quote putchar)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(matrix-case 'some-name)\n\nPattern to recognize: Macro call that should be transformed by MATRIX-CASE", "input": "(matrix-case 'some-name)", "output": "(defmacro MATRIX-CASE ...)", "macroexpand": "(let ((#:g247 quote))\n (case #:g247))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defreply nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFREPLY", "input": "(defreply nil\n nil)", "output": "(defmacro DEFREPLY ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel)\n (unless (fboundp 'nil)\n (warn 'automatic-message-creation :message-name 'nil)\n (ensure-message 'nil :lambda-list 'nil)))\n (ensure-reply 'nil :qualifiers 'nil :lambda-list 'nil :participants (list)\n :documentation nil :function\n (lambda (#:args136 #:next-replies137 &rest #:more-args139)\n (declare\n (ignorable #:args136 #:next-replies137 #:more-args139))\n (flet ((next-reply-p ()\n (not (null #:next-replies137)))\n (call-next-reply (&rest args)\n (if (null #:next-replies137)\n (apply 'no-next-reply\n (getf #:more-args139 :message)\n (getf #:more-args139 :reply)\n (or args #:args136))\n (apply (reply-function (car #:next-replies137))\n (or args #:args136)\n (cdr #:next-replies137) #:more-args139))))\n (declare\n (ignorable (function next-reply-p)\n (function call-next-reply)))\n (flet ((#:reply-function138 ()\n (declare (ignorable))\n (block nil)))\n (declare (inline #:reply-function138))\n (apply #'#:reply-function138 #:args136))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(*> #'integer (opt (*> (char #\\.) (take-while1 #'digit?))))\n\nPattern to recognize: Macro call that should be transformed by *>", "input": "(*> #'integer (opt (*> (char #\\.) (take-while1 #'digit?))))", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset215) (multiple-value-bind (#:*>-res216 #:*>-next217) (funcall (function integer) #:*>-offset215) (if (ok? #:*>-res216) (funcall (opt (*> (char #\\FULL_STOP) (take-while1 (function digit?)))) #:*>-next217) (fail #:*>-next217))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-html-string (:xy \"Hello\"))\n\nIssue: Macro call that should be transformed by with-html", "input": "(with-html-string (:xy \"Hello\"))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:xy \"Hello\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(maybe-once-only nil\n nil)\n\nProblem: Macro call that should be transformed by MAYBE-ONCE-ONLY", "input": "(maybe-once-only nil\n nil)", "output": "(defmacro MAYBE-ONCE-ONLY ...)", "macroexpand": "(let* ((#:g182 nil))\n `(let* ,(nreverse #:g182)\n ,nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(flow-lambda-macro (flow-context) (with-flow-function-macro (body-fu lambda-list body) `(dispatch-dynamically ,flow-context #',body-fu)))\n\nProblem: Macro call that should be transformed by flow-lambda-macro", "input": "(flow-lambda-macro (flow-context) (with-flow-function-macro (body-fu lambda-list body) `(dispatch-dynamically ,flow-context #',body-fu)))", "output": "(defmacro flow-lambda-macro ((flow-context) &body body)\n `(with-gensyms (,flow-context)\n `(%flow-lambda (,,flow-context)\n ,,@body)))", "macroexpand": "(with-gensyms (flow-context) (sb-int:quasiquote (%flow-lambda (#S(sb-impl::comma :expr flow-context :kind 0)) #S(sb-impl::comma :expr (with-flow-function-macro (body-fu lambda-list body) (sb-int:quasiquote (dispatch-dynamically #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr body-fu :kind 0))))) :kind 0))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-element-maker :radial-gradient \"radialGradient\" '(:id :cx :cy :r))\n\nPattern to recognize: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :radial-gradient \"radialGradient\" '(:id :cx :cy :r))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :radial-gradient)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:id :cx :cy :r)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :radial-gradient missing))))) (defmethod make-svg-element ((element (eql :radial-gradient)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"radialGradient\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-context (context) (process-response this result))\n\nIssue: Macro call that should be transformed by with-context", "input": "(with-context (context) (process-response this result))", "output": "(defmacro with-context ((context) &body body)\n `(let* ((*context* ,context)\n (*request* (context :request))\n (*response* (context :response))\n (*session* (context :session)))\n ,@body))", "macroexpand": "(let* ((*context* context) (*request* (context :request)) (*response* (context :response)) (*session* (context :session))) (process-response this result))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-neo4j-fun query-index ((type :node) name query) :get (:uri-spec (format nil \"index/~A/~A/?query=~A\" (string-downcase (symbol-name type)) name (urlencode query))) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'index-entry-not-found-error :uri uri))))\n\nProblem: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun query-index ((type :node) name query) :get (:uri-spec (format nil \"index/~A/~A/?query=~A\" (string-downcase (symbol-name type)) name (urlencode query))) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'index-entry-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun query-index (&key (type :node) name query) (let ((uri (format nil \"index/~A/~A/?query=~A\" (string-downcase (symbol-name type)) name (urlencode query))) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote index-entry-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(receive () (values) nil)\n\nWhat needs to change: Macro call that should be transformed by receive", "input": "(receive () (values) nil)", "output": "(defmacro receive (formals expr &body body)\n \"Stricter version of `multiple-value-bind'.\n\nUse `receive' when you want to enforce that EXPR should return a\ncertain number of values, or a minimum number of values.\n\nIf FORMALS is a proper list, then EXPR must return exactly as many\nvalues -- no more and no less -- as there are variables in FORMALS.\n\nIf FORMALS is an improper list (VARS . REST), then EXPR must return at\nleast as many values as there are VARS, and any further values are\nbound, as a list, to REST.\n\nLastly, if FORMALS is a symbol, bind that symbol to all the values\nreturned by EXPR, as if by `multiple-value-list'.\n\nFrom Scheme (SRFI-8).\"\n ;; It's probably not worth stack-allocating the thunk.\n (cond ((null formals)\n `(multiple-value-call\n (lambda ()\n ,@body)\n ,expr))\n ((atom formals)\n ;; This could also be written:\n #+(or) `(let ((,formals (multiple-value-list ,expr)))\n ,@body)\n ;; But I want it to be possible to declare FORMALS to have\n ;; dynamic extent, and most Lisps support that for &rest\n ;; lists.\n `(multiple-value-call\n (lambda (&rest ,formals)\n ,@body)\n ,expr))\n ((proper-list-p formals)\n (when (intersection formals lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda ,formals\n ,@body)\n ,expr))\n (t (let* ((last (last formals))\n (vars (append (butlast formals)\n (list (car last))))\n (rest (cdr last)))\n (when (intersection (cons rest vars) lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda (,@vars &rest ,rest)\n ,@body)\n ,expr)))))", "macroexpand": "(multiple-value-call (lambda nil nil) (values))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defmethod* nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil\n :key\n nil)", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(defmethod :key nil (the t ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(send nil (progn))\n\nIssue: Macro call that should be transformed by SEND", "input": "(send nil (progn))", "output": "(defmacro SEND ...)", "macroexpand": "(send (funcall (slot-value nil 'progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-assert-observers (\"deleting foo\" foo foo+1) (store-remove :foo store))\n\nPattern to recognize: Macro call that should be transformed by with-assert-observers", "input": "(with-assert-observers (\"deleting foo\" foo foo+1) (store-remove :foo store))", "output": "(defmacro with-assert-observers ((desc &rest asserted-observers) &body body) \n `(let ((*observers* nil))\n (trc ,desc \" -- checking observers\")\n ,@body\n (let ((superfluous-observers (loop for run in *observers* if (not (member run (list ,@asserted-observers))) collect run))\n\t (failed-observers (loop for asserted in (list ,@asserted-observers) if (not (member asserted *observers*)) collect asserted)))\n (trc \"called observers on\" *observers* :superflous superfluous-observers :failed failed-observers)\n (assert (not superfluous-observers))\n (assert (not failed-observers)))))", "macroexpand": "(let ((*observers* nil)) (trc \"deleting foo\" \" -- checking observers\") (store-remove :foo store) (let ((superfluous-observers (loop for run in *observers* if (not (member run (list foo foo+1))) collect run)) (failed-observers (loop for asserted in (list foo foo+1) if (not (member asserted *observers*)) collect asserted))) (trc \"called observers on\" *observers* :superflous superfluous-observers :failed failed-observers) (assert (not superfluous-observers)) (assert (not failed-observers))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(return 'some-name)\n\nProblem: Macro call that should be transformed by RETURN", "input": "(return 'some-name)", "output": "(defmacro RETURN ...)", "macroexpand": "(return-from nil 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(reduced-typecase nil (progn))\n\nPattern to recognize: Macro call that should be transformed by REDUCED-TYPECASE", "input": "(reduced-typecase nil (progn))", "output": "(defmacro REDUCED-TYPECASE ...)", "macroexpand": "(typecase nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(enable-fn-syntax)\n\nWhat needs to change: Macro call that should be transformed by ENABLE-FN-SYNTAX", "input": "(enable-fn-syntax)", "output": "(defmacro ENABLE-FN-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (%enable-fn-syntax))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (eql (top-sign) 'skip-first-template) (pop-sign))\n\nProblem: Macro call that should be transformed by when", "input": "(when (eql (top-sign) 'skip-first-template) (pop-sign))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql (top-sign) (quote skip-first-template)) (pop-sign))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(gen-lambda () (if (> i (1- seqlen)) 'generator-stop (prog1 (elt seq i) (incf i))))\n\nIssue: Macro call that should be transformed by gen-lambda", "input": "(gen-lambda () (if (> i (1- seqlen)) 'generator-stop (prog1 (elt seq i) (incf i))))", "output": "(defmacro gen-lambda (params &body rest)\n \"Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions.\"\n `(let ((values-handler (create-values-handler)))\n (declare (ignorable values-handler))\n (make-instance \n 'basic-generator \n :function (lambda ,params ,@rest))))", "macroexpand": "(let ((values-handler (create-values-handler))) (declare (ignorable values-handler)) (make-instance (quote basic-generator) :function (lambda nil (if (> i (1- seqlen)) (quote generator-stop) (prog1 (elt seq i) (incf i))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-language-macro 'some-name)\n\nIssue: Macro call that should be transformed by DEFINE-LANGUAGE-MACRO", "input": "(define-language-macro 'some-name)", "output": "(defmacro DEFINE-LANGUAGE-MACRO ...)", "macroexpand": "(defmacro 'some-name (&whole whole &body body)\n (declare (ignore body))\n `(macrolet ((,(car whole) (&body body)\n (let* ((lang (make-instance ',(car whole)))\n (env (top-level-environment lang)))\n (codegen-text (sexp->ops lang body env) ,*pretty*))))\n ,@(if *pretty*\n `((let ((*text-pretty-printer* (get-pretty-printer)))\n ,whole))\n `(,whole))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do+ (options :name inner-loop) (do+ (terminate outer-loop 3)))\n\nProblem: Macro call that should be transformed by do+", "input": "(do+ (options :name inner-loop) (do+ (terminate outer-loop 3)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (options :name inner-loop) (do+ (terminate outer-loop 3)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(dynamic-relet* 'some-name)\n\nIssue: Macro call that should be transformed by DYNAMIC-RELET*", "input": "(dynamic-relet* 'some-name)", "output": "(defmacro DYNAMIC-RELET* ...)", "macroexpand": "(dynamic-relet (quote)\n (dynamic-relet* (some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-component coffee :input-type \"coffee\" :output-type \"js\" :compile-function (lambda (input-pathname output-pathname) (declare (ignore output-pathname)) (inferior-shell:run `(\"coffee\" \"-c\" ,input-pathname) :show t)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-component", "input": "(define-component coffee :input-type \"coffee\" :output-type \"js\" :compile-function (lambda (input-pathname output-pathname) (declare (ignore output-pathname)) (inferior-shell:run `(\"coffee\" \"-c\" ,input-pathname) :show t)))", "output": "(defmacro define-component (name &key input-type output-type compile-function)\n \"Define an ASDF component.\"\n `(progn\n (defclass ,name (source-file)\n ((type :initform ,input-type)\n (output :reader output :initarg :output)))\n\n (defmethod perform ((o load-op) (component ,name)) t)\n\n (defmethod output-files ((operation compile-op) (component ,name))\n (list\n (output-pathname component ,output-type)))\n\n (defmethod perform ((o compile-op) (component ,name))\n (funcall ,compile-function\n (component-pathname component)\n (output-pathname component ,output-type)))\n\n (import ',name :asdf)))", "macroexpand": "(progn (defclass coffee (source-file) ((type :initform \"coffee\") (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component coffee)) t) (defmethod output-files ((operation compile-op) (component coffee)) (list (output-pathname component \"js\"))) (defmethod perform ((o compile-op) (component coffee)) (funcall (lambda (input-pathname output-pathname) (declare (ignore output-pathname)) (inferior-shell:run (sb-int:quasiquote (\"coffee\" \"-c\" #S(sb-impl::comma :expr input-pathname :kind 0))) :show t)) (component-pathname component) (output-pathname component \"js\"))) (import (quote coffee) :asdf))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is (= 4 d))\n\nProblem: Macro call that should be transformed by is", "input": "(is (= 4 d))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e277 4) (#:a278 d)) (if (progn (= #:e277 #:a278)) (add-result (quote test-passed) :test-expr (quote (= 4 d))) (process-failure (quote (= 4 d)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote d) #:a278 (quote =) #:e277)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-generator (d s (izip data selectors)) (when s (yield d)))\n\nProblem: Macro call that should be transformed by do-generator", "input": "(do-generator (d s (izip data selectors)) (when s (yield d)))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g159 (izip data selectors))) (loop do (if-generator ((d s) #:g159) (progn (when s (yield d))) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-html-string (:div (:div)))\n\nWhat needs to change: Macro call that should be transformed by with-html", "input": "(with-html-string (:div (:div)))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:div (:div))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(*> #'comment +skip-junk+)\n\nProblem: Macro call that should be transformed by *>", "input": "(*> #'comment +skip-junk+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset221) (multiple-value-bind (#:*>-res222 #:*>-next223) (funcall (function comment) #:*>-offset221) (if (ok? #:*>-res222) (funcall +skip-junk+ #:*>-next223) (fail #:*>-next223))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(assoc-cdr :jwks--uri disc)\n\nWhat needs to change: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr :jwks--uri disc)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc :jwks--uri disc :test (function eql)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(%escape-string-form (format nil \"~A\" form))\n\nProblem: Macro call that should be transformed by %escape-string-form", "input": "(%escape-string-form (format nil \"~A\" form))", "output": "(defmacro %escape-string-form (val)\n (let ((val2 (gensym)))\n `(let ((,val2 ,val))\n (if (should-escape-p ,val2)\n `(escape-string ,,val2)\n ,val2))))", "macroexpand": "(let ((#:g123 (format nil \"~A\" form))) (if (should-escape-p #:g123) (sb-int:quasiquote (escape-string #S(sb-impl::comma :expr #:g123 :kind 0))) #:g123))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dflet ((foo/lock () 13) (list () 42)) (is (eql 42 (list))) (is (eql 13 (foo/lock))))\n\nWhat needs to change: Macro call that should be transformed by dflet", "input": "(dflet ((foo/lock () 13) (list () 42)) (is (eql 42 (list))) (is (eql 13 (foo/lock))))", "output": "(defmacro dflet ((&rest definitions) &body body)\n \"Like FLET, but dynamically sets the FDEFINITIONS during the duration of\nthe BODY.\"\n `(progf\n ',(mapcar #'car definitions)\n (list\n ,.(mapcar (lambda (definition)\n `(lambda ,(cadr definition)\n ,@(cddr definition)))\n definitions))\n ,@body))", "macroexpand": "(progf (quote (foo/lock list)) (list (lambda nil 13) (lambda nil 42)) (is (eql 42 (list))) (is (eql 13 (foo/lock))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(while nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by WHILE", "input": "(while nil\n :key\n nil)", "output": "(defmacro WHILE ...)", "macroexpand": "(loop while nil\n do (progn :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> :p () (mt:open-latch latch))\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> :p () (mt:open-latch latch))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :p nil (cl-muth:open-latch latch))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is = 0.0f0 (read-from-string \"0.0\"))\n\nIssue: Macro call that should be transformed by is", "input": "(is = 0.0f0 (read-from-string \"0.0\"))", "output": "(defmacro is (comp expected form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(is ,comp ,expected ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected ,expected\n :comparison ,(maybe-quote comp)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is = 0.0 (read-from-string \"0.0\"))) :value-form (quote (read-from-string \"0.0\")) :body (lambda nil (read-from-string \"0.0\")) :expected 0.0 :comparison (quote =)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defclause (appending expr &optional into var at (place 'end)) \"Append into a list\" (return-collection-code :variable var :expression expr :start-operation 'append :end-operation '(subst (var expr) (copy-list expr)) :place place :one-element nil))\n\nPattern to recognize: Macro call that should be transformed by defclause", "input": "(defclause (appending expr &optional into var at (place 'end)) \"Append into a list\" (return-collection-code :variable var :expression expr :start-operation 'append :end-operation '(subst (var expr) (copy-list expr)) :place place :one-element nil))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-appending-20 (&key ((:appending expr)) ((:into var)) ((:at place) (quote end))) \"Append into a list\" (return-collection-code :variable var :expression expr :start-operation (quote append) :end-operation (quote (subst (var expr) (copy-list expr))) :place place :one-element nil)) (install-clause-info (quote (appending)) (quote (appending &optional :into :at)) (quote clause-appending-20) \"Append into a list\" nil) (quote (appending expr &optional into var at (place (quote end)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dynamic-relet nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DYNAMIC-RELET", "input": "(dynamic-relet nil\n (progn))", "output": "(defmacro DYNAMIC-RELET ...)", "macroexpand": "(dynamic-wind\n :proceed\n #:proceed190\n (let ()\n (declare (special))\n (#:proceed190 (progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(~> (loop for i from 0 below 3 collecting (let ((i i)) (-> :p (a) (declare (type fixnum a)) (the fixnum (+ a i))))))\n\nWrite a macro that addresses: Macro call that should be transformed by ~>", "input": "(~> (loop for i from 0 below 3 collecting (let ((i i)) (-> :p (a) (declare (type fixnum a)) (the fixnum (+ a i))))))", "output": "(defmacro ~> (&rest body)\n \"See flow:concurrently\"\n `(concurrently ,@body))", "macroexpand": "(concurrently (loop for i from 0 below 3 collecting (let ((i i)) (-> :p (a) (declare (type fixnum a)) (the fixnum (+ a i))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(as->* nil)\n\nWhat needs to change: Macro call that should be transformed by AS->*", "input": "(as->* nil)", "output": "(defmacro AS->* ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym maximizing :max)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym maximizing :max)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote maximizing) (quote synonym)) (quote :max)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(advisable-lambda nil\n (progn))\n\nProblem: Macro call that should be transformed by ADVISABLE-LAMBDA", "input": "(advisable-lambda nil\n (progn))", "output": "(defmacro ADVISABLE-LAMBDA ...)", "macroexpand": "(make-instance 'advisable-function :main #'(lambda () (progn)) :arguments 'nil\n :dispatcher-generator\n #'(lambda (#:fobj126)\n #'(lambda ()\n #A((29) base-char . \"Advisable function dispatcher\")\n (let ((#:fixed127 (append)))\n (apply-before #:fobj126 #:fixed127)\n (multiple-value-prog1\n (apply-around #:fobj126 #:fixed127)\n (apply-after #:fobj126 #:fixed127))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(let+ nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by LET+", "input": "(let+ nil\n (progn))", "output": "(defmacro LET+ ...)", "macroexpand": "(locally (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (plusp 1))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (plusp 1))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:v178 1)) (if (plusp #:v178) (add-result (quote test-passed) :test-expr (quote (plusp 1))) (process-failure (quote (plusp 1)) \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\" (quote 1) #:v178 (quote plusp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(let+ nil\n nil)\n\nIssue: Macro call that should be transformed by LET+", "input": "(let+ nil\n nil)", "output": "(defmacro LET+ ...)", "macroexpand": "(locally nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(f_)\n\nProblem: Macro call that should be transformed by F_", "input": "(f_)", "output": "(defmacro F_ ...)", "macroexpand": "(lambda (_))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-space (if safe? (write-string string *html*) (escape-to-stream string #'escape-string-char *html*)))\n\nIssue: Macro call that should be transformed by with-space", "input": "(with-space (if safe? (write-string string *html*) (escape-to-stream string #'escape-string-char *html*)))", "output": "(defmacro with-space (&body body)\n (with-thunk (body)\n `(call-with-space ,body)))", "macroexpand": "(flet ((#:stack-fn-body1 nil (if safe? (write-string string *html*) (escape-to-stream string (function escape-string-char) *html*)))) (declare (dynamic-extent (function #:stack-fn-body1))) (symbol-macrolet ((#:stack-fn-body1 (function #:stack-fn-body1))) (call-with-space #:stack-fn-body1)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym thereis :there-is)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym thereis :there-is)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote thereis) (quote synonym)) (quote :there-is)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error assignment-type-match (:error-type varjo-critical-error) (code-obj-a code-obj-b form) \"Currently varjo cannot handle changing the type through an assignment due to the static nature of glsl. place: ~a value: ~a Problematic form: ~s\" (type->type-spec (primary-type code-obj-a)) (type->type-spec (primary-type code-obj-b)) form)\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error assignment-type-match (:error-type varjo-critical-error) (code-obj-a code-obj-b form) \"Currently varjo cannot handle changing the type through an assignment due to the static nature of glsl. place: ~a value: ~a Problematic form: ~s\" (type->type-spec (primary-type code-obj-a)) (type->type-spec (primary-type code-obj-b)) form)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition assignment-type-match (:error-type varjo-critical-error :prefix \"Varjo\") (code-obj-a code-obj-b form) \"Currently varjo cannot handle changing the type through an assignment due to the static nature of glsl. place: ~a value: ~a Problematic form: ~s\" (type->type-spec (primary-type code-obj-a)) (type->type-spec (primary-type code-obj-b)) form)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(and nil nil)\n\nIssue: Macro call that should be transformed by AND", "input": "(and nil nil)", "output": "(defmacro AND ...)", "macroexpand": "(if nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (let* ((executable (namestring (make-pathname :type \"out\" :defaults input-file)))) (run-command-with-debug-print `(\"gplc\" ,input-file \"-o\" ,executable) :input input :output output :error error) (run-command-with-debug-print `(,executable) :input input :output output :error error)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-temp", "input": "(with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (let* ((executable (namestring (make-pathname :type \"out\" :defaults input-file)))) (run-command-with-debug-print `(\"gplc\" ,input-file \"-o\" ,executable) :input input :output output :error error) (run-command-with-debug-print `(,executable) :input input :output output :error error)))", "output": "(defmacro with-temp ((var &key directory template (tmpdir \"/tmp/\") debug) &body body)\n \"Create a temporary file, then remove the file by unwind-protect.\nMost arguments are analogous to mktemp.\nWhen DIRECTORY is non-nil, creates a directory instead.\nDEBUG is a form.\nWhen evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.\nIt may be evaluated multiple times.\"\n (with-gensyms (command)\n `(let ((,var (uiop:run-program\n (let ((,command (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\"\n ,tmpdir ,directory ,template)))\n (when ,debug\n (format *error-output* \"~&; ~a~%\" ,command))\n ,command)\n :output '(:string :stripped t))))\n (unwind-protect\n (progn ,@body)\n (if ,debug\n (format *error-output* \"~&; not removing ~a for debugging~%\" ,var)\n (uiop:run-program (format nil \"rm -rf ~a\" (namestring ,var)) :ignore-error-status t))))))", "macroexpand": "(let ((input-file (uiop/run-program:run-program (let ((#:command174 (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\" d nil \"XXXXXX.prolog\"))) (when (<= 1 *debug-prolog*) (format *error-output* \"~&; ~a~%\" #:command174)) #:command174) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (let* ((executable (namestring (make-pathname :type \"out\" :defaults input-file)))) (run-command-with-debug-print (sb-int:quasiquote (\"gplc\" #S(sb-impl::comma :expr input-file :kind 0) \"-o\" #S(sb-impl::comma :expr executable :kind 0))) :input input :output output :error error) (run-command-with-debug-print (sb-int:quasiquote (#S(sb-impl::comma :expr executable :kind 0))) :input input :output output :error error))) (if (<= 1 *debug-prolog*) (format *error-output* \"~&; not removing ~a for debugging~%\" input-file) (uiop/run-program:run-program (format nil \"rm -rf ~a\" (namestring input-file)) :ignore-error-status t))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(draw-relative (intern (concatenate 'string (string name) \"-R\")))\n\nWrite a macro that addresses: Macro call that should be transformed by draw", "input": "(draw-relative (intern (concatenate 'string (string name) \"-R\")))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(draw-relative (intern (concatenate (quote string) (string name) \"-R\")))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defrule nil)\n\nIssue: Macro call that should be transformed by DEFRULE", "input": "(defrule nil)", "output": "(defmacro DEFRULE ...)", "macroexpand": "(setf (gethash #A((3) base-char . \"NIL\") cl-rules.core::*rules*)\n '#S(cl-rules.core::rule\n :name #A((3) base-char . \"NIL\")\n :conditions nil\n :actions nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-hook-type void (function ()) \"Empty hook type with no arguments.\")\n\nProblem: Macro call that should be transformed by define-hook-type", "input": "(define-hook-type void (function ()) \"Empty hook type with no arguments.\")", "output": "(defmacro define-hook-type (name type &optional documentation)\n \"Define hook class.\nType must be something like:\n\n (function (string) (values integer t))\n\nThe `handler-type' of the defined hook class has `:class' allocation\ntype, so that all hooks of such class have the same `handler-type'.\"\n (let* ((name (string name))\n (hook-class-name (intern (serapeum:concat \"HOOK-\" name))))\n `(defclass ,hook-class-name (hook)\n ((handler-type :initform ',type :allocation :class))\n (:metaclass closer-mop:funcallable-standard-class)\n ,@(when documentation\n `((:documentation ,documentation))))))", "macroexpand": "(defclass hook-void (hook) ((handler-type :initform (quote (function nil)) :allocation :class)) (:metaclass sb-mop:funcallable-standard-class) (:documentation \"Empty hook type with no arguments.\"))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect nil (progn))\n\nWhat needs to change: Macro call that should be transformed by COLLECT", "input": "(collect nil (progn))", "output": "(defmacro COLLECT ...)", "macroexpand": "(common-lisp:let* ((#:generator-601 (generator (progn)))\n #:items-594\n #:seq-595\n (#:limit-596\n (common-lisp:multiple-value-bind (x y)\n (decode-seq-type (list 'quote nil))\n (declare (ignore x))\n y))\n (#:lst-597 nil))\n (declare (type generator #:generator-601)\n (type (null-or nonnegative-integer) #:limit-596)\n (type list #:lst-597))\n (tagbody\n #:ll-602\n (setq #:items-594 (next-in #:generator-601 (go end)))\n (setq #:lst-597 (cons #:items-594 #:lst-597))\n (go #:ll-602)\n end)\n (common-lisp:let ((num (length #:lst-597)))\n (declare (type nonnegative-integer num))\n (setq #:seq-595 (make-sequence nil (or #:limit-596 num)))\n (do ((i (1- num) (1- i)))\n ((minusp i))\n (setf (elt #:seq-595 i) (pop #:lst-597))))\n #:seq-595)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-script-symbol-macro 'some-name)\n\nPattern to recognize: Macro call that should be transformed by DEFINE-SCRIPT-SYMBOL-MACRO", "input": "(define-script-symbol-macro 'some-name)", "output": "(defmacro DEFINE-SCRIPT-SYMBOL-MACRO ...)", "macroexpand": "(define-ps-symbol-macro 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(signal-syntax-error \"Backreference to register ~A which has not been defined.\" max-back-ref)\n\nPattern to recognize: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Backreference to register ~A which has not been defined.\" max-back-ref)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Backreference to register ~A which has not been defined.\" max-back-ref)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defvar-unbound *readtable-copy* \"Bound to the current readtable if it has to be temporarily modified.\")\n\nWrite a macro that addresses: Macro call that should be transformed by defvar-unbound", "input": "(defvar-unbound *readtable-copy* \"Bound to the current readtable if it has to be temporarily modified.\")", "output": "(defmacro defvar-unbound (variable-name documentation)\n \"Like DEFVAR, but the variable will be unbound rather than getting\nan initial value. This is useful for variables which should have no\nglobal value but might have a dynamically bound value.\"\n ;; stolen from comp.lang.lisp article by\n ;; \"prunesquallor@comcast.net\"\n `(eval-when (:load-toplevel :compile-toplevel :execute)\n (defvar ,variable-name)\n (setf (documentation ',variable-name 'variable)\n ,documentation)))", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *readtable-copy*) (setf (documentation (quote *readtable-copy*) (quote variable)) \"Bound to the current readtable if it has to be temporarily modified.\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) (1+ val)))\n\nProblem: Macro call that should be transformed by c?-with-stored", "input": "(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) (1+ val)))", "output": "(defmacro c?-with-stored ((var key store &optional default) &body body)\n `(c? (bwhen-c-stored (,var ,key ,store ,default)\n\t ,@body)))", "macroexpand": "(c? (bwhen-c-stored (v :foo store (quote nothing)) (bwhen (val (value v)) (1+ val))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-cfun c-malloc)\n\nProblem: Macro call that should be transformed by define-cfun", "input": "(define-cfun c-malloc)", "output": "(defmacro define-cfun (name-or-function &optional (package *package*))\n (when-let ((fun (find-function name-or-function)))\n (with-wrap-attempt (\"function ~S\" name-or-function) name-or-function\n (with-slots (name type c-symbol fields) fun\n (let* ((fun-name (intern (symbol-name name) package))\n (param-names (mapcar #'foreign-type-name fields))\n (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))\n (make-function-p (not (foreign-function-variadic-p fun)))\n (maybe-cbv-return\n (when (cbv-return-p fun)\n (list 'return-value))))\n (with-gensyms (!fun !fields rest)\n (let ((form\n (if make-function-p\n `(defun ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n ,(let ((!fun (find-function name-or-function)))\n (with-slots ((!fields fields)) !fun\n (foreign-to-ffi\n (and (car !fields) (foreign-type (car !fields)))\n param-syms\n param-names\n !fields\n (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)\n param-syms (when (foreign-function-variadic-p fun) rest))))))\n `(defmacro ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n (let ((,!fun (find-function ',name-or-function)))\n (with-slots ((,!fields fields)) ,!fun\n (foreign-to-ffi\n (and (car ,!fields) (foreign-type (car ,!fields)))\n ',param-syms\n (list ,@param-names)\n ,!fields\n (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)\n ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))\n `(progn\n ,@(when (foreign-function-cbv-p fun)\n (list (funcall *build-libffi-definition* fun)))\n ,form))))))))", "macroexpand": "(progn (defun c-malloc (size) (let ((#:size193 size)) (declare (ignorable #:size193)) (cffi-sys:%foreign-funcall \"malloc\" (:unsigned-long-long #:size193 :pointer) :convention :cdecl))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym while :while)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym while :while)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote while) (quote synonym)) (quote :while)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(mvlet* ((x y (floor 20 6)) (z a (values x 5))) (+ x y z a))\n\nPattern to recognize: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((x y (floor 20 6)) (z a (values x 5))) (+ x y z a))", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(multiple-value-bind (x y) (floor 20 6) (mvlet* ((z a (values x 5))) (+ x y z a)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g)))\n\nPattern to recognize: Macro call that should be transformed by do-generator", "input": "(do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g)))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g172 (multi-gen (some-numbers) (list->generator data)))) (loop do (destructuring-bind (#:g174 . #:g173) (multiple-value-list (next-generator-value #:g172)) (unless #:g174 (return)) (let ((g (elt (elt #:g173 0) 0)) (l (elt (elt #:g173 1) 0))) (yield (+ l g))))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-script-symbol-macro nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEFINE-SCRIPT-SYMBOL-MACRO", "input": "(define-script-symbol-macro nil\n :key\n nil)", "output": "(defmacro DEFINE-SCRIPT-SYMBOL-MACRO ...)", "macroexpand": "(define-ps-symbol-macro nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq)) (member target bound-variables :test #'eq)) (setf unsafe? t)) (values))\n\nIssue: Macro call that should be transformed by action", "input": "(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq)) (member target bound-variables :test #'eq)) (setf unsafe? t)) (values))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-variable) (lambda (node bound-variables) (declare (type node-variable node)) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test (function eq))) (member target bound-variables :test (function eq))) (setf unsafe? t)) (values)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some-> nil (progn))\n\nIssue: Macro call that should be transformed by SOME->", "input": "(some-> nil (progn))", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:g143 nil))\n (if (null #:g143)\n nil\n (-> #:g143 (progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when export `(export '(,name ,@slot-list)))\n\nIssue: Macro call that should be transformed by when", "input": "(when export `(export '(,name ,@slot-list)))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if export (sb-int:quasiquote (export (quote (#S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr slot-list :kind 2))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lambda* nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by LAMBDA*", "input": "(lambda* nil\n :key\n nil)", "output": "(defmacro LAMBDA* ...)", "macroexpand": "(lambda () (the t (block nil :key nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do+ (for x (from 0)) (generating y (across #(0 1))) (collect (list x y)) (when (oddp x) (is (= (update y) y))))\n\nWhat needs to change: Macro call that should be transformed by do+", "input": "(do+ (for x (from 0)) (generating y (across #(0 1))) (collect (list x y)) (when (oddp x) (is (= (update y) y))))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (from 0)) (generating y (across #(0 1))) (collect (list x y)) (when (oddp x) (is (= (update y) y))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-template nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-TEMPLATE", "input": "(define-template nil nil)", "output": "(defmacro DEFINE-TEMPLATE ...)", "macroexpand": "(defmacro define-nil (&optional (#:name126))\n (flet ((template-unfulfillable ()\n (error 'template-unfulfillable :template 'nil :arguments (list))))\n (declare (ignorable (function template-unfulfillable)))\n (let ((body (progn)) (name (or #:name126 (compose-name #\\SOLIDUS 'nil))))\n `(progn\n (declaim\n (ftype\n (function\n ,(loop with types = (declared-variable-types body)\n for arg in (quote nil)\n collect (or (second (assoc arg types)) (quote t)))\n ,(declared-return-type body))\n ,name)\n ,@(when (find (quote inline) (declarations body)) `((inline ,name))))\n (defun ,name ,'nil\n (declare (optimize speed (safety 0) (debug 0) (compilation-speed 0))\n ,@(remove (quote inline) (declarations body)))\n ,@(remove-if #'declaration-p body))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-mocks () (register-mock 'foo) (let ((sym (gensym))) (foo sym) (is (equal `((foo ,sym)) (invocations)))))\n\nPattern to recognize: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (register-mock 'foo) (let ((sym (gensym))) (foo sym) (is (equal `((foo ,sym)) (invocations)))))", "output": "(defmacro with-mocks ((&key (recordp T)) &body body)\n \"Execute BODY in a new mocking context. Invocations will be recorded\nif RECORDP is set (default true).\"\n `(call-with-mocks\n (lambda () ,@body)\n :recordp ,recordp))", "macroexpand": "(call-with-mocks (lambda nil (register-mock (quote foo)) (let ((sym (gensym))) (foo sym) (is (equal (sb-int:quasiquote ((foo #S(sb-impl::comma :expr sym :kind 0)))) (invocations))))) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda () (progn))\n\nWhat needs to change: Macro call that should be transformed by LAMBDA", "input": "(lambda () (progn))", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda () (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error switch-type-error () (form) \"Currently the clause forms of a switch must all be either ints, uints, floats or doubles:~%Code:~%~a\" form)\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error switch-type-error () (form) \"Currently the clause forms of a switch must all be either ints, uints, floats or doubles:~%Code:~%~a\" form)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition switch-type-error (:error-type varjo-error :prefix \"Varjo\") (form) \"Currently the clause forms of a switch must all be either ints, uints, floats or doubles:~%Code:~%~a\" form)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-cache (\"foo\" :store storage) (error \"MUST NOT BE ERROR\"))\n\nWhat needs to change: Macro call that should be transformed by with-cache", "input": "(with-cache (\"foo\" :store storage) (error \"MUST NOT BE ERROR\"))", "output": "(defmacro with-cache ((key &key store expire) &body body)\n \"If a cache indicated by KEY exists, this just returns the cache\nvalue without evaluating BODY. Otherwise, this evaluates BODY and\nstores the evaluated value into STORE with KEY and EXPIRE. KEY is a\nform that an evaluated value indicates the cache key.\n\nExample:\n\n (defun f (x)\n (with-cache (x *store*)\n (very-complex-computation x)))\"\n (once-only (key store expire)\n (with-gensyms (value exists-p)\n `(multiple-value-bind (,value ,exists-p)\n (getcache ,key ,store)\n (if ,exists-p\n ,value\n (let ((,value (progn ,@body)))\n (setcache ,key ,value ,store :expire ,expire)\n ,value))))))", "macroexpand": "(let ((#:key237 \"foo\") (#:store238 storage) (#:expire239 nil)) (multiple-value-bind (#:value240 #:exists-p241) (getcache #:key237 #:store238) (if #:exists-p241 #:value240 (let ((#:value240 (progn (error \"MUST NOT BE ERROR\")))) (setcache #:key237 #:value240 #:store238 :expire #:expire239) #:value240))))", "category": "anaphoric", "technique": "once-only,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(action (:after node-bind node) (multiple-value-bind (new-node new-changed?) (maybe-collapse-bind node) (when new-changed? (setf changed? t) new-node)))\n\nIssue: Macro call that should be transformed by action", "input": "(action (:after node-bind node) (multiple-value-bind (new-node new-changed?) (maybe-collapse-bind node) (when new-changed? (setf changed? t) new-node)))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-bind) (lambda (node) (declare (type node-bind node)) (multiple-value-bind (new-node new-changed?) (maybe-collapse-bind node) (when new-changed? (setf changed? t) new-node))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield-binds (format nil \"~{~A~^, ~}\" (mapcar (lambda (element) (if (sql-statement-p element) (format nil \"(~A)\" (yield element)) (yield element))) (sql-list-elements list))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~{~A~^, ~}\" (mapcar (lambda (element) (if (sql-statement-p element) (format nil \"(~A)\" (yield element)) (yield element))) (sql-list-elements list))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~{~A~^, ~}\" (mapcar (lambda (element) (if (sql-statement-p element) (format nil \"(~A)\" (yield element)) (yield element))) (sql-list-elements list)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(like \"truth\" \"^true\")\n\nProblem: Macro call that should be transformed by like", "input": "(like \"truth\" \"^true\")", "output": "(defmacro like (got regex &optional desc)\n (with-gensyms (duration result)\n (once-only (regex desc)\n `(with-catching-errors (:description ,desc :expected ,regex)\n (with-duration ((,duration ,result) ,got)\n (test ,result ,regex ,desc\n :duration ,duration\n :test-fn (lambda (x y) (not (null (ppcre:scan y x))))\n :report-expected-label \"be like\"))))))", "macroexpand": "(let ((#:regex211 \"^true\") (#:desc212 nil)) (with-catching-errors (:description #:desc212 :expected #:regex211) (with-duration ((#:duration209 #:result210) \"truth\") (test #:result210 #:regex211 #:desc212 :duration #:duration209 :test-fn (lambda (x y) (not (null (cl-ppcre:scan y x)))) :report-expected-label \"be like\"))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause (until expr) \"Exit loop if test is non-nil\" (setq *loop-end-used?* t) (return-code :body `((if ,(walk-expr expr) (go ,*loop-end*)))))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause (until expr) \"Exit loop if test is non-nil\" (setq *loop-end-used?* t) (return-code :body `((if ,(walk-expr expr) (go ,*loop-end*)))))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-until-15 (&key ((:until expr))) \"Exit loop if test is non-nil\" (setq *loop-end-used?* t) (return-code :body (sb-int:quasiquote ((if #S(sb-impl::comma :expr (walk-expr expr) :kind 0) (go #S(sb-impl::comma :expr *loop-end* :kind 0))))))) (install-clause-info (quote (until)) (quote (until)) (quote clause-until-15) \"Exit loop if test is non-nil\" nil) (quote (until expr)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(receive (one two three four) (values 1 2 3) (list one two three four))\n\nPattern to recognize: Macro call that should be transformed by receive", "input": "(receive (one two three four) (values 1 2 3) (list one two three four))", "output": "(defmacro receive (formals expr &body body)\n \"Stricter version of `multiple-value-bind'.\n\nUse `receive' when you want to enforce that EXPR should return a\ncertain number of values, or a minimum number of values.\n\nIf FORMALS is a proper list, then EXPR must return exactly as many\nvalues -- no more and no less -- as there are variables in FORMALS.\n\nIf FORMALS is an improper list (VARS . REST), then EXPR must return at\nleast as many values as there are VARS, and any further values are\nbound, as a list, to REST.\n\nLastly, if FORMALS is a symbol, bind that symbol to all the values\nreturned by EXPR, as if by `multiple-value-list'.\n\nFrom Scheme (SRFI-8).\"\n ;; It's probably not worth stack-allocating the thunk.\n (cond ((null formals)\n `(multiple-value-call\n (lambda ()\n ,@body)\n ,expr))\n ((atom formals)\n ;; This could also be written:\n #+(or) `(let ((,formals (multiple-value-list ,expr)))\n ,@body)\n ;; But I want it to be possible to declare FORMALS to have\n ;; dynamic extent, and most Lisps support that for &rest\n ;; lists.\n `(multiple-value-call\n (lambda (&rest ,formals)\n ,@body)\n ,expr))\n ((proper-list-p formals)\n (when (intersection formals lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda ,formals\n ,@body)\n ,expr))\n (t (let* ((last (last formals))\n (vars (append (butlast formals)\n (list (car last))))\n (rest (cdr last)))\n (when (intersection (cons rest vars) lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda (,@vars &rest ,rest)\n ,@body)\n ,expr)))))", "macroexpand": "(multiple-value-call (lambda (one two three four) (list one two three four)) (values 1 2 3))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(rem-plist-val! nil nil)\n\nPattern to recognize: Macro call that should be transformed by REM-PLIST-VAL!", "input": "(rem-plist-val! nil nil)", "output": "(defmacro rem-plist-val! (id place &key (test '(default-test)) (key '(default-key)))\n `(setf ,place\n (rem-plist-val ,id ,place :test ,test :key ,key)))", "macroexpand": "(setf nil (rem-plist-val nil nil :test (default-test) :key (default-key)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(~> (-> :g (a) (+ 1 a)) (list nil) (-> :g (a) (+ a 2)) (>> (-> :g (b) (+ b 6)) (-> :g (b) (+ b 7))) (list (-> :g (a) (+ a 3)) (-> :g (a) (+ a 4)) (-> :g (a) (values (+ a 5) -1))))\n\nIssue: Macro call that should be transformed by ~>", "input": "(~> (-> :g (a) (+ 1 a)) (list nil) (-> :g (a) (+ a 2)) (>> (-> :g (b) (+ b 6)) (-> :g (b) (+ b 7))) (list (-> :g (a) (+ a 3)) (-> :g (a) (+ a 4)) (-> :g (a) (values (+ a 5) -1))))", "output": "(defmacro ~> (&rest body)\n \"See flow:concurrently\"\n `(concurrently ,@body))", "macroexpand": "(concurrently (-> :g (a) (+ 1 a)) (list nil) (-> :g (a) (+ a 2)) (>> (-> :g (b) (+ b 6)) (-> :g (b) (+ b 7))) (list (-> :g (a) (+ a 3)) (-> :g (a) (+ a 4)) (-> :g (a) (values (+ a 5) -1))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (= 3 (length results)))\n\nIssue: Macro call that should be transformed by is", "input": "(is (= 3 (length results)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e223 3) (#:a224 (length results))) (if (progn (= #:e223 #:a224)) (add-result (quote test-passed) :test-expr (quote (= 3 (length results)))) (process-failure (quote (= 3 (length results))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (length results)) #:a224 (quote =) #:e223)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-access-values nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by WITH-ACCESS-VALUES", "input": "(with-access-values nil\n :key\n nil)", "output": "(defmacro with-access-values ((&rest bindings) obj &body body)\n \"A macro which binds local variables from accessed values on object\n according to bindings\n\n bindings: (local-symbol-and-access-key\n or (local-symbol access-key)\n ...)\n obj: the thing we are accessing data from\n \"\n (flet ((key-for (it)\n (etypecase it\n (symbol `(quote ,it))\n ((or string keyword list) it))))\n (let* ((o (gensym \"OBJ\"))\n (expanded-bindings\n (iter (for b in (ensure-list bindings))\n (when (first-iteration-p)\n (collect `(,o ,obj)))\n (typecase b\n (null)\n (list (collect `(,(first b) (access ,o ,(key-for (second b))))))\n (symbol (collect `(,b (access ,o ,(key-for b)))))))))\n `(let* ,expanded-bindings\n ,@body))))", "macroexpand": "(let* ()\n nil)", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.825} {"instruction": "Generate a defmacro form that transforms code like this:\n(builder (:auth/basic :authenticator (lambda (user pass) (and (string= user \"hoge\") (string= pass \"fuga\")))) (lambda (env) `(200 () (,(format nil \"Hello, ~A\" (getf env :remote-user))))))\n\nPattern to recognize: Macro call that should be transformed by builder", "input": "(builder (:auth/basic :authenticator (lambda (user pass) (and (string= user \"hoge\") (string= pass \"fuga\")))) (lambda (env) `(200 () (,(format nil \"Hello, ~A\" (getf env :remote-user))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app186) (funcall (find-middleware :auth/basic) #:app186 :authenticator (lambda (user pass) (and (string= user \"hoge\") (string= pass \"fuga\"))))))) :initial-value (to-app (lambda (env) (sb-int:quasiquote (200 nil (#S(sb-impl::comma :expr (format nil \"Hello, ~A\" (getf env :remote-user)) :kind 0)))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(builder (:static :path \"/public/\" :root (asdf:system-relative-pathname :lack #P\"data/\")) (lambda (env) (declare (ignore env)) `(200 (:content-type \"text/plain\") (\"Happy Valentine!\"))))\n\nIssue: Macro call that should be transformed by builder", "input": "(builder (:static :path \"/public/\" :root (asdf:system-relative-pathname :lack #P\"data/\")) (lambda (env) (declare (ignore env)) `(200 (:content-type \"text/plain\") (\"Happy Valentine!\"))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app226) (funcall (find-middleware :static) #:app226 :path \"/public/\" :root (asdf/system:system-relative-pathname :lack #P\"data/\"))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (\"Happy Valentine!\"))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ematch0 missing ((list) pattern) ((list* var rest) (bind-missing-vars-with-nil (with-gensyms (it) `(guard1 ,it t nil (guard1 ,var t) ,it ,pattern)) rest)))\n\nWrite a macro that addresses: Macro call that should be transformed by ematch0", "input": "(ematch0 missing ((list) pattern) ((list* var rest) (bind-missing-vars-with-nil (with-gensyms (it) `(guard1 ,it t nil (guard1 ,var t) ,it ,pattern)) rest)))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 missing ((list) pattern) ((list* var rest) (bind-missing-vars-with-nil (with-gensyms (it) (sb-int:quasiquote (guard1 #S(sb-impl::comma :expr it :kind 0) t nil (guard1 #S(sb-impl::comma :expr var :kind 0) t) #S(sb-impl::comma :expr it :kind 0) #S(sb-impl::comma :expr pattern :kind 0)))) rest)) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(builder :accesslog (lambda (env) (declare (ignore env)) '(200 () (\"ok\"))))\n\nProblem: Macro call that should be transformed by builder", "input": "(builder :accesslog (lambda (env) (declare (ignore env)) '(200 () (\"ok\"))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (find-middleware :accesslog))) :initial-value (to-app (lambda (env) (declare (ignore env)) (quote (200 nil (\"ok\"))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-op (:/ conjunctive-op))\n\nProblem: Macro call that should be transformed by define-op", "input": "(define-op (:/ conjunctive-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (/-op (:include conjunctive-op (name \"/\")) (:constructor make-/-op (&rest expressions))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(when (node-slot initializer) (del-proxy initializer))\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when (node-slot initializer) (del-proxy initializer))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (node-slot initializer) (del-proxy initializer))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(letrec nil)\n\nWhat needs to change: Macro call that should be transformed by LETREC", "input": "(letrec nil)", "output": "(defmacro LETREC ...)", "macroexpand": "(let ()\n (flet ()\n nil\n (setf)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(next-in nil nil)\n\nIssue: Macro call that should be transformed by NEXT-IN", "input": "(next-in nil nil)", "output": "(defmacro NEXT-IN ...)", "macroexpand": "(do-next-in nil #'(lambda () nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defjsmacro 'some-name)\n\nProblem: Macro call that should be transformed by DEFJSMACRO", "input": "(defjsmacro 'some-name)", "output": "(defmacro DEFJSMACRO ...)", "macroexpand": "(defpsmacro 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause (repeat n) \"Repeat the loop some number of times\" (top-level-check) (let* ((c-type (or (expression-type n) 'fixnum)) (count-var (make-var-and-binding 'count n :type c-type))) (setq *loop-end-used?* t) (return-code :body `((if (<= ,count-var 0) (go ,*loop-end*))) :step `((setq ,count-var (1- ,count-var))))))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause (repeat n) \"Repeat the loop some number of times\" (top-level-check) (let* ((c-type (or (expression-type n) 'fixnum)) (count-var (make-var-and-binding 'count n :type c-type))) (setq *loop-end-used?* t) (return-code :body `((if (<= ,count-var 0) (go ,*loop-end*))) :step `((setq ,count-var (1- ,count-var))))))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-repeat-2 (&key ((:repeat n))) \"Repeat the loop some number of times\" (top-level-check) (let* ((c-type (or (expression-type n) (quote fixnum))) (count-var (make-var-and-binding (quote count) n :type c-type))) (setq *loop-end-used?* t) (return-code :body (sb-int:quasiquote ((if (<= #S(sb-impl::comma :expr count-var :kind 0) 0) (go #S(sb-impl::comma :expr *loop-end* :kind 0))))) :step (sb-int:quasiquote ((setq #S(sb-impl::comma :expr count-var :kind 0) (1- #S(sb-impl::comma :expr count-var :kind 0)))))))) (install-clause-info (quote (repeat)) (quote (repeat)) (quote clause-repeat-2) \"Repeat the loop some number of times\" nil) (quote (repeat n)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(inext nil (progn))\n\nProblem: Macro call that should be transformed by INEXT", "input": "(inext nil (progn))", "output": "(defmacro INEXT ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro nil) (progn)))))\n (if (not vals)\n (coexit!)\n (car vals)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((token-list-for-print (remove-whitespace-marker directive-token-list))) (error 'preprocess-error :format-control \"[File ~A: Line ~D] #error: ~{~A~^ ~}\" :format-arguments (list (if file-pathname (enough-namestring file-pathname)) line-number token-list-for-print))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((token-list-for-print (remove-whitespace-marker directive-token-list))) (error 'preprocess-error :format-control \"[File ~A: Line ~D] #error: ~{~A~^ ~}\" :format-arguments (list (if file-pathname (enough-namestring file-pathname)) line-number token-list-for-print))))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((token-list-for-print (remove-whitespace-marker directive-token-list))) (error (quote preprocess-error) :format-control \"[File ~A: Line ~D] #error: ~{~A~^ ~}\" :format-arguments (list (if file-pathname (enough-namestring file-pathname)) line-number token-list-for-print))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defvar-compile-time *function-record-table* (make-hash-table :test #'equal) \"The function record table.\")\n\nWhat needs to change: Macro call that should be transformed by defvar-compile-time", "input": "(defvar-compile-time *function-record-table* (make-hash-table :test #'equal) \"The function record table.\")", "output": "(defmacro defvar-compile-time (name &optional initial-value documentation)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,name ,initial-value ,documentation)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *function-record-table* (make-hash-table :test (function equal)) \"The function record table.\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun/1 ldexp (x n) (* x (expt 2 n)))\n\nPattern to recognize: Macro call that should be transformed by defun/1", "input": "(defun/1 ldexp (x n) (* x (expt 2 n)))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun ldexp (x n) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (* x (expt 2 n))) (defparameter ldexp (vacietis.c:mkptr& (symbol-function (quote ldexp)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do+ (for x (in '(1 3 5 7 9))) (for k (from 10 :to 0)) (initially (format t \"initially k = ~S~%\" k)) (for m (to 100 :by 5)) (initially (format t \"another init form~%\")) (with (y 42) z) (stop-when (eql x 7)) (counting loops) (finally (format t \"finally k = ~S~%\" k)) (accumulating-to w) (accumulating-to p :initially 0 :by #'+ :finally #'-) (returning (list 'x x 'y y 'z z 'k k 'm m 'w w 'p p 'loops loops 'max-length max-length 'longest-list longest-list)) (finally (format t \"another final form~%\")) (finding max-x (maximizing x)) (for list (in '((1 2) (3) (4 5 6) (7 8) (9)))) (finding max-length (maximizing (length list) :saving list :in longest-list)) (let ((foo \"look ma, body is nested!\")) (declare (ignore foo)) (format t \"~%loop no. ~A~%\" loops) (format t \"before collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%\" x y z k m w list max-length longest-list) (collect x :into w) (collect x :into p) (format t \"after collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%\" x y z k m w list max-length longest-list)))\n\nWhat needs to change: Macro call that should be transformed by do+", "input": "(do+ (for x (in '(1 3 5 7 9))) (for k (from 10 :to 0)) (initially (format t \"initially k = ~S~%\" k)) (for m (to 100 :by 5)) (initially (format t \"another init form~%\")) (with (y 42) z) (stop-when (eql x 7)) (counting loops) (finally (format t \"finally k = ~S~%\" k)) (accumulating-to w) (accumulating-to p :initially 0 :by #'+ :finally #'-) (returning (list 'x x 'y y 'z z 'k k 'm m 'w w 'p p 'loops loops 'max-length max-length 'longest-list longest-list)) (finally (format t \"another final form~%\")) (finding max-x (maximizing x)) (for list (in '((1 2) (3) (4 5 6) (7 8) (9)))) (finding max-length (maximizing (length list) :saving list :in longest-list)) (let ((foo \"look ma, body is nested!\")) (declare (ignore foo)) (format t \"~%loop no. ~A~%\" loops) (format t \"before collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%\" x y z k m w list max-length longest-list) (collect x :into w) (collect x :into p) (format t \"after collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%\" x y z k m w list max-length longest-list)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (in (quote (1 3 5 7 9)))) (for k (from 10 :to 0)) (initially (format t \"initially k = ~S~%\" k)) (for m (to 100 :by 5)) (initially (format t \"another init form~%\")) (with (y 42) z) (stop-when (eql x 7)) (counting loops) (finally (format t \"finally k = ~S~%\" k)) (accumulating-to w) (accumulating-to p :initially 0 :by (function +) :finally (function -)) (returning (list (quote x) x (quote y) y (quote z) z (quote k) k (quote m) m (quote w) w (quote p) p (quote loops) loops (quote max-length) max-length (quote longest-list) longest-list)) (finally (format t \"another final form~%\")) (finding max-x (maximizing x)) (for list (in (quote ((1 2) (3) (4 5 6) (7 8) (9))))) (finding max-length (maximizing (length list) :saving list :in longest-list)) (let ((foo \"look ma, body is nested!\")) (declare (ignore foo)) (format t \"~%loop no. ~A~%\" loops) (format t \"before collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%\" x y z k m w list max-length longest-list) (collect x :into w) (collect x :into p) (format t \"after collect, x ~A y ~A z ~A k ~A m ~A w ~A ~% list ~A max-length ~A longest-list ~A ~%\" x y z k m w list max-length longest-list)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(do+ (options :name outer-loop) (do+ (options :name inner-loop) (do+ (terminate outer-loop 3))))\n\nPattern to recognize: Macro call that should be transformed by do+", "input": "(do+ (options :name outer-loop) (do+ (options :name inner-loop) (do+ (terminate outer-loop 3))))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (options :name outer-loop) (do+ (options :name inner-loop) (do+ (terminate outer-loop 3))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<>\n nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by -<>", "input": "(-<>\n nil\n :key\n nil)", "output": "(defmacro -<> ...)", "macroexpand": "(let* ((#:var208 nil) (#:var209 (:key #:var208)) (#:var210 (nil #:var209)))\n #:var210)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defvar* nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by DEFVAR*", "input": "(defvar* nil :key nil)", "output": "(defmacro DEFVAR* ...)", "macroexpand": "(defvar/param defvar nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(enable-punch-syntax)\n\nIssue: Macro call that should be transformed by enable-punch-syntax", "input": "(enable-punch-syntax)", "output": "(defmacro enable-punch-syntax ()\n '(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl-syntax:use-syntax punch-syntax)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (cl-syntax:use-syntax punch-syntax))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error invalid-for-loop-type () (decl-obj) \"Invalid type ~a used as counter for for-loop\" (primary-type decl-obj))\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error invalid-for-loop-type () (decl-obj) \"Invalid type ~a used as counter for for-loop\" (primary-type decl-obj))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition invalid-for-loop-type (:error-type varjo-error :prefix \"Varjo\") (decl-obj) \"Invalid type ~a used as counter for for-loop\" (primary-type decl-obj))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-compile-time cps-convert-multiple-value-call (nondeterministic? function forms continuation types value? environment) (let ((dummy-argument (gensym \"DUMMY-\")) (other-arguments (gensym \"OTHER-\"))) (cps-convert function `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) ,(cps-convert-multiple-value-call-internal nondeterministic? dummy-argument forms continuation types value? environment)) nil t environment)))\n\nWhat needs to change: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time cps-convert-multiple-value-call (nondeterministic? function forms continuation types value? environment) (let ((dummy-argument (gensym \"DUMMY-\")) (other-arguments (gensym \"OTHER-\"))) (cps-convert function `#'(lambda (&optional ,dummy-argument &rest ,other-arguments) (declare (magic) (ignore ,other-arguments)) ,(cps-convert-multiple-value-call-internal nondeterministic? dummy-argument forms continuation types value? environment)) nil t environment)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun cps-convert-multiple-value-call (nondeterministic? function forms continuation types value? environment) (let ((dummy-argument (gensym \"DUMMY-\")) (other-arguments (gensym \"OTHER-\"))) (cps-convert function (sb-int:quasiquote (function (lambda (&optional #S(sb-impl::comma :expr dummy-argument :kind 0) &rest #S(sb-impl::comma :expr other-arguments :kind 0)) (declare (magic) (ignore #S(sb-impl::comma :expr other-arguments :kind 0))) #S(sb-impl::comma :expr (cps-convert-multiple-value-call-internal nondeterministic? dummy-argument forms continuation types value? environment) :kind 0)))) nil t environment))) (eval-when (:compile-toplevel) (compile (quote cps-convert-multiple-value-call))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defvar-unbound *stream* \"Bound to the stream which is read from while parsing a string.\")\n\nProblem: Macro call that should be transformed by defvar-unbound", "input": "(defvar-unbound *stream* \"Bound to the stream which is read from while parsing a string.\")", "output": "(defmacro defvar-unbound (variable-name documentation)\n \"Like DEFVAR, but the variable will be unbound rather than getting\nan initial value. This is useful for variables which should have no\nglobal value but might have a dynamically bound value.\"\n ;; stolen from comp.lang.lisp article by\n ;; \"prunesquallor@comcast.net\"\n `(eval-when (:load-toplevel :compile-toplevel :execute)\n (defvar ,variable-name)\n (setf (documentation ',variable-name 'variable)\n ,documentation)))", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *stream*) (setf (documentation (quote *stream*) (quote variable)) \"Bound to the stream which is read from while parsing a string.\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-generic generic (a b &key c &allow-other-keys) (+ a b))\n\nProblem: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c &allow-other-keys) (+ a b))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key &allow-other-keys) (:method (a b &key c &allow-other-keys) (+ a b))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda-coro)\n\nPattern to recognize: Macro call that should be transformed by LAMBDA-CORO", "input": "(lambda-coro)", "output": "(defmacro LAMBDA-CORO ...)", "macroexpand": "(progn\n (defcoroutine #:name123\n (#:arg124)\n (macrolet ((yield (form)\n (let ((g!-it (gensym \"IT\")))\n `(progn\n (let ((,g!-it ,form))\n (cl-coroutine:yield ,g!-it))\n ,'#:arg124)))\n (last-yield-value ()\n '#:arg124))\n (coexit!)))\n (make-coroutine '#:name123))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deferror \"23505\" unique-violation integrity-violation)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"23505\" unique-violation integrity-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition unique-violation (integrity-violation) nil) (setf (gethash \"23505\" *error-table*) (quote unique-violation)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-simple-appender-to-place nil)\n\nWhat needs to change: Macro call that should be transformed by MAKE-SIMPLE-APPENDER-TO-PLACE", "input": "(make-simple-appender-to-place nil)", "output": "(defmacro MAKE-SIMPLE-APPENDER-TO-PLACE ...)", "macroexpand": "(progn\n (setf nil (alexandria:ensure-list nil))\n (let ((#:tail131 (last nil)))\n (lambda (&rest values) (append-at-end nil #:tail131 values) nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(action (:after node-direct-application node) (when (eq name (node-rator-name node)) (incf count)) (values))\n\nWrite a macro that addresses: Macro call that should be transformed by action", "input": "(action (:after node-direct-application node) (when (eq name (node-rator-name node)) (incf count)) (values))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-direct-application) (lambda (node) (declare (type node-direct-application node)) (when (eq name (node-rator-name node)) (incf count)) (values)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-cfun c-memcpy)\n\nWhat needs to change: Macro call that should be transformed by define-cfun", "input": "(define-cfun c-memcpy)", "output": "(defmacro define-cfun (name-or-function &optional (package *package*))\n (when-let ((fun (find-function name-or-function)))\n (with-wrap-attempt (\"function ~S\" name-or-function) name-or-function\n (with-slots (name type c-symbol fields) fun\n (let* ((fun-name (intern (symbol-name name) package))\n (param-names (mapcar #'foreign-type-name fields))\n (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))\n (make-function-p (not (foreign-function-variadic-p fun)))\n (maybe-cbv-return\n (when (cbv-return-p fun)\n (list 'return-value))))\n (with-gensyms (!fun !fields rest)\n (let ((form\n (if make-function-p\n `(defun ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n ,(let ((!fun (find-function name-or-function)))\n (with-slots ((!fields fields)) !fun\n (foreign-to-ffi\n (and (car !fields) (foreign-type (car !fields)))\n param-syms\n param-names\n !fields\n (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)\n param-syms (when (foreign-function-variadic-p fun) rest))))))\n `(defmacro ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n (let ((,!fun (find-function ',name-or-function)))\n (with-slots ((,!fields fields)) ,!fun\n (foreign-to-ffi\n (and (car ,!fields) (foreign-type (car ,!fields)))\n ',param-syms\n (list ,@param-names)\n ,!fields\n (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)\n ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))\n `(progn\n ,@(when (foreign-function-cbv-p fun)\n (list (funcall *build-libffi-definition* fun)))\n ,form))))))))", "macroexpand": "(progn (defun c-memcpy (dest src n) (let ((#:dest224 dest)) (declare (ignorable #:dest224)) (let ((#:src225 src)) (declare (ignorable #:src225)) (let ((#:n226 n)) (declare (ignorable #:n226)) (cffi-sys:%foreign-funcall \"memcpy\" (:pointer #:dest224 :pointer #:src225 :unsigned-long-long #:n226 :pointer) :convention :cdecl))))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(as->* nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by AS->*", "input": "(as->* nil (progn))", "output": "(defmacro AS->* ...)", "macroexpand": "(as-> (progn) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-reader-syntax nil (progn))\n\nPattern to recognize: Macro call that should be transformed by ENABLE-READER-SYNTAX", "input": "(enable-reader-syntax nil (progn))", "output": "(defmacro ENABLE-READER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (push *readtable* *previous-readtables*)\n (setq *readtable* (copy-readtable))\n (%enable-reader-syntax *readtable* nil (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(f_n\n nil)\n\nProblem: Macro call that should be transformed by F_N", "input": "(f_n\n nil)", "output": "(defmacro F_N ...)", "macroexpand": "(lambda (&rest _) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-mocks () T)\n\nIssue: Macro call that should be transformed by with-mocks", "input": "(with-mocks () T)", "output": "(defmacro with-mocks ((&key (recordp T)) &body body)\n \"Execute BODY in a new mocking context. Invocations will be recorded\nif RECORDP is set (default true).\"\n `(call-with-mocks\n (lambda () ,@body)\n :recordp ,recordp))", "macroexpand": "(call-with-mocks (lambda nil t) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(assoc-cdr :last-name uinfo)\n\nWrite a macro that addresses: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr :last-name uinfo)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc :last-name uinfo :test (function eql)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(false T)\n\nProblem: Macro call that should be transformed by false", "input": "(false T)", "output": "(defmacro false (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(false ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected 'NIL\n :comparison 'geq\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (false t)) :value-form (quote t) :body (lambda nil t) :expected (quote nil) :comparison (quote geq)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(insert-char-class-tester (regex (schar *string* curr-pos)) (non-greedy-constant-length-closure (char-class-test)))\n\nWhat needs to change: Macro call that should be transformed by insert-char-class-tester", "input": "(insert-char-class-tester (regex (schar *string* curr-pos)) (non-greedy-constant-length-closure (char-class-test)))", "output": "(defmacro insert-char-class-tester ((char-class chr-expr) &body body)\n \"Utility macro to replace each occurence of '\\(CHAR-CLASS-TEST)\nwithin BODY with the correct test (corresponding to CHAR-CLASS)\nagainst CHR-EXPR.\"\n (with-rebinding (char-class)\n (with-unique-names (test-function)\n (flet ((substitute-char-class-tester (new)\n (subst new '(char-class-test) body\n :test #'equalp)))\n `(let ((,test-function (test-function ,char-class)))\n ,@(substitute-char-class-tester\n `(funcall ,test-function ,chr-expr)))))))", "macroexpand": "(let ((#:char-class159 regex)) (let ((#:test-function160 (test-function #:char-class159))) (non-greedy-constant-length-closure (funcall #:test-function160 (schar *string* curr-pos)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when (first in-decl-item) (if (gethash identifier (first names)) (setf (first make-block) t) (progn (push identifier (first delta-names)) (setf (gethash identifier (first names)) t))))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when (first in-decl-item) (if (gethash identifier (first names)) (setf (first make-block) t) (progn (push identifier (first delta-names)) (setf (gethash identifier (first names)) t))))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (first in-decl-item) (if (gethash identifier (first names)) (setf (first make-block) t) (progn (push identifier (first delta-names)) (setf (gethash identifier (first names)) t))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(set-plist-val! nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by SET-PLIST-VAL!", "input": "(set-plist-val! nil :key nil)", "output": "(defmacro set-plist-val! (new id place\n &key (test '(default-test)) (key '(default-key)))\n `(setf ,place\n (set-plist-val ,new ,id ,place :test ,test :key ,key)))", "macroexpand": "(setf nil (set-plist-val nil :key nil :test (default-test) :key (default-key)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(iterate:declare-variables)\n\nWrite a macro that addresses: Macro call that should be transformed by iterate", "input": "(iterate:declare-variables)", "output": "(defmacro iterate (&body body)\n \"Jonathan Amsterdam's powerful iteration facility\"\n `(iter .,body))", "macroexpand": "(declare-variables)", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-packages-unlocked nil\n nil)\n\nIssue: Macro call that should be transformed by WITH-PACKAGES-UNLOCKED", "input": "(with-packages-unlocked nil\n nil)", "output": "(defmacro WITH-PACKAGES-UNLOCKED ...)", "macroexpand": "(let ((#:|packages121| (locked-packages 'nil)))\n (unlock-packages #:|packages121|)\n (unwind-protect nil (lock-packages #:|packages121|)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(defhandler quote (quote object) `(list ',quote ',object))\n\nPattern to recognize: Macro call that should be transformed by defhandler", "input": "(defhandler quote (quote object) `(list ',quote ',object))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-quote (quote object) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr quote :kind 0)) (quote #S(sb-impl::comma :expr object :kind 0))))) (setf (gethash (quote quote) *form-handler*) (quote hander-quote)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ematch0 more-patterns ((list _ pattern) (analyze-pattern pattern)) ((list* _ pattern more-patterns) (analyze-pattern pattern) (analyze-more-patterns more-patterns)))\n\nWrite a macro that addresses: Macro call that should be transformed by ematch0", "input": "(ematch0 more-patterns ((list _ pattern) (analyze-pattern pattern)) ((list* _ pattern more-patterns) (analyze-pattern pattern) (analyze-more-patterns more-patterns)))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 more-patterns ((list _ pattern) (analyze-pattern pattern)) ((list* _ pattern more-patterns) (analyze-pattern pattern) (analyze-more-patterns more-patterns)) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(draw group (:circle :cx x :cy y :r (/ w 4)))\n\nWhat needs to change: Macro call that should be transformed by draw", "input": "(draw group (:circle :cx x :cy y :r (/ w 4)))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g159 (funcall (function make-svg-element) :circle (append (list :cx x :cy y :r (/ w 4)) (list))))) (add-element group #:g159) #:g159)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-syntax-error \"There is no property named ~S.\" property-name)\n\nIssue: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"There is no property named ~S.\" property-name)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"There is no property named ~S.\" property-name)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-object-lookup compiler-macro compiler-macro-function)\n\nIssue: Macro call that should be transformed by define-simple-object-lookup", "input": "(define-simple-object-lookup compiler-macro compiler-macro-function)", "output": "(defmacro define-simple-object-lookup (class lookup-function &body body)\n `(defmethod object ((,class ,class))\n ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function (designator ,class)))))", "macroexpand": "(defmethod object ((compiler-macro compiler-macro)) (compiler-macro-function (designator compiler-macro)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym collect :collect)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym collect :collect)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote collect) (quote synonym)) (quote :collect)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*> +comma+ +skip-space-and-comments+)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> +comma+ +skip-space-and-comments+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset239) (multiple-value-bind (#:*>-res240 #:*>-next241) (funcall +comma+ #:*>-offset239) (if (ok? #:*>-res240) (funcall +skip-space-and-comments+ #:*>-next241) (fail #:*>-next241))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-for nil\n (progn))\n\nProblem: Macro call that should be transformed by DO-FOR", "input": "(do-for nil\n (progn))", "output": "(defmacro DO-FOR ...)", "macroexpand": "(block nil (lc ((block nil (tagbody (return (progn (progn)))))) progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-condition partial-cant-be-found () ((partial-name :initarg :partial-name :type string :reader partial-name)) (:report (lambda (condition stream) (format stream \"Unable to find dynamic partial \\\"~A\\\" in a context.\" (partial-name condition)))))\n\nWrite a macro that addresses: Macro call that should be transformed by define", "input": "(define-condition partial-cant-be-found () ((partial-name :initarg :partial-name :type string :reader partial-name)) (:report (lambda (condition stream) (format stream \"Unable to find dynamic partial \\\"~A\\\" in a context.\" (partial-name condition)))))", "output": "(defmacro define (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "macroexpand": "(progn (sb-kernel::%define-condition (quote partial-cant-be-found) (quote (condition)) (sb-kernel::find-condition-layout (quote partial-cant-be-found) (quote (condition))) (list (sb-kernel::make-condition-slot :name (quote partial-name) :initargs (quote (:partial-name)) :readers (quote (partial-name)) :writers (quote nil) :initform-p (quote nil) :documentation (quote nil) :initform nil :initfunction nil :allocation (quote :instance))) (list) (quote (partial-name)) (quote nil) (sb-c:source-location)) (sb-kernel::%set-condition-report (quote partial-cant-be-found) (function (sb-int:named-lambda (sb-kernel::condition-report partial-cant-be-found) (condition stream) (declare (type condition condition) (type stream stream)) (funcall (function (lambda (condition stream) (format stream \"Unable to find dynamic partial \\\"~A\\\" in a context.\" (partial-name condition)))) condition stream)))) (quote partial-cant-be-found))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-custom-var (:string-char *string-char-handler*) (constantly t) \"Designator for a function of 1 character argument (String char).\")\n\nIssue: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:string-char *string-char-handler*) (constantly t) \"Designator for a function of 1 character argument (String char).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*string-char-handler* . :string-char)) *custom-vars* :test (function equal)) (defvar *string-char-handler* (constantly t) \"Designator for a function of 1 character argument (String char).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(flow-lambda-macro (flow-context) (with-flow-function-macro (body-fu lambda-list body) `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts)))\n\nWrite a macro that addresses: Macro call that should be transformed by flow-lambda-macro", "input": "(flow-lambda-macro (flow-context) (with-flow-function-macro (body-fu lambda-list body) `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts)))", "output": "(defmacro flow-lambda-macro ((flow-context) &body body)\n `(with-gensyms (,flow-context)\n `(%flow-lambda (,,flow-context)\n ,,@body)))", "macroexpand": "(with-gensyms (flow-context) (sb-int:quasiquote (%flow-lambda (#S(sb-impl::comma :expr flow-context :kind 0)) #S(sb-impl::comma :expr (with-flow-function-macro (body-fu lambda-list body) (sb-int:quasiquote (dispatch-atomically #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr body-fu :kind 0)) #S(sb-impl::comma :expr invariant :kind 0) #S(sb-impl::comma :expr opts :kind 2)))) :kind 0))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(enable-reader-syntax 'some-name)\n\nWhat needs to change: Macro call that should be transformed by ENABLE-READER-SYNTAX", "input": "(enable-reader-syntax 'some-name)", "output": "(defmacro ENABLE-READER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (push *readtable* *previous-readtables*)\n (setq *readtable* (copy-readtable))\n (%enable-reader-syntax *readtable* 'some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some-<>>\n nil\n (progn))\n\nProblem: Macro call that should be transformed by SOME-<>>", "input": "(some-<>>\n nil\n (progn))", "output": "(defmacro SOME-<>> ...)", "macroexpand": "(let* ((#:var143 nil)\n (#:var144\n (if #:var143\n (progn #:var143)\n nil)))\n #:var144)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defvar-compile-time *nondeterministic-context?* nil \"This must be globally NIL.\")\n\nIssue: Macro call that should be transformed by defvar-compile-time", "input": "(defvar-compile-time *nondeterministic-context?* nil \"This must be globally NIL.\")", "output": "(defmacro defvar-compile-time (name &optional initial-value documentation)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,name ,initial-value ,documentation)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *nondeterministic-context?* nil \"This must be globally NIL.\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defpackage nil :key nil)\n\nProblem: Macro call that should be transformed by DEFPACKAGE", "input": "(defpackage nil :key nil)", "output": "(defmacro DEFPACKAGE ...)", "macroexpand": "(common-lisp:defpackage nil\n (:use :adhoc :closer-mop :cl)\n (:shadowing-import-from :closer-mop\n #:defmethod\n #:standard-generic-function\n #:defgeneric\n #:standard-method\n #:standard-class)\n (:shadowing-import-from :adhoc #:defpackage #:variable #:the)\n :key\n ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-generic generic (a b &key c) (declare (optimize speed (space 2))) (+ a b c))\n\nPattern to recognize: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c) (declare (optimize speed (space 2))) (+ a b c))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (declare (optimize speed (space 2))) (:method (a b &key c) (declare (optimize speed (space 2))) (+ a b c))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n($ nil (progn))\n\nIssue: Macro call that should be transformed by $", "input": "($ nil (progn))", "output": "(defmacro $ ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(without-c-dependency (c-propagate c prior-value t))\n\nProblem: Macro call that should be transformed by without-c-dependency", "input": "(without-c-dependency (c-propagate c prior-value t))", "output": "(defmacro without-c-dependency (&body body)\n ` (let (*depender*)\n ,@body))", "macroexpand": "(let (*depender*) (c-propagate c prior-value t))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(collect-stream nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by COLLECT-STREAM", "input": "(collect-stream nil :key nil)", "output": "(defmacro COLLECT-STREAM ...)", "macroexpand": "(common-lisp:let* ((#:generator-489 (generator :key)) #:items-484)\n (declare (type generator #:generator-489))\n (tagbody\n #:ll-490\n (setq #:items-484 (next-in #:generator-489 (go end)))\n (common-lisp:funcall nil #:items-484 nil)\n (go #:ll-490)\n end)\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclass/a dbd-sqlite3-connection (dbi-connection) ())\n\nProblem: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbd-sqlite3-connection (dbi-connection) ())", "output": "(defmacro defclass/a (name superclasses slots &rest class-options)\n `(progn\n (defclass ,name ,superclasses ,slots ,@class-options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (defclass dbd-sqlite3-connection (dbi-connection) nil) (deftype nil (quote dbd-sqlite3-connection)) (setf (find-class (quote )) (find-class (quote dbd-sqlite3-connection))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-collectors nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-COLLECTORS", "input": "(with-collectors nil\n :key\n nil)", "output": "(defmacro WITH-COLLECTORS ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield (do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield", "input": "(with-yield (do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g))))", "output": "(defmacro with-yield (&body body)\n (let ((point (gensym))\n (current (gensym)))\n `(let (,point ,current)\n (with-call/cc\n\t (labels ((yield (&rest values)\n\t\t (setf ,current values)\n\t\t (let/cc k\n\t\t (setf ,point k))))\n\t ,@body\n\t (setf ,point nil)))\n (gen-lambda ()\n\t (cond ((null ,point)\n\t\t'generator-stop)\n\t (t\n\t\t(let ((current ,current))\n\t\t (funcall ,point nil)\n\t\t ;values-handler: see gen-lambda\n\t\t (apply #'values (funcall values-handler current)))))))))", "macroexpand": "(let (#:g145 #:g146) (with-call/cc (labels ((yield (&rest values) (setf #:g146 values) (let/cc k (setf #:g145 k)))) (do-generators ((g (some-numbers)) (:list l data)) (yield (+ l g))) (setf #:g145 nil))) (gen-lambda nil (cond ((null #:g145) (quote generator-stop)) (t (let ((current #:g146)) (funcall #:g145 nil) (apply (function values) (funcall values-handler current)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(%proper-list-p object)\n\nPattern to recognize: Macro call that should be transformed by %proper-list-p", "input": "(%proper-list-p object)", "output": "(defmacro %proper-list-p (var &optional (element-type '*))\n `(loop\n (typecase ,var\n (null (return t))\n (cons (if (or ,(eq element-type '*)\n (typep (car ,var) ,element-type))\n (setq ,var (cdr ,var))\n (return)))\n (t (return)))))", "macroexpand": "(loop (typecase object (null (return t)) (cons (if (or t (typep (car object) *)) (setq object (cdr object)) (return))) (t (return))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun/1 putc (c fd) (fputc c fd))\n\nIssue: Macro call that should be transformed by defun/1", "input": "(defun/1 putc (c fd) (fputc c fd))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun putc (c fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (fputc c fd)) (defparameter putc (vacietis.c:mkptr& (symbol-function (quote putc)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(assoc-cdr \"code\" parameters #'equal)\n\nWrite a macro that addresses: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr \"code\" parameters #'equal)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc \"code\" parameters :test (function equal)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(match list ((list x) unless (evenp x) x))\n\nProblem: Macro call that should be transformed by match", "input": "(match list ((list x) unless (evenp x) x))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(%or (%if (consp list) (let ((#:g142 (car list)) (#:g143 (cdr list))) (declare (ignorable #:g142 #:g143)) (%if (%equals #:g143 nil) (%or (let ((x #:g142)) (if (not (evenp x)) x (fail))) (fail)) (fail))) (fail)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(builder (if t (lambda (app) (lambda (env) (funcall app env))) nil) *app*)\n\nPattern to recognize: Macro call that should be transformed by builder", "input": "(builder (if t (lambda (app) (lambda (env) (funcall app env))) nil) *app*)", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (let ((#:res168 (if t (lambda (app) (lambda (env) (funcall app env))) nil))) (typecase #:res168 (keyword (find-middleware #:res168)) (cons (if (keywordp (car #:res168)) (let ((#:res-mw167 (find-middleware (car #:res168)))) (lambda (#:app166) (apply #:res-mw167 #:app166 (cdr #:res168)))) #:res168)) (standard-object (lambda (#:app166) (funcall (intern (string :wrap) :clack.middleware) #:res168 #:app166))) (otherwise #:res168))))) :initial-value (to-app *app*) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-definition-resolver declaration (designator) (sb-int:info :source-location :declaration designator))\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver declaration (designator) (sb-int:info :source-location :declaration designator))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver declaration (declaration #:package152) (when (ignore-errors (let ((designator declaration)) (sb-int:info :source-location :declaration designator))) (list (make-instance (quote declaration) :designator declaration :package #:package152))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(draw scene (:ellipse :cx (random 500) :cy (random 500) :rx (+ 10 (random 65)) :ry (+ 10 (random 65))) :stroke \"rgb(232, 229, 148)\" :fill (one-of *groovy-test-colors*))\n\nWrite a macro that addresses: Macro call that should be transformed by draw", "input": "(draw scene (:ellipse :cx (random 500) :cy (random 500) :rx (+ 10 (random 65)) :ry (+ 10 (random 65))) :stroke \"rgb(232, 229, 148)\" :fill (one-of *groovy-test-colors*))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g146 (funcall (function make-svg-element) :ellipse (append (list :cx (random 500) :cy (random 500) :rx (+ 10 (random 65)) :ry (+ 10 (random 65))) (list :stroke \"rgb(232, 229, 148)\" :fill (one-of *groovy-test-colors*)))))) (add-element scene #:g146) #:g146)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(accase (car x) (:y :no) (:x (list it :yes)))\n\nProblem: Macro call that should be transformed by accase", "input": "(accase (car x) (:y :no) (:x (list it :yes)))", "output": "(defmacro accase (keyform &body cases)\n \"Like CCASE, except binds the result of the keyform to IT (via LET) for the\nscope of the cases. Unlike CCASE, the keyform/place doesn't receive new values\npossibly stored with STORE-VALUE restart; the new value is received by IT.\"\n `(anaphoric ccase ,keyform ,@cases))", "macroexpand": "(anaphoric ccase (car x) (:y :no) (:x (list it :yes)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-name-transformer 'some-name)\n\nWhat needs to change: Macro call that should be transformed by MAKE-NAME-TRANSFORMER", "input": "(make-name-transformer 'some-name)", "output": "(defmacro MAKE-NAME-TRANSFORMER ...)", "macroexpand": "(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol 'some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(emit 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by EMIT", "input": "(emit 'some-name)", "output": "(defmacro EMIT ...)", "macroexpand": "(let ((#:ast182 'some-name))\n (progn\n (assert (typep #:ast182 'delayed-emitting) nil\n \"Something went awry around the quasi quoted stuff, EMIT got a ~S.\"\n #:ast182)\n (funcall #:ast182)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (eql (top-sign) 'first-initializer) (pop-sign))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (eql (top-sign) 'first-initializer) (pop-sign))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql (top-sign) (quote first-initializer)) (pop-sign))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(letrec ((f (constantly t)) (a (funcall f))) a)\n\nIssue: Macro call that should be transformed by letrec", "input": "(letrec ((f (constantly t)) (a (funcall f))) a)", "output": "(defmacro letrec ((&rest bindings) &body body)\n \"Recursive LET.\nThe idea is that functions created in BINDINGS can close over one\nanother, and themselves.\n\nNote that `letrec' only binds variables: it can define recursive\nfunctions, but can't bind them as functions. (But see `fbindrec'.)\"\n `(letrec-with psetq ,bindings\n ,@body))", "macroexpand": "(letrec-with psetq ((f (constantly t)) (a (funcall f))) a)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-class child2 (parent2) ((name \"foo\" :type string) (age 17) (bio \"Dummy biography\")) (:automatic-types-p t))\n\nWrite a macro that addresses: Macro call that should be transformed by define-class", "input": "(define-class child2 (parent2) ((name \"foo\" :type string) (age 17) (bio \"Dummy biography\")) (:automatic-types-p t))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass child2 (parent2) ((name :initform \"foo\" :accessor name :initarg :name :type string) (age :initform 17 :accessor age :initarg :age) (bio :initform \"Dummy biography\" :accessor bio :initarg :bio))) (unless (fboundp (quote child2p)) (define-generic child2p (object) #A((71) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `child2'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote child2)))) (setf (documentation (quote bio) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot BIO.\")) (ignore-errors (setf (documentation (fdefinition (quote bio)) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot BIO.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf bio))) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot BIO.\"))) (setf (documentation (quote age) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\")) (ignore-errors (setf (documentation (fdefinition (quote age)) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf age))) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\"))) (setf (documentation (quote name) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\")) (ignore-errors (setf (documentation (fdefinition (quote name)) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf name))) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\"))) (find-class (quote child2) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-infix-syntax)\n\nProblem: Macro call that should be transformed by ENABLE-INFIX-SYNTAX", "input": "(enable-infix-syntax)", "output": "(defmacro ENABLE-INFIX-SYNTAX ...)", "macroexpand": "(use-syntax :mexpr)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(var nil)\n\nProblem: Macro call that should be transformed by VAR", "input": "(var nil)", "output": "(defmacro VAR ...)", "macroexpand": "(defparameter nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-option-expander import-from (package import-package &rest symbols) (import (collect-symbols-from import-package symbols) package))\n\nPattern to recognize: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander import-from (package import-package &rest symbols) (import (collect-symbols-from import-package symbols) package))", "output": "(defmacro define-option-expander (name (package &rest arguments) &body body)\n (let ((args (gensym \"ARGS\")))\n `(defmethod expand-option ((,(gensym \"TYPE\") (eql ,(intern (string name) \"KEYWORD\"))) ,package ,args)\n (destructuring-bind ,arguments ,args\n ,@body))))", "macroexpand": "(defmethod expand-option ((#:type132 (eql :import-from)) package #:args131) (destructuring-bind (import-package &rest symbols) #:args131 (import (collect-symbols-from import-package symbols) package)))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclause accumulating-to (vars &key initially by finally) \"Specifies an accumulation clause. Refer to the manual for details.\" (labels ((make-finally-form (var function) `(setf ,var (funcall ,function ,var))) (make-one-accumulation (var) (cons (make-simple-iteration :var var :init initially) (if by (list* (make-accumulator :var var :function by) (when finally (list (make-finalization :form (make-finally-form var finally))))) (list (make-accumulator :var var :function '(function cons)) (make-finalization :form (make-finally-form var (or finally '(function nreverse))))))))) (mapcan #'make-one-accumulation (ensure-list vars))))\n\nProblem: Macro call that should be transformed by defclause", "input": "(defclause accumulating-to (vars &key initially by finally) \"Specifies an accumulation clause. Refer to the manual for details.\" (labels ((make-finally-form (var function) `(setf ,var (funcall ,function ,var))) (make-one-accumulation (var) (cons (make-simple-iteration :var var :init initially) (if by (list* (make-accumulator :var var :function by) (when finally (list (make-finalization :form (make-finally-form var finally))))) (list (make-accumulator :var var :function '(function cons)) (make-finalization :form (make-finally-form var (or finally '(function nreverse))))))))) (mapcan #'make-one-accumulation (ensure-list vars))))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro accumulating-to (vars &key initially by finally) \"Specifies an accumulation clause. Refer to the manual for details.\" (labels ((make-finally-form (var function) (sb-int:quasiquote (setf #S(sb-impl::comma :expr var :kind 0) (funcall #S(sb-impl::comma :expr function :kind 0) #S(sb-impl::comma :expr var :kind 0))))) (make-one-accumulation (var) (cons (make-simple-iteration :var var :init initially) (if by (list* (make-accumulator :var var :function by) (when finally (list (make-finalization :form (make-finally-form var finally))))) (list (make-accumulator :var var :function (quote (function cons))) (make-finalization :form (make-finally-form var (or finally (quote (function nreverse)))))))))) (mapcan (function make-one-accumulation) (ensure-list vars)))) (pushnew (quote accumulating-to) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defsynonym leave :leave)\n\nWrite a macro that addresses: Macro call that should be transformed by defsynonym", "input": "(defsynonym leave :leave)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote leave) (quote synonym)) (quote :leave)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(maybe-once-only 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by MAYBE-ONCE-ONLY", "input": "(maybe-once-only 'some-name)", "output": "(defmacro MAYBE-ONCE-ONLY ...)", "macroexpand": "(let* ((#:g185 nil)\n (quote\n (let ((form (ps-macroexpand quote)))\n (if (atom form)\n form\n (let ((var1 (ps-gensym 'quote)))\n (push (list var1 form) #:g185)\n var1))))\n (some-name\n (let ((form (ps-macroexpand some-name)))\n (if (atom form)\n form\n (let ((var1 (ps-gensym 'some-name)))\n (push (list var1 form) #:g185)\n var1)))))\n `(let* ,(nreverse #:g185)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-path curvy (smooth-quadratic-curve-to (random 500) (random 500)))\n\nPattern to recognize: Macro call that should be transformed by with-path", "input": "(with-path curvy (smooth-quadratic-curve-to (random 500) (random 500)))", "output": "(defmacro with-path (path &body cmds)\n (let ((s (gensym \"stream\"))\n (n (gensym)))\n `(flet ((assert-string (s)\n (error-unless-string s)))\n (with-output-to-string (,s ,path)\n ;; Do trivial breaking up of the path data - SVG does not have\n ;; to accept indefinitely long lines of data.\n (let ((,n 0))\n (dolist (inst (mapcar #'assert-string (list ,@cmds)) (format ,s \"~&\"))\n (format ,s \"~@{~A~}\" inst)\n (incf ,n)\n (when (= (mod ,n 10) 0)\n (format ,s \"~&\"))))))))", "macroexpand": "(flet ((assert-string (s) (error-unless-string s))) (with-output-to-string (#:|stream138| curvy) (let ((#:g139 0)) (dolist (inst (mapcar (function assert-string) (list (smooth-quadratic-curve-to (random 500) (random 500)))) (format #:|stream138| \"~&\")) (format #:|stream138| \"~@{~A~}\" inst) (incf #:g139) (when (= (mod #:g139 10) 0) (format #:|stream138| \"~&\"))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-error keyword-in-function-position () (form) \"Keyword cannot appear in function name position : ~s\" form)\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error keyword-in-function-position () (form) \"Keyword cannot appear in function name position : ~s\" form)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition keyword-in-function-position (:error-type varjo-error :prefix \"Varjo\") (form) \"Keyword cannot appear in function name position : ~s\" form)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-element-maker :polyline \"polyline\" '(:points))\n\nWhat needs to change: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :polyline \"polyline\" '(:points))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :polyline)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:points)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :polyline missing))))) (defmethod make-svg-element ((element (eql :polyline)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"polyline\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(answer (foo 1) 42)\n\nProblem: Macro call that should be transformed by answer", "input": "(answer (foo 1) 42)", "output": "(defmacro answer (call &body forms)\n (let ((name (if (listp call) (car call) call))\n (sym (gensym)))\n `(if-called\n ',name\n (let ((,sym (fdefinition ',name)))\n (declare (ignorable ,sym))\n (let ((times 0))\n (lambda (&rest args)\n (declare (ignorable args))\n ,(let ((cases\n `(case (prog1 times (incf times))\n ,.(loop\n for i from 0\n for (form . rest) on forms\n collect `(,(if rest i T) ,form)))))\n (if (listp call)\n `(trivia:match args\n ((list . ,(cdr call)) ,cases)\n (_ (unhandled)))\n cases))))))))", "macroexpand": "(if-called (quote foo) (let ((#:g158 (fdefinition (quote foo)))) (declare (ignorable #:g158)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (trivia.level2:match args ((list 1) (case (prog1 times (incf times)) (t 42))) (_ (unhandled)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(c? (incf delta-ct) (trc nil \"syn-b rule firing!!!!!!!!!!!!!!\" delta-ct) (eko (nil \"syn-b rule returning\") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a))))\n\nWhat needs to change: Macro call that should be transformed by c?", "input": "(c? (incf delta-ct) (trc nil \"syn-b rule firing!!!!!!!!!!!!!!\" delta-ct) (eko (nil \"syn-b rule returning\") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a))))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((incf delta-ct) (trc nil \"syn-b rule firing!!!!!!!!!!!!!!\" delta-ct) (eko (nil \"syn-b rule returning\") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a))))) :value-state :unevaluated :rule (c-lambda (incf delta-ct) (trc nil \"syn-b rule firing!!!!!!!!!!!!!!\" delta-ct) (eko (nil \"syn-b rule returning\") (f-delta :syna-1 (:sensitivity 2) (^m-syn-a)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield-binds (format nil \"~A ~A ~A\" (slot-value clause 'name) (yield (distinct-on-clause-columns clause)) (yield (statement-clause-statement clause))))\n\nWhat needs to change: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~A ~A ~A\" (slot-value clause 'name) (yield (distinct-on-clause-columns clause)) (yield (statement-clause-statement clause))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~A ~A ~A\" (slot-value clause (quote name)) (yield (distinct-on-clause-columns clause)) (yield (statement-clause-statement clause)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-global-parameter* nil nil)\n\nIssue: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER*", "input": "(define-global-parameter* nil nil)", "output": "(defmacro DEFINE-GLOBAL-PARAMETER* ...)", "macroexpand": "(progn\n (setf (get 'nil +value-key+) nil)\n (sb-ext:define-load-time-global nil (get 'nil +value-key+))\n (setf nil (get 'nil +value-key+))\n (remprop 'nil +value-key+)\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-store-entry (key store) (trc \"looked up dead item -- resetting to nil\" key store) (setf (item key store) nil))\n\nWrite a macro that addresses: Macro call that should be transformed by with-store-entry", "input": "(with-store-entry (key store) (trc \"looked up dead item -- resetting to nil\" key store) (setf (item key store) nil))", "output": "(defmacro with-store-entry ((key store &key quiet) &body body)\n `(prog1\n (progn\n\t ,@body)\n (unless ,quiet\n (kick-c-link ,key ,store))))", "macroexpand": "(prog1 (progn (trc \"looked up dead item -- resetting to nil\" key store) (setf (item key store) nil)) (unless nil (kick-c-link key store)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(js-inline nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by JS-INLINE", "input": "(js-inline nil :key nil)", "output": "(defmacro JS-INLINE ...)", "macroexpand": "(js-inline* '(progn nil :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars)))\n\nWrite a macro that addresses: Macro call that should be transformed by do-generator-value-list", "input": "(do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars)))", "output": "(defmacro do-generator-value-list ((var generator) &body body)\n \"Like do-generator, except all values emitted by the generator are placed in a list under the user defined variable.\"\n (let ((g (gensym)))\n `(let ((,g ,generator))\n (loop \n\t do (if-generator (,var ,g)\n\t\t\t (progn ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g179 (apply (function multi-gen) generators))) (loop do (if-generator (vars #:g179) (progn (apply (function yield) (mapcar (function car) vars))) (return))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-case-aware-token-p-function pp-with-c-syntax-pragma-p find-pragma-name with-c-syntax.pragma-name:|WITH_C_SYNTAX|)\n\nProblem: Macro call that should be transformed by define-case-aware-token-p-function", "input": "(define-case-aware-token-p-function pp-with-c-syntax-pragma-p find-pragma-name with-c-syntax.pragma-name:|WITH_C_SYNTAX|)", "output": "(defmacro define-case-aware-token-p-function (function-name find-symbol-function symbol)\n `(defun ,function-name (token &optional (readtable-case (readtable-case *readtable*)))\n (and (symbolp token)\n (eq (,find-symbol-function (string token) readtable-case)\n ',symbol))))", "macroexpand": "(defun pp-with-c-syntax-pragma-p (token &optional (readtable-case (readtable-case *readtable*))) (and (symbolp token) (eq (find-pragma-name (string token) readtable-case) (quote with-c-syntax.pragma-name:with_c_syntax))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-stream-method pp-xml-attr (s (kw symbol) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" (xmlify-keyword kw)))\n\nWhat needs to change: Macro call that should be transformed by make-stream-method", "input": "(make-stream-method pp-xml-attr (s (kw symbol) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" (xmlify-keyword kw)))", "output": "(defmacro make-stream-method (name (s &rest args) &body body)\n `(progn\n (defmethod ,name ((,s stream) ,@args)\n ,@body)\n #+abcl\n (defmethod ,name ((,s xp::xp-structure) ,@args)\n ,@body)))", "macroexpand": "(progn (defmethod pp-xml-attr ((s stream) (kw symbol) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" (xmlify-keyword kw))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-global-var nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-GLOBAL-VAR", "input": "(define-global-var nil :key nil)", "output": "(defmacro DEFINE-GLOBAL-VAR ...)", "macroexpand": "(sb-ext:defglobal nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclass/std prefix () ((without-prefix)))\n\nProblem: Macro call that should be transformed by defclass/std", "input": "(defclass/std prefix () ((without-prefix)))", "output": "(defmacro defclass/std (name direct-superclasses direct-slots &rest options\n &environment env)\n \"Shortcut macro to the DEFCLASS macro.\n\n (defclass/std example ()\n ((slot1 slot2 slot3)))\n\n expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\n Each slot definition accepts options:\n\n :std 1 => changes the :initform to 1. It can be :unbound.\n :with or :with-prefix => creates accessors with the class name as prefix.\n\n See the README for more.\n\n See also `class/std' and `print-object/std'.\n \"\n `(defclass ,name ,direct-superclasses\n ,(process-slots env direct-slots name)\n ,@options))", "macroexpand": "(defclass prefix nil ((without-prefix :accessor without-prefix :initarg :without-prefix :initform nil)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defsynonym :as :for)\n\nIssue: Macro call that should be transformed by defsynonym", "input": "(defsynonym :as :for)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :as) (quote synonym)) (quote :for)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(-> :g (a) (+ 1 a))\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(-> :g (a) (+ 1 a))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (a) (+ 1 a))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-length nil)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-LENGTH", "input": "(collect-length nil)", "output": "(defmacro COLLECT-LENGTH ...)", "macroexpand": "(common-lisp:let* ((#:generator-462 (generator nil)) (#:number-459 0))\n (declare (type generator #:generator-462)\n (type fixnum #:number-459))\n (tagbody\n #:ll-463\n (next-in #:generator-462 (go end))\n (incf #:number-459)\n (go #:ll-463)\n end)\n #:number-459)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(check-cursor-attached cluffer:erase-item (cursor))\n\nPattern to recognize: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:erase-item (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:erase-item :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-hook (:boot uiop) () (unless uiop/image::*image-restored-p* (setf uiop/image::*image-restored-p* :in-progress) (uiop/image:call-image-restore-hook) (setf uiop/image::*image-restored-p* T)))\n\nPattern to recognize: Macro call that should be transformed by define-hook", "input": "(define-hook (:boot uiop) () (unless uiop/image::*image-restored-p* (setf uiop/image::*image-restored-p* :in-progress) (uiop/image:call-image-restore-hook) (setf uiop/image::*image-restored-p* T)))", "output": "(defmacro define-hook ((type name &optional (priority 0)) args &body body)\n (ecase type (:pre-load) (:load) (:build) (:deploy) (:boot) (:quit))\n (check-type name symbol)\n `(let ((,name (or (hook ,type ',name)\n (make-instance 'hook :name ',name :type ,type))))\n (setf (hook-priority ,name) ,priority)\n (setf (hook-function ,name) (flet ((,name (&key ,@args &allow-other-keys)\n ,@body))\n #',name))\n (setf (hook ,type ',name) ,name)\n (setf (docstring ,name) ,(if (stringp (car body)) (car body)))\n ',name))", "macroexpand": "(let ((uiop (or (hook :boot (quote uiop)) (make-instance (quote hook) :name (quote uiop) :type :boot)))) (setf (hook-priority uiop) 0) (setf (hook-function uiop) (flet ((uiop (&key &allow-other-keys) (unless uiop/image::*image-restored-p* (setf uiop/image::*image-restored-p* :in-progress) (uiop/image:call-image-restore-hook) (setf uiop/image::*image-restored-p* t)))) (function uiop))) (setf (hook :boot (quote uiop)) uiop) (setf (docstring uiop) nil) (quote uiop))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-fixture-restore macro (symbol value) (setf (macro-function symbol) value))\n\nWhat needs to change: Macro call that should be transformed by define-fixture-restore", "input": "(define-fixture-restore macro (symbol value) (setf (macro-function symbol) value))", "output": "(defmacro define-fixture-restore (name args &body body)\n `(progn (setf (gethash ',name *fixture-restores*)\n (lambda ,args ,@body))\n ',name))", "macroexpand": "(progn (setf (gethash (quote macro) *fixture-restores*) (lambda (symbol value) (setf (macro-function symbol) value))) (quote macro))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some->\n nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by SOME->", "input": "(some->\n nil\n :key\n nil)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:var173 nil)\n (#:var174\n (if #:var173\n (:key #:var173)\n nil))\n (#:var175\n (if #:var174\n (nil #:var174)\n nil)))\n #:var175)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym multiply :mult)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym multiply :mult)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote multiply) (quote synonym)) (quote :mult)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defjsmacro nil (progn))\n\nIssue: Macro call that should be transformed by DEFJSMACRO", "input": "(defjsmacro nil (progn))", "output": "(defmacro DEFJSMACRO ...)", "macroexpand": "(defpsmacro nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(assert-values (\"deleted bar\") (foo 'nothing) (foo+1 'nothing) (bar 'nothing) (bar-1 'nothing) (baz 'nothing))\n\nWrite a macro that addresses: Macro call that should be transformed by assert-values", "input": "(assert-values (\"deleted bar\") (foo 'nothing) (foo+1 'nothing) (bar 'nothing) (bar-1 'nothing) (baz 'nothing))", "output": "(defmacro assert-values ((desc) &body objects-and-values)\n `(progn\n (trc ,desc)\n ,@(loop for (obj val) in objects-and-values\n\t collect `(assert (eql (value ,obj) ,val)))))", "macroexpand": "(progn (trc \"deleted bar\") (assert (eql (value foo) (quote nothing))) (assert (eql (value foo+1) (quote nothing))) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))) (assert (eql (value baz) (quote nothing))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-quasi-quoted-string-to-binary-emitting-form-syntax nil)\n\nProblem: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX", "input": "(enable-quasi-quoted-string-to-binary-emitting-form-syntax nil)", "output": "(defmacro ENABLE-QUASI-QUOTED-STRING-TO-BINARY-EMITTING-FORM-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-string-to-binary-emitting-form-syntax-in-readtable nil\n :with-inline-emitting\n nil\n :declarations\n 'nil\n :start-character\n nil\n :end-character\n nil\n :unquote-character\n #\\COMMA\n :splice-character\n #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP\n :dispatched-quasi-quote-name\n \"str\"\n :encoding\n *default-character-encoding*)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun/1 fgetc (fd) (handler-case (char-code (read-char (fd-stream fd))) (end-of-file () (setf (feof fd) 1) EOF) (error () (setf (ferror fd) EIO) EOF)))\n\nWhat needs to change: Macro call that should be transformed by defun/1", "input": "(defun/1 fgetc (fd) (handler-case (char-code (read-char (fd-stream fd))) (end-of-file () (setf (feof fd) 1) EOF) (error () (setf (ferror fd) EIO) EOF)))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun fgetc (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (char-code (read-char (fd-stream fd))) (end-of-file nil (setf (feof fd) 1) eof) (error nil (setf (ferror fd) eio) eof))) (defparameter fgetc (vacietis.c:mkptr& (symbol-function (quote fgetc)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(max-of 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by MAX-OF", "input": "(max-of 'some-name)", "output": "(defmacro MAX-OF ...)", "macroexpand": "(lc ('some-name) maximize)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(rte-ecase nil)\n\nWrite a macro that addresses: Macro call that should be transformed by RTE-ECASE", "input": "(rte-ecase nil)", "output": "(defmacro RTE-ECASE ...)", "macroexpand": "(let ((#:rte171 nil))\n (rte-ecase #:rte171\n ((:* t) (error \"The sequence ~A fell through the RTE-ECASE\" #:rte171))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(class/std new-stub var1 var2 var3 var4 :with :std :unbound)\n\nPattern to recognize: Macro call that should be transformed by class/std", "input": "(class/std new-stub var1 var2 var3 var4 :with :std :unbound)", "output": "(defmacro class/std (name &body defaulted-slots)\n \"The most concise shortcut macro to DEFCLASS.\n\n (class/std example slot1 slot2 slot3)\n\n expands to:\n\n (DEFCLASS/STD EXAMPLE ()\n ((SLOT1 SLOT2 SLOT3)))\n\n which expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\"\n `(defclass/std ,name ()\n ((,@defaulted-slots))))", "macroexpand": "(defclass/std new-stub nil ((var1 var2 var3 var4 :with :std :unbound)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"40P01\" deadlock-detected transaction-rollback)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"40P01\" deadlock-detected transaction-rollback)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition deadlock-detected (transaction-rollback) nil) (setf (gethash \"40P01\" *error-table*) (quote deadlock-detected)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(signal-syntax-error* (1- (lexer-pos lexer)) \"Character '~A' may not follow '(?<' (because ~a = NIL)\" next-char '*allow-named-registers*)\n\nPattern to recognize: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (1- (lexer-pos lexer)) \"Character '~A' may not follow '(?<' (because ~a = NIL)\" next-char '*allow-named-registers*)", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos (1- (lexer-pos lexer)) :format-control \"Character '~A' may not follow '(?<' (because ~a = NIL)\" :format-arguments (list next-char (quote *allow-named-registers*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(fn 'some-name)\n\nProblem: Macro call that should be transformed by FN", "input": "(fn 'some-name)", "output": "(defmacro FN ...)", "macroexpand": "(lambda () 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-symbol-access\n nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-SYMBOL-ACCESS", "input": "(with-symbol-access\n nil\n nil)", "output": "(defmacro WITH-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* t))\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def$flavor nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by DEF$FLAVOR", "input": "(def$flavor nil :key nil)", "output": "(defmacro DEF$FLAVOR ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel)\n (defvar nil)\n (setq nil\n (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))\n flavor-class :name 'nil :supers\n (if 'nil\n (list)\n (list standard-object))\n :own-slots ':key :req-inst-vars 'nil)))\n (eval-when (:load-toplevel)\n (defvar nil)\n (setq nil\n (send-fast\n (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))\n flavor-class :name 'nil :supers\n (if 'nil\n (list)\n (list standard-object))\n :own-slots ':key :req-inst-vars 'nil)\n :init)))\n (eval-when (:execute)\n (defvar nil)\n (let ((new-class\n (funcall (mcs-slot-value flavor-class (index-of-basicnew-fn))\n flavor-class :name 'nil :supers\n (if 'nil\n (list)\n (list standard-object))\n :own-slots ':key :req-inst-vars 'nil)))\n (if (flavorp 'nil)\n (redefine-class nil new-class)\n (setq nil (send-fast new-class :init))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-wrap-attempt (\"accessors for structure ~S\" foreign-record) foreign-record (let ((*package* (find-package package)) (foreign-record (etypecase foreign-record (foreign-record foreign-record) ((or symbol cons) (require-type-no-context foreign-record))))) (unless (and (typep foreign-record 'foreign-alias) (struct-or-union-p (foreign-type-name foreign-record))) (let* ((*accessor-forms*) (*accessor-seen-types*) (*accessor-params* (list (foreign-type-name foreign-record))) (*accessor-record-name* (foreign-type-name foreign-record)) (actual-foreign-record (basic-foreign-type foreign-record))) (when (typep actual-foreign-record 'foreign-record) (%make-accessors actual-foreign-record :prefix *accessor-record-name*) `(progn ,@(nreverse *accessor-forms*)))))))\n\nWhat needs to change: Macro call that should be transformed by with-wrap-attempt", "input": "(with-wrap-attempt (\"accessors for structure ~S\" foreign-record) foreign-record (let ((*package* (find-package package)) (foreign-record (etypecase foreign-record (foreign-record foreign-record) ((or symbol cons) (require-type-no-context foreign-record))))) (unless (and (typep foreign-record 'foreign-alias) (struct-or-union-p (foreign-type-name foreign-record))) (let* ((*accessor-forms*) (*accessor-seen-types*) (*accessor-params* (list (foreign-type-name foreign-record))) (*accessor-record-name* (foreign-type-name foreign-record)) (actual-foreign-record (basic-foreign-type foreign-record))) (when (typep actual-foreign-record 'foreign-record) (%make-accessors actual-foreign-record :prefix *accessor-record-name*) `(progn ,@(nreverse *accessor-forms*)))))))", "output": "(defmacro with-wrap-attempt ((&optional format-control &rest format-args) wrappable-name &body body)\n `(call-with-wrap-attempt ,wrappable-name (lambda () ,@body) ,format-control (list ,@format-args)))", "macroexpand": "(call-with-wrap-attempt foreign-record (lambda nil (let ((*package* (find-package package)) (foreign-record (etypecase foreign-record (foreign-record foreign-record) ((or symbol cons) (require-type-no-context foreign-record))))) (unless (and (typep foreign-record (quote foreign-alias)) (struct-or-union-p (foreign-type-name foreign-record))) (let* ((*accessor-forms*) (*accessor-seen-types*) (*accessor-params* (list (foreign-type-name foreign-record))) (*accessor-record-name* (foreign-type-name foreign-record)) (actual-foreign-record (basic-foreign-type foreign-record))) (when (typep actual-foreign-record (quote foreign-record)) (%make-accessors actual-foreign-record :prefix *accessor-record-name*) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (nreverse *accessor-forms*) :kind 2)))))))) \"accessors for structure ~S\" (list foreign-record))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define 'some-name)\n\nPattern to recognize: Macro call that should be transformed by DEFINE", "input": "(define 'some-name)", "output": "(defmacro DEFINE ...)", "macroexpand": "(eval-when (:load-toplevel :execute)\n (check-if-bound ''some-name)\n (setf (get ''some-name 'read-macro)\n (lambda (#:stream149) (let ((*standard-input* #:stream149)))))\n ''some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(mvlet* ((fn (caar bindings)) (body decls (parse-body body)) (local others (partition-declarations `((function ,fn)) decls env))) `(fbind (,(first bindings)) ,@local (fbind* ,(rest bindings) ,@others ,@body)))\n\nProblem: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((fn (caar bindings)) (body decls (parse-body body)) (local others (partition-declarations `((function ,fn)) decls env))) `(fbind (,(first bindings)) ,@local (fbind* ,(rest bindings) ,@others ,@body)))", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(let* ((fn (caar bindings))) (mvlet* ((body decls (parse-body body)) (local others (partition-declarations (sb-int:quasiquote ((function #S(sb-impl::comma :expr fn :kind 0)))) decls env))) (sb-int:quasiquote (fbind (#S(sb-impl::comma :expr (first bindings) :kind 0)) #S(sb-impl::comma :expr local :kind 2) (fbind* #S(sb-impl::comma :expr (rest bindings) :kind 0) #S(sb-impl::comma :expr others :kind 2) #S(sb-impl::comma :expr body :kind 2))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-disable-handler-restart ((first handler-entry)) (with-hook-restart (list (apply (first handler-entry) args))))\n\nPattern to recognize: Macro call that should be transformed by with-disable-handler-restart", "input": "(with-disable-handler-restart ((first handler-entry)) (with-hook-restart (list (apply (first handler-entry) args))))", "output": "(defmacro with-disable-handler-restart ((handler) &body body)\n \"This is intended to wrap all handler executions.\"\n `(restart-case\n (progn ,@body)\n (disable-handler ()\n :report\n (lambda (stream)\n (format stream \"Disable handler ~a which causes the error.\" ,handler))\n (disable-hook *hook* ,handler))))", "macroexpand": "(restart-case (progn (with-hook-restart (list (apply (first handler-entry) args)))) (disable-handler nil :report (lambda (stream) (format stream \"Disable handler ~a which causes the error.\" (first handler-entry))) (disable-hook *hook* (first handler-entry))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:body (:h* \"This is a top level heading\") (:p \"...\") (let ((*html-path* (append *html-path* '(:section)))) (:h* \"This is a second-level tricked by *HTML-PATH*\") (:p \"...\"))))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:body (:h* \"This is a top level heading\") (:p \"...\") (let ((*html-path* (append *html-path* '(:section)))) (:h* \"This is a second-level tricked by *HTML-PATH*\") (:p \"...\"))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:body (:h* \"This is a top level heading\") (:p \"...\") (let ((*html-path* (append *html-path* (quote (:section))))) (:h* \"This is a second-level tricked by *HTML-PATH*\") (:p \"...\")))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(gen-lambda-with-sticky-stop () (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop))))\n\nWhat needs to change: Macro call that should be transformed by gen-lambda-with-sticky-stop", "input": "(gen-lambda-with-sticky-stop () (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop))))", "output": "(defmacro gen-lambda-with-sticky-stop (&rest rest)\n `(make-instance \n 'basic-generator \n :function (sticky-stop-lambda ,@rest)))", "macroexpand": "(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(macroexpand-convention (form) (if (consp form) (expand-export-constructors-using-head (first form) form) form))\n\nWrite a macro that addresses: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (if (consp form) (expand-export-constructors-using-head (first form) form) form))", "output": "(defmacro macroexpand-convention ((original-form) &body body)\n \"Executes BODY as like `progn' and return the result as the first\nvalue. As the second value, returns a boolean whether the result is\nnot same with ORIGINAL-FORM or not.\nThis macro is designed to follow the `macroexpand' convention.\"\n `(multiple-value-bind (result expanded-p)\n (progn ,@body)\n (values result\n (or expanded-p\n (not (eq result ,original-form))))))", "macroexpand": "(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-constructors-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-bug loop-flow-analysis-failure (:error-type varjo-critical-error) () \"Varjo's flow analyzer has been unable to resolve the variable flow in this loop within a reasonable ammount of time. This counts as a compiler bug so please report it on github\")\n\nProblem: Macro call that should be transformed by define-bug", "input": "(define-bug loop-flow-analysis-failure (:error-type varjo-critical-error) () \"Varjo's flow analyzer has been unable to resolve the variable flow in this loop within a reasonable ammount of time. This counts as a compiler bug so please report it on github\")", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition loop-flow-analysis-failure (:error-type varjo-critical-error :prefix \"Varjo Bug\") nil \"Varjo's flow analyzer has been unable to resolve the variable flow in this loop within a reasonable ammount of time. This counts as a compiler bug so please report it on github\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*> +skip-space+ +slash+)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> +skip-space+ +slash+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset259) (multiple-value-bind (#:*>-res260 #:*>-next261) (funcall +skip-space+ #:*>-offset259) (if (ok? #:*>-res260) (funcall +slash+ #:*>-next261) (fail #:*>-next261))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(none-of nil)\n\nWrite a macro that addresses: Macro call that should be transformed by NONE-OF", "input": "(none-of nil)", "output": "(defmacro NONE-OF ...)", "macroexpand": "(lc (nil) never)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-csv-input-stream (in-stream stream-or-string) (read-with-dispatch-table csv-reader in-stream) (coerce (rows csv-reader) 'list))\n\nWrite a macro that addresses: Macro call that should be transformed by with-csv-input-stream", "input": "(with-csv-input-stream (in-stream stream-or-string) (read-with-dispatch-table csv-reader in-stream) (coerce (rows csv-reader) 'list))", "output": "(defmacro with-csv-input-stream ((name inp) &body body)\n (alexandria:with-unique-names (opened?)\n `(multiple-value-bind (,name ,opened?) (%in-stream ,inp)\n (flet ((body () ,@body))\n (unwind-protect (body)\n (when (and ,name ,opened?)\n (close ,name)))))))", "macroexpand": "(multiple-value-bind (in-stream #:opened?199) (%in-stream stream-or-string) (flet ((body nil (read-with-dispatch-table csv-reader in-stream) (coerce (rows csv-reader) (quote list)))) (unwind-protect (body) (when (and in-stream #:opened?199) (close in-stream)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-input-from-file (stream pathname :element-type '(unsigned-byte 8)) (read-stream-content-into-byte-vector stream :initial-size (file-length stream)))\n\nIssue: Macro call that should be transformed by with-input-from-file", "input": "(with-input-from-file (stream pathname :element-type '(unsigned-byte 8)) (read-stream-content-into-byte-vector stream :initial-size (file-length stream)))", "output": "(defmacro with-input-from-file ((stream-name file-name &rest args\n &key (direction nil direction-p)\n &allow-other-keys)\n &body body)\n \"Evaluate BODY with STREAM-NAME to an input stream on the file\nFILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT,\nwhich is only sent to WITH-OPEN-FILE when it's not NIL.\"\n (declare (ignore direction))\n (when direction-p\n (error \"Can't specify :DIRECTION for WITH-INPUT-FROM-FILE.\"))\n `(with-open-file* (,stream-name ,file-name :direction :input ,@args)\n ,@body))", "macroexpand": "(with-open-file* (stream pathname :direction :input :element-type (quote (unsigned-byte 8))) (read-stream-content-into-byte-vector stream :initial-size (file-length stream)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(-> nil (value) (1+ value))\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(-> nil (value) (1+ value))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically nil (value) (1+ value))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(deferror \"08000\" connection-exception)\n\nWhat needs to change: Macro call that should be transformed by deferror", "input": "(deferror \"08000\" connection-exception)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition connection-exception (database-error) nil) (setf (gethash \"08000\" *error-table*) (quote connection-exception)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-readtable ((char reader-fn non-terminating-p disp? table) from) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to)))))\n\nPattern to recognize: Macro call that should be transformed by do-readtable", "input": "(do-readtable ((char reader-fn non-terminating-p disp? table) from) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to)))))", "output": "(defmacro do-readtable ((entry-designator readtable &optional result)\n &body body)\n \"Iterate through a readtable's macro characters, and dispatch macro characters.\"\n (destructuring-bind (char &optional reader-fn non-terminating-p disp? table)\n (if (symbolp entry-designator)\n (list entry-designator)\n entry-designator)\n (let ((iter (gensym \"ITER+\"))\n (more? (gensym \"MORE?+\"))\n (rt (gensym \"READTABLE+\")))\n `(let ((,rt ,readtable))\n (with-readtable-iterator (,iter ,rt)\n (loop\n (multiple-value-bind (,more?\n ,char\n ,@(when reader-fn (list reader-fn))\n ,@(when disp? (list disp?))\n ,@(when table (list table)))\n (,iter)\n (unless ,more? (return ,result))\n (let ,(when non-terminating-p\n ;; FIXME: N-T-P should be incorporated in iterators.\n `((,non-terminating-p\n (nth-value 1 (get-macro-character ,char ,rt)))))\n ,@body))))))))", "macroexpand": "(let ((#:readtable+149 from)) (with-readtable-iterator (#:iter+147 #:readtable+149) (loop (multiple-value-bind (#:more?+148 char reader-fn disp? table) (#:iter+147) (unless #:more?+148 (return nil)) (let ((non-terminating-p (nth-value 1 (get-macro-character char #:readtable+149)))) (check-reader-macro-conflict from to char) (cond ((not disp?) (set-macro-character char reader-fn non-terminating-p to)) (t (ensure-dispatch-macro-character char non-terminating-p to) (loop for (subchar . subfn) in table do (check-reader-macro-conflict from to char subchar) (set-dispatch-macro-character char subchar subfn to)))))))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :g (r) (put r))\n\nProblem: Macro call that should be transformed by ->", "input": "(-> :g (r) (put r))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (r) (put r))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<>> nil nil)\n\nProblem: Macro call that should be transformed by -<>>", "input": "(-<>> nil nil)", "output": "(defmacro -<>> ...)", "macroexpand": "(nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda-ignoring-_ (kwd id _l decl _r) (make-struct-or-union-spec :type kwd :id id :struct-decl-list decl))\n\nWrite a macro that addresses: Macro call that should be transformed by lambda-ignoring-_", "input": "(lambda-ignoring-_ (kwd id _l decl _r) (make-struct-or-union-spec :type kwd :id id :struct-decl-list decl))", "output": "(defmacro lambda-ignoring-_ (lambda-list &body body)\n \"Works like `cl:lambda' macro except automatically `declare's\n `ignore' for parameters beginning with '_' character.\"\n (let ((ignored-parameters\n (collect-_-symbol-in-lambda-list lambda-list)))\n (unless ignored-parameters\n (warn \"No ignored parameters in: ~A\" lambda-list))\n (multiple-value-bind (body decls doc)\n (parse-body body :documentation t)\n `(lambda ,lambda-list\n ,@ (if doc `(,doc))\n (declare (ignore ,@ignored-parameters))\n ,@decls\n ,@body))))", "macroexpand": "(lambda (kwd id _l decl _r) (declare (ignore _l _r)) (make-struct-or-union-spec :type kwd :id id :struct-decl-list decl))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-test override (true T) (skip \"Not ready yet\" (false T) (is = 5 6)) (with-forced-status (:failed) (false NIL)))\n\nWhat needs to change: Macro call that should be transformed by define-test", "input": "(define-test override (true T) (skip \"Not ready yet\" (false T) (is = 5 6)) (with-forced-status (:failed) (false NIL)))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote override) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote override) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (true t)) (lambda nil (skip \"Not ready yet\" (false t) (is = 5 6))) (lambda nil (with-forced-status (:failed) (false nil)))) :parent (quote nil))) (quote override))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-declaration nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFINE-DECLARATION", "input": "(define-declaration nil\n :key\n nil)", "output": "(defmacro DEFINE-DECLARATION ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (proclaim '(declaration nil))\n (flet ((sb-cltl2::func :key\n nil))\n (setf (sb-int:info :declaration :known 'nil)\n (lambda\n (sb-kernel:lexenv sb-cltl2::spec sb-cltl2::pd-vars\n sb-cltl2::pd-fvars)\n (multiple-value-bind (sb-cltl2::kind sb-cltl2::data)\n (sb-cltl2::func sb-cltl2::spec sb-kernel:lexenv)\n (sb-cltl2::update-lexenv-user-data sb-kernel:lexenv\n sb-cltl2::kind\n sb-cltl2::data\n sb-cltl2::pd-vars\n sb-cltl2::pd-fvars))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(make-stream-method pp-xml-attr (s (kw string) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" kw))\n\nPattern to recognize: Macro call that should be transformed by make-stream-method", "input": "(make-stream-method pp-xml-attr (s (kw string) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" kw))", "output": "(defmacro make-stream-method (name (s &rest args) &body body)\n `(progn\n (defmethod ,name ((,s stream) ,@args)\n ,@body)\n #+abcl\n (defmethod ,name ((,s xp::xp-structure) ,@args)\n ,@body)))", "macroexpand": "(progn (defmethod pp-xml-attr ((s stream) (kw string) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" kw)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(->> nil nil)\n\nPattern to recognize: Macro call that should be transformed by ->>", "input": "(->> nil nil)", "output": "(defmacro ->> ...)", "macroexpand": "(nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(action (:after node-lisp node new-subs) (multiple-value-bind (let-bindings lisp-var-bindings) (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for new-var := (gensym (symbol-name coalton-var)) :for res := (or (find coalton-var subs :key #'ast-substitution-from) (find coalton-var new-subs :key #'ast-substitution-from)) :if (and res (node-variable-p (ast-substitution-to res))) :collect (cons lisp-var (node-variable-value (ast-substitution-to res))) :into lisp-var-bindings :else :if res :collect (cons lisp-var new-var) :into lisp-var-bindings :and :collect (cons new-var (ast-substitution-to res)) :into let-bindings :else :collect (cons lisp-var coalton-var) :into lisp-var-bindings :finally (return (values let-bindings lisp-var-bindings))) (let ((new-lisp-node (make-node-lisp :type (node-type node) :vars lisp-var-bindings :form (node-lisp-form node)))) (if (endp let-bindings) new-lisp-node (make-node-let :type (node-type node) :bindings let-bindings :subexpr new-lisp-node)))))\n\nWhat needs to change: Macro call that should be transformed by action", "input": "(action (:after node-lisp node new-subs) (multiple-value-bind (let-bindings lisp-var-bindings) (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for new-var := (gensym (symbol-name coalton-var)) :for res := (or (find coalton-var subs :key #'ast-substitution-from) (find coalton-var new-subs :key #'ast-substitution-from)) :if (and res (node-variable-p (ast-substitution-to res))) :collect (cons lisp-var (node-variable-value (ast-substitution-to res))) :into lisp-var-bindings :else :if res :collect (cons lisp-var new-var) :into lisp-var-bindings :and :collect (cons new-var (ast-substitution-to res)) :into let-bindings :else :collect (cons lisp-var coalton-var) :into lisp-var-bindings :finally (return (values let-bindings lisp-var-bindings))) (let ((new-lisp-node (make-node-lisp :type (node-type node) :vars lisp-var-bindings :form (node-lisp-form node)))) (if (endp let-bindings) new-lisp-node (make-node-let :type (node-type node) :bindings let-bindings :subexpr new-lisp-node)))))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-lisp) (lambda (node new-subs) (declare (type node-lisp node)) (multiple-value-bind (let-bindings lisp-var-bindings) (loop :for (lisp-var . coalton-var) :in (node-lisp-vars node) :for new-var := (gensym (symbol-name coalton-var)) :for res := (or (find coalton-var subs :key (function ast-substitution-from)) (find coalton-var new-subs :key (function ast-substitution-from))) :if (and res (node-variable-p (ast-substitution-to res))) :collect (cons lisp-var (node-variable-value (ast-substitution-to res))) :into lisp-var-bindings :else :if res :collect (cons lisp-var new-var) :into lisp-var-bindings :and :collect (cons new-var (ast-substitution-to res)) :into let-bindings :else :collect (cons lisp-var coalton-var) :into lisp-var-bindings :finally (return (values let-bindings lisp-var-bindings))) (let ((new-lisp-node (make-node-lisp :type (node-type node) :vars lisp-var-bindings :form (node-lisp-form node)))) (if (endp let-bindings) new-lisp-node (make-node-let :type (node-type node) :bindings let-bindings :subexpr new-lisp-node))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-html-string (:a :href \"#\" :data-instant t))\n\nWrite a macro that addresses: Macro call that should be transformed by with-html", "input": "(with-html-string (:a :href \"#\" :data-instant t))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:a :href \"#\" :data-instant t)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT", "input": "(collect 'some-name)", "output": "(defmacro COLLECT ...)", "macroexpand": "(common-lisp:let* ((#:generator-608 (generator 'some-name))\n #:items-603\n (#:lastcons-604 (list nil))\n (#:lst-605 #:lastcons-604))\n (declare (type generator #:generator-608)\n (type cons #:lastcons-604)\n (type list #:lst-605))\n (tagbody\n #:ll-609\n (setq #:items-603 (next-in #:generator-608 (go end)))\n (setq #:lastcons-604 (setf (cdr #:lastcons-604) (cons #:items-603 nil)))\n (go #:ll-609)\n end)\n (cdr #:lst-605))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-clause never (form &aux (result T)) (values `(when ,form (setf ,result NIL) (end-for)) result))\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-clause", "input": "(define-simple-clause never (form &aux (result T)) (values `(when ,form (setf ,result NIL) (end-for)) result))", "output": "(defmacro define-simple-clause (name args &body body)\n (multiple-value-bind (args outer-let inner-let result-let) (compute-binding-parts NIL NIL args)\n `(define-direct-clause ,name ,(rest args)\n (let ,outer-let\n (values* `(let* ,(list\n ,@result-let)\n (declare (ignorable ,,@(mapcar #'delist outer-let))))\n (let ,inner-let\n (declare (ignorable ,@(mapcar #'delist inner-let)))\n ,@body))))))", "macroexpand": "(define-direct-clause never (form) (let ((#:result187 (gensym #A((6) base-char . \"RESULT\")))) (values* (sb-int:quasiquote (let* #S(sb-impl::comma :expr (list (list #:result187 (quote t))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:result187 :kind 0))))) (let ((result #:result187)) (declare (ignorable result)) (values (sb-int:quasiquote (when #S(sb-impl::comma :expr form :kind 0) (setf #S(sb-impl::comma :expr result :kind 0) nil) (end-for))) result)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-c-compilation-unit () (parse-with-lexer lexer *c-parser*))\n\nIssue: Macro call that should be transformed by with-c-compilation-unit", "input": "(with-c-compilation-unit () (parse-with-lexer lexer *c-parser*))", "output": "(defmacro with-c-compilation-unit ((&key return-last-statement)\n\t\t\t\t &body body)\n \"Establishes variable bindings for a new compilation.\"\n `(let ((*struct-specs* (copy-hash-table *struct-specs*))\n (*typedef-names* (copy-hash-table *typedef-names*))\n\t (*return-last-statement* ,return-last-statement)\n (*function-pointer-ids* nil))\n ,@body))", "macroexpand": "(let ((*struct-specs* (copy-hash-table *struct-specs*)) (*typedef-names* (copy-hash-table *typedef-names*)) (*return-last-statement* nil) (*function-pointer-ids* nil)) (parse-with-lexer lexer *c-parser*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n($send nil nil)\n\nPattern to recognize: Macro call that should be transformed by $SEND", "input": "($send nil nil)", "output": "(defmacro $SEND ...)", "macroexpand": "(send-message nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-component-testers (a b #'pathname-directory) (and (null a) (null b)) (and (= (length a) (length b)) (every (lambda (a b) (or (and (stringp a) (stringp b) (string= a b)) (and (null a) (null b)) (and (keywordp a) (keywordp b) (eql a b)))) a b)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-component-testers", "input": "(with-component-testers (a b #'pathname-directory) (and (null a) (null b)) (and (= (length a) (length b)) (every (lambda (a b) (or (and (stringp a) (stringp b) (string= a b)) (and (null a) (null b)) (and (keywordp a) (keywordp b) (eql a b)))) a b)))", "output": "(defmacro with-component-testers ((a b key) &body body)\n (let ((k (gensym)))\n `(let* ((,k ,key)\n (,a (funcall ,k ,a))\n (,b (funcall ,k ,b)))\n (labels ((components-are (test)\n (and (funcall test ,a) (funcall test ,b)))\n (components-are-member (values)\n (and (member ,a values :test #'eql)\n (member ,b values :test #'eql)\n (eql ,a ,b)))\n (components-are-string= ()\n (and (stringp ,a) (stringp ,b) (string= ,a ,b)))\n (components-are-every (test)\n (and (consp ,a)\n (consp ,b)\n (every test ,a ,b))))\n (declare (ignorable #'components-are #'components-are-member\n #'components-are-string= #'components-are-every))\n (if (or ,@body)\n (values t ,a ,b)\n nil)))))", "macroexpand": "(let* ((#:g145 (function pathname-directory)) (a (funcall #:g145 a)) (b (funcall #:g145 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (and (null a) (null b)) (and (= (length a) (length b)) (every (lambda (a b) (or (and (stringp a) (stringp b) (string= a b)) (and (null a) (null b)) (and (keywordp a) (keywordp b) (eql a b)))) a b))) (values t a b) nil)))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(c-assert (c-model c) () \"c-awaken sees uninstalled cell\" c)\n\nWhat needs to change: Macro call that should be transformed by c-assert", "input": "(c-assert (c-model c) () \"c-awaken sees uninstalled cell\" c)", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (c-model c) (c-break \"c-awaken sees uninstalled cell\" c)))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.9375} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defsynonym generate :generate)\n\nIssue: Macro call that should be transformed by defsynonym", "input": "(defsynonym generate :generate)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote generate) (quote synonym)) (quote :generate)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(cond->> nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by COND->>", "input": "(cond->> nil :key nil)", "output": "(defmacro COND->> ...)", "macroexpand": "(let* ((#:g136 nil))\n (if :key\n (->> #:g136 nil)\n #:g136))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dflet ((foo () 23)) (is (eql 23 (foo))))\n\nProblem: Macro call that should be transformed by dflet", "input": "(dflet ((foo () 23)) (is (eql 23 (foo))))", "output": "(defmacro dflet ((&rest definitions) &body body)\n \"Like FLET, but dynamically sets the FDEFINITIONS during the duration of\nthe BODY.\"\n `(progf\n ',(mapcar #'car definitions)\n (list\n ,.(mapcar (lambda (definition)\n `(lambda ,(cadr definition)\n ,@(cddr definition)))\n definitions))\n ,@body))", "macroexpand": "(progf (quote (foo)) (list (lambda nil 23)) (is (eql 23 (foo))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(return)\n\nIssue: Macro call that should be transformed by RETURN", "input": "(return)", "output": "(defmacro RETURN ...)", "macroexpand": "(return-from nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some->> nil nil)\n\nIssue: Macro call that should be transformed by SOME->>", "input": "(some->> nil nil)", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:|some121| nil) (#:|some121| (when #:|some121| (#:|some121|))))\n #:|some121|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (fill out pad :end offset) out)\n\nPattern to recognize: Macro call that should be transformed by lret*", "input": "(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (fill out pad :end offset) out)", "output": "(defmacro lret* ((&rest bindings) &body body)\n \"Cf. `lret'.\"\n `(lret-aux let* ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (fill out pad :end offset) out)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :p () 1)\n\nProblem: Macro call that should be transformed by ->", "input": "(-> :p () 1)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :p nil 1)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(match 1 (1 1))\n\nIssue: Macro call that should be transformed by match", "input": "(match 1 (1 1))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(let ((#:var148 1)) (declare (ignorable #:var148)) (%or (%if (%equals #:var148 1) (%or 1 (fail)) (fail)) nil))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defhandler eval-when (eval-when situation &rest body) `(list ',eval-when ',situation ,@(e-list body)))\n\nIssue: Macro call that should be transformed by defhandler", "input": "(defhandler eval-when (eval-when situation &rest body) `(list ',eval-when ',situation ,@(e-list body)))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-eval-when (eval-when situation &rest body) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr eval-when :kind 0)) (quote #S(sb-impl::comma :expr situation :kind 0)) #S(sb-impl::comma :expr (e-list body) :kind 2)))) (setf (gethash (quote eval-when) *form-handler*) (quote hander-eval-when)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-component-testers (a b #'pathname-host) (eq a b) (components-are-member '(nil :unspecific)) (components-are-string=) (components-are-every #'string=))\n\nPattern to recognize: Macro call that should be transformed by with-component-testers", "input": "(with-component-testers (a b #'pathname-host) (eq a b) (components-are-member '(nil :unspecific)) (components-are-string=) (components-are-every #'string=))", "output": "(defmacro with-component-testers ((a b key) &body body)\n (let ((k (gensym)))\n `(let* ((,k ,key)\n (,a (funcall ,k ,a))\n (,b (funcall ,k ,b)))\n (labels ((components-are (test)\n (and (funcall test ,a) (funcall test ,b)))\n (components-are-member (values)\n (and (member ,a values :test #'eql)\n (member ,b values :test #'eql)\n (eql ,a ,b)))\n (components-are-string= ()\n (and (stringp ,a) (stringp ,b) (string= ,a ,b)))\n (components-are-every (test)\n (and (consp ,a)\n (consp ,b)\n (every test ,a ,b))))\n (declare (ignorable #'components-are #'components-are-member\n #'components-are-string= #'components-are-every))\n (if (or ,@body)\n (values t ,a ,b)\n nil)))))", "macroexpand": "(let* ((#:g143 (function pathname-host)) (a (funcall #:g143 a)) (b (funcall #:g143 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (eq a b) (components-are-member (quote (nil :unspecific))) (components-are-string=) (components-are-every (function string=))) (values t a b) nil)))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-class-method nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFINE-CLASS-METHOD", "input": "(define-class-method nil\n (progn))", "output": "(defmacro DEFINE-CLASS-METHOD ...)", "macroexpand": "(progn\n (define-incongruent-method nil\n (progn))\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (add-class-principal-method 'nil '(progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause counting (var) \"Counts the number of iterations, starting from 0.\" (make-simple-iteration :var var :init 0 :step `(1+ ,var)))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause counting (var) \"Counts the number of iterations, starting from 0.\" (make-simple-iteration :var var :init 0 :step `(1+ ,var)))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro counting (var) \"Counts the number of iterations, starting from 0.\" (make-simple-iteration :var var :init 0 :step (sb-int:quasiquote (1+ #S(sb-impl::comma :expr var :kind 0))))) (pushnew (quote counting) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(rem-arg-list-key-value! nil nil)\n\nProblem: Macro call that should be transformed by REM-ARG-LIST-KEY-VALUE!", "input": "(rem-arg-list-key-value! nil nil)", "output": "(defmacro rem-arg-list-key-value! (ids place &key (test '#'equalper) (key '#'identity))\n `(progn\n (iter (for id in (ensure-list ,ids))\n (setf ,place (rem-arg-list-key-value id ,place :test ,test :key ,key)))\n ,place))", "macroexpand": "(progn\n (iter\n (for id in (ensure-list nil))\n (setf nil (rem-arg-list-key-value id nil :test #'equalper :key #'identity)))\n nil)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-filtered-function nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEFINE-FILTERED-FUNCTION", "input": "(define-filtered-function nil\n nil)", "output": "(defmacro DEFINE-FILTERED-FUNCTION ...)", "macroexpand": "(progn\n (defgeneric nil\n nil\n (:generic-function-class filtered-function)\n (:method-class filtered-method)\n (:method-combination filtered))\n (setf (generic-function-filters (fdefinition 'nil)) (list))\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(iterate\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ITERATE", "input": "(iterate\n nil)", "output": "(defmacro ITERATE ...)", "macroexpand": "(iter\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(ltbdd-with-new-hash 'some-name)\n\nPattern to recognize: Macro call that should be transformed by LTBDD-WITH-NEW-HASH", "input": "(ltbdd-with-new-hash 'some-name)", "output": "(defmacro LTBDD-WITH-NEW-HASH ...)", "macroexpand": "(bdd-call-with-new-hash (lambda (quote some-name)) :bdd-node-type\n '(or lisp-type-bdd-node bdd-leaf))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield (do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield", "input": "(with-yield (do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g))))", "output": "(defmacro with-yield (&body body)\n (let ((point (gensym))\n (current (gensym)))\n `(let (,point ,current)\n (with-call/cc\n\t (labels ((yield (&rest values)\n\t\t (setf ,current values)\n\t\t (let/cc k\n\t\t (setf ,point k))))\n\t ,@body\n\t (setf ,point nil)))\n (gen-lambda ()\n\t (cond ((null ,point)\n\t\t'generator-stop)\n\t (t\n\t\t(let ((current ,current))\n\t\t (funcall ,point nil)\n\t\t ;values-handler: see gen-lambda\n\t\t (apply #'values (funcall values-handler current)))))))))", "macroexpand": "(let (#:g147 #:g148) (with-call/cc (labels ((yield (&rest values) (setf #:g148 values) (let/cc k (setf #:g147 k)))) (do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g))) (setf #:g147 nil))) (gen-lambda nil (cond ((null #:g147) (quote generator-stop)) (t (let ((current #:g148)) (funcall #:g147 nil) (apply (function values) (funcall values-handler current)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(matrix-ecase nil)\n\nWhat needs to change: Macro call that should be transformed by MATRIX-ECASE", "input": "(matrix-ecase nil)", "output": "(defmacro MATRIX-ECASE ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do+ (for (x &optional (y 'y) &rest z &key k1 (k2 'k2) ((:kk k3) 'k3)) (in '((1 a) (2) (3 c :k1 a :kk b :k2 c)))) (collect (list x y z k1 k2 k3)))\n\nProblem: Macro call that should be transformed by do+", "input": "(do+ (for (x &optional (y 'y) &rest z &key k1 (k2 'k2) ((:kk k3) 'k3)) (in '((1 a) (2) (3 c :k1 a :kk b :k2 c)))) (collect (list x y z k1 k2 k3)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for (x &optional (y (quote y)) &rest z &key k1 (k2 (quote k2)) ((:kk k3) (quote k3))) (in (quote ((1 a) (2) (3 c :k1 a :kk b :k2 c))))) (collect (list x y z k1 k2 k3)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(rem-bops 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by REM-BOPS", "input": "(rem-bops 'some-name)", "output": "(defmacro REM-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn (save-binfix) (mapc 'rmbop '('some-name)) (assign-properties)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-bug problem-with-the-compiler () (target) \"This shouldnt have been possible so this needs a bug report. Sorry about that~%~s\" target)\n\nWhat needs to change: Macro call that should be transformed by define-bug", "input": "(define-bug problem-with-the-compiler () (target) \"This shouldnt have been possible so this needs a bug report. Sorry about that~%~s\" target)", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition problem-with-the-compiler (:error-type varjo-error :prefix \"Varjo Bug\") (target) \"This shouldnt have been possible so this needs a bug report. Sorry about that~%~s\" target)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(unless nil :key nil)\n\nIssue: Macro call that should be transformed by UNLESS", "input": "(unless nil :key nil)", "output": "(defmacro UNLESS ...)", "macroexpand": "(if nil\n nil\n (progn :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(quasiquote-unexpand-1 'unquote-nsplicing el)\n\nProblem: Macro call that should be transformed by quasiquote", "input": "(quasiquote-unexpand-1 'unquote-nsplicing el)", "output": "(defmacro quasiquote (x) (quasiquote-expand x))", "macroexpand": "(quasiquote-unexpand-1 (quote unquote-nsplicing) el)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7925} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield-binds (format nil \"ON DUPLICATE KEY UPDATE ~{~A = ~A~^, ~}\" (mapcar #'yield-arg (on-duplicate-key-update-clause-args clause))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"ON DUPLICATE KEY UPDATE ~{~A = ~A~^, ~}\" (mapcar #'yield-arg (on-duplicate-key-update-clause-args clause))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"ON DUPLICATE KEY UPDATE ~{~A = ~A~^, ~}\" (mapcar (function yield-arg) (on-duplicate-key-update-clause-args clause)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defclass/std unknown () ((slot :a :unknown keywords :without-values)))\n\nPattern to recognize: Macro call that should be transformed by defclass/std", "input": "(defclass/std unknown () ((slot :a :unknown keywords :without-values)))", "output": "(defmacro defclass/std (name direct-superclasses direct-slots &rest options\n &environment env)\n \"Shortcut macro to the DEFCLASS macro.\n\n (defclass/std example ()\n ((slot1 slot2 slot3)))\n\n expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\n Each slot definition accepts options:\n\n :std 1 => changes the :initform to 1. It can be :unbound.\n :with or :with-prefix => creates accessors with the class name as prefix.\n\n See the README for more.\n\n See also `class/std' and `print-object/std'.\n \"\n `(defclass ,name ,direct-superclasses\n ,(process-slots env direct-slots name)\n ,@options))", "macroexpand": "(defclass unknown nil ((slot :accessor slot :initform nil :unknown keywords :without-values)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(pmap #'1+ #'unsigned)\n\nWrite a macro that addresses: Macro call that should be transformed by pmap", "input": "(pmap #'1+ #'unsigned)", "output": "(defmacro pmap (f parser)\n \"Similar to `fmap', but this transforms a parser into another one, altering\nits inner result if it happened to be successful.\"\n `(lambda (offset)\n (fmap ,f (funcall ,parser offset))))", "macroexpand": "(lambda (offset) (fmap (function 1+) (funcall (function unsigned) offset)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-reader-syntax (get-val array hash-table) (with-output-to-string (*error-output*) (is (char= #\\f (er \"(with-env (setp #\\\\f [str 0]))\"))) (is (eq 'f (er \"(with-env (setp 'f [vec 0]))\"))) (is (= 4 (er \"(with-env (setp 4 [arr 0 2]))\"))) (is (eq 'f (er \"(with-env (setp 'f [list 3]))\"))) (is (eq 'f (er \"(with-env (setp 'f [ht 'a]))\"))) (is (= 2 (er \"(with-env (setp 2 [assoc-list 'a]))\"))) (is (eq 3 (er \"(with-env (setp 3 [assoc-list 'c]))\"))) (is (= 2 (er \"(with-env (setp 2 [plist :c]))\"))) (is (eq 3 (er \"(with-env (setp 3 [plist :e]))\"))) (is (eq 5 (er \"(with-env (setp 5 [clos-object 'a]))\"))) (is (eq 7 (er \"(with-env (setp 7 [struct 'a]))\")))))\n\nIssue: Macro call that should be transformed by with-reader-syntax", "input": "(with-reader-syntax (get-val array hash-table) (with-output-to-string (*error-output*) (is (char= #\\f (er \"(with-env (setp #\\\\f [str 0]))\"))) (is (eq 'f (er \"(with-env (setp 'f [vec 0]))\"))) (is (= 4 (er \"(with-env (setp 4 [arr 0 2]))\"))) (is (eq 'f (er \"(with-env (setp 'f [list 3]))\"))) (is (eq 'f (er \"(with-env (setp 'f [ht 'a]))\"))) (is (= 2 (er \"(with-env (setp 2 [assoc-list 'a]))\"))) (is (eq 3 (er \"(with-env (setp 3 [assoc-list 'c]))\"))) (is (= 2 (er \"(with-env (setp 2 [plist :c]))\"))) (is (eq 3 (er \"(with-env (setp 3 [plist :e]))\"))) (is (eq 5 (er \"(with-env (setp 5 [clos-object 'a]))\"))) (is (eq 7 (er \"(with-env (setp 7 [struct 'a]))\")))))", "output": "(defmacro with-reader-syntax (reader-macro-identifiers &body body)\n \"This macro is only made for use by read-and-eval functionality,\nand rather directed towards tests than users. So, do not export.\"\n (let ((identifiers (loop :for identifier :in reader-macro-identifiers\n :collect `(quote ,identifier))))\n `(let ((*array-function* 'make-t-array-from-initial-contents)\n (*hash-table-function* 'alexandria:plist-hash-table)\n (*get-val-function* 'get-val)\n (*get-val-array-function* 'cl:aref)\n (*set-function* 'cl:remove-duplicates)\n (*alists-are-lists* nil)\n (*plists-are-lists* nil)\n (*readtable* (%enable-reader-syntax *readtable* ,@identifiers)))\n ,@body)))", "macroexpand": "(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote get-val) (quote array) (quote hash-table)))) (with-output-to-string (*error-output*) (is (char= #\\LATIN_SMALL_LETTER_F (er \"(with-env (setp #\\\\f [str 0]))\"))) (is (eq (quote f) (er \"(with-env (setp 'f [vec 0]))\"))) (is (= 4 (er \"(with-env (setp 4 [arr 0 2]))\"))) (is (eq (quote f) (er \"(with-env (setp 'f [list 3]))\"))) (is (eq (quote f) (er \"(with-env (setp 'f [ht 'a]))\"))) (is (= 2 (er \"(with-env (setp 2 [assoc-list 'a]))\"))) (is (eq 3 (er \"(with-env (setp 3 [assoc-list 'c]))\"))) (is (= 2 (er \"(with-env (setp 2 [plist :c]))\"))) (is (eq 3 (er \"(with-env (setp 3 [plist :e]))\"))) (is (eq 5 (er \"(with-env (setp 5 [clos-object 'a]))\"))) (is (eq 7 (er \"(with-env (setp 7 [struct 'a]))\")))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(cond->> 'some-name)\n\nProblem: Macro call that should be transformed by COND->>", "input": "(cond->> 'some-name)", "output": "(defmacro COND->> ...)", "macroexpand": "(let* ((#:g137 'some-name))\n #:g137)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-generic generic ((a a) (b b) &key (c nil)) (+ a b) \"This is not recognized as documentation.\")\n\nProblem: Macro call that should be transformed by define-generic", "input": "(define-generic generic ((a a) (b b) &key (c nil)) (+ a b) \"This is not recognized as documentation.\")", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:method ((a a) (b b) &key (c nil)) (+ a b) \"This is not recognized as documentation.\")))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-standard-definer-options nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by WITH-STANDARD-DEFINER-OPTIONS", "input": "(with-standard-definer-options nil\n nil)", "output": "(defmacro WITH-STANDARD-DEFINER-OPTIONS ...)", "macroexpand": "`(progn\n ,@(when (getf -options- :export)\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',nil))))\n ,nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(defstore example (object &key &allow-other-keys))\n\nPattern to recognize: Macro call that should be transformed by defstore", "input": "(defstore example (object &key &allow-other-keys))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote example) (quote (object &key &allow-other-keys)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is #\\a #\\a)\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is #\\a #\\a)", "output": "(defmacro is (got expected &rest args)\n (with-gensyms (duration result new-args desc)\n (once-only (expected)\n `(let* ((,new-args (list ,@args))\n (,desc (parse-description-and-test ,new-args)))\n (with-catching-errors (:description ,desc :expected ,expected)\n (with-duration ((,duration ,result) ,got)\n (test ,result ,expected ,new-args\n :duration ,duration)))))))", "macroexpand": "(let ((#:expected166 #\\LATIN_SMALL_LETTER_A)) (let* ((#:new-args164 (list)) (#:desc165 (parse-description-and-test #:new-args164))) (with-catching-errors (:description #:desc165 :expected #:expected166) (with-duration ((#:duration162 #:result163) #\\LATIN_SMALL_LETTER_A) (test #:result163 #:expected166 #:new-args164 :duration #:duration162)))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defgenerator dropwhile (predicate generator) \"Goes through generator, dropping the items until the predicate fails, then emits the rest of the source generator's items. Eg: (dropwhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 6 4 1\" (do-generator (item generator) (unless (funcall predicate item) (yield item) (return))) (yield-all generator))\n\nIssue: Macro call that should be transformed by defgenerator", "input": "(defgenerator dropwhile (predicate generator) \"Goes through generator, dropping the items until the predicate fails, then emits the rest of the source generator's items. Eg: (dropwhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 6 4 1\" (do-generator (item generator) (unless (funcall predicate item) (yield item) (return))) (yield-all generator))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun dropwhile (predicate generator) \"Goes through generator, dropping the items until the predicate fails, then emits the rest of the source generator's items. Eg: (dropwhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 6 4 1\" (with-yield (do-generator (item generator) (unless (funcall predicate item) (yield item) (return))) (yield-all generator)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(-> :tag-3 (text) (setf result text) (mt:open-latch latch))\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(-> :tag-3 (text) (setf result text) (mt:open-latch latch))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :tag-3 (text) (setf result text) (cl-muth:open-latch latch))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-launched-iter nil\n (progn))\n\nIssue: Macro call that should be transformed by DEF-LAUNCHED-ITER", "input": "(def-launched-iter nil\n (progn))", "output": "(defmacro DEF-LAUNCHED-ITER ...)", "macroexpand": "(defun nil (progn)\n (let ((it (make-instance 'iterator :coro (lambda-coro))))\n (inext-or-error it)\n it))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (and (>= (length operatorXX) 8) (string-equal \"operator\" operatorXX :start2 0 :end2 8)) (when (not (gethash operatorXX name-map))) (setf (gethash operatorXX name-map) check-name))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (and (>= (length operatorXX) 8) (string-equal \"operator\" operatorXX :start2 0 :end2 8)) (when (not (gethash operatorXX name-map))) (setf (gethash operatorXX name-map) check-name))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (and (>= (length operatorxx) 8) (string-equal \"operator\" operatorxx :start2 0 :end2 8)) (progn (when (not (gethash operatorxx name-map))) (setf (gethash operatorxx name-map) check-name)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-wcs-math-error-handling (ret (log x)) (check-wcs-math-result))\n\nPattern to recognize: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (log x)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g221 x) (#:g222 nil) (#:g223 (list #:g221))) (declare (ignorable #:g222) (type list #:g223) (dynamic-extent #:g223)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote log) #:g223) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g223)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-iter-values ((item it)) (setf result (funcall f (funcall key item) result)))\n\nWhat needs to change: Macro call that should be transformed by do-iter-values", "input": "(do-iter-values ((item it)) (setf result (funcall f (funcall key item) result)))", "output": "(defmacro do-iter-values ((&rest iters) &body forms)\n \"Iterate over the remaining elements of a sequence pointed to by static iterators.\n\n Evaluate FORMS at each iteration, for each remaining element, until\n one of the iterators reaches the end of the sequence.\n\n NOTE: May only be used inside a WITH-ITERATORS form.\n\n ITERS:\n\n List of bindings. Each element is of the form (PATTERN ITER),\n interpreted as if to WITH-ITER-VALUE, where PATTERN is a binding\n pattern, for the binding to the sequence element value, and ITER\n is a static iterator identifier symbol, introduced in a parent\n WITH-ITERATORS form.\n\n FORMS\n\n List of forms evaluated for each remaining element in the\n sequences pointed to by the static iterators.\n\n At each evaluation the next element of each sequence, pointed by\n each ITER in ITERS, is bound to the variable(s) specified by the\n corresponding PATTERN. After which the iterators are advanced to\n the next elements.\n\n If one of the iterators has reached the end of its sequence, a\n non-local jump outside the enclosing WITH-ITERATORS form is\n performed, i.e. any forms following this form, within the enclosing\n WITH-ITERATORS form, will not be evaluated.\"\n\n (with-gensyms (start)\n `(tagbody\n ,start\n (with-iter-values ,iters ,@forms)\n (go ,start))))", "macroexpand": "(tagbody #:start171 (with-iter-values ((item it)) (setf result (funcall f (funcall key item) result))) (go #:start171))", "category": "anaphoric", "technique": "tagbody-go,gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(disable-reader-syntax)\n\nPattern to recognize: Macro call that should be transformed by DISABLE-READER-SYNTAX", "input": "(disable-reader-syntax)", "output": "(defmacro DISABLE-READER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setq *readtable*\n (if *previous-readtables*\n (pop *previous-readtables*)\n (copy-readtable nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(augment *final* final)\n\nPattern to recognize: Macro call that should be transformed by augment", "input": "(augment *final* final)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf *final* (nconc *final* final))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-syntax-error* (lexer-pos lexer) \"Expected left brace after \\\\~A.\" first-char)\n\nIssue: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (lexer-pos lexer) \"Expected left brace after \\\\~A.\" first-char)", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos (lexer-pos lexer) :format-control \"Expected left brace after \\\\~A.\" :format-arguments (list first-char))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(multi-line-mode-p flags)\n\nProblem: Macro call that should be transformed by multi-line-mode-p", "input": "(multi-line-mode-p flags)", "output": "(defmacro multi-line-mode-p (flags)\n \"Accessor macro to extract the second flag out of a three-element flag list.\"\n `(second ,flags))", "macroexpand": "(second flags)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(receive (one two) (values 1 2 3) (list one two))\n\nWhat needs to change: Macro call that should be transformed by receive", "input": "(receive (one two) (values 1 2 3) (list one two))", "output": "(defmacro receive (formals expr &body body)\n \"Stricter version of `multiple-value-bind'.\n\nUse `receive' when you want to enforce that EXPR should return a\ncertain number of values, or a minimum number of values.\n\nIf FORMALS is a proper list, then EXPR must return exactly as many\nvalues -- no more and no less -- as there are variables in FORMALS.\n\nIf FORMALS is an improper list (VARS . REST), then EXPR must return at\nleast as many values as there are VARS, and any further values are\nbound, as a list, to REST.\n\nLastly, if FORMALS is a symbol, bind that symbol to all the values\nreturned by EXPR, as if by `multiple-value-list'.\n\nFrom Scheme (SRFI-8).\"\n ;; It's probably not worth stack-allocating the thunk.\n (cond ((null formals)\n `(multiple-value-call\n (lambda ()\n ,@body)\n ,expr))\n ((atom formals)\n ;; This could also be written:\n #+(or) `(let ((,formals (multiple-value-list ,expr)))\n ,@body)\n ;; But I want it to be possible to declare FORMALS to have\n ;; dynamic extent, and most Lisps support that for &rest\n ;; lists.\n `(multiple-value-call\n (lambda (&rest ,formals)\n ,@body)\n ,expr))\n ((proper-list-p formals)\n (when (intersection formals lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda ,formals\n ,@body)\n ,expr))\n (t (let* ((last (last formals))\n (vars (append (butlast formals)\n (list (car last))))\n (rest (cdr last)))\n (when (intersection (cons rest vars) lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda (,@vars &rest ,rest)\n ,@body)\n ,expr)))))", "macroexpand": "(multiple-value-call (lambda (one two) (list one two)) (values 1 2 3))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-reader-syntax (describe) (is (string= (with-output-to-string (*standard-output*) (describe 'reader:enable-reader-syntax)) (er \"(with-output-to-string (*standard-output*) ?reader:enable-reader-syntax )\"))))\n\nWhat needs to change: Macro call that should be transformed by with-reader-syntax", "input": "(with-reader-syntax (describe) (is (string= (with-output-to-string (*standard-output*) (describe 'reader:enable-reader-syntax)) (er \"(with-output-to-string (*standard-output*) ?reader:enable-reader-syntax )\"))))", "output": "(defmacro with-reader-syntax (reader-macro-identifiers &body body)\n \"This macro is only made for use by read-and-eval functionality,\nand rather directed towards tests than users. So, do not export.\"\n (let ((identifiers (loop :for identifier :in reader-macro-identifiers\n :collect `(quote ,identifier))))\n `(let ((*array-function* 'make-t-array-from-initial-contents)\n (*hash-table-function* 'alexandria:plist-hash-table)\n (*get-val-function* 'get-val)\n (*get-val-array-function* 'cl:aref)\n (*set-function* 'cl:remove-duplicates)\n (*alists-are-lists* nil)\n (*plists-are-lists* nil)\n (*readtable* (%enable-reader-syntax *readtable* ,@identifiers)))\n ,@body)))", "macroexpand": "(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote describe)))) (is (string= (with-output-to-string (*standard-output*) (describe (quote enable-reader-syntax))) (er \"(with-output-to-string (*standard-output*) ?reader:enable-reader-syntax )\"))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"42\" syntax-error-or-access-violation)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"42\" syntax-error-or-access-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition syntax-error-or-access-violation (database-error) nil) (setf (gethash \"42\" *error-table*) (quote syntax-error-or-access-violation)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(iter)\n\nWhat needs to change: Macro call that should be transformed by ITER", "input": "(iter)", "output": "(defmacro ITER ...)", "macroexpand": "(let* ()\n (block nil\n (block nil\n (tagbody (progn) loop-top-nil (progn) (progn) (go loop-top-nil) (progn))\n nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-neo4j-fun delete-node (node-id) :delete (:uri-spec (format nil \"node/~A\" node-id)) (:status-handlers (204 (values t body)) (404 (error 'node-not-found-error :uri uri)) (409 (error 'unable-to-delete-node-error :uri uri))))\n\nWhat needs to change: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun delete-node (node-id) :delete (:uri-spec (format nil \"node/~A\" node-id)) (:status-handlers (204 (values t body)) (404 (error 'node-not-found-error :uri uri)) (409 (error 'unable-to-delete-node-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun delete-node (&key node-id) (let ((uri (format nil \"node/~A\" node-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :delete uri json (list (list 204 (lambda (body uri json) (values t body))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))) (list 409 (lambda (body uri json) (error (quote unable-to-delete-node-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-instance* 'class (a b c) :x x)\n\nIssue: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class (a b c) :x x)", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(make-instance (quote class) :a a :b b :c c :x x)", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-modf-function subseq 1 (new-val seq start &optional (end (length seq))) (concatenate (type-of seq) (subseq seq 0 start) (subseq new-val 0 (min (length new-val) (- end start))) (subseq seq (+ start (min (length new-val) (- end start))))))\n\nProblem: Macro call that should be transformed by define-modf-function", "input": "(define-modf-function subseq 1 (new-val seq start &optional (end (length seq))) (concatenate (type-of seq) (subseq seq 0 start) (subseq new-val 0 (min (length new-val) (- end start))) (subseq seq (+ start (min (length new-val) (- end start))))))", "output": "(defmacro define-modf-function (name nth-arg (new-val &rest args) &body body)\n \"Define a new modf function. It inverts NAME forms by modifying the NTH-ARG\nterm of the arguments of the place form in the MODF macro.\"\n ;; Side effect in a macro, I know. How can you do this via EVAL-WHEN if I\n ;; want it to run even if not a toplevel macro?\n (setf (gethash name *modf-nth-arg*)\n nth-arg)\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-nth-arg*)\n ,nth-arg))\n (defun ,(intern (modf-name name) :modf) (,new-val ,@args)\n ,@body)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote subseq) *modf-nth-arg*) 1)) (defun |BUILDER:COMMON-LISP:SUBSEQ| (new-val seq start &optional (end (length seq))) (concatenate (type-of seq) (subseq seq 0 start) (subseq new-val 0 (min (length new-val) (- end start))) (subseq seq (+ start (min (length new-val) (- end start)))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-path-instruction-pair vertical-to \"V\" (y))\n\nWrite a macro that addresses: Macro call that should be transformed by define-path-instruction-pair", "input": "(define-path-instruction-pair vertical-to \"V\" (y))", "output": "(defmacro define-path-instruction-pair (name instruction (&rest args))\n (let ((draw-relative (intern (concatenate 'string (string name) \"-R\"))))\n `(progn\n (defun ,name (,@args)\n (format-instruction ,instruction ,@args))\n (defun ,draw-relative (,@args)\n (format-instruction ,(string-downcase instruction) ,@args)))))", "macroexpand": "(progn (defun vertical-to (y) (format-instruction \"V\" y)) (defun vertical-to-r (y) (format-instruction \"v\" y)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (<= a b))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (<= a b))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e134 a) (#:a135 b)) (if (progn (<= #:e134 #:a135)) (add-result (quote test-passed) :test-expr (quote (<= a b))) (process-failure (quote (<= a b)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote b) #:a135 (quote <=) #:e134)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define _IOFBF 1)\n\nWrite a macro that addresses: Macro call that should be transformed by define", "input": "(define _IOFBF 1)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote _iofbf) *preprocessor-defines*) #A((1) base-char . \"1\"))) (defparameter _iofbf 1))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(binding-forms (get 'bind :binding-forms))\n\nWrite a macro that addresses: Macro call that should be transformed by bind", "input": "(binding-forms (get 'bind :binding-forms))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(binding-forms (get (quote bind) :binding-forms))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(aif it it)\n\nWhat needs to change: Macro call that should be transformed by aif", "input": "(aif it it)", "output": "(defmacro aif (test then &optional else)\n \"Like IF, except binds the result of the test to IT (via LET) for\nthe scope of the then and else expressions.\" \n `(anaphoric if ,test ,then ,else))", "macroexpand": "(anaphoric if it it nil)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dletf* nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DLETF*", "input": "(dletf* nil\n (progn))", "output": "(defmacro DLETF* ...)", "macroexpand": "(progn (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> +skip-all-space+ +skip-comments+)\n\nIssue: Macro call that should be transformed by *>", "input": "(*> +skip-all-space+ +skip-comments+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset251) (multiple-value-bind (#:*>-res252 #:*>-next253) (funcall +skip-all-space+ #:*>-offset251) (if (ok? #:*>-res252) (funcall +skip-comments+ #:*>-next253) (fail #:*>-next253))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(\u03c8 nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by \u03a8", "input": "(\u03c8 nil :key nil)", "output": "(defmacro \u03a8 ...)", "macroexpand": "(mapcar (\u03bb :key nil) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun nil (progn))\n\nIssue: Macro call that should be transformed by DEFUN", "input": "(defun nil (progn))", "output": "(defmacro DEFUN ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel) (sb-c:%compiler-defun 'nil t nil nil))\n (sb-impl::%defun 'nil\n (sb-int:named-lambda nil\n (progn)\n (block nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lret ((out (make-array shape :element-type element-type))) (replace* (%flatten out) (%flatten array)))\n\nWhat needs to change: Macro call that should be transformed by lret", "input": "(lret ((out (make-array shape :element-type element-type))) (replace* (%flatten out) (%flatten array)))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let ((out (make-array shape :element-type element-type))) (replace* (%flatten out) (%flatten array)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclass/a dbd-null (cl-dbi:dbi-driver) ())\n\nProblem: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbd-null (cl-dbi:dbi-driver) ())", "output": "(defmacro defclass/a (name superclasses slots &rest class-options)\n `(progn\n (defclass ,name ,superclasses ,slots ,@class-options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (defclass dbd-null (dbi.driver:dbi-driver) nil) (deftype nil (quote dbd-null)) (setf (find-class (quote )) (find-class (quote dbd-null))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(letrec* (x) x)\n\nPattern to recognize: Macro call that should be transformed by letrec", "input": "(letrec* (x) x)", "output": "(defmacro letrec ((&rest bindings) &body body)\n \"Recursive LET.\nThe idea is that functions created in BINDINGS can close over one\nanother, and themselves.\n\nNote that `letrec' only binds variables: it can define recursive\nfunctions, but can't bind them as functions. (But see `fbindrec'.)\"\n `(letrec-with psetq ,bindings\n ,@body))", "macroexpand": "(letrec-with setq (x) x)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(min-of nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by MIN-OF", "input": "(min-of nil\n nil)", "output": "(defmacro MIN-OF ...)", "macroexpand": "(lc (nil nil) minimize)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-find-c-readtable-name-methods c-reader-level-0 0)\n\nWrite a macro that addresses: Macro call that should be transformed by define-find-c-readtable-name-methods", "input": "(define-find-c-readtable-name-methods c-reader-level-0 0)", "output": "(defmacro define-find-c-readtable-name-methods (base-readtable-name level)\n (check-type base-readtable-name symbol)\n (check-type level integer)\n (loop with case-modes = '(nil :upcase :downcase :preserve :invert)\n for mode in case-modes\n as name = (format-symbol :with-c-syntax.core \"~A~@[-~A~]\"\n base-readtable-name mode)\n collect `(defmethod find-c-readtable-name\n ((level (eql ,level)) (readtable-case (eql ,mode)))\n ',name)\n into bodies\n finally\n (return `(progn ,@bodies))))", "macroexpand": "(progn (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql nil))) (quote c-reader-level-0)) (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql :upcase))) (quote c-reader-level-0-upcase)) (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql :downcase))) (quote c-reader-level-0-downcase)) (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql :preserve))) (quote c-reader-level-0-preserve)) (defmethod find-c-readtable-name ((level (eql 0)) (readtable-case (eql :invert))) (quote c-reader-level-0-invert)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-unary-op vacietis.c:~ lognot)\n\nWhat needs to change: Macro call that should be transformed by def-unary-op", "input": "(def-unary-op vacietis.c:~ lognot)", "output": "(defmacro def-unary-op (c lisp)\n (let ((x (gensym)))\n `(defmacro ,c (,x)\n `(,',lisp ,,x))))", "macroexpand": "(defmacro vacietis.c:~ (#:g225) (sb-int:quasiquote (#S(sb-impl::comma :expr (quote lognot) :kind 0) #S(sb-impl::comma :expr #:g225 :kind 0))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(product-of nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by PRODUCT-OF", "input": "(product-of nil\n :key\n nil)", "output": "(defmacro PRODUCT-OF ...)", "macroexpand": "(lc (nil :key nil) multiply)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(assoc-cdr \"oauth_token\" parameters #'equal)\n\nIssue: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr \"oauth_token\" parameters #'equal)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc \"oauth_token\" parameters :test (function equal)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun/1 modf (x ptr) (multiple-value-bind (whole part) (fround x) (setf (deref* ptr) whole) part))\n\nIssue: Macro call that should be transformed by defun/1", "input": "(defun/1 modf (x ptr) (multiple-value-bind (whole part) (fround x) (setf (deref* ptr) whole) part))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun modf (x ptr) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (multiple-value-bind (whole part) (fround x) (setf (deref* ptr) whole) part)) (defparameter modf (vacietis.c:mkptr& (symbol-function (quote modf)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defmessage nil (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFMESSAGE", "input": "(defmessage nil (progn))", "output": "(defmacro DEFMESSAGE ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel) (proclaim `(ftype function ,'nil)))\n (aprog1 (ensure-message 'nil :lambda-list '(progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun/1 va_copy (dest src) (setf (deref* dest) (deref* src)))\n\nIssue: Macro call that should be transformed by defun/1", "input": "(defun/1 va_copy (dest src) (setf (deref* dest) (deref* src)))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun va_copy (dest src) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (setf (deref* dest) (deref* src))) (defparameter va_copy (vacietis.c:mkptr& (symbol-function (quote va_copy)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-left-arrow-accessors nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-LEFT-ARROW-ACCESSORS", "input": "(define-left-arrow-accessors nil)", "output": "(defmacro DEFINE-LEFT-ARROW-ACCESSORS ...)", "macroexpand": "(progn (declaim (inline)) 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (first in-decl) (setf (first in-decl-item) t))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (first in-decl) (setf (first in-decl-item) t))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (first in-decl) (setf (first in-decl-item) t))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda-ignoring-_ (dspecs _t) (finalize-decl-specs dspecs) `(,dspecs nil))\n\nWhat needs to change: Macro call that should be transformed by lambda-ignoring-_", "input": "(lambda-ignoring-_ (dspecs _t) (finalize-decl-specs dspecs) `(,dspecs nil))", "output": "(defmacro lambda-ignoring-_ (lambda-list &body body)\n \"Works like `cl:lambda' macro except automatically `declare's\n `ignore' for parameters beginning with '_' character.\"\n (let ((ignored-parameters\n (collect-_-symbol-in-lambda-list lambda-list)))\n (unless ignored-parameters\n (warn \"No ignored parameters in: ~A\" lambda-list))\n (multiple-value-bind (body decls doc)\n (parse-body body :documentation t)\n `(lambda ,lambda-list\n ,@ (if doc `(,doc))\n (declare (ignore ,@ignored-parameters))\n ,@decls\n ,@body))))", "macroexpand": "(lambda (dspecs _t) (declare (ignore _t)) (finalize-decl-specs dspecs) (sb-int:quasiquote (#S(sb-impl::comma :expr dspecs :kind 0) nil)))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-generic generic ((a a) (b b) &key (c nil)) (+ a b) (:method ((a x) (b z) &key c) c))\n\nWrite a macro that addresses: Macro call that should be transformed by define-generic", "input": "(define-generic generic ((a a) (b b) &key (c nil)) (+ a b) (:method ((a x) (b z) &key c) c))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:method ((a a) (b b) &key (c nil)) (+ a b)) (:method ((a x) (b z) &key c) c)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is-values (values 1 2 nil 3) '(1 2 nil 3))\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is-values (values 1 2 nil 3) '(1 2 nil 3))", "output": "(defmacro is (got expected &rest args)\n (with-gensyms (duration result new-args desc)\n (once-only (expected)\n `(let* ((,new-args (list ,@args))\n (,desc (parse-description-and-test ,new-args)))\n (with-catching-errors (:description ,desc :expected ,expected)\n (with-duration ((,duration ,result) ,got)\n (test ,result ,expected ,new-args\n :duration ,duration)))))))", "macroexpand": "(is (multiple-value-list (values 1 2 nil 3)) (quote (1 2 nil 3)))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-foreign-pointer-as-string (s 100) (sprintf s \"%.0f\" :double (* pi 100d0)))\n\nIssue: Macro call that should be transformed by with-foreign-pointer", "input": "(with-foreign-pointer-as-string (s 100) (sprintf s \"%.0f\" :double (* pi 100d0)))", "output": "(defmacro with-foreign-pointer ((var size &optional size-var) &body body)\n \"Bind 'var to 'size bytes of foreign memory during 'body. The\n pointer in 'var is invalid beyond the dynamic extent of 'body, and\n may be stack-allocated if supported by the implementation. If\n 'size-var is supplied, it will be bound to 'size during 'body.\"\n (unless size-var\n (setf size-var (gensym (symbol-name '#:size))))\n ;; If the size is constant we can stack-allocate.\n (cond ((constantp size)\n (let ((alien-var (gensym (symbol-name '#:alien))))\n `(with-alien ((,alien-var (array (unsigned 8) ,(eval size))))\n (let ((,size-var ,size)\n (,var (alien-sap ,alien-var)))\n (declare (ignorable ,size-var))\n ,@body))))\n (t\n `(let ((,size-var ,size))\n (alien:with-bytes (,var ,size-var)\n ,@body)))))", "macroexpand": "(with-foreign-pointer-as-string (s 100) (sprintf s \"%.0f\" :double (* pi 100.0d0)))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ignore-errors)\n\nProblem: Macro call that should be transformed by IGNORE-ERRORS", "input": "(ignore-errors)", "output": "(defmacro IGNORE-ERRORS ...)", "macroexpand": "(handler-case (progn) (error (condition) (values nil condition)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defcategory :notice (or :notice :warning))\n\nProblem: Macro call that should be transformed by defcategory", "input": "(defcategory :notice (or :notice :warning))", "output": "(defmacro defcategory (category &optional expands-as set)\n `(defcategory-fn ',category ',expands-as ,set))", "macroexpand": "(defcategory-fn (quote :notice) (quote (or :notice :warning)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7925} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-templated-dispatch nil\n nil)\n\nProblem: Macro call that should be transformed by DEFINE-TEMPLATED-DISPATCH", "input": "(define-templated-dispatch nil\n nil)", "output": "(defmacro DEFINE-TEMPLATED-DISPATCH ...)", "macroexpand": "(define-type-dispatch nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-additional-indent (reporter stream \"~& \") (with-color (:white :stream stream) (format/indent reporter stream (slot-value report 'description))) (terpri stream))\n\nProblem: Macro call that should be transformed by with-additional-indent", "input": "(with-additional-indent (reporter stream \"~& \") (with-color (:white :stream stream) (format/indent reporter stream (slot-value report 'description))) (terpri stream))", "output": "(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)\n (declare (ignorable reporter stream control-string))\n (let* ((need-new-line (ppcre:scan \"^~&\" control-string))\n (string (apply #'format nil control-string format-arguments))\n (increment (length string)))\n `(with-slots (indent-space) reporter\n (let* ((first-line-indent (indent indent-space))\n (*additional-indent* ,(if need-new-line\n increment\n `(+ *additional-indent*\n ,increment))))\n (declare (ignorable first-line-indent))\n ,(if need-new-line\n `(progn (fresh-line stream)\n (write-string first-line-indent ,stream)\n ;; because we just started a new line, we\n ;; should use format/indent to write string\n ;; taking into account a main indentation level\n (format/indent ,reporter ,stream ,string))\n ;; otherwise, just output our prefix\n `(write-string ,string ,stream))\n \n \n ,@body))))", "macroexpand": "(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* 1)) (declare (ignorable first-line-indent)) (progn (fresh-line stream) (write-string first-line-indent stream) (format/indent reporter stream #A((1) base-char . \" \"))) (with-color (:white :stream stream) (format/indent reporter stream (slot-value report (quote description)))) (terpri stream)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n($ \"$min\" ($ \"value-1\" 600))\n\nProblem: Macro call that should be transformed by $", "input": "($ \"$min\" ($ \"value-1\" 600))", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(kv \"$min\" ($ \"value-1\" 600))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclause while (condition) \"Same as (until (not )).\" (make-termination :condition `(not ,condition)))\n\nIssue: Macro call that should be transformed by defclause", "input": "(defclause while (condition) \"Same as (until (not )).\" (make-termination :condition `(not ,condition)))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro while (condition) \"Same as (until (not )).\" (make-termination :condition (sb-int:quasiquote (not #S(sb-impl::comma :expr condition :kind 0))))) (pushnew (quote while) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder :backtrace (lambda (env) (declare (ignore env)) (error 'test-error)))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder :backtrace (lambda (env) (declare (ignore env)) (error 'test-error)))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (find-middleware :backtrace))) :initial-value (to-app (lambda (env) (declare (ignore env)) (error (quote test-error)))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when-let* ((x t) (y (consp x)) (z (error \"OOPS\"))) t)\n\nProblem: Macro call that should be transformed by when-let*", "input": "(when-let* ((x t) (y (consp x)) (z (error \"OOPS\"))) t)", "output": "(defmacro when-let* (bindings &body body)\n \"Creates new variable bindings, and conditionally executes BODY.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nEach INITIAL-FORM is executed in turn, and the variable bound to the\ncorresponding value. INITIAL-FORM expressions can refer to variables\npreviously bound by the WHEN-LET*.\n\nExecution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.\nIf all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit\nPROGN.\"\n (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings)))\n (labels ((bind (bindings body)\n (if bindings\n `(let (,(car bindings))\n (when ,(caar bindings)\n ,(bind (cdr bindings) body)))\n `(progn ,@body))))\n (bind binding-list body))))", "macroexpand": "(let ((x t)) (when x (let ((y (consp x))) (when y (let ((z (error \"OOPS\"))) (when z (progn t)))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(match nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by MATCH", "input": "(match nil (progn))", "output": "(defmacro MATCH ...)", "macroexpand": "(block #:match127\n (let (progn)\n (when (and (setft progn nil)) (return-from #:match127 nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n($ ($ \"$min\" ($ \"value-1\" 600)) ($ \"$max\" ($ \"value-1\" 610)) ($ \"query\" ($ nil nil)))\n\nIssue: Macro call that should be transformed by $", "input": "($ ($ \"$min\" ($ \"value-1\" 600)) ($ \"$max\" ($ \"value-1\" 610)) ($ \"query\" ($ nil nil)))", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(kv ($ \"$min\" ($ \"value-1\" 600)) ($ \"$max\" ($ \"value-1\" 610)) ($ \"query\" ($ nil nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-properties nil\n (progn))\n\nIssue: Macro call that should be transformed by WITH-PROPERTIES", "input": "(with-properties nil\n (progn))", "output": "(defmacro WITH-PROPERTIES ...)", "macroexpand": "(let ((#:g134 (progn)))\n (symbol-macrolet ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ps-to-stream 'some-name)\n\nProblem: Macro call that should be transformed by PS-TO-STREAM", "input": "(ps-to-stream 'some-name)", "output": "(defmacro PS-TO-STREAM ...)", "macroexpand": "(let ((*parenscript-stream* 'some-name))\n (write-string \"\" *parenscript-stream*))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when-let* (x y) (1+ x))\n\nWrite a macro that addresses: Macro call that should be transformed by when-let*", "input": "(when-let* (x y) (1+ x))", "output": "(defmacro when-let* (bindings &body body)\n \"Creates new variable bindings, and conditionally executes BODY.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nEach INITIAL-FORM is executed in turn, and the variable bound to the\ncorresponding value. INITIAL-FORM expressions can refer to variables\npreviously bound by the WHEN-LET*.\n\nExecution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.\nIf all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit\nPROGN.\"\n (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings)))\n (labels ((bind (bindings body)\n (if bindings\n `(let (,(car bindings))\n (when ,(caar bindings)\n ,(bind (cdr bindings) body)))\n `(progn ,@body))))\n (bind binding-list body))))", "macroexpand": "(let ((x y)) (when x (progn (1+ x))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-class nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by DEFINE-CLASS", "input": "(define-class nil\n :key\n nil)", "output": "(defmacro DEFINE-CLASS ...)", "macroexpand": "(progn (defclass nil :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-generic generic (a b &key c) (declare (ignorable a b c)) (+ a b c))\n\nIssue: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c) (declare (ignorable a b c)) (+ a b c))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:method (a b &key c) (declare (ignorable a b c)) (+ a b c))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(f0\n nil\n nil)\n\nProblem: Macro call that should be transformed by F0", "input": "(f0\n nil\n nil)", "output": "(defmacro F0 ...)", "macroexpand": "(lambda () nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-op (:> infix-op))\n\nWhat needs to change: Macro call that should be transformed by define-op", "input": "(define-op (:> infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (>-op (:include infix-op (name \">\")) (:constructor make->-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(unless nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by UNLESS", "input": "(unless nil (progn))", "output": "(defmacro UNLESS ...)", "macroexpand": "(if nil\n nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(mapping)\n\nPattern to recognize: Macro call that should be transformed by MAPPING", "input": "(mapping)", "output": "(defmacro MAPPING ...)", "macroexpand": "(mapping-mac)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(list-of nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by LIST-OF", "input": "(list-of nil\n (progn))", "output": "(defmacro LIST-OF ...)", "macroexpand": "(lc (nil (progn)) collect)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-shared-method nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-SHARED-METHOD", "input": "(define-shared-method nil\n nil)", "output": "(defmacro DEFINE-SHARED-METHOD ...)", "macroexpand": "(define-incongruent-method incongruent-methods.methods::nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-definition-resolver global (designator) (eq :global (sb-cltl2:variable-information designator)))\n\nIssue: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver global (designator) (eq :global (sb-cltl2:variable-information designator)))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver global (global #:package147) (when (ignore-errors (let ((designator global)) (eq :global (sb-cltl2:variable-information designator)))) (list (make-instance (quote global) :designator global :package #:package147))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(match ARG (PATTERN THEN) (otherwise ELSE))\n\nWrite a macro that addresses: Macro call that should be transformed by match", "input": "(match ARG (PATTERN THEN) (otherwise ELSE))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(%or (%or (let ((pattern arg)) then) else (fail)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(macroexpand-convention (form) (if (consp form) (expand-export-slots-using-head (first form) form) form))\n\nProblem: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (if (consp form) (expand-export-slots-using-head (first form) form) form))", "output": "(defmacro macroexpand-convention ((original-form) &body body)\n \"Executes BODY as like `progn' and return the result as the first\nvalue. As the second value, returns a boolean whether the result is\nnot same with ORIGINAL-FORM or not.\nThis macro is designed to follow the `macroexpand' convention.\"\n `(multiple-value-bind (result expanded-p)\n (progn ,@body)\n (values result\n (or expanded-p\n (not (eq result ,original-form))))))", "macroexpand": "(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-slots-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-column-type string (&optional length) (if length `(:varchar ,length) :text))\n\nPattern to recognize: Macro call that should be transformed by define-column-type", "input": "(define-column-type string (&optional length) (if length `(:varchar ,length) :text))", "output": "(defmacro define-column-type (type-symbol lambda-list &body body)\n (let ((type (gensym \"TYPE\"))\n (args (gensym \"ARGS\")))\n `(defmethod cltype-to-dbtype ((,type (eql ',type-symbol)) &rest ,args)\n (declare (ignore ,type))\n (destructuring-bind ,lambda-list ,args\n ,@body))))", "macroexpand": "(defmethod cltype-to-dbtype ((#:type222 (eql (quote string))) &rest #:args223) (declare (ignore #:type222)) (destructuring-bind (&optional length) #:args223 (if length (sb-int:quasiquote (:varchar #S(sb-impl::comma :expr length :kind 0))) :text)))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-documentation-lookup special-operator cl:function)\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup special-operator cl:function)", "output": "(defmacro define-simple-documentation-lookup (class documentation-type)\n `(defmethod documentation ((,class ,class))\n ,(if (eql documentation-type T)\n `(cl:documentation (object ,class) 'T)\n `(cl:documentation (designator ,class) ',documentation-type))))", "macroexpand": "(defmethod documentation ((special-operator special-operator)) (common-lisp:documentation (designator special-operator) (quote common-lisp:function)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (typep (car evaluated) 'node) (setf asts (append asts evaluated)))\n\nProblem: Macro call that should be transformed by when", "input": "(when (typep (car evaluated) 'node) (setf asts (append asts evaluated)))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (typep (car evaluated) (quote node)) (setf asts (append asts evaluated)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ensure-getf options :type type)\n\nWhat needs to change: Macro call that should be transformed by ensure-getf", "input": "(ensure-getf options :type type)", "output": "(defmacro ensure-getf (place key &optional default)\n (once-only (key default)\n `(setf (getf ,place ,key) (getf ,place ,key ,default))))", "macroexpand": "(let ((#:key169 :type) (#:default170 type)) (setf (getf options #:key169) (getf options #:key169 #:default170)))", "category": "control-flow", "technique": "once-only", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-type-map type cl:type)\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-type-map", "input": "(define-simple-type-map type cl:type)", "output": "(defmacro define-simple-type-map (class type)\n `(defmethod type ((,class ,class))\n ',type))", "macroexpand": "(defmethod type ((type type)) (quote common-lisp:type))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n;; Sorting multiple places requires manual compare-and-swap\n(when (> b a) (rotatef a b))\n(when (> c a) (rotatef a c))\n(when (> c b) (rotatef b c))\n;; This is a sorting network but manually written - error-prone\n;; For more than 3 elements, the network is complex\n\nWrite a macro that addresses: Sorting multiple values in-place requires compare-and-swap networks \u2014 want automatic sorting network generation", "input": ";; Sorting multiple places requires manual compare-and-swap\n(when (> b a) (rotatef a b))\n(when (> c a) (rotatef a c))\n(when (> c b) (rotatef b c))\n;; This is a sorting network but manually written - error-prone\n;; For more than 3 elements, the network is complex", "output": "(defun build-batcher-sn (n)\n (let* (network\n (tee (ceiling (log n 2)))\n (p (ash 1 (- tee 1))))\n (loop while (> p 0) do\n (let ((q (ash 1 (- tee 1)))\n (r 0)\n (d p))\n (loop while (> d 0) do\n (loop for i from 0 to (- n d 1) do\n (if (= (logand i p) r)\n (push (list i (+ i d))\n network)))\n (setf d (- q p)\n q (ash q -1)\n r p)))\n (setf p (ash p -1)))\n (nreverse network)))\n\n(defmacro! sortf (comparator &rest places)\n (if places\n `(tagbody\n ,@(mapcar\n #`(let ((,g!a #1=,(nth (car a1) places))\n (,g!b #2=,(nth (cadr a1) places)))\n (if (,comparator ,g!b ,g!a)\n (setf #1# ,g!b\n #2# ,g!a)))\n (build-batcher-sn (length places))))))", "macroexpand": ";; (sortf string< a b c d e)\n;; Generates a Batcher sorting network of compare-and-swap operations\n;; Each pair is: (let ((#:ga (nth 0 places)) (#:gb (nth 3 places)))\n;; (if (string< #:gb #:ga) (setf #1# #:gb #2# #:ga)))\n;; All within a tagbody for compiler optimization", "category": "efficiency", "technique": "gensym,tagbody-go", "complexity": "advanced", "quality_score": 0.9624999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(the nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by THE", "input": "(the nil (progn))", "output": "(defmacro THE ...)", "macroexpand": "(send self nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(bind (((:struct metabang-bind-test-1- a c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list a c))\n\nProblem: Macro call that should be transformed by bind", "input": "(bind (((:struct metabang-bind-test-1- a c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list a c))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-188| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (a (metabang-bind-test-1-a #:|values-188|)) (c (metabang-bind-test-1-c #:|values-188|))) (declare (ignorable #:|values-188|)) (progn (list a c)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(enable-quasiquote-2.0)\n\nWhat needs to change: Macro call that should be transformed by ENABLE-QUASIQUOTE-2.0", "input": "(enable-quasiquote-2.0)", "output": "(defmacro ENABLE-QUASIQUOTE-2.0 ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (%enable-quasiquote-2.0))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(*> +array-open+ +skip-space-and-comments+)\n\nPattern to recognize: Macro call that should be transformed by *>", "input": "(*> +array-open+ +skip-space-and-comments+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset236) (multiple-value-bind (#:*>-res237 #:*>-next238) (funcall +array-open+ #:*>-offset236) (if (ok? #:*>-res237) (funcall +skip-space-and-comments+ #:*>-next238) (fail #:*>-next238))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(special-symbol-progv nil\n nil)\n\nIssue: Macro call that should be transformed by SPECIAL-SYMBOL-PROGV", "input": "(special-symbol-progv nil\n nil)", "output": "(defmacro SPECIAL-SYMBOL-PROGV ...)", "macroexpand": "(let (#:symbol-list176)\n (tagbody\n #:retry177\n (setq #:symbol-list176 nil)\n (unless (every #'special-symbol-p #:symbol-list176)\n (cerror \"Retry to rebind the place(s).\"\n \"Attempt at rebinding one or more non-special places: ~S\" 'nil)\n (go #:retry177)))\n (dynamic-progv #:symbol-list176\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield\n 'some-name)\n\nWhat needs to change: Macro call that should be transformed by WITH-YIELD", "input": "(with-yield\n 'some-name)", "output": "(defmacro WITH-YIELD ...)", "macroexpand": "(isolate-cont\n (enable-yield\n nil\n 'some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(labels* nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by LABELS*", "input": "(labels* nil\n (progn))", "output": "(defmacro LABELS* ...)", "macroexpand": "(labels ()\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when (typep (node-slot name) 'identifier) (format stream \"~~\"))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when (typep (node-slot name) 'identifier) (format stream \"~~\"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (typep (node-slot name) (quote identifier)) (format stream \"~~\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(var nil (progn))\n\nWhat needs to change: Macro call that should be transformed by VAR", "input": "(var nil (progn))", "output": "(defmacro VAR ...)", "macroexpand": "(defparameter nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defparam nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFPARAM", "input": "(defparam nil nil)", "output": "(defmacro DEFPARAM ...)", "macroexpand": "(setf (gethash #A((3) base-char . \"NIL\") cl-rules.core::*parameters*) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(rte-case 'some-name)\n\nPattern to recognize: Macro call that should be transformed by RTE-CASE", "input": "(rte-case 'some-name)", "output": "(defmacro RTE-CASE ...)", "macroexpand": "(let ((#:rte170 'some-name))\n (typecase #:rte170\n ((not sequence) nil)\n (t\n (funcall\n (lambda (#:rte170)\n (declare (optimize (speed 3) (debug 0) (safety 0)))\n (block check\n (typecase #:rte170\n (list nil)\n (simple-vector\n (let ((i 0) (len (length #:rte170)))\n (declare (type (and unsigned-byte fixnum) i len)\n (ignorable len))\n nil))\n (vector\n (let ((i 0) (len (length #:rte170)))\n (declare (type (and fixnum unsigned-byte) i len)\n (ignorable len))\n nil))\n (sequence\n (let ((i 0) (len (sb-sequence:length #:rte170)))\n (declare (type (and fixnum unsigned-byte) i len)\n (ignorable len))\n nil))\n (t nil))))\n #:rte170))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:p (:button \"Log in\") (:a :href \"#\" \"Forgot?\")))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:p (:button \"Log in\") (:a :href \"#\" \"Forgot?\")))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:p (:button \"Log in\") (:a :href \"#\" \"Forgot?\"))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))\n\nWrite a macro that addresses: Macro call that should be transformed by path", "input": "(path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))", "output": "(defmacro path (&body cmds)\n (let ((path (gensym \"path\")))\n `(let ((,path (make-path)))\n (with-path ,path\n ,@cmds)\n ,path)))", "macroexpand": "(let ((#:|path141| (make-path))) (with-path #:|path141| (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50)) #:|path141|)", "category": "control-flow", "technique": "gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n($ 'some-name)\n\nProblem: Macro call that should be transformed by $", "input": "($ 'some-name)", "output": "(defmacro $ ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(aand (+ 1 1) (+ 1 it))\n\nProblem: Macro call that should be transformed by aand", "input": "(aand (+ 1 1) (+ 1 it))", "output": "(defmacro aand (first &rest rest)\n \"Like AND, except binds the first argument to IT (via LET) for the\nscope of the rest of the arguments.\"\n `(anaphoric and ,first ,@rest))", "macroexpand": "(anaphoric and (+ 1 1) (+ 1 it))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defiter nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by DEFITER", "input": "(defiter nil\n :key\n nil)", "output": "(defmacro DEFITER ...)", "macroexpand": "(defun nil :key\n (make-instance 'iterator :coro\n (lambda-coro\n nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(when-let* ((x 2) (y x)) (+ x y))\n\nPattern to recognize: Macro call that should be transformed by when-let*", "input": "(when-let* ((x 2) (y x)) (+ x y))", "output": "(defmacro when-let* (bindings &body body)\n \"Creates new variable bindings, and conditionally executes BODY.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nEach INITIAL-FORM is executed in turn, and the variable bound to the\ncorresponding value. INITIAL-FORM expressions can refer to variables\npreviously bound by the WHEN-LET*.\n\nExecution of WHEN-LET* stops immediately if any INITIAL-FORM evaluates to NIL.\nIf all INITIAL-FORMs evaluate to true, then BODY is executed as an implicit\nPROGN.\"\n (let ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings)))\n (labels ((bind (bindings body)\n (if bindings\n `(let (,(car bindings))\n (when ,(caar bindings)\n ,(bind (cdr bindings) body)))\n `(progn ,@body))))\n (bind binding-list body))))", "macroexpand": "(let ((x 2)) (when x (let ((y x)) (when y (progn (+ x y))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do+ (for (k v) (hash-entries-of ht)) (collect (cons k v)))\n\nWhat needs to change: Macro call that should be transformed by do+", "input": "(do+ (for (k v) (hash-entries-of ht)) (collect (cons k v)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for (k v) (hash-entries-of ht)) (collect (cons k v)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ct-let* nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by CT-LET*", "input": "(ct-let* nil\n :key\n nil)", "output": "(defmacro CT-LET* ...)", "macroexpand": "(cond (*within-captured-dynenv* (progn :key nil))\n (t\n (error\n \"No macrodynamic environment has been captured to establish CT-LET* bindings.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-neo4j-fun get-relationship-properties (relationship-id) :get (:uri-spec (format nil \"relationship/~A/properties\" relationship-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (204 nil) (404 (error 'relationship-not-found-error :uri uri))))\n\nIssue: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-relationship-properties (relationship-id) :get (:uri-spec (format nil \"relationship/~A/properties\" relationship-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (204 nil) (404 (error 'relationship-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-relationship-properties (&key relationship-id) (let ((uri (format nil \"relationship/~A/properties\" relationship-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 204 (lambda (body uri json) nil)) (list 404 (lambda (body uri json) (error (quote relationship-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when (eql counter 0) (return))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when (eql counter 0) (return))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql counter 0) (return))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defgenerator ifilter-false (predicate generator) \"Emits only those items in generator that are false by predicate. The generator equivalent of remove-if\" (do-generator (g generator) (unless (funcall predicate g) (yield g))))\n\nWhat needs to change: Macro call that should be transformed by defgenerator", "input": "(defgenerator ifilter-false (predicate generator) \"Emits only those items in generator that are false by predicate. The generator equivalent of remove-if\" (do-generator (g generator) (unless (funcall predicate g) (yield g))))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun ifilter-false (predicate generator) \"Emits only those items in generator that are false by predicate. The generator equivalent of remove-if\" (with-yield (do-generator (g generator) (unless (funcall predicate g) (yield g)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-neo4j-fun remove-from-index ((type :node) name key value object-id) :delete (:uri-spec (format nil \"index/~A/~A/~@[~A/~]~@[~A/~]~A\" (string-downcase (symbol-name type)) name key (urlencode value) object-id)) (:status-handlers (204 (values t body)) (404 (error 'index-entry-not-found-error :uri uri))))\n\nPattern to recognize: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun remove-from-index ((type :node) name key value object-id) :delete (:uri-spec (format nil \"index/~A/~A/~@[~A/~]~@[~A/~]~A\" (string-downcase (symbol-name type)) name key (urlencode value) object-id)) (:status-handlers (204 (values t body)) (404 (error 'index-entry-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun remove-from-index (&key (type :node) name key value object-id) (let ((uri (format nil \"index/~A/~A/~@[~A/~]~@[~A/~]~A\" (string-downcase (symbol-name type)) name key (urlencode value) object-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :delete uri json (list (list 204 (lambda (body uri json) (values t body))) (list 404 (lambda (body uri json) (error (quote index-entry-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do-sequences! ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))\n\nIssue: Macro call that should be transformed by do-sequences", "input": "(do-sequences! ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))", "output": "(defmacro do-sequences (name/seqs &body forms &environment env)\n \"Iterate over the elements of one or more sequences.\n\n Iteration is performed using the iterator interface, and over\n multiple sequences simultaneously.\n\n The macro arguments can be in one of the following two forms:\n\n 1. (NAME (&REST SEQS) &BODY BODY)\n\n 2. ((&REST SEQS) &BODY BODY)\n\n NAME is a symbol serving as the name of the BLOCK from which the\n forms in BODY can return, using (RETURN-FROM NAME ...). If not\n given defaults to NIL.\n\n Each element of SEQS is a list of the form (VAR SEQUENCE . ARGS),\n where VAR is the variable to which the element of the sequence,\n SEQUENCE, is bound, at each iteration, and ARGS are arguments\n passed to the ITERATOR function, after the sequence.\n\n BODY is a list of forms evaluated at each iteration. RETURN-FROM to\n the block named NAME may be used to terminate the iteration early\n and return a value from the DO-SEQUENCES form. NIL is returned if\n there is no explicit RETURN.\"\n\n (let-if ((name name/seqs)\n (seqs (first forms) name/seqs)\n (forms (rest forms) forms))\n (symbolp name/seqs)\n\n (let ((safety (cadr (assoc 'safety (declaration-information 'optimize env)))))\n `(,(if (> safety 2)\n 'do-sequences-safe%\n 'do-sequences-fast%)\n\n ,name\n ,seqs\n ,@forms))))", "macroexpand": "(do-sequences!-fast% nil ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(orf (formatted-message-text self) (format-message self))\n\nWrite a macro that addresses: Macro call that should be transformed by orf", "input": "(orf (formatted-message-text self) (format-message self))", "output": "(defmacro orf (location form &environment env)\n (multiple-value-bind (vars values new setter getter)\n (get-setf-expansion location env)\n (when (cdr new)\n (error \"Can't work with setf-expansion for ~s - ~d values from setter ~s\"\n location (length new) new))\n (let ((current (car new)))\n `(let* (,@(mapcar 'list vars values)\n (,current ,getter))\n (or ,current\n (progn (setf ,current ,form)\n ,setter))))))", "macroexpand": "(let* ((#:self132 self) (#:new131 (formatted-message-text #:self132))) (or #:new131 (progn (setf #:new131 (format-message self)) (funcall (function (setf formatted-message-text)) #:new131 #:self132))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-special-initargs* 'some-name)\n\nPattern to recognize: Macro call that should be transformed by WITH-SPECIAL-INITARGS*", "input": "(with-special-initargs* 'some-name)", "output": "(defmacro WITH-SPECIAL-INITARGS* ...)", "macroexpand": "(with-special-initargs (quote)\n (with-special-initargs* (some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(match nil nil)\n\nIssue: Macro call that should be transformed by MATCH", "input": "(match nil nil)", "output": "(defmacro MATCH ...)", "macroexpand": "(block #:match125 (when (and (not nil)) (return-from #:match125 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-custom-var (:end-of-array *end-of-array-handler*) (constantly nil) \"Designator for a function of no arguments (called at encountering a closing bracket for an Array).\")\n\nWrite a macro that addresses: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:end-of-array *end-of-array-handler*) (constantly nil) \"Designator for a function of no arguments (called at encountering a closing bracket for an Array).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*end-of-array-handler* . :end-of-array)) *custom-vars* :test (function equal)) (defvar *end-of-array-handler* (constantly nil) \"Designator for a function of no arguments (called at encountering a closing bracket for an Array).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(when-let* ((x t) (y (consp x)) (z (error \"OOPS\"))) t)\n\nPattern to recognize: Macro call that should be transformed by when-let", "input": "(when-let* ((x t) (y (consp x)) (z (error \"OOPS\"))) t)", "output": "(defmacro when-let (bindings &body forms)\n \"Creates new variable bindings, and conditionally executes FORMS.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nAll initial-forms are executed sequentially in the specified order. Then all\nthe variables are bound to the corresponding values.\n\nIf all variables were bound to true values, then FORMS are executed as an\nimplicit PROGN.\"\n (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings))\n (variables (mapcar #'car binding-list)))\n `(let ,binding-list\n (when (and ,@variables)\n ,@forms))))", "macroexpand": "(let ((x t)) (when x (let ((y (consp x))) (when y (let ((z (error \"OOPS\"))) (when z (progn t)))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) val))\n\nIssue: Macro call that should be transformed by c?-with-stored", "input": "(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) val))", "output": "(defmacro c?-with-stored ((var key store &optional default) &body body)\n `(c? (bwhen-c-stored (,var ,key ,store ,default)\n\t ,@body)))", "macroexpand": "(c? (bwhen-c-stored (v :bar store (quote nothing)) (bwhen (val (value v)) val)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(c? (c-assert (listp (kid-values self))) (mapsort (^sort-map) (the-kids (mapcar (lambda (kid-value) (trc \"making kid\" kid-value) (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil \"family-values forced to make new kid\" self .cache kid-value) (funcall (kid-factory self) self kid-value))) (^kid-values)))))\n\nWrite a macro that addresses: Macro call that should be transformed by c?", "input": "(c? (c-assert (listp (kid-values self))) (mapsort (^sort-map) (the-kids (mapcar (lambda (kid-value) (trc \"making kid\" kid-value) (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil \"family-values forced to make new kid\" self .cache kid-value) (funcall (kid-factory self) self kid-value))) (^kid-values)))))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((c-assert (listp (kid-values self))) (mapsort (^sort-map) (the-kids (mapcar (lambda (kid-value) (trc \"making kid\" kid-value) (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil \"family-values forced to make new kid\" self .cache kid-value) (funcall (kid-factory self) self kid-value))) (^kid-values)))))) :value-state :unevaluated :rule (c-lambda (c-assert (listp (kid-values self))) (mapsort (^sort-map) (the-kids (mapcar (lambda (kid-value) (trc \"making kid\" kid-value) (or (find kid-value .cache :key (kv-key self) :test (kv-key-test self)) (trc nil \"family-values forced to make new kid\" self .cache kid-value) (funcall (kid-factory self) self kid-value))) (^kid-values))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-syntax common-lisp:nil common-lisp:nil)\n\nProblem: Macro call that should be transformed by DEFINE-SYNTAX", "input": "(define-syntax common-lisp:nil common-lisp:nil)", "output": "(defmacro DEFINE-SYNTAX ...)", "macroexpand": "(common-lisp:defmacro common-lisp:nil\n (\n common-lisp:&rest\n |https://github.com/g000001/mbe#internals|::__syntax-rules-arg__)\n (common-lisp:let ((|https://github.com/g000001/mbe#internals|::__syntax-rules-arg__\n (common-lisp:cons 'common-lisp:nil\n |https://github.com/g000001/mbe#internals|::__syntax-rules-arg__))\n (|https://github.com/g000001/mbe#internals|::__syntax-rules-keywords__\n '(common-lisp:nil)))\n (common-lisp:cond\n (common-lisp:t\n (common-lisp:error \"~a: no matching clause\" 'common-lisp:nil)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(setf)\n\nIssue: Macro call that should be transformed by SETF", "input": "(setf)", "output": "(defmacro SETF ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(any-of nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ANY-OF", "input": "(any-of nil\n nil)", "output": "(defmacro ANY-OF ...)", "macroexpand": "(lc (nil nil) thereis)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(isnt \"1\" 1)\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(isnt \"1\" 1)", "output": "(defmacro is (got expected &rest args)\n (with-gensyms (duration result new-args desc)\n (once-only (expected)\n `(let* ((,new-args (list ,@args))\n (,desc (parse-description-and-test ,new-args)))\n (with-catching-errors (:description ,desc :expected ,expected)\n (with-duration ((,duration ,result) ,got)\n (test ,result ,expected ,new-args\n :duration ,duration)))))))", "macroexpand": "(let ((#:expected161 1)) (let* ((#:new-args159 (list)) (#:desc160 (parse-description-and-test #:new-args159))) (with-catching-errors (:description #:desc160 :expected #:expected161) (with-duration ((#:duration157 #:result158) \"1\") (test #:result158 #:expected161 #:new-args159 :notp t :duration #:duration157)))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-mocks () (register-mock 'foo) (is (null (multiple-value-list (foo)))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (register-mock 'foo) (is (null (multiple-value-list (foo)))))", "output": "(defmacro with-mocks ((&key (recordp T)) &body body)\n \"Execute BODY in a new mocking context. Invocations will be recorded\nif RECORDP is set (default true).\"\n `(call-with-mocks\n (lambda () ,@body)\n :recordp ,recordp))", "macroexpand": "(call-with-mocks (lambda nil (register-mock (quote foo)) (is (null (multiple-value-list (foo))))) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-color (:yellow :stream stream) (format/indent reporter stream \"\u25b3 Looks like you planned ~D test~:*~P but ran ~A.~%\" plan count))\n\nPattern to recognize: Macro call that should be transformed by with-color", "input": "(with-color (:yellow :stream stream) (format/indent reporter stream \"\u25b3 Looks like you planned ~D test~:*~P but ran ~A.~%\" plan count))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq :yellow :gray) (eq :yellow :grey) (eq :yellow +gray+) (eq :yellow +grey+)) (with-gray stream (format/indent reporter stream \"\u25b3 Looks like you planned ~D test~:*~P but ran ~A.~%\" plan count)) (cl-ansi-text:with-color (:yellow :stream stream) (format/indent reporter stream \"\u25b3 Looks like you planned ~D test~:*~P but ran ~A.~%\" plan count))) (progn (format/indent reporter stream \"\u25b3 Looks like you planned ~D test~:*~P but ran ~A.~%\" plan count)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-quasi-quoted-binary-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BINARY-SYNTAX", "input": "(enable-quasi-quoted-binary-syntax)", "output": "(defmacro ENABLE-QUASI-QUOTED-BINARY-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-binary-syntax-in-readtable :start-character nil\n :end-character nil\n :unquote-character #\\COMMA\n :splice-character\n #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP\n :dispatched-quasi-quote-name\n \"bin\" :transformation-pipeline\n nil)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym :minimizing :min)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym :minimizing :min)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :minimizing) (quote synonym)) (quote :min)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-html-string (:a :href \"#\" :data-instant nil))\n\nIssue: Macro call that should be transformed by with-html", "input": "(with-html-string (:a :href \"#\" :data-instant nil))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:a :href \"#\" :data-instant nil)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(let-syntax 'some-name)\n\nPattern to recognize: Macro call that should be transformed by LET-SYNTAX", "input": "(let-syntax 'some-name)", "output": "(defmacro LET-SYNTAX ...)", "macroexpand": "(letrec-syntax (common-lisp:quote) (let-syntax (some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n($op* op l)\n\nWrite a macro that addresses: Macro call that should be transformed by $op", "input": "($op* op l)", "output": "(defmacro $op (op &rest args)\n (cond ((consp (car args)) `(map-reduce-op ,op ($exp+ ,@args)))\n\t(t `($op* ,op ,@args))))", "macroexpand": "(multiple-value-bind (#:g325 #:g328) (op-split (unwrap (list ($exp+ l)))) (let ((#:g327 (kv (car #:g325) (kv op #:g328)))) (dolist (#:g326 (cdr #:g325)) (setf #:g327 (kv #:g327 (kv #:g326 (kv op #:g328))))) #:g327))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.8474999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-global-parameter nil nil)\n\nPattern to recognize: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER", "input": "(define-global-parameter nil nil)", "output": "(defmacro DEFINE-GLOBAL-PARAMETER ...)", "macroexpand": "(progn\n (store-in-symbol-plist nil nil .value-key.)\n (sb-ext:defglobal nil (get 'nil +value-key+))\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf nil (get 'nil +value-key+)))\n (remprop 'nil +value-key+)\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-access nil\n nil)\n\nProblem: Macro call that should be transformed by WITH-ACCESS", "input": "(with-access nil\n nil)", "output": "(defmacro with-access ((&rest keys) val-form &body body)\n \"Similar to with-accessors except using the access functions\"\n (let* ((gval (gensym \"val\"))\n (forms\n (iter (for k in keys)\n (for (k-to k-from) = (if (listp k) k (list k k)))\n (collect `(,k-to (access ,gval ',k-from))))))\n `(let ((,gval ,val-form))\n (declare (ignorable ,gval))\n (symbol-macrolet (,@forms)\n ,@body\n ))))", "macroexpand": "(let ((#:|val241| nil))\n (declare (ignorable #:|val241|))\n (symbol-macrolet ()))", "category": "dispatch", "technique": "symbol-macrolet,gensym", "complexity": "intermediate", "quality_score": 0.88} {"instruction": "Generate a defmacro form that transforms code like this:\n($> \"l\" -9)\n\nPattern to recognize: Macro call that should be transformed by $", "input": "($> \"l\" -9)", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "($op \"$gt\" \"l\" -9)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-value-binding in (var list &key (by NIL by-p)) (declare (type list list)) `(cond (,list ,(if by-p `(progn (update ,var (car ,list)) (setf ,list (funcall ,by ,list))) `(update ,var (pop ,list)))) (T (end-for))))\n\nIssue: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding in (var list &key (by NIL by-p)) (declare (type list list)) `(cond (,list ,(if by-p `(progn (update ,var (car ,list)) (setf ,list (funcall ,by ,list))) `(update ,var (pop ,list)))) (T (end-for))))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding in (var list &key (by nil by-p)) (let ((#:list134 (gensym #A((4) base-char . \"LIST\"))) (#:by135 (gensym #A((2) base-char . \"BY\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:list134 list) (list #:by135 by) (loop for #:var133 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var133 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:list134 :kind 0) #S(sb-impl::comma :expr #:by135 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote list) :kind 0) #S(sb-impl::comma :expr #:list134 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((list #:list134) (by #:by135)) (declare (ignorable list by)) (sb-int:quasiquote (cond (#S(sb-impl::comma :expr list :kind 0) #S(sb-impl::comma :expr (if by-p (sb-int:quasiquote (progn (update #S(sb-impl::comma :expr var :kind 0) (car #S(sb-impl::comma :expr list :kind 0))) (setf #S(sb-impl::comma :expr list :kind 0) (funcall #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr list :kind 0))))) (sb-int:quasiquote (update #S(sb-impl::comma :expr var :kind 0) (pop #S(sb-impl::comma :expr list :kind 0))))) :kind 0)) (t (end-for))))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-nth nil :key nil)\n\nProblem: Macro call that should be transformed by COLLECT-NTH", "input": "(collect-nth nil :key nil)", "output": "(defmacro COLLECT-NTH ...)", "macroexpand": "(common-lisp:let* ((#:generator-420 (generator :key))\n #:items-412\n (#:counter-414 nil)\n (#:item-415 nil))\n (declare (type generator #:generator-420)\n (type (null-or fixnum) #:counter-414)\n (type (null-or t) #:item-415))\n (tagbody\n #:ll-421\n (setq #:items-412 (next-in #:generator-420 (go end)))\n (when (zerop #:counter-414) (setq #:item-415 #:items-412) (go end))\n (decf #:counter-414)\n (go #:ll-421)\n end)\n #:item-415)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(pop-preprocessor-directive-token token-list :|_Pragma|)\n\nIssue: Macro call that should be transformed by pop-preprocessor-directive-token", "input": "(pop-preprocessor-directive-token token-list :|_Pragma|)", "output": "(defmacro pop-preprocessor-directive-token (token-list directive-name &key (errorp t))\n \"Pops the next token in TOKEN-LIST ignoring `+whitespace-marker+'\"\n (with-gensyms (head_)\n `(let ((,head_\n (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)))\n (if (eq +whitespace-marker+ ,head_)\n (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)\n ,head_))))", "macroexpand": "(let ((#:head_268 (check-and-pop-pp-directive-token-1 token-list :|_Pragma| t))) (if (eq +whitespace-marker+ #:head_268) (check-and-pop-pp-directive-token-1 token-list :|_Pragma| t) #:head_268))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(loop 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by LOOP", "input": "(loop 'some-name)", "output": "(defmacro LOOP ...)", "macroexpand": "(block nil (tagbody #:g191 (progn 'some-name) (go #:g191)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-errno-symbol EILSEQ)\n\nWhat needs to change: Macro call that should be transformed by define-errno-symbol", "input": "(define-errno-symbol EILSEQ)", "output": "(defmacro define-errno-symbol (name)\n `(defparameter ,name\n (find-errno-symbol (string ',name))))", "macroexpand": "(defparameter eilseq (find-errno-symbol (string (quote eilseq))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(destructuring-case 'some-name)\n\nIssue: Macro call that should be transformed by DESTRUCTURING-CASE", "input": "(destructuring-case 'some-name)", "output": "(defmacro DESTRUCTURING-CASE ...)", "macroexpand": "(destructuring-case-alt 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-test bad-dependency :depends-on (failing) (is = 5 5))\n\nPattern to recognize: Macro call that should be transformed by define-test", "input": "(define-test bad-dependency :depends-on (failing) (is = 5 5))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote bad-dependency) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote bad-dependency) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (is = 5 5))) :parent (quote nil) (quote :depends-on) (quote (failing)))) (quote bad-dependency))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(signal-syntax-error* open-paren-pos \"Opening paren has no matching closing paren.\")\n\nWhat needs to change: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* open-paren-pos \"Opening paren has no matching closing paren.\")", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos open-paren-pos :format-control \"Opening paren has no matching closing paren.\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(dflet ((list ())) (is (eql 42 (list))))\n\nPattern to recognize: Macro call that should be transformed by dflet", "input": "(dflet ((list ())) (is (eql 42 (list))))", "output": "(defmacro dflet ((&rest definitions) &body body)\n \"Like FLET, but dynamically sets the FDEFINITIONS during the duration of\nthe BODY.\"\n `(progf\n ',(mapcar #'car definitions)\n (list\n ,.(mapcar (lambda (definition)\n `(lambda ,(cadr definition)\n ,@(cddr definition)))\n definitions))\n ,@body))", "macroexpand": "(progf (quote (list)) (list (lambda nil)) (is (eql 42 (list))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-option-expander nicknames (package &rest nicknames) (loop for nick in nicknames do (add-package-nickname package nick)))\n\nProblem: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander nicknames (package &rest nicknames) (loop for nick in nicknames do (add-package-nickname package nick)))", "output": "(defmacro define-option-expander (name (package &rest arguments) &body body)\n (let ((args (gensym \"ARGS\")))\n `(defmethod expand-option ((,(gensym \"TYPE\") (eql ,(intern (string name) \"KEYWORD\"))) ,package ,args)\n (destructuring-bind ,arguments ,args\n ,@body))))", "macroexpand": "(defmethod expand-option ((#:type122 (eql :nicknames)) package #:args121) (destructuring-bind (&rest nicknames) #:args121 (loop for nick in nicknames do (add-package-nickname package nick))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-connection (let ((user (retrieve-one :user :by :name := \"nitro_idiot\"))) (is-type user 'trivial-types:property-list)) (let ((user (retrieve-one :user :by :name := \"nitro_idiot\" :as 'hash-table))) (is-type user 'hash-table)) (let* ((*default-row-type* 'hash-table) (user (retrieve-one :user :by :name := \"nitro_idiot\"))) (is-type user 'hash-table)) (let* ((*default-row-type* 'hash-table) (user (retrieve-one :user :by :name := \"nitro_idiot\" :as 'trivial-types:association-list))) (is-type user 'trivial-types:association-list)))\n\nProblem: Macro call that should be transformed by with-connection", "input": "(with-connection (let ((user (retrieve-one :user :by :name := \"nitro_idiot\"))) (is-type user 'trivial-types:property-list)) (let ((user (retrieve-one :user :by :name := \"nitro_idiot\" :as 'hash-table))) (is-type user 'hash-table)) (let* ((*default-row-type* 'hash-table) (user (retrieve-one :user :by :name := \"nitro_idiot\"))) (is-type user 'hash-table)) (let* ((*default-row-type* 'hash-table) (user (retrieve-one :user :by :name := \"nitro_idiot\" :as 'trivial-types:association-list))) (is-type user 'trivial-types:association-list)))", "output": "(defmacro with-connection (&body body)\n `(let ((*connection* (connect-cached :sqlite3 :database-name *db-path*)))\n ,@body))", "macroexpand": "(let ((let (connect ((user (retrieve-one :user :by :name := \"nitro_idiot\"))) (is-type user (quote trivial-types:property-list))))) (unwind-protect (progn (let ((user (retrieve-one :user :by :name := \"nitro_idiot\" :as (quote hash-table)))) (is-type user (quote hash-table))) (let* ((*default-row-type* (quote hash-table)) (user (retrieve-one :user :by :name := \"nitro_idiot\"))) (is-type user (quote hash-table))) (let* ((*default-row-type* (quote hash-table)) (user (retrieve-one :user :by :name := \"nitro_idiot\" :as (quote trivial-types:association-list)))) (is-type user (quote trivial-types:association-list)))) (disconnect let)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-unique-names (s-indicator current-s-indicator) (defmacro symbolic (operation test &rest other-args) (with-unique-names (this-s) (let ((current-s (get s-indicator current-s-indicator))) (setf (get s-indicator current-s-indicator) this-s) `(symbol-macrolet ((,this-s (internal-symbol-macrolet ((it ,current-s)) ,test)) (it ,this-s)) (,operation it ,@other-args))))) (defmacro anaphoric (op test &body body) (with-unique-names (this-s) (setf (get s-indicator current-s-indicator) this-s) `(let* ((it ,test) (,this-s it)) (declare (ignorable ,this-s)) (,op it ,@body)))))\n\nProblem: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (s-indicator current-s-indicator) (defmacro symbolic (operation test &rest other-args) (with-unique-names (this-s) (let ((current-s (get s-indicator current-s-indicator))) (setf (get s-indicator current-s-indicator) this-s) `(symbol-macrolet ((,this-s (internal-symbol-macrolet ((it ,current-s)) ,test)) (it ,this-s)) (,operation it ,@other-args))))) (defmacro anaphoric (op test &body body) (with-unique-names (this-s) (setf (get s-indicator current-s-indicator) this-s) `(let* ((it ,test) (,this-s it)) (declare (ignorable ,this-s)) (,op it ,@body)))))", "output": "(defmacro with-unique-names ((&rest bindings) &body body)\n `(let ,(mapcar #'(lambda (binding)\n\t\t (destructuring-bind (var prefix)\n\t\t\t (if (consp binding) binding (list binding binding))\n\t\t `(,var (gensym ,(string prefix)))))\n\t\t bindings)\n ,@body))", "macroexpand": "(let ((s-indicator (gensym #A((12) base-char . \"S-INDICATOR-\"))) (current-s-indicator (gensym #A((20) base-char . \"CURRENT-S-INDICATOR-\")))) (defmacro symbolic (operation test &rest other-args) (with-unique-names (this-s) (let ((current-s (get s-indicator current-s-indicator))) (setf (get s-indicator current-s-indicator) this-s) (quasiquote (symbol-macrolet ((#S(sb-impl::comma :expr this-s :kind 0) (internal-symbol-macrolet ((it #S(sb-impl::comma :expr current-s :kind 0))) #S(sb-impl::comma :expr test :kind 0))) (it #S(sb-impl::comma :expr this-s :kind 0))) (#S(sb-impl::comma :expr operation :kind 0) it #S(sb-impl::comma :expr other-args :kind 2))))))) (defmacro anaphoric (op test &body body) (with-unique-names (this-s) (setf (get s-indicator current-s-indicator) this-s) (quasiquote (let* ((it #S(sb-impl::comma :expr test :kind 0)) (#S(sb-impl::comma :expr this-s :kind 0) it)) (declare (ignorable #S(sb-impl::comma :expr this-s :kind 0))) (#S(sb-impl::comma :expr op :kind 0) it #S(sb-impl::comma :expr body :kind 2)))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-type-map setf-expander cl:setf)\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-type-map", "input": "(define-simple-type-map setf-expander cl:setf)", "output": "(defmacro define-simple-type-map (class type)\n `(defmethod type ((,class ,class))\n ',type))", "macroexpand": "(defmethod type ((setf-expander setf-expander)) (quote setf))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ematch0 list ((cons it nil) (cons (funcall fn it nil) nil)) ((cons it rest) (cons (funcall fn it t) (mapcar1-with-next fn rest))))\n\nProblem: Macro call that should be transformed by ematch0", "input": "(ematch0 list ((cons it nil) (cons (funcall fn it nil) nil)) ((cons it rest) (cons (funcall fn it t) (mapcar1-with-next fn rest))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 list ((cons it nil) (cons (funcall fn it nil) nil)) ((cons it rest) (cons (funcall fn it t) (mapcar1-with-next fn rest))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> +table-open+ +skip-space+)\n\nIssue: Macro call that should be transformed by *>", "input": "(*> +table-open+ +skip-space+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset230) (multiple-value-bind (#:*>-res231 #:*>-next232) (funcall +table-open+ #:*>-offset230) (if (ok? #:*>-res231) (funcall +skip-space+ #:*>-next232) (fail #:*>-next232))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda-cmatch (PATTERN BODY...))\n\nPattern to recognize: Macro call that should be transformed by lambda-cmatch", "input": "(lambda-cmatch (PATTERN BODY...))", "output": "(defmacro lambda-cmatch (&body clauses)\n \"Equivalent to (lambda (arg) (cmatch arg CLAUSES...)).\"\n (with-unique-names (arg)\n `(lambda (,arg) (cmatch ,arg ,@clauses))))", "macroexpand": "(lambda (#:arg124) (cmatch #:arg124 (pattern body...)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(rte-ecase 'some-name)\n\nProblem: Macro call that should be transformed by RTE-ECASE", "input": "(rte-ecase 'some-name)", "output": "(defmacro RTE-ECASE ...)", "macroexpand": "(let ((#:rte172 'some-name))\n (rte-ecase #:rte172\n ((:* t) (error \"The sequence ~A fell through the RTE-ECASE\" #:rte172))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-api register-readtable (name readtable) (symbol readtable => readtable) \"Associate READTABLE with NAME. Returns the readtable.\" (assert (typep name '(not (satisfies reserved-readtable-name-p)))) (%associate-readtable-with-name name readtable) (%associate-name-with-readtable name readtable) readtable)\n\nIssue: Macro call that should be transformed by define-api", "input": "(define-api register-readtable (name readtable) (symbol readtable => readtable) \"Associate READTABLE with NAME. Returns the readtable.\" (assert (typep name '(not (satisfies reserved-readtable-name-p)))) (%associate-readtable-with-name name readtable) (%associate-name-with-readtable name readtable) readtable)", "output": "(defmacro define-api (name lambda-list type-list &body body)\n (flet ((parse-type-list (type-list)\n (let ((pos (position '=> type-list)))\n (assert pos () \"You forgot to specify return type (`=>' missing.)\")\n (values (subseq type-list 0 pos)\n `(values ,@(nthcdr (1+ pos) type-list) &optional)))))\n (multiple-value-bind (body decls docstring)\n (parse-body body :documentation t :whole `(define-api ,name))\n (multiple-value-bind (arg-typespec value-typespec)\n (parse-type-list type-list)\n (multiple-value-bind (reqs opts rest keys)\n (parse-ordinary-lambda-list lambda-list)\n (declare (ignorable reqs opts rest keys))\n `(progn\n (declaim (ftype (function ,arg-typespec ,value-typespec) ,name))\n (locally\n ;; Muffle the annoying \"&OPTIONAL and &KEY found in\n ;; the same lambda list\" style-warning\n #+sbcl (declare (sb-ext:muffle-conditions style-warning))\n (defun ,name ,lambda-list\n ,docstring\n ,@decls\n (locally\n #+sbcl (declare (sb-ext:unmuffle-conditions style-warning))\n\n ;; SBCL will interpret the ftype declaration as\n ;; assertion and will insert type checks for us.\n #-sbcl\n (progn\n ;; CHECK-TYPE required parameters\n ,@(loop for req-arg in reqs\n for req-type = (pop type-list)\n do (assert req-type)\n collect `(check-type ,req-arg ,req-type))\n\n ;; CHECK-TYPE optional parameters\n ,@(progn\n (assert (or (null opts)\n (eq (pop type-list) '&optional)))\n (loop for (opt-arg . nil) in opts\n for opt-type = (pop type-list)\n do (assert opt-type)\n collect `(check-type ,opt-arg ,opt-type)))\n\n ;; CHECK-TYPE rest parameter\n ,@(when rest\n (assert (eq (pop type-list) '&rest))\n (let ((rest-type (pop type-list)))\n (assert rest-type)\n `((dolist (x ,rest)\n (check-type x ,rest-type)))))\n\n ;; CHECK-TYPE key parameters\n ,@(progn\n (assert (or (null keys)\n (eq (pop type-list) '&key)))\n (loop for ((keyword key-arg) . nil) in keys\n for (nil key-type) = (find keyword type-list\n :key #'car)\n collect `(check-type ,key-arg ,key-type))))\n\n ,@body)))))))))", "macroexpand": "(progn (declaim (ftype (function (symbol readtable) (values readtable &optional)) register-readtable)) (locally (declare (sb-ext:muffle-conditions style-warning)) (defun register-readtable (name readtable) \"Associate READTABLE with NAME. Returns the readtable.\" (locally (declare (sb-ext:unmuffle-conditions style-warning)) (assert (typep name (quote (not (satisfies reserved-readtable-name-p))))) (%associate-readtable-with-name name readtable) (%associate-name-with-readtable name readtable) readtable))))", "category": "efficiency", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-function last 1 (new-val obj) (let ((len (length obj))) (replace-nthcdr (- len 1) obj new-val)))\n\nIssue: Macro call that should be transformed by define-modf-function", "input": "(define-modf-function last 1 (new-val obj) (let ((len (length obj))) (replace-nthcdr (- len 1) obj new-val)))", "output": "(defmacro define-modf-function (name nth-arg (new-val &rest args) &body body)\n \"Define a new modf function. It inverts NAME forms by modifying the NTH-ARG\nterm of the arguments of the place form in the MODF macro.\"\n ;; Side effect in a macro, I know. How can you do this via EVAL-WHEN if I\n ;; want it to run even if not a toplevel macro?\n (setf (gethash name *modf-nth-arg*)\n nth-arg)\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-nth-arg*)\n ,nth-arg))\n (defun ,(intern (modf-name name) :modf) (,new-val ,@args)\n ,@body)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote last) *modf-nth-arg*) 1)) (defun |BUILDER:COMMON-LISP:LAST| (new-val obj) (let ((len (length obj))) (replace-nthcdr (- len 1) obj new-val))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time callees (function-name) (function-record-callees (get-function-record function-name)))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time callees (function-name) (function-record-callees (get-function-record function-name)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun callees (function-name) (function-record-callees (get-function-record function-name))) (eval-when (:compile-toplevel) (compile (quote callees))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(action (:after node-application) #'apply-candidate)\n\nIssue: Macro call that should be transformed by action", "input": "(action (:after node-application) #'apply-candidate)", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-application) (function apply-candidate))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defannotation metaclass (metaclass class-definition-form) (:arity 2) (progn-form-replace-last (lambda (class-definition-form) (if (get-class-option :metaclass class-definition-form) (error \":metaclass is not empty\") (append class-definition-form `((:metaclass ,metaclass))))) class-definition-form))\n\nWrite a macro that addresses: Macro call that should be transformed by defannotation", "input": "(defannotation metaclass (metaclass class-definition-form) (:arity 2) (progn-form-replace-last (lambda (class-definition-form) (if (get-class-option :metaclass class-definition-form) (error \":metaclass is not empty\") (append class-definition-form `((:metaclass ,metaclass))))) class-definition-form))", "output": "(defmacro defannotation (name lambda-list options &body body)\n `(progn\n (set-annotation-options ',name ',options)\n (defmacro ,name ,lambda-list ,@body)))", "macroexpand": "(progn (set-annotation-options (quote metaclass) (quote (:arity 2))) (defmacro metaclass (metaclass class-definition-form) (progn-form-replace-last (lambda (class-definition-form) (if (get-class-option :metaclass class-definition-form) (error \":metaclass is not empty\") (append class-definition-form (sb-int:quasiquote ((:metaclass #S(sb-impl::comma :expr metaclass :kind 0))))))) class-definition-form)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(dispatch-serially ,flow-context ,flow-list)))\n\nProblem: Macro call that should be transformed by with-flow-let-macro", "input": "(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(dispatch-serially ,flow-context ,flow-list)))", "output": "(defmacro with-flow-let-macro ((var flow) &body body)\n `(with-gensyms (,var)\n `(let ((,,var (list ,@,flow)))\n ,,@body)))", "macroexpand": "(with-gensyms (flow-list) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr flow-list :kind 0) (list #S(sb-impl::comma :expr flow :kind 2)))) #S(sb-impl::comma :expr (flow-lambda-macro (flow-context) (sb-int:quasiquote (dispatch-serially #S(sb-impl::comma :expr flow-context :kind 0) #S(sb-impl::comma :expr flow-list :kind 0)))) :kind 0))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-input-from-file (file-stream pathname :external-format external-format) (read-stream-content-into-string file-stream :buffer-size buffer-size))\n\nPattern to recognize: Macro call that should be transformed by with-input-from-file", "input": "(with-input-from-file (file-stream pathname :external-format external-format) (read-stream-content-into-string file-stream :buffer-size buffer-size))", "output": "(defmacro with-input-from-file ((stream-name file-name &rest args\n &key (direction nil direction-p)\n &allow-other-keys)\n &body body)\n \"Evaluate BODY with STREAM-NAME to an input stream on the file\nFILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT,\nwhich is only sent to WITH-OPEN-FILE when it's not NIL.\"\n (declare (ignore direction))\n (when direction-p\n (error \"Can't specify :DIRECTION for WITH-INPUT-FROM-FILE.\"))\n `(with-open-file* (,stream-name ,file-name :direction :input ,@args)\n ,@body))", "macroexpand": "(with-open-file* (file-stream pathname :direction :input :external-format external-format) (read-stream-content-into-string file-stream :buffer-size buffer-size))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-ps-gensyms 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-PS-GENSYMS", "input": "(with-ps-gensyms 'some-name)", "output": "(defmacro WITH-PS-GENSYMS ...)", "macroexpand": "(let* ((quote (ps-gensym #A((5) base-char . \"QUOTE\")))\n (some-name (ps-gensym \"SOME-NAME\"))))", "category": "control-flow", "technique": "gensym", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dynamic-reprogv nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DYNAMIC-REPROGV", "input": "(dynamic-reprogv nil\n :key\n nil)", "output": "(defmacro DYNAMIC-REPROGV ...)", "macroexpand": "(dynamic-wind\n :proceed\n #:proceed204\n (let* ((#:computed-symbols202 nil)\n (#:computed-bindings203 (compute-bindings #:computed-symbols202 :key)))\n (progv #:computed-symbols202 #:computed-bindings203 (#:proceed204 nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(f_\n nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by F_", "input": "(f_\n nil\n nil)", "output": "(defmacro F_ ...)", "macroexpand": "(lambda (_) nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-html-string (:tag :name \"xy\" \"Hello\"))\n\nPattern to recognize: Macro call that should be transformed by with-html", "input": "(with-html-string (:tag :name \"xy\" \"Hello\"))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:tag :name \"xy\" \"Hello\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(bind ((#(a b c) #(1 2 3))) (list a b c))\n\nPattern to recognize: Macro call that should be transformed by bind", "input": "(bind ((#(a b c) #(1 2 3))) (list a b c))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-166| #(1 2 3)) (a (aref #:|values-166| 0)) (b (aref #:|values-166| 1)) (c (aref #:|values-166| 2))) (declare (ignorable #:|values-166|)) (progn (list a b c)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(the nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by THE", "input": "(the nil :key nil)", "output": "(defmacro THE ...)", "macroexpand": "(send self nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(m 'some-name)\n\nPattern to recognize: Macro call that should be transformed by M", "input": "(m 'some-name)", "output": "(defmacro M ...)", "macroexpand": "(lambda (&rest #:|macro-lambda-list124|)\n (destructuring-bind (quote some-name) #:|macro-lambda-list124|))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(match nil\n (progn))\n\nIssue: Macro call that should be transformed by MATCH", "input": "(match nil\n (progn))", "output": "(defmacro MATCH ...)", "macroexpand": "(match* (nil)\n ((progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(c-assert entry)\n\nPattern to recognize: Macro call that should be transformed by c-assert", "input": "(c-assert entry)", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless entry (c-break \"failed assertion: ~a\" (quote entry))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.885} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(producing nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by PRODUCING", "input": "(producing nil nil)", "output": "(defmacro PRODUCING ...)", "macroexpand": "(non-opt-producing nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(cardinality-case nil)\n\nWhat needs to change: Macro call that should be transformed by CARDINALITY-CASE", "input": "(cardinality-case nil)", "output": "(defmacro CARDINALITY-CASE ...)", "macroexpand": "(let ((#:cardinality127 nil))\n (typecase #:cardinality127))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(maybe-do-not-silence-errors (handler-case (call-next-method) (error (err) (setf (value result) (if (typep result 'multiple-value-result) (list err) err)) (setf (status result) :failed))))\n\nProblem: Macro call that should be transformed by maybe-do-not-silence-errors", "input": "(maybe-do-not-silence-errors (handler-case (call-next-method) (error (err) (setf (value result) (if (typep result 'multiple-value-result) (list err) err)) (setf (status result) :failed))))", "output": "(defmacro maybe-do-not-silence-errors (&body body)\n `(if *silence-plain-compilation-errors-p*\n ,@body\n (let ((ok nil))\n (unwind-protect\n (multiple-value-prog1\n (call-next-method)\n (setf ok t))\n (unless ok (setf (status result) :failed))))))", "macroexpand": "(if *silence-plain-compilation-errors-p* (handler-case (call-next-method) (error (err) (setf (value result) (if (typep result (quote multiple-value-result)) (list err) err)) (setf (status result) :failed))) (let ((ok nil)) (unwind-protect (multiple-value-prog1 (call-next-method) (setf ok t)) (unless ok (setf (status result) :failed)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-hook-type any (function (&rest t)) \"Hook accepting any arguments and returning anything.\")\n\nWhat needs to change: Macro call that should be transformed by define-hook-type", "input": "(define-hook-type any (function (&rest t)) \"Hook accepting any arguments and returning anything.\")", "output": "(defmacro define-hook-type (name type &optional documentation)\n \"Define hook class.\nType must be something like:\n\n (function (string) (values integer t))\n\nThe `handler-type' of the defined hook class has `:class' allocation\ntype, so that all hooks of such class have the same `handler-type'.\"\n (let* ((name (string name))\n (hook-class-name (intern (serapeum:concat \"HOOK-\" name))))\n `(defclass ,hook-class-name (hook)\n ((handler-type :initform ',type :allocation :class))\n (:metaclass closer-mop:funcallable-standard-class)\n ,@(when documentation\n `((:documentation ,documentation))))))", "macroexpand": "(defclass hook-any (hook) ((handler-type :initform (quote (function (&rest t))) :allocation :class)) (:metaclass sb-mop:funcallable-standard-class) (:documentation \"Hook accepting any arguments and returning anything.\"))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(n-spaces *indent*)\n\nProblem: Macro call that should be transformed by n-spaces", "input": "(n-spaces *indent*)", "output": "(defmacro n-spaces (n)\n \"A string with N spaces - used by indentation.\"\n `(make-array ,n\n :element-type 'base-char\n :displaced-to +spaces+\n :displaced-index-offset 0))", "macroexpand": "(make-array *indent* :element-type (quote base-char) :displaced-to +spaces+ :displaced-index-offset 0)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(ematch0 parsed1 ((list slot pattern) (let (effslot reader) (cond ((setf effslot (find-effective-slot slot type)) `((slot-value ,it ',(c2mop:slot-definition-name effslot)) ,pattern)) ((setf reader (find-reader slot type)) `((,reader ,it) ,pattern)) (t (error \"Failed to deduce the way to access the slot ~s\" slot))))))\n\nPattern to recognize: Macro call that should be transformed by ematch0", "input": "(ematch0 parsed1 ((list slot pattern) (let (effslot reader) (cond ((setf effslot (find-effective-slot slot type)) `((slot-value ,it ',(c2mop:slot-definition-name effslot)) ,pattern)) ((setf reader (find-reader slot type)) `((,reader ,it) ,pattern)) (t (error \"Failed to deduce the way to access the slot ~s\" slot))))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 parsed1 ((list slot pattern) (let (effslot reader) (cond ((setf effslot (find-effective-slot slot type)) (sb-int:quasiquote ((slot-value #S(sb-impl::comma :expr it :kind 0) (quote #S(sb-impl::comma :expr (sb-mop:slot-definition-name effslot) :kind 0))) #S(sb-impl::comma :expr pattern :kind 0)))) ((setf reader (find-reader slot type)) (sb-int:quasiquote ((#S(sb-impl::comma :expr reader :kind 0) #S(sb-impl::comma :expr it :kind 0)) #S(sb-impl::comma :expr pattern :kind 0)))) (t (error \"Failed to deduce the way to access the slot ~s\" slot))))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defmethod* nil (progn))\n\nProblem: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil (progn))", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(let* ((#:nil127 (ensure-generic*-function 'nil))\n (temp-method (defmethod #:nil126 (progn)))\n (actual-gf\n (ensure-generic*-function 'nil :lambda-list\n (sb-mop:generic-function-lambda-list\n (symbol-function '#:nil126))\n :special-variables 'nil))\n (actual-method\n (add-method* #:nil127\n (make-instance 'method* :special-variables (list)\n :qualifiers 'nil :specializers\n (sb-mop:method-specializers temp-method)\n :lambda-list\n (sb-mop:method-lambda-list temp-method)\n :documentation\n (documentation temp-method t) :function\n (sb-mop:method-function temp-method)))))\n (declare (ignorable #:nil127)\n (ignore actual-gf))\n (setf (documentation actual-method t) (documentation temp-method t))\n actual-method)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-wcs-math-error-handling (ret (hypot x y)) (check-wcs-math-result))\n\nIssue: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (hypot x y)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g236 x) (#:g237 y) (#:g238 (list #:g236 #:g237))) (declare (ignorable #:g237) (type list #:g238) (dynamic-extent #:g238)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote hypot) #:g238) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g238)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defgenerator take-as-generator (n generator &key (fail-if-short t)) \"This function has the same meaning as TAKE but returns a generator instead of a list. Eg: (generator->list (take-as-generator 10 (list->generator '(1 2 3)))) -> Signals a condition (generator->list (take-as-generator 10 (list->generator '(1 2 3)) :fail-if-short nil)) -> (1 2 3) (generator->list (take-as-generator 3 (repeat 1))) -> (1 1 1)\" (declare (type (integer 1) n)) (let ((count 0)) (do-generator (g generator) (yield g) (incf count) (when (= count n) (yield 'generator-stop)))) (when fail-if-short (error 'insufficient-items :format-control \"Insufficient items in generator\")))\n\nProblem: Macro call that should be transformed by defgenerator", "input": "(defgenerator take-as-generator (n generator &key (fail-if-short t)) \"This function has the same meaning as TAKE but returns a generator instead of a list. Eg: (generator->list (take-as-generator 10 (list->generator '(1 2 3)))) -> Signals a condition (generator->list (take-as-generator 10 (list->generator '(1 2 3)) :fail-if-short nil)) -> (1 2 3) (generator->list (take-as-generator 3 (repeat 1))) -> (1 1 1)\" (declare (type (integer 1) n)) (let ((count 0)) (do-generator (g generator) (yield g) (incf count) (when (= count n) (yield 'generator-stop)))) (when fail-if-short (error 'insufficient-items :format-control \"Insufficient items in generator\")))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun take-as-generator (n generator &key (fail-if-short t)) \"This function has the same meaning as TAKE but returns a generator instead of a list. Eg: (generator->list (take-as-generator 10 (list->generator '(1 2 3)))) -> Signals a condition (generator->list (take-as-generator 10 (list->generator '(1 2 3)) :fail-if-short nil)) -> (1 2 3) (generator->list (take-as-generator 3 (repeat 1))) -> (1 1 1)\" (declare (type (integer 1) n)) (with-yield (let ((count 0)) (do-generator (g generator) (yield g) (incf count) (when (= count n) (yield (quote generator-stop))))) (when fail-if-short (error (quote insufficient-items) :format-control \"Insufficient items in generator\"))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(make-instance* 'class () (apply-form))\n\nProblem: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class () (apply-form))", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(apply (function make-instance) (quote class) (apply-form))", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(compile-$flavor-$methods)\n\nWrite a macro that addresses: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS", "input": "(compile-$flavor-$methods)", "output": "(defmacro COMPILE-$FLAVOR-$METHODS ...)", "macroexpand": "(eval-when (:load-toplevel) (combine-class-methods))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(fail (error \"An expected failure.\"))\n\nIssue: Macro call that should be transformed by fail", "input": "(fail (error \"An expected failure.\"))", "output": "(defmacro fail (form &optional (type 'error) description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(fail ,form ,type)\n :value-form '(capture-error ,form)\n :body (lambda () (capture-error ,form ,(maybe-unquote type)))\n :expected ',(maybe-unquote type)\n :comparison 'typep\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (fail (error \"An expected failure.\") error)) :value-form (quote (capture-error (error \"An expected failure.\"))) :body (lambda nil (capture-error (error \"An expected failure.\") error)) :expected (quote error) :comparison (quote typep)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(disable-version-syntax)\n\nProblem: Macro call that should be transformed by disable-version-syntax", "input": "(disable-version-syntax)", "output": "(defmacro disable-version-syntax ()\n \"Restore readtable which was active before last call to\nENABLE-VERSION-SYNTAX. If there was no such call, the standard\nreadtable is used.\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (%disable-version-syntax)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (%disable-version-syntax))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(sctypecase (car x) (symbol (setf it 'symbol)) (bit (setf it 'bit)))\n\nProblem: Macro call that should be transformed by sctypecase", "input": "(sctypecase (car x) (symbol (setf it 'symbol)) (bit (setf it 'bit)))", "output": "(defmacro sctypecase (keyform &body cases)\n \"Like CTYPECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for\nthe scope of the cases. IT can be set with SETF.\"\n `(symbolic ctypecase ,keyform ,@cases))", "macroexpand": "(symbolic ctypecase (car x) (symbol (setf it (quote symbol))) (bit (setf it (quote bit))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(psetq nil (progn))\n\nPattern to recognize: Macro call that should be transformed by PSETQ", "input": "(psetq nil (progn))", "output": "(defmacro PSETQ ...)", "macroexpand": "(progn (setq nil (progn)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(psetf nil nil)\n\nWhat needs to change: Macro call that should be transformed by PSETF", "input": "(psetf nil nil)", "output": "(defmacro PSETF ...)", "macroexpand": "(progn (setf nil nil) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-fixture-capture function (symbol) (when (and (fboundp symbol) (not (macro-function symbol)) (not (locked-package-p (symbol-package symbol)))) (values (fdefinition symbol) T)))\n\nWhat needs to change: Macro call that should be transformed by define-fixture-capture", "input": "(define-fixture-capture function (symbol) (when (and (fboundp symbol) (not (macro-function symbol)) (not (locked-package-p (symbol-package symbol)))) (values (fdefinition symbol) T)))", "output": "(defmacro define-fixture-capture (name args &body body)\n `(progn (setf (gethash ',name *fixture-captures*)\n (lambda ,args ,@body))\n ',name))", "macroexpand": "(progn (setf (gethash (quote function) *fixture-captures*) (lambda (symbol) (when (and (fboundp symbol) (not (macro-function symbol)) (not (locked-package-p (symbol-package symbol)))) (values (fdefinition symbol) t)))) (quote function))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defobject-amendment nil)\n\nPattern to recognize: Macro call that should be transformed by DEFOBJECT-AMENDMENT", "input": "(defobject-amendment nil)", "output": "(defmacro DEFOBJECT-AMENDMENT ...)", "macroexpand": "(defobject nil\n (standard-object))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(gather-next nil (progn))\n\nProblem: Macro call that should be transformed by GATHER-NEXT", "input": "(gather-next nil (progn))", "output": "(defmacro GATHER-NEXT ...)", "macroexpand": "(common-lisp:funcall nil (progn) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-wrap-attempt () name (let* ((return-type (ensure-type return-type \"function ~S (nee ~S) with return type ~S\" name c-symbol return-type)) (fun (make-instance 'foreign-function :name name :c-symbol c-symbol :type return-type :variadic-p variadic-p))) (setf (foreign-record-fields fun) (loop for param in params collect (make-instance 'foreign-field :name (car param) :type (ensure-type (cadr param) \"function ~S (nee ~S) due to parameter ~S of type ~S\" name c-symbol (car param) (cadr param))))) (setf (gethash name *foreign-functions*) fun)))\n\nProblem: Macro call that should be transformed by with-wrap-attempt", "input": "(with-wrap-attempt () name (let* ((return-type (ensure-type return-type \"function ~S (nee ~S) with return type ~S\" name c-symbol return-type)) (fun (make-instance 'foreign-function :name name :c-symbol c-symbol :type return-type :variadic-p variadic-p))) (setf (foreign-record-fields fun) (loop for param in params collect (make-instance 'foreign-field :name (car param) :type (ensure-type (cadr param) \"function ~S (nee ~S) due to parameter ~S of type ~S\" name c-symbol (car param) (cadr param))))) (setf (gethash name *foreign-functions*) fun)))", "output": "(defmacro with-wrap-attempt ((&optional format-control &rest format-args) wrappable-name &body body)\n `(call-with-wrap-attempt ,wrappable-name (lambda () ,@body) ,format-control (list ,@format-args)))", "macroexpand": "(call-with-wrap-attempt name (lambda nil (let* ((return-type (ensure-type return-type \"function ~S (nee ~S) with return type ~S\" name c-symbol return-type)) (fun (make-instance (quote foreign-function) :name name :c-symbol c-symbol :type return-type :variadic-p variadic-p))) (setf (foreign-record-fields fun) (loop for param in params collect (make-instance (quote foreign-field) :name (car param) :type (ensure-type (cadr param) \"function ~S (nee ~S) due to parameter ~S of type ~S\" name c-symbol (car param) (cadr param))))) (setf (gethash name *foreign-functions*) fun))) nil (list))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(nlet nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by NLET", "input": "(nlet nil\n nil)", "output": "(defmacro NLET ...)", "macroexpand": "(let* ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-unique-names (value coerced-value) `((,name (,value) (let ((,coerced-value (coerce ,value ',type))) (declare (type ,type ,coerced-value)) (when (or ,firstp (> ,coerced-value ,var)) (setq ,var ,coerced-value ,firstp nil))))))\n\nWhat needs to change: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (value coerced-value) `((,name (,value) (let ((,coerced-value (coerce ,value ',type))) (declare (type ,type ,coerced-value)) (when (or ,firstp (> ,coerced-value ,var)) (setq ,var ,coerced-value ,firstp nil))))))", "output": "(defmacro with-unique-names (names &body body)\n `(let ,(mapcar (lambda (sym)\n `(,sym (gensym ,(symbol-name sym))))\n names)\n ,@body))", "macroexpand": "(let ((value (gensym #A((5) base-char . \"VALUE\"))) (coerced-value (gensym #A((14) base-char . \"COERCED-VALUE-\")))) (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (let ((#S(sb-impl::comma :expr coerced-value :kind 0) (coerce #S(sb-impl::comma :expr value :kind 0) (quote #S(sb-impl::comma :expr type :kind 0))))) (declare (type #S(sb-impl::comma :expr type :kind 0) #S(sb-impl::comma :expr coerced-value :kind 0))) (when (or #S(sb-impl::comma :expr firstp :kind 0) (> #S(sb-impl::comma :expr coerced-value :kind 0) #S(sb-impl::comma :expr var :kind 0))) (setq #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr coerced-value :kind 0) #S(sb-impl::comma :expr firstp :kind 0) nil)))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-local-readtable\n nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by WITH-LOCAL-READTABLE", "input": "(with-local-readtable\n nil\n (progn))", "output": "(defmacro WITH-LOCAL-READTABLE ...)", "macroexpand": "(bind ((*readtable* (copy-readtable *readtable*)))\n nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-abstract-class nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-ABSTRACT-CLASS", "input": "(define-abstract-class nil :key nil)", "output": "(defmacro DEFINE-ABSTRACT-CLASS ...)", "macroexpand": "(defclass nil :key nil (:metaclass abstract-class))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(augment finalp-code finalp)\n\nProblem: Macro call that should be transformed by augment", "input": "(augment finalp-code finalp)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf finalp-code (nconc finalp-code finalp))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-value-binding across (var vector &aux (i 0) (length (length vector))) (declare (type vector vector) (type (integer 0) i length)) `(cond ((= ,length ,i) (end-for)) (T (update ,var (aref ,vector ,i)) (incf ,i))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding across (var vector &aux (i 0) (length (length vector))) (declare (type vector vector) (type (integer 0) i length)) `(cond ((= ,length ,i) (end-for)) (T (update ,var (aref ,vector ,i)) (incf ,i))))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding across (var vector) (let ((#:i141 (gensym #A((1) base-char . \"I\"))) (#:length142 (gensym #A((6) base-char . \"LENGTH\"))) (#:vector140 (gensym #A((6) base-char . \"VECTOR\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:vector140 vector) (list #:i141 0) (list #:length142 (list (quote length) #:vector140)) (loop for #:var139 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var139 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:i141 :kind 0) #S(sb-impl::comma :expr #:length142 :kind 0) #S(sb-impl::comma :expr #:vector140 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote vector) :kind 0) #S(sb-impl::comma :expr #:vector140 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote (integer 0)) :kind 0) #S(sb-impl::comma :expr #:i141 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote (integer 0)) :kind 0) #S(sb-impl::comma :expr #:length142 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((i #:i141) (length #:length142) (vector #:vector140)) (declare (ignorable i length vector)) (sb-int:quasiquote (cond ((= #S(sb-impl::comma :expr length :kind 0) #S(sb-impl::comma :expr i :kind 0)) (end-for)) (t (update #S(sb-impl::comma :expr var :kind 0) (aref #S(sb-impl::comma :expr vector :kind 0) #S(sb-impl::comma :expr i :kind 0))) (incf #S(sb-impl::comma :expr i :kind 0)))))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lambda-match ((list* :method args) (make-save-method args)) ((list* :method-combination name options) (setf combination name) (setf combination-options options)))\n\nProblem: Macro call that should be transformed by lambda-match", "input": "(lambda-match ((list* :method args) (make-save-method args)) ((list* :method-combination name options) (setf combination name) (setf combination-options options)))", "output": "(defmacro lambda-match (&body clauses)\n (with-gensyms (args)\n `(lambda (,args)\n (match ,args\n\t ,@clauses))))", "macroexpand": "(lambda (#:args125) (match #:args125 ((list* :method args) (make-save-method args)) ((list* :method-combination name options) (setf combination name) (setf combination-options options))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report 'slow-threshold)))) (when (slot-value report 'description) (format/indent reporter stream (concatenate 'string \"~&\" (report-expected-line report))))) (terpri stream))\n\nWrite a macro that addresses: Macro call that should be transformed by with-color", "input": "(with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report 'slow-threshold)))) (when (slot-value report 'description) (format/indent reporter stream (concatenate 'string \"~&\" (report-expected-line report))))) (terpri stream))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq :red :gray) (eq :red :grey) (eq :red +gray+) (eq :red +grey+)) (with-gray stream (with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report (quote slow-threshold))))) (when (slot-value report (quote description)) (format/indent reporter stream (concatenate (quote string) \"~&\" (report-expected-line report))))) (terpri stream)) (cl-ansi-text:with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report (quote slow-threshold))))) (when (slot-value report (quote description)) (format/indent reporter stream (concatenate (quote string) \"~&\" (report-expected-line report))))) (terpri stream))) (progn (with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report (quote slow-threshold))))) (when (slot-value report (quote description)) (format/indent reporter stream (concatenate (quote string) \"~&\" (report-expected-line report))))) (terpri stream)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(path (gensym \"path\"))\n\nProblem: Macro call that should be transformed by path", "input": "(path (gensym \"path\"))", "output": "(defmacro path (&body cmds)\n (let ((path (gensym \"path\")))\n `(let ((,path (make-path)))\n (with-path ,path\n ,@cmds)\n ,path)))", "macroexpand": "(let ((#:|path140| (make-path))) (with-path #:|path140| (gensym \"path\")) #:|path140|)", "category": "control-flow", "technique": "gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dynamic-let* 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by DYNAMIC-LET*", "input": "(dynamic-let* 'some-name)", "output": "(defmacro DYNAMIC-LET* ...)", "macroexpand": "(dynamic-let (quote)\n (dynamic-let* (some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(inext 'some-name)\n\nProblem: Macro call that should be transformed by INEXT", "input": "(inext 'some-name)", "output": "(defmacro INEXT ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro 'some-name) nil))))\n (if (not vals)\n (coexit!)\n (car vals)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(ps-html)\n\nPattern to recognize: Macro call that should be transformed by PS-HTML", "input": "(ps-html)", "output": "(defmacro PS-HTML ...)", "macroexpand": "(stringify)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield-binds (format nil \"~A~:[~; AFTER ~:*~A~]~:[~; FIRST~]\" (call-next-method) (and (column-modifier-clause-after clause) (yield (column-modifier-clause-after clause))) (column-modifier-clause-first clause)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~A~:[~; AFTER ~:*~A~]~:[~; FIRST~]\" (call-next-method) (and (column-modifier-clause-after clause) (yield (column-modifier-clause-after clause))) (column-modifier-clause-first clause)))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~A~:[~; AFTER ~:*~A~]~:[~; FIRST~]\" (call-next-method) (and (column-modifier-clause-after clause) (yield (column-modifier-clause-after clause))) (column-modifier-clause-first clause))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-unique-names (value coerced-value) `((,name (,value) (let ((,coerced-value (coerce ,value ',type))) (declare (type ,type ,coerced-value)) (when (or ,firstp (< ,coerced-value ,var)) (setq ,var ,coerced-value ,firstp nil))))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (value coerced-value) `((,name (,value) (let ((,coerced-value (coerce ,value ',type))) (declare (type ,type ,coerced-value)) (when (or ,firstp (< ,coerced-value ,var)) (setq ,var ,coerced-value ,firstp nil))))))", "output": "(defmacro with-unique-names (names &body body)\n `(let ,(mapcar (lambda (sym)\n `(,sym (gensym ,(symbol-name sym))))\n names)\n ,@body))", "macroexpand": "(let ((value (gensym #A((5) base-char . \"VALUE\"))) (coerced-value (gensym #A((14) base-char . \"COERCED-VALUE-\")))) (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (let ((#S(sb-impl::comma :expr coerced-value :kind 0) (coerce #S(sb-impl::comma :expr value :kind 0) (quote #S(sb-impl::comma :expr type :kind 0))))) (declare (type #S(sb-impl::comma :expr type :kind 0) #S(sb-impl::comma :expr coerced-value :kind 0))) (when (or #S(sb-impl::comma :expr firstp :kind 0) (< #S(sb-impl::comma :expr coerced-value :kind 0) #S(sb-impl::comma :expr var :kind 0))) (setq #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr coerced-value :kind 0) #S(sb-impl::comma :expr firstp :kind 0) nil)))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-gensyms (parent-type term type string current-mode position position-foobage mode-wait new-position advance) `(let ((,parent-type (or (find-coloring-type ,parent) (and ,parent (error \"No such coloring type: ~S\" ,parent))))) (setf (find-coloring-type ,name) (make-instance 'coloring-type :fancy-name ',fancy-name :modes (append ',modes (if ,parent-type (coloring-type-modes ,parent-type))) :default-mode (or ',default-mode (if ,parent-type (coloring-type-default-mode ,parent-type))) ,@(if autodetect `(:autodetect-function ,autodetect)) :parent-type ,parent-type :visible (not ,invisible) :formatter-initial-values (lambda nil (list* ,@(mapcar #'(lambda (e) `(cons ',(car e) ,(second e))) formatter-variables) (if ,parent-type (funcall (coloring-type-formatter-initial-values ,parent-type)) nil))) :formatter-after-hook (lambda nil (symbol-macrolet ,(mapcar #'(lambda (e) `(,(car e) (cdr (assoc ',(car e) *formatter-local-variables*)))) formatter-variables) (concatenate 'string (funcall ,formatter-after-hook) (if ,parent-type (funcall (coloring-type-formatter-after-hook ,parent-type)) \"\")))) :term-formatter (symbol-macrolet ,(mapcar #'(lambda (e) `(,(car e) (cdr (assoc ',(car e) *formatter-local-variables*)))) formatter-variables) (lambda (,term) (labels ((call-parent-formatter (&optional (,type (car ,term)) (,string (cdr ,term))) (if ,parent-type (funcall (coloring-type-term-formatter ,parent-type) (cons ,type ,string)))) (call-formatter (&optional (,type (car ,term)) (,string (cdr ,term))) (funcall (case (first ,type) ,@formatters (t (lambda (,type text) (call-parent-formatter ,type text)))) ,type ,string))) (call-formatter)))) :transition-functions (list ,@(loop for transition in transitions collect (destructuring-bind (mode &rest table) transition `(cons ',mode (lambda (,current-mode ,string ,position) (let ((,mode-wait (constantly nil)) (,position-foobage ,position)) (with-scanning-functions ,string ,position-foobage ,current-mode ,mode-wait (let ((*reset-position* ,position)) (cond ,@table)) (values ,position-foobage ,current-mode (lambda (,new-position) (setf ,position-foobage ,new-position) (let ((,advance (nth-value 1 (funcall ,mode-wait ,position-foobage)))) (values ,position-foobage ,advance))))) ))))))))))\n\nWhat needs to change: Macro call that should be transformed by with-gensyms", "input": "(with-gensyms (parent-type term type string current-mode position position-foobage mode-wait new-position advance) `(let ((,parent-type (or (find-coloring-type ,parent) (and ,parent (error \"No such coloring type: ~S\" ,parent))))) (setf (find-coloring-type ,name) (make-instance 'coloring-type :fancy-name ',fancy-name :modes (append ',modes (if ,parent-type (coloring-type-modes ,parent-type))) :default-mode (or ',default-mode (if ,parent-type (coloring-type-default-mode ,parent-type))) ,@(if autodetect `(:autodetect-function ,autodetect)) :parent-type ,parent-type :visible (not ,invisible) :formatter-initial-values (lambda nil (list* ,@(mapcar #'(lambda (e) `(cons ',(car e) ,(second e))) formatter-variables) (if ,parent-type (funcall (coloring-type-formatter-initial-values ,parent-type)) nil))) :formatter-after-hook (lambda nil (symbol-macrolet ,(mapcar #'(lambda (e) `(,(car e) (cdr (assoc ',(car e) *formatter-local-variables*)))) formatter-variables) (concatenate 'string (funcall ,formatter-after-hook) (if ,parent-type (funcall (coloring-type-formatter-after-hook ,parent-type)) \"\")))) :term-formatter (symbol-macrolet ,(mapcar #'(lambda (e) `(,(car e) (cdr (assoc ',(car e) *formatter-local-variables*)))) formatter-variables) (lambda (,term) (labels ((call-parent-formatter (&optional (,type (car ,term)) (,string (cdr ,term))) (if ,parent-type (funcall (coloring-type-term-formatter ,parent-type) (cons ,type ,string)))) (call-formatter (&optional (,type (car ,term)) (,string (cdr ,term))) (funcall (case (first ,type) ,@formatters (t (lambda (,type text) (call-parent-formatter ,type text)))) ,type ,string))) (call-formatter)))) :transition-functions (list ,@(loop for transition in transitions collect (destructuring-bind (mode &rest table) transition `(cons ',mode (lambda (,current-mode ,string ,position) (let ((,mode-wait (constantly nil)) (,position-foobage ,position)) (with-scanning-functions ,string ,position-foobage ,current-mode ,mode-wait (let ((*reset-position* ,position)) (cond ,@table)) (values ,position-foobage ,current-mode (lambda (,new-position) (setf ,position-foobage ,new-position) (let ((,advance (nth-value 1 (funcall ,mode-wait ,position-foobage)))) (values ,position-foobage ,advance))))) ))))))))))", "output": "(defmacro with-gensyms ((&rest names) &body body)\n `(let ,(mapcar #'(lambda (name)\n (list name `(make-symbol ,(symbol-name name)))) names)\n ,@body))", "macroexpand": "(let ((parent-type (gensym #A((11) base-char . \"PARENT-TYPE\"))) (term (gensym #A((4) base-char . \"TERM\"))) (type (gensym #A((4) base-char . \"TYPE\"))) (string (gensym #A((6) base-char . \"STRING\"))) (current-mode (gensym #A((12) base-char . \"CURRENT-MODE\"))) (position (gensym #A((8) base-char . \"POSITION\"))) (position-foobage (gensym #A((16) base-char . \"POSITION-FOOBAGE\"))) (mode-wait (gensym #A((9) base-char . \"MODE-WAIT\"))) (new-position (gensym #A((12) base-char . \"NEW-POSITION\"))) (advance (gensym #A((7) base-char . \"ADVANCE\")))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr parent-type :kind 0) (or (find-coloring-type #S(sb-impl::comma :expr parent :kind 0)) (and #S(sb-impl::comma :expr parent :kind 0) (error \"No such coloring type: ~S\" #S(sb-impl::comma :expr parent :kind 0)))))) (setf (find-coloring-type #S(sb-impl::comma :expr name :kind 0)) (make-instance (quote coloring-type) :fancy-name (quote #S(sb-impl::comma :expr fancy-name :kind 0)) :modes (append (quote #S(sb-impl::comma :expr modes :kind 0)) (if #S(sb-impl::comma :expr parent-type :kind 0) (coloring-type-modes #S(sb-impl::comma :expr parent-type :kind 0)))) :default-mode (or (quote #S(sb-impl::comma :expr default-mode :kind 0)) (if #S(sb-impl::comma :expr parent-type :kind 0) (coloring-type-default-mode #S(sb-impl::comma :expr parent-type :kind 0)))) #S(sb-impl::comma :expr (if autodetect (sb-int:quasiquote (:autodetect-function #S(sb-impl::comma :expr autodetect :kind 0)))) :kind 2) :parent-type #S(sb-impl::comma :expr parent-type :kind 0) :visible (not #S(sb-impl::comma :expr invisible :kind 0)) :formatter-initial-values (lambda nil (list* #S(sb-impl::comma :expr (mapcar (function (lambda (e) (sb-int:quasiquote (cons (quote #S(sb-impl::comma :expr (car e) :kind 0)) #S(sb-impl::comma :expr (second e) :kind 0))))) formatter-variables) :kind 2) (if #S(sb-impl::comma :expr parent-type :kind 0) (funcall (coloring-type-formatter-initial-values #S(sb-impl::comma :expr parent-type :kind 0))) nil))) :formatter-after-hook (lambda nil (symbol-macrolet #S(sb-impl::comma :expr (mapcar (function (lambda (e) (sb-int:quasiquote (#S(sb-impl::comma :expr (car e) :kind 0) (cdr (assoc (quote #S(sb-impl::comma :expr (car e) :kind 0)) *formatter-local-variables*)))))) formatter-variables) :kind 0) (concatenate (quote string) (funcall #S(sb-impl::comma :expr formatter-after-hook :kind 0)) (if #S(sb-impl::comma :expr parent-type :kind 0) (funcall (coloring-type-formatter-after-hook #S(sb-impl::comma :expr parent-type :kind 0))) \"\")))) :term-formatter (symbol-macrolet #S(sb-impl::comma :expr (mapcar (function (lambda (e) (sb-int:quasiquote (#S(sb-impl::comma :expr (car e) :kind 0) (cdr (assoc (quote #S(sb-impl::comma :expr (car e) :kind 0)) *formatter-local-variables*)))))) formatter-variables) :kind 0) (lambda (#S(sb-impl::comma :expr term :kind 0)) (labels ((call-parent-formatter (&optional (#S(sb-impl::comma :expr type :kind 0) (car #S(sb-impl::comma :expr term :kind 0))) (#S(sb-impl::comma :expr string :kind 0) (cdr #S(sb-impl::comma :expr term :kind 0)))) (if #S(sb-impl::comma :expr parent-type :kind 0) (funcall (coloring-type-term-formatter #S(sb-impl::comma :expr parent-type :kind 0)) (cons #S(sb-impl::comma :expr type :kind 0) #S(sb-impl::comma :expr string :kind 0))))) (call-formatter (&optional (#S(sb-impl::comma :expr type :kind 0) (car #S(sb-impl::comma :expr term :kind 0))) (#S(sb-impl::comma :expr string :kind 0) (cdr #S(sb-impl::comma :expr term :kind 0)))) (funcall (case (first #S(sb-impl::comma :expr type :kind 0)) #S(sb-impl::comma :expr formatters :kind 2) (t (lambda (#S(sb-impl::comma :expr type :kind 0) text) (call-parent-formatter #S(sb-impl::comma :expr type :kind 0) text)))) #S(sb-impl::comma :expr type :kind 0) #S(sb-impl::comma :expr string :kind 0)))) (call-formatter)))) :transition-functions (list #S(sb-impl::comma :expr (loop for transition in transitions collect (destructuring-bind (mode &rest table) transition (sb-int:quasiquote (cons (quote #S(sb-impl::comma :expr mode :kind 0)) (lambda (#S(sb-impl::comma :expr current-mode :kind 0) #S(sb-impl::comma :expr string :kind 0) #S(sb-impl::comma :expr position :kind 0)) (let ((#S(sb-impl::comma :expr mode-wait :kind 0) (constantly nil)) (#S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr position :kind 0))) (with-scanning-functions #S(sb-impl::comma :expr string :kind 0) #S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr current-mode :kind 0) #S(sb-impl::comma :expr mode-wait :kind 0) (let ((*reset-position* #S(sb-impl::comma :expr position :kind 0))) (cond #S(sb-impl::comma :expr table :kind 2))) (values #S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr current-mode :kind 0) (lambda (#S(sb-impl::comma :expr new-position :kind 0)) (setf #S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr new-position :kind 0)) (let ((#S(sb-impl::comma :expr advance :kind 0) (nth-value 1 (funcall #S(sb-impl::comma :expr mode-wait :kind 0) #S(sb-impl::comma :expr position-foobage :kind 0))))) (values #S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr advance :kind 0)))))))))))) :kind 2)))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(or)\n\nWrite a macro that addresses: Macro call that should be transformed by OR", "input": "(or)", "output": "(defmacro OR ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-shell-component ditaa :input-type \"ditaa\" :output-type \"png\" :shell-command \"ditaa\")\n\nPattern to recognize: Macro call that should be transformed by define-shell-component", "input": "(define-shell-component ditaa :input-type \"ditaa\" :output-type \"png\" :shell-command \"ditaa\")", "output": "(defmacro define-shell-component (name &key input-type output-type shell-command)\n \"Define an ASDF component that's compiled by running a shell command.\"\n `(define-component ,name\n :input-type ,input-type\n :output-type ,output-type\n :compile-function (lambda (input-pathname output-pathname)\n (inferior-shell:run (list ,@(ensure-list shell-command)\n input-pathname\n output-pathname)\n :show t))))", "macroexpand": "(define-component ditaa :input-type \"ditaa\" :output-type \"png\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run (list \"ditaa\" input-pathname output-pathname) :show t)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(signal-syntax-error* (+ open-paren-pos 2) \"Opening paren has no matching closing paren.\")\n\nPattern to recognize: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (+ open-paren-pos 2) \"Opening paren has no matching closing paren.\")", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos (+ open-paren-pos 2) :format-control \"Opening paren has no matching closing paren.\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(use-syntax nil)\n\nWhat needs to change: Macro call that should be transformed by USE-SYNTAX", "input": "(use-syntax nil)", "output": "(defmacro use-syntax (name)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (%use-syntax ,name)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (%use-syntax nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-mustache-character #\\& (make-instance 'ampersand-tag :text arg-text))\n\nProblem: Macro call that should be transformed by define", "input": "(define-mustache-character #\\& (make-instance 'ampersand-tag :text arg-text))", "output": "(defmacro define (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "macroexpand": "(set-mustache-character #\\AMPERSAND (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote ampersand-tag) :text arg-text)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-definition-resolver function designator-function-p)\n\nPattern to recognize: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver function designator-function-p)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver function (function #:package133) (when (ignore-errors (designator-function-p function)) (list (make-instance (quote function) :designator function :package #:package133))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lambda* nil)\n\nIssue: Macro call that should be transformed by LAMBDA*", "input": "(lambda* nil)", "output": "(defmacro LAMBDA* ...)", "macroexpand": "(lambda () (with-yield))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'make-vector-accumulator :array-element #'vector-accumulator-add :end-of-array #'vector-accumulator-get-sequence :beginning-of-object #'make-accumulator-with-prototype :object-key #'accumulator-add-key-or-set-prototype :object-value #'accumulator-add-value-or-set-prototype :end-of-object #'accumulator-get-object :beginning-of-string #'make-vector-accumulator :string-char #'vector-accumulator-add :end-of-string #'vector-accumulator-get-string)\n\nIssue: Macro call that should be transformed by set-custom-vars", "input": "(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'make-vector-accumulator :array-element #'vector-accumulator-add :end-of-array #'vector-accumulator-get-sequence :beginning-of-object #'make-accumulator-with-prototype :object-key #'accumulator-add-key-or-set-prototype :object-value #'accumulator-add-value-or-set-prototype :end-of-object #'accumulator-get-object :beginning-of-string #'make-vector-accumulator :string-char #'vector-accumulator-add :end-of-string #'vector-accumulator-get-string)", "output": "(defmacro set-custom-vars (&rest key-args)\n `(setq\n ,@(loop for (supplied-key value) on key-args by #'cddr\n append (loop for (var . var-key) in *custom-vars*\n thereis (if (eql var-key supplied-key)\n (list var value))))))", "macroexpand": "(setq *integer-handler* (function parse-number) *real-handler* (function parse-number) *boolean-handler* (function json-boolean-to-lisp) *beginning-of-array-handler* (function make-vector-accumulator) *end-of-array-handler* (function vector-accumulator-get-sequence) *beginning-of-object-handler* (function make-accumulator-with-prototype) *object-key-handler* (function accumulator-add-key-or-set-prototype) *object-value-handler* (function accumulator-add-value-or-set-prototype) *end-of-object-handler* (function accumulator-get-object) *beginning-of-string-handler* (function make-vector-accumulator) *string-char-handler* (function vector-accumulator-add) *end-of-string-handler* (function vector-accumulator-get-string))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-library compression-lib)\n\nProblem: Macro call that should be transformed by define-library", "input": "(define-library compression-lib)", "output": "(defmacro define-library (name &body initargs)\n #+cffi\n `(change-class (cffi::get-foreign-library ',name)\n 'library\n ,@initargs)\n #-cffi\n `(make-instance 'library ,@initargs))", "macroexpand": "(change-class (cffi::get-foreign-library (quote compression-lib)) (quote library))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-simple-type-map function cl:function)\n\nProblem: Macro call that should be transformed by define-simple-type-map", "input": "(define-simple-type-map function cl:function)", "output": "(defmacro define-simple-type-map (class type)\n `(defmethod type ((,class ,class))\n ',type))", "macroexpand": "(defmethod type ((function function)) (quote common-lisp:function))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*> +comma+ +consume-space+)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> +comma+ +consume-space+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset172) (multiple-value-bind (#:*>-res173 #:*>-next174) (funcall +comma+ #:*>-offset172) (if (ok? #:*>-res173) (funcall +consume-space+ #:*>-next174) (fail #:*>-next174))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(matrix-case nil)\n\nWhat needs to change: Macro call that should be transformed by MATRIX-CASE", "input": "(matrix-case nil)", "output": "(defmacro MATRIX-CASE ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-inactive-layers nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-INACTIVE-LAYERS", "input": "(with-inactive-layers nil\n :key\n nil)", "output": "(defmacro WITH-INACTIVE-LAYERS ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-wcs-math-error-handling (ret (log1+ x)) (check-wcs-math-result))\n\nIssue: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (log1+ x)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g227 x) (#:g228 nil) (#:g229 (list #:g227))) (declare (ignorable #:g228) (type list #:g229) (dynamic-extent #:g229)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote log1+) #:g229) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g229)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-table node hash depth (bitmap array bits index hit) (when hit (%hamt-lookup (aref array index) key hash (1+ depth) test)))\n\nIssue: Macro call that should be transformed by with-table", "input": "(with-table node hash depth (bitmap array bits index hit) (when hit (%hamt-lookup (aref array index) key hash (1+ depth) test)))", "output": "(defmacro with-table (node hash depth\n (bitmap array bits index hit)\n &body body)\n \"Bitshifting in HAMT tables\"\n `(let* ((,bitmap (table-bitmap ,node))\n (,array (table-array ,node))\n (,bits (get-bits ,hash ,depth))\n (,index (get-index ,bits ,bitmap))\n (,hit (logbitp ,bits ,bitmap)))\n ,@body))", "macroexpand": "(let* ((bitmap (table-bitmap node)) (array (table-array node)) (bits (get-bits hash depth)) (index (get-index bits bitmap)) (hit (logbitp bits bitmap))) (when hit (%hamt-lookup (aref array index) key hash (1+ depth) test)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(receive x (values) x)\n\nIssue: Macro call that should be transformed by receive", "input": "(receive x (values) x)", "output": "(defmacro receive (formals expr &body body)\n \"Stricter version of `multiple-value-bind'.\n\nUse `receive' when you want to enforce that EXPR should return a\ncertain number of values, or a minimum number of values.\n\nIf FORMALS is a proper list, then EXPR must return exactly as many\nvalues -- no more and no less -- as there are variables in FORMALS.\n\nIf FORMALS is an improper list (VARS . REST), then EXPR must return at\nleast as many values as there are VARS, and any further values are\nbound, as a list, to REST.\n\nLastly, if FORMALS is a symbol, bind that symbol to all the values\nreturned by EXPR, as if by `multiple-value-list'.\n\nFrom Scheme (SRFI-8).\"\n ;; It's probably not worth stack-allocating the thunk.\n (cond ((null formals)\n `(multiple-value-call\n (lambda ()\n ,@body)\n ,expr))\n ((atom formals)\n ;; This could also be written:\n #+(or) `(let ((,formals (multiple-value-list ,expr)))\n ,@body)\n ;; But I want it to be possible to declare FORMALS to have\n ;; dynamic extent, and most Lisps support that for &rest\n ;; lists.\n `(multiple-value-call\n (lambda (&rest ,formals)\n ,@body)\n ,expr))\n ((proper-list-p formals)\n (when (intersection formals lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda ,formals\n ,@body)\n ,expr))\n (t (let* ((last (last formals))\n (vars (append (butlast formals)\n (list (car last))))\n (rest (cdr last)))\n (when (intersection (cons rest vars) lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda (,@vars &rest ,rest)\n ,@body)\n ,expr)))))", "macroexpand": "(multiple-value-call (lambda (&rest x) x) (values))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(yield-all (flatten (car list)))\n\nProblem: Macro call that should be transformed by yield-all", "input": "(yield-all (flatten (car list)))", "output": "(defmacro yield-all (generator)\n \"Walks through generator, re-yielding all of the items in it. Only meant for use inside of a defgenerator or with-yield block.\"\n (let ((x (gensym)))\n `(do-generator (,x ,generator)\n (yield ,x))))", "macroexpand": "(do-generator (#:g184 (flatten (car list))) (yield #:g184))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.8125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-color ((cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (T :gray)) :stream stream) (format stream (if (error-report-p report) \"x\" \".\")))\n\nPattern to recognize: Macro call that should be transformed by with-color", "input": "(with-color ((cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (T :gray)) :stream stream) (format stream (if (error-report-p report) \"x\" \".\")))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq (cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) :gray) (eq (cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) :grey) (eq (cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) +gray+) (eq (cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) +grey+)) (with-gray stream (format stream (if (error-report-p report) \"x\" \".\"))) (cl-ansi-text:with-color ((cond ((failed-report-p report) :red) ((skipped-report-p report) :cyan) (t :gray)) :stream stream) (format stream (if (error-report-p report) \"x\" \".\")))) (progn (format stream (if (error-report-p report) \"x\" \".\"))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (= 1 a))\n\nIssue: Macro call that should be transformed by is", "input": "(is (= 1 a))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e265 1) (#:a266 a)) (if (progn (= #:e265 #:a266)) (add-result (quote test-passed) :test-expr (quote (= 1 a))) (process-failure (quote (= 1 a)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote a) #:a266 (quote =) #:e265)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield-binds (format nil \"(~{~A~^ ~})\" (mapcar #'yield (sql-expression-list-elements list))))\n\nWhat needs to change: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"(~{~A~^ ~})\" (mapcar #'yield (sql-expression-list-elements list))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"(~{~A~^ ~})\" (mapcar (function yield) (sql-expression-list-elements list)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(mvlet nil\n (progn))\n\nProblem: Macro call that should be transformed by MVLET", "input": "(mvlet nil\n (progn))", "output": "(defmacro MVLET ...)", "macroexpand": "(progn (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-direct-clause repeat (n) (let ((limit (gensym \"LIMIT\")) (counter (gensym \"COUNTER\"))) (values `(let ((,limit ,n) (,counter 0))) `(when (<= ,limit (incf ,counter)) (end-for)))))\n\nPattern to recognize: Macro call that should be transformed by define-direct-clause", "input": "(define-direct-clause repeat (n) (let ((limit (gensym \"LIMIT\")) (counter (gensym \"COUNTER\"))) (values `(let ((,limit ,n) (,counter 0))) `(when (<= ,limit (incf ,counter)) (end-for)))))", "output": "(defmacro define-direct-clause (name args &body body)\n (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym \"ENVIRONMENT\"))))\n `(progn (setf (clause ',name)\n (lambda ,(lambda-fiddle:remove-environment-part args)\n (let ((,env *environment*))\n (declare (ignorable ,env))\n ,@body)))\n ',name)))", "macroexpand": "(progn (setf (clause (quote repeat)) (lambda (n) (let ((#:environment183 *environment*)) (declare (ignorable #:environment183)) (let ((limit (gensym \"LIMIT\")) (counter (gensym \"COUNTER\"))) (values (sb-int:quasiquote (let ((#S(sb-impl::comma :expr limit :kind 0) #S(sb-impl::comma :expr n :kind 0)) (#S(sb-impl::comma :expr counter :kind 0) 0)))) (sb-int:quasiquote (when (<= #S(sb-impl::comma :expr limit :kind 0) (incf #S(sb-impl::comma :expr counter :kind 0))) (end-for)))))))) (quote repeat))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(bind (((:structure metabang-bind-test-1- (my-a a) c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list c my-a))\n\nIssue: Macro call that should be transformed by bind", "input": "(bind (((:structure metabang-bind-test-1- (my-a a) c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list c my-a))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-191| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (my-a (metabang-bind-test-1-a #:|values-191|)) (c (metabang-bind-test-1-c #:|values-191|))) (declare (ignorable #:|values-191|)) (progn (list c my-a)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"22021\" invalid-byte-sequence data-exception)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"22021\" invalid-byte-sequence data-exception)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition invalid-byte-sequence (data-exception) nil) (setf (gethash \"22021\" *error-table*) (quote invalid-byte-sequence)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-prepared-query query (conn \"SELECT last_insert_id() AS last_insert_id\") (or (first (dbi:fetch (dbi:execute query) :format :values)) 0))\n\nIssue: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (conn \"SELECT last_insert_id() AS last_insert_id\") (or (first (dbi:fetch (dbi:execute query) :format :values)) 0))", "output": "(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)\n `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))", "macroexpand": "(call-with-prepared-query conn \"SELECT last_insert_id() AS last_insert_id\" (lambda (query) (or (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)) 0)) :use-prepare-cached nil)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(->> (v) (flow-gen v))\n\nProblem: Macro call that should be transformed by ->>", "input": "(->> (v) (flow-gen v))", "output": "(defmacro ->> (lambda-list &body body)\n \"See flow:dynamically\"\n `(dynamically ,lambda-list\n ,@body))", "macroexpand": "(dynamically (v) (flow-gen v))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defvar nil nil)\n\nIssue: Macro call that should be transformed by DEFVAR", "input": "(defvar nil nil)", "output": "(defmacro DEFVAR ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel) (sb-impl::%compiler-defvar 'nil))\n (sb-impl::%defvar 'nil (sb-c:source-location) 'nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-bug name-clash (:error-type varjo-critical-error) (lisp glsl) \"The glsl name ~s was generated for the lisp-name ~s However this name was already taken. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience\" glsl lisp)\n\nIssue: Macro call that should be transformed by define-bug", "input": "(define-bug name-clash (:error-type varjo-critical-error) (lisp glsl) \"The glsl name ~s was generated for the lisp-name ~s However this name was already taken. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience\" glsl lisp)", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition name-clash (:error-type varjo-critical-error :prefix \"Varjo Bug\") (lisp glsl) \"The glsl name ~s was generated for the lisp-name ~s However this name was already taken. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience\" glsl lisp)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(mvlet nil)\n\nPattern to recognize: Macro call that should be transformed by MVLET", "input": "(mvlet nil)", "output": "(defmacro MVLET ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-preprocessor-state-slots (state) (push if-section-obj if-section-stack) (when (and (null if-section-skip-reason) (not eval-result)) (setf if-section-skip-reason if-section-obj)))\n\nPattern to recognize: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (push if-section-obj if-section-stack) (when (and (null if-section-skip-reason) (not eval-result)) (setf if-section-skip-reason if-section-obj)))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (push if-section-obj if-section-stack) (when (and (null if-section-skip-reason) (not eval-result)) (setf if-section-skip-reason if-section-obj)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ensure-gethash x table 13)\n\nWhat needs to change: Macro call that should be transformed by ensure-gethash", "input": "(ensure-gethash x table 13)", "output": "(defmacro ensure-gethash (key hash-table &optional default)\n \"Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT\nunder key before returning it. Secondary return value is true if key was\nalready in the table.\"\n (once-only (key hash-table)\n (with-unique-names (value presentp)\n `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table)\n (if ,presentp\n (values ,value ,presentp)\n (values (setf (gethash ,key ,hash-table) ,default) nil))))))", "macroexpand": "(let ((#:n-key-163 x) (#:n-hash-table-164 table)) (multiple-value-bind (#:value165 #:foundp166) (gethash #:n-key-163 #:n-hash-table-164) (if #:foundp166 (values #:value165 t) (values (setf (gethash #:n-key-163 #:n-hash-table-164) 13) nil))))", "category": "anaphoric", "technique": "once-only,anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-mustache-character #\\^ (make-instance 'section-start-tag :text arg-text :end end :falsey t))\n\nProblem: Macro call that should be transformed by define", "input": "(define-mustache-character #\\^ (make-instance 'section-start-tag :text arg-text :end end :falsey t))", "output": "(defmacro define (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "macroexpand": "(set-mustache-character #\\CIRCUMFLEX_ACCENT (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-start-tag) :text arg-text :end end :falsey t)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-c-syntax-reader-for-each-case-mode c-reader-level-1)\n\nPattern to recognize: Macro call that should be transformed by define-c-syntax-reader-for-each-case-mode", "input": "(define-c-syntax-reader-for-each-case-mode c-reader-level-1)", "output": "(defmacro define-c-syntax-reader-for-each-case-mode (base-readtable-name)\n (check-type base-readtable-name symbol)\n (loop with case-modes = '(:upcase :downcase :preserve :invert)\n for mode in case-modes\n as name = (format-symbol :with-c-syntax.core \"~A-~A\" base-readtable-name mode)\n collect `(defreadtable ,name\n (:merge ,base-readtable-name)\n (:case ,mode))\n into bodies\n finally\n (return `(progn ,@bodies))))", "macroexpand": "(progn (defreadtable c-reader-level-1-upcase (:merge c-reader-level-1) (:case :upcase)) (defreadtable c-reader-level-1-downcase (:merge c-reader-level-1) (:case :downcase)) (defreadtable c-reader-level-1-preserve (:merge c-reader-level-1) (:case :preserve)) (defreadtable c-reader-level-1-invert (:merge c-reader-level-1) (:case :invert)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(flet* nil\n nil)\n\nProblem: Macro call that should be transformed by FLET*", "input": "(flet* nil\n nil)", "output": "(defmacro FLET* ...)", "macroexpand": "(flet ()\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause list-tails (&whole form list &key (by '(function cdr)) &environment env) \"Loops over the successive tails of a list, checking for the end of the list as if by ATOM. Can perform destructuring.\" (if (symbolp *iteration-variable*) (let ((g (gensym))) (list (make-simple-iteration :var *iteration-variable* :init list :step `(funcall ,by ,*iteration-variable*)) (make-simple-iteration :var g :init nil :step nil :precondition `(not (atom ,*iteration-variable*))))) (expand-with-simple-destructuring form env)))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause list-tails (&whole form list &key (by '(function cdr)) &environment env) \"Loops over the successive tails of a list, checking for the end of the list as if by ATOM. Can perform destructuring.\" (if (symbolp *iteration-variable*) (let ((g (gensym))) (list (make-simple-iteration :var *iteration-variable* :init list :step `(funcall ,by ,*iteration-variable*)) (make-simple-iteration :var g :init nil :step nil :precondition `(not (atom ,*iteration-variable*))))) (expand-with-simple-destructuring form env)))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro list-tails (&whole form list &key (by (quote (function cdr))) &environment env) \"Loops over the successive tails of a list, checking for the end of the list as if by ATOM. Can perform destructuring.\" (if (symbolp *iteration-variable*) (let ((g (gensym))) (list (make-simple-iteration :var *iteration-variable* :init list :step (sb-int:quasiquote (funcall #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr *iteration-variable* :kind 0)))) (make-simple-iteration :var g :init nil :step nil :precondition (sb-int:quasiquote (not (atom #S(sb-impl::comma :expr *iteration-variable* :kind 0))))))) (expand-with-simple-destructuring form env))) (pushnew (quote list-tails) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (= 2 (length (remove-if-not #'test-passed-p results))))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (= 2 (length (remove-if-not #'test-passed-p results))))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e238 2) (#:a239 (length (remove-if-not (function test-passed-p) results)))) (if (progn (= #:e238 #:a239)) (add-result (quote test-passed) :test-expr (quote (= 2 (length (remove-if-not (function test-passed-p) results))))) (process-failure (quote (= 2 (length (remove-if-not (function test-passed-p) results)))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (length (remove-if-not (function test-passed-p) results))) #:a239 (quote =) #:e238)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(match list ((list x) (if (oddp x) x (fail))))\n\nPattern to recognize: Macro call that should be transformed by match", "input": "(match list ((list x) (if (oddp x) x (fail))))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(%or (%if (consp list) (let ((#:g144 (car list)) (#:g145 (cdr list))) (declare (ignorable #:g144 #:g145)) (%if (%equals #:g145 nil) (%or (let ((x #:g144)) (if (oddp x) x (fail))) (fail)) (fail))) (fail)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(->> nil)\n\nProblem: Macro call that should be transformed by ->>", "input": "(->> nil)", "output": "(defmacro ->> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(dict-of nil (progn))\n\nPattern to recognize: Macro call that should be transformed by DICT-OF", "input": "(dict-of nil (progn))", "output": "(defmacro DICT-OF ...)", "macroexpand": "(let ((#:dict128 (make-hash-table :test 'equal)))\n (do-for ((progn))\n (multiple-value-call\n (lambda (#:k129 #:v130) (setf (gethash #:k129 #:dict128) #:v130))\n nil))\n #:dict128)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-properties nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-PROPERTIES", "input": "(with-properties nil\n :key\n nil)", "output": "(defmacro WITH-PROPERTIES ...)", "macroexpand": "(let ((#:g135 :key))\n (symbol-macrolet ()\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defprotocol nil)\n\nWhat needs to change: Macro call that should be transformed by DEFPROTOCOL", "input": "(defprotocol nil)", "output": "(defmacro DEFPROTOCOL ...)", "macroexpand": "(progn\n (progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (%build-protocol-object (%ensure-protocol-compilation-note 'nil) 'nil)\n (defun nil-p (object)\n #A((29) base-char . \"test if object implements NIL\")\n (implements-protocol? object (ensure-protocol 'nil)))\n (deftype nil () nil '(satisfies nil-p)))\n (let ((#:g131 (ensure-protocol 'nil)))\n (%build-protocol-object #:g131 'nil)\n (setf (protocol-includes-generic-pun #:g131) nil\n (protocol-includes-method-pun #:g131) nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-custom-var (:object-key *object-key-handler*) (constantly t) \"Designator for a function of 1 string argument (decoded member key of Object).\")\n\nWrite a macro that addresses: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:object-key *object-key-handler*) (constantly t) \"Designator for a function of 1 string argument (decoded member key of Object).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*object-key-handler* . :object-key)) *custom-vars* :test (function equal)) (defvar *object-key-handler* (constantly t) \"Designator for a function of 1 string argument (decoded member key of Object).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(dlet* nil)\n\nPattern to recognize: Macro call that should be transformed by DLET*", "input": "(dlet* nil)", "output": "(defmacro DLET* ...)", "macroexpand": "(dynamic-let* nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(make-instance* 'class (a b c))\n\nProblem: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class (a b c))", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(apply (function make-instance) (quote class) (a b c))", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-all-namespaces 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DO-ALL-NAMESPACES", "input": "(do-all-namespaces 'some-name)", "output": "(defmacro DO-ALL-NAMESPACES ...)", "macroexpand": "(do-namespace (namespace _ quote some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> (from :users) (when include-inactive (where (:= :active 0))) (when sort-by-date (order-by :created_at)))\n\nIssue: Macro call that should be transformed by ->", "input": "(-> (from :users) (when include-inactive (where (:= :active 0))) (when sort-by-date (order-by :created_at)))", "output": "(defmacro -> (value &rest forms)\n \"Smart threading macro that dispatches based on clause types returned by forms.\n\n This macro enables immutable query composition by threading clauses through\n query-state objects. Creates a single copy at the beginning, then destructively\n adds clauses for efficiency. Supports both v1 select-statements and composer query-states.\n\n Forms that evaluate to NIL are skipped, enabling conditional composition:\n (-> (from :users)\n (when active-only (where (:= :active 1)))\n (when sort-by-name (order-by :name)))\n\n Examples:\n ;; With composer clause\n (-> (from :users)\n (where (:= :active 1))\n (order-by :name))\n\n ;; With v1 select-statement (backward compatible)\n (-> (select (:id :name) (from :users))\n (where (:= :active 1))\n (order-by :name))\n\n ;; Conditional composition\n (-> (from :users)\n (when include-inactive (where (:= :active 0)))\n (when sort-by-date (order-by :created_at)))\"\n (a:with-gensyms (threaded-var clause-var)\n `(let* ((,threaded-var ,value)\n ;; Convert to query-state and copy once at the beginning\n (,threaded-var\n (typecase ,threaded-var\n (query-state-base (copy-query-state-immutable ,threaded-var))\n (stmt:select-statement (select-statement-to-query-state ,threaded-var))\n (stmt:insert-into-statement (insert-statement-to-query-state ,threaded-var))\n (stmt:update-statement (update-statement-to-query-state ,threaded-var))\n (stmt:delete-from-statement (delete-statement-to-query-state ,threaded-var))\n (otherwise (add-clause (make-select-query-state) ,threaded-var)))))\n ;; Now destructively add clauses (no more copying), skipping NILs\n ,@(loop for form in forms\n collect `(let ((,clause-var ,(if (listp form)\n ;; For list forms, call the function with its arguments (no threading)\n `(,(car form) ,@(cdr form))\n ;; For symbol forms, call the function with no arguments\n `(,form))))\n (when ,clause-var\n (add-clause ,threaded-var ,clause-var))))\n ,threaded-var)))", "macroexpand": "(let* ((#:threaded-var147 (from :users)) (#:threaded-var147 (typecase #:threaded-var147 (query-state-base (copy-query-state-immutable #:threaded-var147)) (stmt:select-statement (select-statement-to-query-state #:threaded-var147)) (stmt:insert-into-statement (insert-statement-to-query-state #:threaded-var147)) (stmt:update-statement (update-statement-to-query-state #:threaded-var147)) (stmt:delete-from-statement (delete-statement-to-query-state #:threaded-var147)) (otherwise (add-clause (make-select-query-state) #:threaded-var147))))) (let ((#:clause-var148 (when include-inactive (where (:= :active 0))))) (when #:clause-var148 (add-clause #:threaded-var147 #:clause-var148))) (let ((#:clause-var148 (when sort-by-date (order-by :created_at)))) (when #:clause-var148 (add-clause #:threaded-var147 #:clause-var148))) #:threaded-var147)", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(if-let ((x 1) (y nil)) :oops (and (not y) x))\n\nWhat needs to change: Macro call that should be transformed by if-let", "input": "(if-let ((x 1) (y nil)) :oops (and (not y) x))", "output": "(defmacro if-let (bindings &body (then-form &optional else-form))\n \"Creates new variable bindings, and conditionally executes either\nTHEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nAll initial-forms are executed sequentially in the specified order. Then all\nthe variables are bound to the corresponding values.\n\nIf all variables were bound to true values, the THEN-FORM is executed with the\nbindings in effect, otherwise the ELSE-FORM is executed with the bindings in\neffect.\"\n (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings))\n (variables (mapcar #'car binding-list)))\n `(let ,binding-list\n (if (and ,@variables)\n ,then-form\n ,else-form))))", "macroexpand": "(let ((x 1) (y nil)) (if (and x y) :oops (and (not y) x)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(subtest \"Outer testcase with multiline description.\" (is 'blah 'blah \"Blah with multiline description!\") (subtest \"Inner testcase with multiline description.\" (is 'foo 'foo \"Foo with multiline description!\")))\n\nWrite a macro that addresses: Macro call that should be transformed by subtest", "input": "(subtest \"Outer testcase with multiline description.\" (is 'blah 'blah \"Blah with multiline description!\") (subtest \"Inner testcase with multiline description.\" (is 'foo 'foo \"Foo with multiline description!\")))", "output": "(defmacro subtest (desc &body body)\n `(%subtest ,desc (lambda () ,@body)))", "macroexpand": "(%subtest \"Outer testcase with multiline description.\" (lambda nil (is (quote blah) (quote blah) \"Blah with multiline description!\") (subtest \"Inner testcase with multiline description.\" (is (quote foo) (quote foo) \"Foo with multiline description!\"))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-op (:union conjunctive-op))\n\nWrite a macro that addresses: Macro call that should be transformed by define-op", "input": "(define-op (:union conjunctive-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (union-op (:include conjunctive-op (name \"UNION\")) (:constructor make-union-op (&rest expressions))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(def-neo4j-fun del-node-property (node-id property) :delete (:uri-spec (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:status-handlers (204 (values t body)) (404 (error 'node-not-found-error :uri uri)) (409 (error 'unable-to-delete-node-error :uri uri))))\n\nWrite a macro that addresses: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun del-node-property (node-id property) :delete (:uri-spec (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:status-handlers (204 (values t body)) (404 (error 'node-not-found-error :uri uri)) (409 (error 'unable-to-delete-node-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun del-node-property (&key node-id property) (let ((uri (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :delete uri json (list (list 204 (lambda (body uri json) (values t body))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))) (list 409 (lambda (body uri json) (error (quote unable-to-delete-node-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> +underscore+ +digit-chunks+)\n\nIssue: Macro call that should be transformed by *>", "input": "(*> +underscore+ +digit-chunks+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset242) (multiple-value-bind (#:*>-res243 #:*>-next244) (funcall +underscore+ #:*>-offset242) (if (ok? #:*>-res243) (funcall +digit-chunks+ #:*>-next244) (fail #:*>-next244))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-decoder-simple-list-semantics (let* ((error (eq output-value :error)) (expected (cond ((eq output-value :error) nil) (t (with-guessing-encoder (encode-json-to-string output-value))))) (input-encoded (with-guessing-encoder (encode-json-to-string input-value))) (result (handler-bind ((error #'(lambda (x) (invoke-restart 'json-rpc:send-error (format nil \"~a\" x) 999)))) (json-rpc:invoke-rpc (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"method\\\":\\\"fooA\\\",\\\"params\\\":[~a],\\\"id\\\":999}\" (json-rpc-2-p) input-encoded))))) (if error (let ((res (decode-json-from-string result))) (is (and (null (cdr (assoc :result res))) (cdr (assoc :error res))))) (is (string= result (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"result\\\":~a,~@[~*\\\"error\\\":null,~]\\\"id\\\":999}\" (json-rpc-2-p) expected (not (json-rpc-2-p))))))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (let* ((error (eq output-value :error)) (expected (cond ((eq output-value :error) nil) (t (with-guessing-encoder (encode-json-to-string output-value))))) (input-encoded (with-guessing-encoder (encode-json-to-string input-value))) (result (handler-bind ((error #'(lambda (x) (invoke-restart 'json-rpc:send-error (format nil \"~a\" x) 999)))) (json-rpc:invoke-rpc (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"method\\\":\\\"fooA\\\",\\\"params\\\":[~a],\\\"id\\\":999}\" (json-rpc-2-p) input-encoded))))) (if error (let ((res (decode-json-from-string result))) (is (and (null (cdr (assoc :result res))) (cdr (assoc :error res))))) (is (string= result (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"result\\\":~a,~@[~*\\\"error\\\":null,~]\\\"id\\\":999}\" (json-rpc-2-p) expected (not (json-rpc-2-p))))))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (let* ((error (eq output-value :error)) (expected (cond ((eq output-value :error) nil) (t (with-guessing-encoder (encode-json-to-string output-value))))) (input-encoded (with-guessing-encoder (encode-json-to-string input-value))) (result (handler-bind ((error (function (lambda (x) (invoke-restart (quote json-rpc:send-error) (format nil \"~a\" x) 999))))) (json-rpc:invoke-rpc (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"method\\\":\\\"fooA\\\",\\\"params\\\":[~a],\\\"id\\\":999}\" (json-rpc-2-p) input-encoded))))) (if error (let ((res (decode-json-from-string result))) (is (and (null (cdr (assoc :result res))) (cdr (assoc :error res))))) (is (string= result (format nil \"{~@[~*\\\"jsonrpc\\\":\\\"2.0\\\",~]\\\"result\\\":~a,~@[~*\\\"error\\\":null,~]\\\"id\\\":999}\" (json-rpc-2-p) expected (not (json-rpc-2-p))))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(lret ((x 1)) (setf x 2))\n\nPattern to recognize: Macro call that should be transformed by lret", "input": "(lret ((x 1)) (setf x 2))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let ((x 1)) (setf x 2))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-html-string (:html (:head (:link #p\"styles.css\" :type \"text/css\"))))\n\nWhat needs to change: Macro call that should be transformed by with-html", "input": "(with-html-string (:html (:head (:link #p\"styles.css\" :type \"text/css\"))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:html (:head (:link #P\"styles.css\" :type \"text/css\")))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n($map-reduce \"foo\" m r :query ($> \"l\" -9))\n\nPattern to recognize: Macro call that should be transformed by $map-reduce", "input": "($map-reduce \"foo\" m r :query ($> \"l\" -9))", "output": "(defmacro $map-reduce (collection map reduce &key (query nil) (limit 0) (out nil) \n\t\t (keeptemp nil) (finalize nil) (verbose t))\n \"Run map reduce on the mongo server. map and reduce are either the names of the \njavascript functions, created with defjs or defsrvjs or are function definitions in javascript.\nThe keywords refer to option available for map reduce in mongo. This returns a result summary document.\nWhen using :keeptemp t without specificing :out the collection is mr. \"\n `(db.find \"$cmd\" (kv (kv \"mapreduce\" ,collection) \n\t\t\t (kv \"map\" (or (jsdef ,map) ',map))\n\t\t\t (kv \"reduce\" (or (jsdef ,reduce) ',reduce))\n\t\t\t (when ,finalize (kv \"finalize\" (jsdef ,finalize)))\n\t\t\t (kv \"out\" (if ,out ,out (concatenate 'string \"mr.\" ,collection))) \n\t\t\t (kv \"verbose\" ,verbose)\n\t\t\t (kv \"limit\" ,limit)\n\t\t\t (kv \"keeptemp\" ,keeptemp)\n\t\t\t (kv \"query\" ,query))))", "macroexpand": "(db.find \"$cmd\" (kv (kv \"mapreduce\" \"foo\") (kv \"map\" (or (jsdef m) (quote m))) (kv \"reduce\" (or (jsdef r) (quote r))) (when nil (kv \"finalize\" (jsdef nil))) (kv \"out\" (if nil nil (concatenate (quote string) \"mr.\" \"foo\"))) (kv \"verbose\" t) (kv \"limit\" 0) (kv \"keeptemp\" nil) (kv \"query\" ($> \"l\" -9))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defgeneric* nil nil)\n\nPattern to recognize: Macro call that should be transformed by DEFGENERIC*", "input": "(defgeneric* nil nil)", "output": "(defmacro DEFGENERIC* ...)", "macroexpand": "(ensure-generic*-function 'nil :name 'nil :lambda-list 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-wcs-math-error-handling (ret (tan x)) (check-wcs-math-result))\n\nWhat needs to change: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (tan x)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g215 x) (#:g216 nil) (#:g217 (list #:g215))) (declare (ignorable #:g216) (type list #:g217) (dynamic-extent #:g217)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote tan) #:g217) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g217)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-generic generic ((a a) (b b) &key (c nil)) \"This expands to documentation.\" (+ a b))\n\nWrite a macro that addresses: Macro call that should be transformed by define-generic", "input": "(define-generic generic ((a a) (b b) &key (c nil)) \"This expands to documentation.\" (+ a b))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:method ((a a) (b b) &key (c nil)) (+ a b)) (:documentation \"This expands to documentation.\")) (setf (documentation (quote generic) (quote function)) \"This expands to documentation.\") (setf (documentation (fdefinition (quote generic)) (quote function)) \"This expands to documentation.\"))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-transaction *db* (do-sql *db* \"INSERT INTO person (id, name) VALUES (4, 'meymao')\"))\n\nProblem: Macro call that should be transformed by with-transaction", "input": "(with-transaction *db* (do-sql *db* \"INSERT INTO person (id, name) VALUES (4, 'meymao')\"))", "output": "(defmacro with-transaction (conn &body body)\n \"Start a transaction and commit at the end of this block. If the evaluation `body` is interrupted, the transaction is rolled back automatically.\"\n (let ((conn-var (gensym \"CONN-VAR\")))\n `(let ((,conn-var ,conn))\n (if (in-transaction ,conn-var)\n (with-savepoint ,conn-var ,@body)\n (%with-transaction ,conn-var ,@body)))))", "macroexpand": "(let ((#:conn-var160 *db*)) (if (in-transaction #:conn-var160) (with-savepoint #:conn-var160 (do-sql *db* \"INSERT INTO person (id, name) VALUES (4, 'meymao')\")) (%with-transaction #:conn-var160 (do-sql *db* \"INSERT INTO person (id, name) VALUES (4, 'meymao')\"))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> :g () 3)\n\nIssue: Macro call that should be transformed by ->", "input": "(-> :g () 3)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g nil 3)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defalias path:rm-r (pathname) cl-fad:delete-directory-and-files)\n\nIssue: Macro call that should be transformed by defalias", "input": "(defalias path:rm-r (pathname) cl-fad:delete-directory-and-files)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:rm-r (pathname) (delete-directory-and-files pathname)) (define-compiler-macro path:rm-r (&rest args) (list* (quote delete-directory-and-files) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.945} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(let1 x 1 (list y z))\n\nWhat needs to change: Macro call that should be transformed by let1", "input": "(let1 x 1 (list y z))", "output": "(defmacro let1 (var expr &body body)\n \"Bind VAR, immutably, to EXPR and evaluate BODY.\n\nThis may be pronounced with equal propriety as \\\"let-one\\\" or\n\\\"let-once\\\".\"\n `(let ((,var ,expr))\n (with-read-only-vars (,var)\n ,@body)))", "macroexpand": "(let ((x 1)) (with-read-only-vars (x) (list y z)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-binary-op-mapping-definer define-binary-ops `(progn (declaim (inline ,op)) (defun ,op (x y) (,cl x y))))\n\nPattern to recognize: Macro call that should be transformed by define", "input": "(define-binary-op-mapping-definer define-binary-ops `(progn (declaim (inline ,op)) (defun ,op (x y) (,cl x y))))", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(defmacro define-binary-ops (&rest map) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (loop for (vacietis cl) on map by (function cddr) collect (let ((op (find-symbol (symbol-name vacietis) (quote #:vacietis.c)))) (sb-int:quasiquote (progn (declaim (inline #S(sb-impl::comma :expr op :kind 0))) (defun #S(sb-impl::comma :expr op :kind 0) (x y) (#S(sb-impl::comma :expr cl :kind 0) x y)))))) :kind 2))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(cond-> nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by COND->", "input": "(cond-> nil :key nil)", "output": "(defmacro COND-> ...)", "macroexpand": "(let* ((#:g139 nil))\n (if :key\n (-> #:g139 nil)\n #:g139))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(some-> 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by SOME->", "input": "(some-> 'some-name)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:|some129| 'some-name))\n #:|some129|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(c-assert (listp new-kids) () \"New kids value for ~a not listp: ~a ~a\" self (type-of new-kids) new-kids)\n\nWrite a macro that addresses: Macro call that should be transformed by c-assert", "input": "(c-assert (listp new-kids) () \"New kids value for ~a not listp: ~a ~a\" self (type-of new-kids) new-kids)", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (listp new-kids) (c-break \"New kids value for ~a not listp: ~a ~a\" self (type-of new-kids) new-kids)))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.9375} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(action (:after node-variable node bound-variables) (let ((name (node-variable-value node))) (unless (member name bound-variables :test #'eq) (alexandria:when-let ((target (alias-substitution-target name aliases))) (copy-node target (node-type node))))))\n\nWrite a macro that addresses: Macro call that should be transformed by action", "input": "(action (:after node-variable node bound-variables) (let ((name (node-variable-value node))) (unless (member name bound-variables :test #'eq) (alexandria:when-let ((target (alias-substitution-target name aliases))) (copy-node target (node-type node))))))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-variable) (lambda (node bound-variables) (declare (type node-variable node)) (let ((name (node-variable-value node))) (unless (member name bound-variables :test (function eq)) (alexandria:when-let ((target (alias-substitution-target name aliases))) (copy-node target (node-type node)))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-sum 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-SUM", "input": "(collect-sum 'some-name)", "output": "(defmacro COLLECT-SUM ...)", "macroexpand": "(common-lisp:let* ((#:generator-242 (generator 'some-name))\n #:numbers-238\n (#:sum-239 0))\n (declare (type generator #:generator-242)\n (type number #:sum-239))\n (tagbody\n #:ll-243\n (setq #:numbers-238 (next-in #:generator-242 (go end)))\n (setq #:sum-239 (+ #:sum-239 #:numbers-238))\n (go #:ll-243)\n end)\n #:sum-239)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defannotation export* (definition-form) (:alias export) \"Export the definition symbol of DEFINITION-FORM.\" (let ((name (definition-form-symbol definition-form))) (if name `(progn (export ',name) ,definition-form) definition-form)))\n\nIssue: Macro call that should be transformed by defannotation", "input": "(defannotation export* (definition-form) (:alias export) \"Export the definition symbol of DEFINITION-FORM.\" (let ((name (definition-form-symbol definition-form))) (if name `(progn (export ',name) ,definition-form) definition-form)))", "output": "(defmacro defannotation (name lambda-list options &body body)\n `(progn\n (set-annotation-options ',name ',options)\n (defmacro ,name ,lambda-list ,@body)))", "macroexpand": "(progn (set-annotation-options (quote export*) (quote (:alias export))) (defmacro export* (definition-form) \"Export the definition symbol of DEFINITION-FORM.\" (let ((name (definition-form-symbol definition-form))) (if name (sb-int:quasiquote (progn (export (quote #S(sb-impl::comma :expr name :kind 0))) #S(sb-impl::comma :expr definition-form :kind 0))) definition-form))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lret* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)\n\nWhat needs to change: Macro call that should be transformed by lret", "input": "(lret* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when-it (remove-if-not #'internal-variable? (free-variables form)) (clause-error \"The variable~p ~{~A~^, ~} ~:[is~;are~] bound in a context ~ internal to the Iterate form.~% This part of the clause will be moved outside ~ the body of the loop, so it must not contain anything that depends on the body.\" (length it) it (rest it)))\n\nWhat needs to change: Macro call that should be transformed by when-it", "input": "(when-it (remove-if-not #'internal-variable? (free-variables form)) (clause-error \"The variable~p ~{~A~^, ~} ~:[is~;are~] bound in a context ~ internal to the Iterate form.~% This part of the clause will be moved outside ~ the body of the loop, so it must not contain anything that depends on the body.\" (length it) it (rest it)))", "output": "(defmacro when-it (test &body body)\n \"Like WHEN. IT is bound to TEST.\"\n `(let ((it ,test))\n (when it\n ,@body)))", "macroexpand": "(let ((it (remove-if-not (function internal-variable?) (free-variables form)))) (when it (clause-error \"The variable~p ~{~A~^, ~} ~:[is~;are~] bound in a context ~ internal to the Iterate form.~% This part of the clause will be moved outside ~ the body of the loop, so it must not contain anything that depends on the body.\" (length it) it (rest it))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(caching-types\n nil)\n\nIssue: Macro call that should be transformed by CACHING-TYPES", "input": "(caching-types\n nil)", "output": "(defmacro CACHING-TYPES ...)", "macroexpand": "(call-with-disjoint-hash\n (lambda ()\n (call-with-subtype-hash\n (lambda ()\n (call-with-equiv-hash\n (lambda () (call-with-subtypep-cache (lambda () nil))))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-color (color :stream stream) (format stream \"(~Dms)\" duration))\n\nProblem: Macro call that should be transformed by with-color", "input": "(with-color (color :stream stream) (format stream \"(~Dms)\" duration))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq color :gray) (eq color :grey) (eq color +gray+) (eq color +grey+)) (with-gray stream (format stream \"(~Dms)\" duration)) (cl-ansi-text:with-color (color :stream stream) (format stream \"(~Dms)\" duration))) (progn (format stream \"(~Dms)\" duration)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-dynenv nil\n (progn))\n\nIssue: Macro call that should be transformed by WITH-DYNENV", "input": "(with-dynenv nil\n (progn))", "output": "(defmacro WITH-DYNENV ...)", "macroexpand": "(multiple-value-bind (#:var-expansion130 #:var-expanded-p131)\n (macroexpand-1 'var-space nil)\n (multiple-value-bind (#:fun-expansion132 #:fun-expanded-p133)\n (macroexpand-1 'fun-space nil)\n (let ((*var-space* (when #:var-expanded-p131 #:var-expansion130))\n (*fun-space* (when #:fun-expanded-p133 #:fun-expansion132))\n (*within-captured-dynenv* t))\n (progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (oddp (length rest)) (error \"Set operator with odd number of elements: ~a\" rest))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (oddp (length rest)) (error \"Set operator with odd number of elements: ~a\" rest))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (oddp (length rest)) (error \"Set operator with odd number of elements: ~a\" rest))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dreletf nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DRELETF", "input": "(dreletf nil\n (progn))", "output": "(defmacro DRELETF ...)", "macroexpand": "(let ((#:symbol-store233\n (with-symbol-access\n (list))))\n (special-symbol-reprogv #:symbol-store233\n (list)\n (locally (declare (special)) (progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(mvlet* ((slot-names slot-binds (loop for slot in slots if (listp slot) collect slot into slot-binds and collect (first slot) into slot-names else collect slot into slot-names and collect (list slot slot) into slot-binds finally (return (values slot-names slot-binds)))) (body decls (parse-body body)) (slot-decls decls (partition-declarations slot-names decls))) `(macrolet ((:method (name &body args) (mvlet* ((class ',class) (self ',self) (slot-binds ',slot-binds) (qualifiers lambda-list body (parse-defmethod-args args)) (body decls docstring (parse-body body :documentation t)) (ll-with-self (substitute (list self class) self lambda-list))) (when (equal ll-with-self lambda-list) (error \"No binding for ~s in ~s\" self lambda-list)) `(symbol-macrolet ,(loop for (alias ref) in slot-binds collect (ematch ref ((and ref (type symbol)) `(,alias (slot-value ,self ',ref))) ((list 'function fn) `(,alias (,fn ,self))))) ,@',slot-decls (defmethod ,name ,@qualifiers ,ll-with-self ,@(unsplice docstring) ,@decls ,@body))))) ,@decls ,@body))\n\nPattern to recognize: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((slot-names slot-binds (loop for slot in slots if (listp slot) collect slot into slot-binds and collect (first slot) into slot-names else collect slot into slot-names and collect (list slot slot) into slot-binds finally (return (values slot-names slot-binds)))) (body decls (parse-body body)) (slot-decls decls (partition-declarations slot-names decls))) `(macrolet ((:method (name &body args) (mvlet* ((class ',class) (self ',self) (slot-binds ',slot-binds) (qualifiers lambda-list body (parse-defmethod-args args)) (body decls docstring (parse-body body :documentation t)) (ll-with-self (substitute (list self class) self lambda-list))) (when (equal ll-with-self lambda-list) (error \"No binding for ~s in ~s\" self lambda-list)) `(symbol-macrolet ,(loop for (alias ref) in slot-binds collect (ematch ref ((and ref (type symbol)) `(,alias (slot-value ,self ',ref))) ((list 'function fn) `(,alias (,fn ,self))))) ,@',slot-decls (defmethod ,name ,@qualifiers ,ll-with-self ,@(unsplice docstring) ,@decls ,@body))))) ,@decls ,@body))", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(multiple-value-bind (slot-names slot-binds) (loop for slot in slots if (listp slot) collect slot into slot-binds and collect (first slot) into slot-names else collect slot into slot-names and collect (list slot slot) into slot-binds finally (return (values slot-names slot-binds))) (mvlet* ((body decls (parse-body body)) (slot-decls decls (partition-declarations slot-names decls))) (sb-int:quasiquote (macrolet ((:method (name &body args) (mvlet* ((class (quote #S(sb-impl::comma :expr class :kind 0))) (self (quote #S(sb-impl::comma :expr self :kind 0))) (slot-binds (quote #S(sb-impl::comma :expr slot-binds :kind 0))) (qualifiers lambda-list body (parse-defmethod-args args)) (body decls docstring (parse-body body :documentation t)) (ll-with-self (substitute (list self class) self lambda-list))) (when (equal ll-with-self lambda-list) (error \"No binding for ~s in ~s\" self lambda-list)) (sb-int:quasiquote (symbol-macrolet #S(sb-impl::comma :expr (loop for (alias ref) in slot-binds collect (ematch ref ((and ref (type symbol)) (sb-int:quasiquote (#S(sb-impl::comma :expr alias :kind 0) (slot-value #S(sb-impl::comma :expr self :kind 0) (quote #S(sb-impl::comma :expr ref :kind 0)))))) ((list (quote function) fn) (sb-int:quasiquote (#S(sb-impl::comma :expr alias :kind 0) (#S(sb-impl::comma :expr fn :kind 0) #S(sb-impl::comma :expr self :kind 0))))))) :kind 0) #S(sb-impl::comma :expr (quote #S(sb-impl::comma :expr slot-decls :kind 0)) :kind 2) (defmethod #S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr qualifiers :kind 2) #S(sb-impl::comma :expr ll-with-self :kind 0) #S(sb-impl::comma :expr (unsplice docstring) :kind 2) #S(sb-impl::comma :expr decls :kind 2) #S(sb-impl::comma :expr body :kind 2))))))) #S(sb-impl::comma :expr decls :kind 2) #S(sb-impl::comma :expr body :kind 2)))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some-<>> nil)\n\nIssue: Macro call that should be transformed by SOME-<>>", "input": "(some-<>> nil)", "output": "(defmacro SOME-<>> ...)", "macroexpand": "(let* ((#:g130 nil))\n #:g130)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(mvlet* ((x 2) (y x)) x y)\n\nWhat needs to change: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((x 2) (y x)) x y)", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(let* ((x 2) (y x)) x y)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(augment *initial* init)\n\nWhat needs to change: Macro call that should be transformed by augment", "input": "(augment *initial* init)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf *initial* (nconc *initial* init))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(*> +open-brace+ +consume-space+)\n\nProblem: Macro call that should be transformed by *>", "input": "(*> +open-brace+ +consume-space+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset178) (multiple-value-bind (#:*>-res179 #:*>-next180) (funcall +open-brace+ #:*>-offset178) (if (ok? #:*>-res179) (funcall +consume-space+ #:*>-next180) (fail #:*>-next180))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-class bar () ((name \"fooname\") (age :accessor this-age) (address :accessor nil)) (:accessor-name-transformer (lambda (name def) (declare (ignore def)) name)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-class", "input": "(define-class bar () ((name \"fooname\") (age :accessor this-age) (address :accessor nil)) (:accessor-name-transformer (lambda (name def) (declare (ignore def)) name)))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass bar nil ((name :initform \"fooname\" :accessor name :initarg :name) (age :initform nil :accessor this-age :initarg :age) (address :initform nil :initarg :address))) (unless (fboundp (quote barp)) (define-generic barp (object) #A((68) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `bar'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote bar)))) (setf (documentation (quote this-age) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\")) (ignore-errors (setf (documentation (fdefinition (quote this-age)) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf this-age))) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\"))) (setf (documentation (quote name) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\")) (ignore-errors (setf (documentation (fdefinition (quote name)) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf name))) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\"))) (find-class (quote bar) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(jbind true t true)\n\nPattern to recognize: Macro call that should be transformed by jbind", "input": "(jbind true t true)", "output": "(defmacro jbind (destructuring-pattern form &body body)\n \"Match the FORM against DESTRUCTURING-PATTERN.\nThe pattern might be:\n- A symbol, in which case the current chosen form is bound to it. If\n the symbol is _, simply skip the form.\n- A literal form:\n - String or number: compare with `equal'.\n - Keywords :TRUE, :FALSE, and :NULL, matching T, NIL, and :NULL\n respectively.\n- If the pattern is a property list of string+pattern pairs, match the\n string+pattern pairs inside it to the provided JSON object and\n resolve them recursively.\n- If the pattern is a list of symbols (VAR &optional VAR-P), these are\n bound to the respective values of `jget'. It is a good way to make\n `jbind' to be more lenient to missing keys, because the default\n behavior is to error on missing data.\n- If the pattern is an inline vector, match it against a JSON array\n with at least as many elements as provided in the vector. Match\n every form in the vector against the element with the same index.\n\nIf the DESTRUCTURING-PATTERN doesn't match the object, throw\n`value-mismatch'.\n\nUnderlying `jget' can throw errors for the exceptionally malformed\ninputs. See `jget' documentation for the types of errors it throws.\n\nExample:\n\\(\\\"hello\\\" hello \\\"a\\\" _ \\\"b\\\" b\n \\\"array\\\" #(first second third _))\n\nmatches a JSON object\n{\\\"hello\\\": 3, \\\"a\\\": 8, \\\"b\\\": 3, \\\"c\\\": null, \\\"array\\\": [1, 2, 3, 4]}\n\nand binds\n- HELLO to 3\n- B to 3\n- FIRST to 1\n- SECOND to 2\n- THIRD to 3\n\nIt also checks that \\\"a\\\" key is present in the object and there's a\nfourth element in the nested array.\n\nSee more examples in njson tests.\"\n (let ((form-sym (gensym \"BIND-FORM\"))\n (bindings (list)))\n (labels ((parse-pattern (pattern &optional (current-path (list)))\n (etypecase pattern\n ((or (member :true :false :null) string real)\n (push (cons pattern (copy-list current-path))\n bindings))\n ((cons symbol *)\n (push (cons pattern (copy-list current-path))\n bindings))\n (list\n (loop for (key subpattern) on pattern by #'cddr\n do (parse-pattern subpattern (append current-path (list key))))\n (push (cons nil (copy-list current-path))\n bindings))\n ((and symbol (not keyword))\n (push (cons (if (equal \"_\" (symbol-name pattern))\n (gensym \"_PATTERN\")\n pattern)\n (copy-list current-path))\n bindings))\n (array\n\t\t (loop for elem across pattern\n for index from 0\n do (parse-pattern elem (append current-path (list index))))\n\t\t (push (cons #() (copy-list current-path))\n\t\t\tbindings)))))\n (check-type destructuring-pattern (or list (and array (not string))\n (and symbol (not keyword)))\n \"proper jbind destructuring pattern: list, array, or symbol\")\n (parse-pattern destructuring-pattern)\n (let ((let-forms (loop for (binding . key) in bindings\n do (check-type binding (or array real symbol\n ;; For (VAR VAR-P) forms\n (cons symbol (or (cons symbol null)\n null))))\n if (typep binding '(or array real null\n (member :true :false :null)))\n collect `(,(gensym) (check-value ,binding (vector ,@key) ,form-sym))\n else if (and (symbolp binding)\n (uiop:emptyp key))\n collect `(,binding ,form-sym)\n else if (listp binding)\n append (destructuring-bind (var &optional (var-p nil var-p-provided))\n binding\n (append\n `((,var (jget (vector ,@key) ,form-sym)))\n (when var-p-provided\n `((,var-p (nth-value 1 (jget (vector ,@key) ,form-sym)))))))\n else\n collect `(,binding (check-value t (vector ,@key) ,form-sym)))))\n `(let* ((,form-sym ,form)\n ,@let-forms)\n (declare (ignorable ,form-sym ,@(mapcar #'first let-forms)))\n ,@body))))", "macroexpand": "(let* ((#:bind-form125 t) (true #:bind-form125)) (declare (ignorable #:bind-form125 true)) true)", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8099999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(check-cursor-attached cluffer:backward-item (cursor))\n\nProblem: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:backward-item (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:backward-item :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when 'some-name)\n\nIssue: Macro call that should be transformed by WHEN", "input": "(when 'some-name)", "output": "(defmacro WHEN ...)", "macroexpand": "(if 'some-name\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(resolving\n nil)\n\nWhat needs to change: Macro call that should be transformed by RESOLVING", "input": "(resolving\n nil)", "output": "(defmacro RESOLVING ...)", "macroexpand": "(resolve\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cond->> nil)\n\nIssue: Macro call that should be transformed by COND->>", "input": "(cond->> nil)", "output": "(defmacro COND->> ...)", "macroexpand": "(let* ((#:g135 nil))\n #:g135)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder (:session :keep-empty nil) (lambda (env) (when (string= (getf env :path-info) \"/session\") (setf (gethash \"user\" (getf env :lack.session)) \"Eitaro\")) '(200 () (\"hi\"))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder (:session :keep-empty nil) (lambda (env) (when (string= (getf env :path-info) \"/session\") (setf (gethash \"user\" (getf env :lack.session)) \"Eitaro\")) '(200 () (\"hi\"))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app224) (funcall (find-middleware :session) #:app224 :keep-empty nil)))) :initial-value (to-app (lambda (env) (when (string= (getf env :path-info) \"/session\") (setf (gethash \"user\" (getf env :lack.session)) \"Eitaro\")) (quote (200 nil (\"hi\"))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-quote-char (format out \"~{~{~A;~%~}~^~%~}\" (mapcar (lambda (class) (mapcar #'sxql:yield (table-definition class))) (all-dao-classes))) (format out \"~2&~A;~%\" (sxql:yield (schema-migrations-table-definition))))\n\nWhat needs to change: Macro call that should be transformed by with-quote-char", "input": "(with-quote-char (format out \"~{~{~A;~%~}~^~%~}\" (mapcar (lambda (class) (mapcar #'sxql:yield (table-definition class))) (all-dao-classes))) (format out \"~2&~A;~%\" (sxql:yield (schema-migrations-table-definition))))", "output": "(defmacro with-quote-char (&body body)\n `(let ((sxql:*quote-character* (or sxql:*quote-character*\n (connection-quote-character *connection*))))\n ,@body))", "macroexpand": "(let ((sxql/sql-type:*quote-character* (or sxql/sql-type:*quote-character* (connection-quote-character *connection*)))) (format out \"~{~{~A;~%~}~^~%~}\" (mapcar (lambda (class) (mapcar (function sxql/sql-type:yield) (table-definition class))) (all-dao-classes))) (format out \"~2&~A;~%\" (sxql/sql-type:yield (schema-migrations-table-definition))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when (node-slot linebreak) (format stream \"~&~a\" indent))\n\nIssue: Macro call that should be transformed by when", "input": "(when (node-slot linebreak) (format stream \"~&~a\" indent))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (node-slot linebreak) (format stream \"~&~a\" indent))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(match either m ((right x) (funcall f x)) ((left b) (left b)))\n\nIssue: Macro call that should be transformed by match", "input": "(match either m ((right x) (funcall f x)) ((left b) (left b)))", "output": "(defmacro match (adt obj &body clauses)\n \"Perform pattern matching on OBJ with (adt-type) ADT.\n\nEach clause must have the following syntax:\n\n := | '_'\n := '_'\n | ( *)\n := ( )\n\nThe symbol '_' denotes a wildcard, as well as a fallthough.\n\nNote that pattern matching is only shallow (patterns are one-level\ndeep).\n\"\n (assert (symbolp adt)\n (adt)\n \"MATCH requires a symbol for the first argument. Given ~S.\"\n adt)\n\n (let ((ctors (mapcar #'car (get-constructors adt)))\n (types (mapcar (lambda (clause)\n (ensure-car (car clause)))\n clauses))\n (once (gensym \"OBJ-\")))\n\n ;; Check for duplicate matches.\n (let ((dupes (duplicates types)))\n (when dupes\n (warn \"Duplicate matching clauses exist. Duplicate pattern ~\n constructors:~{ ~S~}\"\n dupes)))\n\n ;; Check for match exhaustiveness.\n (unless (some #'wild? types)\n (let ((diff (set-difference ctors types)))\n (when diff\n (warn \"Non-exhaustive match on ~A data ~\n type. Missing cases:~{ ~S~}\" adt diff))))\n\n ;; Generate the matching code.\n `(let ((,once ,obj))\n (check-type ,once ,adt)\n (etypecase ,once\n ,@(loop :for (bindings . body) :in clauses\n :collect (let ((type (ensure-car bindings)))\n (if (wild? type)\n `(t ,@body)\n `(,type\n (with-data ,(ensure-list bindings)\n ,once\n ,@body)))))))))", "macroexpand": "(let ((#:obj-149 m)) (check-type #:obj-149 either) (etypecase #:obj-149 (right (with-data (right x) #:obj-149 (funcall f x))) (left (with-data (left b) #:obj-149 (left b)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-rules nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-RULES", "input": "(with-rules nil\n nil)", "output": "(defmacro WITH-RULES ...)", "macroexpand": "(dolist (nil (alexandria:hash-table-keys cl-rules.core::*rules*)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(augment prev-code prev)\n\nWrite a macro that addresses: Macro call that should be transformed by augment", "input": "(augment prev-code prev)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf prev-code (nconc prev-code prev))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(\u0192\u0192 'some-name)\n\nProblem: Macro call that should be transformed by \u0191\u0191", "input": "(\u0192\u0192 'some-name)", "output": "(defmacro \u0191\u0191 ...)", "macroexpand": "(defun 'some-name (&optional \u03b1) (cond))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(c-assert (or (null before) (eql (fm-parent kid) (fm-parent before))))\n\nProblem: Macro call that should be transformed by c-assert", "input": "(c-assert (or (null before) (eql (fm-parent kid) (fm-parent before))))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (or (null before) (eql (fm-parent kid) (fm-parent before))) (c-break \"failed assertion: ~a\" (quote (or (null before) (eql (fm-parent kid) (fm-parent before)))))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.9375} {"instruction": "Generate a defmacro form that transforms code like this:\n($map-reduce \"foo\" m r :out \"testit\" :query ($> \"l\" -900))\n\nPattern to recognize: Macro call that should be transformed by $", "input": "($map-reduce \"foo\" m r :out \"testit\" :query ($> \"l\" -900))", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(db.find \"$cmd\" (kv (kv \"mapreduce\" \"foo\") (kv \"map\" (or (jsdef m) (quote m))) (kv \"reduce\" (or (jsdef r) (quote r))) (when nil (kv \"finalize\" (jsdef nil))) (kv \"out\" (if \"testit\" \"testit\" (concatenate (quote string) \"mr.\" \"foo\"))) (kv \"verbose\" t) (kv \"limit\" 0) (kv \"keeptemp\" nil) (kv \"query\" ($> \"l\" -900))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(without-package-lock (:common-lisp #+lispworks :implementation) (defmethod print-object :around ((rt readtable) stream) (let ((name (readtable-name rt))) (if name (print-unreadable-object (rt stream :type nil :identity t) (format stream \"~A ~S\" :named-readtable name)) (call-next-method)))))\n\nWhat needs to change: Macro call that should be transformed by without-package-lock", "input": "(without-package-lock (:common-lisp #+lispworks :implementation) (defmethod print-object :around ((rt readtable) stream) (let ((name (readtable-name rt))) (if name (print-unreadable-object (rt stream :type nil :identity t) (format stream \"~A ~S\" :named-readtable name)) (call-next-method)))))", "output": "(defmacro without-package-lock ((&rest package-names) &body body)\n (declare (ignorable package-names))\n #+clisp\n (return-from without-package-lock\n `(ext:without-package-lock (,@package-names) ,@body))\n #+lispworks\n (return-from without-package-lock\n `(let ((hcl:*packages-for-warn-on-redefinition*\n (set-difference hcl:*packages-for-warn-on-redefinition*\n '(,@package-names)\n :key (lambda (package-designator)\n (if (packagep package-designator)\n (package-name package-designator)\n package-designator))\n :test #'string=)))\n ,@body))\n `(progn ,@body))", "macroexpand": "(progn (defmethod print-object :around ((rt readtable) stream) (let ((name (readtable-name rt))) (if name (print-unreadable-object (rt stream :type nil :identity t) (format stream \"~A ~S\" :named-readtable name)) (call-next-method)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defrte nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFRTE", "input": "(defrte nil nil)", "output": "(defmacro DEFRTE ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (getf (symbol-plist '-nil) :rte-pattern) 'nil\n (gethash 'nil *rte-hash*) 'nil)\n (defun -nil (seq)\n (declare (optimize (speed 3) (debug 0) (safety 0)))\n (block check\n (typecase seq\n (list\n (tagbody\n (go 1)\n 1\n (if (null seq)\n (return-from check nil)\n (case (pop seq) (t (return-from check nil))))))\n (simple-vector\n (let ((i 0) (len (length seq)))\n (declare (type (and unsigned-byte fixnum) i len)\n (ignorable len))\n (tagbody\n (go 1)\n 1\n (if (>= i len)\n (return-from check nil)\n (case (prog1 (svref seq i) (incf i))\n (t (return-from check nil)))))))\n (vector\n (let ((i 0) (len (length seq)))\n (declare (type (and fixnum unsigned-byte) i len)\n (ignorable len))\n (tagbody\n (go 1)\n 1\n (if (>= i len)\n (return-from check nil)\n (case (prog1 (aref seq i) (incf i))\n (t (return-from check nil)))))))\n (sequence\n (let ((i 0) (len (sb-sequence:length seq)))\n (declare (type (and fixnum unsigned-byte) i len)\n (ignorable len))\n (tagbody\n (go 1)\n 1\n (if (or (sb-sequence:emptyp seq) (>= i len))\n (return-from check nil)\n (case (prog1 (sb-sequence:elt seq i) (incf i))\n (t (return-from check nil)))))))\n (t nil)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(signal-syntax-error \"Unknown symbol ~A in character class.\" item)\n\nPattern to recognize: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Unknown symbol ~A in character class.\" item)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Unknown symbol ~A in character class.\" item)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-data (rect x y) pt (set-data pt (rect y x)))\n\nWhat needs to change: Macro call that should be transformed by with-data", "input": "(with-data (rect x y) pt (set-data pt (rect y x)))", "output": "(defmacro with-data ((name &rest vars) obj &body body)\n \"Destructure the ADT value OBJ, whose constructor is NAME. VARS must\nbe symbol which will be bound, or they must be the symbol '_', which\nmeans the value will not be bound.\"\n (let* ((once (gensym \"ONCE-\"))\n (bindings (loop :for i :from 0\n :for v :in vars\n :when (not (wild? v))\n :collect `(,v (,(field name i)\n ,once)))))\n `(let ((,once ,obj))\n (declare (ignorable ,once))\n (let (,@bindings)\n ,@body))))", "macroexpand": "(let ((#:once-146 pt)) (declare (ignorable #:once-146)) (let ((x (rect%0 #:once-146)) (y (rect%1 #:once-146))) (set-data pt (rect y x))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define EXIT_FAILURE 1)\n\nPattern to recognize: Macro call that should be transformed by define", "input": "(define EXIT_FAILURE 1)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote exit_failure) *preprocessor-defines*) #A((1) base-char . \"1\"))) (defparameter exit_failure 1))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-neo4j-fun get-node (node-id) :get (:uri-spec (if node-id (format nil \"node/~A\" node-id) \"\")) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))\n\nProblem: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-node (node-id) :get (:uri-spec (if node-id (format nil \"node/~A\" node-id) \"\")) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-node (&key node-id) (let ((uri (if node-id (format nil \"node/~A\" node-id) \"\")) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(alist-bind (type) form (alist-bind ((type-tag :tag)) type (cond ((or (string= \":char\" type-tag) (string= \":unsigned-char\" type-tag)) '((:string))) (t `((:pointer ,@(parse-type type type-tag)))))))\n\nPattern to recognize: Macro call that should be transformed by alist-bind", "input": "(alist-bind (type) form (alist-bind ((type-tag :tag)) type (cond ((or (string= \":char\" type-tag) (string= \":unsigned-char\" type-tag)) '((:string))) (t `((:pointer ,@(parse-type type type-tag)))))))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist234 form)) (let ((type (aval :type #:alist234))) (alist-bind ((type-tag :tag)) type (cond ((or (string= \":char\" type-tag) (string= \":unsigned-char\" type-tag)) (quote ((:string)))) (t (sb-int:quasiquote ((:pointer #S(sb-impl::comma :expr (parse-type type type-tag) :kind 2)))))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(letrec nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by LETREC", "input": "(letrec nil\n nil)", "output": "(defmacro LETREC ...)", "macroexpand": "(let ()\n (flet ()\n nil\n (setf)\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report 'slow-threshold)))) (when (slot-value report 'description) (format/indent reporter stream (concatenate 'string \"~&\" (report-expected-line report)))))\n\nWhat needs to change: Macro call that should be transformed by with-additional-indent", "input": "(with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report 'slow-threshold)))) (when (slot-value report 'description) (format/indent reporter stream (concatenate 'string \"~&\" (report-expected-line report)))))", "output": "(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)\n (declare (ignorable reporter stream control-string))\n (let* ((need-new-line (ppcre:scan \"^~&\" control-string))\n (string (apply #'format nil control-string format-arguments))\n (increment (length string)))\n `(with-slots (indent-space) reporter\n (let* ((first-line-indent (indent indent-space))\n (*additional-indent* ,(if need-new-line\n increment\n `(+ *additional-indent*\n ,increment))))\n (declare (ignorable first-line-indent))\n ,(if need-new-line\n `(progn (fresh-line stream)\n (write-string first-line-indent ,stream)\n ;; because we just started a new line, we\n ;; should use format/indent to write string\n ;; taking into account a main indentation level\n (format/indent ,reporter ,stream ,string))\n ;; otherwise, just output our prefix\n `(write-string ,string ,stream))\n \n \n ,@body))))", "macroexpand": "(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* (+ *additional-indent* 2))) (declare (ignorable first-line-indent)) (write-string \"\u00d7 \" stream) (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report (quote slow-threshold))))) (when (slot-value report (quote description)) (format/indent reporter stream (concatenate (quote string) \"~&\" (report-expected-line report))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(-> :two () (increment))\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(-> :two () (increment))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :two nil (increment))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defproto 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DEFPROTO", "input": "(defproto 'some-name)", "output": "(defmacro DEFPROTO ...)", "macroexpand": "(progn\n (declaim (special (quote some-name)))\n (eval-when (:compile-toplevel))\n (setf (symbol-value ''some-name)\n (ensure-object (when (boundp ''some-name) (symbol-value ''some-name))\n (list) :properties (list) :nickname ''some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(drelet* 'some-name)\n\nProblem: Macro call that should be transformed by DRELET*", "input": "(drelet* 'some-name)", "output": "(defmacro DRELET* ...)", "macroexpand": "(dynamic-relet* 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(if-let (x (opaque nil)) :bad (and (not x) :ok))\n\nProblem: Macro call that should be transformed by if-let", "input": "(if-let (x (opaque nil)) :bad (and (not x) :ok))", "output": "(defmacro if-let (bindings &body (then-form &optional else-form))\n \"Creates new variable bindings, and conditionally executes either\nTHEN-FORM or ELSE-FORM. ELSE-FORM defaults to NIL.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nAll initial-forms are executed sequentially in the specified order. Then all\nthe variables are bound to the corresponding values.\n\nIf all variables were bound to true values, the THEN-FORM is executed with the\nbindings in effect, otherwise the ELSE-FORM is executed with the bindings in\neffect.\"\n (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings))\n (variables (mapcar #'car binding-list)))\n `(let ,binding-list\n (if (and ,@variables)\n ,then-form\n ,else-form))))", "macroexpand": "(let ((x (opaque nil))) (if (and x) :bad (and (not x) :ok)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(\u0192 nil)\n\nWhat needs to change: Macro call that should be transformed by \u0191", "input": "(\u0192 nil)", "output": "(defmacro \u0191 ...)", "macroexpand": "(defun nil (&optional \u03b1)\n (let ((\u03b1 (or \u03b1 t)))\n (cond)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-fn nil :key nil)\n\nProblem: Macro call that should be transformed by COLLECT-FN", "input": "(collect-fn nil :key nil)", "output": "(defmacro COLLECT-FN ...)", "macroexpand": "(common-lisp:let* ((#:c-176 (common-lisp:funcall :key)))\n (tagbody\n #:ll-181\n (setq #:c-176 (common-lisp:funcall nil #:c-176))\n (go #:ll-181))\n #:c-176)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-reader-case 'some-name)\n\nWhat needs to change: Macro call that should be transformed by WITH-READER-CASE", "input": "(with-reader-case 'some-name)", "output": "(defmacro WITH-READER-CASE ...)", "macroexpand": "(let ()\n (let ((#:previous-case182 (readtable-case *readtable*)))\n (setf (readtable-case *readtable*) 'some-name)\n (unwind-protect (progn)\n (setf (readtable-case *readtable*) #:previous-case182))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(c-assert self)\n\nPattern to recognize: Macro call that should be transformed by c-assert", "input": "(c-assert self)", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless self (c-break \"failed assertion: ~a\" (quote self))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.885} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deftag h* (body attrs &key) `(dynamic-tag :name (heading-depth-heading) ,@attrs ,@body))\n\nWrite a macro that addresses: Macro call that should be transformed by deftag", "input": "(deftag h* (body attrs &key) `(dynamic-tag :name (heading-depth-heading) ,@attrs ,@body))", "output": "(defmacro deftag (name (body attrs-var &rest ll) &body tag)\n \"Define NAME as a tag.\nIf NAME is not a keyword, it will also be defined as a macro with an\nimplicit `with-html'.\"\n (let ((definer\n (if (keywordp name)\n 'deftag/keyword\n 'deftag/macro)))\n `(,definer ,name (,body ,attrs-var ,@ll) ,@tag)))", "macroexpand": "(deftag/macro h* (body attrs &key) (sb-int:quasiquote (dynamic-tag :name (heading-depth-heading) #S(sb-impl::comma :expr attrs :kind 2) #S(sb-impl::comma :expr body :kind 2))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(bind (((:flet constant (x)) (declare (ignore x)) 42)) (ensure-same (constant 1) 42))\n\nIssue: Macro call that should be transformed by bind", "input": "(bind (((:flet constant (x)) (declare (ignore x)) 42)) (ensure-same (constant 1) 42))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(flet ((constant (x) (declare (ignore x)) (progn 42))) (progn (ensure-same (constant 1) 42)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield-binds (format nil \"~A ~{~A~^, ~}\" (sql-clause-name clause) (mapcar #'yield (expression-list-clause-expressions clause))))\n\nWhat needs to change: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~A ~{~A~^, ~}\" (sql-clause-name clause) (mapcar #'yield (expression-list-clause-expressions clause))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~A ~{~A~^, ~}\" (sql-clause-name clause) (mapcar (function yield) (expression-list-clause-expressions clause)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (= 1 (length (remove-if-not #'test-failure-p results))))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (= 1 (length (remove-if-not #'test-failure-p results))))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e241 1) (#:a242 (length (remove-if-not (function test-failure-p) results)))) (if (progn (= #:e241 #:a242)) (add-result (quote test-passed) :test-expr (quote (= 1 (length (remove-if-not (function test-failure-p) results))))) (process-failure (quote (= 1 (length (remove-if-not (function test-failure-p) results)))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (length (remove-if-not (function test-failure-p) results))) #:a242 (quote =) #:e241)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-decoder-simple-list-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :json-test))))\n\nIssue: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :json-test))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :json-test))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(dispatch-concurrently ,flow-context ,flow-list)))\n\nProblem: Macro call that should be transformed by with-flow-let-macro", "input": "(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(dispatch-concurrently ,flow-context ,flow-list)))", "output": "(defmacro with-flow-let-macro ((var flow) &body body)\n `(with-gensyms (,var)\n `(let ((,,var (list ,@,flow)))\n ,,@body)))", "macroexpand": "(with-gensyms (flow-list) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr flow-list :kind 0) (list #S(sb-impl::comma :expr flow :kind 2)))) #S(sb-impl::comma :expr (flow-lambda-macro (flow-context) (sb-int:quasiquote (dispatch-concurrently #S(sb-impl::comma :expr flow-context :kind 0) #S(sb-impl::comma :expr flow-list :kind 0)))) :kind 0))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-min nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-MIN", "input": "(collect-min nil (progn))", "output": "(defmacro COLLECT-MIN ...)", "macroexpand": "(common-lisp:let* ((#:generator-299 (generator (progn)))\n #:items-289\n (#:generator-297 (generator nil))\n #:numbers-288\n (#:number-291 nil)\n #:result-292)\n (declare (type generator #:generator-299)\n (type generator #:generator-297)\n (type (null-or t) #:result-292))\n (tagbody\n #:ll-300\n (setq #:items-289 (next-in #:generator-299 (go end)))\n (setq #:numbers-288 (next-in #:generator-297 (go end)))\n (if (or (null #:number-291) (> #:number-291 #:numbers-288))\n (setq #:number-291 #:numbers-288\n #:result-292 #:items-289))\n (go #:ll-300)\n end)\n (if (null #:number-291)\n (setq #:result-292 nil))\n #:result-292)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-instance* 'class (a b c) nil)\n\nWhat needs to change: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class (a b c) nil)", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(apply (function make-instance) (quote class) :a a :b b :c c nil)", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(dlet* 'some-name)\n\nIssue: Macro call that should be transformed by DLET*", "input": "(dlet* 'some-name)", "output": "(defmacro DLET* ...)", "macroexpand": "(dynamic-let* 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defgeneric* nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEFGENERIC*", "input": "(defgeneric* nil\n nil)", "output": "(defmacro DEFGENERIC* ...)", "macroexpand": "(defgeneric nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(match '(:name \\\"John\\\" :age 23) ((plist :name \\\"John\\\" :age age) age)) => 23\"))\n\nIssue: Macro call that should be transformed by match", "input": "(match '(:name \\\"John\\\" :age 23) ((plist :name \\\"John\\\" :age age) age)) => 23\"))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(let ((#:var153 (quote (:name |\"JOHN\"| :age 23)))) (declare (ignorable #:var153)) (%or (%if (plistp #:var153) (let ((#:g154 (plistname #:var153)) (#:g155 (plistage #:var153))) (declare (ignorable #:g154 #:g155)) (%or (let ((age #:g155)) (let ((|\"JOHN\"| #:g154)) age)) (fail))) (fail)) nil))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(incf 'some-name)\n\nPattern to recognize: Macro call that should be transformed by INCF", "input": "(incf 'some-name)", "output": "(defmacro INCF ...)", "macroexpand": "(let* ((#:some-name199 some-name) (#:new198 (+ 1 '#:some-name199)))\n (funcall #'(setf quote) #:new198 #:some-name199))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (node-slot shared) (del-proxy shared))\n\nProblem: Macro call that should be transformed by when", "input": "(when (node-slot shared) (del-proxy shared))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (node-slot shared) (del-proxy shared))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defhandler return-from (return-from name &optional (value nil value-p)) `(list ',return-from ',name ,@(when value-p `(,(e value)))))\n\nIssue: Macro call that should be transformed by defhandler", "input": "(defhandler return-from (return-from name &optional (value nil value-p)) `(list ',return-from ',name ,@(when value-p `(,(e value)))))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-return-from (return-from name &optional (value nil value-p)) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr return-from :kind 0)) (quote #S(sb-impl::comma :expr name :kind 0)) #S(sb-impl::comma :expr (when value-p (sb-int:quasiquote (#S(sb-impl::comma :expr (e value) :kind 0)))) :kind 2)))) (setf (gethash (quote return-from) *form-handler*) (quote hander-return-from)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ct-let* nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by CT-LET*", "input": "(ct-let* nil\n (progn))", "output": "(defmacro CT-LET* ...)", "macroexpand": "(cond (*within-captured-dynenv* (progn (progn)))\n (t\n (error\n \"No macrodynamic environment has been captured to establish CT-LET* bindings.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(product-of nil\n nil)\n\nIssue: Macro call that should be transformed by PRODUCT-OF", "input": "(product-of nil\n nil)", "output": "(defmacro PRODUCT-OF ...)", "macroexpand": "(lc (nil nil) multiply)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-csv-output-stream (csv-stream stream) (iter (for row in rows-of-items) (write-csv-row row :stream csv-stream)) (unless stream (get-output-stream-string csv-stream)))\n\nProblem: Macro call that should be transformed by with-csv-output-stream", "input": "(with-csv-output-stream (csv-stream stream) (iter (for row in rows-of-items) (write-csv-row row :stream csv-stream)) (unless stream (get-output-stream-string csv-stream)))", "output": "(defmacro with-csv-output-stream ((name inp) &body body)\n (alexandria:with-unique-names (opened?)\n `(multiple-value-bind (,name ,opened?) (%out-stream ,inp)\n (flet ((body () ,@body))\n (unwind-protect (body)\n (when (and ,name ,opened?)\n (close ,name)))))))", "macroexpand": "(multiple-value-bind (csv-stream #:opened?198) (%out-stream stream) (flet ((body nil (iter (for row in rows-of-items) (write-csv-row row :stream csv-stream)) (unless stream (get-output-stream-string csv-stream)))) (unwind-protect (body) (when (and csv-stream #:opened?198) (close csv-stream)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(dflet ((bar/mock (string) (cond ((equalp string \"Hello, World!\") 42)))) (is (eql 43 (foo/mock))) (is (eql 43 (foo/mock \"HELLO, WORLD!\"))))\n\nIssue: Macro call that should be transformed by dflet", "input": "(dflet ((bar/mock (string) (cond ((equalp string \"Hello, World!\") 42)))) (is (eql 43 (foo/mock))) (is (eql 43 (foo/mock \"HELLO, WORLD!\"))))", "output": "(defmacro dflet ((&rest definitions) &body body)\n \"Like FLET, but dynamically sets the FDEFINITIONS during the duration of\nthe BODY.\"\n `(progf\n ',(mapcar #'car definitions)\n (list\n ,.(mapcar (lambda (definition)\n `(lambda ,(cadr definition)\n ,@(cddr definition)))\n definitions))\n ,@body))", "macroexpand": "(progf (quote (bar/mock)) (list (lambda (string) (cond ((equalp string \"Hello, World!\") 42)))) (is (eql 43 (foo/mock))) (is (eql 43 (foo/mock \"HELLO, WORLD!\"))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-reader-syntax (set) (let ((set (er \"#{'a 'b 1 '(1) '(1) :test #'equal}\"))) (is-true (alexandria:setp set)) (is-true (member 'a set)) (is-true (member 'b set)) (is-true (member 1 set)) (is-false (member 2 set)) (is (= 1 (count '(1) set :test #'equal)))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-reader-syntax", "input": "(with-reader-syntax (set) (let ((set (er \"#{'a 'b 1 '(1) '(1) :test #'equal}\"))) (is-true (alexandria:setp set)) (is-true (member 'a set)) (is-true (member 'b set)) (is-true (member 1 set)) (is-false (member 2 set)) (is (= 1 (count '(1) set :test #'equal)))))", "output": "(defmacro with-reader-syntax (reader-macro-identifiers &body body)\n \"This macro is only made for use by read-and-eval functionality,\nand rather directed towards tests than users. So, do not export.\"\n (let ((identifiers (loop :for identifier :in reader-macro-identifiers\n :collect `(quote ,identifier))))\n `(let ((*array-function* 'make-t-array-from-initial-contents)\n (*hash-table-function* 'alexandria:plist-hash-table)\n (*get-val-function* 'get-val)\n (*get-val-array-function* 'cl:aref)\n (*set-function* 'cl:remove-duplicates)\n (*alists-are-lists* nil)\n (*plists-are-lists* nil)\n (*readtable* (%enable-reader-syntax *readtable* ,@identifiers)))\n ,@body)))", "macroexpand": "(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote set)))) (let ((set (er \"#{'a 'b 1 '(1) '(1) :test #'equal}\"))) (is-true (alexandria:setp set)) (is-true (member (quote a) set)) (is-true (member (quote b) set)) (is-true (member 1 set)) (is-false (member 2 set)) (is (= 1 (count (quote (1)) set :test (function equal))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(scond ((= 1 2) :no!))\n\nWrite a macro that addresses: Macro call that should be transformed by scond", "input": "(scond ((= 1 2) :no!))", "output": "(defmacro scond (&body clauses)\n \"Like COND, except each test-form is bound to IT (via SYMBOL-MACROLET) for the\nscope of the corresponsing clause. IT can be set with SETF.\"\n (labels ((rec (clauses)\n\t (if clauses\n\t\t (destructuring-bind ((test &body body) . rest) clauses\n\t\t (if body\n\t\t `(symbolic if ,test (progn ,@body) ,(rec rest))\n\t\t `(symbolic if ,test it ,(rec rest))))\n\t\t nil)))\n (rec clauses)))", "macroexpand": "(symbolic if (= 1 2) (progn :no!) nil)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defvar-unbound *pair-level* \"\")\n\nWhat needs to change: Macro call that should be transformed by defvar-unbound", "input": "(defvar-unbound *pair-level* \"\")", "output": "(defmacro defvar-unbound (variable-name documentation)\n \"Like DEFVAR, but the variable will be unbound rather than getting\nan initial value. This is useful for variables which should have no\nglobal value but might have a dynamically bound value.\"\n ;; stolen from comp.lang.lisp article by\n ;; \"prunesquallor@comcast.net\"\n `(eval-when (:load-toplevel :compile-toplevel :execute)\n (defvar ,variable-name)\n (setf (documentation ',variable-name 'variable)\n ,documentation)))", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *pair-level*) (setf (documentation (quote *pair-level*) (quote variable)) \"\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(match maybe m ((just x) (funcall f x)) (nothing nothing))\n\nWhat needs to change: Macro call that should be transformed by match", "input": "(match maybe m ((just x) (funcall f x)) (nothing nothing))", "output": "(defmacro match (adt obj &body clauses)\n \"Perform pattern matching on OBJ with (adt-type) ADT.\n\nEach clause must have the following syntax:\n\n := | '_'\n := '_'\n | ( *)\n := ( )\n\nThe symbol '_' denotes a wildcard, as well as a fallthough.\n\nNote that pattern matching is only shallow (patterns are one-level\ndeep).\n\"\n (assert (symbolp adt)\n (adt)\n \"MATCH requires a symbol for the first argument. Given ~S.\"\n adt)\n\n (let ((ctors (mapcar #'car (get-constructors adt)))\n (types (mapcar (lambda (clause)\n (ensure-car (car clause)))\n clauses))\n (once (gensym \"OBJ-\")))\n\n ;; Check for duplicate matches.\n (let ((dupes (duplicates types)))\n (when dupes\n (warn \"Duplicate matching clauses exist. Duplicate pattern ~\n constructors:~{ ~S~}\"\n dupes)))\n\n ;; Check for match exhaustiveness.\n (unless (some #'wild? types)\n (let ((diff (set-difference ctors types)))\n (when diff\n (warn \"Non-exhaustive match on ~A data ~\n type. Missing cases:~{ ~S~}\" adt diff))))\n\n ;; Generate the matching code.\n `(let ((,once ,obj))\n (check-type ,once ,adt)\n (etypecase ,once\n ,@(loop :for (bindings . body) :in clauses\n :collect (let ((type (ensure-car bindings)))\n (if (wild? type)\n `(t ,@body)\n `(,type\n (with-data ,(ensure-list bindings)\n ,once\n ,@body)))))))))", "macroexpand": "(let ((#:obj-148 m)) (check-type #:obj-148 maybe) (etypecase #:obj-148 (just (with-data (just x) #:obj-148 (funcall f x))) (nothing (with-data (nothing) #:obj-148 nothing))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(slet (car x) (incf it) (values it x))\n\nPattern to recognize: Macro call that should be transformed by slet", "input": "(slet (car x) (incf it) (values it x))", "output": "(defmacro slet (form &body body)\n \"Binds the FORM to IT (via SYMBOL-MACROLET) in the scope of the BODY. IT can\nbe set with SETF.\"\n `(symbolic ignore-first ,form (progn ,@body)))", "macroexpand": "(symbolic ignore-first (car x) (progn (incf it) (values it x)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defpackage nil nil)\n\nPattern to recognize: Macro call that should be transformed by DEFPACKAGE", "input": "(defpackage nil nil)", "output": "(defmacro DEFPACKAGE ...)", "macroexpand": "(common-lisp:defpackage nil\n (:use :adhoc :closer-mop :cl)\n (:shadowing-import-from :closer-mop\n #:defmethod\n #:standard-generic-function\n #:defgeneric\n #:standard-method\n #:standard-class)\n (:shadowing-import-from :adhoc #:defpackage #:variable #:the)\n ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dotimes (quote some-name))\n\nProblem: Macro call that should be transformed by DOTIMES", "input": "(dotimes (quote some-name))", "output": "(defmacro DOTIMES ...)", "macroexpand": "(do ((quote 0 (1+ quote))\n (#:g163 (the integer some-name)))\n ((>= quote #:g163) nil)\n (declare (type unsigned-byte quote)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-value-binding as ((var value) value) (declare (ignorable value)) (values NIL var))\n\nWrite a macro that addresses: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding as ((var value) value) (declare (ignorable value)) (values NIL var))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding as (var value) (let ((#:value132 (gensym #A((5) base-char . \"VALUE\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:value132 value) (loop for #:var131 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var131 #:value132))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:value132 :kind 0)))) #S(sb-impl::comma :expr nil :kind 0))) (let ((value #:value132)) (declare (ignorable value)) (declare (ignorable value)) (values nil var)))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause optimizing (form &key (test ''>) saving in) \"Finds the optimum value of an expression across the iteration. Refer to the manual for details.\" (let* ((candidate (gensym \"CANDIDATE-MAX\")) (test-form `(funcall ,test ,candidate ,*iteration-variable*)) (saving (ensure-list saving)) (in (ensure-list in))) (when (not (= (length saving) (length in))) (error \":saving and :in have different lengths!\")) (list* (make-simple-iteration :init form) (make-epilogue :form `(let ((,candidate ,form)) (when ,test-form (setf ,*iteration-variable* ,candidate ,@(loop :for x :in saving :for y :in in :collect y :collect x))))) (loop :for x :in saving :for y :in in :collect (make-simple-iteration :var y :init x)))))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause optimizing (form &key (test ''>) saving in) \"Finds the optimum value of an expression across the iteration. Refer to the manual for details.\" (let* ((candidate (gensym \"CANDIDATE-MAX\")) (test-form `(funcall ,test ,candidate ,*iteration-variable*)) (saving (ensure-list saving)) (in (ensure-list in))) (when (not (= (length saving) (length in))) (error \":saving and :in have different lengths!\")) (list* (make-simple-iteration :init form) (make-epilogue :form `(let ((,candidate ,form)) (when ,test-form (setf ,*iteration-variable* ,candidate ,@(loop :for x :in saving :for y :in in :collect y :collect x))))) (loop :for x :in saving :for y :in in :collect (make-simple-iteration :var y :init x)))))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro optimizing (form &key (test (quote (quote >))) saving in) \"Finds the optimum value of an expression across the iteration. Refer to the manual for details.\" (let* ((candidate (gensym \"CANDIDATE-MAX\")) (test-form (sb-int:quasiquote (funcall #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr candidate :kind 0) #S(sb-impl::comma :expr *iteration-variable* :kind 0)))) (saving (ensure-list saving)) (in (ensure-list in))) (when (not (= (length saving) (length in))) (error \":saving and :in have different lengths!\")) (list* (make-simple-iteration :init form) (make-epilogue :form (sb-int:quasiquote (let ((#S(sb-impl::comma :expr candidate :kind 0) #S(sb-impl::comma :expr form :kind 0))) (when #S(sb-impl::comma :expr test-form :kind 0) (setf #S(sb-impl::comma :expr *iteration-variable* :kind 0) #S(sb-impl::comma :expr candidate :kind 0) #S(sb-impl::comma :expr (loop :for x :in saving :for y :in in :collect y :collect x) :kind 2)))))) (loop :for x :in saving :for y :in in :collect (make-simple-iteration :var y :init x))))) (pushnew (quote optimizing) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:li :class nil \"Hello\"))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:li :class nil \"Hello\"))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:li :class nil \"Hello\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(integer-reader 1)\n\nWhat needs to change: Macro call that should be transformed by integer-reader", "input": "(integer-reader 1)", "output": "(defmacro integer-reader (bytes)\n \"Create a function to read integers from a binary stream.\"\n (let ((bits (* bytes 8)))\n (labels ((return-form (signed)\n (if signed\n `(if (logbitp ,(1- bits) result)\n (dpb result (byte ,(1- bits) 0) -1)\n result)\n `result))\n (generate-reader (signed)\n `(defun ,(integer-reader-name bytes signed) (socket)\n (declare (type stream socket)\n #.*optimize*)\n ,(if (= bytes 1)\n `(let ((result (the (unsigned-byte 8) (read-byte socket))))\n (declare (type (unsigned-byte 8) result))\n ,(return-form signed))\n `(let ((result 0))\n (declare (type (unsigned-byte ,bits) result))\n ,@(loop :for byte :from (1- bytes) :downto 0\n :collect `(setf (ldb (byte 8 ,(* 8 byte))\n result)\n (the (unsigned-byte 8)\n (read-byte socket))))\n ,(return-form signed))))))\n `(progn\n ;; This causes weird errors on SBCL in some circumstances. Disabled for now.\n ;; (declaim (inline ,(integer-reader-name bytes t)\n ;; ,(integer-reader-name bytes nil)))\n (declaim (ftype (function (t) (signed-byte ,bits))\n ,(integer-reader-name bytes t)))\n ,(generate-reader t)\n (declaim (ftype (function (t) (unsigned-byte ,bits))\n ,(integer-reader-name bytes nil)))\n ,(generate-reader nil)))))", "macroexpand": "(progn (declaim (ftype (function (t) (signed-byte 8)) read-int1)) (defun read-int1 (socket) (declare (type stream socket) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (let ((result (the (unsigned-byte 8) (read-byte socket)))) (declare (type (unsigned-byte 8) result)) (if (logbitp 7 result) (dpb result (byte 7 0) -1) result))) (declaim (ftype (function (t) (unsigned-byte 8)) read-uint1)) (defun read-uint1 (socket) (declare (type stream socket) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (let ((result (the (unsigned-byte 8) (read-byte socket)))) (declare (type (unsigned-byte 8) result)) result)))", "category": "dsl", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(some-<>> nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by SOME-<>>", "input": "(some-<>> nil (progn))", "output": "(defmacro SOME-<>> ...)", "macroexpand": "(let* ((#:g132 nil))\n (if (null #:g132)\n nil\n (->> #:g132 (progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-custom-var (:real *real-handler*) (constantly 0) \"Designator for a function of 1 string argument (real token).\")\n\nProblem: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:real *real-handler*) (constantly 0) \"Designator for a function of 1 string argument (real token).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*real-handler* . :real)) *custom-vars* :test (function equal)) (defvar *real-handler* (constantly 0) \"Designator for a function of 1 string argument (real token).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(mapcar (lambda (f) `(function ,(force-first f))) bindings)\n\nProblem: Macro call that should be transformed by m", "input": "(mapcar (lambda (f) `(function ,(force-first f))) bindings)", "output": "(defmacro m (form &environment *env*)\n (e form))", "macroexpand": "(mapcar (lambda (f) (sb-int:quasiquote (function #S(sb-impl::comma :expr (force-first f) :kind 0)))) bindings)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ensure-gethash (car tail) table (cadr tail))\n\nWrite a macro that addresses: Macro call that should be transformed by ensure-gethash", "input": "(ensure-gethash (car tail) table (cadr tail))", "output": "(defmacro ensure-gethash (key hash-table &optional default)\n \"Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT\nunder key before returning it. Secondary return value is true if key was\nalready in the table.\"\n (once-only (key hash-table)\n (with-unique-names (value presentp)\n `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table)\n (if ,presentp\n (values ,value ,presentp)\n (values (setf (gethash ,key ,hash-table) ,default) nil))))))", "macroexpand": "(let ((#:n-key-155 (car tail)) (#:n-hash-table-156 table)) (multiple-value-bind (#:value157 #:foundp158) (gethash #:n-key-155 #:n-hash-table-156) (if #:foundp158 (values #:value157 t) (values (setf (gethash #:n-key-155 #:n-hash-table-156) (cadr tail)) nil))))", "category": "anaphoric", "technique": "once-only,anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(make-name-transformer nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by MAKE-NAME-TRANSFORMER", "input": "(make-name-transformer nil :key nil)", "output": "(defmacro MAKE-NAME-TRANSFORMER ...)", "macroexpand": "(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol nil :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cond->>\n nil\n nil)\n\nIssue: Macro call that should be transformed by COND->>", "input": "(cond->>\n nil\n nil)", "output": "(defmacro COND->> ...)", "macroexpand": "(let* ((#:var162 nil)\n (#:var163\n (if nil\n (->>\n #:var162)\n #:var162)))\n #:var163)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(auto-permute-typecase nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE", "input": "(auto-permute-typecase nil\n (progn))", "output": "(defmacro AUTO-PERMUTE-TYPECASE ...)", "macroexpand": "(typecase nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-effective-qualifier generic-function qualifier (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list ,@body)))\n\nIssue: Macro call that should be transformed by with-effective-qualifier", "input": "(with-effective-qualifier generic-function qualifier (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list ,@body)))", "output": "(defmacro with-effective-qualifier (gf-name qualifier &body body)\n \"take generic function and a symbol bound to a qualifier and mask that symbol with the effective qualifier.\n\nThe effective qualifier is the default qualifier for the given generic function should there be one defined by\na define-hook-generic form.\"\n `(let ((,qualifier\n (effective-qualifier ,gf-name ,qualifier)))\n ,@body))", "macroexpand": "(let ((qualifier (effective-qualifier generic-function qualifier))) (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (sb-int:quasiquote (%lay-method-base-for-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-reader-syntax (get-val array hash-table) (with-output-to-string (*error-output*) (is (char= #\\a (er \"(with-env [str 0])\"))) (is (eq 'a (er \"(with-env [vec 0])\"))) (is (= 3 (er \"(with-env [arr 0 2])\"))) (is (eq 'd (er \"(with-env [list 3])\"))) (is (eq 'b (er \"(with-env [ht 'a])\"))) (is (eq nil (er \"(with-env [ht-eq (string (alexandria:copy-array \\\"a\\\"))])\"))) (is (equal \"b\" (er \"(with-env [ht-equalp (copy-list '(4 5 6))])\"))) (is (= 1 (er \"(with-env [assoc-list 'a])\"))) (is (eq nil (er \"(with-env [assoc-list 'c])\"))) (is (= 5 (er \"(with-env [plist :c])\"))) (is (eq nil (er \"(with-env [plist :e])\"))) (is (eq 3 (er \"(with-env [clos-object 'a])\"))) (is (eq 3 (er \"(with-env [struct 'a])\")))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-reader-syntax", "input": "(with-reader-syntax (get-val array hash-table) (with-output-to-string (*error-output*) (is (char= #\\a (er \"(with-env [str 0])\"))) (is (eq 'a (er \"(with-env [vec 0])\"))) (is (= 3 (er \"(with-env [arr 0 2])\"))) (is (eq 'd (er \"(with-env [list 3])\"))) (is (eq 'b (er \"(with-env [ht 'a])\"))) (is (eq nil (er \"(with-env [ht-eq (string (alexandria:copy-array \\\"a\\\"))])\"))) (is (equal \"b\" (er \"(with-env [ht-equalp (copy-list '(4 5 6))])\"))) (is (= 1 (er \"(with-env [assoc-list 'a])\"))) (is (eq nil (er \"(with-env [assoc-list 'c])\"))) (is (= 5 (er \"(with-env [plist :c])\"))) (is (eq nil (er \"(with-env [plist :e])\"))) (is (eq 3 (er \"(with-env [clos-object 'a])\"))) (is (eq 3 (er \"(with-env [struct 'a])\")))))", "output": "(defmacro with-reader-syntax (reader-macro-identifiers &body body)\n \"This macro is only made for use by read-and-eval functionality,\nand rather directed towards tests than users. So, do not export.\"\n (let ((identifiers (loop :for identifier :in reader-macro-identifiers\n :collect `(quote ,identifier))))\n `(let ((*array-function* 'make-t-array-from-initial-contents)\n (*hash-table-function* 'alexandria:plist-hash-table)\n (*get-val-function* 'get-val)\n (*get-val-array-function* 'cl:aref)\n (*set-function* 'cl:remove-duplicates)\n (*alists-are-lists* nil)\n (*plists-are-lists* nil)\n (*readtable* (%enable-reader-syntax *readtable* ,@identifiers)))\n ,@body)))", "macroexpand": "(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote get-val) (quote array) (quote hash-table)))) (with-output-to-string (*error-output*) (is (char= #\\LATIN_SMALL_LETTER_A (er \"(with-env [str 0])\"))) (is (eq (quote a) (er \"(with-env [vec 0])\"))) (is (= 3 (er \"(with-env [arr 0 2])\"))) (is (eq (quote d) (er \"(with-env [list 3])\"))) (is (eq (quote b) (er \"(with-env [ht 'a])\"))) (is (eq nil (er \"(with-env [ht-eq (string (alexandria:copy-array \\\"a\\\"))])\"))) (is (equal \"b\" (er \"(with-env [ht-equalp (copy-list '(4 5 6))])\"))) (is (= 1 (er \"(with-env [assoc-list 'a])\"))) (is (eq nil (er \"(with-env [assoc-list 'c])\"))) (is (= 5 (er \"(with-env [plist :c])\"))) (is (eq nil (er \"(with-env [plist :e])\"))) (is (eq 3 (er \"(with-env [clos-object 'a])\"))) (is (eq 3 (er \"(with-env [struct 'a])\")))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(assert-values (\"changed foo = 1\") (foo 1) (foo+1 2) (bar 'nothing) (bar-1 'nothing))\n\nPattern to recognize: Macro call that should be transformed by assert-values", "input": "(assert-values (\"changed foo = 1\") (foo 1) (foo+1 2) (bar 'nothing) (bar-1 'nothing))", "output": "(defmacro assert-values ((desc) &body objects-and-values)\n `(progn\n (trc ,desc)\n ,@(loop for (obj val) in objects-and-values\n\t collect `(assert (eql (value ,obj) ,val)))))", "macroexpand": "(progn (trc \"changed foo = 1\") (assert (eql (value foo) 1)) (assert (eql (value foo+1) 2)) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-definition-resolver source-transform (designator) (cond ((and (listp designator) (eql 'cl:setf (car designator))) (sb-int:info :function :source-transform (second designator))) ((symbolp designator) (sb-int:info :function :source-transform designator))))\n\nIssue: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver source-transform (designator) (cond ((and (listp designator) (eql 'cl:setf (car designator))) (sb-int:info :function :source-transform (second designator))) ((symbolp designator) (sb-int:info :function :source-transform designator))))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver source-transform (source-transform #:package149) (when (ignore-errors (let ((designator source-transform)) (cond ((and (listp designator) (eql (quote setf) (car designator))) (sb-int:info :function :source-transform (second designator))) ((symbolp designator) (sb-int:info :function :source-transform designator))))) (list (make-instance (quote source-transform) :designator source-transform :package #:package149))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-rules 'some-name)\n\nProblem: Macro call that should be transformed by WITH-RULES", "input": "(with-rules 'some-name)", "output": "(defmacro WITH-RULES ...)", "macroexpand": "(dolist ('some-name (alexandria:hash-table-keys cl-rules.core::*rules*)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(deftag ul* (body attrs &key &allow-other-keys) \"
    with every form (except
  • ) in BODY auto-wrapped into a
  • .\" `(:ul ,@attrs ,@(loop for form in body when (and (listp form) (eq :li (first form))) collect form else collect `(:li ,form))))\n\nWhat needs to change: Macro call that should be transformed by deftag", "input": "(deftag ul* (body attrs &key &allow-other-keys) \"
      with every form (except
    • ) in BODY auto-wrapped into a
    • .\" `(:ul ,@attrs ,@(loop for form in body when (and (listp form) (eq :li (first form))) collect form else collect `(:li ,form))))", "output": "(defmacro deftag (name (body attrs-var &rest ll) &body tag)\n \"Define NAME as a tag.\nIf NAME is not a keyword, it will also be defined as a macro with an\nimplicit `with-html'.\"\n (let ((definer\n (if (keywordp name)\n 'deftag/keyword\n 'deftag/macro)))\n `(,definer ,name (,body ,attrs-var ,@ll) ,@tag)))", "macroexpand": "(deftag/macro ul* (body attrs &key &allow-other-keys) \"
        with every form (except
      • ) in BODY auto-wrapped into a
      • .\" (sb-int:quasiquote (:ul #S(sb-impl::comma :expr attrs :kind 2) #S(sb-impl::comma :expr (loop for form in body when (and (listp form) (eq :li (first form))) collect form else collect (sb-int:quasiquote (:li #S(sb-impl::comma :expr form :kind 0)))) :kind 2))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lambda-coro\n nil)\n\nProblem: Macro call that should be transformed by LAMBDA-CORO", "input": "(lambda-coro\n nil)", "output": "(defmacro LAMBDA-CORO ...)", "macroexpand": "(progn\n (defcoroutine #:name125\n (#:arg126)\n (macrolet ((yield (form)\n (let ((g!-it (gensym \"IT\")))\n `(progn\n (let ((,g!-it ,form))\n (cl-coroutine:yield ,g!-it))\n ,'#:arg126)))\n (last-yield-value ()\n '#:arg126))\n nil\n (coexit!)))\n (make-coroutine '#:name125))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(next-ffi)\n\nIssue: Macro call that should be transformed by next-ffi", "input": "(next-ffi)", "output": "(defmacro next-ffi ()\n (with-gensyms (next)\n `(let ((,next (cadr fields)))\n (foreign-to-ffi\n (and ,next (foreign-type ,next))\n (cdr names)\n (cdr params)\n (cdr fields)\n body))))", "macroexpand": "(let ((#:next192 (cadr fields))) (foreign-to-ffi (and #:next192 (foreign-type #:next192)) (cdr names) (cdr params) (cdr fields) body))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(signal-reader-error \"Incomplete regex comment starting with '(#'\")\n\nProblem: Macro call that should be transformed by signal-reader-error", "input": "(signal-reader-error \"Incomplete regex comment starting with '(#'\")", "output": "(defmacro signal-reader-error (format-control &rest format-arguments)\n \"Like ERROR but signals a SIMPLE-READER-ERROR for the stream\n*STREAM*.\"\n `(error 'simple-reader-error\n :stream *stream*\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote simple-reader-error) :stream *stream* :format-control \"Incomplete regex comment starting with '(#'\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(some-<>\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by SOME-<>", "input": "(some-<>\n 'some-name)", "output": "(defmacro SOME-<> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(gen-lambda-with-sticky-stop () (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop))))\n\nWhat needs to change: Macro call that should be transformed by gen-lambda", "input": "(gen-lambda-with-sticky-stop () (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop))))", "output": "(defmacro gen-lambda (params &body rest)\n \"Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions.\"\n `(let ((values-handler (create-values-handler)))\n (declare (ignorable values-handler))\n (make-instance \n 'basic-generator \n :function (lambda ,params ,@rest))))", "macroexpand": "(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (let ((res (funcall source-func))) (if (funcall predicate res) res (sticky-stop)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda* nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by LAMBDA*", "input": "(lambda* nil\n :key\n nil)", "output": "(defmacro LAMBDA* ...)", "macroexpand": "(lambda ()\n (with-yield\n :key\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-gensyms (num items position not-preceded-by string item new-mode until advancing) `(labels ((advance (,num) (setf ,position-place (+ ,position-place ,num)) t) (peek-any (,items &key ,not-preceded-by) (incf *scan-calls*) (let* ((,items (if (stringp ,items) (coerce ,items 'list) ,items)) (,not-preceded-by (if (characterp ,not-preceded-by) (string ,not-preceded-by) ,not-preceded-by)) (,position ,position-place) (,string ,string-param)) (let ((,item (and (< ,position (length ,string)) (find ,string ,items :test #'(lambda (,string ,item) #+nil (format t \"looking for ~S in ~S starting at ~S~%\" ,item ,string ,position) (if (characterp ,item) (char= (elt ,string ,position) ,item) (search ,item ,string :start2 ,position :end2 (min (length ,string) (+ ,position (length ,item)))))))))) (if (characterp ,item) (setf ,item (string ,item))) (if (if ,item (if ,not-preceded-by (if (>= (- ,position (length ,not-preceded-by)) 0) (not (string= (subseq ,string (- ,position (length ,not-preceded-by)) ,position) ,not-preceded-by)) t) t) nil) ,item (progn (and *reset-position* (setf ,position-place *reset-position*)) nil))))) (scan-any (,items &key ,not-preceded-by) (let ((,item (peek-any ,items :not-preceded-by ,not-preceded-by))) (and ,item (advance (length ,item))))) (peek (,item &key ,not-preceded-by) (peek-any (list ,item) :not-preceded-by ,not-preceded-by)) (scan (,item &key ,not-preceded-by) (scan-any (list ,item) :not-preceded-by ,not-preceded-by))) (macrolet ((set-mode (,new-mode &key ,until (,advancing t)) (list 'progn (list 'setf ',mode-place ,new-mode) (list 'setf ',mode-wait-place (list 'lambda (list ',position) (list 'let (list (list '*reset-position* ',position)) (list 'values ,until ,advancing))))))) ,@body)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-gensyms", "input": "(with-gensyms (num items position not-preceded-by string item new-mode until advancing) `(labels ((advance (,num) (setf ,position-place (+ ,position-place ,num)) t) (peek-any (,items &key ,not-preceded-by) (incf *scan-calls*) (let* ((,items (if (stringp ,items) (coerce ,items 'list) ,items)) (,not-preceded-by (if (characterp ,not-preceded-by) (string ,not-preceded-by) ,not-preceded-by)) (,position ,position-place) (,string ,string-param)) (let ((,item (and (< ,position (length ,string)) (find ,string ,items :test #'(lambda (,string ,item) #+nil (format t \"looking for ~S in ~S starting at ~S~%\" ,item ,string ,position) (if (characterp ,item) (char= (elt ,string ,position) ,item) (search ,item ,string :start2 ,position :end2 (min (length ,string) (+ ,position (length ,item)))))))))) (if (characterp ,item) (setf ,item (string ,item))) (if (if ,item (if ,not-preceded-by (if (>= (- ,position (length ,not-preceded-by)) 0) (not (string= (subseq ,string (- ,position (length ,not-preceded-by)) ,position) ,not-preceded-by)) t) t) nil) ,item (progn (and *reset-position* (setf ,position-place *reset-position*)) nil))))) (scan-any (,items &key ,not-preceded-by) (let ((,item (peek-any ,items :not-preceded-by ,not-preceded-by))) (and ,item (advance (length ,item))))) (peek (,item &key ,not-preceded-by) (peek-any (list ,item) :not-preceded-by ,not-preceded-by)) (scan (,item &key ,not-preceded-by) (scan-any (list ,item) :not-preceded-by ,not-preceded-by))) (macrolet ((set-mode (,new-mode &key ,until (,advancing t)) (list 'progn (list 'setf ',mode-place ,new-mode) (list 'setf ',mode-wait-place (list 'lambda (list ',position) (list 'let (list (list '*reset-position* ',position)) (list 'values ,until ,advancing))))))) ,@body)))", "output": "(defmacro with-gensyms ((&rest names) &body body)\n `(let ,(mapcar #'(lambda (name)\n (list name `(make-symbol ,(symbol-name name)))) names)\n ,@body))", "macroexpand": "(let ((num (gensym #A((3) base-char . \"NUM\"))) (items (gensym #A((5) base-char . \"ITEMS\"))) (position (gensym #A((8) base-char . \"POSITION\"))) (not-preceded-by (gensym #A((15) base-char . \"NOT-PRECEDED-BY\"))) (string (gensym #A((6) base-char . \"STRING\"))) (item (gensym #A((4) base-char . \"ITEM\"))) (new-mode (gensym #A((8) base-char . \"NEW-MODE\"))) (until (gensym #A((5) base-char . \"UNTIL\"))) (advancing (gensym #A((9) base-char . \"ADVANCING\")))) (sb-int:quasiquote (labels ((advance (#S(sb-impl::comma :expr num :kind 0)) (setf #S(sb-impl::comma :expr position-place :kind 0) (+ #S(sb-impl::comma :expr position-place :kind 0) #S(sb-impl::comma :expr num :kind 0))) t) (peek-any (#S(sb-impl::comma :expr items :kind 0) &key #S(sb-impl::comma :expr not-preceded-by :kind 0)) (incf *scan-calls*) (let* ((#S(sb-impl::comma :expr items :kind 0) (if (stringp #S(sb-impl::comma :expr items :kind 0)) (coerce #S(sb-impl::comma :expr items :kind 0) (quote list)) #S(sb-impl::comma :expr items :kind 0))) (#S(sb-impl::comma :expr not-preceded-by :kind 0) (if (characterp #S(sb-impl::comma :expr not-preceded-by :kind 0)) (string #S(sb-impl::comma :expr not-preceded-by :kind 0)) #S(sb-impl::comma :expr not-preceded-by :kind 0))) (#S(sb-impl::comma :expr position :kind 0) #S(sb-impl::comma :expr position-place :kind 0)) (#S(sb-impl::comma :expr string :kind 0) #S(sb-impl::comma :expr string-param :kind 0))) (let ((#S(sb-impl::comma :expr item :kind 0) (and (< #S(sb-impl::comma :expr position :kind 0) (length #S(sb-impl::comma :expr string :kind 0))) (find #S(sb-impl::comma :expr string :kind 0) #S(sb-impl::comma :expr items :kind 0) :test (function (lambda (#S(sb-impl::comma :expr string :kind 0) #S(sb-impl::comma :expr item :kind 0)) (if (characterp #S(sb-impl::comma :expr item :kind 0)) (char= (elt #S(sb-impl::comma :expr string :kind 0) #S(sb-impl::comma :expr position :kind 0)) #S(sb-impl::comma :expr item :kind 0)) (search #S(sb-impl::comma :expr item :kind 0) #S(sb-impl::comma :expr string :kind 0) :start2 #S(sb-impl::comma :expr position :kind 0) :end2 (min (length #S(sb-impl::comma :expr string :kind 0)) (+ #S(sb-impl::comma :expr position :kind 0) (length #S(sb-impl::comma :expr item :kind 0)))))))))))) (if (characterp #S(sb-impl::comma :expr item :kind 0)) (setf #S(sb-impl::comma :expr item :kind 0) (string #S(sb-impl::comma :expr item :kind 0)))) (if (if #S(sb-impl::comma :expr item :kind 0) (if #S(sb-impl::comma :expr not-preceded-by :kind 0) (if (>= (- #S(sb-impl::comma :expr position :kind 0) (length #S(sb-impl::comma :expr not-preceded-by :kind 0))) 0) (not (string= (subseq #S(sb-impl::comma :expr string :kind 0) (- #S(sb-impl::comma :expr position :kind 0) (length #S(sb-impl::comma :expr not-preceded-by :kind 0))) #S(sb-impl::comma :expr position :kind 0)) #S(sb-impl::comma :expr not-preceded-by :kind 0))) t) t) nil) #S(sb-impl::comma :expr item :kind 0) (progn (and *reset-position* (setf #S(sb-impl::comma :expr position-place :kind 0) *reset-position*)) nil))))) (scan-any (#S(sb-impl::comma :expr items :kind 0) &key #S(sb-impl::comma :expr not-preceded-by :kind 0)) (let ((#S(sb-impl::comma :expr item :kind 0) (peek-any #S(sb-impl::comma :expr items :kind 0) :not-preceded-by #S(sb-impl::comma :expr not-preceded-by :kind 0)))) (and #S(sb-impl::comma :expr item :kind 0) (advance (length #S(sb-impl::comma :expr item :kind 0)))))) (peek (#S(sb-impl::comma :expr item :kind 0) &key #S(sb-impl::comma :expr not-preceded-by :kind 0)) (peek-any (list #S(sb-impl::comma :expr item :kind 0)) :not-preceded-by #S(sb-impl::comma :expr not-preceded-by :kind 0))) (scan (#S(sb-impl::comma :expr item :kind 0) &key #S(sb-impl::comma :expr not-preceded-by :kind 0)) (scan-any (list #S(sb-impl::comma :expr item :kind 0)) :not-preceded-by #S(sb-impl::comma :expr not-preceded-by :kind 0)))) (macrolet ((set-mode (#S(sb-impl::comma :expr new-mode :kind 0) &key #S(sb-impl::comma :expr until :kind 0) (#S(sb-impl::comma :expr advancing :kind 0) t)) (list (quote progn) (list (quote setf) (quote #S(sb-impl::comma :expr mode-place :kind 0)) #S(sb-impl::comma :expr new-mode :kind 0)) (list (quote setf) (quote #S(sb-impl::comma :expr mode-wait-place :kind 0)) (list (quote lambda) (list (quote #S(sb-impl::comma :expr position :kind 0))) (list (quote let) (list (list (quote *reset-position*) (quote #S(sb-impl::comma :expr position :kind 0)))) (list (quote values) #S(sb-impl::comma :expr until :kind 0) #S(sb-impl::comma :expr advancing :kind 0)))))))) #S(sb-impl::comma :expr body :kind 2)))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (loop for i from 0 below offset by pad-len do (replace out pad :start1 i :end1 offset)))\n\nProblem: Macro call that should be transformed by lret", "input": "(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (loop for i from 0 below offset by pad-len do (replace out pad :start1 i :end1 offset)))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (loop for i from 0 below offset by pad-len do (replace out pad :start1 i :end1 offset)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-dot nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by WITH-DOT", "input": "(with-dot nil\n :key\n nil)", "output": "(defmacro with-dot (() &body body)\n `(progn ,@(replace-dot-calls body)))", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defgeneric nil :key nil)\n\nIssue: Macro call that should be transformed by DEFGENERIC", "input": "(defgeneric nil :key nil)", "output": "(defmacro DEFGENERIC ...)", "macroexpand": "(common-lisp:defgeneric nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"22003\" numeric-value-out-of-range data-exception)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"22003\" numeric-value-out-of-range data-exception)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition numeric-value-out-of-range (data-exception) nil) (setf (gethash \"22003\" *error-table*) (quote numeric-value-out-of-range)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-instance* 'class (b c) :x x (when something (list :a a)))\n\nWhat needs to change: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class (b c) :x x (when something (list :a a)))", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(apply (function make-instance) (quote class) :b b :c c :x x (when something (list :a a)))", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9624999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(none-of nil\n (progn))\n\nProblem: Macro call that should be transformed by NONE-OF", "input": "(none-of nil\n (progn))", "output": "(defmacro NONE-OF ...)", "macroexpand": "(lc (nil (progn)) never)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"40003\" statement-completion-unknown transaction-rollback)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"40003\" statement-completion-unknown transaction-rollback)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition statement-completion-unknown (transaction-rollback) nil) (setf (gethash \"40003\" *error-table*) (quote statement-completion-unknown)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(integer-writer 1)\n\nWrite a macro that addresses: Macro call that should be transformed by integer-writer", "input": "(integer-writer 1)", "output": "(defmacro integer-writer (bytes)\n \"Create a function to write integers to a binary stream.\"\n (let ((bits (* 8 bytes)))\n `(progn\n (declaim (inline ,(integer-writer-name bytes t)\n ,(integer-writer-name bytes nil)))\n (defun ,(integer-writer-name bytes nil) (socket value)\n (declare (type stream socket)\n (type (unsigned-byte ,bits) value)\n #.*optimize*)\n ,@(if (= bytes 1)\n `((write-byte value socket))\n (loop :for byte :from (1- bytes) :downto 0\n :collect `(write-byte (ldb (byte 8 ,(* byte 8)) value)\n socket)))\n (values))\n (defun ,(integer-writer-name bytes t) (socket value)\n (declare (type stream socket)\n (type (signed-byte ,bits) value)\n #.*optimize*)\n ,@(if (= bytes 1)\n `((write-byte (ldb (byte 8 0) value) socket))\n (loop :for byte :from (1- bytes) :downto 0\n :collect `(write-byte (ldb (byte 8 ,(* byte 8)) value)\n socket)))\n (values)))))", "macroexpand": "(progn (declaim (inline write-int1 write-uint1)) (defun write-uint1 (socket value) (declare (type stream socket) (type (unsigned-byte 8) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte value socket) (values)) (defun write-int1 (socket value) (declare (type stream socket) (type (signed-byte 8) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 0) value) socket) (values)))", "category": "efficiency", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-lock (lru-pool-lock pool) (evict-tail pool))\n\nProblem: Macro call that should be transformed by with-lock", "input": "(with-lock (lru-pool-lock pool) (evict-tail pool))", "output": "(defmacro with-lock (lock &body body)\n (declare (ignorable lock))\n #+thread-support `(bt2:with-lock-held (,lock)\n ,@body)\n #-thread-support `(progn ,@body))", "macroexpand": "(bt2:with-lock-held ((lru-pool-lock pool)) (evict-tail pool))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-active-layers* nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-ACTIVE-LAYERS*", "input": "(with-active-layers* nil\n :key\n nil)", "output": "(defmacro WITH-ACTIVE-LAYERS* ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ematch0 args (nil nil) ((list* '&key rest) (list* '&key (process-keyword-args rest))) ((list* '&aux rest) args) ((list* name rest) (list* name (process-rest-args rest))))\n\nWhat needs to change: Macro call that should be transformed by ematch0", "input": "(ematch0 args (nil nil) ((list* '&key rest) (list* '&key (process-keyword-args rest))) ((list* '&aux rest) args) ((list* name rest) (list* name (process-rest-args rest))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 args (nil nil) ((list* (quote &key) rest) (list* (quote &key) (process-keyword-args rest))) ((list* (quote &aux) rest) args) ((list* name rest) (list* name (process-rest-args rest))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is-false nil)\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is-false nil)", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:value188 nil)) (if #:value188 (process-failure (quote nil) \"~S returned the value ~S, which is true\" (quote nil) #:value188) (add-result (quote test-passed) :test-expr (quote nil))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-env (setp 2 [plist :c]))\n\nWhat needs to change: Macro call that should be transformed by with-env", "input": "(with-env (setp 2 [plist :c]))", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g136) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g136 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) (setp 2 [plist :c]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g136)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-type-map compiler-macro cl:compiler-macro)\n\nWhat needs to change: Macro call that should be transformed by define-simple-type-map", "input": "(define-simple-type-map compiler-macro cl:compiler-macro)", "output": "(defmacro define-simple-type-map (class type)\n `(defmethod type ((,class ,class))\n ',type))", "macroexpand": "(defmethod type ((compiler-macro compiler-macro)) (quote common-lisp:compiler-macro))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-generator 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-GENERATOR", "input": "(with-generator 'some-name)", "output": "(defmacro WITH-GENERATOR ...)", "macroexpand": "(let ((quote some-name))\n (assert (typep quote 'generator!))\n (unwind-protect (progn) (stop quote)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun/1 atan2 (x y) (atan x y))\n\nProblem: Macro call that should be transformed by defun/1", "input": "(defun/1 atan2 (x y) (atan x y))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun atan2 (x y) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (atan x y)) (defparameter atan2 (vacietis.c:mkptr& (symbol-function (quote atan2)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-reader-error \"No character for char-code #x~X\" code)\n\nIssue: Macro call that should be transformed by signal-reader-error", "input": "(signal-reader-error \"No character for char-code #x~X\" code)", "output": "(defmacro signal-reader-error (format-control &rest format-arguments)\n \"Like ERROR but signals a SIMPLE-READER-ERROR for the stream\n*STREAM*.\"\n `(error 'simple-reader-error\n :stream *stream*\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote simple-reader-error) :stream *stream* :format-control \"No character for char-code #x~X\" :format-arguments (list code))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(expand-selector selector)\n\nWhat needs to change: Macro call that should be transformed by expand-selector", "input": "(expand-selector selector)", "output": "(defmacro expand-selector (&rest args)\n `(let ((result ,@args))\n (cond ((typep result 'kv-container) result)\n\t ((typep result 'pair) result)\n\t ((null result) result)\n\t (t ($+ result)))))", "macroexpand": "(let ((result selector)) (cond ((typep result (quote kv-container)) result) ((typep result (quote pair)) result) ((null result) result) (t ($+ result))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-definition-resolver method-combination (designator) (find-method #'sb-mop:find-method-combination nil (list (find-class 'cl:generic-function) `(eql ,designator) T) nil))\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver method-combination (designator) (find-method #'sb-mop:find-method-combination nil (list (find-class 'cl:generic-function) `(eql ,designator) T) nil))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver method-combination (method-combination #:package143) (when (ignore-errors (let ((designator method-combination)) (find-method (common-lisp:function sb-mop:find-method-combination) nil (list (find-class (quote common-lisp:generic-function)) (sb-int:quasiquote (eql #S(sb-impl::comma :expr designator :kind 0))) t) nil))) (list (make-instance (quote method-combination) :designator method-combination :package #:package143))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-definition-resolver vop (designator) (sb-c::vop-parse-or-lose designator))\n\nIssue: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver vop (designator) (sb-c::vop-parse-or-lose designator))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver vop (vop #:package150) (when (ignore-errors (let ((designator vop)) (sb-c::vop-parse-or-lose designator))) (list (make-instance (quote vop) :designator vop :package #:package150))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-custom-var (:array-element *array-element-handler*))\n\nProblem: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:array-element *array-element-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*array-element-handler* . :array-element)) *custom-vars* :test (function equal)) (defvar *array-element-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-symbol-access\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-SYMBOL-ACCESS", "input": "(with-symbol-access\n nil)", "output": "(defmacro WITH-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* t))\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n($)\n\nWhat needs to change: Macro call that should be transformed by $", "input": "($)", "output": "(defmacro $ ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'init-accumulator :array-member #'accumulator-add :end-of-array #'accumulator-get-sequence :array-type 'vector :beginning-of-object #'init-accumulator-and-prototype :object-key #'accumulator-add-key-or-set-prototype :object-value #'accumulator-add-value-or-set-prototype :end-of-object #'accumulator-get-object :beginning-of-string #'init-string-stream-accumulator :string-char #'string-stream-accumulator-add :end-of-string #'string-stream-accumulator-get :aggregate-scope (union *aggregate-scope-variables* '(*accumulator* *accumulator-last*)) :object-scope (union *object-scope-variables* '(*prototype* *json-array-type*)) :internal-decoder #'decode-json)\n\nWrite a macro that addresses: Macro call that should be transformed by set-custom-vars", "input": "(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'init-accumulator :array-member #'accumulator-add :end-of-array #'accumulator-get-sequence :array-type 'vector :beginning-of-object #'init-accumulator-and-prototype :object-key #'accumulator-add-key-or-set-prototype :object-value #'accumulator-add-value-or-set-prototype :end-of-object #'accumulator-get-object :beginning-of-string #'init-string-stream-accumulator :string-char #'string-stream-accumulator-add :end-of-string #'string-stream-accumulator-get :aggregate-scope (union *aggregate-scope-variables* '(*accumulator* *accumulator-last*)) :object-scope (union *object-scope-variables* '(*prototype* *json-array-type*)) :internal-decoder #'decode-json)", "output": "(defmacro set-custom-vars (&rest key-args)\n `(setq\n ,@(loop for (supplied-key value) on key-args by #'cddr\n append (loop for (var . var-key) in *custom-vars*\n thereis (if (eql var-key supplied-key)\n (list var value))))))", "macroexpand": "(setq *integer-handler* (function parse-number) *real-handler* (function parse-number) *boolean-handler* (function json-boolean-to-lisp) *beginning-of-array-handler* (function init-accumulator) *array-member-handler* (function accumulator-add) *end-of-array-handler* (function accumulator-get-sequence) *json-array-type* (quote vector) *beginning-of-object-handler* (function init-accumulator-and-prototype) *object-key-handler* (function accumulator-add-key-or-set-prototype) *object-value-handler* (function accumulator-add-value-or-set-prototype) *end-of-object-handler* (function accumulator-get-object) *beginning-of-string-handler* (function init-string-stream-accumulator) *string-char-handler* (function string-stream-accumulator-add) *end-of-string-handler* (function string-stream-accumulator-get) *aggregate-scope-variables* (union *aggregate-scope-variables* (quote (*accumulator* *accumulator-last*))) *object-scope-variables* (union *object-scope-variables* (quote (*prototype* *json-array-type*))) *internal-decoder* (function decode-json))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(unroll-assignment-ops += -= *= /= %= <<= >>= &= ^= |\\|=|)\n\nWrite a macro that addresses: Macro call that should be transformed by unroll-assignment-ops", "input": "(unroll-assignment-ops += -= *= /= %= <<= >>= &= ^= |\\|=|)", "output": "(defmacro unroll-assignment-ops (&rest ops)\n `(progn\n ,@(loop for op in ops collect\n `(defmacro ,(find-symbol (symbol-name op) '#:vacietis.c)\n (lvalue rvalue)\n `(setf ,lvalue\n (,',(find-symbol\n (reverse (subseq (reverse (symbol-name op)) 1))\n '#:vacietis.c)\n ,lvalue\n ,rvalue))))))", "macroexpand": "(progn (defmacro vacietis.c:+= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:+) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:-= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:-) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:*= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:*) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:/= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:/) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:%= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:%) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:<<= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:<<) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:>>= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:>>) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:&= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:&) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:^= (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:^) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))) (defmacro vacietis.c:|\\|=| (lvalue rvalue) (sb-int:quasiquote (setf #S(sb-impl::comma :expr lvalue :kind 0) (#S(sb-impl::comma :expr (quote vacietis.c:|\\||) :kind 0) #S(sb-impl::comma :expr lvalue :kind 0) #S(sb-impl::comma :expr rvalue :kind 0))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(check-cursor-attached cluffer:item-after-cursor (cursor))\n\nProblem: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:item-after-cursor (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:item-after-cursor :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-clause always (form &aux (result T)) (values `(unless ,form (setf ,result NIL) (end-for)) result))\n\nWhat needs to change: Macro call that should be transformed by define-simple-clause", "input": "(define-simple-clause always (form &aux (result T)) (values `(unless ,form (setf ,result NIL) (end-for)) result))", "output": "(defmacro define-simple-clause (name args &body body)\n (multiple-value-bind (args outer-let inner-let result-let) (compute-binding-parts NIL NIL args)\n `(define-direct-clause ,name ,(rest args)\n (let ,outer-let\n (values* `(let* ,(list\n ,@result-let)\n (declare (ignorable ,,@(mapcar #'delist outer-let))))\n (let ,inner-let\n (declare (ignorable ,@(mapcar #'delist inner-let)))\n ,@body))))))", "macroexpand": "(define-direct-clause always (form) (let ((#:result185 (gensym #A((6) base-char . \"RESULT\")))) (values* (sb-int:quasiquote (let* #S(sb-impl::comma :expr (list (list #:result185 (quote t))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:result185 :kind 0))))) (let ((result #:result185)) (declare (ignorable result)) (values (sb-int:quasiquote (unless #S(sb-impl::comma :expr form :kind 0) (setf #S(sb-impl::comma :expr result :kind 0) nil) (end-for))) result)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-unique-js-names)\n\nIssue: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES", "input": "(with-unique-js-names)", "output": "(defmacro WITH-UNIQUE-JS-NAMES ...)", "macroexpand": "(with-ps-gensyms)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-collectors nil)\n\nProblem: Macro call that should be transformed by WITH-COLLECTORS", "input": "(with-collectors nil)", "output": "(defmacro WITH-COLLECTORS ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(the-part 'some-name)\n\nProblem: Macro call that should be transformed by THE-PART", "input": "(the-part 'some-name)", "output": "(defmacro THE-PART ...)", "macroexpand": "(send part 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(letmatch nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by LETMATCH", "input": "(letmatch nil\n (progn))", "output": "(defmacro LETMATCH ...)", "macroexpand": "(ifmatch (nil (progn) nil (error \"LETMATCH: mismatch.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defaction nil\n nil)\n\nProblem: Macro call that should be transformed by DEFACTION", "input": "(defaction nil\n nil)", "output": "(defmacro DEFACTION ...)", "macroexpand": "(setf (gethash #A((3) base-char . \"NIL\") cl-rules.core::*actions*) (lambda ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(js-inline nil (progn))\n\nProblem: Macro call that should be transformed by JS-INLINE", "input": "(js-inline nil (progn))", "output": "(defmacro JS-INLINE ...)", "macroexpand": "(js-inline* '(progn nil (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-color (:yellow :stream stream) (format/indent reporter stream \"\u25b3 Tests were run but no plan was declared.~%\"))\n\nPattern to recognize: Macro call that should be transformed by with-color", "input": "(with-color (:yellow :stream stream) (format/indent reporter stream \"\u25b3 Tests were run but no plan was declared.~%\"))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq :yellow :gray) (eq :yellow :grey) (eq :yellow +gray+) (eq :yellow +grey+)) (with-gray stream (format/indent reporter stream \"\u25b3 Tests were run but no plan was declared.~%\")) (cl-ansi-text:with-color (:yellow :stream stream) (format/indent reporter stream \"\u25b3 Tests were run but no plan was declared.~%\"))) (progn (format/indent reporter stream \"\u25b3 Tests were run but no plan was declared.~%\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defpattern nil\n nil)\n\nProblem: Macro call that should be transformed by DEFPATTERN", "input": "(defpattern nil\n nil)", "output": "(defmacro DEFPATTERN ...)", "macroexpand": "(eval-always\n (setf (get 'nil 'cl-match-pattern)\n (lambda (#:g133)\n (lett nil\n #:g133))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ltbdd-with-new-hash nil)\n\nWhat needs to change: Macro call that should be transformed by LTBDD-WITH-NEW-HASH", "input": "(ltbdd-with-new-hash nil)", "output": "(defmacro LTBDD-WITH-NEW-HASH ...)", "macroexpand": "(bdd-call-with-new-hash (lambda ()) :bdd-node-type\n '(or lisp-type-bdd-node bdd-leaf))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(->>\n nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ->>", "input": "(->>\n nil\n nil)", "output": "(defmacro ->> ...)", "macroexpand": "(let* ((#:var183 nil) (#:var184 (nil #:var183)))\n #:var184)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-path-instruction-pair smooth-curve-to \"S\" (control-x2 control-y2 x y))\n\nPattern to recognize: Macro call that should be transformed by define-path-instruction-pair", "input": "(define-path-instruction-pair smooth-curve-to \"S\" (control-x2 control-y2 x y))", "output": "(defmacro define-path-instruction-pair (name instruction (&rest args))\n (let ((draw-relative (intern (concatenate 'string (string name) \"-R\"))))\n `(progn\n (defun ,name (,@args)\n (format-instruction ,instruction ,@args))\n (defun ,draw-relative (,@args)\n (format-instruction ,(string-downcase instruction) ,@args)))))", "macroexpand": "(progn (defun smooth-curve-to (control-x2 control-y2 x y) (format-instruction \"S\" control-x2 control-y2 x y)) (defun smooth-curve-to-r (control-x2 control-y2 x y) (format-instruction \"s\" control-x2 control-y2 x y)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-html-string (:p :dataset (:duck (dolomphious) :fish 'fizzgigious :spoon \"runcible\")))\n\nPattern to recognize: Macro call that should be transformed by with-html", "input": "(with-html-string (:p :dataset (:duck (dolomphious) :fish 'fizzgigious :spoon \"runcible\")))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:p :dataset (:duck (dolomphious) :fish (quote fizzgigious) :spoon \"runcible\"))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (loop for i from 0 below offset by pad-len do (replace out pad :start1 i :end1 offset)))\n\nProblem: Macro call that should be transformed by lret*", "input": "(lret* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (loop for i from 0 below offset by pad-len do (replace out pad :start1 i :end1 offset)))", "output": "(defmacro lret* ((&rest bindings) &body body)\n \"Cf. `lret'.\"\n `(lret-aux let* ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((offset (- length (length vec))) (element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec :start1 offset) (loop for i from 0 below offset by pad-len do (replace out pad :start1 i :end1 offset)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(augment post-code `((setq ,extra-save-var ,var)))\n\nPattern to recognize: Macro call that should be transformed by augment", "input": "(augment post-code `((setq ,extra-save-var ,var)))", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf post-code (nconc post-code (sb-int:quasiquote ((setq #S(sb-impl::comma :expr extra-save-var :kind 0) #S(sb-impl::comma :expr var :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*> +period+ +any-digit+ +digits+)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> +period+ +any-digit+ +digits+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset184) (multiple-value-bind (#:*>-res187 #:*>-next188) (multiple-value-bind (#:*>-res185 #:*>-next186) (funcall +period+ #:*>-offset184) (if (ok? #:*>-res185) (funcall +any-digit+ #:*>-next186) (fail #:*>-next186))) (if (ok? #:*>-res187) (funcall +digits+ #:*>-next188) (fail #:*>-next188))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-env [assoc-list 'c])\n\nIssue: Macro call that should be transformed by with-env", "input": "(with-env [assoc-list 'c])", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g128) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g128 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [assoc-list (quote c]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g128)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-test partially-correct (true \"Happy\") (is = (get-universal-time) 2962566000))\n\nProblem: Macro call that should be transformed by define-test", "input": "(define-test partially-correct (true \"Happy\") (is = (get-universal-time) 2962566000))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote partially-correct) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote partially-correct) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (true \"Happy\")) (lambda nil (is = (get-universal-time) 2962566000))) :parent (quote nil))) (quote partially-correct))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is (< 0 1))\n\nProblem: Macro call that should be transformed by is", "input": "(is (< 0 1))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e179 0) (#:a180 1)) (if (progn (< #:e179 #:a180)) (add-result (quote test-passed) :test-expr (quote (< 0 1))) (process-failure (quote (< 0 1)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote 1) #:a180 (quote <) #:e179)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(%destructure-defhook-args args (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (with-effective-qualifier generic-function qualifier (intern-hook generic-function hook-name type-list qualifier) `(progn (%defhook-fun ,hook-name ,vanilla-lambda-list ,@body) (%define-method-dispatch ,generic-function ,qualifier ,specialized-lambda-list)))))\n\nWhat needs to change: Macro call that should be transformed by %destructure-defhook-args", "input": "(%destructure-defhook-args args (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (with-effective-qualifier generic-function qualifier (intern-hook generic-function hook-name type-list qualifier) `(progn (%defhook-fun ,hook-name ,vanilla-lambda-list ,@body) (%define-method-dispatch ,generic-function ,qualifier ,specialized-lambda-list)))))", "output": "(defmacro %destructure-defhook-args (args &body body)\n (let ((args-sym (gensym)))\n `(let* ((,args-sym ,args)\n (qualifier\n (cond ((and (symbolp (car ,args-sym)) (not (null (car ,args-sym))))\n (prog1 (car ,args-sym) (setf ,args-sym (cdr ,args-sym))))\n (t :use-default))))\n (destructuring-bind (specialized-lambda-list &body body) ,args-sym\n ,@body))))", "macroexpand": "(let* ((#:g122 args) (qualifier (cond ((and (symbolp (car #:g122)) (not (null (car #:g122)))) (prog1 (car #:g122) (setf #:g122 (cdr #:g122)))) (t :use-default)))) (destructuring-bind (specialized-lambda-list &body body) #:g122 (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (with-effective-qualifier generic-function qualifier (intern-hook generic-function hook-name type-list qualifier) (sb-int:quasiquote (progn (%defhook-fun #S(sb-impl::comma :expr hook-name :kind 0) #S(sb-impl::comma :expr vanilla-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)) (%define-method-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr specialized-lambda-list :kind 0))))))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-template nil :key nil)\n\nProblem: Macro call that should be transformed by DEFINE-TEMPLATE", "input": "(define-template nil :key nil)", "output": "(defmacro DEFINE-TEMPLATE ...)", "macroexpand": "(defmacro define-nil (:key &optional (#:name128))\n (flet ((template-unfulfillable ()\n (error 'template-unfulfillable :template 'nil :arguments\n (list :key))))\n (declare (ignorable (function template-unfulfillable)))\n (let ((body (progn)) (name (or #:name128 (compose-name #\\SOLIDUS 'nil))))\n `(progn\n (declaim\n (ftype\n (function\n ,(loop with types = (declared-variable-types body)\n for arg in (quote nil)\n collect (or (second (assoc arg types)) (quote t)))\n ,(declared-return-type body))\n ,name)\n ,@(when (find (quote inline) (declarations body)) `((inline ,name))))\n (defun ,name ,'nil\n (declare (optimize speed (safety 0) (debug 0) (compilation-speed 0))\n ,@(remove (quote inline) (declarations body)))\n ,@(remove-if #'declaration-p body))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-fixture-restore function (symbol value) (setf (fdefinition symbol) value))\n\nProblem: Macro call that should be transformed by define-fixture-restore", "input": "(define-fixture-restore function (symbol value) (setf (fdefinition symbol) value))", "output": "(defmacro define-fixture-restore (name args &body body)\n `(progn (setf (gethash ',name *fixture-restores*)\n (lambda ,args ,@body))\n ',name))", "macroexpand": "(progn (setf (gethash (quote function) *fixture-restores*) (lambda (symbol value) (setf (fdefinition symbol) value))) (quote function))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-hook (:boot foreign-libraries (- most-positive-fixnum 10)) () (status 0 \"Reloading foreign libraries.\") (flet ((maybe-load (lib) (let ((lib (ensure-library lib)) #+sbcl(sb-ext:*muffled-warnings* 'style-warning)) (unless (or (library-open-p lib) (library-dont-open-p lib)) (status 1 \"Loading foreign library ~a.\" lib) (open-library lib))))) (dolist (lib *foreign-libraries-to-reload*) (maybe-load lib))))\n\nProblem: Macro call that should be transformed by define-hook", "input": "(define-hook (:boot foreign-libraries (- most-positive-fixnum 10)) () (status 0 \"Reloading foreign libraries.\") (flet ((maybe-load (lib) (let ((lib (ensure-library lib)) #+sbcl(sb-ext:*muffled-warnings* 'style-warning)) (unless (or (library-open-p lib) (library-dont-open-p lib)) (status 1 \"Loading foreign library ~a.\" lib) (open-library lib))))) (dolist (lib *foreign-libraries-to-reload*) (maybe-load lib))))", "output": "(defmacro define-hook ((type name &optional (priority 0)) args &body body)\n (ecase type (:pre-load) (:load) (:build) (:deploy) (:boot) (:quit))\n (check-type name symbol)\n `(let ((,name (or (hook ,type ',name)\n (make-instance 'hook :name ',name :type ,type))))\n (setf (hook-priority ,name) ,priority)\n (setf (hook-function ,name) (flet ((,name (&key ,@args &allow-other-keys)\n ,@body))\n #',name))\n (setf (hook ,type ',name) ,name)\n (setf (docstring ,name) ,(if (stringp (car body)) (car body)))\n ',name))", "macroexpand": "(let ((foreign-libraries (or (hook :boot (quote foreign-libraries)) (make-instance (quote hook) :name (quote foreign-libraries) :type :boot)))) (setf (hook-priority foreign-libraries) (- most-positive-fixnum 10)) (setf (hook-function foreign-libraries) (flet ((foreign-libraries (&key &allow-other-keys) (status 0 \"Reloading foreign libraries.\") (flet ((maybe-load (lib) (let ((lib (ensure-library lib)) (sb-ext:*muffled-warnings* (quote style-warning))) (unless (or (library-open-p lib) (library-dont-open-p lib)) (status 1 \"Loading foreign library ~a.\" lib) (open-library lib))))) (dolist (lib *foreign-libraries-to-reload*) (maybe-load lib))))) (function foreign-libraries))) (setf (hook :boot (quote foreign-libraries)) foreign-libraries) (setf (docstring foreign-libraries) nil) (quote foreign-libraries))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda* nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by LAMBDA*", "input": "(lambda* nil\n (progn))", "output": "(defmacro LAMBDA* ...)", "macroexpand": "(lambda () (the t (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-min 'some-name)\n\nProblem: Macro call that should be transformed by COLLECT-MIN", "input": "(collect-min 'some-name)", "output": "(defmacro COLLECT-MIN ...)", "macroexpand": "(common-lisp:let* ((#:generator-320 (generator 'some-name))\n #:numbers-314\n (#:number-316 nil))\n (declare (type generator #:generator-320))\n (tagbody\n #:ll-321\n (setq #:numbers-314 (next-in #:generator-320 (go end)))\n (if (or (null #:number-316) (> #:number-316 #:numbers-314))\n (setq #:number-316 #:numbers-314))\n (go #:ll-321)\n end)\n (if (null #:number-316)\n (setq #:number-316 nil))\n #:number-316)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is = 5 6)\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is = 5 6)", "output": "(defmacro is (comp expected form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(is ,comp ,expected ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected ,expected\n :comparison ,(maybe-quote comp)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is = 5 6)) :value-form (quote 6) :body (lambda nil 6) :expected 5 :comparison (quote =)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause-driver (for var in-stream stream &optional using (reader '#'read)) \"Forms in a stream (which will be closed at the end)\" (top-level-check) (return-stream-driver-code var stream reader :stream generate))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause-driver (for var in-stream stream &optional using (reader '#'read)) \"Forms in a stream (which will be closed at the end)\" (top-level-check) (return-stream-driver-code var stream reader :stream generate))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-for-in-stream-7 (&key ((:for var)) ((:in-stream stream)) ((:using reader) (quote (function read))) generate) \"Forms in a stream (which will be closed at the end)\" (top-level-check) (return-stream-driver-code var stream reader :stream generate)) (install-clause-info (quote (for :in-stream)) (quote (for :in-stream &optional :using)) (quote clause-for-in-stream-7) \"Forms in a stream (which will be closed at the end)\" t) (quote (for var in-stream stream &optional using (reader (quote (function read))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun/1 ungetc (c fd) (handler-case (progn (unread-char (code-char c) (fd-stream fd)) c) (error () (setf (ferror fd) EIO) EOF)))\n\nIssue: Macro call that should be transformed by defun/1", "input": "(defun/1 ungetc (c fd) (handler-case (progn (unread-char (code-char c) (fd-stream fd)) c) (error () (setf (ferror fd) EIO) EOF)))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun ungetc (c fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (progn (unread-char (code-char c) (fd-stream fd)) c) (error nil (setf (ferror fd) eio) eof))) (defparameter ungetc (vacietis.c:mkptr& (symbol-function (quote ungetc)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield\n nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-YIELD", "input": "(with-yield\n nil\n :key\n nil)", "output": "(defmacro WITH-YIELD ...)", "macroexpand": "(isolate-cont\n (enable-yield\n nil\n nil\n :key\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(aggregate-scope-progv *string-scope-variables* (aggregate-scope-progv *aggregate-scope-variables* (loop initially (funcall *beginning-of-string-handler*) for c = (read-json-string-char stream) while c do (funcall *string-char-handler* c) finally (return (funcall *end-of-string-handler*)))))\n\nWhat needs to change: Macro call that should be transformed by aggregate-scope-progv", "input": "(aggregate-scope-progv *string-scope-variables* (aggregate-scope-progv *aggregate-scope-variables* (loop initially (funcall *beginning-of-string-handler*) for c = (read-json-string-char stream) while c do (funcall *string-char-handler* c) finally (return (funcall *end-of-string-handler*)))))", "output": "(defmacro aggregate-scope-progv (variables &body body)\n \"Establish a dynamic environment where all VARIABLES are freshly\nbound (to their current values), and execute BODY in it, returning the\nresult.\"\n `(progv ,variables (mapcar #'symbol-value ,variables)\n ,@body))", "macroexpand": "(progv *string-scope-variables* (mapcar (function symbol-value) *string-scope-variables*) (aggregate-scope-progv *aggregate-scope-variables* (loop initially (funcall *beginning-of-string-handler*) for c = (read-json-string-char stream) while c do (funcall *string-char-handler* c) finally (return (funcall *end-of-string-handler*)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(gatherlet nil)\n\nPattern to recognize: Macro call that should be transformed by GATHERLET", "input": "(gatherlet nil)", "output": "(defmacro GATHERLET ...)", "macroexpand": "(common-lisp:let ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(cond->\n 'some-name)\n\nPattern to recognize: Macro call that should be transformed by COND->", "input": "(cond->\n 'some-name)", "output": "(defmacro COND-> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-cruft %associate-name-with-readtable (name readtable) \"Associate NAME with READTABLE for FIND-READTABLE to work.\" #+ :allegro (setf (excl:named-readtable (readtable-name-for-allegro name)) readtable) #+ :common-lisp (setf (gethash name *named-readtables*) readtable))\n\nIssue: Macro call that should be transformed by define-cruft", "input": "(define-cruft %associate-name-with-readtable (name readtable) \"Associate NAME with READTABLE for FIND-READTABLE to work.\" #+ :allegro (setf (excl:named-readtable (readtable-name-for-allegro name)) readtable) #+ :common-lisp (setf (gethash name *named-readtables*) readtable))", "output": "(defmacro define-cruft (name lambda-list &body (docstring . alternatives))\n (assert (typep docstring 'string) (docstring) \"Docstring missing!\")\n (assert (not (null alternatives)))\n `(progn\n (declaim (inline ,name))\n (defun ,name ,lambda-list ,docstring ,(first alternatives))))", "macroexpand": "(progn (declaim (inline %associate-name-with-readtable)) (defun %associate-name-with-readtable (name readtable) \"Associate NAME with READTABLE for FIND-READTABLE to work.\" (setf (gethash name *named-readtables*) readtable)))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defjs test_sum() (let ((l (make-array 1 2 3 4)) (sum 0)) (dolist (c l) (incf sum c)) (return sum)))\n\nWrite a macro that addresses: Macro call that should be transformed by defjs", "input": "(defjs test_sum() (let ((l (make-array 1 2 3 4)) (sum 0)) (dolist (c l) (incf sum c)) (return sum)))", "output": "(defmacro defjs (name args &body body)\n \"Define client side javascript. Works like defun; body is in lisp, with parenscript\n additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. \n macro creates a lisp function which sends the javascript function over to the mongo \n server to be evaluated. Result is processed and returned to the reader. \n This will execute 10 times on the server :\n (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))\"\n `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))\n (setf (gethash ',name *js-definitions*) js-body)\n (defun ,name ,args\n (get-element \"retval\" (car (docs (db.eval js-body ,@args)))))))", "macroexpand": "(let* ((js-body (parenscript:ps (lambda nil (let ((l (make-array 1 2 3 4)) (sum 0)) (dolist (c l) (incf sum c)) (return sum)))))) (setf (gethash (quote test_sum) *js-definitions*) js-body) (defun test_sum nil (get-element \"retval\" (car (docs (db.eval js-body))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclause (minimize expr &optional into var) \"Minimize value of an expression\" (return-extremum-code expr var 'min))\n\nProblem: Macro call that should be transformed by defclause", "input": "(defclause (minimize expr &optional into var) \"Minimize value of an expression\" (return-extremum-code expr var 'min))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-minimize-13 (&key ((:minimize expr)) ((:into var))) \"Minimize value of an expression\" (return-extremum-code expr var (quote min))) (install-clause-info (quote (minimize)) (quote (minimize &optional :into)) (quote clause-minimize-13) \"Minimize value of an expression\" nil) (quote (minimize expr &optional into var)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-packages-unlocked nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by WITH-PACKAGES-UNLOCKED", "input": "(with-packages-unlocked nil\n (progn))", "output": "(defmacro WITH-PACKAGES-UNLOCKED ...)", "macroexpand": "(let ((#:|packages122| (locked-packages 'nil)))\n (unlock-packages #:|packages122|)\n (unwind-protect (progn) (lock-packages #:|packages122|)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dlet* nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DLET*", "input": "(dlet* nil\n :key\n nil)", "output": "(defmacro DLET* ...)", "macroexpand": "(dynamic-let* nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(doseq (elem sequence :from-end from-end :start start :end end) (when (funcall test (funcall key elem)) (incf count)))\n\nPattern to recognize: Macro call that should be transformed by doseq", "input": "(doseq (elem sequence :from-end from-end :start start :end end) (when (funcall test (funcall key elem)) (incf count)))", "output": "(defmacro doseq (name/seq &body body)\n \"Iterate over the elements of a single sequence SEQUENCE.\n\n Same as DO-SEQUENCES but for the special case of iterating over a\n single sequence.\n\n The macro arguments can be in one of the following two forms:\n\n 1. (NAME (ELEMENT SEQUENCE &REST ARGS) &BODY BODY)\n\n 2. ((ELEMENT SEQUENCE &REST ARGS) &BODY BODY)\n\n NAME is the block name, NIL if not given.\n\n ELEMENT is the variable to which each element of the sequence is\n bound.\n\n SEQUENCE is the sequence, with ARGS being the remaining arguments\n passed to the ITERATOR function.\n\n BODY is the list of forms evaluated on each iteration.\"\n\n (let-if ((name name/seq)\n (seq (first body) name/seq)\n (body (rest body) body))\n (symbolp name/seq)\n\n (destructuring-bind (element sequence &rest args) seq\n `(do-sequences ,name\n ((,element ,sequence ,@args))\n ,@body))))", "macroexpand": "(do-sequences nil ((elem sequence :from-end from-end :start start :end end)) (when (funcall test (funcall key elem)) (incf count)))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(once-only* args (let ((else `(error 'match-error :values (list ,@args) :patterns ',(mapcar #'car clauses)))) (compile-match args clauses else)))\n\nIssue: Macro call that should be transformed by once-only*", "input": "(once-only* args (let ((else `(error 'match-error :values (list ,@args) :patterns ',(mapcar #'car clauses)))) (compile-match args clauses else)))", "output": "(defmacro once-only* (symbol &body body)\n (with-unique-names (form var vars bindings)\n `(let (,vars ,bindings)\n (dolist (,form ,symbol)\n (if (symbolp ,form)\n (push ,form ,vars)\n (let ((,var (gensym \"VAR\")))\n (push ,var ,vars)\n (push (list ,var ,form) ,bindings))))\n (setq ,vars (nreverse ,vars)\n ,bindings (nreverse ,bindings))\n (if ,bindings\n `(let ,,bindings\n ;(declare (ignorable ,@(mapcar #'car ,bindings)))\n ,(let ((,symbol ,vars))\n ,@body))\n (progn ,@body)))))", "macroexpand": "(let (#:vars166 #:bindings167) (dolist (#:form164 args) (if (symbolp #:form164) (push #:form164 #:vars166) (let ((#:var165 (gensym \"VAR\"))) (push #:var165 #:vars166) (push (list #:var165 #:form164) #:bindings167)))) (setq #:vars166 (nreverse #:vars166) #:bindings167 (nreverse #:bindings167)) (if #:bindings167 (sb-int:quasiquote (let #S(sb-impl::comma :expr #:bindings167 :kind 0) #S(sb-impl::comma :expr (let ((args #:vars166)) (let ((else (sb-int:quasiquote (error (quote match-error) :values (list #S(sb-impl::comma :expr args :kind 2)) :patterns (quote #S(sb-impl::comma :expr (mapcar (function car) clauses) :kind 0)))))) (compile-match args clauses else))) :kind 0))) (progn (let ((else (sb-int:quasiquote (error (quote match-error) :values (list #S(sb-impl::comma :expr args :kind 2)) :patterns (quote #S(sb-impl::comma :expr (mapcar (function car) clauses) :kind 0)))))) (compile-match args clauses else)))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(keep-bops 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by KEEP-BOPS", "input": "(keep-bops 'some-name)", "output": "(defmacro KEEP-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn\n (init-binfix)\n (unless nil\n (setq *binfix*\n (delete nil\n (mapcar\n (lambda (bs)\n (setq bs\n (delete-if\n (lambda (b)\n (unless (member (car b) '('some-name))\n (remprop (car b) 'properties)\n t))\n bs)))\n *binfix*)))\n (assign-properties))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(f_n)\n\nWrite a macro that addresses: Macro call that should be transformed by F_N", "input": "(f_n)", "output": "(defmacro F_N ...)", "macroexpand": "(lambda (&rest _))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n($+ result)\n\nProblem: Macro call that should be transformed by $+", "input": "($+ result)", "output": "(defmacro $+ (arg &rest args)\n `(construct-$+- +1 ,arg ,@args))", "macroexpand": "(construct-$+- 1 result)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(min-of nil)\n\nIssue: Macro call that should be transformed by MIN-OF", "input": "(min-of nil)", "output": "(defmacro MIN-OF ...)", "macroexpand": "(lc (nil) minimize)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(secase (car x) (:y (setf it :no)))\n\nIssue: Macro call that should be transformed by secase", "input": "(secase (car x) (:y (setf it :no)))", "output": "(defmacro secase (keyform &body cases)\n \"Like ECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for the\nscope of the cases. IT can be set with SETF.\"\n `(symbolic ecase ,keyform ,@cases))", "macroexpand": "(symbolic ecase (car x) (:y (setf it :no)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:= infix-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:= infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (=-op (:include infix-op (name \"=\")) (:constructor make-=-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-<>\n 'some-name)\n\nIssue: Macro call that should be transformed by -<>", "input": "(-<>\n 'some-name)", "output": "(defmacro -<> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(bind ((obj (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5)) ((:writable-accessors (my-a a) (my-c c) (d the-d)) obj)) (setf my-a 42) (list d my-c my-a (a obj)))\n\nWrite a macro that addresses: Macro call that should be transformed by bind", "input": "(bind ((obj (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5)) ((:writable-accessors (my-a a) (my-c c) (d the-d)) obj)) (setf my-a 42) (list d my-c my-a (a obj)))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((obj (make-instance (quote metabang-bind-class-2) :a 1 :b 2 :c 3 :d 4 :e 5)) (#:|values-177| obj)) (declare (ignorable #:|values-177|)) (with-accessors ((my-a a) (my-c c) (d the-d)) #:|values-177| (progn (setf my-a 42) (list d my-c my-a (a obj)))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(\u0192\u2192 nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by \u0191\u2192", "input": "(\u0192\u2192 nil :key nil)", "output": "(defmacro \u0191\u2192 ...)", "macroexpand": "(defn nil :key (&optional \u03b1)\n (let ((\u03b1 (or \u03b1 t)))\n (cond)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-generic generic (a b &key c) (declare (optimize (speed 1))) (+ a b c))\n\nWhat needs to change: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c) (declare (optimize (speed 1))) (+ a b c))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (declare (optimize (speed 1))) (:method (a b &key c) (declare (optimize (speed 1))) (+ a b c))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(cond-<>\n nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by COND-<>", "input": "(cond-<>\n nil\n :key\n nil)", "output": "(defmacro COND-<> ...)", "macroexpand": "(let* ((#:var138 nil)\n (#:var139\n (if :key\n (-<>\n #:var138)\n #:var138))\n (#:var140\n (if nil\n (-<>\n #:var139)\n #:var139)))\n #:var140)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (plusp 0))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (plusp 0))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:v191 0)) (if (plusp #:v191) (add-result (quote test-passed) :test-expr (quote (plusp 0))) (process-failure (quote (plusp 0)) \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\" (quote 0) #:v191 (quote plusp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(lret* ((type `(integer ,start (,end))) (len (- end start)) (vector (make-array len :element-type type))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (1+ n))))))\n\nPattern to recognize: Macro call that should be transformed by lret*", "input": "(lret* ((type `(integer ,start (,end))) (len (- end start)) (vector (make-array len :element-type type))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (1+ n))))))", "output": "(defmacro lret* ((&rest bindings) &body body)\n \"Cf. `lret'.\"\n `(lret-aux let* ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((type (sb-int:quasiquote (integer #S(sb-impl::comma :expr start :kind 0) (#S(sb-impl::comma :expr end :kind 0))))) (len (- end start)) (vector (make-array len :element-type type))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (1+ n))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(letmatch nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by LETMATCH", "input": "(letmatch nil\n :key\n nil)", "output": "(defmacro LETMATCH ...)", "macroexpand": "(ifmatch (nil :key nil (error \"LETMATCH: mismatch.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(match list ((list x) when (oddp x) x))\n\nWhat needs to change: Macro call that should be transformed by match", "input": "(match list ((list x) when (oddp x) x))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(%or (%if (consp list) (let ((#:g140 (car list)) (#:g141 (cdr list))) (declare (ignorable #:g140 #:g141)) (%if (%equals #:g141 nil) (%or (let ((x #:g140)) (if (oddp x) x (fail))) (fail)) (fail))) (fail)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclass/std unknown () ((slot :unknown keywords :without-values)))\n\nWhat needs to change: Macro call that should be transformed by defclass/std", "input": "(defclass/std unknown () ((slot :unknown keywords :without-values)))", "output": "(defmacro defclass/std (name direct-superclasses direct-slots &rest options\n &environment env)\n \"Shortcut macro to the DEFCLASS macro.\n\n (defclass/std example ()\n ((slot1 slot2 slot3)))\n\n expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\n Each slot definition accepts options:\n\n :std 1 => changes the :initform to 1. It can be :unbound.\n :with or :with-prefix => creates accessors with the class name as prefix.\n\n See the README for more.\n\n See also `class/std' and `print-object/std'.\n \"\n `(defclass ,name ,direct-superclasses\n ,(process-slots env direct-slots name)\n ,@options))", "macroexpand": "(defclass unknown nil ((slot :accessor slot :initarg :slot :initform nil :unknown keywords :without-values)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (eql (top-sign) 'skip-first-funcall) (pop-sign))\n\nProblem: Macro call that should be transformed by when", "input": "(when (eql (top-sign) 'skip-first-funcall) (pop-sign))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql (top-sign) (quote skip-first-funcall)) (pop-sign))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(without-symbol-access\n nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS", "input": "(without-symbol-access\n nil\n (progn))", "output": "(defmacro WITHOUT-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* nil))\n nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defsynonym repeat :repeat)\n\nIssue: Macro call that should be transformed by defsynonym", "input": "(defsynonym repeat :repeat)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote repeat) (quote synonym)) (quote :repeat)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun-compile-time screamer-error (header &rest args) (apply #'error (concatenate 'string header \"~2%There are eight types of nondeterministic contexts: 1. the body of a function defined with SCREAMER::DEFUN 2. the body of a FOR-EFFECTS macro invocation 3. the body of an ALL-VALUES macro invocation 4. the first argument of a ONE-VALUE macro invocation 5. the body of a PRINT-VALUES macro invocation 6. the second argument of an ITH-VALUE macro invocation 7. the body of a POSSIBLY? macro invocation 8. the body of a NECESSARILY? macro invocation. Note that the default forms of &OPTIONAL and &KEY arguments and the initialization forms of &AUX variables are always deterministic contexts even though they may appear inside a SCREAMER::DEFUN.\") args))\n\nPattern to recognize: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time screamer-error (header &rest args) (apply #'error (concatenate 'string header \"~2%There are eight types of nondeterministic contexts: 1. the body of a function defined with SCREAMER::DEFUN 2. the body of a FOR-EFFECTS macro invocation 3. the body of an ALL-VALUES macro invocation 4. the first argument of a ONE-VALUE macro invocation 5. the body of a PRINT-VALUES macro invocation 6. the second argument of an ITH-VALUE macro invocation 7. the body of a POSSIBLY? macro invocation 8. the body of a NECESSARILY? macro invocation. Note that the default forms of &OPTIONAL and &KEY arguments and the initialization forms of &AUX variables are always deterministic contexts even though they may appear inside a SCREAMER::DEFUN.\") args))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun screamer-error (header &rest args) (apply (function error) (concatenate (quote string) header \"~2%There are eight types of nondeterministic contexts: 1. the body of a function defined with SCREAMER::DEFUN 2. the body of a FOR-EFFECTS macro invocation 3. the body of an ALL-VALUES macro invocation 4. the first argument of a ONE-VALUE macro invocation 5. the body of a PRINT-VALUES macro invocation 6. the second argument of an ITH-VALUE macro invocation 7. the body of a POSSIBLY? macro invocation 8. the body of a NECESSARILY? macro invocation. Note that the default forms of &OPTIONAL and &KEY arguments and the initialization forms of &AUX variables are always deterministic contexts even though they may appear inside a SCREAMER::DEFUN.\") args)) (eval-when (:compile-toplevel) (compile (quote screamer-error))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-progv nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-PROGV", "input": "(dynamic-progv nil\n (progn))", "output": "(defmacro DYNAMIC-PROGV ...)", "macroexpand": "(let* ((#:fixed-symbols238 nil)\n (#:fixed-bindings239 (compute-bindings #:fixed-symbols238 (progn))))\n (dynamic-wind\n :proceed\n #:proceed240\n (progv #:fixed-symbols238 #:fixed-bindings239 (#:proceed240))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(->* nil nil)\n\nProblem: Macro call that should be transformed by ->*", "input": "(->* nil nil)", "output": "(defmacro ->* ...)", "macroexpand": "(-> nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(receive () (values 1))\n\nProblem: Macro call that should be transformed by receive", "input": "(receive () (values 1))", "output": "(defmacro receive (formals expr &body body)\n \"Stricter version of `multiple-value-bind'.\n\nUse `receive' when you want to enforce that EXPR should return a\ncertain number of values, or a minimum number of values.\n\nIf FORMALS is a proper list, then EXPR must return exactly as many\nvalues -- no more and no less -- as there are variables in FORMALS.\n\nIf FORMALS is an improper list (VARS . REST), then EXPR must return at\nleast as many values as there are VARS, and any further values are\nbound, as a list, to REST.\n\nLastly, if FORMALS is a symbol, bind that symbol to all the values\nreturned by EXPR, as if by `multiple-value-list'.\n\nFrom Scheme (SRFI-8).\"\n ;; It's probably not worth stack-allocating the thunk.\n (cond ((null formals)\n `(multiple-value-call\n (lambda ()\n ,@body)\n ,expr))\n ((atom formals)\n ;; This could also be written:\n #+(or) `(let ((,formals (multiple-value-list ,expr)))\n ,@body)\n ;; But I want it to be possible to declare FORMALS to have\n ;; dynamic extent, and most Lisps support that for &rest\n ;; lists.\n `(multiple-value-call\n (lambda (&rest ,formals)\n ,@body)\n ,expr))\n ((proper-list-p formals)\n (when (intersection formals lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda ,formals\n ,@body)\n ,expr))\n (t (let* ((last (last formals))\n (vars (append (butlast formals)\n (list (car last))))\n (rest (cdr last)))\n (when (intersection (cons rest vars) lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda (,@vars &rest ,rest)\n ,@body)\n ,expr)))))", "macroexpand": "(multiple-value-call (lambda nil) (values 1))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> :g () (put 1) 2)\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> :g () (put 1) 2)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g nil (put 1) 2)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(destructuring-methods nil\n nil)\n\nProblem: Macro call that should be transformed by DESTRUCTURING-METHODS", "input": "(destructuring-methods nil\n nil)", "output": "(defmacro DESTRUCTURING-METHODS ...)", "macroexpand": "(let ((#:g131 nil))\n (typecase #:g131 ((not list) nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(some-<> 'some-name)\n\nPattern to recognize: Macro call that should be transformed by SOME-<>", "input": "(some-<> 'some-name)", "output": "(defmacro SOME-<> ...)", "macroexpand": "(let* ((#:g124 'some-name))\n #:g124)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defhandler function (function name) `(list ',function ,(if (function-name-p name) `',name (e name))))\n\nProblem: Macro call that should be transformed by defhandler", "input": "(defhandler function (function name) `(list ',function ,(if (function-name-p name) `',name (e name))))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-function (function name) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr function :kind 0)) #S(sb-impl::comma :expr (if (function-name-p name) (sb-int:quasiquote (quote #S(sb-impl::comma :expr name :kind 0))) (e name)) :kind 0)))) (setf (gethash (quote function) *form-handler*) (quote hander-function)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-iter iterator-zip (iterator-vec n) (zip-from-itl (itl-of-itls) (let* ((itl-of-itls (iter-to-vec itl-of-itls)) (n (length itl-of-itls))) (loop for i below n do (setf (aref itl-of-itls i) (make-iterator (aref itl-of-itls i)))) (if (zerop n) (empty-iterator) (init-state (iterator-vec itl-of-itls) n)))) (loop with alive = t for i below n with ret-vec = (make-array n) while alive do (multiple-value-bind (iter-item iter-alive) (next (aref iterator-vec i)) (setf alive iter-alive) (setf (aref ret-vec i) iter-item)) finally (return (if alive (values ret-vec t) (values nil nil)))))\n\nPattern to recognize: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-zip (iterator-vec n) (zip-from-itl (itl-of-itls) (let* ((itl-of-itls (iter-to-vec itl-of-itls)) (n (length itl-of-itls))) (loop for i below n do (setf (aref itl-of-itls i) (make-iterator (aref itl-of-itls i)))) (if (zerop n) (empty-iterator) (init-state (iterator-vec itl-of-itls) n)))) (loop with alive = t for i below n with ret-vec = (make-array n) while alive do (multiple-value-bind (iter-item iter-alive) (next (aref iterator-vec i)) (setf alive iter-alive) (setf (aref ret-vec i) iter-item)) finally (return (if alive (values ret-vec t) (values nil nil)))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname136 (&key iterator-vec n) (labels ((self nil (loop with alive = t for i below n with ret-vec = (make-array n) while alive do (multiple-value-bind (iter-item iter-alive) (next (aref iterator-vec i)) (setf alive iter-alive) (setf (aref ret-vec i) iter-item)) finally (return (if alive (values ret-vec t) (values nil nil)))))) (function self)))) (defun zip-from-itl (itl-of-itls) \"Function had no docstring, so this one was inserted\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname136)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (let* ((itl-of-itls (iter-to-vec itl-of-itls)) (n (length itl-of-itls))) (loop for i below n do (setf (aref itl-of-itls i) (make-iterator (aref itl-of-itls i)))) (if (zerop n) (empty-iterator) (init-state (iterator-vec itl-of-itls) n))))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-active-layers nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-ACTIVE-LAYERS", "input": "(with-active-layers nil\n :key\n nil)", "output": "(defmacro WITH-ACTIVE-LAYERS ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-element-maker :linear-gradient \"linearGradient\" '(:id :x1 :y1 :x2 :y2))\n\nWrite a macro that addresses: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :linear-gradient \"linearGradient\" '(:id :x1 :y1 :x2 :y2))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :linear-gradient)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:id :x1 :y1 :x2 :y2)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :linear-gradient missing))))) (defmethod make-svg-element ((element (eql :linear-gradient)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"linearGradient\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-string-quote-syntax)\n\nPattern to recognize: Macro call that should be transformed by ENABLE-STRING-QUOTE-SYNTAX", "input": "(enable-string-quote-syntax)", "output": "(defmacro ENABLE-STRING-QUOTE-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-string-quote-syntax-in-readtable :start-character\n #\\HALFWIDTH_LEFT_CORNER_BRACKET\n :end-character\n #\\HALFWIDTH_RIGHT_CORNER_BRACKET\n :transformer #'identity)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deferror \"XX\" internal-error)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"XX\" internal-error)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition internal-error (database-error) nil) (setf (gethash \"XX\" *error-table*) (quote internal-error)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(drelet* nil\n nil)\n\nProblem: Macro call that should be transformed by DRELET*", "input": "(drelet* nil\n nil)", "output": "(defmacro DRELET* ...)", "macroexpand": "(dynamic-relet* nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-<>> (diamond-wand init (cddr exp) t))\n\nWhat needs to change: Macro call that should be transformed by -<>", "input": "(-<>> (diamond-wand init (cddr exp) t))", "output": "(defmacro -<> (init &body exps) (diamond-wand init exps))", "macroexpand": "(diamond-wand init (cddr exp) t)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(f_n\n 'some-name)\n\nPattern to recognize: Macro call that should be transformed by F_N", "input": "(f_n\n 'some-name)", "output": "(defmacro F_N ...)", "macroexpand": "(lambda (&rest _) 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is-error (error \"Raising an error\") 'simple-error)\n\nIssue: Macro call that should be transformed by is", "input": "(is-error (error \"Raising an error\") 'simple-error)", "output": "(defmacro is (got expected &rest args)\n (with-gensyms (duration result new-args desc)\n (once-only (expected)\n `(let* ((,new-args (list ,@args))\n (,desc (parse-description-and-test ,new-args)))\n (with-catching-errors (:description ,desc :expected ,expected)\n (with-duration ((,duration ,result) ,got)\n (test ,result ,expected ,new-args\n :duration ,duration)))))))", "macroexpand": "(with-duration ((#:duration182 #:error181) (handler-case (error \"Raising an error\") (condition (#:error181) #:error181))) (test #:error181 (quote simple-error) nil :duration #:duration182 :got-form (quote (error \"Raising an error\")) :test-fn (function typep) :report-expected-label \"raise a condition\"))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(,*yap* \"-l\" ,input-file ,@args) :input input :output output :error error))\n\nIssue: Macro call that should be transformed by with-temp", "input": "(with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(,*yap* \"-l\" ,input-file ,@args) :input input :output output :error error))", "output": "(defmacro with-temp ((var &key directory template (tmpdir \"/tmp/\") debug) &body body)\n \"Create a temporary file, then remove the file by unwind-protect.\nMost arguments are analogous to mktemp.\nWhen DIRECTORY is non-nil, creates a directory instead.\nDEBUG is a form.\nWhen evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.\nIt may be evaluated multiple times.\"\n (with-gensyms (command)\n `(let ((,var (uiop:run-program\n (let ((,command (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\"\n ,tmpdir ,directory ,template)))\n (when ,debug\n (format *error-output* \"~&; ~a~%\" ,command))\n ,command)\n :output '(:string :stripped t))))\n (unwind-protect\n (progn ,@body)\n (if ,debug\n (format *error-output* \"~&; not removing ~a for debugging~%\" ,var)\n (uiop:run-program (format nil \"rm -rf ~a\" (namestring ,var)) :ignore-error-status t))))))", "macroexpand": "(let ((input-file (uiop/run-program:run-program (let ((#:command180 (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\" d nil \"XXXXXX.prolog\"))) (when (<= 1 *debug-prolog*) (format *error-output* \"~&; ~a~%\" #:command180)) #:command180) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print (sb-int:quasiquote (#S(sb-impl::comma :expr *yap* :kind 0) \"-l\" #S(sb-impl::comma :expr input-file :kind 0) #S(sb-impl::comma :expr args :kind 2))) :input input :output output :error error)) (if (<= 1 *debug-prolog*) (format *error-output* \"~&; not removing ~a for debugging~%\" input-file) (uiop/run-program:run-program (format nil \"rm -rf ~a\" (namestring input-file)) :ignore-error-status t))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-lock (lru-pool-lock pool) (get-from-lru-pool pool host-port))\n\nIssue: Macro call that should be transformed by with-lock", "input": "(with-lock (lru-pool-lock pool) (get-from-lru-pool pool host-port))", "output": "(defmacro with-lock (lock &body body)\n (declare (ignorable lock))\n #+thread-support `(bt2:with-lock-held (,lock)\n ,@body)\n #-thread-support `(progn ,@body))", "macroexpand": "(bt2:with-lock-held ((lru-pool-lock pool)) (get-from-lru-pool pool host-port))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-ps-gensyms nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-PS-GENSYMS", "input": "(with-ps-gensyms nil)", "output": "(defmacro WITH-PS-GENSYMS ...)", "macroexpand": "(let* ())", "category": "control-flow", "technique": "gensym", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(aetypecase 1.0 (fixnum (* 2 it)) (float (+ 2.0 it)) (symbol :oops))\n\nWhat needs to change: Macro call that should be transformed by aetypecase", "input": "(aetypecase 1.0 (fixnum (* 2 it)) (float (+ 2.0 it)) (symbol :oops))", "output": "(defmacro aetypecase (keyform &body cases)\n \"Like ETYPECASE, except binds the result of the keyform to IT (via LET) for\nthe scope of the cases.\"\n `(anaphoric etypecase ,keyform ,@cases))", "macroexpand": "(anaphoric etypecase 1.0 (fixnum (* 2 it)) (float (+ 2.0 it)) (symbol :oops))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun-compile-time walk-lambda-list-reducing (map-function reduce-function screamer? partial? nested? lambda-list environment &optional mode) (cond ((null lambda-list) (funcall reduce-function)) ((member (first lambda-list) *ordered-lambda-list-keywords* :test #'eq) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment (first lambda-list))) (t (ecase mode ((nil &rest &allow-other-keys &aux) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) ((&optional &key) (if (and (consp (first lambda-list)) (consp (rest (first lambda-list)))) (funcall reduce-function (walk map-function reduce-function screamer? partial? nested? (second (first lambda-list)) environment) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)))))))\n\nWrite a macro that addresses: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-lambda-list-reducing (map-function reduce-function screamer? partial? nested? lambda-list environment &optional mode) (cond ((null lambda-list) (funcall reduce-function)) ((member (first lambda-list) *ordered-lambda-list-keywords* :test #'eq) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment (first lambda-list))) (t (ecase mode ((nil &rest &allow-other-keys &aux) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) ((&optional &key) (if (and (consp (first lambda-list)) (consp (rest (first lambda-list)))) (funcall reduce-function (walk map-function reduce-function screamer? partial? nested? (second (first lambda-list)) environment) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)))))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-lambda-list-reducing (map-function reduce-function screamer? partial? nested? lambda-list environment &optional mode) (cond ((null lambda-list) (funcall reduce-function)) ((member (first lambda-list) *ordered-lambda-list-keywords* :test (function eq)) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment (first lambda-list))) (t (ecase mode ((nil &rest &allow-other-keys &aux) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) ((&optional &key) (if (and (consp (first lambda-list)) (consp (rest (first lambda-list)))) (funcall reduce-function (walk map-function reduce-function screamer? partial? nested? (second (first lambda-list)) environment) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode)) (walk-lambda-list-reducing map-function reduce-function screamer? partial? nested? (rest lambda-list) environment mode))))))) (eval-when (:compile-toplevel) (compile (quote walk-lambda-list-reducing))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym sum :sum)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym sum :sum)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote sum) (quote synonym)) (quote :sum)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-special-initargs nil\n (progn))\n\nIssue: Macro call that should be transformed by WITH-SPECIAL-INITARGS", "input": "(with-special-initargs nil\n (progn))", "output": "(defmacro WITH-SPECIAL-INITARGS ...)", "macroexpand": "(funcall-with-special-initargs (list) (lambda () (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:div (:p \"Text \" (:a \"link text\") \" more text\")))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:div (:p \"Text \" (:a \"link text\") \" more text\")))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:div (:p \"Text \" (:a \"link text\") \" more text\"))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(ematch0 patterns ((list) nil) ((list* first rest) (let ((first* (correct-pattern (pattern-expand-all/lift first)))) (cons first* (let ((*lexvars* (variables first*))) (expand-multipatterns rest))))))\n\nPattern to recognize: Macro call that should be transformed by ematch0", "input": "(ematch0 patterns ((list) nil) ((list* first rest) (let ((first* (correct-pattern (pattern-expand-all/lift first)))) (cons first* (let ((*lexvars* (variables first*))) (expand-multipatterns rest))))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 patterns ((list) nil) ((list* first rest) (let ((first* (correct-pattern (pattern-expand-all/lift first)))) (cons first* (let ((*lexvars* (variables first*))) (expand-multipatterns rest))))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-class some-class (some super classes) ((slot1 42 :documentation \"zork\") (slot2 :unbound :accessor slot2-custom) (slot3 :unbound :accessor nil :export :accessor)) (:export-accessor-names-p t) (:export-class-name-p t) (:export-slot-names-p t))\n\nPattern to recognize: Macro call that should be transformed by define-class", "input": "(define-class some-class (some super classes) ((slot1 42 :documentation \"zork\") (slot2 :unbound :accessor slot2-custom) (slot3 :unbound :accessor nil :export :accessor)) (:export-accessor-names-p t) (:export-class-name-p t) (:export-slot-names-p t))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass some-class (some super classes) ((slot1 :initform 42 :accessor slot1 :initarg :slot1 :documentation \"zork\") (slot2 :accessor slot2-custom :initarg :slot2) (slot3 :initarg :slot3))) (unless (fboundp (quote some-class-p)) (define-generic some-class-p (object) #A((75) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `some-class'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote some-class)))) (eval-when (:compile-toplevel :load-toplevel :execute) (export (quote (some-class slot2 slot2-custom slot1 slot1)) #A((8) base-char . \"NCLASSES\"))) (setf (documentation (quote slot2-custom) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT2.\")) (ignore-errors (setf (documentation (fdefinition (quote slot2-custom)) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT2.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf slot2-custom))) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT2.\"))) (setf (documentation (quote slot1) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot SLOT1.\nzork\")) (ignore-errors (setf (documentation (fdefinition (quote slot1)) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot SLOT1.\nzork\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf slot1))) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot SLOT1.\nzork\"))) (find-class (quote some-class) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is something 'a 'a)\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is something 'a 'a)", "output": "(defmacro is (comp expected form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(is ,comp ,expected ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected ,expected\n :comparison ,(maybe-quote comp)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is something (quote a) (quote a))) :value-form (quote (quote a)) :body (lambda nil (quote a)) :expected (quote a) :comparison (quote something)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-alias nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-ALIAS", "input": "(define-alias nil\n nil)", "output": "(defmacro DEFINE-ALIAS ...)", "macroexpand": "(progn\n (macrolet ((thunk ()\n (let ())))\n (defun nil () nil (thunk)))\n (define-compiler-macro nil\n nil\n nil\n `(let ,(list)\n ,(let ()))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(yield-for-union-ops \"UNION ALL\")\n\nWrite a macro that addresses: Macro call that should be transformed by yield-for-union-ops", "input": "(yield-for-union-ops \"UNION ALL\")", "output": "(defmacro yield-for-union-ops (keyword)\n `(multiple-value-bind (statements others)\n (loop for obj in (conjunctive-op-expressions op)\n if (sql-statement-p obj)\n collecting obj into statements\n else\n collecting obj into others\n finally (return (values statements others)))\n (with-yield-binds\n (format nil (if *inside-select*\n \"(~{~A~^ ~})\"\n \"~{~A~^ ~}\")\n (append (list (format nil ,(format nil \"~~{~~A~~^ ~a ~~}\" keyword)\n (mapcar #'yield statements)))\n (when others\n (list (format nil \"~{~A~^ ~}\"\n (mapcar #'yield others)))))))))", "macroexpand": "(multiple-value-bind (statements others) (loop for obj in (conjunctive-op-expressions op) if (sql-statement-p obj) collecting obj into statements else collecting obj into others finally (return (values statements others))) (with-yield-binds (format nil (if *inside-select* \"(~{~A~^ ~})\" \"~{~A~^ ~}\") (append (list (format nil #A((19) base-char . \"~{~A~^ UNION ALL ~}\") (mapcar (function yield) statements))) (when others (list (format nil \"~{~A~^ ~}\" (mapcar (function yield) others))))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> (string \"M\u0101lum\") #'eof)\n\nIssue: Macro call that should be transformed by *>", "input": "(*> (string \"M\u0101lum\") #'eof)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset200) (multiple-value-bind (#:*>-res201 #:*>-next202) (funcall (string \"M\u0101lum\") #:*>-offset200) (if (ok? #:*>-res201) (funcall (function eof) #:*>-next202) (fail #:*>-next202))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signals error (error \"an error\"))\n\nIssue: Macro call that should be transformed by signals", "input": "(signals error (error \"an error\"))", "output": "(defmacro signals (condition-spec\n &body body)\n \"Generates a pass if BODY signals a condition of type\nCONDITION. BODY is evaluated in a block named NIL, CONDITION is\nnot evaluated.\"\n (let ((block-name (gensym)))\n (destructuring-bind (condition &optional reason-control &rest reason-args)\n (ensure-list condition-spec)\n `(block ,block-name\n (handler-bind ((,condition (lambda (c)\n (declare (ignore c))\n ;; ok, body threw condition\n (add-result 'test-passed\n :test-expr ',condition)\n (return-from ,block-name t))))\n (block nil\n ,@body))\n (process-failure\n ',condition\n ,@(if reason-control\n `(,reason-control ,@reason-args)\n `(\"Failed to signal a ~S\" ',condition)))\n (return-from ,block-name nil)))))", "macroexpand": "(block #:g285 (handler-bind ((error (lambda (c) (declare (ignore c)) (add-result (quote test-passed) :test-expr (quote error)) (return-from #:g285 t)))) (block nil (error \"an error\"))) (process-failure (quote error) \"Failed to signal a ~S\" (quote error)) (return-from #:g285 nil))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-error cannot-not-shadow-core () () \"You cannot shadow or replace core macros or special functions.\")\n\nPattern to recognize: Macro call that should be transformed by define-error", "input": "(define-error cannot-not-shadow-core () () \"You cannot shadow or replace core macros or special functions.\")", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition cannot-not-shadow-core (:error-type varjo-error :prefix \"Varjo\") nil \"You cannot shadow or replace core macros or special functions.\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-form-field-values (name) form (print name))\n\nWrite a macro that addresses: Macro call that should be transformed by with-form-field-values", "input": "(with-form-field-values (name) form (print name))", "output": "(defmacro with-form-field-values (fields form &body body)\n \"Bind the value of FIELDS in FORM.\n\nExample:\n\n@lisp\n(with-form-field-values (name) form\n (print name))\n@end lisp\"\n `(let ,(loop for field in fields\n collect `(,field (field-value (get-field ,form ',field))))\n ,@body))", "macroexpand": "(let ((name (field-value (get-field form (quote name))))) (print name))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (= 1 b))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (= 1 b))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e268 1) (#:a269 b)) (if (progn (= #:e268 #:a269)) (add-result (quote test-passed) :test-expr (quote (= 1 b))) (process-failure (quote (= 1 b)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote b) #:a269 (quote =) #:e268)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(c-assert (null (c-callers old)))\n\nProblem: Macro call that should be transformed by c-assert", "input": "(c-assert (null (c-callers old)))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (null (c-callers old)) (c-break \"failed assertion: ~a\" (quote (null (c-callers old))))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(accase (car x) (:y (setf x :no)) (:z (setf x :yes)))\n\nWhat needs to change: Macro call that should be transformed by accase", "input": "(accase (car x) (:y (setf x :no)) (:z (setf x :yes)))", "output": "(defmacro accase (keyform &body cases)\n \"Like CCASE, except binds the result of the keyform to IT (via LET) for the\nscope of the cases. Unlike CCASE, the keyform/place doesn't receive new values\npossibly stored with STORE-VALUE restart; the new value is received by IT.\"\n `(anaphoric ccase ,keyform ,@cases))", "macroexpand": "(anaphoric ccase (car x) (:y (setf x :no)) (:z (setf x :yes)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is-error (error 'my-condition) 'simple-error)\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is-error (error 'my-condition) 'simple-error)", "output": "(defmacro is (got expected &rest args)\n (with-gensyms (duration result new-args desc)\n (once-only (expected)\n `(let* ((,new-args (list ,@args))\n (,desc (parse-description-and-test ,new-args)))\n (with-catching-errors (:description ,desc :expected ,expected)\n (with-duration ((,duration ,result) ,got)\n (test ,result ,expected ,new-args\n :duration ,duration)))))))", "macroexpand": "(with-duration ((#:duration184 #:error183) (handler-case (error (quote my-condition)) (condition (#:error183) #:error183))) (test #:error183 (quote simple-error) nil :duration #:duration184 :got-form (quote (error (quote my-condition))) :test-fn (function typep) :report-expected-label \"raise a condition\"))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-value-binding table-pairs (var table &aux (iterator (hash-table-iterator table)) next key val) (declare (type hash-table table) (type function iterator)) `(multiple-value-bind (,next ,key ,val) (funcall ,iterator) (cond (,next (update ,(first var) ,key) (update ,(second var) ,val)) (T (end-for)))))\n\nPattern to recognize: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding table-pairs (var table &aux (iterator (hash-table-iterator table)) next key val) (declare (type hash-table table) (type function iterator)) `(multiple-value-bind (,next ,key ,val) (funcall ,iterator) (cond (,next (update ,(first var) ,key) (update ,(second var) ,val)) (T (end-for)))))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding table-pairs (var table) (let ((#:iterator157 (gensym #A((8) base-char . \"ITERATOR\"))) (#:next158 (gensym #A((4) base-char . \"NEXT\"))) (#:key159 (gensym #A((3) base-char . \"KEY\"))) (#:val160 (gensym #A((3) base-char . \"VAL\"))) (#:table156 (gensym #A((5) base-char . \"TABLE\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:table156 table) (list #:iterator157 (list (quote hash-table-iterator) #:table156)) (list #:next158 nil) (list #:key159 nil) (list #:val160 nil) (loop for #:var155 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var155 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:iterator157 :kind 0) #S(sb-impl::comma :expr #:next158 :kind 0) #S(sb-impl::comma :expr #:key159 :kind 0) #S(sb-impl::comma :expr #:val160 :kind 0) #S(sb-impl::comma :expr #:table156 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote hash-table) :kind 0) #S(sb-impl::comma :expr #:table156 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote function) :kind 0) #S(sb-impl::comma :expr #:iterator157 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((iterator #:iterator157) (next #:next158) (key #:key159) (val #:val160) (table #:table156)) (declare (ignorable iterator next key val table)) (sb-int:quasiquote (multiple-value-bind (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr val :kind 0)) (funcall #S(sb-impl::comma :expr iterator :kind 0)) (cond (#S(sb-impl::comma :expr next :kind 0) (update #S(sb-impl::comma :expr (first var) :kind 0) #S(sb-impl::comma :expr key :kind 0)) (update #S(sb-impl::comma :expr (second var) :kind 0) #S(sb-impl::comma :expr val :kind 0))) (t (end-for)))))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(sccase (car x) (:y (setf it :no)) (:z (setf it :yes)))\n\nWhat needs to change: Macro call that should be transformed by sccase", "input": "(sccase (car x) (:y (setf it :no)) (:z (setf it :yes)))", "output": "(defmacro sccase (keyform &body cases)\n \"Like CCASE, except binds the keyform to IT (via SYMBOL-MACROLET) for the\nscope of the cases. IT can be set with SETF.\"\n `(symbolic ccase ,keyform ,@cases))", "macroexpand": "(symbolic ccase (car x) (:y (setf it :no)) (:z (setf it :yes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defsynonym :summing :sum)\n\nIssue: Macro call that should be transformed by defsynonym", "input": "(defsynonym :summing :sum)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :summing) (quote synonym)) (quote :sum)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-bug nil-return-set () (form possible-set) \"Could not establish return-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a\" form possible-set)\n\nProblem: Macro call that should be transformed by define-bug", "input": "(define-bug nil-return-set () (form possible-set) \"Could not establish return-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a\" form possible-set)", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition nil-return-set (:error-type varjo-error :prefix \"Varjo Bug\") (form possible-set) \"Could not establish return-set. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic form: ~a Possible Set: ~a\" form possible-set)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(when (eql (top-sign) 'skip-first-parameter) (pop-sign))\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when (eql (top-sign) 'skip-first-parameter) (pop-sign))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql (top-sign) (quote skip-first-parameter)) (pop-sign))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(matrix-ccase 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by MATRIX-CCASE", "input": "(matrix-ccase 'some-name)", "output": "(defmacro MATRIX-CCASE ...)", "macroexpand": "(let ((#:g243 quote))\n (ccase #:g243))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some-<>\n nil\n nil)\n\nProblem: Macro call that should be transformed by SOME-<>", "input": "(some-<>\n nil\n nil)", "output": "(defmacro SOME-<> ...)", "macroexpand": "(let* ((#:var176 nil)\n (#:var177\n (if #:var176\n (nil #:var176)\n nil)))\n #:var177)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-generic generic (a b &key c) \"Body consisting of pseudo-documentation.\")\n\nProblem: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c) \"Body consisting of pseudo-documentation.\")", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:method (a b &key c) \"Body consisting of pseudo-documentation.\")))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(action (:after node-abstraction) #'handle-pop-hoist-point)\n\nPattern to recognize: Macro call that should be transformed by action", "input": "(action (:after node-abstraction) #'handle-pop-hoist-point)", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-abstraction) (function handle-pop-hoist-point))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(whichever a b c)\n\nProblem: Macro call that should be transformed by whichever", "input": "(whichever a b c)", "output": "(defmacro whichever (&rest possibilities &environment env)\n \"Evaluates exactly one of POSSIBILITIES, chosen at random.\"\n (setf possibilities (mapcar (lambda (p) (macroexpand p env)) possibilities))\n (let ((length (length possibilities)))\n (cond\n ((= 1 length)\n (first possibilities))\n ((every #'constantp possibilities)\n `(svref (load-time-value (vector ,@possibilities)) \n (random ,length)))\n (T\n (labels ((expand (possibilities position random-number)\n (if (null (cdr possibilities))\n (car possibilities)\n (let* ((length (length possibilities))\n (half (truncate length 2))\n (second-half (nthcdr half possibilities))\n (first-half (butlast possibilities (- length half))))\n `(if (< ,random-number ,(+ position half))\n ,(expand first-half position random-number)\n ,(expand second-half (+ position half) random-number))))))\n (with-gensyms (random-number)\n `(let ((,random-number (random ,length)))\n ,(expand possibilities 0 random-number))))))))", "macroexpand": "(let ((#:random-number136 (random 3))) (if (< #:random-number136 1) a (if (< #:random-number136 2) b c)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-cache (\"foo\" :expire 2 :store storage) 1)\n\nWrite a macro that addresses: Macro call that should be transformed by with-cache", "input": "(with-cache (\"foo\" :expire 2 :store storage) 1)", "output": "(defmacro with-cache ((key &key store expire) &body body)\n \"If a cache indicated by KEY exists, this just returns the cache\nvalue without evaluating BODY. Otherwise, this evaluates BODY and\nstores the evaluated value into STORE with KEY and EXPIRE. KEY is a\nform that an evaluated value indicates the cache key.\n\nExample:\n\n (defun f (x)\n (with-cache (x *store*)\n (very-complex-computation x)))\"\n (once-only (key store expire)\n (with-gensyms (value exists-p)\n `(multiple-value-bind (,value ,exists-p)\n (getcache ,key ,store)\n (if ,exists-p\n ,value\n (let ((,value (progn ,@body)))\n (setcache ,key ,value ,store :expire ,expire)\n ,value))))))", "macroexpand": "(let ((#:key247 \"foo\") (#:store248 storage) (#:expire249 2)) (multiple-value-bind (#:value250 #:exists-p251) (getcache #:key247 #:store248) (if #:exists-p251 #:value250 (let ((#:value250 (progn 1))) (setcache #:key247 #:value250 #:store248 :expire #:expire249) #:value250))))", "category": "anaphoric", "technique": "once-only,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.85} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-generator (item generator) (funcall function item))\n\nPattern to recognize: Macro call that should be transformed by do-generator", "input": "(do-generator (item generator) (funcall function item))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g168 generator)) (loop do (if-generator ((item) #:g168) (progn (funcall function item)) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-effective-qualifier generic-function qualifier (intern-hook generic-function hook-name type-list qualifier) `(progn (%defhook-fun ,hook-name ,vanilla-lambda-list ,@body) (%define-method-dispatch ,generic-function ,qualifier ,specialized-lambda-list)))\n\nWhat needs to change: Macro call that should be transformed by with-effective-qualifier", "input": "(with-effective-qualifier generic-function qualifier (intern-hook generic-function hook-name type-list qualifier) `(progn (%defhook-fun ,hook-name ,vanilla-lambda-list ,@body) (%define-method-dispatch ,generic-function ,qualifier ,specialized-lambda-list)))", "output": "(defmacro with-effective-qualifier (gf-name qualifier &body body)\n \"take generic function and a symbol bound to a qualifier and mask that symbol with the effective qualifier.\n\nThe effective qualifier is the default qualifier for the given generic function should there be one defined by\na define-hook-generic form.\"\n `(let ((,qualifier\n (effective-qualifier ,gf-name ,qualifier)))\n ,@body))", "macroexpand": "(let ((qualifier (effective-qualifier generic-function qualifier))) (intern-hook generic-function hook-name type-list qualifier) (sb-int:quasiquote (progn (%defhook-fun #S(sb-impl::comma :expr hook-name :kind 0) #S(sb-impl::comma :expr vanilla-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)) (%define-method-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr specialized-lambda-list :kind 0)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-current-source-form 'some-name)\n\nProblem: Macro call that should be transformed by WITH-CURRENT-SOURCE-FORM", "input": "(with-current-source-form 'some-name)", "output": "(defmacro WITH-CURRENT-SOURCE-FORM ...)", "macroexpand": "(sb-ext:with-current-source-form 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(resolving\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by RESOLVING", "input": "(resolving\n 'some-name)", "output": "(defmacro RESOLVING ...)", "macroexpand": "(resolve\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(producing nil (progn))\n\nIssue: Macro call that should be transformed by PRODUCING", "input": "(producing nil (progn))", "output": "(defmacro PRODUCING ...)", "macroexpand": "(non-opt-producing nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(some-> nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by SOME->", "input": "(some-> nil nil)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:|some126| nil) (#:|some126| (when #:|some126| (nil #:|some126|))))\n #:|some126|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dynamic-let nil)\n\nWhat needs to change: Macro call that should be transformed by DYNAMIC-LET", "input": "(dynamic-let nil)", "output": "(defmacro DYNAMIC-LET ...)", "macroexpand": "(let ()\n (dynamic-wind\n :proceed\n #:g192\n (let ()\n (declare (special))\n (#:g192))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(awhen (incf x) (+ 1 it))\n\nWhat needs to change: Macro call that should be transformed by awhen", "input": "(awhen (incf x) (+ 1 it))", "output": "(defmacro awhen (test &body body)\n \"Like WHEN, except binds the result of the test to IT (via LET) for the scope\nof the body.\"\n `(anaphoric when ,test ,@body))", "macroexpand": "(let ((it (incf x))) (when it (+ 1 it)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-neo4j-fun get-node-relationships (node-id direction types) :get (:uri-spec (format nil \"node/~A/relationships/~A/~{~A~^\\\\&~}\" node-id (cond ((null direction) \"all\") ((symbolp direction) (string-downcase (symbol-name direction))) (t direction)) types)) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))\n\nProblem: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-node-relationships (node-id direction types) :get (:uri-spec (format nil \"node/~A/relationships/~A/~{~A~^\\\\&~}\" node-id (cond ((null direction) \"all\") ((symbolp direction) (string-downcase (symbol-name direction))) (t direction)) types)) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-node-relationships (&key node-id direction types) (let ((uri (format nil \"node/~A/relationships/~A/~{~A~^\\\\&~}\" node-id (cond ((null direction) \"all\") ((symbolp direction) (string-downcase (symbol-name direction))) (t direction)) types)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(compile-$flavor-$methods 'some-name)\n\nIssue: Macro call that should be transformed by COMPILE-$FLAVOR-$METHODS", "input": "(compile-$flavor-$methods 'some-name)", "output": "(defmacro COMPILE-$FLAVOR-$METHODS ...)", "macroexpand": "(eval-when (:load-toplevel) (combine-class-methods 'some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(gen-lambda-with-sticky-stop () (multiple-value-bind (res signal) (funcall source) (if signal res (sticky-stop))))\n\nProblem: Macro call that should be transformed by gen-lambda", "input": "(gen-lambda-with-sticky-stop () (multiple-value-bind (res signal) (funcall source) (if signal res (sticky-stop))))", "output": "(defmacro gen-lambda (params &body rest)\n \"Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions.\"\n `(let ((values-handler (create-values-handler)))\n (declare (ignorable values-handler))\n (make-instance \n 'basic-generator \n :function (lambda ,params ,@rest))))", "macroexpand": "(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (multiple-value-bind (res signal) (funcall source) (if signal res (sticky-stop)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-atomic-updates 'with-atomic-updates)\n\nWhat needs to change: Macro call that should be transformed by with-atomic-updates", "input": "(with-atomic-updates 'with-atomic-updates)", "output": "(defmacro with-atomic-updates ((&rest variables) &body body)\n ;;Self-binding is necessary to avoid losing the previous value\n `(with-atomic-updates* ,variables (let ,(mapcar (lambda (var) (list var var)) variables)) ,@body))", "macroexpand": "(with-atomic-updates* (quote with-atomic-updates) (let ((quote quote) (with-atomic-updates with-atomic-updates))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.8624999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ct-flet nil)\n\nWrite a macro that addresses: Macro call that should be transformed by CT-FLET", "input": "(ct-flet nil)", "output": "(defmacro CT-FLET ...)", "macroexpand": "(cond (*within-captured-dynenv* (progn))\n (t\n (error\n \"No macrodynamic environment has been captured to establish CT-FLET bindings.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-dot nil)\n\nPattern to recognize: Macro call that should be transformed by WITH-DOT", "input": "(with-dot nil)", "output": "(defmacro with-dot (() &body body)\n `(progn ,@(replace-dot-calls body)))", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(c? (/ (len self) 2))\n\nPattern to recognize: Macro call that should be transformed by c?", "input": "(c? (/ (len self) 2))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((/ (len self) 2))) :value-state :unevaluated :rule (c-lambda (/ (len self) 2)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-wcs-math-error-handling (ret (ffloor x)) (check-wcs-math-result))\n\nWrite a macro that addresses: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (ffloor x)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g245 x) (#:g246 nil) (#:g247 (list #:g245))) (declare (ignorable #:g246) (type list #:g247) (dynamic-extent #:g247)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote ffloor) #:g247) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g247)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do-readtable (char readtable) (set-syntax-from-char char #\\A readtable))\n\nIssue: Macro call that should be transformed by do-readtable", "input": "(do-readtable (char readtable) (set-syntax-from-char char #\\A readtable))", "output": "(defmacro do-readtable ((entry-designator readtable &optional result)\n &body body)\n \"Iterate through a readtable's macro characters, and dispatch macro characters.\"\n (destructuring-bind (char &optional reader-fn non-terminating-p disp? table)\n (if (symbolp entry-designator)\n (list entry-designator)\n entry-designator)\n (let ((iter (gensym \"ITER+\"))\n (more? (gensym \"MORE?+\"))\n (rt (gensym \"READTABLE+\")))\n `(let ((,rt ,readtable))\n (with-readtable-iterator (,iter ,rt)\n (loop\n (multiple-value-bind (,more?\n ,char\n ,@(when reader-fn (list reader-fn))\n ,@(when disp? (list disp?))\n ,@(when table (list table)))\n (,iter)\n (unless ,more? (return ,result))\n (let ,(when non-terminating-p\n ;; FIXME: N-T-P should be incorporated in iterators.\n `((,non-terminating-p\n (nth-value 1 (get-macro-character ,char ,rt)))))\n ,@body))))))))", "macroexpand": "(let ((#:readtable+143 readtable)) (with-readtable-iterator (#:iter+141 #:readtable+143) (loop (multiple-value-bind (#:more?+142 char) (#:iter+141) (unless #:more?+142 (return nil)) (let nil (set-syntax-from-char char #\\LATIN_CAPITAL_LETTER_A readtable))))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-<>> nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by -<>>", "input": "(-<>> nil (progn))", "output": "(defmacro -<>> ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ematch0 more-patterns (nil nil) ((list* _ subpattern more-patterns) (append (%variables subpattern) (%variables-more-patterns more-patterns))))\n\nIssue: Macro call that should be transformed by ematch0", "input": "(ematch0 more-patterns (nil nil) ((list* _ subpattern more-patterns) (append (%variables subpattern) (%variables-more-patterns more-patterns))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 more-patterns (nil nil) ((list* _ subpattern more-patterns) (append (%variables subpattern) (%variables-more-patterns more-patterns))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ct-let* nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by CT-LET*", "input": "(ct-let* nil\n nil)", "output": "(defmacro CT-LET* ...)", "macroexpand": "(cond (*within-captured-dynenv* (progn nil))\n (t\n (error\n \"No macrodynamic environment has been captured to establish CT-LET* bindings.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(check-cursor-attached cluffer:buffer (cursor))\n\nProblem: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:buffer (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:buffer :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(make-method-function-call (function-name info) args `(#'call-next-method ,(and next-method t)))\n\nWrite a macro that addresses: Macro call that should be transformed by make-method", "input": "(make-method-function-call (function-name info) args `(#'call-next-method ,(and next-method t)))", "output": "(defmacro make-method (form)\n `(cl:make-method ,form))", "macroexpand": "(make-method-function-call (function-name info) args (sb-int:quasiquote ((function call-next-method) #S(sb-impl::comma :expr (and next-method t) :kind 0))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym until :until)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym until :until)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote until) (quote synonym)) (quote :until)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defvar-unbound *start-char* \"Bound to the opening outer delimiter while parsing a string.\")\n\nWhat needs to change: Macro call that should be transformed by defvar-unbound", "input": "(defvar-unbound *start-char* \"Bound to the opening outer delimiter while parsing a string.\")", "output": "(defmacro defvar-unbound (variable-name documentation)\n \"Like DEFVAR, but the variable will be unbound rather than getting\nan initial value. This is useful for variables which should have no\nglobal value but might have a dynamically bound value.\"\n ;; stolen from comp.lang.lisp article by\n ;; \"prunesquallor@comcast.net\"\n `(eval-when (:load-toplevel :compile-toplevel :execute)\n (defvar ,variable-name)\n (setf (documentation ',variable-name 'variable)\n ,documentation)))", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute) (defvar *start-char*) (setf (documentation (quote *start-char*) (quote variable)) \"Bound to the opening outer delimiter while parsing a string.\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defannotation inline* (name) (:alias inline :inline t) \"Shorthand for (DECLARE (INLINE ...)).\" (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type '(defun defmethod))) `(progn (declaim (inline ,symbol)) ,name) `(declare (inline ,name)))))\n\nProblem: Macro call that should be transformed by defannotation", "input": "(defannotation inline* (name) (:alias inline :inline t) \"Shorthand for (DECLARE (INLINE ...)).\" (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type '(defun defmethod))) `(progn (declaim (inline ,symbol)) ,name) `(declare (inline ,name)))))", "output": "(defmacro defannotation (name lambda-list options &body body)\n `(progn\n (set-annotation-options ',name ',options)\n (defmacro ,name ,lambda-list ,@body)))", "macroexpand": "(progn (set-annotation-options (quote inline*) (quote (:alias inline :inline t))) (defmacro inline* (name) \"Shorthand for (DECLARE (INLINE ...)).\" (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type (quote (defun defmethod)))) (sb-int:quasiquote (progn (declaim (inline #S(sb-impl::comma :expr symbol :kind 0))) #S(sb-impl::comma :expr name :kind 0))) (sb-int:quasiquote (declare (inline #S(sb-impl::comma :expr name :kind 0))))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ensure-gethash x table 42)\n\nProblem: Macro call that should be transformed by ensure-gethash", "input": "(ensure-gethash x table 42)", "output": "(defmacro ensure-gethash (key hash-table &optional default)\n \"Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT\nunder key before returning it. Secondary return value is true if key was\nalready in the table.\"\n (once-only (key hash-table)\n (with-unique-names (value presentp)\n `(multiple-value-bind (,value ,presentp) (gethash ,key ,hash-table)\n (if ,presentp\n (values ,value ,presentp)\n (values (setf (gethash ,key ,hash-table) ,default) nil))))))", "macroexpand": "(let ((#:n-key-159 x) (#:n-hash-table-160 table)) (multiple-value-bind (#:value161 #:foundp162) (gethash #:n-key-159 #:n-hash-table-160) (if #:foundp162 (values #:value161 t) (values (setf (gethash #:n-key-159 #:n-hash-table-160) 42) nil))))", "category": "anaphoric", "technique": "once-only,anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder (:static :path (lambda (path-info) (when (starts-with-subseq \"/static/\" path-info) (subseq path-info #.(length \"/static\")))) :root (asdf:system-relative-pathname :lack #P\"data/\")) (lambda (env) (declare (ignore env)) `(200 (:content-type \"text/plain\") (\"ok\"))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder (:static :path (lambda (path-info) (when (starts-with-subseq \"/static/\" path-info) (subseq path-info #.(length \"/static\")))) :root (asdf:system-relative-pathname :lack #P\"data/\")) (lambda (env) (declare (ignore env)) `(200 (:content-type \"text/plain\") (\"ok\"))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app230) (funcall (find-middleware :static) #:app230 :path (lambda (path-info) (when (starts-with-subseq \"/static/\" path-info) (subseq path-info 7))) :root (asdf/system:system-relative-pathname :lack #P\"data/\"))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (\"ok\"))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder :session (:csrf :one-time t) #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type \"text/html\") (,(if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test #'string=)) (cdr (assoc \"name\" (request-body-parameters req) :test #'string=)) (html-form env)))))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder :session (:csrf :one-time t) #'(lambda (env) (let ((req (make-request env))) `(200 (:content-type \"text/html\") (,(if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test #'string=)) (cdr (assoc \"name\" (request-body-parameters req) :test #'string=)) (html-form env)))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (find-middleware :session) (lambda (#:app206) (funcall (find-middleware :csrf) #:app206 :one-time t)))) :initial-value (to-app (function (lambda (env) (let ((req (make-request env))) (sb-int:quasiquote (200 (:content-type \"text/html\") (#S(sb-impl::comma :expr (if (and (eq :post (request-method req)) (assoc \"name\" (request-body-parameters req) :test (function string=))) (cdr (assoc \"name\" (request-body-parameters req) :test (function string=))) (html-form env)) :kind 0)))))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(match ARG (PATTERN BODY...))\n\nPattern to recognize: Macro call that should be transformed by match", "input": "(match ARG (PATTERN BODY...))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(%or (%or (let ((pattern arg)) body...) (fail)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-name-transformer \"BAZ-\" name)\n\nWhat needs to change: Macro call that should be transformed by make-name-transformer", "input": "(make-name-transformer \"BAZ-\" name)", "output": "(defmacro make-name-transformer (&rest elements)\n \"Return an accessor name transformer.\nThe unquoted `name' symbol argument is substituted for the slot name.\nClass option examples:\n\n :accessor-name-transformer (make-name-transformer \\\"FOO-\\\" name \\\"-BAR\\\")\n\nUse the slot name directly:\n\n :accessor-name-transformer (make-name-transformer name)\"\n `(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol ,@(mapcar (lambda (el)\n (if (and (symbolp el)\n (string= (symbol-name el) \"NAME\"))\n 'name\n el))\n elements))))", "macroexpand": "(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol \"BAZ-\" name))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-wind\n nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-WIND", "input": "(dynamic-wind\n nil\n (progn))", "output": "(defmacro DYNAMIC-WIND ...)", "macroexpand": "(flet ((#:dynamic-wind-thunk222 (#:proceed-thunk223)\n (macrolet ((proceed (&body #:proceed-body224)\n `(if ,'#:proceed-thunk223\n (funcall (the function ,'#:proceed-thunk223))\n (progn ,@#:proceed-body224))))\n nil\n (progn))))\n (declare (inline #:dynamic-wind-thunk222))\n (let ((*dynamic-wind-stack*\n (cons #'#:dynamic-wind-thunk222 *dynamic-wind-stack*)))\n (#:dynamic-wind-thunk222 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defmacro+ps nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DEFMACRO+PS", "input": "(defmacro+ps nil\n (progn))", "output": "(defmacro DEFMACRO+PS ...)", "macroexpand": "(progn\n (defmacro nil (progn))\n (defpsmacro nil\n (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defhandler defun (defun name lambda-list &rest body) `(list* ',defun ,(apply 'dump-fbinding name lambda-list body)))\n\nPattern to recognize: Macro call that should be transformed by defhandler", "input": "(defhandler defun (defun name lambda-list &rest body) `(list* ',defun ,(apply 'dump-fbinding name lambda-list body)))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-defun (defun name lambda-list &rest body) (sb-int:quasiquote (list* (quote #S(sb-impl::comma :expr defun :kind 0)) #S(sb-impl::comma :expr (apply (quote dump-fbinding) name lambda-list body) :kind 0)))) (setf (gethash (quote defun) *form-handler*) (quote hander-defun)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defalias path:absolute-p (pathname) cl-fad:pathname-absolute-p)\n\nIssue: Macro call that should be transformed by defalias", "input": "(defalias path:absolute-p (pathname) cl-fad:pathname-absolute-p)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:absolute-p (pathname) (pathname-absolute-p pathname)) (define-compiler-macro path:absolute-p (&rest args) (list* (quote pathname-absolute-p) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.945} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defvar-compile-time *block-tags* '() \"This must be globally NIL.\")\n\nWhat needs to change: Macro call that should be transformed by defvar-compile-time", "input": "(defvar-compile-time *block-tags* '() \"This must be globally NIL.\")", "output": "(defmacro defvar-compile-time (name &optional initial-value documentation)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,name ,initial-value ,documentation)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *block-tags* (quote nil) \"This must be globally NIL.\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(unwind-protect-case () (error \"FOOF!\") (:normal (push :normal result1)) (:abort (push :abort result1)) (:always (push :always result1)))\n\nIssue: Macro call that should be transformed by unwind-protect-case", "input": "(unwind-protect-case () (error \"FOOF!\") (:normal (push :normal result1)) (:abort (push :abort result1)) (:always (push :always result1)))", "output": "(defmacro unwind-protect-case ((&optional abort-flag) protected-form &body clauses)\n \"Like CL:UNWIND-PROTECT, but you can specify the circumstances that\nthe cleanup CLAUSES are run.\n\n clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*\n\nClauses can be given in any order, and more than one clause can be\ngiven for each circumstance. The clauses whose denoted circumstance\noccured, are executed in the order the clauses appear.\n\nABORT-FLAG is the name of a variable that will be bound to T in\nCLAUSES if the PROTECTED-FORM aborted preemptively, and to NIL\notherwise.\n\nExamples:\n\n (unwind-protect-case ()\n (protected-form)\n (:normal (format t \\\"This is only evaluated if PROTECTED-FORM executed normally.~%\\\"))\n (:abort (format t \\\"This is only evaluated if PROTECTED-FORM aborted preemptively.~%\\\"))\n (:always (format t \\\"This is evaluated in either case.~%\\\")))\n\n (unwind-protect-case (aborted-p)\n (protected-form)\n (:always (perform-cleanup-if aborted-p)))\n\"\n (check-type abort-flag (or null symbol))\n (let ((gflag (gensym \"FLAG+\")))\n `(let ((,gflag t))\n (unwind-protect (multiple-value-prog1 ,protected-form (setf ,gflag nil))\n\t (let ,(and abort-flag `((,abort-flag ,gflag)))\n\t ,@(loop for (cleanup-kind . forms) in clauses\n\t\t collect (ecase cleanup-kind\n\t\t\t (:normal `(when (not ,gflag) ,@forms))\n\t\t\t (:abort `(when ,gflag ,@forms))\n\t\t\t (:always `(progn ,@forms)))))))))", "macroexpand": "(let ((#:flag+125 t)) (unwind-protect (multiple-value-prog1 (error \"FOOF!\") (setf #:flag+125 nil)) (let nil (when (not #:flag+125) (push :normal result1)) (when #:flag+125 (push :abort result1)) (progn (push :always result1)))))", "category": "control-flow", "technique": "gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun/1 clearerr (fd) (setf (feof fd) 0 (ferror fd) 0))\n\nIssue: Macro call that should be transformed by defun/1", "input": "(defun/1 clearerr (fd) (setf (feof fd) 0 (ferror fd) 0))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun clearerr (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (setf (feof fd) 0 (ferror fd) 0)) (defparameter clearerr (vacietis.c:mkptr& (symbol-function (quote clearerr)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(signal-syntax-error \"Unknown item ~A in char-class list.\" item)\n\nWrite a macro that addresses: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Unknown item ~A in char-class list.\" item)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Unknown item ~A in char-class list.\" item)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(class-stealth-mixins nil)\n\nIssue: Macro call that should be transformed by CLASS-STEALTH-MIXINS", "input": "(class-stealth-mixins nil)", "output": "(defmacro CLASS-STEALTH-MIXINS ...)", "macroexpand": "(gethash nil *stealth-mixins*)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-temp (d :directory t :debug (<= 1 *debug-prolog*)) (with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (let* ((executable (namestring (make-pathname :type \"out\" :defaults input-file)))) (run-command-with-debug-print `(\"gplc\" ,input-file \"-o\" ,executable) :input input :output output :error error) (run-command-with-debug-print `(,executable) :input input :output output :error error))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-temp", "input": "(with-temp (d :directory t :debug (<= 1 *debug-prolog*)) (with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (let* ((executable (namestring (make-pathname :type \"out\" :defaults input-file)))) (run-command-with-debug-print `(\"gplc\" ,input-file \"-o\" ,executable) :input input :output output :error error) (run-command-with-debug-print `(,executable) :input input :output output :error error))))", "output": "(defmacro with-temp ((var &key directory template (tmpdir \"/tmp/\") debug) &body body)\n \"Create a temporary file, then remove the file by unwind-protect.\nMost arguments are analogous to mktemp.\nWhen DIRECTORY is non-nil, creates a directory instead.\nDEBUG is a form.\nWhen evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.\nIt may be evaluated multiple times.\"\n (with-gensyms (command)\n `(let ((,var (uiop:run-program\n (let ((,command (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\"\n ,tmpdir ,directory ,template)))\n (when ,debug\n (format *error-output* \"~&; ~a~%\" ,command))\n ,command)\n :output '(:string :stripped t))))\n (unwind-protect\n (progn ,@body)\n (if ,debug\n (format *error-output* \"~&; not removing ~a for debugging~%\" ,var)\n (uiop:run-program (format nil \"rm -rf ~a\" (namestring ,var)) :ignore-error-status t))))))", "macroexpand": "(let ((d (uiop/run-program:run-program (let ((#:command173 (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\" \"/tmp/\" t nil))) (when (<= 1 *debug-prolog*) (format *error-output* \"~&; ~a~%\" #:command173)) #:command173) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (let* ((executable (namestring (make-pathname :type \"out\" :defaults input-file)))) (run-command-with-debug-print (sb-int:quasiquote (\"gplc\" #S(sb-impl::comma :expr input-file :kind 0) \"-o\" #S(sb-impl::comma :expr executable :kind 0))) :input input :output output :error error) (run-command-with-debug-print (sb-int:quasiquote (#S(sb-impl::comma :expr executable :kind 0))) :input input :output output :error error)))) (if (<= 1 *debug-prolog*) (format *error-output* \"~&; not removing ~a for debugging~%\" d) (uiop/run-program:run-program (format nil \"rm -rf ~a\" (namestring d)) :ignore-error-status t))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(f_%\n 'some-name)\n\nProblem: Macro call that should be transformed by F_%", "input": "(f_%\n 'some-name)", "output": "(defmacro F_% ...)", "macroexpand": "(lambda (&rest #:|ignore130|) (declare (ignore #:|ignore130|)) 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(assoc-cdr :message at-data)\n\nProblem: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr :message at-data)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc :message at-data :test (function eql)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(deferror \"40001\" serialization-failure transaction-rollback)\n\nPattern to recognize: Macro call that should be transformed by deferror", "input": "(deferror \"40001\" serialization-failure transaction-rollback)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition serialization-failure (transaction-rollback) nil) (setf (gethash \"40001\" *error-table*) (quote serialization-failure)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-iter iterator-starmap (base-iter fn) (starmap (fn iterable-of-iterables) \"Applies `fn` to the first argument of `iterable-of-iterables`, then the second, etc ``` (starmap #'+ '(1 2) '(3 4)) ;; 3, 7 ```\" (init-state (base-iter (make-iterator iterable-of-iterables)) fn)) (multiple-value-bind (base-item base-alive) (next base-iter) (if base-alive (values (apply fn (iter-to-list base-item)) t) (values nil nil))))\n\nProblem: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-starmap (base-iter fn) (starmap (fn iterable-of-iterables) \"Applies `fn` to the first argument of `iterable-of-iterables`, then the second, etc ``` (starmap #'+ '(1 2) '(3 4)) ;; 3, 7 ```\" (init-state (base-iter (make-iterator iterable-of-iterables)) fn)) (multiple-value-bind (base-item base-alive) (next base-iter) (if base-alive (values (apply fn (iter-to-list base-item)) t) (values nil nil))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname140 (&key base-iter fn) (labels ((self nil (multiple-value-bind (base-item base-alive) (next base-iter) (if base-alive (values (apply fn (iter-to-list base-item)) t) (values nil nil))))) (function self)))) (defun starmap (fn iterable-of-iterables) \"Applies `fn` to the first argument of `iterable-of-iterables`, then the second, etc ``` (starmap #'+ '(1 2) '(3 4)) ;; 3, 7 ```\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname140)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (init-state (base-iter (make-iterator iterable-of-iterables)) fn))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(alist-bind (name value) form (maybe-add-constant name value))\n\nPattern to recognize: Macro call that should be transformed by alist-bind", "input": "(alist-bind (name value) form (maybe-add-constant name value))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist245 form)) (let ((name (aval :name #:alist245)) (value (aval :value #:alist245))) (maybe-add-constant name value)))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-for nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by DO-FOR", "input": "(do-for nil\n :key\n nil)", "output": "(defmacro DO-FOR ...)", "macroexpand": "(block nil (lc ((block nil (tagbody (return (progn :key nil))))) progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-standard-readtable\n nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by WITH-STANDARD-READTABLE", "input": "(with-standard-readtable\n nil\n :key\n nil)", "output": "(defmacro WITH-STANDARD-READTABLE ...)", "macroexpand": "(bind ((*readtable* (with-standard-io-syntax (copy-readtable *readtable*))))\n nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-bug name-mismatch (:error-type varjo-critical-error) (lisp glsl taken) \"The glsl name ~s was generated for the lisp-name ~s However this clashes with glsl name for the previous symbol ~s. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience\" glsl lisp taken)\n\nProblem: Macro call that should be transformed by define-bug", "input": "(define-bug name-mismatch (:error-type varjo-critical-error) (lisp glsl taken) \"The glsl name ~s was generated for the lisp-name ~s However this clashes with glsl name for the previous symbol ~s. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience\" glsl lisp taken)", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition name-mismatch (:error-type varjo-critical-error :prefix \"Varjo Bug\") (lisp glsl taken) \"The glsl name ~s was generated for the lisp-name ~s However this clashes with glsl name for the previous symbol ~s. This is Varjo bug, please raise an issue on github. Sorry for the inconvenience\" glsl lisp taken)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-yield-binds (values (format nil \"~A JOIN ~A~:[~;~:* ON ~A~]~:[~;~:* USING ~A~]\" (join-clause-kind clause) (yield (join-clause-statement clause)) (if (join-clause-on clause) (yield (join-clause-on clause)) nil) (if (join-clause-using clause) (yield (join-clause-using clause)) nil))))\n\nIssue: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (values (format nil \"~A JOIN ~A~:[~;~:* ON ~A~]~:[~;~:* USING ~A~]\" (join-clause-kind clause) (yield (join-clause-statement clause)) (if (join-clause-on clause) (yield (join-clause-on clause)) nil) (if (join-clause-using clause) (yield (join-clause-using clause)) nil))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (values (format nil \"~A JOIN ~A~:[~;~:* ON ~A~]~:[~;~:* USING ~A~]\" (join-clause-kind clause) (yield (join-clause-statement clause)) (if (join-clause-on clause) (yield (join-clause-on clause)) nil) (if (join-clause-using clause) (yield (join-clause-using clause)) nil)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*> #'any)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> #'any)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset160) (funcall (function any) #:*>-offset160))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(skip)\n\nPattern to recognize: Macro call that should be transformed by skip", "input": "(skip)", "output": "(defmacro skip () `(next))", "macroexpand": "(trivia.next:next)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-method-combination% max :operator max :identity-with-one-argument t)\n\nProblem: Macro call that should be transformed by define-method-combination%", "input": "(define-method-combination% max :operator max :identity-with-one-argument t)", "output": "(defmacro define-method-combination% (name &rest args)\n \"Define a method-combination for the static-dispatch system only.\n\n Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION.\"\n\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf\n (combination-function ',name)\n ,(match args\n ((or nil\n (list* (and (type symbol) (not nil)) _))\n\n (destructuring-bind (&key (operator name) (identity-with-one-argument nil))\n args\n\n `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))\n\n (_\n `(method-combination-function ,name ,@args))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote max)) (method-combination-function-short max max t)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(maybe-once-only nil)\n\nIssue: Macro call that should be transformed by MAYBE-ONCE-ONLY", "input": "(maybe-once-only nil)", "output": "(defmacro MAYBE-ONCE-ONLY ...)", "macroexpand": "(let* ((#:g181 nil))\n `(let* ,(nreverse #:g181)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(sif (car it) (setf it 'a) :foo)\n\nProblem: Macro call that should be transformed by sif", "input": "(sif (car it) (setf it 'a) :foo)", "output": "(defmacro sif (test then &optional else)\n \"Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for\nthe scope of the then and else expressions. IT can be set with SETF\"\n `(symbolic if ,test ,then ,else))", "macroexpand": "(symbolic if (car it) (setf it (quote a)) :foo)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-test shuffle :serial NIL (true 1) (true 2) (true 3) (true 4) (true 5))\n\nWhat needs to change: Macro call that should be transformed by define-test", "input": "(define-test shuffle :serial NIL (true 1) (true 2) (true 3) (true 4) (true 5))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote shuffle) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote shuffle) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (true 1)) (lambda nil (true 2)) (lambda nil (true 3)) (lambda nil (true 4)) (lambda nil (true 5))) :parent (quote nil) (quote :serial) (quote nil))) (quote shuffle))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(-> (one) :ignore-invariant t () (increment))\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(-> (one) :ignore-invariant t () (increment))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically (one) :ignore-invariant t nil (increment))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(parse-conjunctive-clauses client instance nil :var (parse-d-spec client))\n\nIssue: Macro call that should be transformed by parse-conjunctive-clauses", "input": "(parse-conjunctive-clauses client instance nil :var (parse-d-spec client))", "output": "(defmacro parse-conjunctive-clauses (client region read-name-p &rest args)\n (with-unique-names (clauses next)\n `(prog (,clauses)\n ,next\n (push (do-parse-clause ,client ,region *index* ,read-name-p ,@args)\n ,clauses)\n (when (maybe-parse-token :keywords '(:and))\n (go ,next))\n (return (nreverse ,clauses)))))", "macroexpand": "(prog (#:clauses126) #:next127 (push (do-parse-clause client instance *index* nil :var (parse-d-spec client)) #:clauses126) (when (maybe-parse-token :keywords (quote (:and))) (go #:next127)) (return (nreverse #:clauses126)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(signal-syntax-error* (1- (lexer-pos lexer)) \"Opening #\\< in named group has no closing #\\>.\")\n\nWrite a macro that addresses: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (1- (lexer-pos lexer)) \"Opening #\\< in named group has no closing #\\>.\")", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos (1- (lexer-pos lexer)) :format-control \"Opening #< in named group has no closing #>.\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield-binds (format nil \"~A ~A ~A\" (if (sql-statement-p (infix-op-left op)) (yield (make-sql-list (infix-op-left op))) (yield (infix-op-left op))) (sql-op-name op) (if (sql-statement-p (infix-op-right op)) (yield (make-sql-list (infix-op-right op))) (yield (infix-op-right op)))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~A ~A ~A\" (if (sql-statement-p (infix-op-left op)) (yield (make-sql-list (infix-op-left op))) (yield (infix-op-left op))) (sql-op-name op) (if (sql-statement-p (infix-op-right op)) (yield (make-sql-list (infix-op-right op))) (yield (infix-op-right op)))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~A ~A ~A\" (if (sql-statement-p (infix-op-left op)) (yield (make-sql-list (infix-op-left op))) (yield (infix-op-left op))) (sql-op-name op) (if (sql-statement-p (infix-op-right op)) (yield (make-sql-list (infix-op-right op))) (yield (infix-op-right op))))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defalias path:catdir (&rest pathnames) cl-fad:merge-pathnames-as-directory)\n\nWrite a macro that addresses: Macro call that should be transformed by defalias", "input": "(defalias path:catdir (&rest pathnames) cl-fad:merge-pathnames-as-directory)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:catdir (&rest pathnames) (apply (function merge-pathnames-as-directory) pathnames)) (define-compiler-macro path:catdir (&rest args) (list* (quote merge-pathnames-as-directory) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.945} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defalias path:catfile (&rest pathnames) cl-fad:merge-pathnames-as-file)\n\nProblem: Macro call that should be transformed by defalias", "input": "(defalias path:catfile (&rest pathnames) cl-fad:merge-pathnames-as-file)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:catfile (&rest pathnames) (apply (function merge-pathnames-as-file) pathnames)) (define-compiler-macro path:catfile (&rest args) (list* (quote merge-pathnames-as-file) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.945} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-wind\n nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-WIND", "input": "(dynamic-wind\n nil\n nil)", "output": "(defmacro DYNAMIC-WIND ...)", "macroexpand": "(flet ((#:dynamic-wind-thunk219 (#:proceed-thunk220)\n (macrolet ((proceed (&body #:proceed-body221)\n `(if ,'#:proceed-thunk220\n (funcall (the function ,'#:proceed-thunk220))\n (progn ,@#:proceed-body221))))\n nil\n nil)))\n (declare (inline #:dynamic-wind-thunk219))\n (let ((*dynamic-wind-stack*\n (cons #'#:dynamic-wind-thunk219 *dynamic-wind-stack*)))\n (#:dynamic-wind-thunk219 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dletf nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DLETF", "input": "(dletf nil\n (progn))", "output": "(defmacro DLETF ...)", "macroexpand": "(special-symbol-progv (with-symbol-access\n (list))\n (list)\n (locally (declare (special)) (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-wcs-math-error-handling (ret (log x (float 2 x))) (check-wcs-math-result))\n\nWrite a macro that addresses: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (log x (float 2 x))) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g230 x) (#:g231 (float 2 x)) (#:g232 (list #:g230 #:g231))) (declare (ignorable #:g231) (type list #:g232) (dynamic-extent #:g232)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote log) #:g232) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g232)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(do+ (options :atomic-updates nil) (for x (across #(1 2 3 4) :index index)) (for k (in '(a b c d e))) (returning (list x k :index index)))\n\nPattern to recognize: Macro call that should be transformed by do+", "input": "(do+ (options :atomic-updates nil) (for x (across #(1 2 3 4) :index index)) (for k (in '(a b c d e))) (returning (list x k :index index)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (options :atomic-updates nil) (for x (across #(1 2 3 4) :index index)) (for k (in (quote (a b c d e)))) (returning (list x k :index index)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-custom-var (:symbols-package *json-symbols-package*) (find-package 'keyword))\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:symbols-package *json-symbols-package*) (find-package 'keyword))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*json-symbols-package* . :symbols-package)) *custom-vars* :test (function equal)) (defvar *json-symbols-package* (find-package (quote keyword)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(-<>> nil nil)\n\nPattern to recognize: Macro call that should be transformed by -<>>", "input": "(-<>> nil nil)", "output": "(defmacro -<>> ...)", "macroexpand": "(->> nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-generic generic ((a a) (b b) &key (c nil) &allow-other-keys) (+ a b))\n\nWhat needs to change: Macro call that should be transformed by define-generic", "input": "(define-generic generic ((a a) (b b) &key (c nil) &allow-other-keys) (+ a b))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key &allow-other-keys) (:method ((a a) (b b) &key (c nil) &allow-other-keys) (+ a b))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-value-binding table-keys (var table &aux (iterator (hash-table-iterator table)) next key val) (declare (type hash-table table) (type function iterator)) `(multiple-value-bind (,next ,key ,val) (funcall ,iterator) (declare (ignore ,val)) (if ,next (update ,var ,key) (end-for))))\n\nWhat needs to change: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding table-keys (var table &aux (iterator (hash-table-iterator table)) next key val) (declare (type hash-table table) (type function iterator)) `(multiple-value-bind (,next ,key ,val) (funcall ,iterator) (declare (ignore ,val)) (if ,next (update ,var ,key) (end-for))))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding table-keys (var table) (let ((#:iterator145 (gensym #A((8) base-char . \"ITERATOR\"))) (#:next146 (gensym #A((4) base-char . \"NEXT\"))) (#:key147 (gensym #A((3) base-char . \"KEY\"))) (#:val148 (gensym #A((3) base-char . \"VAL\"))) (#:table144 (gensym #A((5) base-char . \"TABLE\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:table144 table) (list #:iterator145 (list (quote hash-table-iterator) #:table144)) (list #:next146 nil) (list #:key147 nil) (list #:val148 nil) (loop for #:var143 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var143 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:iterator145 :kind 0) #S(sb-impl::comma :expr #:next146 :kind 0) #S(sb-impl::comma :expr #:key147 :kind 0) #S(sb-impl::comma :expr #:val148 :kind 0) #S(sb-impl::comma :expr #:table144 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote hash-table) :kind 0) #S(sb-impl::comma :expr #:table144 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote function) :kind 0) #S(sb-impl::comma :expr #:iterator145 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((iterator #:iterator145) (next #:next146) (key #:key147) (val #:val148) (table #:table144)) (declare (ignorable iterator next key val table)) (sb-int:quasiquote (multiple-value-bind (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr val :kind 0)) (funcall #S(sb-impl::comma :expr iterator :kind 0)) (declare (ignore #S(sb-impl::comma :expr val :kind 0))) (if #S(sb-impl::comma :expr next :kind 0) (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr key :kind 0)) (end-for))))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defgenerator cycle (list-or-gen) \"Repeatedly cycles through a list or generator, yielding its elements indefinitely. Eg: (cycle '(a b c d)) -> a b c d a b c d a b ... Note that this tool may consume considerable storage if the source iterable is long.\" (let ((data (cond ((generatorp list-or-gen) (let ((accum nil)) (do-generator (g list-or-gen) (yield g) (push g accum)) (nreverse accum))) ((listp list-or-gen) list-or-gen) (t (error \"Gen must be a list or generator\"))))) (loop do (dolist (x data) (yield x)))))\n\nIssue: Macro call that should be transformed by defgenerator", "input": "(defgenerator cycle (list-or-gen) \"Repeatedly cycles through a list or generator, yielding its elements indefinitely. Eg: (cycle '(a b c d)) -> a b c d a b c d a b ... Note that this tool may consume considerable storage if the source iterable is long.\" (let ((data (cond ((generatorp list-or-gen) (let ((accum nil)) (do-generator (g list-or-gen) (yield g) (push g accum)) (nreverse accum))) ((listp list-or-gen) list-or-gen) (t (error \"Gen must be a list or generator\"))))) (loop do (dolist (x data) (yield x)))))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun cycle (list-or-gen) \"Repeatedly cycles through a list or generator, yielding its elements indefinitely. Eg: (cycle '(a b c d)) -> a b c d a b c d a b ... Note that this tool may consume considerable storage if the source iterable is long.\" (with-yield (let ((data (cond ((generatorp list-or-gen) (let ((accum nil)) (do-generator (g list-or-gen) (yield g) (push g accum)) (nreverse accum))) ((listp list-or-gen) list-or-gen) (t (error \"Gen must be a list or generator\"))))) (loop do (dolist (x data) (yield x))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-accumulation-binding minimizing (var form &key key) (let ((result (gensym \"RESULT\"))) `(let ((,result ,form)) (when (or (not ,var) (< ,(if key `(funcall ,key ,result) result) ,(if key `(funcall ,key ,var) var))) (setf ,var ,result)))))\n\nWhat needs to change: Macro call that should be transformed by define-accumulation-binding", "input": "(define-accumulation-binding minimizing (var form &key key) (let ((result (gensym \"RESULT\"))) `(let ((,result ,form)) (when (or (not ,var) (< ,(if key `(funcall ,key ,result) result) ,(if key `(funcall ,key ,var) var))) (setf ,var ,result)))))", "output": "(defmacro define-accumulation-binding (name (var &rest args) &body body)\n `(define-form-binding ,name (,var ,@args)\n ,@(form-fiddle:lambda-declarations `(lambda () ,@body))\n (values\n (progn ,@(form-fiddle:lambda-forms `(lambda () ,@body)))\n (delist var))))", "macroexpand": "(define-form-binding minimizing (var form &key key) (values (progn (let ((result (gensym \"RESULT\"))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr result :kind 0) #S(sb-impl::comma :expr form :kind 0))) (when (or (not #S(sb-impl::comma :expr var :kind 0)) (< #S(sb-impl::comma :expr (if key (sb-int:quasiquote (funcall #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr result :kind 0))) result) :kind 0) #S(sb-impl::comma :expr (if key (sb-int:quasiquote (funcall #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr var :kind 0))) var) :kind 0))) (setf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr result :kind 0))))))) (delist var)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(builder :session (lambda (env) (if (equal (getf env :path-info) \"/delayed-expire\") (lambda (responder) (setf (getf (getf env :lack.session.options) :expire) t) (funcall responder '(200 () (\"hi\")))) (lambda (responder) (funcall responder '(200 () \"hi\"))))))\n\nProblem: Macro call that should be transformed by builder", "input": "(builder :session (lambda (env) (if (equal (getf env :path-info) \"/delayed-expire\") (lambda (responder) (setf (getf (getf env :lack.session.options) :expire) t) (funcall responder '(200 () (\"hi\")))) (lambda (responder) (funcall responder '(200 () \"hi\"))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (find-middleware :session))) :initial-value (to-app (lambda (env) (if (equal (getf env :path-info) \"/delayed-expire\") (lambda (responder) (setf (getf (getf env :lack.session.options) :expire) t) (funcall responder (quote (200 nil (\"hi\"))))) (lambda (responder) (funcall responder (quote (200 nil \"hi\"))))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-iter ignored-backing-name (curr-val step) (count (start step) (init-state (curr-val start) step)) (prog1 curr-val (incf curr-val step)))\n\nProblem: Macro call that should be transformed by def-iter", "input": "(def-iter ignored-backing-name (curr-val step) (count (start step) (init-state (curr-val start) step)) (prog1 curr-val (incf curr-val step)))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname129 (&key curr-val step) (labels ((self nil (prog1 curr-val (incf curr-val step)))) (function self)))) (defun count (start step) \"Function had no docstring, so this one was inserted\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname129)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (init-state (curr-val start) step))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defgenerator islice (generator stop-or-start &optional (stop nil has-stop-p) step) \"Emits a subrange of generator. If only stop-or-start is set, islice will emit up to it and stop. If both stop-or-start and stop are set, islice will emit the stretch between stop and start. If step is set, then islice will emit every step-th item between start and stop. If stop is set to nil, then islice will continue through the source generator until it terminates. Eg: (islice (list->generator '(a b c d e f g)) 2) -> A B (islice (list->generator '(a b c d e f g)) 2 4) -> C D (islice (list->generator '(a b c d e f g)) 2 nil) -> C D E F G (islice (list->generator '(a b c d e f g)) 0 nil 2) -> A C E G\" (let ((start (if has-stop-p stop-or-start nil)) (stop (or stop (unless has-stop-p stop-or-start))) (step (or step 1))) (when start (consume start generator)) (if stop (dotimes (i (floor (/ (- stop (or start 0)) step))) (let ((data (take step generator :fail-if-short nil))) (unless data (return)) (yield (car data)))) (loop do (let ((data (take step generator :fail-if-short nil))) (unless data (return)) (yield (car data)))))))\n\nPattern to recognize: Macro call that should be transformed by defgenerator", "input": "(defgenerator islice (generator stop-or-start &optional (stop nil has-stop-p) step) \"Emits a subrange of generator. If only stop-or-start is set, islice will emit up to it and stop. If both stop-or-start and stop are set, islice will emit the stretch between stop and start. If step is set, then islice will emit every step-th item between start and stop. If stop is set to nil, then islice will continue through the source generator until it terminates. Eg: (islice (list->generator '(a b c d e f g)) 2) -> A B (islice (list->generator '(a b c d e f g)) 2 4) -> C D (islice (list->generator '(a b c d e f g)) 2 nil) -> C D E F G (islice (list->generator '(a b c d e f g)) 0 nil 2) -> A C E G\" (let ((start (if has-stop-p stop-or-start nil)) (stop (or stop (unless has-stop-p stop-or-start))) (step (or step 1))) (when start (consume start generator)) (if stop (dotimes (i (floor (/ (- stop (or start 0)) step))) (let ((data (take step generator :fail-if-short nil))) (unless data (return)) (yield (car data)))) (loop do (let ((data (take step generator :fail-if-short nil))) (unless data (return)) (yield (car data)))))))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun islice (generator stop-or-start &optional (stop nil has-stop-p) step) \"Emits a subrange of generator. If only stop-or-start is set, islice will emit up to it and stop. If both stop-or-start and stop are set, islice will emit the stretch between stop and start. If step is set, then islice will emit every step-th item between start and stop. If stop is set to nil, then islice will continue through the source generator until it terminates. Eg: (islice (list->generator '(a b c d e f g)) 2) -> A B (islice (list->generator '(a b c d e f g)) 2 4) -> C D (islice (list->generator '(a b c d e f g)) 2 nil) -> C D E F G (islice (list->generator '(a b c d e f g)) 0 nil 2) -> A C E G\" (with-yield (let ((start (if has-stop-p stop-or-start nil)) (stop (or stop (unless has-stop-p stop-or-start))) (step (or step 1))) (when start (consume start generator)) (if stop (dotimes (i (floor (/ (- stop (or start 0)) step))) (let ((data (take step generator :fail-if-short nil))) (unless data (return)) (yield (car data)))) (loop do (let ((data (take step generator :fail-if-short nil))) (unless data (return)) (yield (car data))))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error invalid-function-return-spec () (func spec) \"Return type spec of function ~a is invalid:~%~a\" func spec)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error invalid-function-return-spec () (func spec) \"Return type spec of function ~a is invalid:~%~a\" func spec)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition invalid-function-return-spec (:error-type varjo-error :prefix \"Varjo\") (func spec) \"Return type spec of function ~a is invalid:~%~a\" func spec)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (= 0 (add-2 -2)))\n\nIssue: Macro call that should be transformed by is", "input": "(is (= 0 (add-2 -2)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e140 0) (#:a141 (add-2 -2))) (if (progn (= #:e140 #:a141)) (add-result (quote test-passed) :test-expr (quote (= 0 (add-2 -2)))) (process-failure (quote (= 0 (add-2 -2))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (add-2 -2)) #:a141 (quote =) #:e140)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (not (plusp -1)))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (not (plusp -1)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:v184 -1)) (if (not (plusp #:v184)) (add-result (quote test-passed) :test-expr (quote (not (plusp -1)))) (process-failure (quote (not (plusp -1))) \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\" (quote -1) #:v184 (quote plusp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is-true nil)\n\nWhat needs to change: Macro call that should be transformed by is-true", "input": "(is-true nil)", "output": "(defmacro is-true (condition &rest reason-args)\n \"Like IS this check generates a pass if CONDITION returns true\n and a failure if CONDITION returns false. Unlike IS this check\n does not inspect CONDITION to determine how to report the\n failure.\"\n `(if ,condition\n (add-result 'test-passed :test-expr ',condition)\n (process-failure ',condition\n ,@(or reason-args\n `(\"~S did not return a true value\" ',condition)))))", "macroexpand": "(if nil (add-result (quote test-passed) :test-expr (quote nil)) (process-failure (quote nil) \"~S did not return a true value\" (quote nil)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda (quote some-name))\n\nPattern to recognize: Macro call that should be transformed by LAMBDA", "input": "(lambda (quote some-name))", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda (quote some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(augment step-code prev-code)\n\nPattern to recognize: Macro call that should be transformed by augment", "input": "(augment step-code prev-code)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf step-code (nconc step-code prev-code))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(some-<>> (diamond-wand init (cddr exp) t t))\n\nWhat needs to change: Macro call that should be transformed by some-<>", "input": "(some-<>> (diamond-wand init (cddr exp) t t))", "output": "(defmacro some-<> (init &body exps) (diamond-wand init exps nil t))", "macroexpand": "(block #:g127 (diamond-wand init (cddr exp) t t))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(bind (((:labels doit (x)) \"if I knew how to get the docstring out of flet, I'd test it.\" (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))\n\nProblem: Macro call that should be transformed by bind", "input": "(bind (((:labels doit (x)) \"if I knew how to get the docstring out of flet, I'd test it.\" (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(labels ((doit (x) \"if I knew how to get the docstring out of flet, I'd test it.\" (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(case nil)\n\nPattern to recognize: Macro call that should be transformed by CASE", "input": "(case nil)", "output": "(defmacro CASE ...)", "macroexpand": "(let ((#:nil nil))\n (declare (ignorable #:nil))\n (cond))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-ps-gensyms nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by WITH-PS-GENSYMS", "input": "(with-ps-gensyms nil\n :key\n nil)", "output": "(defmacro WITH-PS-GENSYMS ...)", "macroexpand": "(let* ()\n :key\n nil)", "category": "control-flow", "technique": "gensym", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-expander slot-value 1 (expr val new-val) `(let ((new (copy-instance ,val))) (setf (slot-value new ,(third expr)) ,new-val) new))\n\nWhat needs to change: Macro call that should be transformed by define-modf-expander", "input": "(define-modf-expander slot-value 1 (expr val new-val) `(let ((new (copy-instance ,val))) (setf (slot-value new ,(third expr)) ,new-val) new))", "output": "(defmacro define-modf-expander (name nth-arg\n (expr val new-val)\n &body body)\n \"Define a new expander which inverts forms starting with NAME. Your function\nshould return an expansion from EXPR to a form that will build a new object that\nhas NEW-VAL in the place specified by expr. NTH-ARG marks which argument is\nconsidered the actual data which will be inverted next.\"\n (setf\n (gethash name *modf-nth-arg*)\n nth-arg)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf\n (gethash ',name *modf-nth-arg*)\n ,nth-arg\n (gethash ',name *modf-expansions*)\n (lambda (,expr ,val ,new-val)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote slot-value) *modf-nth-arg*) 1 (gethash (quote slot-value) *modf-expansions*) (lambda (expr val new-val) (sb-int:quasiquote (let ((new (copy-instance #S(sb-impl::comma :expr val :kind 0)))) (setf (slot-value new #S(sb-impl::comma :expr (third expr) :kind 0)) #S(sb-impl::comma :expr new-val :kind 0)) new)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-macro nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-MACRO", "input": "(define-macro nil\n :key\n nil)", "output": "(defmacro DEFINE-MACRO ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (get 'nil ':key)\n (lambda (#:whole122 #:no-environment)\n (declare (ignorable #:no-environment))\n (handler-case\n (destructuring-bind\n (#:namevar123)\n #:whole122\n (declare (ignore #:namevar123)))\n (error (e) (error 'foo-syntax-error :form #:whole122 :cause e))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(letrec* ((f (constantly t)) (a (funcall f))) (is-true a))\n\nPattern to recognize: Macro call that should be transformed by letrec", "input": "(letrec* ((f (constantly t)) (a (funcall f))) (is-true a))", "output": "(defmacro letrec ((&rest bindings) &body body)\n \"Recursive LET.\nThe idea is that functions created in BINDINGS can close over one\nanother, and themselves.\n\nNote that `letrec' only binds variables: it can define recursive\nfunctions, but can't bind them as functions. (But see `fbindrec'.)\"\n `(letrec-with psetq ,bindings\n ,@body))", "macroexpand": "(letrec-with setq ((f (constantly t)) (a (funcall f))) (is-true a))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-env [assoc-list 'a])\n\nProblem: Macro call that should be transformed by with-env", "input": "(with-env [assoc-list 'a])", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g127) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g127 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [assoc-list (quote a]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g127)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-unbuilder 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-UNBUILDER", "input": "(with-unbuilder 'some-name)", "output": "(defmacro WITH-UNBUILDER ...)", "macroexpand": "(flet ((with-builder-thunk (quote)\n ))\n (declare (dynamic-extent (function with-builder-thunk)))\n (call-with-unbuilder some-name #'with-builder-thunk))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (and (first first-statement) (eql (first parent-node) 'compound-statement) (eql (- level (first curr-level)) 2)) (let ((count (length nodes))) (setf (first first-statement) nil) (setf (first statement-count) (max count (first statement-count)))))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (and (first first-statement) (eql (first parent-node) 'compound-statement) (eql (- level (first curr-level)) 2)) (let ((count (length nodes))) (setf (first first-statement) nil) (setf (first statement-count) (max count (first statement-count)))))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (and (first first-statement) (eql (first parent-node) (quote compound-statement)) (eql (- level (first curr-level)) 2)) (let ((count (length nodes))) (setf (first first-statement) nil) (setf (first statement-count) (max count (first statement-count)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-speedy read-until-crlf*2 (stream) (with-fast-output (buf) (tagbody read-cr (loop for byte of-type (or (unsigned-byte 8) null) = (read-byte stream nil nil) if byte do (fast-write-byte byte buf) else do (go eof) until (= byte (char-code #\\Return))) read-lf (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Newline)) (fast-write-byte next-byte buf) (go read-cr2)) ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf)) (T (fast-write-byte next-byte buf) (go read-cr))))) read-cr2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf2)) (T (fast-write-byte next-byte buf) (go read-cr))))) read-lf2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Newline)) (fast-write-byte next-byte buf)) ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf)) (T (fast-write-byte next-byte buf) (go read-cr))))) eof)))\n\nWhat needs to change: Macro call that should be transformed by defun-speedy", "input": "(defun-speedy read-until-crlf*2 (stream) (with-fast-output (buf) (tagbody read-cr (loop for byte of-type (or (unsigned-byte 8) null) = (read-byte stream nil nil) if byte do (fast-write-byte byte buf) else do (go eof) until (= byte (char-code #\\Return))) read-lf (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Newline)) (fast-write-byte next-byte buf) (go read-cr2)) ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf)) (T (fast-write-byte next-byte buf) (go read-cr))))) read-cr2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf2)) (T (fast-write-byte next-byte buf) (go read-cr))))) read-lf2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Newline)) (fast-write-byte next-byte buf)) ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf)) (T (fast-write-byte next-byte buf) (go read-cr))))) eof)))", "output": "(defmacro defun-speedy (name lambda-list &body body)\n `(progn\n (declaim (notinline ,name))\n (defun ,name ,lambda-list\n ,*speedy-declaration*\n ,@body)))", "macroexpand": "(progn (declaim (notinline read-until-crlf*2)) (defun read-until-crlf*2 (stream) (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))) (with-fast-output (buf) (tagbody read-cr (loop for byte of-type (or (unsigned-byte 8) null) = (read-byte stream nil nil) if byte do (fast-write-byte byte buf) else do (go eof) until (= byte (char-code #\\Return))) read-lf (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Newline)) (fast-write-byte next-byte buf) (go read-cr2)) ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf)) (t (fast-write-byte next-byte buf) (go read-cr))))) read-cr2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf2)) (t (fast-write-byte next-byte buf) (go read-cr))))) read-lf2 (let ((next-byte (read-byte stream nil nil))) (unless next-byte (go eof)) (locally (declare (type (unsigned-byte 8) next-byte)) (cond ((= next-byte (char-code #\\Newline)) (fast-write-byte next-byte buf)) ((= next-byte (char-code #\\Return)) (fast-write-byte next-byte buf) (go read-lf)) (t (fast-write-byte next-byte buf) (go read-cr))))) eof))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(f nil)\n\nProblem: Macro call that should be transformed by F", "input": "(f nil)", "output": "(defmacro F ...)", "macroexpand": "(lambda ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-custom-var (:object-value *object-value-handler*) (constantly t) \"Designator for a function of 1 arbitrary argument (decoded member value of Object).\")\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:object-value *object-value-handler*) (constantly t) \"Designator for a function of 1 arbitrary argument (decoded member value of Object).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*object-value-handler* . :object-value)) *custom-vars* :test (function equal)) (defvar *object-value-handler* (constantly t) \"Designator for a function of 1 arbitrary argument (decoded member value of Object).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclass/a dbd-null-connection (cl-dbi:dbi-connection) ())\n\nWhat needs to change: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbd-null-connection (cl-dbi:dbi-connection) ())", "output": "(defmacro defclass/a (name superclasses slots &rest class-options)\n `(progn\n (defclass ,name ,superclasses ,slots ,@class-options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (defclass dbd-null-connection (dbi.driver:dbi-connection) nil) (deftype nil (quote dbd-null-connection)) (setf (find-class (quote )) (find-class (quote dbd-null-connection))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(producing)\n\nProblem: Macro call that should be transformed by PRODUCING", "input": "(producing)", "output": "(defmacro PRODUCING ...)", "macroexpand": "(non-opt-producing)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(do+ (for x (in '(1 2 3 4))) (for y (previous x)) (for z (previous y)) (collect (list x y z)))\n\nPattern to recognize: Macro call that should be transformed by do+", "input": "(do+ (for x (in '(1 2 3 4))) (for y (previous x)) (for z (previous y)) (collect (list x y z)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (in (quote (1 2 3 4)))) (for y (previous x)) (for z (previous y)) (collect (list x y z)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time indirect-callees (function-name) (indirect-callees-internal (callees function-name) '()))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time indirect-callees (function-name) (indirect-callees-internal (callees function-name) '()))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun indirect-callees (function-name) (indirect-callees-internal (callees function-name) (quote nil))) (eval-when (:compile-toplevel) (compile (quote indirect-callees))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-alias-binding reduce reducing)\n\nIssue: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding reduce reducing)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote reduce)) (quote reducing)) (quote reduce))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(check-cursor-attached cluffer:beginning-of-line (cursor))\n\nWhat needs to change: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:beginning-of-line (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:beginning-of-line :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-quasi-quoted-string-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-STRING-SYNTAX", "input": "(enable-quasi-quoted-string-syntax)", "output": "(defmacro ENABLE-QUASI-QUOTED-STRING-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-string-syntax-in-readtable :start-character nil\n :end-character nil\n :unquote-character #\\COMMA\n :splice-character\n #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP\n :dispatched-quasi-quote-name\n \"str\" :transformation-pipeline\n nil)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-collectors 'some-name)\n\nIssue: Macro call that should be transformed by WITH-COLLECTORS", "input": "(with-collectors 'some-name)", "output": "(defmacro WITH-COLLECTORS ...)", "macroexpand": "(with-collector (quote)\n (with-collectors (some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclause being (form &key (then form)) \"Assigns to the iteration variable a value computed by evaluating FORM on each iteration, including the first. Optionally, the variable can be updated evaluating a differen form (the value of the `then' parameter). Examples: (for x (being (random))), (for y (being 'quiet :then (if (> x 0.5) 'angry 'quiet))).\" (make-simple-iteration :init form :step then))\n\nProblem: Macro call that should be transformed by defclause", "input": "(defclause being (form &key (then form)) \"Assigns to the iteration variable a value computed by evaluating FORM on each iteration, including the first. Optionally, the variable can be updated evaluating a differen form (the value of the `then' parameter). Examples: (for x (being (random))), (for y (being 'quiet :then (if (> x 0.5) 'angry 'quiet))).\" (make-simple-iteration :init form :step then))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro being (form &key (then form)) \"Assigns to the iteration variable a value computed by evaluating FORM on each iteration, including the first. Optionally, the variable can be updated evaluating a differen form (the value of the `then' parameter). Examples: (for x (being (random))), (for y (being 'quiet :then (if (> x 0.5) 'angry 'quiet))).\" (make-simple-iteration :init form :step then)) (pushnew (quote being) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(->> (v) (flow-gen v))\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(->> (v) (flow-gen v))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(dynamically (v) (flow-gen v))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-custom-var (:beginning-of-array *beginning-of-array-handler*) (constantly t) \"Designator for a function of no arguments (called at encountering an opening bracket for an Array).\")\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:beginning-of-array *beginning-of-array-handler*) (constantly t) \"Designator for a function of no arguments (called at encountering an opening bracket for an Array).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*beginning-of-array-handler* . :beginning-of-array)) *custom-vars* :test (function equal)) (defvar *beginning-of-array-handler* (constantly t) \"Designator for a function of no arguments (called at encountering an opening bracket for an Array).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-preprocessor-state-slots (state) (let ((i-state (pop include-stack))) (unless (eql if-section-stack (saved-include-state-if-section-stack i-state)) (error 'preprocess-error :format-control \"#if section does not end in included file ~A\" :format-arguments (list file-pathname))) (setf *package* (saved-include-state-package i-state) *readtable* (saved-include-state-readtable i-state) ) i-state))\n\nWrite a macro that addresses: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (let ((i-state (pop include-stack))) (unless (eql if-section-stack (saved-include-state-if-section-stack i-state)) (error 'preprocess-error :format-control \"#if section does not end in included file ~A\" :format-arguments (list file-pathname))) (setf *package* (saved-include-state-package i-state) *readtable* (saved-include-state-readtable i-state) ) i-state))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (let ((i-state (pop include-stack))) (unless (eql if-section-stack (saved-include-state-if-section-stack i-state)) (error (quote preprocess-error) :format-control \"#if section does not end in included file ~A\" :format-arguments (list file-pathname))) (setf *package* (saved-include-state-package i-state) *readtable* (saved-include-state-readtable i-state)) i-state))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dynenv-macrolet nil\n (progn))\n\nProblem: Macro call that should be transformed by DYNENV-MACROLET", "input": "(dynenv-macrolet nil\n (progn))", "output": "(defmacro DYNENV-MACROLET ...)", "macroexpand": "(macrolet ()\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(*> +any-space+ +skip-all-space+ +pairs+)\n\nProblem: Macro call that should be transformed by *>", "input": "(*> +any-space+ +skip-all-space+ +pairs+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset254) (multiple-value-bind (#:*>-res257 #:*>-next258) (multiple-value-bind (#:*>-res255 #:*>-next256) (funcall +any-space+ #:*>-offset254) (if (ok? #:*>-res255) (funcall +skip-all-space+ #:*>-next256) (fail #:*>-next256))) (if (ok? #:*>-res257) (funcall +pairs+ #:*>-next258) (fail #:*>-next258))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<>> nil (progn))\n\nProblem: Macro call that should be transformed by -<>>", "input": "(-<>> nil (progn))", "output": "(defmacro -<>> ...)", "macroexpand": "(->> nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-direct-binding when (var test sub-binding &rest args) (multiple-value-bind (init body value) (apply (binding sub-binding) var args) (values init `(when ,test ,body) value)))\n\nIssue: Macro call that should be transformed by define-direct-binding", "input": "(define-direct-binding when (var test sub-binding &rest args) (multiple-value-bind (init body value) (apply (binding sub-binding) var args) (values init `(when ,test ,body) value)))", "output": "(defmacro define-direct-binding (name args &body body)\n (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym \"ENVIRONMENT\"))))\n `(progn (setf (binding ',name)\n (lambda ,(lambda-fiddle:remove-environment-part args)\n (let ((,env *environment*))\n (declare (ignorable ,env))\n ,@body)))\n ',name)))", "macroexpand": "(progn (setf (binding (quote when)) (lambda (var test sub-binding &rest args) (let ((#:environment125 *environment*)) (declare (ignorable #:environment125)) (multiple-value-bind (init body value) (apply (binding sub-binding) var args) (values init (sb-int:quasiquote (when #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr body :kind 0))) value))))) (quote when))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-function getf 2 (new-val plist key) (let ((new-plist (copy-list plist))) (setf (getf new-plist key) new-val) new-plist))\n\nWhat needs to change: Macro call that should be transformed by define-modf-function", "input": "(define-modf-function getf 2 (new-val plist key) (let ((new-plist (copy-list plist))) (setf (getf new-plist key) new-val) new-plist))", "output": "(defmacro define-modf-function (name nth-arg (new-val &rest args) &body body)\n \"Define a new modf function. It inverts NAME forms by modifying the NTH-ARG\nterm of the arguments of the place form in the MODF macro.\"\n ;; Side effect in a macro, I know. How can you do this via EVAL-WHEN if I\n ;; want it to run even if not a toplevel macro?\n (setf (gethash name *modf-nth-arg*)\n nth-arg)\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-nth-arg*)\n ,nth-arg))\n (defun ,(intern (modf-name name) :modf) (,new-val ,@args)\n ,@body)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote getf) *modf-nth-arg*) 2)) (defun |BUILDER:COMMON-LISP:GETF| (new-val plist key) (let ((new-plist (copy-list plist))) (setf (getf new-plist key) new-val) new-plist)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-rewrite cdaddr (expr) `(cdr (caddr ,(second expr))))\n\nPattern to recognize: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cdaddr (expr) `(cdr (caddr ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdaddr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (caddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-flow-function-macro (body-fu lambda-list body) `(dispatch-dynamically ,flow-context #',body-fu))\n\nIssue: Macro call that should be transformed by with-flow-function-macro", "input": "(with-flow-function-macro (body-fu lambda-list body) `(dispatch-dynamically ,flow-context #',body-fu))", "output": "(defmacro with-flow-function-macro ((fu-name fu-lambda-list fu-body) &body body)\n `(with-gensyms (,fu-name)\n `(%with-flow-function (,,fu-name ,,fu-lambda-list ,@,fu-body)\n ,,@body)))", "macroexpand": "(with-gensyms (body-fu) (sb-int:quasiquote (%with-flow-function (#S(sb-impl::comma :expr body-fu :kind 0) #S(sb-impl::comma :expr lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)) #S(sb-impl::comma :expr (sb-int:quasiquote (dispatch-dynamically #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr body-fu :kind 0)))) :kind 0))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is = 5 5)\n\nIssue: Macro call that should be transformed by is", "input": "(is = 5 5)", "output": "(defmacro is (comp expected form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(is ,comp ,expected ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected ,expected\n :comparison ,(maybe-quote comp)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is = 5 5)) :value-form (quote 5) :body (lambda nil 5) :expected 5 :comparison (quote =)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Generate a defmacro form that transforms code like this:\n(collecting 'some-name)\n\nPattern to recognize: Macro call that should be transformed by COLLECTING", "input": "(collecting 'some-name)", "output": "(defmacro COLLECTING ...)", "macroexpand": "(with-collector-output (output)\n (dolist (quote (alexandria:ensure-list some-name))\n (restart-case (output (progn))\n (skip nil \"Skip this element\"))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-capped-stack () (make-instance 'environment :condition condition))\n\nPattern to recognize: Macro call that should be transformed by with-capped-stack", "input": "(with-capped-stack () (make-instance 'environment :condition condition))", "output": "(defmacro with-capped-stack (() &body body)\n `(stack-capper (lambda () ,@body)))", "macroexpand": "(stack-capper (lambda nil (make-instance (quote environment) :condition condition)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :g () 1)\n\nProblem: Macro call that should be transformed by ->", "input": "(-> :g () 1)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g nil 1)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:body (:h* \"This is a top level heading\") (:p \"...\") (:section (:p \"...\") (:h* \"This is a second-level heading\") (:p \"...\") (:h* \"This is another second-level heading\") (:p \"...\") (:section (:h* \"This is a third-level heading\") (:p \"...\")))))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:body (:h* \"This is a top level heading\") (:p \"...\") (:section (:p \"...\") (:h* \"This is a second-level heading\") (:p \"...\") (:h* \"This is another second-level heading\") (:p \"...\") (:section (:h* \"This is a third-level heading\") (:p \"...\")))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:body (:h* \"This is a top level heading\") (:p \"...\") (:section (:p \"...\") (:h* \"This is a second-level heading\") (:p \"...\") (:h* \"This is another second-level heading\") (:p \"...\") (:section (:h* \"This is a third-level heading\") (:p \"...\"))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(deferror \"57P03\" cannot-connect-now operator-intervention)\n\nWhat needs to change: Macro call that should be transformed by deferror", "input": "(deferror \"57P03\" cannot-connect-now operator-intervention)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition cannot-connect-now (operator-intervention) nil) (setf (gethash \"57P03\" *error-table*) (quote cannot-connect-now)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is-type 1 'string)\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is-type 1 'string)", "output": "(defmacro is (got expected &rest args)\n (with-gensyms (duration result new-args desc)\n (once-only (expected)\n `(let* ((,new-args (list ,@args))\n (,desc (parse-description-and-test ,new-args)))\n (with-catching-errors (:description ,desc :expected ,expected)\n (with-duration ((,duration ,result) ,got)\n (test ,result ,expected ,new-args\n :duration ,duration)))))))", "macroexpand": "(let ((#:desc179 nil) (#:expected-type180 (quote string))) (with-catching-errors (:description #:desc179 :expected #:expected-type180) (with-duration ((#:duration177 #:result178) 1) (test #:result178 #:expected-type180 #:desc179 :duration #:duration177 :got-form (quote 1) :test-fn (function typep) :report-expected-label \"be a type of\"))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-element-maker :group \"g\" '())\n\nWrite a macro that addresses: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :group \"g\" '())", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :group)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote nil) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :group missing))))) (defmethod make-svg-element ((element (eql :group)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"g\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(multiple-value-prog2 (values 1 1 1) (values 2 20 200) (values 3 3 3))\n\nWrite a macro that addresses: Macro call that should be transformed by multiple-value-prog2", "input": "(multiple-value-prog2 (values 1 1 1) (values 2 20 200) (values 3 3 3))", "output": "(defmacro multiple-value-prog2 (first-form second-form &body forms)\n \"Evaluates FIRST-FORM, then SECOND-FORM, and then FORMS. Yields as its value\nall the value returned by SECOND-FORM.\"\n `(progn ,first-form (multiple-value-prog1 ,second-form ,@forms)))", "macroexpand": "(progn (values 1 1 1) (multiple-value-prog1 (values 2 20 200) (values 3 3 3)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(assoc-cdr :token--endpoint disc)\n\nWhat needs to change: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr :token--endpoint disc)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc :token--endpoint disc :test (function eql)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-rewrite first (expr) `(car ,(second expr)))\n\nIssue: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite first (expr) `(car ,(second expr)))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote first) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car #S(sb-impl::comma :expr (second expr) :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(\u03c8 'some-name)\n\nWhat needs to change: Macro call that should be transformed by \u03a8", "input": "(\u03c8 'some-name)", "output": "(defmacro \u03a8 ...)", "macroexpand": "(mapcar (\u03bb) 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-modf-method pathname-directory 1 (new-val path) (make-pathname :directory new-val :defaults path))\n\nWrite a macro that addresses: Macro call that should be transformed by define-modf-method", "input": "(define-modf-method pathname-directory 1 (new-val path) (make-pathname :directory new-val :defaults path))", "output": "(defmacro define-modf-method (name nth-arg (new-val &rest args) &body body)\n \"Define a new modf method. It inverts NAME forms by modifying the NTH-ARG\nterm of the arguments of the place form in the MODF macro. This method can\nspecialize on any of ARGS.\"\n ;; Side effect in a macro, I know. How can you do this via EVAL-WHEN if I\n ;; want it to run even if not a toplevel macro?\n (setf (gethash name *modf-nth-arg*)\n nth-arg)\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-nth-arg*)\n ,nth-arg))\n (defmethod ,(intern (modf-name name) :modf) (,new-val ,@args)\n ,@body)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote pathname-directory) *modf-nth-arg*) 1)) (defmethod |BUILDER:COMMON-LISP:PATHNAME-DIRECTORY| (new-val path) (make-pathname :directory new-val :defaults path)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-iter iterator-range (curr stop step) (range (s0 &optional s1 (step 1)) \"Works [as in Python](https://docs.python.org/3/library/stdtypes.html#typesseq-range) but produces an iterator (as defined by PICL) instead of a Python-esque range object ``` (range 5) ;; 0, 1, 2, 3, 4 (range 2 5) ;; 2, 3, 4 (range -2) ;; 0, -1 (range 1 7 2) ;; 1, 3, 5 ```\" (init-state (curr (if s1 s0 0)) (stop (if s1 s1 s0)) step)) (if (or (and (> step 0) (< curr stop)) (and (< step 0) (> curr stop))) (values (prog1 curr (incf curr step)) t) (values nil nil)))\n\nWhat needs to change: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-range (curr stop step) (range (s0 &optional s1 (step 1)) \"Works [as in Python](https://docs.python.org/3/library/stdtypes.html#typesseq-range) but produces an iterator (as defined by PICL) instead of a Python-esque range object ``` (range 5) ;; 0, 1, 2, 3, 4 (range 2 5) ;; 2, 3, 4 (range -2) ;; 0, -1 (range 1 7 2) ;; 1, 3, 5 ```\" (init-state (curr (if s1 s0 0)) (stop (if s1 s1 s0)) step)) (if (or (and (> step 0) (< curr stop)) (and (< step 0) (> curr stop))) (values (prog1 curr (incf curr step)) t) (values nil nil)))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname131 (&key curr stop step) (labels ((self nil (if (or (and (> step 0) (< curr stop)) (and (< step 0) (> curr stop))) (values (prog1 curr (incf curr step)) t) (values nil nil)))) (function self)))) (defun range (s0 &optional s1 (step 1)) \"Works [as in Python](https://docs.python.org/3/library/stdtypes.html#typesseq-range) but produces an iterator (as defined by PICL) instead of a Python-esque range object ``` (range 5) ;; 0, 1, 2, 3, 4 (range 2 5) ;; 2, 3, 4 (range -2) ;; 0, -1 (range 1 7 2) ;; 1, 3, 5 ```\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname131)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (init-state (curr (if s1 s0 0)) (stop (if s1 s1 s0)) step))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defpackage nil)\n\nWhat needs to change: Macro call that should be transformed by DEFPACKAGE", "input": "(defpackage nil)", "output": "(defmacro DEFPACKAGE ...)", "macroexpand": "(common-lisp:defpackage nil\n (:use :adhoc :closer-mop :cl)\n (:shadowing-import-from :closer-mop\n #:defmethod\n #:standard-generic-function\n #:defgeneric\n #:standard-method\n #:standard-class)\n (:shadowing-import-from :adhoc #:defpackage #:variable #:the))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause (collect expr &optional into var at (place 'end) result-type (type 'list)) \"Collect into a list\" (return-collection-code :variable var :expression expr :one-element t :start-operation 'cons :end-operation '(subst (var expr) (list expr)) :place place :result-type type))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause (collect expr &optional into var at (place 'end) result-type (type 'list)) \"Collect into a list\" (return-collection-code :variable var :expression expr :one-element t :start-operation 'cons :end-operation '(subst (var expr) (list expr)) :place place :result-type type))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-collect-18 (&key ((:collect expr)) ((:into var)) ((:at place) (quote end)) ((:result-type type) (quote list))) \"Collect into a list\" (return-collection-code :variable var :expression expr :one-element t :start-operation (quote cons) :end-operation (quote (subst (var expr) (list expr))) :place place :result-type type)) (install-clause-info (quote (collect)) (quote (collect &optional :into :at :result-type)) (quote clause-collect-18) \"Collect into a list\" nil) (quote (collect expr &optional into var at (place (quote end)) result-type (type (quote list)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (second item) `(declaration-value (make-node ,(second item))))\n\nProblem: Macro call that should be transformed by when", "input": "(when (second item) `(declaration-value (make-node ,(second item))))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (second item) (sb-int:quasiquote (declaration-value (make-node #S(sb-impl::comma :expr (second item) :kind 0)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ct-let nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by CT-LET", "input": "(ct-let nil\n :key\n nil)", "output": "(defmacro CT-LET ...)", "macroexpand": "(cond\n (*within-captured-dynenv*\n (let ()\n (let ((#:new-var-space161\n (reduce\n (lambda (#:accum162 #:item163)\n (destructuring-bind\n (#:name164 . #:value165)\n #:item163\n (update-alist #:name164 #:value165 #:accum162)))\n (list) :initial-value *var-space*)))\n `(symbol-macrolet ((var-space ,#:new-var-space161))\n ,(let ((*var-space* #:new-var-space161))\n :key\n nil)))))\n (t\n (error\n \"No macrodynamic environment has been captured to establish CT-LET bindings.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(destructuring-case nil)\n\nWhat needs to change: Macro call that should be transformed by DESTRUCTURING-CASE", "input": "(destructuring-case nil)", "output": "(defmacro DESTRUCTURING-CASE ...)", "macroexpand": "(destructuring-case-alt nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defmacro nil ())\n\nWhat needs to change: Macro call that should be transformed by DEFMACRO", "input": "(defmacro nil ())", "output": "(defmacro DEFMACRO ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel)\n (sb-c::%compiler-defmacro :macro-function 'nil))\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c::%defmacro 'nil\n (sb-int:named-lambda (macro-function nil)\n (#:expr #:env)\n (declare (sb-c::lambda-list nil))\n (declare (ignore #:env))\n (sb-int:named-ds-bind (:macro nil . defmacro)\n nil\n (cdr #:expr)\n (declare (sb-c::constant-value))))\n (sb-c:source-location))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(pop-preprocessor-directive-token token-list directive-symbol :errorp nil)\n\nIssue: Macro call that should be transformed by pop-preprocessor-directive-token", "input": "(pop-preprocessor-directive-token token-list directive-symbol :errorp nil)", "output": "(defmacro pop-preprocessor-directive-token (token-list directive-name &key (errorp t))\n \"Pops the next token in TOKEN-LIST ignoring `+whitespace-marker+'\"\n (with-gensyms (head_)\n `(let ((,head_\n (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)))\n (if (eq +whitespace-marker+ ,head_)\n (check-and-pop-pp-directive-token-1 ,token-list ,directive-name ,errorp)\n ,head_))))", "macroexpand": "(let ((#:head_263 (check-and-pop-pp-directive-token-1 token-list directive-symbol nil))) (if (eq +whitespace-marker+ #:head_263) (check-and-pop-pp-directive-token-1 token-list directive-symbol nil) #:head_263))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (<= (length s) 2))\n\nIssue: Macro call that should be transformed by is", "input": "(is (<= (length s) 2))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e256 (length s)) (#:a257 2)) (if (progn (<= #:e256 #:a257)) (add-result (quote test-passed) :test-expr (quote (<= (length s) 2))) (process-failure (quote (<= (length s) 2)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote 2) #:a257 (quote <=) #:e256)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(continue-whopper nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by CONTINUE-WHOPPER", "input": "(continue-whopper nil nil)", "output": "(defmacro CONTINUE-WHOPPER ...)", "macroexpand": "(call-next-method-fn self class-env inst-env mcs%caller mcs%next-methods\n (list nil nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-local-readtable\n nil\n nil)\n\nProblem: Macro call that should be transformed by WITH-LOCAL-READTABLE", "input": "(with-local-readtable\n nil\n nil)", "output": "(defmacro WITH-LOCAL-READTABLE ...)", "macroexpand": "(bind ((*readtable* (copy-readtable *readtable*)))\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-color (:cyan :stream stream) (format/indent reporter stream \"\u25cf ~D test~:*~P skipped\" skipped-count))\n\nWhat needs to change: Macro call that should be transformed by with-color", "input": "(with-color (:cyan :stream stream) (format/indent reporter stream \"\u25cf ~D test~:*~P skipped\" skipped-count))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq :cyan :gray) (eq :cyan :grey) (eq :cyan +gray+) (eq :cyan +grey+)) (with-gray stream (format/indent reporter stream \"\u25cf ~D test~:*~P skipped\" skipped-count)) (cl-ansi-text:with-color (:cyan :stream stream) (format/indent reporter stream \"\u25cf ~D test~:*~P skipped\" skipped-count))) (progn (format/indent reporter stream \"\u25cf ~D test~:*~P skipped\" skipped-count)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-rewrite sixth (expr) `(cadr (cddddr ,(second expr))))\n\nIssue: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite sixth (expr) `(cadr (cddddr ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote sixth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cadr (cddddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclass/a dbd-sqlite3-query (dbi-query) ((store :initarg :store :initform t :accessor sqlite3-use-store)))\n\nProblem: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbd-sqlite3-query (dbi-query) ((store :initarg :store :initform t :accessor sqlite3-use-store)))", "output": "(defmacro defclass/a (name superclasses slots &rest class-options)\n `(progn\n (defclass ,name ,superclasses ,slots ,@class-options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (defclass dbd-sqlite3-query (dbi-query) ((store :initarg :store :initform t :accessor sqlite3-use-store))) (deftype nil (quote dbd-sqlite3-query)) (setf (find-class (quote )) (find-class (quote dbd-sqlite3-query))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(bind (((:struct metabang-bind-test-1- (my-a a) c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list c my-a))\n\nPattern to recognize: Macro call that should be transformed by bind", "input": "(bind (((:struct metabang-bind-test-1- (my-a a) c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (list c my-a))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-190| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (my-a (metabang-bind-test-1-a #:|values-190|)) (c (metabang-bind-test-1-c #:|values-190|))) (declare (ignorable #:|values-190|)) (progn (list c my-a)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(js nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by JS", "input": "(js nil (progn))", "output": "(defmacro JS ...)", "macroexpand": "(ps\n nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-yield-binds (format nil \"~A ~{~A~^ ~}\" (sql-statement-name (car (composed-statement-statements statement))) (loop for (type original-scoped-clauses) on grouped-clauses by #'cddr collect (let ((scoped-clauses original-scoped-clauses)) (when (and (eq type 'fields-clause) (some (lambda (clause) (and (null (select-statement-table-name (scoped-clause-statement clause))) (some (lambda (field) (string= \"*\" (typecase field (as-op (sql-symbol-name (as-op-right field))) (sql-symbol (sql-symbol-name field))))) (sql-splicing-list-elements (fields-clause-statement (scoped-clause-clause clause)))))) scoped-clauses)) (setf scoped-clauses (list (make-scoped-clause (make-clause :fields :*) (make-statement :select))))) (setf scoped-clauses (delete-duplicates scoped-clauses :key #'scoped-clause-clause :test #'equalp :from-end t)) (reduce (if has-join-clause-p (lambda (a b) (scoped-merging-yield a b :with-table-names t)) #'scoped-merging-yield) scoped-clauses :initial-value nil)))))\n\nPattern to recognize: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~A ~{~A~^ ~}\" (sql-statement-name (car (composed-statement-statements statement))) (loop for (type original-scoped-clauses) on grouped-clauses by #'cddr collect (let ((scoped-clauses original-scoped-clauses)) (when (and (eq type 'fields-clause) (some (lambda (clause) (and (null (select-statement-table-name (scoped-clause-statement clause))) (some (lambda (field) (string= \"*\" (typecase field (as-op (sql-symbol-name (as-op-right field))) (sql-symbol (sql-symbol-name field))))) (sql-splicing-list-elements (fields-clause-statement (scoped-clause-clause clause)))))) scoped-clauses)) (setf scoped-clauses (list (make-scoped-clause (make-clause :fields :*) (make-statement :select))))) (setf scoped-clauses (delete-duplicates scoped-clauses :key #'scoped-clause-clause :test #'equalp :from-end t)) (reduce (if has-join-clause-p (lambda (a b) (scoped-merging-yield a b :with-table-names t)) #'scoped-merging-yield) scoped-clauses :initial-value nil)))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~A ~{~A~^ ~}\" (sql-statement-name (car (composed-statement-statements statement))) (loop for (type original-scoped-clauses) on grouped-clauses by (function cddr) collect (let ((scoped-clauses original-scoped-clauses)) (when (and (eq type (quote fields-clause)) (some (lambda (clause) (and (null (select-statement-table-name (scoped-clause-statement clause))) (some (lambda (field) (string= \"*\" (typecase field (as-op (sql-symbol-name (as-op-right field))) (sql-symbol (sql-symbol-name field))))) (sql-splicing-list-elements (fields-clause-statement (scoped-clause-clause clause)))))) scoped-clauses)) (setf scoped-clauses (list (make-scoped-clause (make-clause :fields :*) (make-statement :select))))) (setf scoped-clauses (delete-duplicates scoped-clauses :key (function scoped-clause-clause) :test (function equalp) :from-end t)) (reduce (if has-join-clause-p (lambda (a b) (scoped-merging-yield a b :with-table-names t)) (function scoped-merging-yield)) scoped-clauses :initial-value nil))))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(c-assert (member self (kids (fm-parent self))))\n\nPattern to recognize: Macro call that should be transformed by c-assert", "input": "(c-assert (member self (kids (fm-parent self))))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (member self (kids (fm-parent self))) (c-break \"failed assertion: ~a\" (quote (member self (kids (fm-parent self)))))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-html-string (:div (:textarea \"123\")))\n\nWhat needs to change: Macro call that should be transformed by with-html", "input": "(with-html-string (:div (:textarea \"123\")))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:div (:textarea \"123\"))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield (do-generator (x (list->generator data)) (yield x)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield", "input": "(with-yield (do-generator (x (list->generator data)) (yield x)))", "output": "(defmacro with-yield (&body body)\n (let ((point (gensym))\n (current (gensym)))\n `(let (,point ,current)\n (with-call/cc\n\t (labels ((yield (&rest values)\n\t\t (setf ,current values)\n\t\t (let/cc k\n\t\t (setf ,point k))))\n\t ,@body\n\t (setf ,point nil)))\n (gen-lambda ()\n\t (cond ((null ,point)\n\t\t'generator-stop)\n\t (t\n\t\t(let ((current ,current))\n\t\t (funcall ,point nil)\n\t\t ;values-handler: see gen-lambda\n\t\t (apply #'values (funcall values-handler current)))))))))", "macroexpand": "(let (#:g141 #:g142) (with-call/cc (labels ((yield (&rest values) (setf #:g142 values) (let/cc k (setf #:g141 k)))) (do-generator (x (list->generator data)) (yield x)) (setf #:g141 nil))) (gen-lambda nil (cond ((null #:g141) (quote generator-stop)) (t (let ((current #:g142)) (funcall #:g141 nil) (apply (function values) (funcall values-handler current)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :json-test)) result) (setf result (json-rpc:invoke-rpc \"{\\\"method\\\":\\\"secretmethod\\\",\\\"params\\\":[1,2],\\\"id\\\":\\\"my id\\\"}\")) (json-bind (result error id) result (is-false result) (is-true error) (is (string= id \"my id\")))))\n\nProblem: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :json-test)) result) (setf result (json-rpc:invoke-rpc \"{\\\"method\\\":\\\"secretmethod\\\",\\\"params\\\":[1,2],\\\"id\\\":\\\"my id\\\"}\")) (json-bind (result error id) result (is-false result) (is-true error) (is (string= id \"my id\")))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (let ((*json-symbols-package* (find-package :json-test)) result) (setf result (json-rpc:invoke-rpc \"{\\\"method\\\":\\\"secretmethod\\\",\\\"params\\\":[1,2],\\\"id\\\":\\\"my id\\\"}\")) (json-bind (result error id) result (is-false result) (is-true error) (is (string= id \"my id\")))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-iterators ((it1 seq1 :start start1 :end end1 :from-end from-end) (it2 seq2 :start start2 :end end2 :from-end from-end)) (loop do (with-iter-place (e1 it1 more1?) (with-iter-place (e2 it2 more2?) (when (not (and more1? more2?)) (return-from mismatch (when (or more1? more2?) (compute-pos pos)))) (unless (funcall test (funcall key e1) (funcall key e2)) (return-from mismatch (compute-pos pos))) (cl:incf pos)))))\n\nPattern to recognize: Macro call that should be transformed by with-iterators", "input": "(with-iterators ((it1 seq1 :start start1 :end end1 :from-end from-end) (it2 seq2 :start start2 :end end2 :from-end from-end)) (loop do (with-iter-place (e1 it1 more1?) (with-iter-place (e2 it2 more2?) (when (not (and more1? more2?)) (return-from mismatch (when (or more1? more2?) (compute-pos pos)))) (unless (funcall test (funcall key e1) (funcall key e2)) (return-from mismatch (compute-pos pos))) (cl:incf pos)))))", "output": "(defmacro with-iterators (seqs &body forms &environment env)\n \"Create static iterators for one or more sequence.\n\n This macro attempts to determine the type of each sequence, and calls\n MAKE-DOSEQ to generate optimal static iterator code for the given\n sequence types, rather than creating dynamic iterator objects.\n\n SEQS:\n\n A list where each element is of the form (ITER SEQUENCE . ARGS)\n where ITER is a symbol identifying the iterator for the sequence,\n SEQUENCE is the form which evaluates to a sequence, and ARGS are\n the remaining iteration arguments, interpreted as they are to the\n ITERATOR function.\n\n Each iterator identifier (ITER) can be passed to\n WITH-ITER-VALUE, within the body forms of WITH-ITERATORS, to\n retrieve the values of the elements of the sequence.\n\n The iterator identifiers are in a namespace of their own that is\n they do not name lexical variables/symbol-macros nor functions/macros.\n\n\n FORMS:\n\n A list of forms evaluated in an implicit TAGBODY, thus symbols\n are interpreted as tag names.\n\n The WITH-ITER-VALUE macro can be used, within FORMS, to retrieve\n the current element of the sequence and advance the iterator to\n the next position.\n\n The WITH-ITER-PLACE macro can be used, within FORMS, both to\n retrieve and set the value of the current element of the\n sequence, and advance the iterator to the next position.\n\n NOTE: The value of the last form is not returned, due to it being\n evaluated in a TAGBODY, instead NIL is returned. RETURN-FROM, to\n an outer BLOCK, should be used to return a value from this form.\n\n NOTE: Whilst the intended use of WITH-ITERATORS is to implement\n iteration macros, such as DOSEQ, the FORMS are only evaluated\n once. It is up to the user to implement the actual loop, using\n the provided TAGBODY facility.\"\n\n (with-gensyms (end-tag)\n (labels ((expand-doseq (seq args body env)\n (-> (nth-form-type seq env)\n (make-doseq seq args end-tag body env)\n multiple-value-list))\n\n (make-form (bindings get-values places body)\n (->> (make-macros get-values places body)\n (make-bindings bindings)))\n\n (make-macros (get-values places body)\n `(symbol-macrolet\n ((iter-value-macros\n ,(append get-values (iter-value-macros env)))\n\n (iter-place-macros\n ,(append places (iter-place-macros env))))\n\n ,@body))\n\n ;; Tagbody\n\n (make-tagbody (body)\n `((tagbody\n ,@body\n ,end-tag)))\n\n\n ;; Bindings\n\n (make-bindings (bindings body)\n (loop\n for binding in bindings\n for (init constant?) = (multiple-value-list (make-binding binding))\n if constant? collect init into constants\n else collect init into vars\n finally\n (return\n `(symbol-macrolet ,constants\n (let* ,vars ,body)))))\n\n (make-binding (binding)\n (destructuring-bind (var init &key constant) binding\n (if constant\n (multiple-value-bind (value constant?)\n (constant-form-value init env)\n\n (values\n `(,var ,value)\n constant?))\n\n (values\n `(,var ,init)\n nil)))))\n\n (loop\n for (var seq . args) in seqs\n for (bindings body value place) =\n (expand-doseq seq args (make-tagbody forms) env) then\n (expand-doseq seq args form-body env)\n\n for iter-value = (gensym \"ITER-VALUE\")\n for iter-place = (gensym \"ITER-PLACE\")\n for form-body = `((macrolet ((,iter-value ,@value)\n (,iter-place\n ,@(or place\n `((&rest args)\n (declare (ignore args))\n (error \"In WITH-ITER-PLACE: Iterator ~s points to immutable sequence.\" ',var)))))\n ,@body))\n\n append bindings into all-bindings\n collect (cons var iter-value) into get-values\n collect (cons var iter-place) into places\n\n finally\n (return\n (make-form all-bindings get-values places form-body))))))", "macroexpand": "(symbol-macrolet nil (let* ((#:it165 (iterator seq1 :start start1 :end end1 :from-end from-end)) (#:it168 (iterator seq2 :start start2 :end end2 :from-end from-end))) (symbol-macrolet ((iter-value-macros ((it1 . #:iter-value166) (it2 . #:iter-value169))) (iter-place-macros ((it1 . #:iter-place167) (it2 . #:iter-place170)))) (macrolet ((#:iter-value169 (pattern &body body) (symbol-macrolet ((it (quote #:it168)) (tag (quote #:end-tag164))) (with-destructure-pattern (var pattern) (body decl body) (sb-int:quasiquote (progn (when (endp #S(sb-impl::comma :expr it :kind 0)) (go #S(sb-impl::comma :expr tag :kind 0))) (let ((#S(sb-impl::comma :expr var :kind 0) (at #S(sb-impl::comma :expr it :kind 0)))) #S(sb-impl::comma :expr decl :kind 2) (advance #S(sb-impl::comma :expr it :kind 0)) #S(sb-impl::comma :expr body :kind 2))))))) (#:iter-place170 (name more? &body body) (symbol-macrolet ((it (quote #:it168)) (tag (quote #:end-tag164))) (let ((body (sb-int:quasiquote (prog1 (progn #S(sb-impl::comma :expr body :kind 2)) (advance #S(sb-impl::comma :expr it :kind 0)))))) (with-variable-declarations ((decl-name name) (decl-more? more?)) forms body (sb-int:quasiquote (symbol-macrolet ((#S(sb-impl::comma :expr name :kind 0) (at #S(sb-impl::comma :expr it :kind 0)))) #S(sb-impl::comma :expr decl-name :kind 2) #S(sb-impl::comma :expr (if more? (sb-int:quasiquote (let ((#S(sb-impl::comma :expr more? :kind 0) (not (endp #S(sb-impl::comma :expr it :kind 0))))) #S(sb-impl::comma :expr decl-more? :kind 2) #S(sb-impl::comma :expr forms :kind 0))) (sb-int:quasiquote (progn (when (endp #S(sb-impl::comma :expr it :kind 0)) (go #S(sb-impl::comma :expr tag :kind 0))) #S(sb-impl::comma :expr forms :kind 0)))) :kind 0)))))))) (macrolet ((#:iter-value166 (pattern &body body) (symbol-macrolet ((it (quote #:it165)) (tag (quote #:end-tag164))) (with-destructure-pattern (var pattern) (body decl body) (sb-int:quasiquote (progn (when (endp #S(sb-impl::comma :expr it :kind 0)) (go #S(sb-impl::comma :expr tag :kind 0))) (let ((#S(sb-impl::comma :expr var :kind 0) (at #S(sb-impl::comma :expr it :kind 0)))) #S(sb-impl::comma :expr decl :kind 2) (advance #S(sb-impl::comma :expr it :kind 0)) #S(sb-impl::comma :expr body :kind 2))))))) (#:iter-place167 (name more? &body body) (symbol-macrolet ((it (quote #:it165)) (tag (quote #:end-tag164))) (let ((body (sb-int:quasiquote (prog1 (progn #S(sb-impl::comma :expr body :kind 2)) (advance #S(sb-impl::comma :expr it :kind 0)))))) (with-variable-declarations ((decl-name name) (decl-more? more?)) forms body (sb-int:quasiquote (symbol-macrolet ((#S(sb-impl::comma :expr name :kind 0) (at #S(sb-impl::comma :expr it :kind 0)))) #S(sb-impl::comma :expr decl-name :kind 2) #S(sb-impl::comma :expr (if more? (sb-int:quasiquote (let ((#S(sb-impl::comma :expr more? :kind 0) (not (endp #S(sb-impl::comma :expr it :kind 0))))) #S(sb-impl::comma :expr decl-more? :kind 2) #S(sb-impl::comma :expr forms :kind 0))) (sb-int:quasiquote (progn (when (endp #S(sb-impl::comma :expr it :kind 0)) (go #S(sb-impl::comma :expr tag :kind 0))) #S(sb-impl::comma :expr forms :kind 0)))) :kind 0)))))))) (tagbody (loop do (with-iter-place (e1 it1 more1?) (with-iter-place (e2 it2 more2?) (when (not (and more1? more2?)) (return-from mismatch (when (or more1? more2?) (compute-pos pos)))) (unless (funcall test (funcall key e1) (funcall key e2)) (return-from mismatch (compute-pos pos))) (incf pos)))) #:end-tag164))))))", "category": "anaphoric", "technique": "symbol-macrolet,macrolet,gensym,anaphor", "complexity": "advanced", "quality_score": 0.895} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(matrix-ecase 'some-name)\n\nIssue: Macro call that should be transformed by MATRIX-ECASE", "input": "(matrix-ecase 'some-name)", "output": "(defmacro MATRIX-ECASE ...)", "macroexpand": "(let ((#:g244 quote))\n (ecase #:g244))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-<> nil)\n\nWrite a macro that addresses: Macro call that should be transformed by -<>", "input": "(-<> nil)", "output": "(defmacro -<> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(modf place new-value)\n\nWhat needs to change: Macro call that should be transformed by modf", "input": "(modf place new-value)", "output": "(defmacro modf (place value &rest more &environment env)\n \"Make a new object \\(which may use some of the old object) such that PLACE\nevaluates to VALUE.\n\nMORE should have the form...\n\nMORE : NIL\n | (TEMPORARY-BINDING ANOTHER-MODF-PLACE ANOTHER-VALUE . MORE)\n\nUse it to specify a temporary binding for the new object created which will be\nused in the subsequence MODF-PLACE NEW-VALUE pairs until the end of the MODF\nform.\"\n (if more\n (destructuring-bind (next-symbol next-place next-value &rest next-more) more\n `(let ((,next-symbol ,(modf-expand value place nil env)))\n (modf ,next-place ,next-value ,@next-more)))\n (modf-expand value place nil env)))", "macroexpand": "(let ((nil place)) new-value)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Generate a defmacro form that transforms code like this:\n(fgather-result nil)\n\nPattern to recognize: Macro call that should be transformed by FGATHER-RESULT", "input": "(fgather-result nil)", "output": "(defmacro FGATHER-RESULT ...)", "macroexpand": "(nil nil t)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defmacro+ps nil\n nil)\n\nProblem: Macro call that should be transformed by DEFMACRO+PS", "input": "(defmacro+ps nil\n nil)", "output": "(defmacro DEFMACRO+PS ...)", "macroexpand": "(progn\n (defmacro nil ())\n (defpsmacro nil\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(awhen (not (incf x)) t)\n\nPattern to recognize: Macro call that should be transformed by awhen", "input": "(awhen (not (incf x)) t)", "output": "(defmacro awhen (test &body body)\n \"Like WHEN, except binds the result of the test to IT (via LET) for the scope\nof the body.\"\n `(anaphoric when ,test ,@body))", "macroexpand": "(let ((it (not (incf x)))) (when it t))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-ignore nil)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-IGNORE", "input": "(collect-ignore nil)", "output": "(defmacro COLLECT-IGNORE ...)", "macroexpand": "(common-lisp:let* ((#:generator-169 (generator nil)))\n (declare (type generator #:generator-169))\n (tagbody #:ll-170 (next-in #:generator-169 (go end)) (go #:ll-170) end)\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<>> nil)\n\nProblem: Macro call that should be transformed by -<>>", "input": "(-<>> nil)", "output": "(defmacro -<>> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(gen-lambda () (if (not data) 'generator-stop (prog1 data (setf data (cdr data)))))\n\nWhat needs to change: Macro call that should be transformed by gen-lambda", "input": "(gen-lambda () (if (not data) 'generator-stop (prog1 data (setf data (cdr data)))))", "output": "(defmacro gen-lambda (params &body rest)\n \"Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions.\"\n `(let ((values-handler (create-values-handler)))\n (declare (ignorable values-handler))\n (make-instance \n 'basic-generator \n :function (lambda ,params ,@rest))))", "macroexpand": "(let ((values-handler (create-values-handler))) (declare (ignorable values-handler)) (make-instance (quote basic-generator) :function (lambda nil (if (not data) (quote generator-stop) (prog1 data (setf data (cdr data)))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun/1 pow (x y) (expt x y))\n\nIssue: Macro call that should be transformed by defun/1", "input": "(defun/1 pow (x y) (expt x y))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun pow (x y) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (expt x y)) (defparameter pow (vacietis.c:mkptr& (symbol-function (quote pow)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-mustache-character #\\= (let ((arg-text (string-trim '(#\\Space #\\Tab #\\=) arg-text))) (prog1 (make-instance 'delimiter-tag :text arg-text) (change-delimiter arg-text))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-mustache-character", "input": "(define-mustache-character #\\= (let ((arg-text (string-trim '(#\\Space #\\Tab #\\=) arg-text))) (prog1 (make-instance 'delimiter-tag :text arg-text) (change-delimiter arg-text))))", "output": "(defmacro define-mustache-character (char &body body)\n `(set-mustache-character\n ,char (lambda (raw-text arg-text escapep start end)\n (declare (ignorable raw-text arg-text escapep start end)\n (type simple-string raw-text arg-text)\n (boolean escapep)\n (offset start end))\n ,@body)))", "macroexpand": "(set-mustache-character #\\EQUALS_SIGN (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (let ((arg-text (string-trim (quote (#\\Space #\\Tab #\\EQUALS_SIGN)) arg-text))) (prog1 (make-instance (quote delimiter-tag) :text arg-text) (change-delimiter arg-text)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-iter iterator-dropwhile (base-iter pred been-false) (dropwhile (predicate iterable) \"Drops all elements of `base-iter` until `pred` first returns false, then yields all further elements ``` (dropwhile (lambda (x) (< 3 x) (count))) ;; 3, 4, 5, etc ```\" (init-state (pred predicate) (base-iter (make-iterator iterable)))) (if been-false (next base-iter) (multiple-value-bind (item base-alive) (next base-iter) (if base-alive (if (funcall pred item) (self) (progn (setf been-false t) (values item t))) (values nil nil)))))\n\nIssue: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-dropwhile (base-iter pred been-false) (dropwhile (predicate iterable) \"Drops all elements of `base-iter` until `pred` first returns false, then yields all further elements ``` (dropwhile (lambda (x) (< 3 x) (count))) ;; 3, 4, 5, etc ```\" (init-state (pred predicate) (base-iter (make-iterator iterable)))) (if been-false (next base-iter) (multiple-value-bind (item base-alive) (next base-iter) (if base-alive (if (funcall pred item) (self) (progn (setf been-false t) (values item t))) (values nil nil)))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname138 (&key base-iter pred been-false) (labels ((self nil (if been-false (next base-iter) (multiple-value-bind (item base-alive) (next base-iter) (if base-alive (if (funcall pred item) (self) (progn (setf been-false t) (values item t))) (values nil nil)))))) (function self)))) (defun dropwhile (predicate iterable) \"Drops all elements of `base-iter` until `pred` first returns false, then yields all further elements ``` (dropwhile (lambda (x) (< 3 x) (count))) ;; 3, 4, 5, etc ```\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname138)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (init-state (pred predicate) (base-iter (make-iterator iterable))))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(check-cursor-attached cluffer:end-of-buffer-p (cursor))\n\nPattern to recognize: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:end-of-buffer-p (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:end-of-buffer-p :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defdata maybe (just t) nothing)\n\nWhat needs to change: Macro call that should be transformed by defdata", "input": "(defdata maybe (just t) nothing)", "output": "(defmacro defdata (adt-name &body constructors)\n \"Define a new ADT. ADT-name has the following grammar:\n\nADT-NAME := \n | ( *)\n\nThere is no difference between specifying it as a symbol or as a\nsingleton list. There are two possible options, specified as a\nproperty list:\n\n * :MUTABLE {T, NIL} (default: NIL): Specifies whether the fields\n of the type are mutable, allowing the use of SET-DATA.\n\n * :INCLUDE : Specifies whether another defined ADT\n should be inherited.\n\nConstructors is a list of clauses with the following grammar:\n\n := \n | ( *)\n\nEach clause defines a constructor for the ADT. Nullary constructors\nwill define constants and all other constructors will define\nfunctions.\"\n ;; Do some extreme sanity checking.\n (assert\n (or\n ;; Must be a symbol, or...\n (symbolp adt-name)\n (and\n ;; a list that is...\n (listp adt-name)\n ;; non-empty\n (not (null adt-name))\n ;; whose first element is a symbol (the name of the adt)\n (symbolp (first adt-name))\n ;; and the rest is a property list\n (property-list-p (rest adt-name))))\n (adt-name)\n \"ADT-NAME must either be a symbol, a singleton list with the ADT ~\n name as a symbol, or a list of two elements with the ADT name ~\n and :MUTABLE respectively. Given ~S.\"\n adt-name)\n (let ((valid-options (list ':mutable ':include)))\n (when (and (listp adt-name) (= (mod (length (rest adt-name)) 2) 0))\n (loop for opt in (rest adt-name) by #'cddr do\n\t (when (not (member opt valid-options))\n\t (error \"Option ~A is not valid, valid options are member of ~A.\" opt valid-options)))))\n\n (let ((adt-name (ensure-car adt-name))\n (mutable? (and (listp adt-name)\n (getf (rest adt-name) ':mutable)\n t))\n (include (or (and (listp adt-name)\n (getf (rest adt-name) ':include))\n 'algebraic-data-type))\n (object (gensym \"OBJECT-\"))\n (stream (gensym \"STREAM-\"))\n (depth (gensym \"DEPTH-\"))\n (env (gensym \"ENVIRONMENT-\"))\n (documentation\n (when (stringp (car constructors))\n (pop constructors))))\n\n ;; Sanity check that INCLUDE is a proper algebraic data type.\n (assert (algebraic-data-type-p include)\n ()\n \"When defining the algebraic data type ~S, the :INCLUDE option ~\n was specified with ~S, which is not another algebraic data ~\n type.\"\n adt-name\n include)\n\n ;; Add constructors and their arity to the database.\n (flet ((constructor-and-arity (ctor)\n (if (listp ctor)\n (list (first ctor) (length (rest ctor)))\n (list ctor 0))))\n (set-constructors adt-name (append (get-constructors include)\n (mapcar #'constructor-and-arity constructors))))\n\n (flet ((make-printer (name &optional (nfields 0))\n \"Make a printer function for the structs.\"\n `(lambda (,object ,stream ,depth)\n (declare (ignore ,depth)\n (ignorable ,object))\n ;; We don't check *PRINT-READABLY* because these can\n ;; be readably printed always, provided the arguments\n ;; can be printed readably.\n ;;\n ;; However, we do respect a convenience option\n ;; *PRINT-ADT-READABLY* in case someone finds the\n ;; printing of the #. to be annoying.\n (when *print-adt-readably*\n (write-string \"#.\" ,stream))\n ,(when (plusp nfields)\n `(write-char #\\( ,stream))\n (prin1 ',name ,stream)\n ,@(when (plusp nfields)\n (loop :for i :below nfields\n :append (list\n `(write-char #\\Space ,stream)\n `(prin1 (,(field name i) ,object)\n ,stream))))\n ,(when (plusp nfields)\n `(write-char #\\) ,stream)))))\n ;; Define everything.\n (let ((component-documentation\n ;; Force the adt-name symbol to print with a package\n ;; prefix\n (let ((*package* (find-package :keyword)))\n (format nil \"A component of ADT ~S\" adt-name))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ;; Define the data type.\n (defstruct (,adt-name (:constructor nil)\n (:copier nil)\n (:predicate nil)\n (:include ,include))\n ,@(unsplice documentation))\n\n ;; Define each of the field constructors.\n ,@(loop :for ctor :in (unwrap-singletons constructors)\n :collect\n (etypecase ctor\n ;; Nullary constructor\n (symbol `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defstruct\n (,ctor\n (:include ,adt-name)\n (:constructor ,(internal ctor))\n (:copier nil)\n (:predicate nil)\n (:print-function ,(make-printer ctor)))\n ,component-documentation))\n #+sbcl (declaim (sb-ext:freeze-type ,ctor))\n (defmethod make-load-form ((,object ,ctor) &optional ,env)\n (make-load-form-saving-slots ,object\n :slot-names nil\n :environment ,env))\n (define-constant ,ctor (,(internal ctor))\n ,component-documentation)\n (fmakunbound ',(internal ctor))))\n\n ;; N-ary constructors\n (list (let* ((ctor-name (first ctor))\n (field-types (rest ctor))\n (field-names (gen-names (length field-types))))\n `(progn\n (defstruct (,ctor-name\n (:include ,adt-name)\n (:constructor ,ctor-name (,@field-names))\n (:conc-name ,ctor-name)\n (:copier nil)\n (:predicate nil)\n (:print-function\n ,(make-printer ctor-name\n (length field-names))))\n ,component-documentation\n ,@(mapcar (lambda (name type)\n `(,name (error \"Unspecified field.\")\n :type ,type\n ,@(if mutable?\n nil\n '(:read-only t))))\n field-names\n field-types))\n #+sbcl (declaim (sb-ext:freeze-type ,ctor-name))\n (defmethod make-load-form ((,object ,ctor-name) &optional ,env)\n (make-load-form-saving-slots ,object\n :slot-names ',field-names\n :environment ,env)))))))\n ;; Return the type name\n ',adt-name)))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defstruct (maybe (:constructor nil) (:copier nil) (:predicate nil) (:include algebraic-data-type))) (progn (defstruct (just (:include maybe) (:constructor just (%0)) (:conc-name just) (:copier nil) (:predicate nil) (:print-function (lambda (#:object-133 #:stream-134 #:depth-135) (declare (ignore #:depth-135) (ignorable #:object-133)) (when *print-adt-readably* (write-string \"#.\" #:stream-134)) (write-char #\\LEFT_PARENTHESIS #:stream-134) (prin1 (quote just) #:stream-134) (write-char #\\Space #:stream-134) (prin1 (just%0 #:object-133) #:stream-134) (write-char #\\RIGHT_PARENTHESIS #:stream-134)))) #A((48) base-char . \"A component of ADT CL-ALGEBRAIC-DATA-TYPE::MAYBE\") (%0 (error \"Unspecified field.\") :type t :read-only t)) (declaim (sb-ext:freeze-type just)) (defmethod make-load-form ((#:object-133 just) &optional #:environment-136) (make-load-form-saving-slots #:object-133 :slot-names (quote (%0)) :environment #:environment-136))) (progn (eval-when (:compile-toplevel :load-toplevel :execute) (defstruct (nothing (:include maybe) (:constructor %nothing) (:copier nil) (:predicate nil) (:print-function (lambda (#:object-133 #:stream-134 #:depth-135) (declare (ignore #:depth-135) (ignorable #:object-133)) (when *print-adt-readably* (write-string \"#.\" #:stream-134)) nil (prin1 (quote nothing) #:stream-134) nil))) #A((48) base-char . \"A component of ADT CL-ALGEBRAIC-DATA-TYPE::MAYBE\"))) (declaim (sb-ext:freeze-type nothing)) (defmethod make-load-form ((#:object-133 nothing) &optional #:environment-136) (make-load-form-saving-slots #:object-133 :slot-names nil :environment #:environment-136)) (define-constant nothing (%nothing) #A((48) base-char . \"A component of ADT CL-ALGEBRAIC-DATA-TYPE::MAYBE\")) (fmakunbound (quote %nothing))) (quote maybe))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(bind ((obj (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5)) ((:accessors-read-only a c e) obj)) (setf a :a c :c) (ensure-same (list a c e) '(:a :c 5) :test 'equal) (ensure-same (list (e obj) (c obj) (a obj)) '(5 3 1) :test 'equal))\n\nWhat needs to change: Macro call that should be transformed by bind", "input": "(bind ((obj (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5)) ((:accessors-read-only a c e) obj)) (setf a :a c :c) (ensure-same (list a c e) '(:a :c 5) :test 'equal) (ensure-same (list (e obj) (c obj) (a obj)) '(5 3 1) :test 'equal))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((obj (make-instance (quote metabang-bind-class-2) :a 1 :b 2 :c 3 :d 4 :e 5)) (#:|values-174| obj) (a (a #:|values-174|)) (c (c #:|values-174|)) (e (e #:|values-174|))) (declare (ignorable #:|values-174|)) (progn (setf a :a c :c) (ensure-same (list a c e) (quote (:a :c 5)) :test (quote equal)) (ensure-same (list (e obj) (c obj) (a obj)) (quote (5 3 1)) :test (quote equal))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(signal-reader-error \"Expected } after Unicode character name\")\n\nWhat needs to change: Macro call that should be transformed by signal-reader-error", "input": "(signal-reader-error \"Expected } after Unicode character name\")", "output": "(defmacro signal-reader-error (format-control &rest format-arguments)\n \"Like ERROR but signals a SIMPLE-READER-ERROR for the stream\n*STREAM*.\"\n `(error 'simple-reader-error\n :stream *stream*\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote simple-reader-error) :stream *stream* :format-control \"Expected } after Unicode character name\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(fail (warn \"An expected warning.\") warning)\n\nWrite a macro that addresses: Macro call that should be transformed by fail", "input": "(fail (warn \"An expected warning.\") warning)", "output": "(defmacro fail (form &optional (type 'error) description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(fail ,form ,type)\n :value-form '(capture-error ,form)\n :body (lambda () (capture-error ,form ,(maybe-unquote type)))\n :expected ',(maybe-unquote type)\n :comparison 'typep\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (fail (warn \"An expected warning.\") warning)) :value-form (quote (capture-error (warn \"An expected warning.\"))) :body (lambda nil (capture-error (warn \"An expected warning.\") warning)) :expected (quote warning) :comparison (quote typep)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-iter iterator-combinations (indices pool stopped r n) (combinations (r iterable) \"r-combinations of input iterable, returned as vectors in lexicographic order. ``` (combinations 2 '(1 2 3)) ;; #(1 2), #(1 3), #(2 3) ```\" (let ((ivec (iter-to-vec iterable))) (if (> r (length ivec)) (empty-iterator) (init-state r (n (length ivec)) (pool ivec) (indices (iter-to-vec (range 0 r 1))))))) (if stopped (values nil nil) (multiple-value-prog1 (loop with ret-vec = (make-array r) for i below r do (setf (aref ret-vec i) (aref pool (aref indices i))) finally (return (values ret-vec t))) (loop for i from (1- r) downto 0 when (/= (aref indices i) (+ i n (- r))) do (incf (aref indices i)) (loop for j from (1+ i) to (1- r) do (setf (aref indices j) (1+ (aref indices (1- j))))) (return) finally (setf stopped t)))))\n\nIssue: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-combinations (indices pool stopped r n) (combinations (r iterable) \"r-combinations of input iterable, returned as vectors in lexicographic order. ``` (combinations 2 '(1 2 3)) ;; #(1 2), #(1 3), #(2 3) ```\" (let ((ivec (iter-to-vec iterable))) (if (> r (length ivec)) (empty-iterator) (init-state r (n (length ivec)) (pool ivec) (indices (iter-to-vec (range 0 r 1))))))) (if stopped (values nil nil) (multiple-value-prog1 (loop with ret-vec = (make-array r) for i below r do (setf (aref ret-vec i) (aref pool (aref indices i))) finally (return (values ret-vec t))) (loop for i from (1- r) downto 0 when (/= (aref indices i) (+ i n (- r))) do (incf (aref indices i)) (loop for j from (1+ i) to (1- r) do (setf (aref indices j) (1+ (aref indices (1- j))))) (return) finally (setf stopped t)))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname128 (&key indices pool stopped r n) (labels ((self nil (if stopped (values nil nil) (multiple-value-prog1 (loop with ret-vec = (make-array r) for i below r do (setf (aref ret-vec i) (aref pool (aref indices i))) finally (return (values ret-vec t))) (loop for i from (1- r) downto 0 when (/= (aref indices i) (+ i n (- r))) do (incf (aref indices i)) (loop for j from (1+ i) to (1- r) do (setf (aref indices j) (1+ (aref indices (1- j))))) (return) finally (setf stopped t)))))) (function self)))) (defun combinations (r iterable) \"r-combinations of input iterable, returned as vectors in lexicographic order. ``` (combinations 2 '(1 2 3)) ;; #(1 2), #(1 3), #(2 3) ```\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname128)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (let ((ivec (iter-to-vec iterable))) (if (> r (length ivec)) (empty-iterator) (init-state r (n (length ivec)) (pool ivec) (indices (iter-to-vec (range 0 r 1)))))))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(assert-values (\"changed foo = 1\") (foo 1) (foo+1 2) (bar 2) (bar-1 1))\n\nWrite a macro that addresses: Macro call that should be transformed by assert-values", "input": "(assert-values (\"changed foo = 1\") (foo 1) (foo+1 2) (bar 2) (bar-1 1))", "output": "(defmacro assert-values ((desc) &body objects-and-values)\n `(progn\n (trc ,desc)\n ,@(loop for (obj val) in objects-and-values\n\t collect `(assert (eql (value ,obj) ,val)))))", "macroexpand": "(progn (trc \"changed foo = 1\") (assert (eql (value foo) 1)) (assert (eql (value foo+1) 2)) (assert (eql (value bar) 2)) (assert (eql (value bar-1) 1)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when (or (typep (node-slot expression) 'function-call) (typep (node-slot expression) 'infix-expression) (typep (node-slot expression) 'prefix-expression) (typep (node-slot expression) 'postfix-expression) (typep (node-slot expression) 'empty) (node-slot force-semicolon)) (format stream \";\"))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when (or (typep (node-slot expression) 'function-call) (typep (node-slot expression) 'infix-expression) (typep (node-slot expression) 'prefix-expression) (typep (node-slot expression) 'postfix-expression) (typep (node-slot expression) 'empty) (node-slot force-semicolon)) (format stream \";\"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (or (typep (node-slot expression) (quote function-call)) (typep (node-slot expression) (quote infix-expression)) (typep (node-slot expression) (quote prefix-expression)) (typep (node-slot expression) (quote postfix-expression)) (typep (node-slot expression) (quote empty)) (node-slot force-semicolon)) (format stream \";\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(continue-whopper nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by CONTINUE-WHOPPER", "input": "(continue-whopper nil :key nil)", "output": "(defmacro CONTINUE-WHOPPER ...)", "macroexpand": "(call-next-method-fn self class-env inst-env mcs%caller mcs%next-methods\n (list nil :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(draw scene (:rect :x 30 :y 30 :width 400 :height 150) :fill \"rgb(230,230,230)\" :stroke \"black\")\n\nPattern to recognize: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x 30 :y 30 :width 400 :height 150) :fill \"rgb(230,230,230)\" :stroke \"black\")", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g164 (funcall (function make-svg-element) :rect (append (list :x 30 :y 30 :width 400 :height 150) (list :fill \"rgb(230,230,230)\" :stroke \"black\"))))) (add-element scene #:g164) #:g164)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(letrec* (x) x)\n\nProblem: Macro call that should be transformed by letrec*", "input": "(letrec* (x) x)", "output": "(defmacro letrec* ((&rest bindings) &body body)\n \"Like LETREC, but the bindings are evaluated in order.\nSee Waddell et al., *Fixing Letrec* for motivation.\n\nCf. `fbindrec*'.\"\n `(letrec-with setq ,bindings\n ,@body))", "macroexpand": "(letrec-with setq (x) x)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(alist-bind (name type) form (let ((sym (foreign-type-symbol name :cextern *package*))) (push sym *foreign-extern-list*) `(define-foreign-extern ',sym ,name ',@(parse-type type (aval :tag type)))))\n\nIssue: Macro call that should be transformed by alist-bind", "input": "(alist-bind (name type) form (let ((sym (foreign-type-symbol name :cextern *package*))) (push sym *foreign-extern-list*) `(define-foreign-extern ',sym ,name ',@(parse-type type (aval :tag type)))))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist246 form)) (let ((name (aval :name #:alist246)) (type (aval :type #:alist246))) (let ((sym (foreign-type-symbol name :cextern *package*))) (push sym *foreign-extern-list*) (sb-int:quasiquote (define-foreign-extern (quote #S(sb-impl::comma :expr sym :kind 0)) #S(sb-impl::comma :expr name :kind 0) (quote #S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2)))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-type-map variable cl:variable)\n\nIssue: Macro call that should be transformed by define-simple-type-map", "input": "(define-simple-type-map variable cl:variable)", "output": "(defmacro define-simple-type-map (class type)\n `(defmethod type ((,class ,class))\n ',type))", "macroexpand": "(defmethod type ((variable variable)) (quote common-lisp:variable))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(undefmessage 'some-name)\n\nWhat needs to change: Macro call that should be transformed by UNDEFMESSAGE", "input": "(undefmessage 'some-name)", "output": "(defmacro UNDEFMESSAGE ...)", "macroexpand": "(fmakunbound ''some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(->\n 'some-name)\n\nIssue: Macro call that should be transformed by ->", "input": "(->\n 'some-name)", "output": "(defmacro -> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym multiplying :mult)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym multiplying :mult)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote multiplying) (quote synonym)) (quote :mult)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(next-in nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by NEXT-IN", "input": "(next-in nil :key nil)", "output": "(defmacro NEXT-IN ...)", "macroexpand": "(do-next-in nil #'(lambda () :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-table-name nil (yield obj))\n\nWrite a macro that addresses: Macro call that should be transformed by with-table-name", "input": "(with-table-name nil (yield obj))", "output": "(defmacro with-table-name (table-name &body body)\n `(let ((*table-name-scope* ,table-name))\n ,@body))", "macroexpand": "(let ((*table-name-scope* nil)) (yield obj))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(decf nil nil)\n\nIssue: Macro call that should be transformed by DECF", "input": "(decf nil nil)", "output": "(defmacro DECF ...)", "macroexpand": "(setq nil (sb-impl::xsubtract nil nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(read-char*)\n\nWhat needs to change: Macro call that should be transformed by read-char*", "input": "(read-char*)", "output": "(defmacro read-char* ()\n \"Convenience macro because we always read from the same string with\nthe same arguments.\"\n `(read-char *stream* t nil t))", "macroexpand": "(read-char *stream* t nil t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause (sum expr &optional into var result-type (type 'number)) \"Sum into a variable\" (return-reduction-code :identity 0 :operation '+ :expression expr :test nil :variable var :type type :accum-kind :increment))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause (sum expr &optional into var result-type (type 'number)) \"Sum into a variable\" (return-reduction-code :identity 0 :operation '+ :expression expr :test nil :variable var :type type :accum-kind :increment))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-sum-10 (&key ((:sum expr)) ((:into var)) ((:result-type type) (quote number))) \"Sum into a variable\" (return-reduction-code :identity 0 :operation (quote +) :expression expr :test nil :variable var :type type :accum-kind :increment)) (install-clause-info (quote (sum)) (quote (sum &optional :into :result-type)) (quote clause-sum-10) \"Sum into a variable\" nil) (quote (sum expr &optional into var result-type (type (quote number)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time walk-multiple-value-call-nondeterministic (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper MULTIPLE-VALUE-CALL-NONDETERMINISTIC: ~S\" form)) (unless (>= (length form) 2) (error \"MULTIPLE-VALUE-CALL-NONDETERMINISTIC must have at least one ~ argument, a FUNCTION: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'multiple-value-call-nondeterministic) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'multiple-value-call-nondeterministic)))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-multiple-value-call-nondeterministic (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper MULTIPLE-VALUE-CALL-NONDETERMINISTIC: ~S\" form)) (unless (>= (length form) 2) (error \"MULTIPLE-VALUE-CALL-NONDETERMINISTIC must have at least one ~ argument, a FUNCTION: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'multiple-value-call-nondeterministic) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'multiple-value-call-nondeterministic)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-multiple-value-call-nondeterministic (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper MULTIPLE-VALUE-CALL-NONDETERMINISTIC: ~S\" form)) (unless (>= (length form) 2) (error \"MULTIPLE-VALUE-CALL-NONDETERMINISTIC must have at least one ~ argument, a FUNCTION: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote multiple-value-call-nondeterministic)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote multiple-value-call-nondeterministic)))) (eval-when (:compile-toplevel) (compile (quote walk-multiple-value-call-nondeterministic))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-table node hash depth (bitmap array bits index hit) (if hit (%hamt-lookup (aref array index) key hash (1+ depth) test) (values nil nil)))\n\nProblem: Macro call that should be transformed by with-table", "input": "(with-table node hash depth (bitmap array bits index hit) (if hit (%hamt-lookup (aref array index) key hash (1+ depth) test) (values nil nil)))", "output": "(defmacro with-table (node hash depth\n (bitmap array bits index hit)\n &body body)\n \"Bitshifting in HAMT tables\"\n `(let* ((,bitmap (table-bitmap ,node))\n (,array (table-array ,node))\n (,bits (get-bits ,hash ,depth))\n (,index (get-index ,bits ,bitmap))\n (,hit (logbitp ,bits ,bitmap)))\n ,@body))", "macroexpand": "(let* ((bitmap (table-bitmap node)) (array (table-array node)) (bits (get-bits hash depth)) (index (get-index bits bitmap)) (hit (logbitp bits bitmap))) (if hit (%hamt-lookup (aref array index) key hash (1+ depth) test) (values nil nil)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(action (:after node-match node) (multiple-value-bind (new-node new-changed?) (maybe-simplify-match node) (when new-changed? (setf changed? t) new-node)))\n\nWrite a macro that addresses: Macro call that should be transformed by action", "input": "(action (:after node-match node) (multiple-value-bind (new-node new-changed?) (maybe-simplify-match node) (when new-changed? (setf changed? t) new-node)))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-match) (lambda (node) (declare (type node-match node)) (multiple-value-bind (new-node new-changed?) (maybe-simplify-match node) (when new-changed? (setf changed? t) new-node))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-for nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DO-FOR", "input": "(do-for nil\n nil)", "output": "(defmacro DO-FOR ...)", "macroexpand": "(block nil (lc ((block nil (tagbody (return (progn nil))))) progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> :three () (increment))\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> :three () (increment))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :three nil (increment))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Generate a defmacro form that transforms code like this:\n(set-handler nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by SET-HANDLER", "input": "(set-handler nil :key nil)", "output": "(defmacro SET-HANDLER ...)", "macroexpand": "(let ((key :key) (function nil))\n (let ((found (assoc key nil :test #'equal)))\n (if found\n (setf (cdr found) function)\n (prog1 function (push (cons key function) nil)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'make-accumulator :array-element #'accumulator-add :end-of-array #'accumulator-get-sequence :beginning-of-object #'make-accumulator :object-key #'accumulator-add-key :object-value #'accumulator-add-value :end-of-object #'accumulator-get :beginning-of-string #'make-vector-accumulator :string-char #'vector-accumulator-add :end-of-string #'vector-accumulator-get-string)\n\nIssue: Macro call that should be transformed by set-custom-vars", "input": "(set-custom-vars :integer #'parse-number :real #'parse-number :boolean #'json-boolean-to-lisp :beginning-of-array #'make-accumulator :array-element #'accumulator-add :end-of-array #'accumulator-get-sequence :beginning-of-object #'make-accumulator :object-key #'accumulator-add-key :object-value #'accumulator-add-value :end-of-object #'accumulator-get :beginning-of-string #'make-vector-accumulator :string-char #'vector-accumulator-add :end-of-string #'vector-accumulator-get-string)", "output": "(defmacro set-custom-vars (&rest key-args)\n `(setq\n ,@(loop for (supplied-key value) on key-args by #'cddr\n append (loop for (var . var-key) in *custom-vars*\n thereis (if (eql var-key supplied-key)\n (list var value))))))", "macroexpand": "(setq *integer-handler* (function parse-number) *real-handler* (function parse-number) *boolean-handler* (function json-boolean-to-lisp) *beginning-of-array-handler* (function make-accumulator) *end-of-array-handler* (function accumulator-get-sequence) *beginning-of-object-handler* (function make-accumulator) *object-key-handler* (function accumulator-add-key) *object-value-handler* (function accumulator-add-value) *end-of-object-handler* (function accumulator-get) *beginning-of-string-handler* (function make-vector-accumulator) *string-char-handler* (function vector-accumulator-add) *end-of-string-handler* (function vector-accumulator-get-string))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defstore example (&key (a 0) (b 0) (c (the integer (init-c a b)))))\n\nWhat needs to change: Macro call that should be transformed by defstore", "input": "(defstore example (&key (a 0) (b 0) (c (the integer (init-c a b)))))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (defun a-init-function152 (a #:a?163 b #:b?164) (declare (ignorable a #:a?163 b #:b?164)) (the integer (init-c a b))) (ensure-store (quote example) (quote (&key (a 0 #:a?163) (b 0 #:b?164) (c (the integer (a-init-function152 a #:a?163 b #:b?164)) #:c?165))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-prepared-query query (conn (format nil \"SHOW CREATE VIEW `~A`\" table-name)) (let ((results (dbi:execute query))) (getf (first (dbi:fetch-all results :format :plist)) :|Create View|)))\n\nIssue: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (conn (format nil \"SHOW CREATE VIEW `~A`\" table-name)) (let ((results (dbi:execute query))) (getf (first (dbi:fetch-all results :format :plist)) :|Create View|)))", "output": "(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)\n `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))", "macroexpand": "(call-with-prepared-query conn (format nil \"SHOW CREATE VIEW `~A`\" table-name) (lambda (query) (let ((results (dbi.driver:execute query))) (getf (first (dbi.driver:fetch-all results :format :plist)) :|Create View|))) :use-prepare-cached nil)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when else-body `(make-simple-block ,else-body))\n\nIssue: Macro call that should be transformed by when", "input": "(when else-body `(make-simple-block ,else-body))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if else-body (sb-int:quasiquote (make-simple-block #S(sb-impl::comma :expr else-body :kind 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-case-aware-find-symbol find-pragma-name #:with-c-syntax.pragma-name)\n\nPattern to recognize: Macro call that should be transformed by define-case-aware-find-symbol", "input": "(define-case-aware-find-symbol find-pragma-name #:with-c-syntax.pragma-name)", "output": "(defmacro define-case-aware-find-symbol\n (finder-function-name package-name\n &key (upcased-package-name (format nil \"~A.~A\" (string package-name) '#:UPCASED))\n (docstring\n (format nil \"Find a symbol in `~A' package having a same NAME. If not found, returns `nil'.\"\n package-name)))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defpackage ,upcased-package-name\n (:use)\n (:intern\n ,@(loop for sym being the external-symbol of package-name\n collect (string-upcase (symbol-name sym)))))\n ,@(loop for sym being the external-symbol of package-name\n for upcased = (string-upcase (symbol-name sym))\n collect `(setf (symbol-value (find-symbol ,upcased ',upcased-package-name))\n ',sym))\n (defun ,finder-function-name (string &optional (readtable-case (readtable-case *readtable*)))\n ,@(if docstring `(,docstring))\n (ecase readtable-case\n ((:upcase :invert)\n (if-let ((up-sym (find-symbol string ',upcased-package-name)))\n (symbol-value up-sym)))\n ((:downcase :preserve)\n (find-symbol string ',package-name))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defpackage #A((33) base-char . \"WITH-C-SYNTAX.PRAGMA-NAME.UPCASED\") (:use) (:intern #A((4) base-char . \"STDC\") #A((4) base-char . \"ONCE\") #A((13) base-char . \"WITH_C_SYNTAX\"))) (setf (symbol-value (find-symbol #A((4) base-char . \"STDC\") (quote #A((33) base-char . \"WITH-C-SYNTAX.PRAGMA-NAME.UPCASED\")))) (quote with-c-syntax.pragma-name:stdc)) (setf (symbol-value (find-symbol #A((4) base-char . \"ONCE\") (quote #A((33) base-char . \"WITH-C-SYNTAX.PRAGMA-NAME.UPCASED\")))) (quote with-c-syntax.pragma-name:|once|)) (setf (symbol-value (find-symbol #A((13) base-char . \"WITH_C_SYNTAX\") (quote #A((33) base-char . \"WITH-C-SYNTAX.PRAGMA-NAME.UPCASED\")))) (quote with-c-syntax.pragma-name:with_c_syntax)) (defun find-pragma-name (string &optional (readtable-case (readtable-case *readtable*))) #A((101) base-char . \"Find a symbol in `WITH-C-SYNTAX.PRAGMA-NAME' package having a same NAME. If not found, returns `nil'.\") (ecase readtable-case ((:upcase :invert) (if-let ((up-sym (find-symbol string (quote #A((33) base-char . \"WITH-C-SYNTAX.PRAGMA-NAME.UPCASED\"))))) (symbol-value up-sym))) ((:downcase :preserve) (find-symbol string (quote #:with-c-syntax.pragma-name))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-files (file (app-path \"themes/\") \"tmpl\") (compile-template :common-lisp-backend file))\n\nWhat needs to change: Macro call that should be transformed by do-files", "input": "(do-files (file (app-path \"themes/\") \"tmpl\") (compile-template :common-lisp-backend file))", "output": "(defmacro do-files ((var path &optional extension) &body body)\n \"For each file under PATH, run BODY. If EXTENSION is provided, only run\nBODY on files that match the given extension.\"\n (alexandria:with-gensyms (extension-p)\n `(flet ((,extension-p (file)\n (string= (pathname-type file) ,extension)))\n (cl-fad:walk-directory ,path (lambda (,var) ,@body)\n :follow-symlinks nil\n :test (if ,extension\n #',extension-p\n (constantly t))))))", "macroexpand": "(flet ((#:extension-p289 (file) (string= (pathname-type file) \"tmpl\"))) (cl-fad:walk-directory (app-path \"themes/\") (lambda (file) (compile-template :common-lisp-backend file)) :follow-symlinks nil :test (if \"tmpl\" (function #:extension-p289) (constantly t))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(true 5)\n\nWrite a macro that addresses: Macro call that should be transformed by true", "input": "(true 5)", "output": "(defmacro true (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(true ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected 'T\n :comparison 'geq\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (true 5)) :value-form (quote 5) :body (lambda nil 5) :expected (quote t) :comparison (quote geq)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause (multiply expr &optional into var result-type (type 'number)) \"Multiply into a variable\" (return-reduction-code :identity 1 :operation '* :expression expr :test nil :variable var :type type :accum-kind :increment))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause (multiply expr &optional into var result-type (type 'number)) \"Multiply into a variable\" (return-reduction-code :identity 1 :operation '* :expression expr :test nil :variable var :type type :accum-kind :increment))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-multiply-11 (&key ((:multiply expr)) ((:into var)) ((:result-type type) (quote number))) \"Multiply into a variable\" (return-reduction-code :identity 1 :operation (quote *) :expression expr :test nil :variable var :type type :accum-kind :increment)) (install-clause-info (quote (multiply)) (quote (multiply &optional :into :result-type)) (quote clause-multiply-11) \"Multiply into a variable\" nil) (quote (multiply expr &optional into var result-type (type (quote number)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-wcs-math-error-handling (ret (atanh x)) (check-wcs-math-result))\n\nProblem: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (atanh x)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g218 x) (#:g219 nil) (#:g220 (list #:g218))) (declare (ignorable #:g219) (type list #:g220) (dynamic-extent #:g220)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote atanh) #:g220) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g220)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(->*\n nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by ->*", "input": "(->*\n nil\n :key\n nil)", "output": "(defmacro ->* ...)", "macroexpand": "(let* ((#:var194 nil) (#:var195 (nil #:var194)) (#:var196 (:key #:var195)))\n #:var196)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(let+ nil)\n\nProblem: Macro call that should be transformed by LET+", "input": "(let+ nil)", "output": "(defmacro LET+ ...)", "macroexpand": "(locally)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(fmap #'nreverse (recurse (list res) next))\n\nWrite a macro that addresses: Macro call that should be transformed by fmap", "input": "(fmap #'nreverse (recurse (list res) next))", "output": "(defmacro fmap (f thing)\n \"Apply a pure function to the inner contents of some parsing operation, if the\nparsing itself was successful.\"\n `(multiple-value-bind (res next) ,thing\n (if (failure? res)\n (fail next)\n (values (funcall ,f res) next))))", "macroexpand": "(multiple-value-bind (res next) (recurse (list res) next) (if (failure? res) (fail next) (values (funcall (function nreverse) res) next)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some-> nil (progn))\n\nProblem: Macro call that should be transformed by SOME->", "input": "(some-> nil (progn))", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:|some127| nil) (#:|some127| (when #:|some127| (progn #:|some127|))))\n #:|some127|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(setypecase (car x) (symbol (setf it :no)) (string (setf it \"OK\")) (integer (setf it :noon)))\n\nPattern to recognize: Macro call that should be transformed by setypecase", "input": "(setypecase (car x) (symbol (setf it :no)) (string (setf it \"OK\")) (integer (setf it :noon)))", "output": "(defmacro setypecase (keyform &body cases)\n \"Like ETYPECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for\nthe scope of the cases. IT can be set with SETF.\"\n `(symbolic etypecase ,keyform ,@cases))", "macroexpand": "(symbolic etypecase (car x) (symbol (setf it :no)) (string (setf it \"OK\")) (integer (setf it :noon)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(iterate\n nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by ITERATE", "input": "(iterate\n nil\n (progn))", "output": "(defmacro ITERATE ...)", "macroexpand": "(iter\n nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(sif 1 (aif it it))\n\nIssue: Macro call that should be transformed by sif", "input": "(sif 1 (aif it it))", "output": "(defmacro sif (test then &optional else)\n \"Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for\nthe scope of the then and else expressions. IT can be set with SETF\"\n `(symbolic if ,test ,then ,else))", "macroexpand": "(symbolic if 1 (aif it it) nil)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lambda-match0 ((list* 'guard1 _) t))\n\nProblem: Macro call that should be transformed by lambda-match0", "input": "(lambda-match0 ((list* 'guard1 _) t))", "output": "(defmacro lambda-match0 (&body clauses)\n (alexandria:with-gensyms (arg)\n `(lambda (,arg)\n (match0 ,arg\n ,@clauses))))", "macroexpand": "(lambda (#:arg164) (match0 #:arg164 ((list* (quote guard1) _) t)))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-transaction *db* (commit *db*) (setf value :foo))\n\nProblem: Macro call that should be transformed by with-transaction", "input": "(with-transaction *db* (commit *db*) (setf value :foo))", "output": "(defmacro with-transaction (conn &body body)\n \"Start a transaction and commit at the end of this block. If the evaluation `body` is interrupted, the transaction is rolled back automatically.\"\n (let ((conn-var (gensym \"CONN-VAR\")))\n `(let ((,conn-var ,conn))\n (if (in-transaction ,conn-var)\n (with-savepoint ,conn-var ,@body)\n (%with-transaction ,conn-var ,@body)))))", "macroexpand": "(let ((#:conn-var161 *db*)) (if (in-transaction #:conn-var161) (with-savepoint #:conn-var161 (commit *db*) (setf value :foo)) (%with-transaction #:conn-var161 (commit *db*) (setf value :foo))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(maybe-once-only nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by MAYBE-ONCE-ONLY", "input": "(maybe-once-only nil\n :key\n nil)", "output": "(defmacro MAYBE-ONCE-ONLY ...)", "macroexpand": "(let* ((#:g184 nil))\n `(let* ,(nreverse #:g184)\n ,:key\n ,nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause finally (&rest forms) \"Evaluates
        after the last iteration, before returning a value.\" (mapcar (lambda (form) (make-finalization :form form)) forms))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause finally (&rest forms) \"Evaluates after the last iteration, before returning a value.\" (mapcar (lambda (form) (make-finalization :form form)) forms))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro finally (&rest forms) \"Evaluates after the last iteration, before returning a value.\" (mapcar (lambda (form) (make-finalization :form form)) forms)) (pushnew (quote finally) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(sum-of nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by SUM-OF", "input": "(sum-of nil\n :key\n nil)", "output": "(defmacro SUM-OF ...)", "macroexpand": "(lc (nil :key nil) sum)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deferror \"42701\" duplicate-column syntax-error-or-access-violation)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"42701\" duplicate-column syntax-error-or-access-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition duplicate-column (syntax-error-or-access-violation) nil) (setf (gethash \"42701\" *error-table*) (quote duplicate-column)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(cond-> nil (progn))\n\nWhat needs to change: Macro call that should be transformed by COND->", "input": "(cond-> nil (progn))", "output": "(defmacro COND-> ...)", "macroexpand": "(let* ((#:|cond132| nil)\n (#:|cond132|\n (if progn\n #:|cond132|\n #:|cond132|)))\n #:|cond132|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(in-compile-time nil)\n\nProblem: Macro call that should be transformed by IN-COMPILE-TIME", "input": "(in-compile-time nil)", "output": "(defmacro IN-COMPILE-TIME ...)", "macroexpand": "(macrolet ((#:macro141 (&environment ())\n ))\n (#:macro141))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (not (or (eql (top-info) 'typedef) (eql (top-info) 'decl))) (format stream \";\"))\n\nProblem: Macro call that should be transformed by when", "input": "(when (not (or (eql (top-info) 'typedef) (eql (top-info) 'decl))) (format stream \";\"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (not (or (eql (top-info) (quote typedef)) (eql (top-info) (quote decl)))) (format stream \";\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-neo4j-fun get-node-properties (node-id) :get (:uri-spec (format nil \"node/~A/properties\" node-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (204 nil) (404 (error 'node-not-found-error :uri uri))))\n\nWhat needs to change: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-node-properties (node-id) :get (:uri-spec (format nil \"node/~A/properties\" node-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (204 nil) (404 (error 'node-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-node-properties (&key node-id) (let ((uri (format nil \"node/~A/properties\" node-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 204 (lambda (body uri json) nil)) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda ())\n\nPattern to recognize: Macro call that should be transformed by LAMBDA", "input": "(lambda ())", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(gen-lambda-with-sticky-stop () (loop for g in generators for v in valfuncs do (let ((data (multiple-value-list (funcall v g)))) (if (car data) (progn (push (car data) sigs) (push (cdr data) stor)) (sticky-stop)))) (when (= 0 (length (remove-if (lambda (x) (eq x :filled)) sigs))) (sticky-stop)) (let ((tmp stor)) (setf stor nil) (setf sigs nil) (apply #'values (nreverse tmp))))\n\nWhat needs to change: Macro call that should be transformed by gen-lambda-with-sticky-stop", "input": "(gen-lambda-with-sticky-stop () (loop for g in generators for v in valfuncs do (let ((data (multiple-value-list (funcall v g)))) (if (car data) (progn (push (car data) sigs) (push (cdr data) stor)) (sticky-stop)))) (when (= 0 (length (remove-if (lambda (x) (eq x :filled)) sigs))) (sticky-stop)) (let ((tmp stor)) (setf stor nil) (setf sigs nil) (apply #'values (nreverse tmp))))", "output": "(defmacro gen-lambda-with-sticky-stop (&rest rest)\n `(make-instance \n 'basic-generator \n :function (sticky-stop-lambda ,@rest)))", "macroexpand": "(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (loop for g in generators for v in valfuncs do (let ((data (multiple-value-list (funcall v g)))) (if (car data) (progn (push (car data) sigs) (push (cdr data) stor)) (sticky-stop)))) (when (= 0 (length (remove-if (lambda (x) (eq x :filled)) sigs))) (sticky-stop)) (let ((tmp stor)) (setf stor nil) (setf sigs nil) (apply (function values) (nreverse tmp)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(send nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by SEND", "input": "(send nil :key nil)", "output": "(defmacro SEND ...)", "macroexpand": "(send (slot-value nil ':key) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-wcs-math-error-handling (ret (ftruncate x)) (check-wcs-math-result))\n\nIssue: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling (ret (ftruncate x)) (check-wcs-math-result))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g251 x) (#:g252 nil) (#:g253 (list #:g251))) (declare (ignorable #:g252) (type list #:g253) (dynamic-extent #:g253)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote ftruncate) #:g253) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g253)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-syntax-error* (car this-last-pos) \"Quantifier '~A' not allowed.\" (subseq (lexer-str lexer) (car this-last-pos) (lexer-pos lexer)))\n\nIssue: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (car this-last-pos) \"Quantifier '~A' not allowed.\" (subseq (lexer-str lexer) (car this-last-pos) (lexer-pos lexer)))", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos (car this-last-pos) :format-control \"Quantifier '~A' not allowed.\" :format-arguments (list (subseq (lexer-str lexer) (car this-last-pos) (lexer-pos lexer))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(without-symbol-access)\n\nPattern to recognize: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS", "input": "(without-symbol-access)", "output": "(defmacro WITHOUT-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (and (not (eql (top-info) 'decl)) (> (length (slot-value (node-slot members) 'nodes)) 3)) (push-sign 'enum-break))\n\nProblem: Macro call that should be transformed by when", "input": "(when (and (not (eql (top-info) 'decl)) (> (length (slot-value (node-slot members) 'nodes)) 3)) (push-sign 'enum-break))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (and (not (eql (top-info) (quote decl))) (> (length (slot-value (node-slot members) (quote nodes))) 3)) (push-sign (quote enum-break)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause in-list (&whole form list &key (by '(function cdr)) (rest (gensym \"REST\")) &environment env) \"Like IN, but specialized for lists. Successive lists are obtained by calling the function BY (which by default is #'CDR) on the previous list. REST, if specified, is the variable holding the remaining elements to be processed; REST initially is bound to the entire list, then to successive lists obtained by funcalling BY.\" (if (symbolp *iteration-variable*) (list (make-simple-iteration :var rest :init list :step `(funcall ,by ,rest)) (make-simple-iteration :init `(car ,rest) :step `(car ,rest) :precondition `(not (null ,rest)))) (expand-with-simple-destructuring form env)))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause in-list (&whole form list &key (by '(function cdr)) (rest (gensym \"REST\")) &environment env) \"Like IN, but specialized for lists. Successive lists are obtained by calling the function BY (which by default is #'CDR) on the previous list. REST, if specified, is the variable holding the remaining elements to be processed; REST initially is bound to the entire list, then to successive lists obtained by funcalling BY.\" (if (symbolp *iteration-variable*) (list (make-simple-iteration :var rest :init list :step `(funcall ,by ,rest)) (make-simple-iteration :init `(car ,rest) :step `(car ,rest) :precondition `(not (null ,rest)))) (expand-with-simple-destructuring form env)))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro in-list (&whole form list &key (by (quote (function cdr))) (rest (gensym \"REST\")) &environment env) \"Like IN, but specialized for lists. Successive lists are obtained by calling the function BY (which by default is #'CDR) on the previous list. REST, if specified, is the variable holding the remaining elements to be processed; REST initially is bound to the entire list, then to successive lists obtained by funcalling BY.\" (if (symbolp *iteration-variable*) (list (make-simple-iteration :var rest :init list :step (sb-int:quasiquote (funcall #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr rest :kind 0)))) (make-simple-iteration :init (sb-int:quasiquote (car #S(sb-impl::comma :expr rest :kind 0))) :step (sb-int:quasiquote (car #S(sb-impl::comma :expr rest :kind 0))) :precondition (sb-int:quasiquote (not (null #S(sb-impl::comma :expr rest :kind 0)))))) (expand-with-simple-destructuring form env))) (pushnew (quote in-list) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(yield-all g)\n\nPattern to recognize: Macro call that should be transformed by yield-all", "input": "(yield-all g)", "output": "(defmacro yield-all (generator)\n \"Walks through generator, re-yielding all of the items in it. Only meant for use inside of a defgenerator or with-yield block.\"\n (let ((x (gensym)))\n `(do-generator (,x ,generator)\n (yield ,x))))", "macroexpand": "(do-generator (#:g182 g) (yield #:g182))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.7975} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:% conjunctive-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:% conjunctive-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (%-op (:include conjunctive-op (name \"%\")) (:constructor make-%-op (&rest expressions))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do-for nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DO-FOR", "input": "(do-for nil)", "output": "(defmacro DO-FOR ...)", "macroexpand": "(block nil (lc ((block nil (tagbody (return (progn))))) progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is-traced$method 'some-name)\n\nIssue: Macro call that should be transformed by IS-TRACED$METHOD", "input": "(is-traced$method 'some-name)", "output": "(defmacro IS-TRACED$METHOD ...)", "macroexpand": "(mcs-is-traced quote some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym counting :count)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym counting :count)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote counting) (quote synonym)) (quote :count)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield\n nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-YIELD", "input": "(with-yield\n nil\n nil)", "output": "(defmacro WITH-YIELD ...)", "macroexpand": "(isolate-cont\n (enable-yield\n nil\n nil\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(some-<> nil (progn))\n\nPattern to recognize: Macro call that should be transformed by SOME-<>", "input": "(some-<> nil (progn))", "output": "(defmacro SOME-<> ...)", "macroexpand": "(let* ((#:g122 nil))\n (if (null #:g122)\n nil\n (-> #:g122 (progn))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym first-time-p :first-time-p)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym first-time-p :first-time-p)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote first-time-p) (quote synonym)) (quote :first-time-p)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder (:session :store (make-dbi-store :connector (lambda () *conn*) :record-timestamps t)) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session))))))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder (:session :store (make-dbi-store :connector (lambda () *conn*) :record-timestamps t)) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session))))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app236) (funcall (find-middleware :session) #:app236 :store (make-dbi-store :connector (lambda nil *conn*) :record-timestamps t))))) :initial-value (to-app (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (#S(sb-impl::comma :expr (format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-definition-resolver setf-expander (designator) (sb-int:info :setf :expander designator))\n\nWhat needs to change: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver setf-expander (designator) (sb-int:info :setf :expander designator))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver setf-expander (setf-expander #:package142) (when (ignore-errors (let ((designator setf-expander)) (sb-int:info :setf :expander designator))) (list (make-instance (quote setf-expander) :designator setf-expander :package #:package142))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda-match\n nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by LAMBDA-MATCH", "input": "(lambda-match\n nil\n (progn))", "output": "(defmacro LAMBDA-MATCH ...)", "macroexpand": "(lambda (#:arg148)\n (match #:arg148\n nil\n (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-prepared-query query (conn sql) (or (dbi:fetch-all (dbi:execute query) :format :plist) (error \"Table \\\"~A\\\" doesn't exist.\" table-name)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (conn sql) (or (dbi:fetch-all (dbi:execute query) :format :plist) (error \"Table \\\"~A\\\" doesn't exist.\" table-name)))", "output": "(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)\n `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))", "macroexpand": "(call-with-prepared-query conn sql (lambda (query) (or (dbi.driver:fetch-all (dbi.driver:execute query) :format :plist) (error \"Table \\\"~A\\\" doesn't exist.\" table-name))) :use-prepare-cached nil)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-form-html-output (apply #'forms::renderer-render-form-errors renderer theme form args) (:form :id (forms::form-id form) :action (forms::form-action form) :method (symbol-name (forms::form-method form)) :enctype (forms::form-enctype form) :class (getf args :class) :data-parsley-validate (when (forms::client-validation form) \"true\") (when (forms::form-csrf-protection-p form) (let ((token (forms::set-form-session-csrf-token form))) (htm (:input :name (forms::form-csrf-field-name form) :type \"hidden\" :value token)))) (loop for field in (forms::form-fields form) do (forms::renderer-render-field renderer theme (cdr field) form))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-form", "input": "(with-form-html-output (apply #'forms::renderer-render-form-errors renderer theme form args) (:form :id (forms::form-id form) :action (forms::form-action form) :method (symbol-name (forms::form-method form)) :enctype (forms::form-enctype form) :class (getf args :class) :data-parsley-validate (when (forms::client-validation form) \"true\") (when (forms::form-csrf-protection-p form) (let ((token (forms::set-form-session-csrf-token form))) (htm (:input :name (forms::form-csrf-field-name form) :type \"hidden\" :value token)))) (loop for field in (forms::form-fields form) do (forms::renderer-render-field renderer theme (cdr field) form))))", "output": "(defmacro with-form (form &body body)\n \"Bind *FORM* to FORM and evaluate BODY in that context.\"\n `(call-with-form ,form (lambda () ,@body)))", "macroexpand": "(with-form-html-output (apply (function renderer-render-form-errors) renderer theme form args) (:form :id (form-id form) :action (form-action form) :method (symbol-name (form-method form)) :enctype (form-enctype form) :class (getf args :class) :data-parsley-validate (when (client-validation form) \"true\") (when (form-csrf-protection-p form) (let ((token (set-form-session-csrf-token form))) (htm (:input :name (form-csrf-field-name form) :type \"hidden\" :value token)))) (loop for field in (form-fields form) do (renderer-render-field renderer theme (cdr field) form))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-html-string (:div (:div (:div (:div.list-group.toc-entries :data-instant t)))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-html", "input": "(with-html-string (:div (:div (:div (:div.list-group.toc-entries :data-instant t)))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:div (:div (:div (:div.list-group.toc-entries :data-instant t))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-plist nil (progn))\n\nProblem: Macro call that should be transformed by COLLECT-PLIST", "input": "(collect-plist nil (progn))", "output": "(defmacro COLLECT-PLIST ...)", "macroexpand": "(common-lisp:let* ((#:generator-200 (generator (progn)))\n #:values-193\n (#:generator-198 (generator nil))\n #:indicators-192\n (#:plist-194 nil))\n (declare (type generator #:generator-200)\n (type generator #:generator-198)\n (type list #:plist-194))\n (tagbody\n #:ll-201\n (setq #:values-193 (next-in #:generator-200 (go end)))\n (setq #:indicators-192 (next-in #:generator-198 (go end)))\n (setq #:plist-194 (list* #:indicators-192 #:values-193 #:plist-194))\n (go #:ll-201)\n end)\n #:plist-194)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error uniform-in-sfunc () (func-name) \"Must not have uniforms in shader functions, only appropriate in shader stages: ~a\" func-name)\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error uniform-in-sfunc () (func-name) \"Must not have uniforms in shader functions, only appropriate in shader stages: ~a\" func-name)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition uniform-in-sfunc (:error-type varjo-error :prefix \"Varjo\") (func-name) \"Must not have uniforms in shader functions, only appropriate in shader stages: ~a\" func-name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(atypecase \"Foo\" (fixnum :no) (hash-table :nono))\n\nWhat needs to change: Macro call that should be transformed by atypecase", "input": "(atypecase \"Foo\" (fixnum :no) (hash-table :nono))", "output": "(defmacro atypecase (keyform &body cases)\n \"Like TYPECASE, except binds the result of the keyform to IT (via LET) for\nthe scope of the cases.\"\n `(anaphoric typecase ,keyform ,@cases))", "macroexpand": "(anaphoric typecase \"Foo\" (fixnum :no) (hash-table :nono))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defmethod* nil\n (progn))\n\nIssue: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil\n (progn))", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(defmethod nil (progn) (with-yield))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-env (setp 3 [plist :e]))\n\nWhat needs to change: Macro call that should be transformed by with-env", "input": "(with-env (setp 3 [plist :e]))", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g137) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g137 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) (setp 3 [plist :e]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g137)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(lret* ((type `(integer ,start (,end))) (len (ceiling (- end start) step)) (vector (make-array len :element-type type :initial-element start))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (+ n step))))))\n\nPattern to recognize: Macro call that should be transformed by lret", "input": "(lret* ((type `(integer ,start (,end))) (len (ceiling (- end start) step)) (vector (make-array len :element-type type :initial-element start))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (+ n step))))))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((type (sb-int:quasiquote (integer #S(sb-impl::comma :expr start :kind 0) (#S(sb-impl::comma :expr end :kind 0))))) (len (ceiling (- end start) step)) (vector (make-array len :element-type type :initial-element start))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (+ n step))))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-local-readtable\n nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by WITH-LOCAL-READTABLE", "input": "(with-local-readtable\n nil\n :key\n nil)", "output": "(defmacro WITH-LOCAL-READTABLE ...)", "macroexpand": "(bind ((*readtable* (copy-readtable *readtable*)))\n nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> +period+ +skip-junk+)\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> +period+ +skip-junk+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset227) (multiple-value-bind (#:*>-res228 #:*>-next229) (funcall +period+ #:*>-offset227) (if (ok? #:*>-res228) (funcall +skip-junk+ #:*>-next229) (fail #:*>-next229))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is (characterp c))\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is (characterp c))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:v252 c)) (if (characterp #:v252) (add-result (quote test-passed) :test-expr (quote (characterp c))) (process-failure (quote (characterp c)) \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\" (quote c) #:v252 (quote characterp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-additional-indent (reporter stream \"- \") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description))))\n\nIssue: Macro call that should be transformed by with-additional-indent", "input": "(with-additional-indent (reporter stream \"- \") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description))))", "output": "(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)\n (declare (ignorable reporter stream control-string))\n (let* ((need-new-line (ppcre:scan \"^~&\" control-string))\n (string (apply #'format nil control-string format-arguments))\n (increment (length string)))\n `(with-slots (indent-space) reporter\n (let* ((first-line-indent (indent indent-space))\n (*additional-indent* ,(if need-new-line\n increment\n `(+ *additional-indent*\n ,increment))))\n (declare (ignorable first-line-indent))\n ,(if need-new-line\n `(progn (fresh-line stream)\n (write-string first-line-indent ,stream)\n ;; because we just started a new line, we\n ;; should use format/indent to write string\n ;; taking into account a main indentation level\n (format/indent ,reporter ,stream ,string))\n ;; otherwise, just output our prefix\n `(write-string ,string ,stream))\n \n \n ,@body))))", "macroexpand": "(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* (+ *additional-indent* 2))) (declare (ignorable first-line-indent)) (write-string #A((2) base-char . \"- \") stream) (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFINE", "input": "(define nil\n (progn))", "output": "(defmacro DEFINE ...)", "macroexpand": "(eval-when (:load-toplevel :execute)\n (check-if-bound 'nil)\n (setf (get 'nil 'read-macro)\n (lambda (#:stream147)\n (let ((*standard-input* #:stream147))\n (progn))))\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(draw scene (:rect :x 5 :y 5 :height 30 :width 30))\n\nPattern to recognize: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x 5 :y 5 :height 30 :width 30))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g142 (funcall (function make-svg-element) :rect (append (list :x 5 :y 5 :height 30 :width 30) (list))))) (add-element scene #:g142) #:g142)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do+ (for x (across #())) (collect x))\n\nWhat needs to change: Macro call that should be transformed by do+", "input": "(do+ (for x (across #())) (collect x))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (across #())) (collect x))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8624999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(insert-char-class-tester (regex (schar *string* curr-pos)) (constant-repetition-constant-length-closure (and (char-class-test) (1+ curr-pos))))\n\nPattern to recognize: Macro call that should be transformed by insert-char-class-tester", "input": "(insert-char-class-tester (regex (schar *string* curr-pos)) (constant-repetition-constant-length-closure (and (char-class-test) (1+ curr-pos))))", "output": "(defmacro insert-char-class-tester ((char-class chr-expr) &body body)\n \"Utility macro to replace each occurence of '\\(CHAR-CLASS-TEST)\nwithin BODY with the correct test (corresponding to CHAR-CLASS)\nagainst CHR-EXPR.\"\n (with-rebinding (char-class)\n (with-unique-names (test-function)\n (flet ((substitute-char-class-tester (new)\n (subst new '(char-class-test) body\n :test #'equalp)))\n `(let ((,test-function (test-function ,char-class)))\n ,@(substitute-char-class-tester\n `(funcall ,test-function ,chr-expr)))))))", "macroexpand": "(let ((#:char-class161 regex)) (let ((#:test-function162 (test-function #:char-class161))) (constant-repetition-constant-length-closure (and (funcall #:test-function162 (schar *string* curr-pos)) (1+ curr-pos)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-error if-branch-type-mismatch (:error-type varjo-critical-error) (then-obj) \"Type mismatch: else-case is nil which is of bool type, yet the then form is of ~s type.\" (type->type-spec (primary-type then-obj)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error if-branch-type-mismatch (:error-type varjo-critical-error) (then-obj) \"Type mismatch: else-case is nil which is of bool type, yet the then form is of ~s type.\" (type->type-spec (primary-type then-obj)))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition if-branch-type-mismatch (:error-type varjo-critical-error :prefix \"Varjo\") (then-obj) \"Type mismatch: else-case is nil which is of bool type, yet the then form is of ~s type.\" (type->type-spec (primary-type then-obj)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-value-binding from ((var (if ascending (- from by) (+ from by))) from &key (to NIL to-p) (by 1) &aux (ascending (or (not to) (< from to)))) (declare (type real var from by) (type (or real null) to) (type boolean ascending)) (declare (ignore from)) (if to-p `(cond (,ascending (incf ,var ,by) (when (<= ,to ,var) (end-for))) (T (decf ,var ,by) (when (<= ,var ,to) (end-for)))) `(incf ,var ,by)))\n\nIssue: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding from ((var (if ascending (- from by) (+ from by))) from &key (to NIL to-p) (by 1) &aux (ascending (or (not to) (< from to)))) (declare (type real var from by) (type (or real null) to) (type boolean ascending)) (declare (ignore from)) (if to-p `(cond (,ascending (incf ,var ,by) (when (<= ,to ,var) (end-for))) (T (decf ,var ,by) (when (<= ,var ,to) (end-for)))) `(incf ,var ,by)))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding from (var from &key (to nil to-p) (by 1)) (let ((#:ascending176 (gensym #A((9) base-char . \"ASCENDING\"))) (#:from173 (gensym #A((4) base-char . \"FROM\"))) (#:to174 (gensym #A((2) base-char . \"TO\"))) (#:by175 (gensym #A((2) base-char . \"BY\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:from173 from) (list #:to174 to) (list #:by175 by) (list #:ascending176 (list (quote or) (list (quote not) #:to174) (list (quote <) #:from173 #:to174))) (loop for #:var172 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var172 (list (quote if) #:ascending176 (list (quote -) #:from173 #:by175) (list (quote +) #:from173 #:by175))))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:ascending176 :kind 0) #S(sb-impl::comma :expr #:from173 :kind 0) #S(sb-impl::comma :expr #:to174 :kind 0) #S(sb-impl::comma :expr #:by175 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote real) :kind 0) #S(sb-impl::comma :expr var :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote real) :kind 0) #S(sb-impl::comma :expr #:from173 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote real) :kind 0) #S(sb-impl::comma :expr #:by175 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote (or real null)) :kind 0) #S(sb-impl::comma :expr #:to174 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote boolean) :kind 0) #S(sb-impl::comma :expr #:ascending176 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((ascending #:ascending176) (from #:from173) (to #:to174) (by #:by175)) (declare (ignorable ascending from to by)) (declare (ignore from)) (if to-p (sb-int:quasiquote (cond (#S(sb-impl::comma :expr ascending :kind 0) (incf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr by :kind 0)) (when (<= #S(sb-impl::comma :expr to :kind 0) #S(sb-impl::comma :expr var :kind 0)) (end-for))) (t (decf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr by :kind 0)) (when (<= #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr to :kind 0)) (end-for))))) (sb-int:quasiquote (incf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr by :kind 0))))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-html-string (:div :class \"last-update col-xs-2 col-md-1\" :title \"Last updated 232 days ago\" \"232d\"))\n\nPattern to recognize: Macro call that should be transformed by with-html", "input": "(with-html-string (:div :class \"last-update col-xs-2 col-md-1\" :title \"Last updated 232 days ago\" \"232d\"))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:div :class \"last-update col-xs-2 col-md-1\" :title \"Last updated 232 days ago\" \"232d\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-cfun c-free)\n\nWhat needs to change: Macro call that should be transformed by define-cfun", "input": "(define-cfun c-free)", "output": "(defmacro define-cfun (name-or-function &optional (package *package*))\n (when-let ((fun (find-function name-or-function)))\n (with-wrap-attempt (\"function ~S\" name-or-function) name-or-function\n (with-slots (name type c-symbol fields) fun\n (let* ((fun-name (intern (symbol-name name) package))\n (param-names (mapcar #'foreign-type-name fields))\n (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))\n (make-function-p (not (foreign-function-variadic-p fun)))\n (maybe-cbv-return\n (when (cbv-return-p fun)\n (list 'return-value))))\n (with-gensyms (!fun !fields rest)\n (let ((form\n (if make-function-p\n `(defun ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n ,(let ((!fun (find-function name-or-function)))\n (with-slots ((!fields fields)) !fun\n (foreign-to-ffi\n (and (car !fields) (foreign-type (car !fields)))\n param-syms\n param-names\n !fields\n (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)\n param-syms (when (foreign-function-variadic-p fun) rest))))))\n `(defmacro ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n (let ((,!fun (find-function ',name-or-function)))\n (with-slots ((,!fields fields)) ,!fun\n (foreign-to-ffi\n (and (car ,!fields) (foreign-type (car ,!fields)))\n ',param-syms\n (list ,@param-names)\n ,!fields\n (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)\n ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))\n `(progn\n ,@(when (foreign-function-cbv-p fun)\n (list (funcall *build-libffi-definition* fun)))\n ,form))))))))", "macroexpand": "(progn (defun c-free (ptr) (let ((#:ptr209 ptr)) (declare (ignorable #:ptr209)) (cffi-sys:%foreign-funcall \"free\" (:pointer #:ptr209 :void) :convention :cdecl))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclass/std foo2 () ((bar baz)))\n\nWhat needs to change: Macro call that should be transformed by defclass/std", "input": "(defclass/std foo2 () ((bar baz)))", "output": "(defmacro defclass/std (name direct-superclasses direct-slots &rest options\n &environment env)\n \"Shortcut macro to the DEFCLASS macro.\n\n (defclass/std example ()\n ((slot1 slot2 slot3)))\n\n expands to:\n\n (DEFCLASS EXAMPLE ()\n ((SLOT1 :ACCESSOR SLOT1 :INITARG :SLOT1 :INITFORM NIL)\n (SLOT2 :ACCESSOR SLOT2 :INITARG :SLOT2 :INITFORM NIL)\n (SLOT3 :ACCESSOR SLOT3 :INITARG :SLOT3 :INITFORM NIL)))\n\n Each slot definition accepts options:\n\n :std 1 => changes the :initform to 1. It can be :unbound.\n :with or :with-prefix => creates accessors with the class name as prefix.\n\n See the README for more.\n\n See also `class/std' and `print-object/std'.\n \"\n `(defclass ,name ,direct-superclasses\n ,(process-slots env direct-slots name)\n ,@options))", "macroexpand": "(defclass foo2 nil ((bar :accessor bar :initarg :bar :initform nil) (baz :accessor baz :initarg :baz :initform nil)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(decf nil)\n\nProblem: Macro call that should be transformed by DECF", "input": "(decf nil)", "output": "(defmacro DECF ...)", "macroexpand": "(setq nil (sb-impl::xsubtract 1 nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect-file nil (progn))\n\nWhat needs to change: Macro call that should be transformed by COLLECT-FILE", "input": "(collect-file nil (progn))", "output": "(defmacro COLLECT-FILE ...)", "macroexpand": "(common-lisp:let* ((#:generator-551 (generator (progn)))\n #:items-545\n (#:out-547 t))\n (declare (type generator #:generator-551)\n (type boolean #:out-547))\n (with-open-file (#:outfile-544 nil :direction :output)\n (tagbody\n #:ll-552\n (setq #:items-545 (next-in #:generator-551 (go end)))\n (common-lisp:funcall #'print #:items-545 #:outfile-544)\n (go #:ll-552)\n end))\n #:out-547)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(form-fiddle:lambda-declarations `(lambda () ,@body))\n\nIssue: Macro call that should be transformed by for", "input": "(form-fiddle:lambda-declarations `(lambda () ,@body))", "output": "(defmacro for (&environment env bindings &body body)\n (let ((*environment* env))\n (multiple-value-bind (bind-init bind-forms bind-exit bind-post) (convert-bindings bindings)\n (multiple-value-bind (clause-init body-forms clause-exit) (convert-clauses body)\n `(with-interleaving\n ,@bind-init\n ,@clause-init\n (with-for-block ()\n (with-for-tagbody\n (progn ,@bind-forms\n ,@body-forms\n ,@bind-post)\n (return-for\n ,@clause-exit\n ,@bind-exit))))))))", "macroexpand": "(form-fiddle:lambda-declarations (sb-int:quasiquote (lambda nil #S(sb-impl::comma :expr body :kind 2))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder (:session :store (make-redis-store :namespace *namespace* :connection *connection* :expires 3)) (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session))))))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder (:session :store (make-redis-store :namespace *namespace* :connection *connection* :expires 3)) (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session))))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app242) (funcall (find-middleware :session) #:app242 :store (make-redis-store :namespace *namespace* :connection *connection* :expires 3))))) :initial-value (to-app (lambda (env) (unless (gethash :user (getf env :lack.session)) (setf (gethash :user (getf env :lack.session)) \"\u6df1\u753a\u82f1\u592a\u90ce\")) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (#S(sb-impl::comma :expr (format nil \"Hello, ~A! You've been here for ~Ath times!\" (gethash :user (getf env :lack.session)) (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-form-fields (name) form (print (field-value name)))\n\nIssue: Macro call that should be transformed by with-form-fields", "input": "(with-form-fields (name) form (print (field-value name)))", "output": "(defmacro with-form-fields (fields form &body body)\n \"Bind FIELDS to the form fields in FORM.\n\nExample:\n\n@lisp\n(with-form-fields (name) form\n (print (field-value name)))\n@end lisp\n\nAlso see: WITH-FORM-FIELD-VALUES \"\n `(let ,(loop for field in fields\n collect `(,field (get-field ,form ',field)))\n ,@body))", "macroexpand": "(let ((name (get-field form (quote name)))) (print (field-value name)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(augment-lexenv! :variable whole-var lexenv)\n\nPattern to recognize: Macro call that should be transformed by augment-lexenv!", "input": "(augment-lexenv! :variable whole-var lexenv)", "output": "(defmacro augment-lexenv! (kind name env &rest other-datum)\n `(setf ,env (augment-lexenv ,kind ,name ,env ,@other-datum)))", "macroexpand": "(setf lexenv (augment-lexenv :variable whole-var lexenv))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-error setq-type-match (:error-type varjo-critical-error) (var-name old-value new-value) \"Currently varjo cannot handle changing the type through a setq due to the static nature of glsl. var name: ~a type-of ~a: ~a type-of new-value: ~a\" var-name var-name (v-type-of old-value) (primary-type new-value))\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error setq-type-match (:error-type varjo-critical-error) (var-name old-value new-value) \"Currently varjo cannot handle changing the type through a setq due to the static nature of glsl. var name: ~a type-of ~a: ~a type-of new-value: ~a\" var-name var-name (v-type-of old-value) (primary-type new-value))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition setq-type-match (:error-type varjo-critical-error :prefix \"Varjo\") (var-name old-value new-value) \"Currently varjo cannot handle changing the type through a setq due to the static nature of glsl. var name: ~a type-of ~a: ~a type-of new-value: ~a\" var-name var-name (v-type-of old-value) (primary-type new-value))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-quasi-quoted-bivalent-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-SYNTAX", "input": "(enable-quasi-quoted-bivalent-syntax)", "output": "(defmacro ENABLE-QUASI-QUOTED-BIVALENT-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-bivalent-syntax-in-readtable :start-character nil\n :end-character nil\n :unquote-character #\\COMMA\n :splice-character\n #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP\n :transformation-pipeline nil\n :dispatched-quasi-quote-name\n \"biv\")\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-errno-symbol ERANGE)\n\nProblem: Macro call that should be transformed by define-errno-symbol", "input": "(define-errno-symbol ERANGE)", "output": "(defmacro define-errno-symbol (name)\n `(defparameter ,name\n (find-errno-symbol (string ',name))))", "macroexpand": "(defparameter erange (find-errno-symbol (string (quote erange))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Generate a defmacro form that transforms code like this:\n(defpattern cons (a b) (with-gensyms (it) `(guard1 (,it :type cons) (consp ,it) (car ,it) ,a (cdr ,it) ,b)))\n\nPattern to recognize: Macro call that should be transformed by defpattern", "input": "(defpattern cons (a b) (with-gensyms (it) `(guard1 (,it :type cons) (consp ,it) (car ,it) ,a (cdr ,it) ,b)))", "output": "(defmacro defpattern (name args &body body)\n \"Adds a new derived pattern.\nThe default value of &optional arguments are '_, instead of nil.\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (symbol-pattern ',name)\n #+sbcl\n (sb-int:named-lambda ',name ,(process-lambda-args args) ,@body)\n #-sbcl\n (lambda ,(process-lambda-args args) ,@body))\n ,@(when (stringp (first body))\n ;; lisp-namespace\n `((setf (documentation ',name 'pattern)\n ,(let ((*print-pretty* t))\n #-clisp\n (format nil \"~~\n ~:@_Defined in ~a~\n ~:>\"\n (list args (list (first body)) *compile-file-pathname*))\n #+clisp\n (format nil \"Lambda-List: ~s~%~a\"\n args (first body))))))))", "macroexpand": "(%defpattern cons (quote a) (quote b) (lambda (with-gensyms (it) (quasiquote (guard1 (#S(sb-impl::comma :expr it :kind 0) :type cons) (consp #S(sb-impl::comma :expr it :kind 0)) (car #S(sb-impl::comma :expr it :kind 0)) #S(sb-impl::comma :expr a :kind 0) (cdr #S(sb-impl::comma :expr it :kind 0)) #S(sb-impl::comma :expr b :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(aif (eval `(and ,(incf x) nil)) :never (list it x))\n\nIssue: Macro call that should be transformed by aif", "input": "(aif (eval `(and ,(incf x) nil)) :never (list it x))", "output": "(defmacro aif (test then &optional else)\n \"Like IF, except binds the result of the test to IT (via LET) for\nthe scope of the then and else expressions.\" \n `(anaphoric if ,test ,then ,else))", "macroexpand": "(anaphoric if (eval (sb-int:quasiquote (and #S(sb-impl::comma :expr (incf x) :kind 0) nil))) :never (list it x))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(caching-types\n nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by CACHING-TYPES", "input": "(caching-types\n nil\n (progn))", "output": "(defmacro CACHING-TYPES ...)", "macroexpand": "(call-with-disjoint-hash\n (lambda ()\n (call-with-subtype-hash\n (lambda ()\n (call-with-equiv-hash\n (lambda () (call-with-subtypep-cache (lambda () nil (progn)))))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(fnn nil nil)\n\nWhat needs to change: Macro call that should be transformed by FNN", "input": "(fnn nil nil)", "output": "(defmacro FNN ...)", "macroexpand": "(lambda () nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cond->\n nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by COND->", "input": "(cond->\n nil\n :key\n nil)", "output": "(defmacro COND-> ...)", "macroexpand": "(let* ((#:var131 nil)\n (#:var132\n (if :key\n (->\n #:var131)\n #:var131))\n (#:var133\n (if nil\n (->\n #:var132)\n #:var132)))\n #:var133)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ignore-errors nil)\n\nWhat needs to change: Macro call that should be transformed by IGNORE-ERRORS", "input": "(ignore-errors nil)", "output": "(defmacro IGNORE-ERRORS ...)", "macroexpand": "(handler-case (progn nil) (error (condition) (values nil condition)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(~> (-> :one () (increment)) (-> :two () (increment)) (-> :three () (increment)))\n\nWrite a macro that addresses: Macro call that should be transformed by ~>", "input": "(~> (-> :one () (increment)) (-> :two () (increment)) (-> :three () (increment)))", "output": "(defmacro ~> (&rest body)\n \"See flow:concurrently\"\n `(concurrently ,@body))", "macroexpand": "(concurrently (-> :one nil (increment)) (-> :two nil (increment)) (-> :three nil (increment)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error cannot-compile () (code) \"Cannot compile the following code:~%~a\" code)\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error cannot-compile () (code) \"Cannot compile the following code:~%~a\" code)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition cannot-compile (:error-type varjo-error :prefix \"Varjo\") (code) \"Cannot compile the following code:~%~a\" code)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(some-<>> 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by SOME-<>>", "input": "(some-<>> 'some-name)", "output": "(defmacro SOME-<>> ...)", "macroexpand": "(let* ((#:g134 'some-name))\n #:g134)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(gatherlet nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by GATHERLET", "input": "(gatherlet nil\n :key\n nil)", "output": "(defmacro GATHERLET ...)", "macroexpand": "(common-lisp:let ()\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(make-obsolete mustache-version version \"0.10.0\")\n\nWrite a macro that addresses: Macro call that should be transformed by make-obsolete", "input": "(make-obsolete mustache-version version \"0.10.0\")", "output": "(defmacro make-obsolete (obsolete-name current-name when)\n `(defun ,obsolete-name (&rest args)\n ,(documentation current-name 'function)\n (warn 'deprecation-warning\n :name ',obsolete-name :replacement ',current-name :since ,when)\n (apply ',current-name args)))", "macroexpand": "(defun mustache-version (&rest args) #A((31) base-char . \"Return the CL-MUSTACHE version.\") (warn (quote deprecation-warning) :name (quote mustache-version) :replacement (quote version) :since \"0.10.0\") (apply (quote version) args))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(secase (car x) (:y :no))\n\nWrite a macro that addresses: Macro call that should be transformed by secase", "input": "(secase (car x) (:y :no))", "output": "(defmacro secase (keyform &body cases)\n \"Like ECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for the\nscope of the cases. IT can be set with SETF.\"\n `(symbolic ecase ,keyform ,@cases))", "macroexpand": "(symbolic ecase (car x) (:y :no))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do+ (for x (across #(1 2 3 4) :index index)) (for k (in '(a b c d e))) (returning (list x k :index index)))\n\nWrite a macro that addresses: Macro call that should be transformed by do+", "input": "(do+ (for x (across #(1 2 3 4) :index index)) (for k (in '(a b c d e))) (returning (list x k :index index)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (across #(1 2 3 4) :index index)) (for k (in (quote (a b c d e)))) (returning (list x k :index index)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with* nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by WITH*", "input": "(with* nil\n :key\n nil)", "output": "(defmacro WITH* ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-direct-binding unless (var test sub-binding &rest args) (multiple-value-bind (init body value) (apply (binding sub-binding) var args) (values init `(unless ,test ,body) value)))\n\nIssue: Macro call that should be transformed by define-direct-binding", "input": "(define-direct-binding unless (var test sub-binding &rest args) (multiple-value-bind (init body value) (apply (binding sub-binding) var args) (values init `(unless ,test ,body) value)))", "output": "(defmacro define-direct-binding (name args &body body)\n (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym \"ENVIRONMENT\"))))\n `(progn (setf (binding ',name)\n (lambda ,(lambda-fiddle:remove-environment-part args)\n (let ((,env *environment*))\n (declare (ignorable ,env))\n ,@body)))\n ',name)))", "macroexpand": "(progn (setf (binding (quote unless)) (lambda (var test sub-binding &rest args) (let ((#:environment126 *environment*)) (declare (ignorable #:environment126)) (multiple-value-bind (init body value) (apply (binding sub-binding) var args) (values init (sb-int:quasiquote (unless #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr body :kind 0))) value))))) (quote unless))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defreadtable pax:macro)\n\nProblem: Macro call that should be transformed by defreadtable", "input": "(defreadtable pax:macro)", "output": "(defmacro defreadtable (name &body options)\n \"Define a new named readtable, whose name is given by the symbol NAME.\n Or, if a readtable is already registered under that name, redefine\n that one.\n\n The readtable can be populated using the following OPTIONS:\n\n - If the first element of OPTIONS is a string then it is associated\n with the readtable as in `(SETF (DOCUMENTATION NAME 'READTABLE)\n DOCSTRING)`.\n\n - `(:MERGE READTABLE-DESIGNATORS+)`\n\n Merge the macro character definitions from the readtables\n designated into the new readtable being defined as per\n MERGE-READTABLES-INTO. The copied options are\n :DISPATCH-MACRO-CHAR, :MACRO-CHAR and :SYNTAX-FROM, but not\n READTABLE-CASE.\n\n If no :MERGE clause is given, an empty readtable is used. See\n MAKE-READTABLE.\n\n - `(:FUSE READTABLE-DESIGNATORS+)`\n\n Like :MERGE except:\n\n Error conditions of type READER-MACRO-CONFLICT that are signaled\n during the merge operation will be silently _continued_. It\n follows that reader macros in earlier entries will be\n overwritten by later ones. For backward compatibility, :FUZE is\n accepted as an alias of :FUSE.\n\n - `(:DISPATCH-MACRO-CHAR MACRO-CHAR SUB-CHAR FUNCTION)`\n\n Define a new sub character `SUB-CHAR` for the dispatching macro\n character `MACRO-CHAR`, per SET-DISPATCH-MACRO-CHARACTER. You\n probably have to define `MACRO-CHAR` as a dispatching macro\n character by the following option first.\n\n - `(:MACRO-CHAR MACRO-CHAR FUNCTION [NON-TERMINATING-P])`\n\n Define a new macro character in the readtable, per\n SET-MACRO-CHARACTER. If [FUNCTION][pax:argument] is the keyword\n :DISPATCH, `MACRO-CHAR` is made a dispatching macro character,\n per MAKE-DISPATCH-MACRO-CHARACTER.\n\n - `(:SYNTAX-FROM FROM-READTABLE-DESIGNATOR FROM-CHAR TO-CHAR)`\n\n Set the character syntax of TO-CHAR in the readtable being\n defined to the same syntax as FROM-CHAR as per\n SET-SYNTAX-FROM-CHAR.\n\n - `(:CASE CASE-MODE)`\n\n Defines the _case sensitivity mode_ of the resulting readtable.\n\n Any number of option clauses may appear. The options are grouped by\n their type, but in each group the order the options appeared\n textually is preserved. The following groups exist and are executed\n in the following order: :MERGE and :FUSE (one group), :CASE,\n :MACRO-CHAR and :DISPATCH-MACRO-CHAR (one group), finally\n :SYNTAX-FROM.\n\n Notes:\n\n The readtable is defined at load-time. If you want to have it\n available at compilation time -- say to use its reader-macros in the\n same file as its definition -- you have to wrap the DEFREADTABLE\n form in an explicit EVAL-WHEN.\n\n On redefinition, the target readtable is made empty first before\n it's refilled according to the clauses.\n\n NIL, :STANDARD, :COMMON-LISP, :MODERN, and :CURRENT are\n preregistered readtable names.\"\n (check-type name symbol)\n (when (reserved-readtable-name-p name)\n (error \"~A is the designator for a predefined readtable. ~\n Not acceptable as a user-specified readtable name.\" name))\n (flet ((process-option (option var)\n (destructure-case option\n ((:merge &rest readtable-designators)\n\t `(merge-readtables-into ,var ,@(mapcar #'(lambda (x) `',x)\n readtable-designators)))\n ((:fuse &rest readtable-designators)\n\t `(handler-bind ((reader-macro-conflict #'continue))\n (merge-readtables-into ,var ,@(mapcar #'(lambda (x) `',x)\n readtable-designators))))\n ;; alias for :FUSE\n ((:fuze &rest readtable-designators)\n\t `(handler-bind ((reader-macro-conflict #'continue))\n (merge-readtables-into ,var ,@(mapcar #'(lambda (x) `',x)\n readtable-designators))))\n ((:dispatch-macro-char disp-char sub-char function)\n `(set-dispatch-macro-character ,disp-char ,sub-char\n ,function ,var))\n ((:macro-char char function &optional non-terminating-p)\n\t (if (eq function :dispatch)\n\t\t `(make-dispatch-macro-character ,char ,non-terminating-p ,var)\n\t\t `(set-macro-character ,char ,function\n ,non-terminating-p ,var)))\n\t ((:syntax-from from-rt-designator from-char to-char)\n\t `(set-syntax-from-char ,to-char ,from-char\n\t\t\t\t ,var (find-readtable ,from-rt-designator)))\n\t ((:case mode)\n\t `(setf (readtable-case ,var) ,mode))))\n\t (remove-clauses (clauses options)\n\t (setq clauses (if (listp clauses) clauses (list clauses)))\n\t (remove-if-not #'(lambda (x) (member x clauses))\n\t\t\t options :key #'first)))\n (let* ((docstring (when (stringp (first options))\n (pop options)))\n (merge-clauses (remove-clauses '(:merge :fuze :fuse) options))\n\t (case-clauses (remove-clauses :case options))\n\t (macro-clauses (remove-clauses '(:macro-char :dispatch-macro-char)\n options))\n\t (syntax-clauses (remove-clauses :syntax-from options))\n\t (other-clauses\n (set-difference options\n (append merge-clauses case-clauses\n macro-clauses syntax-clauses)))\n (%dummy (gensym \"SOURCE-LOCATION-DUMMY\")))\n (cond\n\t((not (null other-clauses))\n\t (error \"Bogus DEFREADTABLE clauses: ~/PPRINT-LINEAR/\" other-clauses))\n\t(t\n\t `(eval-when (:load-toplevel :execute)\n ;; The (FIND-READTABLE ...) is important for proper\n ;; redefinition semantics, as redefining has to modify the\n ;; already existing readtable object.\n (let ((readtable (find-readtable ',name)))\n (cond ((not readtable)\n (setq readtable (make-readtable ',name)))\n (t\n (setq readtable (%clear-readtable readtable))\n (simple-style-warn\n \"Overwriting already existing readtable ~S.\"\n readtable)))\n (setf (documentation readtable 'readtable) ,docstring)\n (defun ,%dummy ())\n (%associate-dummy-with-readtable readtable ',%dummy)\n ,@(loop for option in merge-clauses\n collect (process-option option 'readtable))\n ,@(loop for option in case-clauses\n collect (process-option option 'readtable))\n ,@(loop for option in macro-clauses\n collect (process-option option 'readtable))\n ,@(loop for option in syntax-clauses\n collect (process-option option 'readtable))\n readtable)))))))", "macroexpand": "(eval-when (:load-toplevel :execute) (let ((readtable (find-readtable (quote mgl-pax:macro)))) (cond ((not readtable) (setq readtable (make-readtable (quote mgl-pax:macro)))) (t (setq readtable (%clear-readtable readtable)) (simple-style-warn \"Overwriting already existing readtable ~S.\" readtable))) (setf (documentation readtable (quote readtable)) nil) (defun #:source-location-dummy150 nil) (%associate-dummy-with-readtable readtable (quote #:source-location-dummy150)) readtable))", "category": "anaphoric", "technique": "gensym,reader,anaphor", "complexity": "advanced", "quality_score": 0.8099999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-dot-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-DOT-SYNTAX", "input": "(enable-dot-syntax)", "output": "(defmacro enable-dot-syntax ()\n \"Enable reader syntax.\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (%enable-dot-syntax)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (%enable-dot-syntax))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-unique-names (repeat) `(block nil (tagbody ,repeat ,@*body* (go ,repeat))))\n\nProblem: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (repeat) `(block nil (tagbody ,repeat ,@*body* (go ,repeat))))", "output": "(defmacro with-unique-names (names &body body)\n `(let ,(mapcar (lambda (sym)\n `(,sym (gensym ,(symbol-name sym))))\n names)\n ,@body))", "macroexpand": "(let ((repeat (gensym #A((6) base-char . \"REPEAT\")))) (quasiquote (block nil (tagbody #S(sb-impl::comma :expr repeat :kind 0) #S(sb-impl::comma :expr *body* :kind 2) (go #S(sb-impl::comma :expr repeat :kind 0))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-flow-function-macro (body-fu lambda-list body) `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts))\n\nPattern to recognize: Macro call that should be transformed by with-flow-function-macro", "input": "(with-flow-function-macro (body-fu lambda-list body) `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts))", "output": "(defmacro with-flow-function-macro ((fu-name fu-lambda-list fu-body) &body body)\n `(with-gensyms (,fu-name)\n `(%with-flow-function (,,fu-name ,,fu-lambda-list ,@,fu-body)\n ,,@body)))", "macroexpand": "(with-gensyms (body-fu) (sb-int:quasiquote (%with-flow-function (#S(sb-impl::comma :expr body-fu :kind 0) #S(sb-impl::comma :expr lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)) #S(sb-impl::comma :expr (sb-int:quasiquote (dispatch-atomically #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr body-fu :kind 0)) #S(sb-impl::comma :expr invariant :kind 0) #S(sb-impl::comma :expr opts :kind 2))) :kind 0))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-input-from-file (input from :element-type element-type) (with-output-to-file (output to :element-type element-type :if-exists if-to-exists) (copy-stream input output :element-type element-type :finish-output finish-output)))\n\nIssue: Macro call that should be transformed by with-input-from-file", "input": "(with-input-from-file (input from :element-type element-type) (with-output-to-file (output to :element-type element-type :if-exists if-to-exists) (copy-stream input output :element-type element-type :finish-output finish-output)))", "output": "(defmacro with-input-from-file ((stream-name file-name &rest args\n &key (direction nil direction-p)\n &allow-other-keys)\n &body body)\n \"Evaluate BODY with STREAM-NAME to an input stream on the file\nFILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT,\nwhich is only sent to WITH-OPEN-FILE when it's not NIL.\"\n (declare (ignore direction))\n (when direction-p\n (error \"Can't specify :DIRECTION for WITH-INPUT-FROM-FILE.\"))\n `(with-open-file* (,stream-name ,file-name :direction :input ,@args)\n ,@body))", "macroexpand": "(with-open-file* (input from :direction :input :element-type element-type) (with-output-to-file (output to :element-type element-type :if-exists if-to-exists) (copy-stream input output :element-type element-type :finish-output finish-output)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda-ignoring-_ (_kwd exp) (expand-toplevel-const-exp exp))\n\nWhat needs to change: Macro call that should be transformed by lambda-ignoring-_", "input": "(lambda-ignoring-_ (_kwd exp) (expand-toplevel-const-exp exp))", "output": "(defmacro lambda-ignoring-_ (lambda-list &body body)\n \"Works like `cl:lambda' macro except automatically `declare's\n `ignore' for parameters beginning with '_' character.\"\n (let ((ignored-parameters\n (collect-_-symbol-in-lambda-list lambda-list)))\n (unless ignored-parameters\n (warn \"No ignored parameters in: ~A\" lambda-list))\n (multiple-value-bind (body decls doc)\n (parse-body body :documentation t)\n `(lambda ,lambda-list\n ,@ (if doc `(,doc))\n (declare (ignore ,@ignored-parameters))\n ,@decls\n ,@body))))", "macroexpand": "(lambda (_kwd exp) (declare (ignore _kwd)) (expand-toplevel-const-exp exp))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(deferror \"55\" object-state-error)\n\nPattern to recognize: Macro call that should be transformed by deferror", "input": "(deferror \"55\" object-state-error)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition object-state-error (database-error) nil) (setf (gethash \"55\" *error-table*) (quote object-state-error)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(->> nil)\n\nIssue: Macro call that should be transformed by ->>", "input": "(->> nil)", "output": "(defmacro ->> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-neo4j-fun get-relationship-property (relationship-id property) :get (:uri-spec (format nil \"relationship/~A/properties/~A\" relationship-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:status-handlers (200 (decode-neo4j-json-output body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'property-not-found-error :uri uri))))\n\nIssue: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-relationship-property (relationship-id property) :get (:uri-spec (format nil \"relationship/~A/properties/~A\" relationship-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:status-handlers (200 (decode-neo4j-json-output body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'property-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-relationship-property (&key relationship-id property) (let ((uri (format nil \"relationship/~A/properties/~A\" relationship-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))) (list 404 (lambda (body uri json) (error (quote property-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ignore-errors nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by IGNORE-ERRORS", "input": "(ignore-errors nil :key nil)", "output": "(defmacro IGNORE-ERRORS ...)", "macroexpand": "(handler-case (progn nil :key nil) (error (condition) (values nil condition)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-error invalid-shader-stage () (stage) \"Sorry but '~a' is not a valid shader stage\" stage)\n\nPattern to recognize: Macro call that should be transformed by define-error", "input": "(define-error invalid-shader-stage () (stage) \"Sorry but '~a' is not a valid shader stage\" stage)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition invalid-shader-stage (:error-type varjo-error :prefix \"Varjo\") (stage) \"Sorry but '~a' is not a valid shader stage\" stage)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-html-string (:li :class (progn nil)))\n\nIssue: Macro call that should be transformed by with-html", "input": "(with-html-string (:li :class (progn nil)))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:li :class (progn nil))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun/1 fabs (x) (abs x))\n\nIssue: Macro call that should be transformed by defun/1", "input": "(defun/1 fabs (x) (abs x))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun fabs (x) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (abs x)) (defparameter fabs (vacietis.c:mkptr& (symbol-function (quote fabs)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-neo4j-fun get-relationships-types () :get (:uri-spec \"relationship/types\") (:status-handlers (200 (decode-neo4j-json-output body))))\n\nIssue: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-relationships-types () :get (:uri-spec \"relationship/types\") (:status-handlers (200 (decode-neo4j-json-output body))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-relationships-types (&key) (let ((uri \"relationship/types\") (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when-let ((x 2) (y x)) (+ x y))\n\nWhat needs to change: Macro call that should be transformed by when-let", "input": "(when-let ((x 2) (y x)) (+ x y))", "output": "(defmacro when-let (bindings &body forms)\n \"Creates new variable bindings, and conditionally executes FORMS.\n\nBINDINGS must be either single binding of the form:\n\n (variable initial-form)\n\nor a list of bindings of the form:\n\n ((variable-1 initial-form-1)\n (variable-2 initial-form-2)\n ...\n (variable-n initial-form-n))\n\nAll initial-forms are executed sequentially in the specified order. Then all\nthe variables are bound to the corresponding values.\n\nIf all variables were bound to true values, then FORMS are executed as an\nimplicit PROGN.\"\n (let* ((binding-list (if (and (consp bindings) (symbolp (car bindings)))\n (list bindings)\n bindings))\n (variables (mapcar #'car binding-list)))\n `(let ,binding-list\n (when (and ,@variables)\n ,@forms))))", "macroexpand": "(let ((x 2) (y x)) (when (and x y) (+ x y)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-dot nil\n (progn))\n\nProblem: Macro call that should be transformed by WITH-DOT", "input": "(with-dot nil\n (progn))", "output": "(defmacro with-dot (() &body body)\n `(progn ,@(replace-dot-calls body)))", "macroexpand": "(progn (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-definition-resolver ir1-convert (designator) (sb-int:info :function :ir1-convert designator))\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver ir1-convert (designator) (sb-int:info :function :ir1-convert designator))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver ir1-convert (ir1-convert #:package151) (when (ignore-errors (let ((designator ir1-convert)) (sb-int:info :function :ir1-convert designator))) (list (make-instance (quote ir1-convert) :designator ir1-convert :package #:package151))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(mapping nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by MAPPING", "input": "(mapping nil :key nil)", "output": "(defmacro MAPPING ...)", "macroexpand": "(mapping-mac nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (plusp result))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (plusp result))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:v172 result)) (if (plusp #:v172) (add-result (quote test-passed) :test-expr (quote (plusp result))) (process-failure (quote (plusp result)) \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\" (quote result) #:v172 (quote plusp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(unwind-protect nil\n nil)\n\nProblem: Macro call that should be transformed by UNWIND-PROTECT", "input": "(unwind-protect nil\n nil)", "output": "(defmacro UNWIND-PROTECT ...)", "macroexpand": "(common-lisp:unwind-protect nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-hash nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-HASH", "input": "(collect-hash nil :key nil)", "output": "(defmacro COLLECT-HASH ...)", "macroexpand": "(common-lisp:let* ((#:out-160 (make-hash-table nil)))\n (common-lisp:let ((#:generator-164 (generator :key))\n #:values-156\n (#:generator-162 (generator nil))\n #:keys-155)\n (declare (type generator #:generator-164)\n (type generator #:generator-162))\n (tagbody\n #:ll-165\n (setq #:values-156 (next-in #:generator-164 (go end)))\n (setq #:keys-155 (next-in #:generator-162 (go end)))\n (setf (gethash #:keys-155 #:out-160) #:values-156)\n (go #:ll-165)\n end)\n #:out-160))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(js 'some-name)\n\nIssue: Macro call that should be transformed by JS", "input": "(js 'some-name)", "output": "(defmacro JS ...)", "macroexpand": "(ps\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(check-cursor-attached cluffer:insert-item (cursor item))\n\nWrite a macro that addresses: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:insert-item (cursor item))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:insert-item :before ((cursor cluffer:cursor) item) (declare (ignore item)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<>>\n nil\n (progn))\n\nProblem: Macro call that should be transformed by -<>>", "input": "(-<>>\n nil\n (progn))", "output": "(defmacro -<>> ...)", "macroexpand": "(let* ((#:var122 nil) (#:var123 (progn #:var122)))\n #:var123)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(gathering nil\n nil)\n\nProblem: Macro call that should be transformed by GATHERING", "input": "(gathering nil\n nil)", "output": "(defmacro GATHERING ...)", "macroexpand": "(common-lisp:let ()\n nil\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(letrec-syntax common-lisp:nil common-lisp:nil)\n\nProblem: Macro call that should be transformed by LETREC-SYNTAX", "input": "(letrec-syntax common-lisp:nil common-lisp:nil)", "output": "(defmacro LETREC-SYNTAX ...)", "macroexpand": "(common-lisp:macrolet ()\n common-lisp:nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-element-maker :textarea \"textArea\" '(:x :y :width :height))\n\nWhat needs to change: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :textarea \"textArea\" '(:x :y :width :height))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :textarea)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:x :y :width :height)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :textarea missing))))) (defmethod make-svg-element ((element (eql :textarea)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"textArea\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-alias-binding collect collecting)\n\nProblem: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding collect collecting)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote collect)) (quote collecting)) (quote collect))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-wcs-math-error-handling ((quotient remainder) (round x y)) (check-wcs-math-result) (values (coerce remainder 'double-float) (coerce quotient 'double-float)))\n\nWhat needs to change: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling ((quotient remainder) (round x y)) (check-wcs-math-result) (values (coerce remainder 'double-float) (coerce quotient 'double-float)))", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g260 x) (#:g261 y) (#:g262 (list #:g260 #:g261))) (declare (ignorable #:g261) (type list #:g262) (dynamic-extent #:g262)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (quotient remainder) (call-with-wcs-math-error-handler (quote round) #:g262) (flet ((check-wcs-math-result (&optional (ret quotient) (arg-list #:g262)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result) (values (coerce remainder (quote double-float)) (coerce quotient (quote double-float)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when spec --indent (format stream \"~&~a~a:\" indent spec) ++indent)\n\nIssue: Macro call that should be transformed by when", "input": "(when spec --indent (format stream \"~&~a~a:\" indent spec) ++indent)", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if spec (progn --indent (format stream \"~&~a~a:\" indent spec) ++indent))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(builder (:auth/basic :authenticator (lambda (user pass) (declare (ignore user pass)) t)) *app*)\n\nProblem: Macro call that should be transformed by builder", "input": "(builder (:auth/basic :authenticator (lambda (user pass) (declare (ignore user pass)) t)) *app*)", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app176) (funcall (find-middleware :auth/basic) #:app176 :authenticator (lambda (user pass) (declare (ignore user pass)) t))))) :initial-value (to-app *app*) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error flow-id-must-be-specified-vv (:error-type varjo-critical-error) () \"v-values must be given a flow id when created\")\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error flow-id-must-be-specified-vv (:error-type varjo-critical-error) () \"v-values must be given a flow id when created\")", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition flow-id-must-be-specified-vv (:error-type varjo-critical-error :prefix \"Varjo\") nil \"v-values must be given a flow id when created\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(unwind-protect-case () (random 10) (:always (push :always result)) (:normal (push :normal result)) (:abort (push :abort result)))\n\nIssue: Macro call that should be transformed by unwind-protect-case", "input": "(unwind-protect-case () (random 10) (:always (push :always result)) (:normal (push :normal result)) (:abort (push :abort result)))", "output": "(defmacro unwind-protect-case ((&optional abort-flag) protected-form &body clauses)\n \"Like CL:UNWIND-PROTECT, but you can specify the circumstances that\nthe cleanup CLAUSES are run.\n\n clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*\n\nClauses can be given in any order, and more than one clause can be\ngiven for each circumstance. The clauses whose denoted circumstance\noccured, are executed in the order the clauses appear.\n\nABORT-FLAG is the name of a variable that will be bound to T in\nCLAUSES if the PROTECTED-FORM aborted preemptively, and to NIL\notherwise.\n\nExamples:\n\n (unwind-protect-case ()\n (protected-form)\n (:normal (format t \\\"This is only evaluated if PROTECTED-FORM executed normally.~%\\\"))\n (:abort (format t \\\"This is only evaluated if PROTECTED-FORM aborted preemptively.~%\\\"))\n (:always (format t \\\"This is evaluated in either case.~%\\\")))\n\n (unwind-protect-case (aborted-p)\n (protected-form)\n (:always (perform-cleanup-if aborted-p)))\n\"\n (check-type abort-flag (or null symbol))\n (let ((gflag (gensym \"FLAG+\")))\n `(let ((,gflag t))\n (unwind-protect (multiple-value-prog1 ,protected-form (setf ,gflag nil))\n\t (let ,(and abort-flag `((,abort-flag ,gflag)))\n\t ,@(loop for (cleanup-kind . forms) in clauses\n\t\t collect (ecase cleanup-kind\n\t\t\t (:normal `(when (not ,gflag) ,@forms))\n\t\t\t (:abort `(when ,gflag ,@forms))\n\t\t\t (:always `(progn ,@forms)))))))))", "macroexpand": "(let ((#:flag+124 t)) (unwind-protect (multiple-value-prog1 (random 10) (setf #:flag+124 nil)) (let nil (progn (push :always result)) (when (not #:flag+124) (push :normal result)) (when #:flag+124 (push :abort result)))))", "category": "control-flow", "technique": "gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-preprocessor-state-slots (state) (loop for i = (first token-list) while token-list until (eq i +newline-marker+) do (pop token-list) collect i))\n\nWrite a macro that addresses: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (loop for i = (first token-list) while token-list until (eq i +newline-marker+) do (pop token-list) collect i))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (loop for i = (first token-list) while token-list until (eq i +newline-marker+) do (pop token-list) collect i))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-packages-unlocked nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-PACKAGES-UNLOCKED", "input": "(with-packages-unlocked nil)", "output": "(defmacro WITH-PACKAGES-UNLOCKED ...)", "macroexpand": "(let ((#:|packages120| (locked-packages 'nil)))\n (unlock-packages #:|packages120|)\n (unwind-protect (lock-packages #:|packages120|)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(fgather-next nil (progn))\n\nProblem: Macro call that should be transformed by FGATHER-NEXT", "input": "(fgather-next nil (progn))", "output": "(defmacro FGATHER-NEXT ...)", "macroexpand": "(nil (progn) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun nil ())\n\nProblem: Macro call that should be transformed by DEFUN", "input": "(defun nil ())", "output": "(defmacro DEFUN ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel) (sb-c:%compiler-defun 'nil t nil nil))\n (sb-impl::%defun 'nil\n (sb-int:named-lambda nil\n nil\n (block nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(destructuring-bind () (progn))\n\nIssue: Macro call that should be transformed by DESTRUCTURING-BIND", "input": "(destructuring-bind () (progn))", "output": "(defmacro DESTRUCTURING-BIND ...)", "macroexpand": "(sb-int:binding* ((nil (sb-c::check-ds-list (progn) 0 0 'nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do-generator (item generator) (push (funcall function item) result))\n\nIssue: Macro call that should be transformed by do-generator", "input": "(do-generator (item generator) (push (funcall function item) result))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g169 generator)) (loop do (if-generator ((item) #:g169) (progn (push (funcall function item) result)) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(and nil (progn))\n\nProblem: Macro call that should be transformed by AND", "input": "(and nil (progn))", "output": "(defmacro AND ...)", "macroexpand": "(if nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(->)\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(->)", "output": "(defmacro -> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(letrec (x) x)\n\nIssue: Macro call that should be transformed by letrec", "input": "(letrec (x) x)", "output": "(defmacro letrec ((&rest bindings) &body body)\n \"Recursive LET.\nThe idea is that functions created in BINDINGS can close over one\nanother, and themselves.\n\nNote that `letrec' only binds variables: it can define recursive\nfunctions, but can't bind them as functions. (But see `fbindrec'.)\"\n `(letrec-with psetq ,bindings\n ,@body))", "macroexpand": "(letrec-with psetq (x) x)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-table-name nil (yield (else-op-var op)))\n\nPattern to recognize: Macro call that should be transformed by with-table-name", "input": "(with-table-name nil (yield (else-op-var op)))", "output": "(defmacro with-table-name (table-name &body body)\n `(let ((*table-name-scope* ,table-name))\n ,@body))", "macroexpand": "(let ((*table-name-scope* nil)) (yield (else-op-var op)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-package (package) (do-symbols (symbol package) (when (eql (symbol-package symbol) package) (when (fboundp symbol) (fmakunbound symbol)) (when (boundp symbol) (makunbound symbol)))) (delete-package package))\n\nIssue: Macro call that should be transformed by with-package", "input": "(with-package (package) (do-symbols (symbol package) (when (eql (symbol-package symbol) package) (when (fboundp symbol) (fmakunbound symbol)) (when (boundp symbol) (makunbound symbol)))) (delete-package package))", "output": "(defmacro with-package ((var &optional (package var)) &body body)\n `(let ((,var (ensure-package ,package)))\n ,@body))", "macroexpand": "(let ((package (ensure-package package))) (do-symbols (symbol package) (when (eql (symbol-package symbol) package) (when (fboundp symbol) (fmakunbound symbol)) (when (boundp symbol) (makunbound symbol)))) (delete-package package))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(without-trailing-space (funcall body))\n\nWrite a macro that addresses: Macro call that should be transformed by without-trailing-space", "input": "(without-trailing-space (funcall body))", "output": "(defmacro without-trailing-space (&body body)\n (with-thunk (body)\n `(call-without-trailing-space ,body)))", "macroexpand": "(flet ((#:stack-fn-body1 nil (funcall body))) (declare (dynamic-extent (function #:stack-fn-body1))) (symbol-macrolet ((#:stack-fn-body1 (function #:stack-fn-body1))) (call-without-trailing-space #:stack-fn-body1)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n;; format with constant control strings interprets directives at runtime\n(format nil \"Value: ~a, Name: ~a\" val name)\n;; Every call: parse the ~a directives, resolve them, dispatch formatting\n;; The format string is known at compile time but still interpreted at runtime\n\nPattern to recognize: format with compile-time-constant control strings wastes time interpreting directives at runtime \u2014 want compile-time compilation of format strings", "input": ";; format with constant control strings interprets directives at runtime\n(format nil \"Value: ~a, Name: ~a\" val name)\n;; Every call: parse the ~a directives, resolve them, dispatch formatting\n;; The format string is known at compile time but still interpreted at runtime", "output": "(defun fformat (&rest all)\n (apply #'format all))\n\n(define-compiler-macro fformat\n (&whole form\n stream fmt &rest args)\n (if (constantp fmt)\n (if stream\n `(funcall (formatter ,fmt)\n ,stream ,@args)\n (let ((g!stream (gensym \"stream\")))\n `(with-output-to-string (,g!stream)\n (funcall (formatter ,fmt)\n ,g!stream ,@args))))\n form))", "macroexpand": ";; (fformat t \"Value: ~a, Name: ~a\" val name)\n;; Compiler macro sees constant fmt, expands to:\n;; (FUNCALL (FORMATTER \"Value: ~a, Name: ~a\") T VAL NAME)\n;;\n;; formatter macro-expands the control string into direct\n;; write-string, princ, etc. calls - no runtime parsing.\n;;\n;; When fmt is NOT constant: returns original form unchanged.\n;; Graceful degradation - always correct, sometimes faster.", "category": "compiler-macro", "technique": "compiler-macro,gensym", "complexity": "intermediate", "quality_score": 0.97} {"instruction": "Generate a defmacro form that transforms code like this:\n(make-instance* 'class () (when something (list :a a)))\n\nPattern to recognize: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class () (when something (list :a a)))", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(apply (function make-instance) (quote class) (when something (list :a a)))", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9624999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-iterators ((it sequence :from-end from-end :start start :end end)) (setf result (if initp initial-value (funcall key (with-iter-value (value it) value)))) (setf resultp t) (if from-end (do-iter-values ((item it)) (setf result (funcall f (funcall key item) result))) (do-iter-values ((item it)) (setf result (funcall f result (funcall key item))))))\n\nPattern to recognize: Macro call that should be transformed by with-iterators", "input": "(with-iterators ((it sequence :from-end from-end :start start :end end)) (setf result (if initp initial-value (funcall key (with-iter-value (value it) value)))) (setf resultp t) (if from-end (do-iter-values ((item it)) (setf result (funcall f (funcall key item) result))) (do-iter-values ((item it)) (setf result (funcall f result (funcall key item))))))", "output": "(defmacro with-iterators (seqs &body forms &environment env)\n \"Create static iterators for one or more sequence.\n\n This macro attempts to determine the type of each sequence, and calls\n MAKE-DOSEQ to generate optimal static iterator code for the given\n sequence types, rather than creating dynamic iterator objects.\n\n SEQS:\n\n A list where each element is of the form (ITER SEQUENCE . ARGS)\n where ITER is a symbol identifying the iterator for the sequence,\n SEQUENCE is the form which evaluates to a sequence, and ARGS are\n the remaining iteration arguments, interpreted as they are to the\n ITERATOR function.\n\n Each iterator identifier (ITER) can be passed to\n WITH-ITER-VALUE, within the body forms of WITH-ITERATORS, to\n retrieve the values of the elements of the sequence.\n\n The iterator identifiers are in a namespace of their own that is\n they do not name lexical variables/symbol-macros nor functions/macros.\n\n\n FORMS:\n\n A list of forms evaluated in an implicit TAGBODY, thus symbols\n are interpreted as tag names.\n\n The WITH-ITER-VALUE macro can be used, within FORMS, to retrieve\n the current element of the sequence and advance the iterator to\n the next position.\n\n The WITH-ITER-PLACE macro can be used, within FORMS, both to\n retrieve and set the value of the current element of the\n sequence, and advance the iterator to the next position.\n\n NOTE: The value of the last form is not returned, due to it being\n evaluated in a TAGBODY, instead NIL is returned. RETURN-FROM, to\n an outer BLOCK, should be used to return a value from this form.\n\n NOTE: Whilst the intended use of WITH-ITERATORS is to implement\n iteration macros, such as DOSEQ, the FORMS are only evaluated\n once. It is up to the user to implement the actual loop, using\n the provided TAGBODY facility.\"\n\n (with-gensyms (end-tag)\n (labels ((expand-doseq (seq args body env)\n (-> (nth-form-type seq env)\n (make-doseq seq args end-tag body env)\n multiple-value-list))\n\n (make-form (bindings get-values places body)\n (->> (make-macros get-values places body)\n (make-bindings bindings)))\n\n (make-macros (get-values places body)\n `(symbol-macrolet\n ((iter-value-macros\n ,(append get-values (iter-value-macros env)))\n\n (iter-place-macros\n ,(append places (iter-place-macros env))))\n\n ,@body))\n\n ;; Tagbody\n\n (make-tagbody (body)\n `((tagbody\n ,@body\n ,end-tag)))\n\n\n ;; Bindings\n\n (make-bindings (bindings body)\n (loop\n for binding in bindings\n for (init constant?) = (multiple-value-list (make-binding binding))\n if constant? collect init into constants\n else collect init into vars\n finally\n (return\n `(symbol-macrolet ,constants\n (let* ,vars ,body)))))\n\n (make-binding (binding)\n (destructuring-bind (var init &key constant) binding\n (if constant\n (multiple-value-bind (value constant?)\n (constant-form-value init env)\n\n (values\n `(,var ,value)\n constant?))\n\n (values\n `(,var ,init)\n nil)))))\n\n (loop\n for (var seq . args) in seqs\n for (bindings body value place) =\n (expand-doseq seq args (make-tagbody forms) env) then\n (expand-doseq seq args form-body env)\n\n for iter-value = (gensym \"ITER-VALUE\")\n for iter-place = (gensym \"ITER-PLACE\")\n for form-body = `((macrolet ((,iter-value ,@value)\n (,iter-place\n ,@(or place\n `((&rest args)\n (declare (ignore args))\n (error \"In WITH-ITER-PLACE: Iterator ~s points to immutable sequence.\" ',var)))))\n ,@body))\n\n append bindings into all-bindings\n collect (cons var iter-value) into get-values\n collect (cons var iter-place) into places\n\n finally\n (return\n (make-form all-bindings get-values places form-body))))))", "macroexpand": "(symbol-macrolet nil (let* ((#:it161 (iterator sequence :from-end from-end :start start :end end))) (symbol-macrolet ((iter-value-macros ((it . #:iter-value162))) (iter-place-macros ((it . #:iter-place163)))) (macrolet ((#:iter-value162 (pattern &body body) (symbol-macrolet ((it (quote #:it161)) (tag (quote #:end-tag146))) (with-destructure-pattern (var pattern) (body decl body) (sb-int:quasiquote (progn (when (endp #S(sb-impl::comma :expr it :kind 0)) (go #S(sb-impl::comma :expr tag :kind 0))) (let ((#S(sb-impl::comma :expr var :kind 0) (at #S(sb-impl::comma :expr it :kind 0)))) #S(sb-impl::comma :expr decl :kind 2) (advance #S(sb-impl::comma :expr it :kind 0)) #S(sb-impl::comma :expr body :kind 2))))))) (#:iter-place163 (name more? &body body) (symbol-macrolet ((it (quote #:it161)) (tag (quote #:end-tag146))) (let ((body (sb-int:quasiquote (prog1 (progn #S(sb-impl::comma :expr body :kind 2)) (advance #S(sb-impl::comma :expr it :kind 0)))))) (with-variable-declarations ((decl-name name) (decl-more? more?)) forms body (sb-int:quasiquote (symbol-macrolet ((#S(sb-impl::comma :expr name :kind 0) (at #S(sb-impl::comma :expr it :kind 0)))) #S(sb-impl::comma :expr decl-name :kind 2) #S(sb-impl::comma :expr (if more? (sb-int:quasiquote (let ((#S(sb-impl::comma :expr more? :kind 0) (not (endp #S(sb-impl::comma :expr it :kind 0))))) #S(sb-impl::comma :expr decl-more? :kind 2) #S(sb-impl::comma :expr forms :kind 0))) (sb-int:quasiquote (progn (when (endp #S(sb-impl::comma :expr it :kind 0)) (go #S(sb-impl::comma :expr tag :kind 0))) #S(sb-impl::comma :expr forms :kind 0)))) :kind 0)))))))) (tagbody (setf result (if initp initial-value (funcall key (with-iter-value (value it) value)))) (setf resultp t) (if from-end (do-iter-values ((item it)) (setf result (funcall f (funcall key item) result))) (do-iter-values ((item it)) (setf result (funcall f result (funcall key item))))) #:end-tag146)))))", "category": "anaphoric", "technique": "symbol-macrolet,macrolet,gensym,anaphor", "complexity": "advanced", "quality_score": 0.895} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-connection (let ((user (retrieve-one (select :* (from :user) (where (:= :name \"nitro_idiot\")))))) (is user `(:id 1 :name \"nitro_idiot\" :email \"e.arrows@gmail.com\" :status \"normal\" :created-at ,(princ-to-string *now*) :updated-at nil))))\n\nWhat needs to change: Macro call that should be transformed by with-connection", "input": "(with-connection (let ((user (retrieve-one (select :* (from :user) (where (:= :name \"nitro_idiot\")))))) (is user `(:id 1 :name \"nitro_idiot\" :email \"e.arrows@gmail.com\" :status \"normal\" :created-at ,(princ-to-string *now*) :updated-at nil))))", "output": "(defmacro with-connection (&body body)\n `(let ((*connection* (connect-cached :sqlite3 :database-name *db-path*)))\n ,@body))", "macroexpand": "(let ((let (connect ((user (retrieve-one (select :* (from :user) (where (:= :name \"nitro_idiot\")))))) (is user (sb-int:quasiquote (:id 1 :name \"nitro_idiot\" :email \"e.arrows@gmail.com\" :status \"normal\" :created-at #S(sb-impl::comma :expr (princ-to-string *now*) :kind 0) :updated-at nil)))))) (unwind-protect (progn) (disconnect let)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-hamt dict (:test test :hash hash :table table) (flet ((%remove (table key) (%hamt-remove table key (funcall hash key) 0 test))) (make-instance 'hash-dict :test test :hash hash :table (reduce #'%remove keys :initial-value table))))\n\nWhat needs to change: Macro call that should be transformed by with-hamt", "input": "(with-hamt dict (:test test :hash hash :table table) (flet ((%remove (table key) (%hamt-remove table key (funcall hash key) 0 test))) (make-instance 'hash-dict :test test :hash hash :table (reduce #'%remove keys :initial-value table))))", "output": "(defmacro with-hamt (hamt (&key test hash table) &body body)\n \"Accessing HAMT slots\"\n `(with-accessors ((,test hamt-test)\n (,hash hamt-hash)\n (,table hamt-table))\n ,hamt\n ,@body))", "macroexpand": "(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) dict (flet ((%remove (table key) (%hamt-remove table key (funcall hash key) 0 test))) (make-instance (quote hash-dict) :test test :hash hash :table (reduce (function %remove) keys :initial-value table))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(destructuring-bind* nil\n (progn))\n\nProblem: Macro call that should be transformed by DESTRUCTURING-BIND*", "input": "(destructuring-bind* nil\n (progn))", "output": "(defmacro DESTRUCTURING-BIND* ...)", "macroexpand": "(let (#:in-body130)\n (flet ((#:handle131 (#:condition132)\n (unless #:in-body130\n (error\n (make-condition 'destructuring-error :lambda-list 'nil\n :expression '(progn) :reason #:condition132)))))\n (declare (ignorable (function #:handle131)))\n (let ((#:value133 (progn)))\n (handler-bind ((error #'#:handle131))\n (destructuring-bind () #:value133 (setf #:in-body130 t) (locally))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(set-dynamic nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by SET-DYNAMIC", "input": "(set-dynamic nil (progn))", "output": "(defmacro SET-DYNAMIC ...)", "macroexpand": "(setf (dynamic (progn)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(actypecase :foo (string (list :string it)) (keyword (list :keyword it)) (symbol (list :symbol it)))\n\nIssue: Macro call that should be transformed by actypecase", "input": "(actypecase :foo (string (list :string it)) (keyword (list :keyword it)) (symbol (list :symbol it)))", "output": "(defmacro actypecase (keyform &body cases)\n \"Like CTYPECASE, except binds the result of the keyform to IT (via LET) for\nthe scope of the cases. Unlike CTYPECASE, new values possible stored by the\nSTORE-VALUE restart are not received by the keyform/place, but by IT.\"\n `(anaphoric ctypecase ,keyform ,@cases))", "macroexpand": "(anaphoric ctypecase :foo (string (list :string it)) (keyword (list :keyword it)) (symbol (list :symbol it)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:<= infix-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:<= infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (<=-op (:include infix-op (name \"<=\")) (:constructor make-<=-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-api find-readtable (name) (named-readtable-designator => (or readtable null)) \"Looks for the readtable specified by NAME and returns it if it is found. Returns NIL otherwise.\" (cond ((readtablep name) name) ((reserved-readtable-name-p name) (find-reserved-readtable name)) ((%find-readtable name))))\n\nProblem: Macro call that should be transformed by define-api", "input": "(define-api find-readtable (name) (named-readtable-designator => (or readtable null)) \"Looks for the readtable specified by NAME and returns it if it is found. Returns NIL otherwise.\" (cond ((readtablep name) name) ((reserved-readtable-name-p name) (find-reserved-readtable name)) ((%find-readtable name))))", "output": "(defmacro define-api (name lambda-list type-list &body body)\n (flet ((parse-type-list (type-list)\n (let ((pos (position '=> type-list)))\n (assert pos () \"You forgot to specify return type (`=>' missing.)\")\n (values (subseq type-list 0 pos)\n `(values ,@(nthcdr (1+ pos) type-list) &optional)))))\n (multiple-value-bind (body decls docstring)\n (parse-body body :documentation t :whole `(define-api ,name))\n (multiple-value-bind (arg-typespec value-typespec)\n (parse-type-list type-list)\n (multiple-value-bind (reqs opts rest keys)\n (parse-ordinary-lambda-list lambda-list)\n (declare (ignorable reqs opts rest keys))\n `(progn\n (declaim (ftype (function ,arg-typespec ,value-typespec) ,name))\n (locally\n ;; Muffle the annoying \"&OPTIONAL and &KEY found in\n ;; the same lambda list\" style-warning\n #+sbcl (declare (sb-ext:muffle-conditions style-warning))\n (defun ,name ,lambda-list\n ,docstring\n ,@decls\n (locally\n #+sbcl (declare (sb-ext:unmuffle-conditions style-warning))\n\n ;; SBCL will interpret the ftype declaration as\n ;; assertion and will insert type checks for us.\n #-sbcl\n (progn\n ;; CHECK-TYPE required parameters\n ,@(loop for req-arg in reqs\n for req-type = (pop type-list)\n do (assert req-type)\n collect `(check-type ,req-arg ,req-type))\n\n ;; CHECK-TYPE optional parameters\n ,@(progn\n (assert (or (null opts)\n (eq (pop type-list) '&optional)))\n (loop for (opt-arg . nil) in opts\n for opt-type = (pop type-list)\n do (assert opt-type)\n collect `(check-type ,opt-arg ,opt-type)))\n\n ;; CHECK-TYPE rest parameter\n ,@(when rest\n (assert (eq (pop type-list) '&rest))\n (let ((rest-type (pop type-list)))\n (assert rest-type)\n `((dolist (x ,rest)\n (check-type x ,rest-type)))))\n\n ;; CHECK-TYPE key parameters\n ,@(progn\n (assert (or (null keys)\n (eq (pop type-list) '&key)))\n (loop for ((keyword key-arg) . nil) in keys\n for (nil key-type) = (find keyword type-list\n :key #'car)\n collect `(check-type ,key-arg ,key-type))))\n\n ,@body)))))))))", "macroexpand": "(progn (declaim (ftype (function (named-readtable-designator) (values (or readtable null) &optional)) find-readtable)) (locally (declare (sb-ext:muffle-conditions style-warning)) (defun find-readtable (name) \"Looks for the readtable specified by NAME and returns it if it is found. Returns NIL otherwise.\" (locally (declare (sb-ext:unmuffle-conditions style-warning)) (cond ((readtablep name) name) ((reserved-readtable-name-p name) (find-reserved-readtable name)) ((%find-readtable name)))))))", "category": "efficiency", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-launched-iter nil\n nil)\n\nProblem: Macro call that should be transformed by DEF-LAUNCHED-ITER", "input": "(def-launched-iter nil\n nil)", "output": "(defmacro DEF-LAUNCHED-ITER ...)", "macroexpand": "(defun nil ()\n (let ((it (make-instance 'iterator :coro (lambda-coro))))\n (inext-or-error it)\n it))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-value-binding on (var list &key (by NIL by-p)) (declare (type list list)) `(cond (,list ,(if by-p `(progn (update ,var ,list) (setf ,list (funcall ,by ,list))) `(progn (update ,var ,list) (setf ,list (cdr ,list))))) (T (end-for))))\n\nProblem: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding on (var list &key (by NIL by-p)) (declare (type list list)) `(cond (,list ,(if by-p `(progn (update ,var ,list) (setf ,list (funcall ,by ,list))) `(progn (update ,var ,list) (setf ,list (cdr ,list))))) (T (end-for))))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding on (var list &key (by nil by-p)) (let ((#:list137 (gensym #A((4) base-char . \"LIST\"))) (#:by138 (gensym #A((2) base-char . \"BY\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:list137 list) (list #:by138 by) (loop for #:var136 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var136 nil))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:list137 :kind 0) #S(sb-impl::comma :expr #:by138 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote list) :kind 0) #S(sb-impl::comma :expr #:list137 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((list #:list137) (by #:by138)) (declare (ignorable list by)) (sb-int:quasiquote (cond (#S(sb-impl::comma :expr list :kind 0) #S(sb-impl::comma :expr (if by-p (sb-int:quasiquote (progn (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr list :kind 0)) (setf #S(sb-impl::comma :expr list :kind 0) (funcall #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr list :kind 0))))) (sb-int:quasiquote (progn (update #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr list :kind 0)) (setf #S(sb-impl::comma :expr list :kind 0) (cdr #S(sb-impl::comma :expr list :kind 0)))))) :kind 0)) (t (end-for))))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(mvlet* nil)\n\nPattern to recognize: Macro call that should be transformed by MVLET*", "input": "(mvlet* nil)", "output": "(defmacro MVLET* ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-trace-sql (with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (setf query (execute-with-retry query binds)) (query-row-count query)))\n\nIssue: Macro call that should be transformed by with-trace-sql", "input": "(with-trace-sql (with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (setf query (execute-with-retry query binds)) (query-row-count query)))", "output": "(defmacro with-trace-sql (&body body)\n `(let ((dbi:*sql-execution-hooks* (cons #'trace-sql\n dbi:*sql-execution-hooks*)))\n ,@body))", "macroexpand": "(let ((*sql-execution-hooks* (cons (function trace-sql) *sql-execution-hooks*))) (with-prepared-query query (*connection* sql :use-prepare-cached *use-prepare-cached*) (setf query (execute-with-retry query binds)) (query-row-count query)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time cps-convert-block (name body continuation types value? environment) (let* ((c (gensym \"CONTINUATION-\")) (*block-tags* (cons (list name c types value?) *block-tags*))) (possibly-beta-reduce-funcall `#'(lambda (,c) (declare (magic)) ,(cps-convert-progn body c types value? environment)) '() continuation t)))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time cps-convert-block (name body continuation types value? environment) (let* ((c (gensym \"CONTINUATION-\")) (*block-tags* (cons (list name c types value?) *block-tags*))) (possibly-beta-reduce-funcall `#'(lambda (,c) (declare (magic)) ,(cps-convert-progn body c types value? environment)) '() continuation t)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun cps-convert-block (name body continuation types value? environment) (let* ((c (gensym \"CONTINUATION-\")) (*block-tags* (cons (list name c types value?) *block-tags*))) (possibly-beta-reduce-funcall (sb-int:quasiquote (function (lambda (#S(sb-impl::comma :expr c :kind 0)) (declare (magic)) #S(sb-impl::comma :expr (cps-convert-progn body c types value? environment) :kind 0)))) (quote nil) continuation t))) (eval-when (:compile-toplevel) (compile (quote cps-convert-block))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(dletf nil)\n\nIssue: Macro call that should be transformed by DLETF", "input": "(dletf nil)", "output": "(defmacro DLETF ...)", "macroexpand": "(special-symbol-progv (with-symbol-access\n (list))\n (list)\n (locally (declare (special))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error invalid-symbol-macro-form () (name form) \"Symbol macros must expand to a list or atom form : ~s -> ~s~%\" name form)\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error invalid-symbol-macro-form () (name form) \"Symbol macros must expand to a list or atom form : ~s -> ~s~%\" name form)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition invalid-symbol-macro-form (:error-type varjo-error :prefix \"Varjo\") (name form) \"Symbol macros must expand to a list or atom form : ~s -> ~s~%\" name form)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-dynenv-fun nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEF-DYNENV-FUN", "input": "(def-dynenv-fun nil\n :key\n nil)", "output": "(defmacro DEF-DYNENV-FUN ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defun nil (&rest #:args) (apply (dynenv-function nil) #:args))\n (defvar #:nil145 (lambda :key nil))\n (setf (get 'nil 'dynenv-fun) '#:nil145))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(acond ((+ 2 2) (setf foo 38) (incf foo it) foo) (t nil))\n\nPattern to recognize: Macro call that should be transformed by acond", "input": "(acond ((+ 2 2) (setf foo 38) (incf foo it) foo) (t nil))", "output": "(defmacro acond (&body clauses)\n \"Like COND, except result of each test-form is bound to IT (via LET) for the\nscope of the corresponding clause.\"\n (labels ((rec (clauses)\n\t (if clauses\n\t\t (destructuring-bind ((test &body body) . rest) clauses\n\t\t (if body\n\t\t `(anaphoric if ,test (progn ,@body) ,(rec rest))\n\t\t `(anaphoric if ,test it ,(rec rest))))\n\t\t nil)))\n (rec clauses)))", "macroexpand": "(let ((#:it (+ 2 2))) (if #:it (let ((it #:it)) (declare (ignorable it)) (setf foo 38) (incf foo it) foo) (acond (t nil))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is (= (* 2 a) (dummy-add a a)))\n\nProblem: Macro call that should be transformed by is", "input": "(is (= (* 2 a) (dummy-add a a)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e164 (* 2 a)) (#:a165 (dummy-add a a))) (if (progn (= #:e164 #:a165)) (add-result (quote test-passed) :test-expr (quote (= (* 2 a) (dummy-add a a)))) (process-failure (quote (= (* 2 a) (dummy-add a a))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (dummy-add a a)) #:a165 (quote =) #:e164)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-error assigning-to-readonly () (var-name) \"Assignment failed as ~a is readonly\" var-name)\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error assigning-to-readonly () (var-name) \"Assignment failed as ~a is readonly\" var-name)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition assigning-to-readonly (:error-type varjo-error :prefix \"Varjo\") (var-name) \"Assignment failed as ~a is readonly\" var-name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (cdr head) (cons 'progn (cdr head)))\n\nProblem: Macro call that should be transformed by when", "input": "(when (cdr head) (cons 'progn (cdr head)))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (cdr head) (cons (quote progn) (cdr head)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when nil (progn))\n\nIssue: Macro call that should be transformed by WHEN", "input": "(when nil (progn))", "output": "(defmacro WHEN ...)", "macroexpand": "(if nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(rem-bops nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by REM-BOPS", "input": "(rem-bops nil nil)", "output": "(defmacro REM-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn (save-binfix) (mapc 'rmbop '(nil nil)) (assign-properties)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(%destructure-defhook-args args (with-effective-qualifier generic-function qualifier (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list ,@body))))\n\nWrite a macro that addresses: Macro call that should be transformed by %destructure-defhook-args", "input": "(%destructure-defhook-args args (with-effective-qualifier generic-function qualifier (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list ,@body))))", "output": "(defmacro %destructure-defhook-args (args &body body)\n (let ((args-sym (gensym)))\n `(let* ((,args-sym ,args)\n (qualifier\n (cond ((and (symbolp (car ,args-sym)) (not (null (car ,args-sym))))\n (prog1 (car ,args-sym) (setf ,args-sym (cdr ,args-sym))))\n (t :use-default))))\n (destructuring-bind (specialized-lambda-list &body body) ,args-sym\n ,@body))))", "macroexpand": "(let* ((#:g123 args) (qualifier (cond ((and (symbolp (car #:g123)) (not (null (car #:g123)))) (prog1 (car #:g123) (setf #:g123 (cdr #:g123)))) (t :use-default)))) (destructuring-bind (specialized-lambda-list &body body) #:g123 (with-effective-qualifier generic-function qualifier (destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (sb-int:quasiquote (%lay-method-base-for-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2)))))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time walk-go (map-function form) (unless (null (rest (last form))) (error \"Improper GO: ~S\" form)) (unless (= (length form) 2) (error \"GO must have one argument: ~S\" form)) (unless (or (symbolp (second form)) (integerp (second form))) (error \"TAG of GO must be a symbol or integer: ~S\" form)) (funcall map-function form 'go))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-go (map-function form) (unless (null (rest (last form))) (error \"Improper GO: ~S\" form)) (unless (= (length form) 2) (error \"GO must have one argument: ~S\" form)) (unless (or (symbolp (second form)) (integerp (second form))) (error \"TAG of GO must be a symbol or integer: ~S\" form)) (funcall map-function form 'go))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-go (map-function form) (unless (null (rest (last form))) (error \"Improper GO: ~S\" form)) (unless (= (length form) 2) (error \"GO must have one argument: ~S\" form)) (unless (or (symbolp (second form)) (integerp (second form))) (error \"TAG of GO must be a symbol or integer: ~S\" form)) (funcall map-function form (quote go))) (eval-when (:compile-toplevel) (compile (quote walk-go))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(draw scene (:image :x 10 :y 10 :height 600 :width 600 :xlink-href img-url))\n\nProblem: Macro call that should be transformed by draw", "input": "(draw scene (:image :x 10 :y 10 :height 600 :width 600 :xlink-href img-url))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g155 (funcall (function make-svg-element) :image (append (list :x 10 :y 10 :height 600 :width 600 :xlink-href img-url) (list))))) (add-element scene #:g155) #:g155)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(mvlet* ((low high (sort-values #'< start stop)) (in-order? (eql low start)) (element-type (if in-order? `(integer ,low (,high)) `(integer (,low) ,high))) (len (ceiling (abs (- high low)) (abs step)))) (values len element-type))\n\nWhat needs to change: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((low high (sort-values #'< start stop)) (in-order? (eql low start)) (element-type (if in-order? `(integer ,low (,high)) `(integer (,low) ,high))) (len (ceiling (abs (- high low)) (abs step)))) (values len element-type))", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(multiple-value-bind (low high) (sort-values (function <) start stop) (mvlet* ((in-order? (eql low start)) (element-type (if in-order? (sb-int:quasiquote (integer #S(sb-impl::comma :expr low :kind 0) (#S(sb-impl::comma :expr high :kind 0)))) (sb-int:quasiquote (integer (#S(sb-impl::comma :expr low :kind 0)) #S(sb-impl::comma :expr high :kind 0))))) (len (ceiling (abs (- high low)) (abs step)))) (values len element-type)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(c? (if (value bypass-lookup?) 'no-lookup (bwhen-c-stored (v :bar store 'nothing) (value v))))\n\nWrite a macro that addresses: Macro call that should be transformed by c?", "input": "(c? (if (value bypass-lookup?) 'no-lookup (bwhen-c-stored (v :bar store 'nothing) (value v))))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((if (value bypass-lookup?) (quote no-lookup) (bwhen-c-stored (v :bar store (quote nothing)) (value v))))) :value-state :unevaluated :rule (c-lambda (if (value bypass-lookup?) (quote no-lookup) (bwhen-c-stored (v :bar store (quote nothing)) (value v)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defgenerator repeat (item &optional n) \"Returns a single item indefinitely, or up to n times.\" (if n (dotimes (i n) (yield item)) (loop do (yield item))))\n\nWrite a macro that addresses: Macro call that should be transformed by defgenerator", "input": "(defgenerator repeat (item &optional n) \"Returns a single item indefinitely, or up to n times.\" (if n (dotimes (i n) (yield item)) (loop do (yield item))))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun repeat (item &optional n) \"Returns a single item indefinitely, or up to n times.\" (with-yield (if n (dotimes (i n) (yield item)) (loop do (yield item)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n;; Common pattern: test a value, use result in then-branch\n(let ((result (compute-something)))\n (if result\n (format t \"Got: ~a~%\" result)\n :nothing))\n\n;; Want: implicit 'it' bound to test result\n\nPattern to recognize: Repeated pattern of binding test result then branching on it \u2014 want implicit 'it' anaphor", "input": ";; Common pattern: test a value, use result in then-branch\n(let ((result (compute-something)))\n (if result\n (format t \"Got: ~a~%\" result)\n :nothing))\n\n;; Want: implicit 'it' bound to test result", "output": "(defmacro aif (test then &optional else)\n `(let ((it ,test))\n (if it ,then ,else)))", "macroexpand": ";; (aif (compute-something)\n;; (format t \"Got: ~a~%\" it)\n;; :nothing)\n;; Expands to:\n;; (LET ((IT (COMPUTE-SOMETHING)))\n;; (IF IT\n;; (FORMAT T \"Got: ~a~%\" IT)\n;; :NOTHING))", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-let nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-LET", "input": "(dynamic-let nil\n (progn))", "output": "(defmacro DYNAMIC-LET ...)", "macroexpand": "(let ()\n (dynamic-wind\n :proceed\n #:g194\n (let ()\n (declare (special))\n (#:g194 (progn)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-easy-macro nil\n (progn))\n\nIssue: Macro call that should be transformed by DEF-EASY-MACRO", "input": "(def-easy-macro nil\n (progn))", "output": "(defmacro DEF-EASY-MACRO ...)", "macroexpand": "(progn\n (defun call-nil (#:|fn127| progn)\n (flet ((#:|fn127| (&rest args) (declare (inline)) (apply #:|fn127| args)))))\n (defmacro nil ((&rest fn-arg-values) &body macro-body)\n nil\n (build-funcall 'call-nil '(progn) fn-arg-values macro-body)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-definition-resolver class designator-class-p)\n\nWhat needs to change: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver class designator-class-p)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver class (class #:package137) (when (ignore-errors (designator-class-p class)) (list (make-instance (quote class) :designator class :package #:package137))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defpattern nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by DEFPATTERN", "input": "(defpattern nil\n :key\n nil)", "output": "(defmacro DEFPATTERN ...)", "macroexpand": "(eval-always\n (setf (get 'nil 'cl-match-pattern)\n (lambda (#:g133)\n (lett :key\n #:g133\n nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-ps-symbol-macro nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-PS-SYMBOL-MACRO", "input": "(define-ps-symbol-macro nil nil)", "output": "(defmacro DEFINE-PS-SYMBOL-MACRO ...)", "macroexpand": "(progn\n nil\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash 'nil *symbol-macro-toplevel*)\n (lambda (form) (declare (ignore form)) 'nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-rewrite cddaar (expr) `(cdr (cdaar ,(second expr))))\n\nIssue: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cddaar (expr) `(cdr (cdaar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cddaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cdaar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lambda+ nil)\n\nProblem: Macro call that should be transformed by LAMBDA+", "input": "(lambda+ nil)", "output": "(defmacro LAMBDA+ ...)", "macroexpand": "(lambda () (let+ nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(reduced-typecase nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by REDUCED-TYPECASE", "input": "(reduced-typecase nil nil)", "output": "(defmacro REDUCED-TYPECASE ...)", "macroexpand": "(typecase nil (nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-special-initargs nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by WITH-SPECIAL-INITARGS", "input": "(with-special-initargs nil\n nil)", "output": "(defmacro WITH-SPECIAL-INITARGS ...)", "macroexpand": "(funcall-with-special-initargs (list) (lambda () nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(list-of nil)\n\nProblem: Macro call that should be transformed by LIST-OF", "input": "(list-of nil)", "output": "(defmacro LIST-OF ...)", "macroexpand": "(lc (nil) collect)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-yield-binds (with-output-to-string (s) (write-string (yield (column-definition-clause-column-name clause)) s) (when (column-definition-clause-type clause) (let ((*use-placeholder* nil)) (format s \" ~A\" (yield (column-definition-clause-type clause))))) (when (column-definition-clause-not-null clause) (write-string \" NOT NULL\" s)) (when (column-definition-clause-default clause) (format s \" DEFAULT ~A\" (yield (column-definition-clause-default clause)))) (when (column-definition-clause-auto-increment clause) (write-string \" AUTO_INCREMENT\" s)) (when (column-definition-clause-unique clause) (write-string \" UNIQUE\" s)) (when (column-definition-clause-primary-key clause) (write-string \" PRIMARY KEY\" s)) (when (and (column-definition-clause-autoincrement clause) (not (column-definition-clause-auto-increment clause))) (write-string \" AUTOINCREMENT\" s))))\n\nPattern to recognize: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (with-output-to-string (s) (write-string (yield (column-definition-clause-column-name clause)) s) (when (column-definition-clause-type clause) (let ((*use-placeholder* nil)) (format s \" ~A\" (yield (column-definition-clause-type clause))))) (when (column-definition-clause-not-null clause) (write-string \" NOT NULL\" s)) (when (column-definition-clause-default clause) (format s \" DEFAULT ~A\" (yield (column-definition-clause-default clause)))) (when (column-definition-clause-auto-increment clause) (write-string \" AUTO_INCREMENT\" s)) (when (column-definition-clause-unique clause) (write-string \" UNIQUE\" s)) (when (column-definition-clause-primary-key clause) (write-string \" PRIMARY KEY\" s)) (when (and (column-definition-clause-autoincrement clause) (not (column-definition-clause-auto-increment clause))) (write-string \" AUTOINCREMENT\" s))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (with-output-to-string (s) (write-string (yield (column-definition-clause-column-name clause)) s) (when (column-definition-clause-type clause) (let ((*use-placeholder* nil)) (format s \" ~A\" (yield (column-definition-clause-type clause))))) (when (column-definition-clause-not-null clause) (write-string \" NOT NULL\" s)) (when (column-definition-clause-default clause) (format s \" DEFAULT ~A\" (yield (column-definition-clause-default clause)))) (when (column-definition-clause-auto-increment clause) (write-string \" AUTO_INCREMENT\" s)) (when (column-definition-clause-unique clause) (write-string \" UNIQUE\" s)) (when (column-definition-clause-primary-key clause) (write-string \" PRIMARY KEY\" s)) (when (and (column-definition-clause-autoincrement clause) (not (column-definition-clause-auto-increment clause))) (write-string \" AUTOINCREMENT\" s)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(-<>> 'some-name)\n\nPattern to recognize: Macro call that should be transformed by -<>>", "input": "(-<>> 'some-name)", "output": "(defmacro -<>> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defmethod* nil nil)\n\nPattern to recognize: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil nil)", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(let* ((#:nil125 (ensure-generic*-function 'nil))\n (temp-method (defmethod #:nil124 nil))\n (actual-gf\n (ensure-generic*-function 'nil :lambda-list\n (sb-mop:generic-function-lambda-list\n (symbol-function '#:nil124))\n :special-variables 'nil))\n (actual-method\n (add-method* #:nil125\n (make-instance 'method* :special-variables (list)\n :qualifiers 'nil :specializers\n (sb-mop:method-specializers temp-method)\n :lambda-list\n (sb-mop:method-lambda-list temp-method)\n :documentation\n (documentation temp-method t) :function\n (sb-mop:method-function temp-method)))))\n (declare (ignorable #:nil125)\n (ignore actual-gf))\n (setf (documentation actual-method t) (documentation temp-method t))\n actual-method)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(letrec nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by LETREC", "input": "(letrec nil\n :key\n nil)", "output": "(defmacro LETREC ...)", "macroexpand": "(let ()\n (flet ()\n nil\n (setf)\n :key\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"42P06\" duplicate-schema syntax-error-or-access-violation)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"42P06\" duplicate-schema syntax-error-or-access-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition duplicate-schema (syntax-error-or-access-violation) nil) (setf (gethash \"42P06\" *error-table*) (quote duplicate-schema)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-prepared-query query (conn (format nil \"SELECT currval(pg_get_serial_sequence('~A', '~A')) AS last_insert_id\" table-name serial-key-name)) (or (first (dbi:fetch (dbi:execute query) :format :values)) 0))\n\nIssue: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (conn (format nil \"SELECT currval(pg_get_serial_sequence('~A', '~A')) AS last_insert_id\" table-name serial-key-name)) (or (first (dbi:fetch (dbi:execute query) :format :values)) 0))", "output": "(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)\n `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))", "macroexpand": "(call-with-prepared-query conn (format nil \"SELECT currval(pg_get_serial_sequence('~A', '~A')) AS last_insert_id\" table-name serial-key-name) (lambda (query) (or (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)) 0)) :use-prepare-cached nil)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-function nth 2 (new-val nth obj) (replace-nth nth obj new-val))\n\nPattern to recognize: Macro call that should be transformed by define-modf-function", "input": "(define-modf-function nth 2 (new-val nth obj) (replace-nth nth obj new-val))", "output": "(defmacro define-modf-function (name nth-arg (new-val &rest args) &body body)\n \"Define a new modf function. It inverts NAME forms by modifying the NTH-ARG\nterm of the arguments of the place form in the MODF macro.\"\n ;; Side effect in a macro, I know. How can you do this via EVAL-WHEN if I\n ;; want it to run even if not a toplevel macro?\n (setf (gethash name *modf-nth-arg*)\n nth-arg)\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-nth-arg*)\n ,nth-arg))\n (defun ,(intern (modf-name name) :modf) (,new-val ,@args)\n ,@body)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote nth) *modf-nth-arg*) 2)) (defun |BUILDER:COMMON-LISP:NTH| (new-val nth obj) (replace-nth nth obj new-val)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (eql (top-info) 'aref) (format stream \")\"))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (eql (top-info) 'aref) (format stream \")\"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql (top-info) (quote aref)) (format stream \")\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(some-<>>\n nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by SOME-<>>", "input": "(some-<>>\n nil\n :key\n nil)", "output": "(defmacro SOME-<>> ...)", "macroexpand": "(let* ((#:var145 nil)\n (#:var146\n (if #:var145\n (:key #:var145)\n nil))\n (#:var147\n (if #:var146\n (nil #:var146)\n nil)))\n #:var147)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-declaration nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFINE-DECLARATION", "input": "(define-declaration nil\n (progn))", "output": "(defmacro DEFINE-DECLARATION ...)", "macroexpand": "(sb-cltl2:define-declaration nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-compile-time get-function-record (function-name) (or (gethash function-name *function-record-table*) (setf (gethash function-name *function-record-table*) (make-function-record :function-name function-name))))\n\nWhat needs to change: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time get-function-record (function-name) (or (gethash function-name *function-record-table*) (setf (gethash function-name *function-record-table*) (make-function-record :function-name function-name))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun get-function-record (function-name) (or (gethash function-name *function-record-table*) (setf (gethash function-name *function-record-table*) (make-function-record :function-name function-name)))) (eval-when (:compile-toplevel) (compile (quote get-function-record))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n;; Macro with double-evaluation bug\n(defmacro square (x)\n `(* ,x ,x))\n;; (square (incf y)) evaluates (incf y) TWICE\n\n;; Manual fix requires gensym + let boilerplate every time\n(defmacro square (x)\n (let ((g (gensym)))\n `(let ((,g ,x))\n (* ,g ,g))))\n\nProblem: Macro arguments evaluated multiple times (double evaluation) \u2014 need automatic once-only that also provides both original form and evaluated value", "input": ";; Macro with double-evaluation bug\n(defmacro square (x)\n `(* ,x ,x))\n;; (square (incf y)) evaluates (incf y) TWICE\n\n;; Manual fix requires gensym + let boilerplate every time\n(defmacro square (x)\n (let ((g (gensym)))\n `(let ((,g ,x))\n (* ,g ,g))))", "output": "(defun o!-symbol-p (s)\n (and (symbolp s)\n (> (length (symbol-name s)) 2)\n (string= (symbol-name s)\n \"O!\"\n :start1 0\n :end1 2)))\n\n(defun o!-symbol-to-g!-symbol (s)\n (symb \"G!\"\n (subseq (symbol-name s) 2)))\n\n(defmacro defmacro! (name args &rest body)\n (let* ((os (remove-if-not #'o!-symbol-p (flatten args)))\n (gs (mapcar #'o!-symbol-to-g!-symbol os)))\n (multiple-value-bind (body declarations docstring)\n (parse-body body :documentation t)\n `(defmacro/g! ,name ,args\n ,@(when docstring\n (list docstring))\n ,@declarations\n `(let ,(mapcar #'list (list ,@gs) (list ,@os))\n ,(progn ,@body))))))", "macroexpand": ";; (defmacro! square (o!x)\n;; `(* ,g!x ,g!x))\n;;\n;; (macroexpand '(square (incf y)))\n;; => (LET ((#:X1633 (INCF Y)))\n;; (* #:X1633 #:X1633))\n;;\n;; o!x = original form (still accessible via ',o!x)\n;; g!x = evaluated value, bound once", "category": "capture-management", "technique": "once-only,gensym", "complexity": "advanced", "quality_score": 0.9624999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defgeneric* nil (progn))\n\nIssue: Macro call that should be transformed by DEFGENERIC*", "input": "(defgeneric* nil (progn))", "output": "(defmacro DEFGENERIC* ...)", "macroexpand": "(ensure-generic*-function 'nil :name 'nil :lambda-list '(progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(make-obsolete mustache-context make-context \"0.10.0\")\n\nWrite a macro that addresses: Macro call that should be transformed by make-obsolete", "input": "(make-obsolete mustache-context make-context \"0.10.0\")", "output": "(defmacro make-obsolete (obsolete-name current-name when)\n `(defun ,obsolete-name (&rest args)\n ,(documentation current-name 'function)\n (warn 'deprecation-warning\n :name ',obsolete-name :replacement ',current-name :since ,when)\n (apply ',current-name args)))", "macroexpand": "(defun mustache-context (&rest args) #A((40) base-char . \"Create mustache context from alist DATA.\") (warn (quote deprecation-warning) :name (quote mustache-context) :replacement (quote make-context) :since \"0.10.0\") (apply (quote make-context) args))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-generator (a b (with-yield (dolist (x data) (yield x (1+ x))))) a (return b))\n\nWhat needs to change: Macro call that should be transformed by do-generator", "input": "(do-generator (a b (with-yield (dolist (x data) (yield x (1+ x))))) a (return b))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g171 (with-yield (dolist (x data) (yield x (1+ x)))))) (loop do (if-generator ((a b) #:g171) (progn a (return b)) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-c-syntax-reader-for-each-case-mode c-reader-level-0)\n\nWhat needs to change: Macro call that should be transformed by define-c-syntax-reader-for-each-case-mode", "input": "(define-c-syntax-reader-for-each-case-mode c-reader-level-0)", "output": "(defmacro define-c-syntax-reader-for-each-case-mode (base-readtable-name)\n (check-type base-readtable-name symbol)\n (loop with case-modes = '(:upcase :downcase :preserve :invert)\n for mode in case-modes\n as name = (format-symbol :with-c-syntax.core \"~A-~A\" base-readtable-name mode)\n collect `(defreadtable ,name\n (:merge ,base-readtable-name)\n (:case ,mode))\n into bodies\n finally\n (return `(progn ,@bodies))))", "macroexpand": "(progn (defreadtable c-reader-level-0-upcase (:merge c-reader-level-0) (:case :upcase)) (defreadtable c-reader-level-0-downcase (:merge c-reader-level-0) (:case :downcase)) (defreadtable c-reader-level-0-preserve (:merge c-reader-level-0) (:case :preserve)) (defreadtable c-reader-level-0-invert (:merge c-reader-level-0) (:case :invert)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-html-string (:ul (:li (:a \"hai\"))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-html", "input": "(with-html-string (:ul (:li (:a \"hai\"))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:ul (:li (:a \"hai\")))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(aand (values nil t) it)\n\nWrite a macro that addresses: Macro call that should be transformed by aand", "input": "(aand (values nil t) it)", "output": "(defmacro aand (first &rest rest)\n \"Like AND, except binds the first argument to IT (via LET) for the\nscope of the rest of the arguments.\"\n `(anaphoric and ,first ,@rest))", "macroexpand": "(anaphoric and (values nil t) it)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-open-temporary-file (f :keep t) (pathname f))\n\nProblem: Macro call that should be transformed by with-open-temporary-file", "input": "(with-open-temporary-file (f :keep t) (pathname f))", "output": "(defmacro with-open-temporary-file ((stream &rest args &key keep &allow-other-keys) &body body)\n \"Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY\n with STREAM bound to the temporary file stream. Returns the values\n returned by BODY. By default, the file is deleted when BODY is\n exited. If a true value is passed in KEEP, the file is not deleted\n when the body is exited. See OPEN-TEMPORARY for more permitted\n options.\"\n `(with-open-stream (,stream (open-temporary ,@(alexandria:remove-from-plist args :keep)))\n #+sbcl\n (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note))\n ,(if (and (constantp keep)\n keep)\n `(progn ,@body)\n `(unwind-protect\n (progn ,@body)\n (unless ,keep\n (close ,stream)\n (delete-file (pathname ,stream)))))))", "macroexpand": "(with-open-stream (f (open-temporary)) (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note)) (progn (pathname f)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(some->> nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by SOME->>", "input": "(some->> nil :key nil)", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:|some123| nil)\n (#:|some123| (when #:|some123| (:key #:|some123|)))\n (#:|some123| (when #:|some123| (#:|some123|))))\n #:|some123|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun-compile-time expand-local-setq (pairs environment) (if (null pairs) '(progn) (let ((d (gensym \"DUMMY-\"))) `(let ((,d ,(first pairs))) (trail #'(lambda () (setq ,(first pairs) ,d))) ,@(if (null (rest (rest pairs))) (list `(setq ,(first pairs) ,(perform-substitutions (second pairs) environment))) (list `(setq ,(first pairs) ,(perform-substitutions (second pairs) environment)) (expand-local-setq (rest (rest pairs)) environment)))))))\n\nWrite a macro that addresses: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time expand-local-setq (pairs environment) (if (null pairs) '(progn) (let ((d (gensym \"DUMMY-\"))) `(let ((,d ,(first pairs))) (trail #'(lambda () (setq ,(first pairs) ,d))) ,@(if (null (rest (rest pairs))) (list `(setq ,(first pairs) ,(perform-substitutions (second pairs) environment))) (list `(setq ,(first pairs) ,(perform-substitutions (second pairs) environment)) (expand-local-setq (rest (rest pairs)) environment)))))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun expand-local-setq (pairs environment) (if (null pairs) (quote (progn)) (let ((d (gensym \"DUMMY-\"))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr d :kind 0) #S(sb-impl::comma :expr (first pairs) :kind 0))) (trail (function (lambda nil (setq #S(sb-impl::comma :expr (first pairs) :kind 0) #S(sb-impl::comma :expr d :kind 0))))) #S(sb-impl::comma :expr (if (null (rest (rest pairs))) (list (sb-int:quasiquote (setq #S(sb-impl::comma :expr (first pairs) :kind 0) #S(sb-impl::comma :expr (perform-substitutions (second pairs) environment) :kind 0)))) (list (sb-int:quasiquote (setq #S(sb-impl::comma :expr (first pairs) :kind 0) #S(sb-impl::comma :expr (perform-substitutions (second pairs) environment) :kind 0))) (expand-local-setq (rest (rest pairs)) environment))) :kind 2)))))) (eval-when (:compile-toplevel) (compile (quote expand-local-setq))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda () nil)\n\nWrite a macro that addresses: Macro call that should be transformed by LAMBDA", "input": "(lambda () nil)", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda () nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(resolving\n nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by RESOLVING", "input": "(resolving\n nil\n (progn))", "output": "(defmacro RESOLVING ...)", "macroexpand": "(resolve\n nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-decoder-simple-clos-semantics (is (equal-objects-p (make-instance 'frob :bar 46 :quux 98) (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"frob\\\"}\")))) (finalize-inheritance (find-class 'foo)) (finalize-inheritance (find-class 'goo)) (is (equal-objects-p (json:make-object '((bar . 46) (xyzzy . t) (quux . 98)) nil '(foo goo)) (decode-json-from-string (format nil input \"{\\\"lispSuperclasses\\\": [\\\"foo\\\", \\\"goo\\\"], \\\"lispPackage\\\":\\\"jsonTest\\\"}\")))) (is (typep (prototype (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"pFrob\\\"}\"))) 'prototype)) (is (equalp '((bar . 46) (xyzzy . t) (quux . 98)) (decode-json-from-string (format nil input \"{\\\"lispClass\\\": \\\"cons\\\", \\\"lispPackage\\\":\\\"jsonTest\\\"}\")))) (is (loop with ht = (decode-json-from-string (format nil input \"{\\\"lispClass\\\": \\\"hashTable\\\", \\\"lispPackage\\\":\\\"jsonTest\\\"}\")) initially (if (/= (hash-table-count ht) 3) (return nil)) for k being each hash-key of ht using (hash-value v) always (case k (bar (eql v 46)) (xyzzy (eql v t)) (quux (eql v 98)) (t nil)))))\n\nProblem: Macro call that should be transformed by with-decoder-simple-clos-semantics", "input": "(with-decoder-simple-clos-semantics (is (equal-objects-p (make-instance 'frob :bar 46 :quux 98) (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"frob\\\"}\")))) (finalize-inheritance (find-class 'foo)) (finalize-inheritance (find-class 'goo)) (is (equal-objects-p (json:make-object '((bar . 46) (xyzzy . t) (quux . 98)) nil '(foo goo)) (decode-json-from-string (format nil input \"{\\\"lispSuperclasses\\\": [\\\"foo\\\", \\\"goo\\\"], \\\"lispPackage\\\":\\\"jsonTest\\\"}\")))) (is (typep (prototype (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"pFrob\\\"}\"))) 'prototype)) (is (equalp '((bar . 46) (xyzzy . t) (quux . 98)) (decode-json-from-string (format nil input \"{\\\"lispClass\\\": \\\"cons\\\", \\\"lispPackage\\\":\\\"jsonTest\\\"}\")))) (is (loop with ht = (decode-json-from-string (format nil input \"{\\\"lispClass\\\": \\\"hashTable\\\", \\\"lispPackage\\\":\\\"jsonTest\\\"}\")) initially (if (/= (hash-table-count ht) 3) (return nil)) for k being each hash-key of ht using (hash-value v) always (case k (bar (eql v 46)) (xyzzy (eql v t)) (quux (eql v 98)) (t nil)))))", "output": "(defmacro with-decoder-simple-clos-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-CLOS-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-clos-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-clos-semantics) (is (equal-objects-p (make-instance (quote frob) :bar 46 :quux 98) (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"frob\\\"}\")))) (finalize-inheritance (find-class (quote foo))) (finalize-inheritance (find-class (quote goo))) (is (equal-objects-p (make-object (quote ((bar . 46) (xyzzy . t) (quux . 98))) nil (quote (foo goo))) (decode-json-from-string (format nil input \"{\\\"lispSuperclasses\\\": [\\\"foo\\\", \\\"goo\\\"], \\\"lispPackage\\\":\\\"jsonTest\\\"}\")))) (is (typep (prototype (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"pFrob\\\"}\"))) (quote prototype))) (is (equalp (quote ((bar . 46) (xyzzy . t) (quux . 98))) (decode-json-from-string (format nil input \"{\\\"lispClass\\\": \\\"cons\\\", \\\"lispPackage\\\":\\\"jsonTest\\\"}\")))) (is (loop with ht = (decode-json-from-string (format nil input \"{\\\"lispClass\\\": \\\"hashTable\\\", \\\"lispPackage\\\":\\\"jsonTest\\\"}\")) initially (if (/= (hash-table-count ht) 3) (return nil)) for k being each hash-key of ht using (hash-value v) always (case k (bar (eql v 46)) (xyzzy (eql v t)) (quux (eql v 98)) (t nil)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(action (:after node-lisp node bound-variables) (when (loop :for (_ . coalton-var) :in (node-lisp-vars node) :thereis (and (eq name coalton-var) (not (member name bound-variables :test #'eq)))) (setf unsafe? t)) (values))\n\nWhat needs to change: Macro call that should be transformed by action", "input": "(action (:after node-lisp node bound-variables) (when (loop :for (_ . coalton-var) :in (node-lisp-vars node) :thereis (and (eq name coalton-var) (not (member name bound-variables :test #'eq)))) (setf unsafe? t)) (values))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-lisp) (lambda (node bound-variables) (declare (type node-lisp node)) (when (loop :for (_ . coalton-var) :in (node-lisp-vars node) :thereis (and (eq name coalton-var) (not (member name bound-variables :test (function eq))))) (setf unsafe? t)) (values)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (find (first x) (list 'flag)) (let ((s (short x)) (l (long x))) (if s (push s flags-short)) (if l (push l flags-long))))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (find (first x) (list 'flag)) (let ((s (short x)) (l (long x))) (if s (push s flags-short)) (if l (push l flags-long))))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (find (first x) (list (quote flag))) (let ((s (short x)) (l (long x))) (if s (push s flags-short)) (if l (push l flags-long))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is (< less more))\n\nProblem: Macro call that should be transformed by is", "input": "(is (< less more))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e247 less) (#:a248 more)) (if (progn (< #:e247 #:a248)) (add-result (quote test-passed) :test-expr (quote (< less more))) (process-failure (quote (< less more)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote more) #:a248 (quote <) #:e247)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"57014\" query-canceled operator-intervention)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"57014\" query-canceled operator-intervention)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition query-canceled (operator-intervention) nil) (setf (gethash \"57014\" *error-table*) (quote query-canceled)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n;; Manual dispatch by keyword with multiple lambdas is repetitive\n(let ((count 0))\n (setf (symbol-function 'counter)\n (lambda (&rest args)\n (case (car args)\n (:inc (apply (lambda (n) (incf count n)) (cdr args)))\n (:dec (apply (lambda (n) (decf count n)) (cdr args)))\n (:reset (progn (setf count 0) nil))\n (t (error \"Unknown: ~a\" (car args)))))))\n\n;; Every method: keyword, lambda wrapper, arg destructuring - repetitive\n\nWrite a macro that addresses: Repeated keyword-dispatch with automatic argument destructuring \u2014 each keyword maps to a lambda with its own parameter list", "input": ";; Manual dispatch by keyword with multiple lambdas is repetitive\n(let ((count 0))\n (setf (symbol-function 'counter)\n (lambda (&rest args)\n (case (car args)\n (:inc (apply (lambda (n) (incf count n)) (cdr args)))\n (:dec (apply (lambda (n) (decf count n)) (cdr args)))\n (:reset (progn (setf count 0) nil))\n (t (error \"Unknown: ~a\" (car args)))))))\n\n;; Every method: keyword, lambda wrapper, arg destructuring - repetitive", "output": "(defmacro! dlambda (&rest ds)\n `(lambda (&rest ,g!args)\n (case (car ,g!args)\n ,@(mapcar\n (lambda (d)\n `(,(if (eq t (car d))\n t\n (list (car d)))\n (apply (lambda ,@(cdr d))\n ,(if (eq t (car d))\n g!args\n `(cdr ,g!args)))))\n ds))))", "macroexpand": ";; (dlambda\n;; (:inc (n) (incf count n))\n;; (:dec (n) (decf count n))\n;; (:reset () (setf count 0))\n;; (t (&rest args) (format t \"Unknown: ~a~%\" args)))\n;;\n;; Expands to a single lambda with case dispatch.\n;; Each method has its own destructured argument list.\n;; t as the key provides a default/catch-all.", "category": "dispatch", "technique": "dlambda,gensym", "complexity": "intermediate", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-dynenv-var nil (progn))\n\nProblem: Macro call that should be transformed by DEF-DYNENV-VAR", "input": "(def-dynenv-var nil (progn))", "output": "(defmacro DEF-DYNENV-VAR ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar #:nil173 (load-time-value (progn)))\n (setf (get 'nil 'dynenv-var) '#:nil173)\n (define-symbol-macro nil (get-dynenv-var 'nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> :g ((a (n) b c (d e f))) (put (list a n b c d e f)))\n\nIssue: Macro call that should be transformed by ->", "input": "(-> :g ((a (n) b c (d e f))) (put (list a n b c d e f)))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g ((a (n) b c (d e f))) (put (list a n b c d e f)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(deftag dynamic-tag (body attrs &key name) (unless name (error \"No tag name\")) (let ((empty? (null body)) (thunk (gensym (string 'dynamic-tag-thunk))) (attrs (escape-attrs nil attrs))) `(prog1 nil (flet ((,thunk () ,@(loop for expr in body collect `(catch-output ,expr)))) (declare (dynamic-extent #',thunk)) (dynamic-tag* ,name (list ,@attrs) #',thunk ,empty?)))))\n\nWhat needs to change: Macro call that should be transformed by deftag", "input": "(deftag dynamic-tag (body attrs &key name) (unless name (error \"No tag name\")) (let ((empty? (null body)) (thunk (gensym (string 'dynamic-tag-thunk))) (attrs (escape-attrs nil attrs))) `(prog1 nil (flet ((,thunk () ,@(loop for expr in body collect `(catch-output ,expr)))) (declare (dynamic-extent #',thunk)) (dynamic-tag* ,name (list ,@attrs) #',thunk ,empty?)))))", "output": "(defmacro deftag (name (body attrs-var &rest ll) &body tag)\n \"Define NAME as a tag.\nIf NAME is not a keyword, it will also be defined as a macro with an\nimplicit `with-html'.\"\n (let ((definer\n (if (keywordp name)\n 'deftag/keyword\n 'deftag/macro)))\n `(,definer ,name (,body ,attrs-var ,@ll) ,@tag)))", "macroexpand": "(deftag/macro dynamic-tag (body attrs &key name) (unless name (error \"No tag name\")) (let ((empty? (null body)) (thunk (gensym (string (quote dynamic-tag-thunk)))) (attrs (escape-attrs nil attrs))) (sb-int:quasiquote (prog1 nil (flet ((#S(sb-impl::comma :expr thunk :kind 0) nil #S(sb-impl::comma :expr (loop for expr in body collect (sb-int:quasiquote (catch-output #S(sb-impl::comma :expr expr :kind 0)))) :kind 2))) (declare (dynamic-extent (function #S(sb-impl::comma :expr thunk :kind 0)))) (dynamic-tag* #S(sb-impl::comma :expr name :kind 0) (list #S(sb-impl::comma :expr attrs :kind 2)) (function #S(sb-impl::comma :expr thunk :kind 0)) #S(sb-impl::comma :expr empty? :kind 0)))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some->\n nil\n (progn))\n\nProblem: Macro call that should be transformed by SOME->", "input": "(some->\n nil\n (progn))", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:var171 nil)\n (#:var172\n (if #:var171\n (progn #:var171)\n nil)))\n #:var172)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(c-assert (listp old-kids))\n\nIssue: Macro call that should be transformed by c-assert", "input": "(c-assert (listp old-kids))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (listp old-kids) (c-break \"failed assertion: ~a\" (quote (listp old-kids)))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.885} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(continue-whopper)\n\nWrite a macro that addresses: Macro call that should be transformed by CONTINUE-WHOPPER", "input": "(continue-whopper)", "output": "(defmacro CONTINUE-WHOPPER ...)", "macroexpand": "(call-next-method-fn self class-env inst-env mcs%caller mcs%next-methods\n mcs%args)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(reduced-typecase nil)\n\nProblem: Macro call that should be transformed by REDUCED-TYPECASE", "input": "(reduced-typecase nil)", "output": "(defmacro REDUCED-TYPECASE ...)", "macroexpand": "(typecase nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym there-is :there-is)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym there-is :there-is)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote there-is) (quote synonym)) (quote :there-is)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(do+ inner-loop (do+ (terminate outer-loop 3)))\n\nPattern to recognize: Macro call that should be transformed by do+", "input": "(do+ inner-loop (do+ (terminate outer-loop 3)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil inner-loop (do+ (terminate outer-loop 3)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8624999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(iterate:declare-variables)\n\nWrite a macro that addresses: Macro call that should be transformed by iter", "input": "(iterate:declare-variables)", "output": "(defmacro iter (&body body &environment env)\n \"Jonathan Amsterdam's powerful and extensible iteration facility,\nproviding multiple accumulation, generators, memory of previous\niterations, over 50 clauses to start with and a Lisp-like syntax.\nEvaluate (iterate:display-iterate-clauses) for an overview of clauses\"\n (let* ((*env* env)\n\t (*result-var* (genvar 'result))\n\t (*type-alist* nil)\n\t (*declare-variables* *always-declare-variables*)\n\t (*bindings* nil)\n\t (*internal-variables* nil)\n\t (*previous-vars-alist* nil)\n\t (*declarations* nil)\n\t (*loop-body-wrappers* nil)\n\t (*accum-var-alist* nil)\n\t (*shared-bindings-alist* nil)\n\t (*top-level?* t)\n\t (*binding-context?* nil)\n\t (*temps* nil)\n\t (*temps-in-use* nil)\n\t (*driver-info-alist* nil)\n\t (*loop-name* (if (symbolp (car body))\n\t\t\t (car body)\n\t\t\t (gensym \"ITERATE\")))\n\t (*block-name* (if (symbolp (car body))\n\t\t\t (pop body)\n\t\t\t nil))\n\t (*loop-top* (symbol-append 'loop-top- *block-name*))\n\t (*loop-step* (symbol-append 'loop-step- *block-name*))\n\t (*loop-end* (symbol-append 'loop-end- *block-name*))\n\t (*loop-step-used?* nil)\n\t (*loop-end-used?* nil))\n (process-top-level-decls body)\n (multiple-value-bind (body decls init-code steppers final-code final-prot)\n\t(walk-list body)\n (multiple-value-bind (init step)\n\t (insert-previous-code)\n\t(augment init-code init)\n\t(augment steppers step))\n (prepend (default-driver-code) body)\n (let* ((it-bod `(block ,*loop-name*\n\t\t\t(tagbody\n\t\t\t (progn ,.init-code)\n\t\t\t ,*loop-top*\n\t\t\t (progn ,.body)\n\t\t\t ,.(if *loop-step-used?* (list *loop-step*))\n\t\t\t (progn ,.steppers)\n\t\t\t (go ,*loop-top*)\n\t\t\t ,.(if *loop-end-used?* (list *loop-end*))\n\t\t\t (progn ,.final-code))\n\t\t\t,(if (member *result-var* *bindings* :key #'car)\n\t\t\t *result-var*\n\t\t\t nil)))\n\t (it-bod (if (eql *block-name* nil)\n\t\t\t `(block nil ,it-bod)\n\t\t\t it-bod)))\n\t(wrap-form *loop-body-wrappers*\n\t\t `(let* ,(nreverse *bindings*)\n\t\t ,.(if *declarations*\n\t\t\t `((declare .,*declarations*)))\n\t\t ,.decls\n\t\t ,(if final-prot\n\t\t\t `(unwind-protect ,it-bod .,final-prot)\n\t\t\t it-bod)))))))", "macroexpand": "(declare-variables)", "category": "anaphoric", "technique": "tagbody-go,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.835} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(bind ((#(a nil c) #(1 2 3))) (list a c))\n\nWrite a macro that addresses: Macro call that should be transformed by bind", "input": "(bind ((#(a nil c) #(1 2 3))) (list a c))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-168| #(1 2 3)) (a (aref #:|values-168| 0)) (c (aref #:|values-168| 2))) (declare (ignorable #:|values-168|)) (progn (list a c)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym finish :finish)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym finish :finish)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote finish) (quote synonym)) (quote :finish)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error multi-val-bind-mismatch () (bindings val-form return-set) \"Multiple Value Bind - Number of values returned from value form does not match bindings: Bindings: ~a Value Form: ~a Returned Values: ~a\" bindings val-form (map 'list #'type->type-spec return-set))\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error multi-val-bind-mismatch () (bindings val-form return-set) \"Multiple Value Bind - Number of values returned from value form does not match bindings: Bindings: ~a Value Form: ~a Returned Values: ~a\" bindings val-form (map 'list #'type->type-spec return-set))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition multi-val-bind-mismatch (:error-type varjo-error :prefix \"Varjo\") (bindings val-form return-set) \"Multiple Value Bind - Number of values returned from value form does not match bindings: Bindings: ~a Value Form: ~a Returned Values: ~a\" bindings val-form (map (quote list) (function type->type-spec) return-set))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-open-temporary-file (f :keep nil))\n\nPattern to recognize: Macro call that should be transformed by with-open-temporary-file", "input": "(with-open-temporary-file (f :keep nil))", "output": "(defmacro with-open-temporary-file ((stream &rest args &key keep &allow-other-keys) &body body)\n \"Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY\n with STREAM bound to the temporary file stream. Returns the values\n returned by BODY. By default, the file is deleted when BODY is\n exited. If a true value is passed in KEEP, the file is not deleted\n when the body is exited. See OPEN-TEMPORARY for more permitted\n options.\"\n `(with-open-stream (,stream (open-temporary ,@(alexandria:remove-from-plist args :keep)))\n #+sbcl\n (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note))\n ,(if (and (constantp keep)\n keep)\n `(progn ,@body)\n `(unwind-protect\n (progn ,@body)\n (unless ,keep\n (close ,stream)\n (delete-file (pathname ,stream)))))))", "macroexpand": "(with-open-stream (f (open-temporary)) (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note)) (unwind-protect (progn) (unless nil (close f) (delete-file (pathname f)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dynamic-relet* nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DYNAMIC-RELET*", "input": "(dynamic-relet* nil\n :key\n nil)", "output": "(defmacro DYNAMIC-RELET* ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-symbol-access\n nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by WITH-SYMBOL-ACCESS", "input": "(with-symbol-access\n nil\n :key\n nil)", "output": "(defmacro WITH-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* t))\n nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun/1 log10 (x) (log x 10))\n\nIssue: Macro call that should be transformed by defun/1", "input": "(defun/1 log10 (x) (log x 10))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun log10 (x) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (log x 10)) (defparameter log10 (vacietis.c:mkptr& (symbol-function (quote log10)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(cond-<>\n nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by COND-<>", "input": "(cond-<>\n nil\n nil)", "output": "(defmacro COND-<> ...)", "macroexpand": "(let* ((#:var134 nil)\n (#:var135\n (if nil\n (-<>\n #:var134)\n #:var134)))\n #:var135)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-cruft %clear-readtable (readtable) \"Make all macro characters in READTABLE be constituents.\" #+ :sbcl (prog1 readtable (do-readtable (char readtable) (set-syntax-from-char char #\\A readtable)) (setf (sb-impl::dispatch-tables readtable) nil)) #+ :allegro (prog1 readtable (do-readtable (char readtable) (set-syntax-from-char char #\\A readtable)) (let ((dispatch-tables (excl::readtable-dispatch-tables readtable))) (setf (cdr dispatch-tables) nil) (setf (caar dispatch-tables) #\\Backspace) (setf (cadar dispatch-tables) (fill (cadar dispatch-tables) nil)))) #+ :cmucl (prog1 readtable (do-readtable (char readtable) (set-syntax-from-char char #\\A readtable)) (setf (lisp::dispatch-tables readtable) nil)) #+ :common-lisp (do-readtable (char readtable readtable) (set-syntax-from-char char #\\A readtable)))\n\nWhat needs to change: Macro call that should be transformed by define-cruft", "input": "(define-cruft %clear-readtable (readtable) \"Make all macro characters in READTABLE be constituents.\" #+ :sbcl (prog1 readtable (do-readtable (char readtable) (set-syntax-from-char char #\\A readtable)) (setf (sb-impl::dispatch-tables readtable) nil)) #+ :allegro (prog1 readtable (do-readtable (char readtable) (set-syntax-from-char char #\\A readtable)) (let ((dispatch-tables (excl::readtable-dispatch-tables readtable))) (setf (cdr dispatch-tables) nil) (setf (caar dispatch-tables) #\\Backspace) (setf (cadar dispatch-tables) (fill (cadar dispatch-tables) nil)))) #+ :cmucl (prog1 readtable (do-readtable (char readtable) (set-syntax-from-char char #\\A readtable)) (setf (lisp::dispatch-tables readtable) nil)) #+ :common-lisp (do-readtable (char readtable readtable) (set-syntax-from-char char #\\A readtable)))", "output": "(defmacro define-cruft (name lambda-list &body (docstring . alternatives))\n (assert (typep docstring 'string) (docstring) \"Docstring missing!\")\n (assert (not (null alternatives)))\n `(progn\n (declaim (inline ,name))\n (defun ,name ,lambda-list ,docstring ,(first alternatives))))", "macroexpand": "(progn (declaim (inline %clear-readtable)) (defun %clear-readtable (readtable) \"Make all macro characters in READTABLE be constituents.\" (prog1 readtable (do-readtable (char readtable) (set-syntax-from-char char #\\LATIN_CAPITAL_LETTER_A readtable)) (setf (sb-impl:dispatch-tables readtable) nil))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-package (package) (loop for (type . args) in options do (expand-option type package args)))\n\nIssue: Macro call that should be transformed by with-package", "input": "(with-package (package) (loop for (type . args) in options do (expand-option type package args)))", "output": "(defmacro with-package ((var &optional (package var)) &body body)\n `(let ((,var (ensure-package ,package)))\n ,@body))", "macroexpand": "(let ((package (ensure-package package))) (loop for (type . args) in options do (expand-option type package args)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defsynonym count :count)\n\nWrite a macro that addresses: Macro call that should be transformed by defsynonym", "input": "(defsynonym count :count)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote count) (quote synonym)) (quote :count)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-yield-binds (format nil \"DROP~:[~; IF EXISTS~] VIEW ~A\" (drop-view-statement-if-exists statement) (yield (drop-view-statement-view-name statement))))\n\nIssue: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"DROP~:[~; IF EXISTS~] VIEW ~A\" (drop-view-statement-if-exists statement) (yield (drop-view-statement-view-name statement))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"DROP~:[~; IF EXISTS~] VIEW ~A\" (drop-view-statement-if-exists statement) (yield (drop-view-statement-view-name statement)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(*> +opt-fws+ #'comment)\n\nProblem: Macro call that should be transformed by *>", "input": "(*> +opt-fws+ #'comment)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset137) (multiple-value-bind (#:*>-res138 #:*>-next139) (funcall +opt-fws+ #:*>-offset137) (if (ok? #:*>-res138) (funcall (function comment) #:*>-next139) (fail #:*>-next139))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(compiler-macro-lambda (int) `(format t \"~&Compile time: ~A -> ~A.~%\" ',int ,int))\n\nPattern to recognize: Macro call that should be transformed by compiler-macro-lambda", "input": "(compiler-macro-lambda (int) `(format t \"~&Compile time: ~A -> ~A.~%\" ',int ,int))", "output": "(defmacro compiler-macro-lambda (lambda-list &body body)\n (introspect-environment:parse-compiler-macro (gensym \"COMPILER-MACRO-LAMBDA\")\n lambda-list\n body))", "macroexpand": "(sb-int:named-lambda (compiler-macro #:compiler-macro-lambda145) (#:expr #:env) (declare (sb-c::lambda-list (int))) (declare (ignore #:env)) (sb-int:named-ds-bind (:macro #:compiler-macro-lambda145 . define-compiler-macro) (int) (sb-c::compiler-macro-args #:expr) (declare (sb-c::constant-value int) (sb-c::no-compiler-macro #:compiler-macro-lambda145)) (block #:compiler-macro-lambda145 (sb-int:quasiquote (format t \"~&Compile time: ~A -> ~A.~%\" (quote #S(sb-impl::comma :expr int :kind 0)) #S(sb-impl::comma :expr int :kind 0))))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(in-compile-time nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by IN-COMPILE-TIME", "input": "(in-compile-time nil\n :key\n nil)", "output": "(defmacro IN-COMPILE-TIME ...)", "macroexpand": "(macrolet ((#:macro144 (&environment ())\n :key\n nil))\n (#:macro144))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield-binds (format nil \"~A AS ~A\" (if (sql-statement-p (as-op-left op)) (yield (make-sql-list (as-op-left op))) (yield (as-op-left op))) (with-table-name nil (yield (as-op-right op)))))\n\nWhat needs to change: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~A AS ~A\" (if (sql-statement-p (as-op-left op)) (yield (make-sql-list (as-op-left op))) (yield (as-op-left op))) (with-table-name nil (yield (as-op-right op)))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~A AS ~A\" (if (sql-statement-p (as-op-left op)) (yield (make-sql-list (as-op-left op))) (yield (as-op-left op))) (with-table-name nil (yield (as-op-right op))))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(vect-of nil nil)\n\nIssue: Macro call that should be transformed by VECT-OF", "input": "(vect-of nil nil)", "output": "(defmacro VECT-OF ...)", "macroexpand": "(let ((#:vect138 (make-array 10 :adjustable t :fill-pointer 0)))\n (do-for (nil)\n (vector-push-extend nil #:vect138))\n #:vect138)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-iter iterator-repeat (max curr item) (repeat (s0 &optional s1) \"If a single argument is given, yields `s0` repeatedly forever If two arguments are given, then yields `s1` `s0` times ``` (repeat t) ;; t, t, etc (repeat 4 t) ;; t, t, t, t ```\" (init-state (item (or s1 s0)) (max (and s1 s0)) (curr 0))) (if max (if (< curr max) (values (progn (incf curr) item) t) (values nil nil)) (values item t)))\n\nWhat needs to change: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-repeat (max curr item) (repeat (s0 &optional s1) \"If a single argument is given, yields `s0` repeatedly forever If two arguments are given, then yields `s1` `s0` times ``` (repeat t) ;; t, t, etc (repeat 4 t) ;; t, t, t, t ```\" (init-state (item (or s1 s0)) (max (and s1 s0)) (curr 0))) (if max (if (< curr max) (values (progn (incf curr) item) t) (values nil nil)) (values item t)))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname133 (&key max curr item) (labels ((self nil (if max (if (< curr max) (values (progn (incf curr) item) t) (values nil nil)) (values item t)))) (function self)))) (defun repeat (s0 &optional s1) \"If a single argument is given, yields `s0` repeatedly forever If two arguments are given, then yields `s1` `s0` times ``` (repeat t) ;; t, t, etc (repeat 4 t) ;; t, t, t, t ```\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname133)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (init-state (item (or s1 s0)) (max (and s1 s0)) (curr 0)))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(setf nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by SETF", "input": "(setf nil (progn))", "output": "(defmacro SETF ...)", "macroexpand": "(setq nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-global-parameter nil (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER", "input": "(define-global-parameter nil (progn))", "output": "(defmacro DEFINE-GLOBAL-PARAMETER ...)", "macroexpand": "(progn\n (store-in-symbol-plist nil (progn) .value-key.)\n (sb-ext:defglobal nil (get 'nil +value-key+))\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf nil (get 'nil +value-key+)))\n (remprop 'nil +value-key+)\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-definition-resolver optimizer (designator package) (let ((fun-info (when (symbolp designator) (sb-int:info :function :info designator)))) (when fun-info (let ((otypes '(sb-c:fun-info-derive-type sb-c:fun-info-ltn-annotate sb-c:fun-info-optimizer sb-c:fun-info-ir2-convert sb-c::fun-info-stack-allocate-result sb-c::fun-info-constraint-propagate sb-c::fun-info-constraint-propagate-if sb-c::fun-info-call-type-deriver))) (loop for reader in otypes for fn = (funcall reader fun-info) when fn collect (make-instance 'optimizer :designator designator :package package :optimizer fn))))))\n\nWhat needs to change: Macro call that should be transformed by define-definition-resolver", "input": "(define-definition-resolver optimizer (designator package) (let ((fun-info (when (symbolp designator) (sb-int:info :function :info designator)))) (when fun-info (let ((otypes '(sb-c:fun-info-derive-type sb-c:fun-info-ltn-annotate sb-c:fun-info-optimizer sb-c:fun-info-ir2-convert sb-c::fun-info-stack-allocate-result sb-c::fun-info-constraint-propagate sb-c::fun-info-constraint-propagate-if sb-c::fun-info-call-type-deriver))) (loop for reader in otypes for fn = (funcall reader fun-info) when fn collect (make-instance 'optimizer :designator designator :package package :optimizer fn))))))", "output": "(defmacro define-definition-resolver (name args &body body)\n `(progn (setf (definition-resolver ',name)\n (lambda ,args ,@body))\n ',name))", "macroexpand": "(progn (setf (definition-resolver (quote optimizer)) (lambda (designator package) (let ((fun-info (when (symbolp designator) (sb-int:info :function :info designator)))) (when fun-info (let ((otypes (quote (sb-c:fun-info-derive-type sb-c:fun-info-ltn-annotate sb-c:fun-info-optimizer sb-c:fun-info-ir2-convert sb-c::fun-info-stack-allocate-result sb-c::fun-info-constraint-propagate sb-c::fun-info-constraint-propagate-if sb-c::fun-info-call-type-deriver)))) (loop for reader in otypes for fn = (funcall reader fun-info) when fn collect (make-instance (quote optimizer) :designator designator :package package :optimizer fn))))))) (quote optimizer))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(->\n nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by ->", "input": "(->\n nil\n :key\n nil)", "output": "(defmacro -> ...)", "macroexpand": "(let* ((#:var152 nil) (#:var153 (:key #:var152)) (#:var154 (nil #:var153)))\n #:var154)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-mocks () (register-mock 'foo) (dotimes (i 3) (foo)) (is (eql 3 (length (invocations)))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (register-mock 'foo) (dotimes (i 3) (foo)) (is (eql 3 (length (invocations)))))", "output": "(defmacro with-mocks ((&key (recordp T)) &body body)\n \"Execute BODY in a new mocking context. Invocations will be recorded\nif RECORDP is set (default true).\"\n `(call-with-mocks\n (lambda () ,@body)\n :recordp ,recordp))", "macroexpand": "(call-with-mocks (lambda nil (register-mock (quote foo)) (dotimes (i 3) (foo)) (is (eql 3 (length (invocations))))) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-env (setp 7 [struct 'a]))\n\nProblem: Macro call that should be transformed by with-env", "input": "(with-env (setp 7 [struct 'a]))", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g139) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g139 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) (setp 7 [struct (quote a])))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g139)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-element-maker :symbol \"symbol\" '(:id))\n\nWrite a macro that addresses: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :symbol \"symbol\" '(:id))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :symbol)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:id)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :symbol missing))))) (defmethod make-svg-element ((element (eql :symbol)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"symbol\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> #'any #'eof)\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> #'any #'eof)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset161) (multiple-value-bind (#:*>-res162 #:*>-next163) (funcall (function any) #:*>-offset161) (if (ok? #:*>-res162) (funcall (function eof) #:*>-next163) (fail #:*>-next163))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when head (if (eql (first head) t) (cons 'progn (cdr head)) `(if ,(first head) ,(when (cdr head) (cons 'progn (cdr head))) ,(when (cdr clauses) `(cond ,@(cdr clauses))))))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when head (if (eql (first head) t) (cons 'progn (cdr head)) `(if ,(first head) ,(when (cdr head) (cons 'progn (cdr head))) ,(when (cdr clauses) `(cond ,@(cdr clauses))))))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if head (if (eql (first head) t) (cons (quote progn) (cdr head)) (sb-int:quasiquote (if #S(sb-impl::comma :expr (first head) :kind 0) #S(sb-impl::comma :expr (when (cdr head) (cons (quote progn) (cdr head))) :kind 0) #S(sb-impl::comma :expr (when (cdr clauses) (sb-int:quasiquote (cond #S(sb-impl::comma :expr (cdr clauses) :kind 2)))) :kind 0)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defiter nil\n nil)\n\nIssue: Macro call that should be transformed by DEFITER", "input": "(defiter nil\n nil)", "output": "(defmacro DEFITER ...)", "macroexpand": "(defun nil () (make-instance 'iterator :coro (lambda-coro)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(c-assert (typep fm-parent 'family))\n\nPattern to recognize: Macro call that should be transformed by c-assert", "input": "(c-assert (typep fm-parent 'family))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (typep fm-parent (quote family)) (c-break \"failed assertion: ~a\" (quote (typep fm-parent (quote family))))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error no-valid-function () (name types form) \"There is no applicable method for the glsl function '~s' when called with ~a ~@[Form: ~a~]\" name (if types (format nil \"argument types:~%~s\" (mapcar #'type->type-spec types)) \"no arguments.\") form)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error no-valid-function () (name types form) \"There is no applicable method for the glsl function '~s' when called with ~a ~@[Form: ~a~]\" name (if types (format nil \"argument types:~%~s\" (mapcar #'type->type-spec types)) \"no arguments.\") form)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition no-valid-function (:error-type varjo-error :prefix \"Varjo\") (name types form) \"There is no applicable method for the glsl function '~s' when called with ~a ~@[Form: ~a~]\" name (if types (format nil \"argument types:~%~s\" (mapcar (function type->type-spec) types)) \"no arguments.\") form)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when-let (name (messenger-name self)) (format stream \"~a\" name))\n\nIssue: Macro call that should be transformed by when-let", "input": "(when-let (name (messenger-name self)) (format stream \"~a\" name))", "output": "(defmacro when-let (binding &body body)\n (destructuring-bind (var val) binding\n `(let ((,var ,val))\n (when ,var\n\t ,@body))))", "macroexpand": "(let ((name (messenger-name self))) (when name (format stream \"~a\" name)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(collect-product nil)\n\nIssue: Macro call that should be transformed by COLLECT-PRODUCT", "input": "(collect-product nil)", "output": "(defmacro COLLECT-PRODUCT ...)", "macroexpand": "(common-lisp:let* ((#:generator-125 (generator nil))\n #:numbers-121\n (#:mul-122 1))\n (declare (type generator #:generator-125)\n (type number #:mul-122))\n (tagbody\n #:ll-126\n (setq #:numbers-121 (next-in #:generator-125 (go end)))\n (setq #:mul-122 (* #:mul-122 #:numbers-121))\n (go #:ll-126)\n end)\n #:mul-122)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(resolving\n nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by RESOLVING", "input": "(resolving\n nil\n :key\n nil)", "output": "(defmacro RESOLVING ...)", "macroexpand": "(resolve\n nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(->> nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by ->>", "input": "(->> nil :key nil)", "output": "(defmacro ->> ...)", "macroexpand": "((:key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(continue-whopper nil)\n\nWhat needs to change: Macro call that should be transformed by CONTINUE-WHOPPER", "input": "(continue-whopper nil)", "output": "(defmacro CONTINUE-WHOPPER ...)", "macroexpand": "(call-next-method-fn self class-env inst-env mcs%caller mcs%next-methods\n (list nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-condition/a dbi-programming-error (dbi-database-error) () (:documentation \"Exception raised for programming errors, e.g. table not found or already exists, syntax error in SQL statement, wrong number of parameters specified, etc.\"))\n\nIssue: Macro call that should be transformed by define-condition/a", "input": "(define-condition/a dbi-programming-error (dbi-database-error) () (:documentation \"Exception raised for programming errors, e.g. table not found or already exists, syntax error in SQL statement, wrong number of parameters specified, etc.\"))", "output": "(defmacro define-condition/a (name parent-types slots &body options)\n `(progn\n (define-condition ,name ,parent-types ,slots ,@options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (define-condition dbi-programming-error (dbi-database-error) nil (:documentation \"Exception raised for programming errors, e.g. table not found or already exists, syntax error in SQL statement, wrong number of parameters specified, etc.\")) (deftype nil (quote dbi-programming-error)) (setf (find-class (quote )) (find-class (quote dbi-programming-error))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when item `(make-node ,item))\n\nIssue: Macro call that should be transformed by when", "input": "(when item `(make-node ,item))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if item (sb-int:quasiquote (make-node #S(sb-impl::comma :expr item :kind 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-accumulation-binding appending (var form &aux (head (cons NIL NIL)) (tail head)) (declare (type list var) (type cons head tail)) (let ((result (gensym \"RESULT\")) (new-tail (gensym \"NEW-TAIL\"))) `(let ((,result ,form)) (when ,result (multiple-value-bind (,head ,new-tail) (copy-list* ,result) (setf (cdr ,tail) ,head ,tail ,new-tail)) (setf ,var (cdr ,head))))))\n\nWhat needs to change: Macro call that should be transformed by define-accumulation-binding", "input": "(define-accumulation-binding appending (var form &aux (head (cons NIL NIL)) (tail head)) (declare (type list var) (type cons head tail)) (let ((result (gensym \"RESULT\")) (new-tail (gensym \"NEW-TAIL\"))) `(let ((,result ,form)) (when ,result (multiple-value-bind (,head ,new-tail) (copy-list* ,result) (setf (cdr ,tail) ,head ,tail ,new-tail)) (setf ,var (cdr ,head))))))", "output": "(defmacro define-accumulation-binding (name (var &rest args) &body body)\n `(define-form-binding ,name (,var ,@args)\n ,@(form-fiddle:lambda-declarations `(lambda () ,@body))\n (values\n (progn ,@(form-fiddle:lambda-forms `(lambda () ,@body)))\n (delist var))))", "macroexpand": "(define-form-binding appending (var form &aux (head (cons nil nil)) (tail head)) (declare (type list var) (type cons head tail)) (values (progn (let ((result (gensym \"RESULT\")) (new-tail (gensym \"NEW-TAIL\"))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr result :kind 0) #S(sb-impl::comma :expr form :kind 0))) (when #S(sb-impl::comma :expr result :kind 0) (multiple-value-bind (#S(sb-impl::comma :expr head :kind 0) #S(sb-impl::comma :expr new-tail :kind 0)) (copy-list* #S(sb-impl::comma :expr result :kind 0)) (setf (cdr #S(sb-impl::comma :expr tail :kind 0)) #S(sb-impl::comma :expr head :kind 0) #S(sb-impl::comma :expr tail :kind 0) #S(sb-impl::comma :expr new-tail :kind 0))) (setf #S(sb-impl::comma :expr var :kind 0) (cdr #S(sb-impl::comma :expr head :kind 0)))))))) (delist var)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when (find (first x) (list 'stropt)) (let ((s (short x)) (l (long x))) (if s (push s opts-short)) (if l (push l opts-long))))\n\nIssue: Macro call that should be transformed by when", "input": "(when (find (first x) (list 'stropt)) (let ((s (short x)) (l (long x))) (if s (push s opts-short)) (if l (push l opts-long))))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (find (first x) (list (quote stropt))) (let ((s (short x)) (l (long x))) (if s (push s opts-short)) (if l (push l opts-long))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> :g (v) (put v))\n\nIssue: Macro call that should be transformed by ->", "input": "(-> :g (v) (put v))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (v) (put v))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> (from :users) (where (:= :active 1)) (order-by :name))\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> (from :users) (where (:= :active 1)) (order-by :name))", "output": "(defmacro -> (value &rest forms)\n \"Smart threading macro that dispatches based on clause types returned by forms.\n\n This macro enables immutable query composition by threading clauses through\n query-state objects. Creates a single copy at the beginning, then destructively\n adds clauses for efficiency. Supports both v1 select-statements and composer query-states.\n\n Forms that evaluate to NIL are skipped, enabling conditional composition:\n (-> (from :users)\n (when active-only (where (:= :active 1)))\n (when sort-by-name (order-by :name)))\n\n Examples:\n ;; With composer clause\n (-> (from :users)\n (where (:= :active 1))\n (order-by :name))\n\n ;; With v1 select-statement (backward compatible)\n (-> (select (:id :name) (from :users))\n (where (:= :active 1))\n (order-by :name))\n\n ;; Conditional composition\n (-> (from :users)\n (when include-inactive (where (:= :active 0)))\n (when sort-by-date (order-by :created_at)))\"\n (a:with-gensyms (threaded-var clause-var)\n `(let* ((,threaded-var ,value)\n ;; Convert to query-state and copy once at the beginning\n (,threaded-var\n (typecase ,threaded-var\n (query-state-base (copy-query-state-immutable ,threaded-var))\n (stmt:select-statement (select-statement-to-query-state ,threaded-var))\n (stmt:insert-into-statement (insert-statement-to-query-state ,threaded-var))\n (stmt:update-statement (update-statement-to-query-state ,threaded-var))\n (stmt:delete-from-statement (delete-statement-to-query-state ,threaded-var))\n (otherwise (add-clause (make-select-query-state) ,threaded-var)))))\n ;; Now destructively add clauses (no more copying), skipping NILs\n ,@(loop for form in forms\n collect `(let ((,clause-var ,(if (listp form)\n ;; For list forms, call the function with its arguments (no threading)\n `(,(car form) ,@(cdr form))\n ;; For symbol forms, call the function with no arguments\n `(,form))))\n (when ,clause-var\n (add-clause ,threaded-var ,clause-var))))\n ,threaded-var)))", "macroexpand": "(let* ((#:threaded-var143 (from :users)) (#:threaded-var143 (typecase #:threaded-var143 (query-state-base (copy-query-state-immutable #:threaded-var143)) (stmt:select-statement (select-statement-to-query-state #:threaded-var143)) (stmt:insert-into-statement (insert-statement-to-query-state #:threaded-var143)) (stmt:update-statement (update-statement-to-query-state #:threaded-var143)) (stmt:delete-from-statement (delete-statement-to-query-state #:threaded-var143)) (otherwise (add-clause (make-select-query-state) #:threaded-var143))))) (let ((#:clause-var144 (where (:= :active 1)))) (when #:clause-var144 (add-clause #:threaded-var143 #:clause-var144))) (let ((#:clause-var144 (order-by :name))) (when #:clause-var144 (add-clause #:threaded-var143 #:clause-var144))) #:threaded-var143)", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(implies (slot-boundp object (slot-definition-name slot)) (typep (slot-value object (slot-definition-name slot)) (slot-definition-type slot)))\n\nProblem: Macro call that should be transformed by implies", "input": "(implies (slot-boundp object (slot-definition-name slot)) (typep (slot-value object (slot-definition-name slot)) (slot-definition-type slot)))", "output": "(defmacro implies (condition consequent)\n \"A boolean operator that evaluates to the value of CONSEQUENT if CONDITION is\n true, and otherwise evaluates to T. This isn't particularly specific to Quid\n Pro Quo, but it is a useful logical operator for contracts.\"\n `(if ,condition ,consequent t))", "macroexpand": "(if (slot-boundp object (slot-definition-name slot)) (typep (slot-value object (slot-definition-name slot)) (slot-definition-type slot)) t)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dlet* nil\n (progn))\n\nProblem: Macro call that should be transformed by DLET*", "input": "(dlet* nil\n (progn))", "output": "(defmacro DLET* ...)", "macroexpand": "(dynamic-let* nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"22\" data-exception)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"22\" data-exception)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition data-exception (database-error) nil) (setf (gethash \"22\" *error-table*) (quote data-exception)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Generate a defmacro form that transforms code like this:\n(newq 'some-name)\n\nPattern to recognize: Macro call that should be transformed by NEWQ", "input": "(newq 'some-name)", "output": "(defmacro NEWQ ...)", "macroexpand": "(new ''some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(if-generator (tmp gen) (mapcar #'list tmp))\n\nPattern to recognize: Macro call that should be transformed by if-generator", "input": "(if-generator (tmp gen) (mapcar #'list tmp))", "output": "(defmacro if-generator ((var gen) true-clause &optional false-clause)\n \"Pulls a single iteration out of gen. If a single var is specified, it places all the values from the iteration in a list under var. If var is a list, destructures values into the vars in the list. If the generator has stopped, evaluates false-clause, otherwise evaluates true-clause.\"\n `(,@(if (listp var)\n\t `(multiple-value-bind ,var\n\t (funcall ,gen))\n\t `(let ((,var (multiple-value-list (funcall ,gen))))))\n (if (eq 'generator-stop\n\t ,(if (listp var)\n\t\t (car var)\n\t\t `(car ,var)))\n\t ,false-clause\n\t ,true-clause)))", "macroexpand": "(let ((tmp (multiple-value-list (funcall gen)))) (if (eq (quote generator-stop) (car tmp)) nil (mapcar (function list) tmp)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-yield-binds (format nil \"CREATE~:[~; OR REPLACE~] VIEW ~A AS ~A\" (create-view-statement-or-replace statement) (yield (create-view-statement-view-name statement)) (let ((as (create-view-statement-as statement))) (typecase as (string as) (otherwise (yield as))))))\n\nProblem: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"CREATE~:[~; OR REPLACE~] VIEW ~A AS ~A\" (create-view-statement-or-replace statement) (yield (create-view-statement-view-name statement)) (let ((as (create-view-statement-as statement))) (typecase as (string as) (otherwise (yield as))))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"CREATE~:[~; OR REPLACE~] VIEW ~A AS ~A\" (create-view-statement-or-replace statement) (yield (create-view-statement-view-name statement)) (let ((as (create-view-statement-as statement))) (typecase as (string as) (otherwise (yield as)))))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq))) (incf count) (unless (identifiers-disjoint-p value-vars bound-variables) (setf unsafe? t))) (values))\n\nProblem: Macro call that should be transformed by action", "input": "(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq))) (incf count) (unless (identifiers-disjoint-p value-vars bound-variables) (setf unsafe? t))) (values))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-variable) (lambda (node bound-variables) (declare (type node-variable node)) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test (function eq)))) (incf count) (unless (identifiers-disjoint-p value-vars bound-variables) (setf unsafe? t))) (values)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n($ \"value-1\" 600)\n\nWrite a macro that addresses: Macro call that should be transformed by $", "input": "($ \"value-1\" 600)", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(kv \"value-1\" 600)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dlet* nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DLET*", "input": "(dlet* nil\n nil)", "output": "(defmacro DLET* ...)", "macroexpand": "(dynamic-let* nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-case-aware-find-symbol find-preprocessor-directive #:with-c-syntax.preprocessor-directive)\n\nWhat needs to change: Macro call that should be transformed by define-case-aware-find-symbol", "input": "(define-case-aware-find-symbol find-preprocessor-directive #:with-c-syntax.preprocessor-directive)", "output": "(defmacro define-case-aware-find-symbol\n (finder-function-name package-name\n &key (upcased-package-name (format nil \"~A.~A\" (string package-name) '#:UPCASED))\n (docstring\n (format nil \"Find a symbol in `~A' package having a same NAME. If not found, returns `nil'.\"\n package-name)))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defpackage ,upcased-package-name\n (:use)\n (:intern\n ,@(loop for sym being the external-symbol of package-name\n collect (string-upcase (symbol-name sym)))))\n ,@(loop for sym being the external-symbol of package-name\n for upcased = (string-upcase (symbol-name sym))\n collect `(setf (symbol-value (find-symbol ,upcased ',upcased-package-name))\n ',sym))\n (defun ,finder-function-name (string &optional (readtable-case (readtable-case *readtable*)))\n ,@(if docstring `(,docstring))\n (ecase readtable-case\n ((:upcase :invert)\n (if-let ((up-sym (find-symbol string ',upcased-package-name)))\n (symbol-value up-sym)))\n ((:downcase :preserve)\n (find-symbol string ',package-name))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defpackage #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\") (:use) (:intern #A((4) base-char . \"ELIF\") #A((6) base-char . \"IFNDEF\") #A((5) base-char . \"UNDEF\") #A((5) base-char . \"ERROR\") #A((5) base-char . \"ENDIF\") #A((6) base-char . \"PRAGMA\") #A((6) base-char . \"DEFINE\") #A((4) base-char . \"ELSE\") #A((2) base-char . \"IF\") #A((7) base-char . \"INCLUDE\") #A((5) base-char . \"IFDEF\") #A((4) base-char . \"LINE\"))) (setf (symbol-value (find-symbol #A((4) base-char . \"ELIF\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|elif|)) (setf (symbol-value (find-symbol #A((6) base-char . \"IFNDEF\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|ifndef|)) (setf (symbol-value (find-symbol #A((5) base-char . \"UNDEF\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|undef|)) (setf (symbol-value (find-symbol #A((5) base-char . \"ERROR\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|error|)) (setf (symbol-value (find-symbol #A((5) base-char . \"ENDIF\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|endif|)) (setf (symbol-value (find-symbol #A((6) base-char . \"PRAGMA\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|pragma|)) (setf (symbol-value (find-symbol #A((6) base-char . \"DEFINE\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|define|)) (setf (symbol-value (find-symbol #A((4) base-char . \"ELSE\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|else|)) (setf (symbol-value (find-symbol #A((2) base-char . \"IF\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|if|)) (setf (symbol-value (find-symbol #A((7) base-char . \"INCLUDE\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|include|)) (setf (symbol-value (find-symbol #A((5) base-char . \"IFDEF\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|ifdef|)) (setf (symbol-value (find-symbol #A((4) base-char . \"LINE\") (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\")))) (quote with-c-syntax.preprocessor-directive:|line|)) (defun find-preprocessor-directive (string &optional (readtable-case (readtable-case *readtable*))) #A((112) base-char . \"Find a symbol in `WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE' package having a same NAME. If not found, returns `nil'.\") (ecase readtable-case ((:upcase :invert) (if-let ((up-sym (find-symbol string (quote #A((44) base-char . \"WITH-C-SYNTAX.PREPROCESSOR-DIRECTIVE.UPCASED\"))))) (symbol-value up-sym))) ((:downcase :preserve) (find-symbol string (quote #:with-c-syntax.preprocessor-directive))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-files (file (repo-dir *config*) file-type) (let ((obj (construct (class-name doc-type) (read-content file)))) (add-document obj)))\n\nPattern to recognize: Macro call that should be transformed by do-files", "input": "(do-files (file (repo-dir *config*) file-type) (let ((obj (construct (class-name doc-type) (read-content file)))) (add-document obj)))", "output": "(defmacro do-files ((var path &optional extension) &body body)\n \"For each file under PATH, run BODY. If EXTENSION is provided, only run\nBODY on files that match the given extension.\"\n (alexandria:with-gensyms (extension-p)\n `(flet ((,extension-p (file)\n (string= (pathname-type file) ,extension)))\n (cl-fad:walk-directory ,path (lambda (,var) ,@body)\n :follow-symlinks nil\n :test (if ,extension\n #',extension-p\n (constantly t))))))", "macroexpand": "(flet ((#:extension-p287 (file) (string= (pathname-type file) file-type))) (cl-fad:walk-directory (repo-dir *config*) (lambda (file) (let ((obj (construct (class-name doc-type) (read-content file)))) (add-document obj))) :follow-symlinks nil :test (if file-type (function #:extension-p287) (constantly t))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(bind (((:plist- a (b _) (c _ 2) (dd d)) '(b \"B\" a \"A\" d \"D\"))) (list a b c dd))\n\nPattern to recognize: Macro call that should be transformed by bind", "input": "(bind (((:plist- a (b _) (c _ 2) (dd d)) '(b \"B\" a \"A\" d \"D\"))) (list a b c dd))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-165| (quote (b \"B\" a \"A\" d \"D\"))) (a (getf #:|values-165| (quote a))) (b (getf #:|values-165| (quote b))) (c (getf #:|values-165| (quote c) 2)) (dd (getf #:|values-165| (quote d)))) (declare (ignorable #:|values-165|)) (progn (list a b c dd)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-simple-object-lookup package find-package)\n\nProblem: Macro call that should be transformed by define-simple-object-lookup", "input": "(define-simple-object-lookup package find-package)", "output": "(defmacro define-simple-object-lookup (class lookup-function &body body)\n `(defmethod object ((,class ,class))\n ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function (designator ,class)))))", "macroexpand": "(defmethod object ((package package)) (find-package (designator package)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(without-dependency-capture\n 'some-name)\n\nPattern to recognize: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE", "input": "(without-dependency-capture\n 'some-name)", "output": "(defmacro WITHOUT-DEPENDENCY-CAPTURE ...)", "macroexpand": "(let ((%dependent% nil))\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dotable (k v ht2) (setf (gethash k rez) (funcall fn v (gethash k rez))))\n\nWrite a macro that addresses: Macro call that should be transformed by dotable", "input": "(dotable (k v ht2) (setf (gethash k rez) (funcall fn v (gethash k rez))))", "output": "(defmacro dotable ((k v table &optional rez) &body body)\n \"Like DOLIST but iterates over key-value pairs (K V) in anything, that can be\n viewed as a table (hash-table, alist, plist, object).\n Autodeclares variables named _ as ignored.\"\n (with-gensyms (pair)\n (once-only (table)\n (let ((_ (find \"_\" (list k v)\n :test 'string=\n :key 'symbol-name)))\n `(block nil\n (etypecase ,table\n (hash-table (maphash (lambda (,k ,v)\n ,(when _ `(declare (ignore rutils.bind:_)))\n ,@body)\n ,table))\n\n (list (if (rutils.list:alistp ,table)\n (dolist (,pair ,table)\n (destructuring-bind (,k . ,v) ,pair\n ,@(when _ `((declare (ignore ,_))))\n ,@body))\n (error 'simple-type-error\n :format-control \"Can't iterate over proper list ~\n in DOTABLE: need an alist\"))))\n ,rez)))))", "macroexpand": "(let ((#:table170 ht2)) (block nil (etypecase #:table170 (hash-table (maphash (lambda (k v) nil (setf (gethash k rez) (funcall fn v (gethash k rez)))) #:table170)) (list (if (alistp #:table170) (dolist (#:g169 #:table170) (destructuring-bind (k . v) #:g169 (setf (gethash k rez) (funcall fn v (gethash k rez))))) (error (quote simple-type-error) :format-control \"Can't iterate over proper list ~\n in DOTABLE: need an alist\")))) nil))", "category": "anaphoric", "technique": "once-only,gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(%define-hash-table-entries-pattern hash-table-entries hash-table-entry)\n\nWrite a macro that addresses: Macro call that should be transformed by %define-hash-table-entries-pattern", "input": "(%define-hash-table-entries-pattern hash-table-entries hash-table-entry)", "output": "(defmacro %define-hash-table-entries-pattern (name entry-pattern)\n `(defpattern ,name (key pattern &rest keys-and-patterns)\n ,(format nil \"Matches hash table which has KEY set to value matching PATTERN.~\n Multiple KEY PATTERN pairs can be provided, e.g. `(~A :key1 _ :key2 value :key3 1)`.~\n Expands into list of ~A patterns combined with AND.\"\n name entry-pattern)\n (when (oddp (length keys-and-patterns))\n (warn 'hash-table-odd-number-of-entries-warning\n :format-control ,(format nil \"Odd number of arguments given to ~A pattern. NIL will be used as ~~S pattern.\" name)\n :format-arguments (last keys-and-patterns)))\n `(and ,(list ',entry-pattern key pattern)\n ,@(loop :for (key pattern) :on keys-and-patterns :by #'cddr\n :collect (list ',entry-pattern key pattern)))))", "macroexpand": "(defpattern hash-table-entries (key pattern &rest keys-and-patterns) #A((228) base-char . \"Matches hash table which has KEY set to value matching PATTERN.Multiple KEY PATTERN pairs can be provided, e.g. `(HASH-TABLE-ENTRIES :key1 _ :key2 value :key3 1)`.Expands into list of HASH-TABLE-ENTRY patterns combined with AND.\") (when (oddp (length keys-and-patterns)) (warn (quote hash-table-odd-number-of-entries-warning) :format-control #A((92) base-char . \"Odd number of arguments given to HASH-TABLE-ENTRIES pattern. NIL will be used as ~S pattern.\") :format-arguments (last keys-and-patterns))) (sb-int:quasiquote (and #S(sb-impl::comma :expr (list (quote hash-table-entry) key pattern) :kind 0) #S(sb-impl::comma :expr (loop :for (key pattern) :on keys-and-patterns :by (function cddr) :collect (list (quote hash-table-entry) key pattern)) :kind 2))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error conditional-return-type-mismatch () (sets) \"Due to a conditional the function could return any of the following:~{~%~a~} This stopped us working out the correct return types for this function\" (mapcar (lambda (x) (or (map 'list #'type->type-spec x) :void)) sets))\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error conditional-return-type-mismatch () (sets) \"Due to a conditional the function could return any of the following:~{~%~a~} This stopped us working out the correct return types for this function\" (mapcar (lambda (x) (or (map 'list #'type->type-spec x) :void)) sets))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition conditional-return-type-mismatch (:error-type varjo-error :prefix \"Varjo\") (sets) \"Due to a conditional the function could return any of the following:~{~%~a~} This stopped us working out the correct return types for this function\" (mapcar (lambda (x) (or (map (quote list) (function type->type-spec) x) :void)) sets))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(cond-<>\n nil\n (progn))\n\nProblem: Macro call that should be transformed by COND-<>", "input": "(cond-<>\n nil\n (progn))", "output": "(defmacro COND-<> ...)", "macroexpand": "(let* ((#:var136 nil)\n (#:var137\n (if progn\n (-<>\n #:var136)\n #:var136)))\n #:var137)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(alist-bind (name type) form (let ((sym (foreign-type-symbol name :ctype *package*))) (if (pointer*-to-record-form-p type) (pushnew sym *foreign-record-list* :test #'equal) (if (pointer-alias-form-p type) (pushnew sym *foreign-alias-list* :test #'equal) (pushnew sym *foreign-other-exports-list*))) `(define-foreign-alias ',sym ',@(parse-type type (aval :tag type)))))\n\nIssue: Macro call that should be transformed by alist-bind", "input": "(alist-bind (name type) form (let ((sym (foreign-type-symbol name :ctype *package*))) (if (pointer*-to-record-form-p type) (pushnew sym *foreign-record-list* :test #'equal) (if (pointer-alias-form-p type) (pushnew sym *foreign-alias-list* :test #'equal) (pushnew sym *foreign-other-exports-list*))) `(define-foreign-alias ',sym ',@(parse-type type (aval :tag type)))))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist239 form)) (let ((name (aval :name #:alist239)) (type (aval :type #:alist239))) (let ((sym (foreign-type-symbol name :ctype *package*))) (if (pointer*-to-record-form-p type) (pushnew sym *foreign-record-list* :test (function equal)) (if (pointer-alias-form-p type) (pushnew sym *foreign-alias-list* :test (function equal)) (pushnew sym *foreign-other-exports-list*))) (sb-int:quasiquote (define-foreign-alias (quote #S(sb-impl::comma :expr sym :kind 0)) (quote #S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2)))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(some-> nil)\n\nWhat needs to change: Macro call that should be transformed by SOME->", "input": "(some-> nil)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:g141 nil))\n #:g141)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-env (setp 2 [assoc-list 'a]))\n\nProblem: Macro call that should be transformed by with-env", "input": "(with-env (setp 2 [assoc-list 'a]))", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g134) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g134 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) (setp 2 [assoc-list (quote a])))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g134)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-cfun __error)\n\nProblem: Macro call that should be transformed by define-cfun", "input": "(define-cfun __error)", "output": "(defmacro define-cfun (name-or-function &optional (package *package*))\n (when-let ((fun (find-function name-or-function)))\n (with-wrap-attempt (\"function ~S\" name-or-function) name-or-function\n (with-slots (name type c-symbol fields) fun\n (let* ((fun-name (intern (symbol-name name) package))\n (param-names (mapcar #'foreign-type-name fields))\n (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))\n (make-function-p (not (foreign-function-variadic-p fun)))\n (maybe-cbv-return\n (when (cbv-return-p fun)\n (list 'return-value))))\n (with-gensyms (!fun !fields rest)\n (let ((form\n (if make-function-p\n `(defun ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n ,(let ((!fun (find-function name-or-function)))\n (with-slots ((!fields fields)) !fun\n (foreign-to-ffi\n (and (car !fields) (foreign-type (car !fields)))\n param-syms\n param-names\n !fields\n (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)\n param-syms (when (foreign-function-variadic-p fun) rest))))))\n `(defmacro ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n (let ((,!fun (find-function ',name-or-function)))\n (with-slots ((,!fields fields)) ,!fun\n (foreign-to-ffi\n (and (car ,!fields) (foreign-type (car ,!fields)))\n ',param-syms\n (list ,@param-names)\n ,!fields\n (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)\n ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))\n `(progn\n ,@(when (foreign-function-cbv-p fun)\n (list (funcall *build-libffi-definition* fun)))\n ,form))))))))", "macroexpand": "(progn (defun __error nil (cffi-sys:%foreign-funcall \"__error\" (:pointer) :convention :cdecl)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-color (:green :stream stream) (format/indent reporter stream \"\u2713 ~D test~:*~P completed\" count))\n\nProblem: Macro call that should be transformed by with-color", "input": "(with-color (:green :stream stream) (format/indent reporter stream \"\u2713 ~D test~:*~P completed\" count))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq :green :gray) (eq :green :grey) (eq :green +gray+) (eq :green +grey+)) (with-gray stream (format/indent reporter stream \"\u2713 ~D test~:*~P completed\" count)) (cl-ansi-text:with-color (:green :stream stream) (format/indent reporter stream \"\u2713 ~D test~:*~P completed\" count))) (progn (format/indent reporter stream \"\u2713 ~D test~:*~P completed\" count)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-append nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-APPEND", "input": "(collect-append nil (progn))", "output": "(defmacro COLLECT-APPEND ...)", "macroexpand": "(common-lisp:let* ((#:generator-223 (generator (progn)))\n #:items-218\n (#:seq-219 nil))\n (declare (type generator #:generator-223))\n (tagbody\n #:ll-224\n (setq #:items-218 (next-in #:generator-223 (go end)))\n (setq #:seq-219 (cons #:items-218 #:seq-219))\n (go #:ll-224)\n end)\n (apply #'concatenate nil (nreverse #:seq-219)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(\"swipl\" \"--quiet\" \"-l\" ,input-file ,@args) :input input :output output :error error))\n\nWhat needs to change: Macro call that should be transformed by with-temp", "input": "(with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(\"swipl\" \"--quiet\" \"-l\" ,input-file ,@args) :input input :output output :error error))", "output": "(defmacro with-temp ((var &key directory template (tmpdir \"/tmp/\") debug) &body body)\n \"Create a temporary file, then remove the file by unwind-protect.\nMost arguments are analogous to mktemp.\nWhen DIRECTORY is non-nil, creates a directory instead.\nDEBUG is a form.\nWhen evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.\nIt may be evaluated multiple times.\"\n (with-gensyms (command)\n `(let ((,var (uiop:run-program\n (let ((,command (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\"\n ,tmpdir ,directory ,template)))\n (when ,debug\n (format *error-output* \"~&; ~a~%\" ,command))\n ,command)\n :output '(:string :stripped t))))\n (unwind-protect\n (progn ,@body)\n (if ,debug\n (format *error-output* \"~&; not removing ~a for debugging~%\" ,var)\n (uiop:run-program (format nil \"rm -rf ~a\" (namestring ,var)) :ignore-error-status t))))))", "macroexpand": "(let ((input-file (uiop/run-program:run-program (let ((#:command176 (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\" d nil \"XXXXXX.prolog\"))) (when (<= 1 *debug-prolog*) (format *error-output* \"~&; ~a~%\" #:command176)) #:command176) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print (sb-int:quasiquote (\"swipl\" \"--quiet\" \"-l\" #S(sb-impl::comma :expr input-file :kind 0) #S(sb-impl::comma :expr args :kind 2))) :input input :output output :error error)) (if (<= 1 *debug-prolog*) (format *error-output* \"~&; not removing ~a for debugging~%\" input-file) (uiop/run-program:run-program (format nil \"rm -rf ~a\" (namestring input-file)) :ignore-error-status t))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-test timeout :time-limit 0.5 (sleep 0.75))\n\nIssue: Macro call that should be transformed by define-test", "input": "(define-test timeout :time-limit 0.5 (sleep 0.75))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote timeout) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote timeout) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (sleep 0.75))) :parent (quote nil) (quote :time-limit) (quote 0.5))) (quote timeout))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-reader-syntax nil)\n\nProblem: Macro call that should be transformed by ENABLE-READER-SYNTAX", "input": "(enable-reader-syntax nil)", "output": "(defmacro ENABLE-READER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (push *readtable* *previous-readtables*)\n (setq *readtable* (copy-readtable))\n (%enable-reader-syntax *readtable* nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(when (node-slot type) (del-proxy type))\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when (node-slot type) (del-proxy type))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (node-slot type) (del-proxy type))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do+ (for x (across #(3 2 1) :start 2 :end 0)) (collect x))\n\nWhat needs to change: Macro call that should be transformed by do+", "input": "(do+ (for x (across #(3 2 1) :start 2 :end 0)) (collect x))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (across #(3 2 1) :start 2 :end 0)) (collect x))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defhandler load-time-value (load-time-value form &optional (read-only-p nil rop-p)) `(list ',load-time-value ,(e form) ,@(when rop-p `(',read-only-p))))\n\nProblem: Macro call that should be transformed by defhandler", "input": "(defhandler load-time-value (load-time-value form &optional (read-only-p nil rop-p)) `(list ',load-time-value ,(e form) ,@(when rop-p `(',read-only-p))))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-load-time-value (load-time-value form &optional (read-only-p nil rop-p)) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr load-time-value :kind 0)) #S(sb-impl::comma :expr (e form) :kind 0) #S(sb-impl::comma :expr (when rop-p (sb-int:quasiquote ((quote #S(sb-impl::comma :expr read-only-p :kind 0))))) :kind 2)))) (setf (gethash (quote load-time-value) *form-handler*) (quote hander-load-time-value)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (or body initializer) `(make-block ,body))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (or body initializer) `(make-block ,body))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (or body initializer) (sb-int:quasiquote (make-block #S(sb-impl::comma :expr body :kind 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deferror \"42P07\" duplicate-table syntax-error-or-access-violation)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"42P07\" duplicate-table syntax-error-or-access-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition duplicate-table (syntax-error-or-access-violation) nil) (setf (gethash \"42P07\" *error-table*) (quote duplicate-table)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(auto-permute-typecase 'some-name)\n\nPattern to recognize: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE", "input": "(auto-permute-typecase 'some-name)", "output": "(defmacro AUTO-PERMUTE-TYPECASE ...)", "macroexpand": "(typecase 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(dynamic-relet nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by DYNAMIC-RELET", "input": "(dynamic-relet nil\n :key\n nil)", "output": "(defmacro DYNAMIC-RELET ...)", "macroexpand": "(dynamic-wind\n :proceed\n #:proceed191\n (let ()\n (declare (special))\n (#:proceed191 :key nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(rem-bops)\n\nIssue: Macro call that should be transformed by REM-BOPS", "input": "(rem-bops)", "output": "(defmacro REM-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn (save-binfix) (mapc 'rmbop 'nil) (assign-properties)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(mvlet* 'some-name)\n\nPattern to recognize: Macro call that should be transformed by MVLET*", "input": "(mvlet* 'some-name)", "output": "(defmacro MVLET* ...)", "macroexpand": "(progn (let* ((quote) (some-name))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-bug user-func-invalid-x () (kind name args) \"Invalid types found in internal user-function construction. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: NAME: ~s ~a: ~s\" name kind args)\n\nPattern to recognize: Macro call that should be transformed by define-bug", "input": "(define-bug user-func-invalid-x () (kind name args) \"Invalid types found in internal user-function construction. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: NAME: ~s ~a: ~s\" name kind args)", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition user-func-invalid-x (:error-type varjo-error :prefix \"Varjo Bug\") (kind name args) \"Invalid types found in internal user-function construction. Our apologies for this mistake. If you have the time please raise an issue at https://github.com/cbaggers/varjo/issues including the code that triggered this issue. Problematic Definition: NAME: ~s ~a: ~s\" name kind args)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-op (:not unary-op))\n\nWhat needs to change: Macro call that should be transformed by define-op", "input": "(define-op (:not unary-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (not-op (:include unary-op (name \"NOT\")) (:constructor make-not-op (var))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-or nil)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-OR", "input": "(collect-or nil)", "output": "(defmacro COLLECT-OR ...)", "macroexpand": "(common-lisp:let* ((#:generator-326 (generator nil))\n #:bools-322\n (#:bool-323 nil))\n (declare (type generator #:generator-326))\n (tagbody\n #:ll-327\n (setq #:bools-322 (next-in #:generator-326 (go end)))\n (if (setq #:bool-323 #:bools-322)\n (go end))\n (go #:ll-327)\n end)\n #:bool-323)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(action (:after node-field) #'handle-static-superclass)\n\nWrite a macro that addresses: Macro call that should be transformed by action", "input": "(action (:after node-field) #'handle-static-superclass)", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-field) (function handle-static-superclass))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(inext-noexit 'some-name)\n\nWhat needs to change: Macro call that should be transformed by INEXT-NOEXIT", "input": "(inext-noexit 'some-name)", "output": "(defmacro INEXT-NOEXIT ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro 'some-name) nil))))\n (if (not vals)\n (values nil nil)\n (values (car vals) t)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(bind (((:flet doit (x)) \"whatever\" (declare (type fixnum x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))\n\nPattern to recognize: Macro call that should be transformed by bind", "input": "(bind (((:flet doit (x)) \"whatever\" (declare (type fixnum x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(flet ((doit (x) \"whatever\" (declare (type fixnum x)) (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(without-dependency-capture\n nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE", "input": "(without-dependency-capture\n nil\n (progn))", "output": "(defmacro WITHOUT-DEPENDENCY-CAPTURE ...)", "macroexpand": "(let ((%dependent% nil))\n nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-constant-values (start end) env ((start end) (let* ((counted? (or (> start 0) end)) (test (if counted? `(and ,more? (cl:< ,index ,size)) more?)) (inc (when counted? `((cl:incf ,index))))) (values `((,table ,form) ,@(when counted? `((,index ,start) (,size ,(or end `(hash-table-count ,table)))))) `((with-custom-hash-table (with-hash-table-iterator (,next ,table) ,@body))) (make-iter-value test inc) (make-iter-place test inc)))) (nil (values `((,table ,form) (,index ,start) (,size (or ,end (hash-table-count ,table)))) `((with-custom-hash-table (with-hash-table-iterator (,next ,table) ,@body))) (make-iter-value `(and ,more? (cl:< ,index ,size)) `((cl:incf ,index))) (make-iter-place `(and ,more? (cl:< ,index ,size)) `((cl:incf ,index))))))\n\nPattern to recognize: Macro call that should be transformed by with-constant-values", "input": "(with-constant-values (start end) env ((start end) (let* ((counted? (or (> start 0) end)) (test (if counted? `(and ,more? (cl:< ,index ,size)) more?)) (inc (when counted? `((cl:incf ,index))))) (values `((,table ,form) ,@(when counted? `((,index ,start) (,size ,(or end `(hash-table-count ,table)))))) `((with-custom-hash-table (with-hash-table-iterator (,next ,table) ,@body))) (make-iter-value test inc) (make-iter-place test inc)))) (nil (values `((,table ,form) (,index ,start) (,size (or ,end (hash-table-count ,table)))) `((with-custom-hash-table (with-hash-table-iterator (,next ,table) ,@body))) (make-iter-value `(and ,more? (cl:< ,index ,size)) `((cl:incf ,index))) (make-iter-place `(and ,more? (cl:< ,index ,size)) `((cl:incf ,index))))))", "output": "(defmacro with-constant-values ((&rest things) env &body clauses)\n \"Check whether one or more forms are constant and retrieve their values.\n\n THINGS:\n\n A list of bindings each of the form (VAR INITFORM).\n\n Each INITFORM is evaluated and the result is checked whether it\n is a constant form in the environment ENV. If so the constant\n value is stored in VAR otherwise the resulting form (to which\n INITFORM evaluates) itself is stored in VAR.\n\n Alternatively each element of THINGS can be a symbol in which\n case it is a shorthand for (VAR VAR).\n\n ENV:\n\n The environment in which to check whether the forms are\n constants.\n\n CLAUSES:\n\n A list of clauses each of the form (VARS . FORMS), where\n VARS is a list of variables, listed in THINGS, which should be\n constant in order for the corresponding FORMS to be evaluated.\n\n If all variables in VARS are constants FORMS are evaluated in an\n implicit PROGN, with the result of the last form returned.\n\n If not all of VARS are constant, FORMS are not evaluated and the\n next clause is tried. If no clause succeeds NIL is returned.\"\n\n (let ((const-vars (pairlis (mapcar #'ensure-car things)\n (make-gensym-list (length things) \"CONST?\"))))\n\n (labels ((make-get-value (thing body)\n (destructuring-bind (var &optional (form var))\n (ensure-list thing)\n\n (let ((const-var (cdr (assoc var const-vars))))\n (assert const-var)\n\n `(multiple-value-bind (,var ,const-var)\n (constant-form-value ,form ,env)\n\n ,body))))\n\n (const-var (var)\n (let ((cvar (cdr (assoc var const-vars))))\n (unless cvar\n (error \"Variable ~s in clause not one of ~s.\"\n var (mapcar #'ensure-car things)))\n\n cvar))\n\n (make-clause (clause)\n (destructuring-bind (vars &rest body) clause\n `((and ,@(mapcar #'const-var vars))\n ,@body))))\n\n (cl:reduce\n #'make-get-value\n things\n :from-end t\n :initial-value\n `(cond ,@(mapcar #'make-clause clauses))))))", "macroexpand": "(multiple-value-bind (start #:const?144) (constant-form-value start env) (multiple-value-bind (end #:const?145) (constant-form-value end env) (cond ((and #:const?144 #:const?145) (let* ((counted? (or (> start 0) end)) (test (if counted? (sb-int:quasiquote (and #S(sb-impl::comma :expr more? :kind 0) (< #S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr size :kind 0)))) more?)) (inc (when counted? (sb-int:quasiquote ((incf #S(sb-impl::comma :expr index :kind 0))))))) (values (sb-int:quasiquote ((#S(sb-impl::comma :expr table :kind 0) #S(sb-impl::comma :expr form :kind 0)) #S(sb-impl::comma :expr (when counted? (sb-int:quasiquote ((#S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr start :kind 0)) (#S(sb-impl::comma :expr size :kind 0) #S(sb-impl::comma :expr (or end (sb-int:quasiquote (hash-table-count #S(sb-impl::comma :expr table :kind 0)))) :kind 0))))) :kind 2))) (sb-int:quasiquote ((with-custom-hash-table (with-hash-table-iterator (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr table :kind 0)) #S(sb-impl::comma :expr body :kind 2))))) (make-iter-value test inc) (make-iter-place test inc)))) ((and) (values (sb-int:quasiquote ((#S(sb-impl::comma :expr table :kind 0) #S(sb-impl::comma :expr form :kind 0)) (#S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr start :kind 0)) (#S(sb-impl::comma :expr size :kind 0) (or #S(sb-impl::comma :expr end :kind 0) (hash-table-count #S(sb-impl::comma :expr table :kind 0)))))) (sb-int:quasiquote ((with-custom-hash-table (with-hash-table-iterator (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr table :kind 0)) #S(sb-impl::comma :expr body :kind 2))))) (make-iter-value (sb-int:quasiquote (and #S(sb-impl::comma :expr more? :kind 0) (< #S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr size :kind 0)))) (sb-int:quasiquote ((incf #S(sb-impl::comma :expr index :kind 0))))) (make-iter-place (sb-int:quasiquote (and #S(sb-impl::comma :expr more? :kind 0) (< #S(sb-impl::comma :expr index :kind 0) #S(sb-impl::comma :expr size :kind 0)))) (sb-int:quasiquote ((incf #S(sb-impl::comma :expr index :kind 0))))))))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-condition missing-partial (serious-condition) ())\n\nWrite a macro that addresses: Macro call that should be transformed by define", "input": "(define-condition missing-partial (serious-condition) ())", "output": "(defmacro define (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "macroexpand": "(progn (sb-kernel::%define-condition (quote missing-partial) (quote (serious-condition)) (sb-kernel::find-condition-layout (quote missing-partial) (quote (serious-condition))) (list) (list) (quote nil) (quote nil) (sb-c:source-location)) (sb-kernel::%set-condition-report (quote missing-partial) nil) (quote missing-partial))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do+ (terminate outer-loop 3))\n\nIssue: Macro call that should be transformed by do+", "input": "(do+ (terminate outer-loop 3))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (terminate outer-loop 3))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8474999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(->>\n nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by ->>", "input": "(->>\n nil\n :key\n nil)", "output": "(defmacro ->> ...)", "macroexpand": "(let* ((#:var187 nil) (#:var188 (:key #:var187)) (#:var189 (nil #:var188)))\n #:var189)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(receive (new-k new-v) (funcall fn k v) (dict* new new-k new-v))\n\nProblem: Macro call that should be transformed by receive", "input": "(receive (new-k new-v) (funcall fn k v) (dict* new new-k new-v))", "output": "(defmacro receive (formals expr &body body)\n \"Stricter version of `multiple-value-bind'.\n\nUse `receive' when you want to enforce that EXPR should return a\ncertain number of values, or a minimum number of values.\n\nIf FORMALS is a proper list, then EXPR must return exactly as many\nvalues -- no more and no less -- as there are variables in FORMALS.\n\nIf FORMALS is an improper list (VARS . REST), then EXPR must return at\nleast as many values as there are VARS, and any further values are\nbound, as a list, to REST.\n\nLastly, if FORMALS is a symbol, bind that symbol to all the values\nreturned by EXPR, as if by `multiple-value-list'.\n\nFrom Scheme (SRFI-8).\"\n ;; It's probably not worth stack-allocating the thunk.\n (cond ((null formals)\n `(multiple-value-call\n (lambda ()\n ,@body)\n ,expr))\n ((atom formals)\n ;; This could also be written:\n #+(or) `(let ((,formals (multiple-value-list ,expr)))\n ,@body)\n ;; But I want it to be possible to declare FORMALS to have\n ;; dynamic extent, and most Lisps support that for &rest\n ;; lists.\n `(multiple-value-call\n (lambda (&rest ,formals)\n ,@body)\n ,expr))\n ((proper-list-p formals)\n (when (intersection formals lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda ,formals\n ,@body)\n ,expr))\n (t (let* ((last (last formals))\n (vars (append (butlast formals)\n (list (car last))))\n (rest (cdr last)))\n (when (intersection (cons rest vars) lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda (,@vars &rest ,rest)\n ,@body)\n ,expr)))))", "macroexpand": "(multiple-value-call (lambda (new-k new-v) (dict* new new-k new-v)) (funcall fn k v))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(gatherlet nil\n (progn))\n\nIssue: Macro call that should be transformed by GATHERLET", "input": "(gatherlet nil\n (progn))", "output": "(defmacro GATHERLET ...)", "macroexpand": "(common-lisp:let ()\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-cache (\"foo\" :store storage) 1)\n\nProblem: Macro call that should be transformed by with-cache", "input": "(with-cache (\"foo\" :store storage) 1)", "output": "(defmacro with-cache ((key &key store expire) &body body)\n \"If a cache indicated by KEY exists, this just returns the cache\nvalue without evaluating BODY. Otherwise, this evaluates BODY and\nstores the evaluated value into STORE with KEY and EXPIRE. KEY is a\nform that an evaluated value indicates the cache key.\n\nExample:\n\n (defun f (x)\n (with-cache (x *store*)\n (very-complex-computation x)))\"\n (once-only (key store expire)\n (with-gensyms (value exists-p)\n `(multiple-value-bind (,value ,exists-p)\n (getcache ,key ,store)\n (if ,exists-p\n ,value\n (let ((,value (progn ,@body)))\n (setcache ,key ,value ,store :expire ,expire)\n ,value))))))", "macroexpand": "(let ((#:key232 \"foo\") (#:store233 storage) (#:expire234 nil)) (multiple-value-bind (#:value235 #:exists-p236) (getcache #:key232 #:store233) (if #:exists-p236 #:value235 (let ((#:value235 (progn 1))) (setcache #:key232 #:value235 #:store233 :expire #:expire234) #:value235))))", "category": "anaphoric", "technique": "once-only,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.85} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"58\" system-error)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"58\" system-error)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition system-error (database-error) nil) (setf (gethash \"58\" *error-table*) (quote system-error)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Generate a defmacro form that transforms code like this:\n(some-<>>\n 'some-name)\n\nPattern to recognize: Macro call that should be transformed by SOME-<>>", "input": "(some-<>>\n 'some-name)", "output": "(defmacro SOME-<>> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(f_%\n nil)\n\nProblem: Macro call that should be transformed by F_%", "input": "(f_%\n nil)", "output": "(defmacro F_% ...)", "macroexpand": "(lambda (&rest #:|ignore126|) (declare (ignore #:|ignore126|)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(finish T)\n\nPattern to recognize: Macro call that should be transformed by finish", "input": "(finish T)", "output": "(defmacro finish (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'finishing-result\n :expression '(finish ,form)\n :body (lambda () ,form)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote finishing-result) :expression (quote (finish t)) :body (lambda nil t)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(aprog1 :yes (unless (eql it :yes) (error \"Broken.\")) :no)\n\nProblem: Macro call that should be transformed by aprog1", "input": "(aprog1 :yes (unless (eql it :yes) (error \"Broken.\")) :no)", "output": "(defmacro aprog1 (first &body rest)\n \"Binds IT to the first form so that it can be used in the rest of the\nforms. The whole thing returns IT.\"\n `(anaphoric prog1 ,first ,@rest))", "macroexpand": "(anaphoric prog1 :yes (unless (eql it :yes) (error \"Broken.\")) :no)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(destructuring-bind* nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DESTRUCTURING-BIND*", "input": "(destructuring-bind* nil\n :key\n nil)", "output": "(defmacro DESTRUCTURING-BIND* ...)", "macroexpand": "(let (#:in-body134)\n (flet ((#:handle135 (#:condition136)\n (unless #:in-body134\n (error\n (make-condition 'destructuring-error :lambda-list 'nil\n :expression ':key :reason #:condition136)))))\n (declare (ignorable (function #:handle135)))\n (let ((#:value137 :key))\n (handler-bind ((error #'#:handle135))\n (destructuring-bind\n ()\n #:value137\n (setf #:in-body134 t)\n (locally nil))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(any-of nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ANY-OF", "input": "(any-of nil\n :key\n nil)", "output": "(defmacro ANY-OF ...)", "macroexpand": "(lc (nil :key nil) thereis)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when-let (previous (find-messenger name :manager manager)) (stop-messenger previous))\n\nIssue: Macro call that should be transformed by when-let", "input": "(when-let (previous (find-messenger name :manager manager)) (stop-messenger previous))", "output": "(defmacro when-let (binding &body body)\n (destructuring-bind (var val) binding\n `(let ((,var ,val))\n (when ,var\n\t ,@body))))", "macroexpand": "(let ((previous (find-messenger name :manager manager))) (when previous (stop-messenger previous)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-mocks () (register-mock 'foo/simple) (foo/simple) (pass))\n\nIssue: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (register-mock 'foo/simple) (foo/simple) (pass))", "output": "(defmacro with-mocks ((&key (recordp T)) &body body)\n \"Execute BODY in a new mocking context. Invocations will be recorded\nif RECORDP is set (default true).\"\n `(call-with-mocks\n (lambda () ,@body)\n :recordp ,recordp))", "macroexpand": "(call-with-mocks (lambda nil (register-mock (quote foo/simple)) (foo/simple) (pass)) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(macroexpand-convention (form) (if (consp form) (expand-export-class-using-head (first form) form) form))\n\nProblem: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (if (consp form) (expand-export-class-using-head (first form) form) form))", "output": "(defmacro macroexpand-convention ((original-form) &body body)\n \"Executes BODY as like `progn' and return the result as the first\nvalue. As the second value, returns a boolean whether the result is\nnot same with ORIGINAL-FORM or not.\nThis macro is designed to follow the `macroexpand' convention.\"\n `(multiple-value-bind (result expanded-p)\n (progn ,@body)\n (values result\n (or expanded-p\n (not (eq result ,original-form))))))", "macroexpand": "(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-class-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-alias-binding range ranging)\n\nWhat needs to change: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding range ranging)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote range)) (quote ranging)) (quote range))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-changing-vertex (vertex) (call-next-method))\n\nPattern to recognize: Macro call that should be transformed by with-changing-vertex", "input": "(with-changing-vertex (vertex) (call-next-method))", "output": "(defmacro with-changing-vertex ((vertex) &body body)\n \"This is used to maintain consistency when changing the value of vertex elements while iterating over the vertexes...\" \n (with-variables (v g)\n `(let* ((,v ,vertex)\n (,g (graph ,v)))\n (delete-item-at (graph-vertexes ,g) \n (funcall (vertex-key ,g) (element ,v))) \n ,@body\n (setf (item-at (graph-vertexes ,g) \n (funcall (vertex-key ,g) (element ,v))) ,v))))", "macroexpand": "(let* ((#:v0003 vertex) (#:g0004 (graph #:v0003))) (delete-item-at (graph-vertexes #:g0004) (funcall (vertex-key #:g0004) (element #:v0003))) (call-next-method) (setf (item-at (graph-vertexes #:g0004) (funcall (vertex-key #:g0004) (element #:v0003))) #:v0003))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(match 'some-name)\n\nIssue: Macro call that should be transformed by MATCH", "input": "(match 'some-name)", "output": "(defmacro MATCH ...)", "macroexpand": "(match* ('some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defjs map4() (emit this.name 1) (emit \"hello\" this.k))\n\nWrite a macro that addresses: Macro call that should be transformed by defjs", "input": "(defjs map4() (emit this.name 1) (emit \"hello\" this.k))", "output": "(defmacro defjs (name args &body body)\n \"Define client side javascript. Works like defun; body is in lisp, with parenscript\n additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. \n macro creates a lisp function which sends the javascript function over to the mongo \n server to be evaluated. Result is processed and returned to the reader. \n This will execute 10 times on the server :\n (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))\"\n `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))\n (setf (gethash ',name *js-definitions*) js-body)\n (defun ,name ,args\n (get-element \"retval\" (car (docs (db.eval js-body ,@args)))))))", "macroexpand": "(let* ((js-body (parenscript:ps (lambda nil (emit this.name 1) (emit \"hello\" this.k))))) (setf (gethash (quote map4) *js-definitions*) js-body) (defun map4 nil (get-element \"retval\" (car (docs (db.eval js-body))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) val))\n\nPattern to recognize: Macro call that should be transformed by c?-with-stored", "input": "(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) val))", "output": "(defmacro c?-with-stored ((var key store &optional default) &body body)\n `(c? (bwhen-c-stored (,var ,key ,store ,default)\n\t ,@body)))", "macroexpand": "(c? (bwhen-c-stored (v :foo store (quote nothing)) (bwhen (val (value v)) val)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(ematch0 list ((cons it nil) (cons (funcall fn it t) nil)) ((cons it rest) (cons (funcall fn it nil) (mapcar1-with-last fn rest))))\n\nPattern to recognize: Macro call that should be transformed by ematch0", "input": "(ematch0 list ((cons it nil) (cons (funcall fn it t) nil)) ((cons it rest) (cons (funcall fn it nil) (mapcar1-with-last fn rest))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 list ((cons it nil) (cons (funcall fn it t) nil)) ((cons it rest) (cons (funcall fn it nil) (mapcar1-with-last fn rest))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(skip () :report (lambda (s) (format s \"Skip the test ~S and all its dependencies.\" (name test))) (with-run-state (result-list) (push (make-instance 'test-skipped :reason \"Circular dependencies\" :test-case test) result-list)) (setf (status test) :circular))\n\nIssue: Macro call that should be transformed by skip", "input": "(skip () :report (lambda (s) (format s \"Skip the test ~S and all its dependencies.\" (name test))) (with-run-state (result-list) (push (make-instance 'test-skipped :reason \"Circular dependencies\" :test-case test) result-list)) (setf (status test) :circular))", "output": "(defmacro skip (&rest reason)\n \"Generates a TEST-SKIPPED result.\"\n `(add-result 'test-skipped :reason (format nil ,@reason)))", "macroexpand": "(add-result (quote test-skipped) :reason (format nil nil :report (lambda (s) (format s \"Skip the test ~S and all its dependencies.\" (name test))) (with-run-state (result-list) (push (make-instance (quote test-skipped) :reason \"Circular dependencies\" :test-case test) result-list)) (setf (status test) :circular)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-custom-var (:beginning-of-array *beginning-of-array-handler*))\n\nWrite a macro that addresses: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:beginning-of-array *beginning-of-array-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*beginning-of-array-handler* . :beginning-of-array)) *custom-vars* :test (function equal)) (defvar *beginning-of-array-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error args-incompatible () (previous-args current-args) \"Sorry but the output arguments from one stage are not compatible with the input arguments of the next.~%Out vars from previous stage: ~a~%In args from this stage: ~a\" previous-args current-args)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error args-incompatible () (previous-args current-args) \"Sorry but the output arguments from one stage are not compatible with the input arguments of the next.~%Out vars from previous stage: ~a~%In args from this stage: ~a\" previous-args current-args)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition args-incompatible (:error-type varjo-error :prefix \"Varjo\") (previous-args current-args) \"Sorry but the output arguments from one stage are not compatible with the input arguments of the next.~%Out vars from previous stage: ~a~%In args from this stage: ~a\" previous-args current-args)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-mustache-character #\\! (make-instance 'comment-tag :text \"\"))\n\nWhat needs to change: Macro call that should be transformed by define-mustache-character", "input": "(define-mustache-character #\\! (make-instance 'comment-tag :text \"\"))", "output": "(defmacro define-mustache-character (char &body body)\n `(set-mustache-character\n ,char (lambda (raw-text arg-text escapep start end)\n (declare (ignorable raw-text arg-text escapep start end)\n (type simple-string raw-text arg-text)\n (boolean escapep)\n (offset start end))\n ,@body)))", "macroexpand": "(set-mustache-character #\\EXCLAMATION_MARK (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote comment-tag) :text \"\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when (node-slot type) (make-proxy type type))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when (node-slot type) (make-proxy type type))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (node-slot type) (make-proxy type type))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(macroexpand-convention (form) (if (consp form) (expand-export-accessors-using-head (first form) form) form))\n\nIssue: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (if (consp form) (expand-export-accessors-using-head (first form) form) form))", "output": "(defmacro macroexpand-convention ((original-form) &body body)\n \"Executes BODY as like `progn' and return the result as the first\nvalue. As the second value, returns a boolean whether the result is\nnot same with ORIGINAL-FORM or not.\nThis macro is designed to follow the `macroexpand' convention.\"\n `(multiple-value-bind (result expanded-p)\n (progn ,@body)\n (values result\n (or expanded-p\n (not (eq result ,original-form))))))", "macroexpand": "(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-export-accessors-using-head (first form) form) form)) (values result (or expanded-p (not (eq result form)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-definition-resolver special-variable (designator) (eq :special (sb-cltl2:variable-information designator)))\n\nIssue: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver special-variable (designator) (eq :special (sb-cltl2:variable-information designator)))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver special-variable (special-variable #:package145) (when (ignore-errors (let ((designator special-variable)) (eq :special (sb-cltl2:variable-information designator)))) (list (make-instance (quote special-variable) :designator special-variable :package #:package145))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n($slot nil)\n\nPattern to recognize: Macro call that should be transformed by $SLOT", "input": "($slot nil)", "output": "(defmacro $SLOT ...)", "macroexpand": "(get-slot nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some-> 'some-name)\n\nProblem: Macro call that should be transformed by SOME->", "input": "(some-> 'some-name)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:g145 'some-name))\n #:g145)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-api readtable-name (named-readtable) (named-readtable-designator => symbol) \"Returns the name of the readtable designated by NAMED-READTABLE, or NIL.\" (let ((readtable (ensure-readtable named-readtable))) (cond ((%readtable-name readtable)) ((eq readtable *readtable*) :current) ((eq readtable *standard-readtable*) :common-lisp) ((eq readtable *case-preserving-standard-readtable*) :modern) (t nil))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-api", "input": "(define-api readtable-name (named-readtable) (named-readtable-designator => symbol) \"Returns the name of the readtable designated by NAMED-READTABLE, or NIL.\" (let ((readtable (ensure-readtable named-readtable))) (cond ((%readtable-name readtable)) ((eq readtable *readtable*) :current) ((eq readtable *standard-readtable*) :common-lisp) ((eq readtable *case-preserving-standard-readtable*) :modern) (t nil))))", "output": "(defmacro define-api (name lambda-list type-list &body body)\n (flet ((parse-type-list (type-list)\n (let ((pos (position '=> type-list)))\n (assert pos () \"You forgot to specify return type (`=>' missing.)\")\n (values (subseq type-list 0 pos)\n `(values ,@(nthcdr (1+ pos) type-list) &optional)))))\n (multiple-value-bind (body decls docstring)\n (parse-body body :documentation t :whole `(define-api ,name))\n (multiple-value-bind (arg-typespec value-typespec)\n (parse-type-list type-list)\n (multiple-value-bind (reqs opts rest keys)\n (parse-ordinary-lambda-list lambda-list)\n (declare (ignorable reqs opts rest keys))\n `(progn\n (declaim (ftype (function ,arg-typespec ,value-typespec) ,name))\n (locally\n ;; Muffle the annoying \"&OPTIONAL and &KEY found in\n ;; the same lambda list\" style-warning\n #+sbcl (declare (sb-ext:muffle-conditions style-warning))\n (defun ,name ,lambda-list\n ,docstring\n ,@decls\n (locally\n #+sbcl (declare (sb-ext:unmuffle-conditions style-warning))\n\n ;; SBCL will interpret the ftype declaration as\n ;; assertion and will insert type checks for us.\n #-sbcl\n (progn\n ;; CHECK-TYPE required parameters\n ,@(loop for req-arg in reqs\n for req-type = (pop type-list)\n do (assert req-type)\n collect `(check-type ,req-arg ,req-type))\n\n ;; CHECK-TYPE optional parameters\n ,@(progn\n (assert (or (null opts)\n (eq (pop type-list) '&optional)))\n (loop for (opt-arg . nil) in opts\n for opt-type = (pop type-list)\n do (assert opt-type)\n collect `(check-type ,opt-arg ,opt-type)))\n\n ;; CHECK-TYPE rest parameter\n ,@(when rest\n (assert (eq (pop type-list) '&rest))\n (let ((rest-type (pop type-list)))\n (assert rest-type)\n `((dolist (x ,rest)\n (check-type x ,rest-type)))))\n\n ;; CHECK-TYPE key parameters\n ,@(progn\n (assert (or (null keys)\n (eq (pop type-list) '&key)))\n (loop for ((keyword key-arg) . nil) in keys\n for (nil key-type) = (find keyword type-list\n :key #'car)\n collect `(check-type ,key-arg ,key-type))))\n\n ,@body)))))))))", "macroexpand": "(progn (declaim (ftype (function (named-readtable-designator) (values symbol &optional)) readtable-name)) (locally (declare (sb-ext:muffle-conditions style-warning)) (defun readtable-name (named-readtable) \"Returns the name of the readtable designated by NAMED-READTABLE, or NIL.\" (locally (declare (sb-ext:unmuffle-conditions style-warning)) (let ((readtable (ensure-readtable named-readtable))) (cond ((%readtable-name readtable)) ((eq readtable *readtable*) :current) ((eq readtable *standard-readtable*) :common-lisp) ((eq readtable *case-preserving-standard-readtable*) :modern) (t nil)))))))", "category": "efficiency", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(setypecase 'foo (string :nono))\n\nWrite a macro that addresses: Macro call that should be transformed by setypecase", "input": "(setypecase 'foo (string :nono))", "output": "(defmacro setypecase (keyform &body cases)\n \"Like ETYPECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for\nthe scope of the cases. IT can be set with SETF.\"\n `(symbolic etypecase ,keyform ,@cases))", "macroexpand": "(symbolic etypecase (quote foo) (string :nono))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(make-window-or-instance nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE", "input": "(make-window-or-instance nil nil)", "output": "(defmacro MAKE-WINDOW-OR-INSTANCE ...)", "macroexpand": "(make-$instance nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-generic generic (a b &key c) \"If :export-generic-name-p is true, export the name.\" (:export-generic-name-p t))\n\nProblem: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c) \"If :export-generic-name-p is true, export the name.\" (:export-generic-name-p t))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:documentation \"If :export-generic-name-p is true, export the name.\")) (eval-when (:compile-toplevel :load-toplevel :execute) (export (quote generic) #A((8) base-char . \"NCLASSES\"))) (setf (documentation (quote generic) (quote function)) \"If :export-generic-name-p is true, export the name.\") (setf (documentation (fdefinition (quote generic)) (quote function)) \"If :export-generic-name-p is true, export the name.\"))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cond-<>>\n nil\n nil)\n\nIssue: Macro call that should be transformed by COND-<>>", "input": "(cond-<>>\n nil\n nil)", "output": "(defmacro COND-<>> ...)", "macroexpand": "(let* ((#:var155 nil)\n (#:var156\n (if nil\n (-<>>\n #:var155)\n #:var155)))\n #:var156)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(inext-or-error nil (progn))\n\nProblem: Macro call that should be transformed by INEXT-OR-ERROR", "input": "(inext-or-error nil (progn))", "output": "(defmacro INEXT-OR-ERROR ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro nil) (progn)))))\n (if (not vals)\n (error 'stop-iteration)\n (values (car vals) t)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-neo4j-fun get-node-property (node-id property) :get (:uri-spec (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:status-handlers (200 (decode-neo4j-json-output body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'property-not-found-error :uri uri))))\n\nPattern to recognize: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-node-property (node-id property) :get (:uri-spec (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:status-handlers (200 (decode-neo4j-json-output body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'property-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-node-property (&key node-id property) (let ((uri (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))) (list 404 (lambda (body uri json) (error (quote property-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-table-name table-name-b (yield clause-b))\n\nIssue: Macro call that should be transformed by with-table-name", "input": "(with-table-name table-name-b (yield clause-b))", "output": "(defmacro with-table-name (table-name &body body)\n `(let ((*table-name-scope* ,table-name))\n ,@body))", "macroexpand": "(let ((*table-name-scope* table-name-b)) (yield clause-b))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(vect-of nil (progn))\n\nWhat needs to change: Macro call that should be transformed by VECT-OF", "input": "(vect-of nil (progn))", "output": "(defmacro VECT-OF ...)", "macroexpand": "(let ((#:vect139 (make-array 10 :adjustable t :fill-pointer 0)))\n (do-for ((progn))\n (vector-push-extend nil #:vect139))\n #:vect139)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(psetq nil nil)\n\nProblem: Macro call that should be transformed by PSETQ", "input": "(psetq nil nil)", "output": "(defmacro PSETQ ...)", "macroexpand": "(progn (setq nil nil) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defhandler setq (setq &rest pairs) (declare (ignore setq)) (let ((vars (loop for s in pairs by #'cddr collect (macroexpand s *env*)))) (let ((expanded (loop for n in vars for r in (rest pairs) by #'cddr collect n collect r))) (if (some 'listp vars) (e `(setf ,@expanded)) `(list 'setq ,@(e-list expanded))))))\n\nProblem: Macro call that should be transformed by defhandler", "input": "(defhandler setq (setq &rest pairs) (declare (ignore setq)) (let ((vars (loop for s in pairs by #'cddr collect (macroexpand s *env*)))) (let ((expanded (loop for n in vars for r in (rest pairs) by #'cddr collect n collect r))) (if (some 'listp vars) (e `(setf ,@expanded)) `(list 'setq ,@(e-list expanded))))))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-setq (setq &rest pairs) (declare (ignore setq)) (let ((vars (loop for s in pairs by (function cddr) collect (macroexpand s *env*)))) (let ((expanded (loop for n in vars for r in (rest pairs) by (function cddr) collect n collect r))) (if (some (quote listp) vars) (e (sb-int:quasiquote (setf #S(sb-impl::comma :expr expanded :kind 2)))) (sb-int:quasiquote (list (quote setq) #S(sb-impl::comma :expr (e-list expanded) :kind 2))))))) (setf (gethash (quote setq) *form-handler*) (quote hander-setq)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol))) (remove-local-preprocessor-macro state identifier)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol))) (remove-local-preprocessor-macro state identifier)))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (let ((identifier (pop-last-preprocessor-directive-token directive-token-list directive-symbol))) (remove-local-preprocessor-macro state identifier)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-quasi-quoted-bivalent-to-bivalent-emitting-form-syntax nil)\n\nPattern to recognize: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-TO-BIVALENT-EMITTING-FORM-SYNTAX", "input": "(enable-quasi-quoted-bivalent-to-bivalent-emitting-form-syntax nil)", "output": "(defmacro ENABLE-QUASI-QUOTED-BIVALENT-TO-BIVALENT-EMITTING-FORM-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-bivalent-to-bivalent-emitting-form-syntax-in-readtable nil\n :with-inline-emitting\n nil\n :declarations\n 'nil\n :start-character\n nil\n :end-character\n nil\n :unquote-character\n #\\COMMA\n :splice-character\n #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP\n :dispatched-quasi-quote-name\n \"biv\")\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(draw scene (:rect :x 40 :y 40 :height 30 :width 30) :stroke \"blue\" :stroke-width 1 :fill \"yellow\")\n\nProblem: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x 40 :y 40 :height 30 :width 30) :stroke \"blue\" :stroke-width 1 :fill \"yellow\")", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g143 (funcall (function make-svg-element) :rect (append (list :x 40 :y 40 :height 30 :width 30) (list :stroke \"blue\" :stroke-width 1 :fill \"yellow\"))))) (add-element scene #:g143) #:g143)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error for-loop-only-one-var () () \"for loops can only iterate over one variable\")\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error for-loop-only-one-var () () \"for loops can only iterate over one variable\")", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition for-loop-only-one-var (:error-type varjo-error :prefix \"Varjo\") nil \"for loops can only iterate over one variable\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-special-initargs nil)\n\nIssue: Macro call that should be transformed by WITH-SPECIAL-INITARGS", "input": "(with-special-initargs nil)", "output": "(defmacro WITH-SPECIAL-INITARGS ...)", "macroexpand": "(funcall-with-special-initargs (list) (lambda ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-rewrite cadar (expr) `(car (cdar ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cadar (expr) `(car (cdar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cadar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cdar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(->*\n nil\n nil)\n\nProblem: Macro call that should be transformed by ->*", "input": "(->*\n nil\n nil)", "output": "(defmacro ->* ...)", "macroexpand": "(let* ((#:var190 nil) (#:var191 (nil #:var190)))\n #:var191)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define SEEK_END 2)\n\nPattern to recognize: Macro call that should be transformed by define", "input": "(define SEEK_END 2)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote seek_end) *preprocessor-defines*) #A((1) base-char . \"2\"))) (defparameter seek_end 2))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(quasiquote nil (progn))\n\nWhat needs to change: Macro call that should be transformed by QUASIQUOTE", "input": "(quasiquote nil (progn))", "output": "(defmacro QUASIQUOTE ...)", "macroexpand": "(let ((#:source123 nil))\n (%append #:source123 (common-lisp:list (%quote #:source123 'progn))\n (%quote #:source123 'nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-neo4j-fun set-node-properties (node-id properties) :put (:encode properties :string) (:uri-spec (format nil \"node/~A/properties\" node-id)) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'node-not-found-error :uri uri))))\n\nWhat needs to change: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun set-node-properties (node-id properties) :put (:encode properties :string) (:uri-spec (format nil \"node/~A/properties\" node-id)) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'node-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun set-node-properties (&key node-id properties) (let ((uri (format nil \"node/~A/properties\" node-id)) (json (encode-neo4j-json-payload properties :string))) (make-neo4j-request :put uri json (list (list 204 (lambda (body uri json) (values t body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))) (list 404 (lambda (body uri json) (error (quote node-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-cruft %list-all-readtable-names () \"Return a list of all available readtable names.\" #+ :common-lisp (list* :standard :current :modern (loop for name being each hash-value of *readtable-names* collect name)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-cruft", "input": "(define-cruft %list-all-readtable-names () \"Return a list of all available readtable names.\" #+ :common-lisp (list* :standard :current :modern (loop for name being each hash-value of *readtable-names* collect name)))", "output": "(defmacro define-cruft (name lambda-list &body (docstring . alternatives))\n (assert (typep docstring 'string) (docstring) \"Docstring missing!\")\n (assert (not (null alternatives)))\n `(progn\n (declaim (inline ,name))\n (defun ,name ,lambda-list ,docstring ,(first alternatives))))", "macroexpand": "(progn (declaim (inline %list-all-readtable-names)) (defun %list-all-readtable-names nil \"Return a list of all available readtable names.\" (list* :standard :current :modern (loop for name being each hash-value of *readtable-names* collect name))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-shared-method nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFINE-SHARED-METHOD", "input": "(define-shared-method nil\n :key\n nil)", "output": "(defmacro DEFINE-SHARED-METHOD ...)", "macroexpand": "(define-incongruent-method incongruent-methods.methods::nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time self-evaluating? (thing) (and (not (consp thing)) (or (not (symbolp thing)) (null thing) (eq thing t) (eq (symbol-package thing) (symbol-package :x)))))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time self-evaluating? (thing) (and (not (consp thing)) (or (not (symbolp thing)) (null thing) (eq thing t) (eq (symbol-package thing) (symbol-package :x)))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun self-evaluating? (thing) (and (not (consp thing)) (or (not (symbolp thing)) (null thing) (eq thing t) (eq (symbol-package thing) (symbol-package :x))))) (eval-when (:compile-toplevel) (compile (quote self-evaluating?))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(alist-bind (name fields) form (let ((sym (foreign-type-symbol name :cunion *package*))) (let ((cunion-fields (parse-fields fields))) (when (symbol-package sym) (pushnew `(:union (,sym)) *foreign-record-list* :test #'equal)) `(define-foreign-record ',sym :union ,(aval :bit-size form) ,(aval :bit-alignment form) ',cunion-fields))))\n\nPattern to recognize: Macro call that should be transformed by alist-bind", "input": "(alist-bind (name fields) form (let ((sym (foreign-type-symbol name :cunion *package*))) (let ((cunion-fields (parse-fields fields))) (when (symbol-package sym) (pushnew `(:union (,sym)) *foreign-record-list* :test #'equal)) `(define-foreign-record ',sym :union ,(aval :bit-size form) ,(aval :bit-alignment form) ',cunion-fields))))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist242 form)) (let ((name (aval :name #:alist242)) (fields (aval :fields #:alist242))) (let ((sym (foreign-type-symbol name :cunion *package*))) (let ((cunion-fields (parse-fields fields))) (when (symbol-package sym) (pushnew (sb-int:quasiquote (:union (#S(sb-impl::comma :expr sym :kind 0)))) *foreign-record-list* :test (function equal))) (sb-int:quasiquote (define-foreign-record (quote #S(sb-impl::comma :expr sym :kind 0)) :union #S(sb-impl::comma :expr (aval :bit-size form) :kind 0) #S(sb-impl::comma :expr (aval :bit-alignment form) :kind 0) (quote #S(sb-impl::comma :expr cunion-fields :kind 0))))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-global-parameter nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER", "input": "(define-global-parameter nil :key nil)", "output": "(defmacro DEFINE-GLOBAL-PARAMETER ...)", "macroexpand": "(progn\n (store-in-symbol-plist nil :key .value-key.)\n (sb-ext:defglobal nil (get 'nil +value-key+))\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf nil (get 'nil +value-key+)))\n (remprop 'nil +value-key+)\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"08003\" connection-does-not-exist)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"08003\" connection-does-not-exist)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition connection-does-not-exist (database-error) nil) (setf (gethash \"08003\" *error-table*) (quote connection-does-not-exist)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> (take-while (lambda (c) (eql #\\a c))) (take-while (lambda (c) (or (eql #\\b c) (eql #\\c c) (eql #\\d c)))))\n\nIssue: Macro call that should be transformed by *>", "input": "(*> (take-while (lambda (c) (eql #\\a c))) (take-while (lambda (c) (or (eql #\\b c) (eql #\\c c) (eql #\\d c)))))", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset212) (multiple-value-bind (#:*>-res213 #:*>-next214) (funcall (take-while (lambda (c) (eql #\\LATIN_SMALL_LETTER_A c))) #:*>-offset212) (if (ok? #:*>-res213) (funcall (take-while (lambda (c) (or (eql #\\LATIN_SMALL_LETTER_B c) (eql #\\LATIN_SMALL_LETTER_C c) (eql #\\LATIN_SMALL_LETTER_D c)))) #:*>-next214) (fail #:*>-next214))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define SEEK_CUR 1)\n\nIssue: Macro call that should be transformed by define", "input": "(define SEEK_CUR 1)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote seek_cur) *preprocessor-defines*) #A((1) base-char . \"1\"))) (defparameter seek_cur 1))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(receive (k v) (apply fn args) (setf (gethash k hash-table) v))\n\nPattern to recognize: Macro call that should be transformed by receive", "input": "(receive (k v) (apply fn args) (setf (gethash k hash-table) v))", "output": "(defmacro receive (formals expr &body body)\n \"Stricter version of `multiple-value-bind'.\n\nUse `receive' when you want to enforce that EXPR should return a\ncertain number of values, or a minimum number of values.\n\nIf FORMALS is a proper list, then EXPR must return exactly as many\nvalues -- no more and no less -- as there are variables in FORMALS.\n\nIf FORMALS is an improper list (VARS . REST), then EXPR must return at\nleast as many values as there are VARS, and any further values are\nbound, as a list, to REST.\n\nLastly, if FORMALS is a symbol, bind that symbol to all the values\nreturned by EXPR, as if by `multiple-value-list'.\n\nFrom Scheme (SRFI-8).\"\n ;; It's probably not worth stack-allocating the thunk.\n (cond ((null formals)\n `(multiple-value-call\n (lambda ()\n ,@body)\n ,expr))\n ((atom formals)\n ;; This could also be written:\n #+(or) `(let ((,formals (multiple-value-list ,expr)))\n ,@body)\n ;; But I want it to be possible to declare FORMALS to have\n ;; dynamic extent, and most Lisps support that for &rest\n ;; lists.\n `(multiple-value-call\n (lambda (&rest ,formals)\n ,@body)\n ,expr))\n ((proper-list-p formals)\n (when (intersection formals lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda ,formals\n ,@body)\n ,expr))\n (t (let* ((last (last formals))\n (vars (append (butlast formals)\n (list (car last))))\n (rest (cdr last)))\n (when (intersection (cons rest vars) lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda (,@vars &rest ,rest)\n ,@body)\n ,expr)))))", "macroexpand": "(multiple-value-call (lambda (k v) (setf (gethash k hash-table) v)) (apply fn args))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-element-maker :clip-path \"clipPath\" '(:id))\n\nIssue: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :clip-path \"clipPath\" '(:id))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :clip-path)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:id)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :clip-path missing))))) (defmethod make-svg-element ((element (eql :clip-path)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"clipPath\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lambda* nil\n nil)\n\nIssue: Macro call that should be transformed by LAMBDA*", "input": "(lambda* nil\n nil)", "output": "(defmacro LAMBDA* ...)", "macroexpand": "(lambda ()\n (with-yield\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(match* (pattern qualifiers) (('* _) t) ((nil nil) t) (((type symbol) (type symbol)) (eql pattern qualifiers)) (((list* pfirst prest) (list* qualifier qualifiers)) (and (matches? qualifier pfirst) (matches? qualifiers prest))))\n\nIssue: Macro call that should be transformed by match*", "input": "(match* (pattern qualifiers) (('* _) t) ((nil nil) t) (((type symbol) (type symbol)) (eql pattern qualifiers)) (((list* pfirst prest) (list* qualifier qualifiers)) (and (matches? qualifier pfirst) (matches? qualifiers prest))))", "output": "(defmacro match* ((&rest things) &body clauses)\n `(multiple-value-match (values ,@things)\n ,@clauses))", "macroexpand": "(multiple-value-match (values pattern qualifiers) (((quote *) _) t) ((nil nil) t) (((type symbol) (type symbol)) (eql pattern qualifiers)) (((list* pfirst prest) (list* qualifier qualifiers)) (and (matches? qualifier pfirst) (matches? qualifiers prest))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*> +octothorp+ +skip-til-end+)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> +octothorp+ +skip-til-end+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset224) (multiple-value-bind (#:*>-res225 #:*>-next226) (funcall +octothorp+ #:*>-offset224) (if (ok? #:*>-res225) (funcall +skip-til-end+ #:*>-next226) (fail #:*>-next226))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-custom-var (:beginning-of-string *beginning-of-string-handler*))\n\nWrite a macro that addresses: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:beginning-of-string *beginning-of-string-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*beginning-of-string-handler* . :beginning-of-string)) *custom-vars* :test (function equal)) (defvar *beginning-of-string-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(sunless x (setf it :ok))\n\nIssue: Macro call that should be transformed by sunless", "input": "(sunless x (setf it :ok))", "output": "(defmacro sunless (test &body body)\n \"Like UNLESS, except binds the test form to IT (via SYMBOL-MACROLET) for the\nscope of the body. IT can be set with SETF.\"\n `(symbolic unless ,test ,@body))", "macroexpand": "(symbolic unless x (setf it :ok))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-space (call-next-method))\n\nProblem: Macro call that should be transformed by with-space", "input": "(with-space (call-next-method))", "output": "(defmacro with-space (&body body)\n (with-thunk (body)\n `(call-with-space ,body)))", "macroexpand": "(flet ((#:stack-fn-body1 nil (call-next-method))) (declare (dynamic-extent (function #:stack-fn-body1))) (symbol-macrolet ((#:stack-fn-body1 (function #:stack-fn-body1))) (call-with-space #:stack-fn-body1)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-active-layers nil)\n\nIssue: Macro call that should be transformed by WITH-ACTIVE-LAYERS", "input": "(with-active-layers nil)", "output": "(defmacro WITH-ACTIVE-LAYERS ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(serially (atomically nil () (decf counter)))\n\nProblem: Macro call that should be transformed by serially", "input": "(serially (atomically nil () (decf counter)))", "output": "(defmacro serially (&body flow)\n \"Executes child elements serially (but possibly in different threads)\nreturning a value of the last atomic block or flow. Non-consing.\"\n (with-flow-let-macro (flow-list flow)\n (flow-lambda-macro (flow-context)\n `(dispatch-serially ,flow-context ,flow-list))))", "macroexpand": "(let ((#:flow-list162 (list (atomically nil nil (decf counter))))) (%flow-lambda (#:flow-context163) (dispatch-serially #:flow-context163 #:flow-list162)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n;; Accessing pandoric variables requires verbose funcall\n(let ((sum (funcall box :pandoric-get 'sum))\n (count (funcall box :pandoric-get 'count)))\n (format t \"sum=~a count=~a~%\" sum count))\n\n;; Setting is even worse:\n(progn\n (funcall box :pandoric-set 'sum new-value)\n new-value)\n\n;; Want: regular variable syntax for pandoric access\n\nIssue: Pandoric get/set requires verbose keyword funcalls \u2014 want transparent variable syntax using symbol-macrolet", "input": ";; Accessing pandoric variables requires verbose funcall\n(let ((sum (funcall box :pandoric-get 'sum))\n (count (funcall box :pandoric-get 'count)))\n (format t \"sum=~a count=~a~%\" sum count))\n\n;; Setting is even worse:\n(progn\n (funcall box :pandoric-set 'sum new-value)\n new-value)\n\n;; Want: regular variable syntax for pandoric access", "output": "(defun get-pandoric (box sym)\n (funcall box :pandoric-get sym))\n\n(defsetf get-pandoric (box sym) (val)\n `(progn\n (funcall ,box :pandoric-set ,sym ,val)\n ,val))\n\n(defmacro with-pandoric (syms box &rest body)\n (let ((g!box (gensym \"box\")))\n `(let ((,g!box ,box))\n (declare (ignorable ,g!box))\n (symbol-macrolet\n (,@(mapcar #`(,a1 (get-pandoric ,g!box ',a1))\n syms))\n ,@body))))", "macroexpand": ";; (with-pandoric (sum count) #'counter\n;; (format t \"sum=~a count=~a~%\" sum count)\n;; (incf sum 10)\n;; (setf count 0))\n;;\n;; Expands to:\n;; (SYMBOL-MACROLET\n;; ((SUM (GET-PANDORIC #:BOX123 'SUM))\n;; (COUNT (GET-PANDORIC #:BOX123 'COUNT)))\n;; (FORMAT T \"sum=~a count=~a~%\" SUM COUNT)\n;; (INCF SUM 10)\n;; (SETF COUNT 0))\n;;\n;; Reading SUM expands to (GET-PANDORIC ... 'SUM)\n;; Writing SUM expands to setf -> get-pandoric setf expander", "category": "dispatch", "technique": "symbol-macrolet,defsetf,gensym", "complexity": "advanced", "quality_score": 0.9824999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-interpreter oid:+int2+ \"int2\" int 2)\n\nWrite a macro that addresses: Macro call that should be transformed by define-interpreter", "input": "(define-interpreter oid:+int2+ \"int2\" int 2)", "output": "(defmacro define-interpreter (oid name fields &body value)\n \"Shorthand for defining binary readers.\"\n (declare (ignore name)) ;; Names are there just for clarity\n `(set-sql-reader ,oid (binary-reader ,fields ,@value) :binary-p t))", "macroexpand": "(set-sql-reader cl-postgres-oid:+int2+ (binary-reader int 2) :binary-p t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-column-type enum (&rest candidates) `(:enum ,@(mapcar #'(lambda (candidate) (if (symbolp candidate) (symbol-name-literally candidate) candidate)) candidates)))\n\nWhat needs to change: Macro call that should be transformed by define-column-type", "input": "(define-column-type enum (&rest candidates) `(:enum ,@(mapcar #'(lambda (candidate) (if (symbolp candidate) (symbol-name-literally candidate) candidate)) candidates)))", "output": "(defmacro define-column-type (type-symbol lambda-list &body body)\n (let ((type (gensym \"TYPE\"))\n (args (gensym \"ARGS\")))\n `(defmethod cltype-to-dbtype ((,type (eql ',type-symbol)) &rest ,args)\n (declare (ignore ,type))\n (destructuring-bind ,lambda-list ,args\n ,@body))))", "macroexpand": "(defmethod cltype-to-dbtype ((#:type228 (eql (quote enum))) &rest #:args229) (declare (ignore #:type228)) (destructuring-bind (&rest candidates) #:args229 (sb-int:quasiquote (:enum #S(sb-impl::comma :expr (mapcar (function (lambda (candidate) (if (symbolp candidate) (symbol-name-literally candidate) candidate))) candidates) :kind 2)))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<>> nil :key nil)\n\nProblem: Macro call that should be transformed by -<>>", "input": "(-<>> nil :key nil)", "output": "(defmacro -<>> ...)", "macroexpand": "((:key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defgeneric* nil\n (progn))\n\nProblem: Macro call that should be transformed by DEFGENERIC*", "input": "(defgeneric* nil\n (progn))", "output": "(defmacro DEFGENERIC* ...)", "macroexpand": "(defgeneric (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-decoder-simple-clos-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :json-test))))\n\nWhat needs to change: Macro call that should be transformed by with-decoder-simple-clos-semantics", "input": "(with-decoder-simple-clos-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :json-test))))", "output": "(defmacro with-decoder-simple-clos-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-CLOS-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-clos-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-clos-semantics) (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (first-bound-slot-name x)) (find-package :json-test))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defvariant 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFVARIANT", "input": "(defvariant 'some-name)", "output": "(defmacro DEFVARIANT ...)", "macroexpand": "(progn\n (defstruct (quote (:constructor nil) some-name))\n (defmacro match-quote (expr &body match-cases)\n #A((36) base-char . \"Match values of variant type: QUOTE.\")\n (let ((expr-var (gensym \"-val\")))\n `(let ((,expr-var ,expr))\n ,(build-dispatch `,'quote `,'nil match-cases expr-var)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(assoc-cdr \"state\" parameters #'equal)\n\nWhat needs to change: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr \"state\" parameters #'equal)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc \"state\" parameters :test (function equal)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(check-cursor-attached cluffer:item-before-cursor (cursor))\n\nPattern to recognize: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:item-before-cursor (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:item-before-cursor :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*> (char #\\e) (alt (char #\\M) (char #\\m)))\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> (char #\\e) (alt (char #\\M) (char #\\m)))", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset169) (multiple-value-bind (#:*>-res170 #:*>-next171) (funcall (char #\\LATIN_SMALL_LETTER_E) #:*>-offset169) (if (ok? #:*>-res170) (funcall (alt (char #\\LATIN_CAPITAL_LETTER_M) (char #\\LATIN_SMALL_LETTER_M)) #:*>-next171) (fail #:*>-next171))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(binary-reader ((days int 4)) (funcall f days))\n\nProblem: Macro call that should be transformed by binary-reader", "input": "(binary-reader ((days int 4)) (funcall f days))", "output": "(defmacro binary-reader (fields &body value)\n \"A slightly convoluted macro for defining interpreter functions. It\nallows two forms. The first is to pass a single type identifier, in\nwhich case a value of this type will be read and returned directly.\nThe second is to pass a list of lists containing names and types, and\nthen a body. In this case the names will be bound to values read from\nthe socket and interpreted as the given types, and then the body will\nbe run in the resulting environment. If the last field is of type\nbytes, string, or uint2s, all remaining data will be read and\ninterpreted as an array of the given type.\"\n (let ((stream-name (gensym))\n (size-name (gensym))\n (length-used 0))\n (flet ((read-type (type &optional modifier)\n (ecase type\n (bytes `(read-bytes ,stream-name (- ,size-name ,length-used)))\n (string `(enc-read-string ,stream-name\n :byte-length (- ,size-name ,length-used)))\n (uint2s `(let* ((size (/ (- ,size-name ,length-used) 2))\n (result\n (make-array size\n :element-type '(unsigned-byte 16)\n :initial-element 0)))\n (dotimes (i size)\n (setf (elt result i) (read-uint2 ,stream-name)))\n result))\n (int (assert (integerp modifier))\n (incf length-used modifier)\n `(,(integer-reader-name modifier t) ,stream-name))\n (uint (assert (integerp modifier))\n (incf length-used modifier)\n `(,(integer-reader-name modifier nil) ,stream-name)))))\n `(lambda (,stream-name ,size-name)\n (declare (type stream ,stream-name)\n (type integer ,size-name)\n (ignorable ,size-name))\n ,(if (consp fields)\n (progn\n `(let ,(loop :for field :in fields\n :collect `(,(first field)\n ,(apply #'read-type (cdr field))))\n ,@value))\n (read-type fields (car value)))))))", "macroexpand": "(lambda (#:g206 #:g207) (declare (type stream #:g206) (type integer #:g207) (ignorable #:g207)) (let ((days (read-int4 #:g206))) (funcall f days)))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.825} {"instruction": "Generate a defmacro form that transforms code like this:\n(builder (lambda (app) (lambda (env) (funcall app env))) *app*)\n\nPattern to recognize: Macro call that should be transformed by builder", "input": "(builder (lambda (app) (lambda (env) (funcall app env))) *app*)", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (let ((#:res165 (lambda (app) (lambda (env) (funcall app env))))) (typecase #:res165 (keyword (find-middleware #:res165)) (cons (if (keywordp (car #:res165)) (let ((#:res-mw164 (find-middleware (car #:res165)))) (lambda (#:app163) (apply #:res-mw164 #:app163 (cdr #:res165)))) #:res165)) (standard-object (lambda (#:app163) (funcall (intern (string :wrap) :clack.middleware) #:res165 #:app163))) (otherwise #:res165))))) :initial-value (to-app *app*) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defvar-compile-time *ordered-lambda-list-keywords* '(&optional &rest &key &allow-other-keys &aux) \"The allowed lambda list keywords in order.\")\n\nPattern to recognize: Macro call that should be transformed by defvar-compile-time", "input": "(defvar-compile-time *ordered-lambda-list-keywords* '(&optional &rest &key &allow-other-keys &aux) \"The allowed lambda list keywords in order.\")", "output": "(defmacro defvar-compile-time (name &optional initial-value documentation)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,name ,initial-value ,documentation)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *ordered-lambda-list-keywords* (quote (&optional &rest &key &allow-other-keys &aux)) \"The allowed lambda list keywords in order.\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (<= less more))\n\nIssue: Macro call that should be transformed by is", "input": "(is (<= less more))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e128 less) (#:a129 more)) (if (progn (<= #:e128 #:a129)) (add-result (quote test-passed) :test-expr (quote (<= less more))) (process-failure (quote (<= less more)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote more) #:a129 (quote <=) #:e128)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(macroexpand-convention (form) (if (consp form) (expand-documentation-using-head (first form) docstring form) form))\n\nWhat needs to change: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (if (consp form) (expand-documentation-using-head (first form) docstring form) form))", "output": "(defmacro macroexpand-convention ((original-form) &body body)\n \"Executes BODY as like `progn' and return the result as the first\nvalue. As the second value, returns a boolean whether the result is\nnot same with ORIGINAL-FORM or not.\nThis macro is designed to follow the `macroexpand' convention.\"\n `(multiple-value-bind (result expanded-p)\n (progn ,@body)\n (values result\n (or expanded-p\n (not (eq result ,original-form))))))", "macroexpand": "(multiple-value-bind (result expanded-p) (progn (if (consp form) (expand-documentation-using-head (first form) docstring form) form)) (values result (or expanded-p (not (eq result form)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(action (:after node-application) #'apply-specialization)\n\nProblem: Macro call that should be transformed by action", "input": "(action (:after node-application) #'apply-specialization)", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-application) (function apply-specialization))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (< 0 -1))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (< 0 -1))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e192 0) (#:a193 -1)) (if (progn (< #:e192 #:a193)) (add-result (quote test-passed) :test-expr (quote (< 0 -1))) (process-failure (quote (< 0 -1)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote -1) #:a193 (quote <) #:e192)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(if-generator (x gen) nil (if fail-if-short (error 'insufficient-items \"Insufficient items in generator\") (return nil)))\n\nWrite a macro that addresses: Macro call that should be transformed by if-generator", "input": "(if-generator (x gen) nil (if fail-if-short (error 'insufficient-items \"Insufficient items in generator\") (return nil)))", "output": "(defmacro if-generator ((var gen) true-clause &optional false-clause)\n \"Pulls a single iteration out of gen. If a single var is specified, it places all the values from the iteration in a list under var. If var is a list, destructures values into the vars in the list. If the generator has stopped, evaluates false-clause, otherwise evaluates true-clause.\"\n `(,@(if (listp var)\n\t `(multiple-value-bind ,var\n\t (funcall ,gen))\n\t `(let ((,var (multiple-value-list (funcall ,gen))))))\n (if (eq 'generator-stop\n\t ,(if (listp var)\n\t\t (car var)\n\t\t `(car ,var)))\n\t ,false-clause\n\t ,true-clause)))", "macroexpand": "(let ((x (multiple-value-list (funcall gen)))) (if (eq (quote generator-stop) (car x)) (if fail-if-short (error (quote insufficient-items) \"Insufficient items in generator\") (return nil)) nil))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(m nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by M", "input": "(m nil\n :key\n nil)", "output": "(defmacro M ...)", "macroexpand": "(lambda (&rest #:|macro-lambda-list123|)\n (destructuring-bind () #:|macro-lambda-list123| :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-table-name nil (yield (when-op-left op)))\n\nIssue: Macro call that should be transformed by with-table-name", "input": "(with-table-name nil (yield (when-op-left op)))", "output": "(defmacro with-table-name (table-name &body body)\n `(let ((*table-name-scope* ,table-name))\n ,@body))", "macroexpand": "(let ((*table-name-scope* nil)) (yield (when-op-left op)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(summing-to total)\n\nIssue: Macro call that should be transformed by sum", "input": "(summing-to total)", "output": "(defmacro sum (value &key (to (error \"sum requires a target accumulator (:to key)\")))\n \"Syntactic sugar for collect, intended to be used when the accumulator computes a sum.\"\n `(collect ,value :into ,to))", "macroexpand": "(accumulating-to total :initially 0 :by (function +) :finally nil)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ignore-errors nil (progn))\n\nProblem: Macro call that should be transformed by IGNORE-ERRORS", "input": "(ignore-errors nil (progn))", "output": "(defmacro IGNORE-ERRORS ...)", "macroexpand": "(handler-case (progn nil (progn)) (error (condition) (values nil condition)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-path curvy (move-to 350 350))\n\nWhat needs to change: Macro call that should be transformed by with-path", "input": "(with-path curvy (move-to 350 350))", "output": "(defmacro with-path (path &body cmds)\n (let ((s (gensym \"stream\"))\n (n (gensym)))\n `(flet ((assert-string (s)\n (error-unless-string s)))\n (with-output-to-string (,s ,path)\n ;; Do trivial breaking up of the path data - SVG does not have\n ;; to accept indefinitely long lines of data.\n (let ((,n 0))\n (dolist (inst (mapcar #'assert-string (list ,@cmds)) (format ,s \"~&\"))\n (format ,s \"~@{~A~}\" inst)\n (incf ,n)\n (when (= (mod ,n 10) 0)\n (format ,s \"~&\"))))))))", "macroexpand": "(flet ((assert-string (s) (error-unless-string s))) (with-output-to-string (#:|stream136| curvy) (let ((#:g137 0)) (dolist (inst (mapcar (function assert-string) (list (move-to 350 350))) (format #:|stream136| \"~&\")) (format #:|stream136| \"~@{~A~}\" inst) (incf #:g137) (when (= (mod #:g137 10) 0) (format #:|stream136| \"~&\"))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-global-var nil (progn))\n\nProblem: Macro call that should be transformed by DEFINE-GLOBAL-VAR", "input": "(define-global-var nil (progn))", "output": "(defmacro DEFINE-GLOBAL-VAR ...)", "macroexpand": "(sb-ext:defglobal nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-modf-method pathname-type 1 (new-val path) (make-pathname :type new-val :defaults path))\n\nWrite a macro that addresses: Macro call that should be transformed by define-modf-method", "input": "(define-modf-method pathname-type 1 (new-val path) (make-pathname :type new-val :defaults path))", "output": "(defmacro define-modf-method (name nth-arg (new-val &rest args) &body body)\n \"Define a new modf method. It inverts NAME forms by modifying the NTH-ARG\nterm of the arguments of the place form in the MODF macro. This method can\nspecialize on any of ARGS.\"\n ;; Side effect in a macro, I know. How can you do this via EVAL-WHEN if I\n ;; want it to run even if not a toplevel macro?\n (setf (gethash name *modf-nth-arg*)\n nth-arg)\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-nth-arg*)\n ,nth-arg))\n (defmethod ,(intern (modf-name name) :modf) (,new-val ,@args)\n ,@body)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote pathname-type) *modf-nth-arg*) 1)) (defmethod |BUILDER:COMMON-LISP:PATHNAME-TYPE| (new-val path) (make-pathname :type new-val :defaults path)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (= 2 (length *toplevel-suites*)))\n\nIssue: Macro call that should be transformed by is", "input": "(is (= 2 (length *toplevel-suites*)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e280 2) (#:a281 (length *toplevel-suites*))) (if (progn (= #:e280 #:a281)) (add-result (quote test-passed) :test-expr (quote (= 2 (length *toplevel-suites*)))) (process-failure (quote (= 2 (length *toplevel-suites*))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (length *toplevel-suites*)) #:a281 (quote =) #:e280)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-mustache-character #\\> (make-instance 'partial-tag :text arg-text))\n\nIssue: Macro call that should be transformed by define-mustache-character", "input": "(define-mustache-character #\\> (make-instance 'partial-tag :text arg-text))", "output": "(defmacro define-mustache-character (char &body body)\n `(set-mustache-character\n ,char (lambda (raw-text arg-text escapep start end)\n (declare (ignorable raw-text arg-text escapep start end)\n (type simple-string raw-text arg-text)\n (boolean escapep)\n (offset start end))\n ,@body)))", "macroexpand": "(set-mustache-character #\\GREATER-THAN_SIGN (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote partial-tag) :text arg-text)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(declare-deprecated-operators 'some-name)\n\nProblem: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS", "input": "(declare-deprecated-operators 'some-name)", "output": "(defmacro DECLARE-DEPRECATED-OPERATORS ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (define-compiler-macro 'some-name\n (&whole form &rest arguments)\n (declare (ignore arguments))\n (let ((where-from (or *compile-file-truename* *load-truename*)))\n (when *deprecation-warnings*\n (warn 'deprecation-warning :operator-name ''some-name :source-file\n where-from :source-form form))\n (when where-from\n (pushnew where-from (gethash ''some-name *deprecation-locations*) :test\n #'equalp))\n form))\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-path-instruction-pair arc-to \"A\" (rx ry x-rotation large-arc-flag sweep-flag x y))\n\nIssue: Macro call that should be transformed by define-path-instruction-pair", "input": "(define-path-instruction-pair arc-to \"A\" (rx ry x-rotation large-arc-flag sweep-flag x y))", "output": "(defmacro define-path-instruction-pair (name instruction (&rest args))\n (let ((draw-relative (intern (concatenate 'string (string name) \"-R\"))))\n `(progn\n (defun ,name (,@args)\n (format-instruction ,instruction ,@args))\n (defun ,draw-relative (,@args)\n (format-instruction ,(string-downcase instruction) ,@args)))))", "macroexpand": "(progn (defun arc-to (rx ry x-rotation large-arc-flag sweep-flag x y) (format-instruction \"A\" rx ry x-rotation large-arc-flag sweep-flag x y)) (defun arc-to-r (rx ry x-rotation large-arc-flag sweep-flag x y) (format-instruction \"a\" rx ry x-rotation large-arc-flag sweep-flag x y)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(matrix-ctypecase 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by MATRIX-CTYPECASE", "input": "(matrix-ctypecase 'some-name)", "output": "(defmacro MATRIX-CTYPECASE ...)", "macroexpand": "(let ((#:g248 quote))\n (ctypecase #:g248))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(draw scene (:rect :x (- (random 750) 25) :y (- (random 750) 25) :rx 4 :ry 4 :height (+ 5 (random 65)) :width (+ 5 (random 65))) :stroke \"rgb(232, 229, 148)\" :opacity (+ 0.3 (random 0.2)) :fill (one-of *groovy-test-colors*))\n\nPattern to recognize: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x (- (random 750) 25) :y (- (random 750) 25) :rx 4 :ry 4 :height (+ 5 (random 65)) :width (+ 5 (random 65))) :stroke \"rgb(232, 229, 148)\" :opacity (+ 0.3 (random 0.2)) :fill (one-of *groovy-test-colors*))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g147 (funcall (function make-svg-element) :rect (append (list :x (- (random 750) 25) :y (- (random 750) 25) :rx 4 :ry 4 :height (+ 5 (random 65)) :width (+ 5 (random 65))) (list :stroke \"rgb(232, 229, 148)\" :opacity (+ 0.3 (random 0.2)) :fill (one-of *groovy-test-colors*)))))) (add-element scene #:g147) #:g147)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-option-expander intern (package &rest symbols) (mapcar #'(lambda (s) (intern (string s) package)) symbols))\n\nWhat needs to change: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander intern (package &rest symbols) (mapcar #'(lambda (s) (intern (string s) package)) symbols))", "output": "(defmacro define-option-expander (name (package &rest arguments) &body body)\n (let ((args (gensym \"ARGS\")))\n `(defmethod expand-option ((,(gensym \"TYPE\") (eql ,(intern (string name) \"KEYWORD\"))) ,package ,args)\n (destructuring-bind ,arguments ,args\n ,@body))))", "macroexpand": "(defmethod expand-option ((#:type136 (eql :intern)) package #:args135) (destructuring-bind (&rest symbols) #:args135 (mapcar (function (lambda (s) (intern (string s) package))) symbols)))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:div (:p \"Hello\") (:a \"world\")))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:div (:p \"Hello\") (:a \"world\")))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:div (:p \"Hello\") (:a \"world\"))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(draw scene (:path :d \"M 1000 750 L 2000 750 L 2500 1250\") :fill \"none\" :stroke \"black\" :stroke-width 100 :marker-end (xlink-href marker))\n\nProblem: Macro call that should be transformed by draw", "input": "(draw scene (:path :d \"M 1000 750 L 2000 750 L 2500 1250\") :fill \"none\" :stroke \"black\" :stroke-width 100 :marker-end (xlink-href marker))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g153 (funcall (function make-svg-element) :path (append (list :d \"M 1000 750 L 2000 750 L 2500 1250\") (list :fill \"none\" :stroke \"black\" :stroke-width 100 :marker-end (xlink-href marker)))))) (add-element scene #:g153) #:g153)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(assoc-cdr :message uinfo)\n\nProblem: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr :message uinfo)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc :message uinfo :test (function eql)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-op (:similar-to infix-op))\n\nWrite a macro that addresses: Macro call that should be transformed by define-op", "input": "(define-op (:similar-to infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (similar-to-op (:include infix-op (name \"SIMILAR TO\")) (:constructor make-similar-to-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(rem-bops nil :key nil)\n\nIssue: Macro call that should be transformed by REM-BOPS", "input": "(rem-bops nil :key nil)", "output": "(defmacro REM-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn (save-binfix) (mapc 'rmbop '(nil :key nil)) (assign-properties)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(who-ps-html nil)\n\nPattern to recognize: Macro call that should be transformed by WHO-PS-HTML", "input": "(who-ps-html nil)", "output": "(defmacro WHO-PS-HTML ...)", "macroexpand": "(stringify nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-compile-time walk-full (map-function form) (unless (null (rest (last form))) (error \"Improper FULL: ~S\" form)) (unless (= (length form) 2) (error \"FULL must have exactly one argument, a FORM: ~S\" form)) (funcall map-function form 'full))\n\nWhat needs to change: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-full (map-function form) (unless (null (rest (last form))) (error \"Improper FULL: ~S\" form)) (unless (= (length form) 2) (error \"FULL must have exactly one argument, a FORM: ~S\" form)) (funcall map-function form 'full))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-full (map-function form) (unless (null (rest (last form))) (error \"Improper FULL: ~S\" form)) (unless (= (length form) 2) (error \"FULL must have exactly one argument, a FORM: ~S\" form)) (funcall map-function form (quote full))) (eval-when (:compile-toplevel) (compile (quote walk-full))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-<>> nil)\n\nWrite a macro that addresses: Macro call that should be transformed by -<>>", "input": "(-<>> nil)", "output": "(defmacro -<>> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause-sequence in-string index-of-string :access-fn 'char :size-fn 'length :sequence-type 'string :element-type 'character :element-doc-string \"Characters in a string\" :index-doc-string \"Indices of a string\")\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause-sequence in-string index-of-string :access-fn 'char :size-fn 'length :sequence-type 'string :element-type 'character :element-doc-string \"Characters in a string\" :index-doc-string \"Indices of a string\")", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(progn (defclause-driver (for var in-string seq &sequence) \"Characters in a string\" (return-sequence-code :element-var var :sequence seq :access-fn (quote char) :size-fn (quote length) :element-type (quote character) :sequence-type (quote string))) (defclause-driver (for var index-of-string seq &sequence) \"Indices of a string\" (cond (with-index (clause-error \"WITH-INDEX should not be specified for this clause\")) (t (setq with-index var) (return-sequence-code :sequence seq :size-fn (quote length) :sequence-type (quote string))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(match 1 (2 2))\n\nWhat needs to change: Macro call that should be transformed by match", "input": "(match 1 (2 2))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(let ((#:var149 1)) (declare (ignorable #:var149)) (%or (%if (%equals #:var149 2) (%or 2 (fail)) (fail)) nil))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (< a (dummy-add a 1)))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (< a (dummy-add a 1)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e161 a) (#:a162 (dummy-add a 1))) (if (progn (< #:e161 #:a162)) (add-result (quote test-passed) :test-expr (quote (< a (dummy-add a 1)))) (process-failure (quote (< a (dummy-add a 1))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (dummy-add a 1)) #:a162 (quote <) #:e161)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym else :else)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym else :else)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote else) (quote synonym)) (quote :else)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-reader-syntax (run-program)- (is (string= \"hello world\" (er \"(with-output-to-string (*standard-output*) #!echo -n hello world )\"))))\n\nProblem: Macro call that should be transformed by with-reader-syntax", "input": "(with-reader-syntax (run-program)- (is (string= \"hello world\" (er \"(with-output-to-string (*standard-output*) #!echo -n hello world )\"))))", "output": "(defmacro with-reader-syntax (reader-macro-identifiers &body body)\n \"This macro is only made for use by read-and-eval functionality,\nand rather directed towards tests than users. So, do not export.\"\n (let ((identifiers (loop :for identifier :in reader-macro-identifiers\n :collect `(quote ,identifier))))\n `(let ((*array-function* 'make-t-array-from-initial-contents)\n (*hash-table-function* 'alexandria:plist-hash-table)\n (*get-val-function* 'get-val)\n (*get-val-array-function* 'cl:aref)\n (*set-function* 'cl:remove-duplicates)\n (*alists-are-lists* nil)\n (*plists-are-lists* nil)\n (*readtable* (%enable-reader-syntax *readtable* ,@identifiers)))\n ,@body)))", "macroexpand": "(let ((*array-function* (quote make-t-array-from-initial-contents)) (*hash-table-function* (quote alexandria:plist-hash-table)) (*get-val-function* (quote get-val)) (*get-val-array-function* (quote aref)) (*set-function* (quote remove-duplicates)) (*alists-are-lists* nil) (*plists-are-lists* nil) (*readtable* (%enable-reader-syntax *readtable* (quote run-program)))) - (is (string= \"hello world\" (er \"(with-output-to-string (*standard-output*) #!echo -n hello world )\"))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(prepend (default-driver-code) body)\n\nProblem: Macro call that should be transformed by prepend", "input": "(prepend (default-driver-code) body)", "output": "(defmacro prepend (stuff var)\n `(setf ,var (nconc ,stuff ,var)))", "macroexpand": "(setf body (nconc (default-driver-code) body))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:< infix-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:< infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (<-op (:include infix-op (name \"<\")) (:constructor make-<-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(unless 'some-name)\n\nIssue: Macro call that should be transformed by UNLESS", "input": "(unless 'some-name)", "output": "(defmacro UNLESS ...)", "macroexpand": "(if 'some-name\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> (char #\\a) (char #\\b))\n\nIssue: Macro call that should be transformed by *>", "input": "(*> (char #\\a) (char #\\b))", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset189) (multiple-value-bind (#:*>-res190 #:*>-next191) (funcall (char #\\LATIN_SMALL_LETTER_A) #:*>-offset189) (if (ok? #:*>-res190) (funcall (char #\\LATIN_SMALL_LETTER_B) #:*>-next191) (fail #:*>-next191))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield-binds (format nil (if *inside-function-op* \"(~A ~{~A~^ ~})\" \"~A ~{~A~^ ~}\") (sql-statement-name statement) (mapcar #'yield (sql-composed-statement-children statement))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil (if *inside-function-op* \"(~A ~{~A~^ ~})\" \"~A ~{~A~^ ~}\") (sql-statement-name statement) (mapcar #'yield (sql-composed-statement-children statement))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil (if *inside-function-op* \"(~A ~{~A~^ ~})\" \"~A ~{~A~^ ~}\") (sql-statement-name statement) (mapcar (function yield) (sql-composed-statement-children statement)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(rem-plist-val! nil (progn))\n\nProblem: Macro call that should be transformed by REM-PLIST-VAL!", "input": "(rem-plist-val! nil (progn))", "output": "(defmacro rem-plist-val! (id place &key (test '(default-test)) (key '(default-key)))\n `(setf ,place\n (rem-plist-val ,id ,place :test ,test :key ,key)))", "macroexpand": "(setf (progn)\n (rem-plist-val nil (progn) :test (default-test) :key (default-key)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error merge-env-func-scope-mismatch () (env-a env-b) \"Attempting to merge two environments with different function scopes ~s~%~s~%~s\" (cons (v-function-scope env-a) (v-function-scope env-b)) env-a env-b)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error merge-env-func-scope-mismatch () (env-a env-b) \"Attempting to merge two environments with different function scopes ~s~%~s~%~s\" (cons (v-function-scope env-a) (v-function-scope env-b)) env-a env-b)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition merge-env-func-scope-mismatch (:error-type varjo-error :prefix \"Varjo\") (env-a env-b) \"Attempting to merge two environments with different function scopes ~s~%~s~%~s\" (cons (v-function-scope env-a) (v-function-scope env-b)) env-a env-b)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(any-of nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ANY-OF", "input": "(any-of nil)", "output": "(defmacro ANY-OF ...)", "macroexpand": "(lc (nil) thereis)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(insert-char-class-tester (regex (schar *string* curr-pos)) (greedy-constant-length-closure (char-class-test)))\n\nProblem: Macro call that should be transformed by insert-char-class-tester", "input": "(insert-char-class-tester (regex (schar *string* curr-pos)) (greedy-constant-length-closure (char-class-test)))", "output": "(defmacro insert-char-class-tester ((char-class chr-expr) &body body)\n \"Utility macro to replace each occurence of '\\(CHAR-CLASS-TEST)\nwithin BODY with the correct test (corresponding to CHAR-CLASS)\nagainst CHR-EXPR.\"\n (with-rebinding (char-class)\n (with-unique-names (test-function)\n (flet ((substitute-char-class-tester (new)\n (subst new '(char-class-test) body\n :test #'equalp)))\n `(let ((,test-function (test-function ,char-class)))\n ,@(substitute-char-class-tester\n `(funcall ,test-function ,chr-expr)))))))", "macroexpand": "(let ((#:char-class157 regex)) (let ((#:test-function158 (test-function #:char-class157))) (greedy-constant-length-closure (funcall #:test-function158 (schar *string* curr-pos)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-simple-definition-resolver condition designator-condition-p)\n\nWrite a macro that addresses: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver condition designator-condition-p)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver condition (condition #:package138) (when (ignore-errors (designator-condition-p condition)) (list (make-instance (quote condition) :designator condition :package #:package138))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(labels* nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by LABELS*", "input": "(labels* nil\n nil)", "output": "(defmacro LABELS* ...)", "macroexpand": "(labels ()\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-component-testers (a b #'pathname-device) (components-are-member '(nil :unspecific)) (components-are-string=))\n\nPattern to recognize: Macro call that should be transformed by with-component-testers", "input": "(with-component-testers (a b #'pathname-device) (components-are-member '(nil :unspecific)) (components-are-string=))", "output": "(defmacro with-component-testers ((a b key) &body body)\n (let ((k (gensym)))\n `(let* ((,k ,key)\n (,a (funcall ,k ,a))\n (,b (funcall ,k ,b)))\n (labels ((components-are (test)\n (and (funcall test ,a) (funcall test ,b)))\n (components-are-member (values)\n (and (member ,a values :test #'eql)\n (member ,b values :test #'eql)\n (eql ,a ,b)))\n (components-are-string= ()\n (and (stringp ,a) (stringp ,b) (string= ,a ,b)))\n (components-are-every (test)\n (and (consp ,a)\n (consp ,b)\n (every test ,a ,b))))\n (declare (ignorable #'components-are #'components-are-member\n #'components-are-string= #'components-are-every))\n (if (or ,@body)\n (values t ,a ,b)\n nil)))))", "macroexpand": "(let* ((#:g144 (function pathname-device)) (a (funcall #:g144 a)) (b (funcall #:g144 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (components-are-member (quote (nil :unspecific))) (components-are-string=)) (values t a b) nil)))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(destructuring-case nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DESTRUCTURING-CASE", "input": "(destructuring-case nil\n (progn))", "output": "(defmacro DESTRUCTURING-CASE ...)", "macroexpand": "(destructuring-case-alt nil\n (progn nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is = (get-universal-time) 2962566000)\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is = (get-universal-time) 2962566000)", "output": "(defmacro is (comp expected form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(is ,comp ,expected ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected ,expected\n :comparison ,(maybe-quote comp)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (is = (get-universal-time) 2962566000)) :value-form (quote 2962566000) :body (lambda nil 2962566000) :expected (get-universal-time) :comparison (quote =)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(\u0192 'some-name)\n\nIssue: Macro call that should be transformed by \u0191", "input": "(\u0192 'some-name)", "output": "(defmacro \u0191 ...)", "macroexpand": "(defun 'some-name (&optional \u03b1)\n (let ((\u03b1 (or \u03b1 t)))\n (cond)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun/1 fgets (str n fd) (fgets-is-dumb str n fd nil))\n\nPattern to recognize: Macro call that should be transformed by defun/1", "input": "(defun/1 fgets (str n fd) (fgets-is-dumb str n fd nil))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun fgets (str n fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (fgets-is-dumb str n fd nil)) (defparameter fgets (vacietis.c:mkptr& (symbol-function (quote fgets)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(builder (:auth-basic :authenticator (lambda (user pass) (when (and (string= user \"nitro_idiot\") (string= pass \"password\")) (values t \"Eitaro Fukamachi\")))) (lambda (env) `(200 () (,(format nil \"Hello, ~A\" (getf env :remote-user))))))\n\nProblem: Macro call that should be transformed by builder", "input": "(builder (:auth-basic :authenticator (lambda (user pass) (when (and (string= user \"nitro_idiot\") (string= pass \"password\")) (values t \"Eitaro Fukamachi\")))) (lambda (env) `(200 () (,(format nil \"Hello, ~A\" (getf env :remote-user))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app188) (funcall (find-middleware :auth-basic) #:app188 :authenticator (lambda (user pass) (when (and (string= user \"nitro_idiot\") (string= pass \"password\")) (values t \"Eitaro Fukamachi\"))))))) :initial-value (to-app (lambda (env) (sb-int:quasiquote (200 nil (#S(sb-impl::comma :expr (format nil \"Hello, ~A\" (getf env :remote-user)) :kind 0)))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> :g () (put 0) t)\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> :g () (put 0) t)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g nil (put 0) t)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(alist-bind ((type-tag :tag)) type (cond ((or (string= \":char\" type-tag) (string= \":unsigned-char\" type-tag)) '((:string))) (t `((:pointer ,@(parse-type type type-tag))))))\n\nProblem: Macro call that should be transformed by alist-bind", "input": "(alist-bind ((type-tag :tag)) type (cond ((or (string= \":char\" type-tag) (string= \":unsigned-char\" type-tag)) '((:string))) (t `((:pointer ,@(parse-type type type-tag))))))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist235 type)) (let ((type-tag (aval :tag #:alist235))) (cond ((or (string= \":char\" type-tag) (string= \":unsigned-char\" type-tag)) (quote ((:string)))) (t (sb-int:quasiquote ((:pointer #S(sb-impl::comma :expr (parse-type type type-tag) :kind 2))))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-instance* 'class :c c :b b (when something (list :a a)))\n\nIssue: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class :c c :b b (when something (list :a a)))", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(apply (function make-instance) (quote class) :c c :b b (when something (list :a a)))", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9624999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-mustache-character #\\# (make-instance 'section-start-tag :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*))\n\nWhat needs to change: Macro call that should be transformed by define-mustache-character", "input": "(define-mustache-character #\\# (make-instance 'section-start-tag :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*))", "output": "(defmacro define-mustache-character (char &body body)\n `(set-mustache-character\n ,char (lambda (raw-text arg-text escapep start end)\n (declare (ignorable raw-text arg-text escapep start end)\n (type simple-string raw-text arg-text)\n (boolean escapep)\n (offset start end))\n ,@body)))", "macroexpand": "(set-mustache-character #\\NUMBER_SIGN (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-start-tag) :text arg-text :end end :open-delimiter *open-delimiter* :close-delimiter *close-delimiter*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dreletf* nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DRELETF*", "input": "(dreletf* nil\n :key\n nil)", "output": "(defmacro DRELETF* ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(labels* nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by LABELS*", "input": "(labels* nil\n :key\n nil)", "output": "(defmacro LABELS* ...)", "macroexpand": "(labels ()\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-additional-indent (reporter stream \"~& \") (with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (when (slot-value report 'description) (format/indent reporter stream \"~A~%\" (slot-value report 'description))) (format/indent reporter stream \"Raised an error ~A (expected: ~S)\" (slot-value report 'got) (slot-value report 'expected)))))\n\nWhat needs to change: Macro call that should be transformed by with-additional-indent", "input": "(with-additional-indent (reporter stream \"~& \") (with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (when (slot-value report 'description) (format/indent reporter stream \"~A~%\" (slot-value report 'description))) (format/indent reporter stream \"Raised an error ~A (expected: ~S)\" (slot-value report 'got) (slot-value report 'expected)))))", "output": "(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)\n (declare (ignorable reporter stream control-string))\n (let* ((need-new-line (ppcre:scan \"^~&\" control-string))\n (string (apply #'format nil control-string format-arguments))\n (increment (length string)))\n `(with-slots (indent-space) reporter\n (let* ((first-line-indent (indent indent-space))\n (*additional-indent* ,(if need-new-line\n increment\n `(+ *additional-indent*\n ,increment))))\n (declare (ignorable first-line-indent))\n ,(if need-new-line\n `(progn (fresh-line stream)\n (write-string first-line-indent ,stream)\n ;; because we just started a new line, we\n ;; should use format/indent to write string\n ;; taking into account a main indentation level\n (format/indent ,reporter ,stream ,string))\n ;; otherwise, just output our prefix\n `(write-string ,string ,stream))\n \n \n ,@body))))", "macroexpand": "(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* 1)) (declare (ignorable first-line-indent)) (progn (fresh-line stream) (write-string first-line-indent stream) (format/indent reporter stream #A((1) base-char . \" \"))) (with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (when (slot-value report (quote description)) (format/indent reporter stream \"~A~%\" (slot-value report (quote description)))) (format/indent reporter stream \"Raised an error ~A (expected: ~S)\" (slot-value report (quote got)) (slot-value report (quote expected)))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun/1 fopen (filename mode) (handler-case (make-instance 'FILE :stream (open-stream filename mode)) (file-error () (setf errno ENOENT) NULL) (error () NULL)))\n\nWrite a macro that addresses: Macro call that should be transformed by defun/1", "input": "(defun/1 fopen (filename mode) (handler-case (make-instance 'FILE :stream (open-stream filename mode)) (file-error () (setf errno ENOENT) NULL) (error () NULL)))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun fopen (filename mode) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (make-instance (quote file) :stream (open-stream filename mode)) (file-error nil (setf errno enoent) null) (error nil null))) (defparameter fopen (vacietis.c:mkptr& (symbol-function (quote fopen)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(bind (((:flet doit (x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))\n\nProblem: Macro call that should be transformed by bind", "input": "(bind (((:flet doit (x)) (setf x (* 2 x)) (setf x (+ x 3)) x)) (ensure-same (doit 1) 5) (ensure-same (doit 2) 7))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(flet ((doit (x) (progn (setf x (* 2 x)) (setf x (+ x 3)) x))) (progn (ensure-same (doit 1) 5) (ensure-same (doit 2) 7)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(iterate:display-iterate-clauses)\n\nPattern to recognize: Macro call that should be transformed by iterate", "input": "(iterate:display-iterate-clauses)", "output": "(defmacro iterate (&body body)\n \"Jonathan Amsterdam's powerful iteration facility\"\n `(iter .,body))", "macroexpand": "(display-iterate-clauses)", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-rewrite eighth (expr) `(cadddr (cddddr ,(second expr))))\n\nPattern to recognize: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite eighth (expr) `(cadddr (cddddr ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote eighth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cadddr (cddddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym search :find)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym search :find)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote search) (quote synonym)) (quote :find)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-window-or-instance nil :key nil)\n\nIssue: Macro call that should be transformed by MAKE-WINDOW-OR-INSTANCE", "input": "(make-window-or-instance nil :key nil)", "output": "(defmacro MAKE-WINDOW-OR-INSTANCE ...)", "macroexpand": "(make-$instance nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-additional-indent (reporter stream \"~& \") (with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report 'slow-threshold)))) (when (slot-value report 'description) (format/indent reporter stream (concatenate 'string \"~&\" (report-expected-line report))))) (terpri stream)))\n\nProblem: Macro call that should be transformed by with-additional-indent", "input": "(with-additional-indent (reporter stream \"~& \") (with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report 'slow-threshold)))) (when (slot-value report 'description) (format/indent reporter stream (concatenate 'string \"~&\" (report-expected-line report))))) (terpri stream)))", "output": "(defmacro with-additional-indent ((reporter stream control-string &rest format-arguments) &body body)\n (declare (ignorable reporter stream control-string))\n (let* ((need-new-line (ppcre:scan \"^~&\" control-string))\n (string (apply #'format nil control-string format-arguments))\n (increment (length string)))\n `(with-slots (indent-space) reporter\n (let* ((first-line-indent (indent indent-space))\n (*additional-indent* ,(if need-new-line\n increment\n `(+ *additional-indent*\n ,increment))))\n (declare (ignorable first-line-indent))\n ,(if need-new-line\n `(progn (fresh-line stream)\n (write-string first-line-indent ,stream)\n ;; because we just started a new line, we\n ;; should use format/indent to write string\n ;; taking into account a main indentation level\n (format/indent ,reporter ,stream ,string))\n ;; otherwise, just output our prefix\n `(write-string ,string ,stream))\n \n \n ,@body))))", "macroexpand": "(with-slots (indent-space) reporter (let* ((first-line-indent (indent indent-space)) (*additional-indent* 1)) (declare (ignorable first-line-indent)) (progn (fresh-line stream) (write-string first-line-indent stream) (format/indent reporter stream #A((1) base-char . \" \"))) (with-color (:red :stream stream) (with-additional-indent (reporter stream \"\u00d7 \") (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (format/indent reporter stream description)) (when duration (format stream \" \") (print-duration stream duration (slot-value report (quote slow-threshold))))) (when (slot-value report (quote description)) (format/indent reporter stream (concatenate (quote string) \"~&\" (report-expected-line report))))) (terpri stream))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n;; Depth-first search with manual backtracking\n(defun search (node)\n (if (goal-p node)\n node\n (let ((children (expand node)))\n (when children\n (let ((result (search (car children))))\n (if result\n result\n (when (cdr children)\n (search (cadr children)))))))))\n;; Manual backtracking is error-prone and obscures the search logic\n\nPattern to recognize: Search/backtracking algorithms require manual state management \u2014 want implicit backtracking via nondeterministic choice", "input": ";; Depth-first search with manual backtracking\n(defun search (node)\n (if (goal-p node)\n node\n (let ((children (expand node)))\n (when children\n (let ((result (search (car children))))\n (if result\n result\n (when (cdr children)\n (search (cadr children)))))))))\n;; Manual backtracking is error-prone and obscures the search logic", "output": "(defparameter *paths* nil)\n(defconstant failsym '@)\n\n(defmacro choose (&rest choices)\n (if choices\n `(progn\n ,@(mapcar #'(lambda (c)\n `(push #'(lambda () ,c) *paths*))\n (reverse (cdr choices)))\n ,(car choices))\n '(fail)))\n\n(defmacro choose-bind (var choices &body body)\n `(cb #'(lambda (,var) ,@body) ,choices))\n\n(defun cb (fn choices)\n (if choices\n (progn\n (if (cdr choices)\n (push #'(lambda () (cb fn (cdr choices)))\n *paths*))\n (funcall fn (car choices)))\n (fail)))\n\n(defun fail ()\n (if *paths*\n (funcall (pop *paths*))\n failsym))", "macroexpand": ";; (defun search (node)\n;; (if (goal-p node)\n;; node\n;; (let ((child (choose (expand node))))\n;; (search child))))\n;;\n;; choose pushes alternatives onto *paths*, executes the first.\n;; When fail is called, it pops the next alternative and retries.\n;; The backtracking is implicit - code reads like depth-first search.\n;;\n;; (choose-bind x '(1 2 3 4 5)\n;; (when (evenp x) (return x)))\n;; => 2 (first even value)", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defjs reduce7(k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))\n\nWrite a macro that addresses: Macro call that should be transformed by defjs", "input": "(defjs reduce7(k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))", "output": "(defmacro defjs (name args &body body)\n \"Define client side javascript. Works like defun; body is in lisp, with parenscript\n additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. \n macro creates a lisp function which sends the javascript function over to the mongo \n server to be evaluated. Result is processed and returned to the reader. \n This will execute 10 times on the server :\n (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))\"\n `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))\n (setf (gethash ',name *js-definitions*) js-body)\n (defun ,name ,args\n (get-element \"retval\" (car (docs (db.eval js-body ,@args)))))))", "macroexpand": "(let* ((js-body (parenscript:ps (lambda (k vals) (let ((sum 0) (index 0)) (dolist (c vals) (if (= index 3) (return c) (progn (incf index 1) (incf sum c)))) (return sum)))))) (setf (gethash (quote reduce7) *js-definitions*) js-body) (defun reduce7 (k vals) (get-element \"retval\" (car (docs (db.eval js-body k vals))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defparameter* nil :key nil)\n\nIssue: Macro call that should be transformed by DEFPARAMETER*", "input": "(defparameter* nil :key nil)", "output": "(defmacro DEFPARAMETER* ...)", "macroexpand": "(defvar/param defparameter nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error loop-will-never-halt () (test-code test-obj) \"The loop is using the following code as it's test.~%~a~%~%This will only ever result in a ~a which means the loop will never halt\" test-code (type->type-spec (primary-type test-obj)))\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error loop-will-never-halt () (test-code test-obj) \"The loop is using the following code as it's test.~%~a~%~%This will only ever result in a ~a which means the loop will never halt\" test-code (type->type-spec (primary-type test-obj)))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition loop-will-never-halt (:error-type varjo-error :prefix \"Varjo\") (test-code test-obj) \"The loop is using the following code as it's test.~%~a~%~%This will only ever result in a ~a which means the loop will never halt\" test-code (type->type-spec (primary-type test-obj)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-generic generic (a b &key c) (:method-combination progn))\n\nProblem: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c) (:method-combination progn))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:method-combination progn)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-unique-js-names nil :key nil)\n\nProblem: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES", "input": "(with-unique-js-names nil :key nil)", "output": "(defmacro WITH-UNIQUE-JS-NAMES ...)", "macroexpand": "(with-ps-gensyms nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-inactive-layers 'some-name)\n\nPattern to recognize: Macro call that should be transformed by WITH-INACTIVE-LAYERS", "input": "(with-inactive-layers 'some-name)", "output": "(defmacro WITH-INACTIVE-LAYERS ...)", "macroexpand": "(dynamic-wind\n :proceed\n #:proceed211\n (%with-inactive-layers 'some-name\n (#:proceed211)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-standard-readtable\n 'some-name)\n\nProblem: Macro call that should be transformed by WITH-STANDARD-READTABLE", "input": "(with-standard-readtable\n 'some-name)", "output": "(defmacro WITH-STANDARD-READTABLE ...)", "macroexpand": "(bind ((*readtable* (with-standard-io-syntax (copy-readtable *readtable*))))\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:input :type \"password\" :name \"password\" :class \"form-control\" :id \"password\" :required t))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:input :type \"password\" :name \"password\" :class \"form-control\" :id \"password\" :required t))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:input :type \"password\" :name \"password\" :class \"form-control\" :id \"password\" :required t)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-yield-binds (format nil \"(~A ~A ~A)\" (f (infix-op-left op)) (sql-op-name op) (f (infix-op-right op))))\n\nProblem: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"(~A ~A ~A)\" (f (infix-op-left op)) (sql-op-name op) (f (infix-op-right op))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"(~A ~A ~A)\" (f (infix-op-left op)) (sql-op-name op) (f (infix-op-right op)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(mapping nil)\n\nPattern to recognize: Macro call that should be transformed by MAPPING", "input": "(mapping nil)", "output": "(defmacro MAPPING ...)", "macroexpand": "(mapping-mac nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deferror \"57P02\" crash-shutdown server-shutdown)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"57P02\" crash-shutdown server-shutdown)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition crash-shutdown (server-shutdown) nil) (setf (gethash \"57P02\" *error-table*) (quote crash-shutdown)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym as :for)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym as :for)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote as) (quote synonym)) (quote :for)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-cruft %get-macro-character (char rt) \"Ensure ANSI behaviour for GET-MACRO-CHARACTER.\" #+ :allegro (let ((fn (get-macro-character char rt))) (cond ((not fn) nil) ((function= fn #'excl::read-token) nil) (t fn))) #+ :cmucl (let ((fn (get-macro-character char rt))) (cond ((not fn) nil) ((function= fn #'lisp::read-token) nil) (t fn))) #+ :common-lisp (get-macro-character char rt))\n\nWhat needs to change: Macro call that should be transformed by define-cruft", "input": "(define-cruft %get-macro-character (char rt) \"Ensure ANSI behaviour for GET-MACRO-CHARACTER.\" #+ :allegro (let ((fn (get-macro-character char rt))) (cond ((not fn) nil) ((function= fn #'excl::read-token) nil) (t fn))) #+ :cmucl (let ((fn (get-macro-character char rt))) (cond ((not fn) nil) ((function= fn #'lisp::read-token) nil) (t fn))) #+ :common-lisp (get-macro-character char rt))", "output": "(defmacro define-cruft (name lambda-list &body (docstring . alternatives))\n (assert (typep docstring 'string) (docstring) \"Docstring missing!\")\n (assert (not (null alternatives)))\n `(progn\n (declaim (inline ,name))\n (defun ,name ,lambda-list ,docstring ,(first alternatives))))", "macroexpand": "(progn (declaim (inline %get-macro-character)) (defun %get-macro-character (char rt) \"Ensure ANSI behaviour for GET-MACRO-CHARACTER.\" (get-macro-character char rt)))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(finishes (signals error (error \"an error\")))\n\nProblem: Macro call that should be transformed by finishes", "input": "(finishes (signals error (error \"an error\")))", "output": "(defmacro finishes (&body body)\n \"Generates a pass if BODY executes to normal completion. In\nother words if body does signal, return-from or throw this test\nfails.\"\n `(unwind-protect-case () (progn ,@body)\n (:normal (add-result 'test-passed :test-expr ',body))\n (:abort (process-failure ',body \"Test didn't finish\"))))", "macroexpand": "(unwind-protect-case nil (progn (signals error (error \"an error\"))) (:normal (add-result (quote test-passed) :test-expr (quote ((signals error (error \"an error\")))))) (:abort (process-failure (quote ((signals error (error \"an error\")))) \"Test didn't finish\")))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-generator (g generator) (yield g) (incf count) (when (= count n) (yield 'generator-stop)))\n\nWhat needs to change: Macro call that should be transformed by do-generator", "input": "(do-generator (g generator) (yield g) (incf count) (when (= count n) (yield 'generator-stop)))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g167 generator)) (loop do (if-generator ((g) #:g167) (progn (yield g) (incf count) (when (= count n) (yield (quote generator-stop)))) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-method-combination% + :operator + :identity-with-one-argument t)\n\nWhat needs to change: Macro call that should be transformed by define-method-combination%", "input": "(define-method-combination% + :operator + :identity-with-one-argument t)", "output": "(defmacro define-method-combination% (name &rest args)\n \"Define a method-combination for the static-dispatch system only.\n\n Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION.\"\n\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf\n (combination-function ',name)\n ,(match args\n ((or nil\n (list* (and (type symbol) (not nil)) _))\n\n (destructuring-bind (&key (operator name) (identity-with-one-argument nil))\n args\n\n `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))\n\n (_\n `(method-combination-function ,name ,@args))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote +)) (method-combination-function-short + + t)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-bop nil)\n\nIssue: Macro call that should be transformed by DEF-BOP", "input": "(def-bop nil)", "output": "(defmacro DEF-BOP ...)", "macroexpand": "t", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(once-only* args (let ((else `(cerror \"Continue.\" 'match-error :values (list ,@args) :patterns ',(mapcar #'car clauses)))) (compile-match args clauses else)))\n\nPattern to recognize: Macro call that should be transformed by once-only*", "input": "(once-only* args (let ((else `(cerror \"Continue.\" 'match-error :values (list ,@args) :patterns ',(mapcar #'car clauses)))) (compile-match args clauses else)))", "output": "(defmacro once-only* (symbol &body body)\n (with-unique-names (form var vars bindings)\n `(let (,vars ,bindings)\n (dolist (,form ,symbol)\n (if (symbolp ,form)\n (push ,form ,vars)\n (let ((,var (gensym \"VAR\")))\n (push ,var ,vars)\n (push (list ,var ,form) ,bindings))))\n (setq ,vars (nreverse ,vars)\n ,bindings (nreverse ,bindings))\n (if ,bindings\n `(let ,,bindings\n ;(declare (ignorable ,@(mapcar #'car ,bindings)))\n ,(let ((,symbol ,vars))\n ,@body))\n (progn ,@body)))))", "macroexpand": "(let (#:vars170 #:bindings171) (dolist (#:form168 args) (if (symbolp #:form168) (push #:form168 #:vars170) (let ((#:var169 (gensym \"VAR\"))) (push #:var169 #:vars170) (push (list #:var169 #:form168) #:bindings171)))) (setq #:vars170 (nreverse #:vars170) #:bindings171 (nreverse #:bindings171)) (if #:bindings171 (sb-int:quasiquote (let #S(sb-impl::comma :expr #:bindings171 :kind 0) #S(sb-impl::comma :expr (let ((args #:vars170)) (let ((else (sb-int:quasiquote (cerror \"Continue.\" (quote match-error) :values (list #S(sb-impl::comma :expr args :kind 2)) :patterns (quote #S(sb-impl::comma :expr (mapcar (function car) clauses) :kind 0)))))) (compile-match args clauses else))) :kind 0))) (progn (let ((else (sb-int:quasiquote (cerror \"Continue.\" (quote match-error) :values (list #S(sb-impl::comma :expr args :kind 2)) :patterns (quote #S(sb-impl::comma :expr (mapcar (function car) clauses) :kind 0)))))) (compile-match args clauses else)))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(some->\n 'some-name)\n\nWhat needs to change: Macro call that should be transformed by SOME->", "input": "(some->\n 'some-name)", "output": "(defmacro SOME-> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(check-cursor-attached cluffer:split-line (cursor))\n\nPattern to recognize: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:split-line (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:split-line :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(appending 'some-name)\n\nIssue: Macro call that should be transformed by APPENDING", "input": "(appending 'some-name)", "output": "(defmacro APPENDING ...)", "macroexpand": "(with-appender-output (output)\n (dolist (quote (alexandria:ensure-list some-name))\n (restart-case (output (progn))\n (skip nil \"Skip this element\"))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-condition/a dbi-warning (simple-warning) () (:documentation \"For important warnings like data truncation, etc.\"))\n\nWrite a macro that addresses: Macro call that should be transformed by define-condition/a", "input": "(define-condition/a dbi-warning (simple-warning) () (:documentation \"For important warnings like data truncation, etc.\"))", "output": "(defmacro define-condition/a (name parent-types slots &body options)\n `(progn\n (define-condition ,name ,parent-types ,slots ,@options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (define-condition dbi-warning (simple-warning) nil (:documentation \"For important warnings like data truncation, etc.\")) (deftype nil (quote dbi-warning)) (setf (find-class (quote )) (find-class (quote dbi-warning))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(augment init-code (do-extra-save-var-hack var save-info-list code-list))\n\nWrite a macro that addresses: Macro call that should be transformed by augment", "input": "(augment init-code (do-extra-save-var-hack var save-info-list code-list))", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf init-code (nconc init-code (do-extra-save-var-hack var save-info-list code-list)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(once-only* args (compile-match args clauses nil))\n\nProblem: Macro call that should be transformed by once-only*", "input": "(once-only* args (compile-match args clauses nil))", "output": "(defmacro once-only* (symbol &body body)\n (with-unique-names (form var vars bindings)\n `(let (,vars ,bindings)\n (dolist (,form ,symbol)\n (if (symbolp ,form)\n (push ,form ,vars)\n (let ((,var (gensym \"VAR\")))\n (push ,var ,vars)\n (push (list ,var ,form) ,bindings))))\n (setq ,vars (nreverse ,vars)\n ,bindings (nreverse ,bindings))\n (if ,bindings\n `(let ,,bindings\n ;(declare (ignorable ,@(mapcar #'car ,bindings)))\n ,(let ((,symbol ,vars))\n ,@body))\n (progn ,@body)))))", "macroexpand": "(let (#:vars162 #:bindings163) (dolist (#:form160 args) (if (symbolp #:form160) (push #:form160 #:vars162) (let ((#:var161 (gensym \"VAR\"))) (push #:var161 #:vars162) (push (list #:var161 #:form160) #:bindings163)))) (setq #:vars162 (nreverse #:vars162) #:bindings163 (nreverse #:bindings163)) (if #:bindings163 (sb-int:quasiquote (let #S(sb-impl::comma :expr #:bindings163 :kind 0) #S(sb-impl::comma :expr (let ((args #:vars162)) (compile-match args clauses nil)) :kind 0))) (progn (compile-match args clauses nil))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-ps-symbol-macro nil (progn))\n\nProblem: Macro call that should be transformed by DEFINE-PS-SYMBOL-MACRO", "input": "(define-ps-symbol-macro nil (progn))", "output": "(defmacro DEFINE-PS-SYMBOL-MACRO ...)", "macroexpand": "(progn\n nil\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash 'nil *symbol-macro-toplevel*)\n (lambda (form) (declare (ignore form)) '(progn)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(inext-noexit nil (progn))\n\nProblem: Macro call that should be transformed by INEXT-NOEXIT", "input": "(inext-noexit nil (progn))", "output": "(defmacro INEXT-NOEXIT ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro nil) (progn)))))\n (if (not vals)\n (values nil nil)\n (values (car vals) t)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun* nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFUN*", "input": "(defun* nil\n :key\n nil)", "output": "(defmacro DEFUN* ...)", "macroexpand": "(defun nil :key\n (with-yield\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-ps-gensyms nil\n nil)\n\nIssue: Macro call that should be transformed by WITH-PS-GENSYMS", "input": "(with-ps-gensyms nil\n nil)", "output": "(defmacro WITH-PS-GENSYMS ...)", "macroexpand": "(let* ()\n nil)", "category": "control-flow", "technique": "gensym", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(dynamic-let* nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by DYNAMIC-LET*", "input": "(dynamic-let* nil\n :key\n nil)", "output": "(defmacro DYNAMIC-LET* ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-context (context) (funcall result (lambda (result) (funcall responder (process-response this result)))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-context", "input": "(with-context (context) (funcall result (lambda (result) (funcall responder (process-response this result)))))", "output": "(defmacro with-context ((context) &body body)\n `(let* ((*context* ,context)\n (*request* (context :request))\n (*response* (context :response))\n (*session* (context :session)))\n ,@body))", "macroexpand": "(let* ((*context* context) (*request* (context :request)) (*response* (context :response)) (*session* (context :session))) (funcall result (lambda (result) (funcall responder (process-response this result)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun/1 fclose (fd) (close (fd-stream fd)) (when (tmp-file fd) (delete-file (tmp-file fd)) (setf (tmp-file fd) nil)) 0)\n\nWhat needs to change: Macro call that should be transformed by defun/1", "input": "(defun/1 fclose (fd) (close (fd-stream fd)) (when (tmp-file fd) (delete-file (tmp-file fd)) (setf (tmp-file fd) nil)) 0)", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun fclose (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (close (fd-stream fd)) (when (tmp-file fd) (delete-file (tmp-file fd)) (setf (tmp-file fd) nil)) 0) (defparameter fclose (vacietis.c:mkptr& (symbol-function (quote fclose)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(deferror \"23514\" check-violation integrity-violation)\n\nPattern to recognize: Macro call that should be transformed by deferror", "input": "(deferror \"23514\" check-violation integrity-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition check-violation (integrity-violation) nil) (setf (gethash \"23514\" *error-table*) (quote check-violation)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-fixture-capture macro (symbol) (when (and (macro-function symbol) (not (locked-package-p (symbol-package symbol)))) (values (macro-function symbol) T)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-fixture-capture", "input": "(define-fixture-capture macro (symbol) (when (and (macro-function symbol) (not (locked-package-p (symbol-package symbol)))) (values (macro-function symbol) T)))", "output": "(defmacro define-fixture-capture (name args &body body)\n `(progn (setf (gethash ',name *fixture-captures*)\n (lambda ,args ,@body))\n ',name))", "macroexpand": "(progn (setf (gethash (quote macro) *fixture-captures*) (lambda (symbol) (when (and (macro-function symbol) (not (locked-package-p (symbol-package symbol)))) (values (macro-function symbol) t)))) (quote macro))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(xor nil nil 1 2)\n\nWhat needs to change: Macro call that should be transformed by xor", "input": "(xor nil nil 1 2)", "output": "(defmacro xor (&rest datums)\n \"Evaluates its arguments one at a time, from left to right. If more than one\nargument evaluates to a true value no further DATUMS are evaluated, and NIL is\nreturned as both primary and secondary value. If exactly one argument\nevaluates to true, its value is returned as the primary value after all the\narguments have been evaluated, and T is returned as the secondary value. If no\narguments evaluate to true NIL is returned as primary, and T as secondary\nvalue.\"\n (with-gensyms (xor tmp true)\n `(let (,tmp ,true)\n (declare (ignorable ,tmp))\n (block ,xor\n ,@(mapcar (lambda (datum)\n `(if (setf ,tmp ,datum)\n (if ,true\n (return-from ,xor (values nil nil))\n (setf ,true ,tmp))))\n datums)\n (return-from ,xor (values ,true t))))))", "macroexpand": "(let (#:tmp144 #:true145) (declare (ignorable #:tmp144)) (block #:xor143 (if (setf #:tmp144 nil) (if #:true145 (return-from #:xor143 (values nil nil)) (setf #:true145 #:tmp144))) (if (setf #:tmp144 nil) (if #:true145 (return-from #:xor143 (values nil nil)) (setf #:true145 #:tmp144))) (if (setf #:tmp144 1) (if #:true145 (return-from #:xor143 (values nil nil)) (setf #:true145 #:tmp144))) (if (setf #:tmp144 2) (if #:true145 (return-from #:xor143 (values nil nil)) (setf #:true145 #:tmp144))) (return-from #:xor143 (values #:true145 t))))", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.835} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defgenerator groupby (generator &key (key #'identity) (comp #'eq)) \"Groups the items from generator by the results of the key func. Each item emitted by groupby will be a pair: the key value, followed by a list of items that produced the key value when passed to the key function. Note: groupby does NOT sort the source generator. In other words it will only group matching items that are adjacent. To get SQL style GROUP BY functionality, sort the source generator before passing it to groupby. Eg: (groupby (list->generator '(A A A A B B B C C))) -> (A (A A A A)) (B (B B B)) ...\" (let ((last (gensym)) (res nil)) (do-generator (g generator) (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil))))))))\n\nWhat needs to change: Macro call that should be transformed by defgenerator", "input": "(defgenerator groupby (generator &key (key #'identity) (comp #'eq)) \"Groups the items from generator by the results of the key func. Each item emitted by groupby will be a pair: the key value, followed by a list of items that produced the key value when passed to the key function. Note: groupby does NOT sort the source generator. In other words it will only group matching items that are adjacent. To get SQL style GROUP BY functionality, sort the source generator before passing it to groupby. Eg: (groupby (list->generator '(A A A A B B B C C))) -> (A (A A A A)) (B (B B B)) ...\" (let ((last (gensym)) (res nil)) (do-generator (g generator) (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil))))))))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun groupby (generator &key (key (function identity)) (comp (function eq))) \"Groups the items from generator by the results of the key func. Each item emitted by groupby will be a pair: the key value, followed by a list of items that produced the key value when passed to the key function. Note: groupby does NOT sort the source generator. In other words it will only group matching items that are adjacent. To get SQL style GROUP BY functionality, sort the source generator before passing it to groupby. Eg: (groupby (list->generator '(A A A A B B B C C))) -> (A (A A A A)) (B (B B B)) ...\" (with-yield (let ((last (gensym)) (res nil)) (do-generator (g generator) (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil)))))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(draw group (:circle :cx (+ x depth 1) :cy (1- (+ y depth)) :r (/ w 3)) :stroke \"none\" :fill \"black\")\n\nIssue: Macro call that should be transformed by draw", "input": "(draw group (:circle :cx (+ x depth 1) :cy (1- (+ y depth)) :r (/ w 3)) :stroke \"none\" :fill \"black\")", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g157 (funcall (function make-svg-element) :circle (append (list :cx (+ x depth 1) :cy (1- (+ y depth)) :r (/ w 3)) (list :stroke \"none\" :fill \"black\"))))) (add-element group #:g157) #:g157)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(send nil)\n\nWhat needs to change: Macro call that should be transformed by SEND", "input": "(send nil)", "output": "(defmacro SEND ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-neo4j-fun get-relationship (relationship-id) :get (:uri-spec (format nil \"relationship/~A\" relationship-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'relationship-not-found-error :uri uri))))\n\nPattern to recognize: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-relationship (relationship-id) :get (:uri-spec (format nil \"relationship/~A\" relationship-id)) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'relationship-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-relationship (&key relationship-id) (let ((uri (format nil \"relationship/~A\" relationship-id)) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote relationship-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-gensyms (random-number) `(let ((,random-number (random ,length))) ,(expand possibilities 0 random-number)))\n\nIssue: Macro call that should be transformed by with-gensyms", "input": "(with-gensyms (random-number) `(let ((,random-number (random ,length))) ,(expand possibilities 0 random-number)))", "output": "(defmacro with-gensyms (names &body forms)\n \"Binds a set of variables to gensyms and evaluates the implicit progn FORMS.\n\nEach element within NAMES is either a symbol SYMBOL or a pair (SYMBOL\nSTRING-DESIGNATOR). Bare symbols are equivalent to the pair (SYMBOL SYMBOL).\n\nEach pair (SYMBOL STRING-DESIGNATOR) specifies that the variable named by SYMBOL\nshould be bound to a symbol constructed using GENSYM with the string designated\nby STRING-DESIGNATOR being its first argument.\"\n `(let ,(mapcar (lambda (name)\n (multiple-value-bind (symbol string)\n (etypecase name\n (symbol\n (values name (symbol-name name)))\n ((cons symbol (cons string-designator null))\n (values (first name) (string (second name)))))\n `(,symbol (gensym ,string))))\n names)\n ,@forms))", "macroexpand": "(let ((random-number (gensym #A((13) base-char . \"RANDOM-NUMBER\")))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr random-number :kind 0) (random #S(sb-impl::comma :expr length :kind 0)))) #S(sb-impl::comma :expr (expand possibilities 0 random-number) :kind 0))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-custom-var (:beginning-of-object *beginning-of-object-handler*) (constantly t) \"Designator for a function of no arguments (called at encountering an opening brace for an Object).\")\n\nWhat needs to change: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:beginning-of-object *beginning-of-object-handler*) (constantly t) \"Designator for a function of no arguments (called at encountering an opening brace for an Object).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*beginning-of-object-handler* . :beginning-of-object)) *custom-vars* :test (function equal)) (defvar *beginning-of-object-handler* (constantly t) \"Designator for a function of no arguments (called at encountering an opening brace for an Object).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-color (:white :stream stream) (format/indent reporter stream (slot-value report 'description)))\n\nWhat needs to change: Macro call that should be transformed by with-color", "input": "(with-color (:white :stream stream) (format/indent reporter stream (slot-value report 'description)))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq :white :gray) (eq :white :grey) (eq :white +gray+) (eq :white +grey+)) (with-gray stream (format/indent reporter stream (slot-value report (quote description)))) (cl-ansi-text:with-color (:white :stream stream) (format/indent reporter stream (slot-value report (quote description))))) (progn (format/indent reporter stream (slot-value report (quote description)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> :g (b) (+ b 6))\n\nIssue: Macro call that should be transformed by ->", "input": "(-> :g (b) (+ b 6))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (b) (+ b 6))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error could-not-find-any (:error-type varjo-critical-error) (name) \"No function, macro or compiler-macro called '~a' could be found in this environment\" name)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error could-not-find-any (:error-type varjo-critical-error) (name) \"No function, macro or compiler-macro called '~a' could be found in this environment\" name)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition could-not-find-any (:error-type varjo-critical-error :prefix \"Varjo\") (name) \"No function, macro or compiler-macro called '~a' could be found in this environment\" name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(let-gensyms (decoder validator value-handler key-handler pass) (let ((vars-tmp (loop repeat (length vars) collect (gensym)))) `(let (,@vars-tmp (,pass (constantly t))) (let ((,validator (custom-decoder :beginning-of-object ,pass :object-key ,pass :object-value ,pass :end-of-object ,pass :beginning-of-array ,pass :array-member ,pass :end-of-array ,pass :beginning-of-string ,pass :string-char ,pass :end-of-string ,pass :internal-decoder 'decode-json)) (,decoder (current-decoder)) (,key-handler *object-key-handler*) (,value-handler *object-value-handler*)) (declare (ignorable ,decoder ,key-handler ,value-handler)) ,(if (null vars) `(decode-json-from-source ,json-source ,validator) `(bind-custom-vars (,@(json-bind-level-customizations (loop for var in vars for var-tmp in vars-tmp collect (cons var-tmp (symbol-name var))) nil decoder validator key-handler value-handler pass) :aggregate-scope (union *aggregate-scope-variables* '(*object-key-handler* *object-value-handler* *internal-decoder*))) (decode-json-from-source ,json-source)))) (let ,(mapcar #'list vars vars-tmp) ,@body))))\n\nProblem: Macro call that should be transformed by let-gensyms", "input": "(let-gensyms (decoder validator value-handler key-handler pass) (let ((vars-tmp (loop repeat (length vars) collect (gensym)))) `(let (,@vars-tmp (,pass (constantly t))) (let ((,validator (custom-decoder :beginning-of-object ,pass :object-key ,pass :object-value ,pass :end-of-object ,pass :beginning-of-array ,pass :array-member ,pass :end-of-array ,pass :beginning-of-string ,pass :string-char ,pass :end-of-string ,pass :internal-decoder 'decode-json)) (,decoder (current-decoder)) (,key-handler *object-key-handler*) (,value-handler *object-value-handler*)) (declare (ignorable ,decoder ,key-handler ,value-handler)) ,(if (null vars) `(decode-json-from-source ,json-source ,validator) `(bind-custom-vars (,@(json-bind-level-customizations (loop for var in vars for var-tmp in vars-tmp collect (cons var-tmp (symbol-name var))) nil decoder validator key-handler value-handler pass) :aggregate-scope (union *aggregate-scope-variables* '(*object-key-handler* *object-value-handler* *internal-decoder*))) (decode-json-from-source ,json-source)))) (let ,(mapcar #'list vars vars-tmp) ,@body))))", "output": "(defmacro let-gensyms ((&rest names) &body body)\n `(let ,(loop for name in names collect `(,name (gensym)))\n ,@body))", "macroexpand": "(let ((decoder (gensym)) (validator (gensym)) (value-handler (gensym)) (key-handler (gensym)) (pass (gensym))) (let ((vars-tmp (loop repeat (length vars) collect (gensym)))) (sb-int:quasiquote (let (#S(sb-impl::comma :expr vars-tmp :kind 2) (#S(sb-impl::comma :expr pass :kind 0) (constantly t))) (let ((#S(sb-impl::comma :expr validator :kind 0) (custom-decoder :beginning-of-object #S(sb-impl::comma :expr pass :kind 0) :object-key #S(sb-impl::comma :expr pass :kind 0) :object-value #S(sb-impl::comma :expr pass :kind 0) :end-of-object #S(sb-impl::comma :expr pass :kind 0) :beginning-of-array #S(sb-impl::comma :expr pass :kind 0) :array-member #S(sb-impl::comma :expr pass :kind 0) :end-of-array #S(sb-impl::comma :expr pass :kind 0) :beginning-of-string #S(sb-impl::comma :expr pass :kind 0) :string-char #S(sb-impl::comma :expr pass :kind 0) :end-of-string #S(sb-impl::comma :expr pass :kind 0) :internal-decoder (quote decode-json))) (#S(sb-impl::comma :expr decoder :kind 0) (current-decoder)) (#S(sb-impl::comma :expr key-handler :kind 0) *object-key-handler*) (#S(sb-impl::comma :expr value-handler :kind 0) *object-value-handler*)) (declare (ignorable #S(sb-impl::comma :expr decoder :kind 0) #S(sb-impl::comma :expr key-handler :kind 0) #S(sb-impl::comma :expr value-handler :kind 0))) #S(sb-impl::comma :expr (if (null vars) (sb-int:quasiquote (decode-json-from-source #S(sb-impl::comma :expr json-source :kind 0) #S(sb-impl::comma :expr validator :kind 0))) (sb-int:quasiquote (bind-custom-vars (#S(sb-impl::comma :expr (json-bind-level-customizations (loop for var in vars for var-tmp in vars-tmp collect (cons var-tmp (symbol-name var))) nil decoder validator key-handler value-handler pass) :kind 2) :aggregate-scope (union *aggregate-scope-variables* (quote (*object-key-handler* *object-value-handler* *internal-decoder*)))) (decode-json-from-source #S(sb-impl::comma :expr json-source :kind 0))))) :kind 0)) (let #S(sb-impl::comma :expr (mapcar (function list) vars vars-tmp) :kind 0) #S(sb-impl::comma :expr body :kind 2))))))", "category": "control-flow", "technique": "gensym", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dflet ((foo/inline () 42)) (is (eql 42 (foo/inline))))\n\nProblem: Macro call that should be transformed by dflet", "input": "(dflet ((foo/inline () 42)) (is (eql 42 (foo/inline))))", "output": "(defmacro dflet ((&rest definitions) &body body)\n \"Like FLET, but dynamically sets the FDEFINITIONS during the duration of\nthe BODY.\"\n `(progf\n ',(mapcar #'car definitions)\n (list\n ,.(mapcar (lambda (definition)\n `(lambda ,(cadr definition)\n ,@(cddr definition)))\n definitions))\n ,@body))", "macroexpand": "(progf (quote (foo/inline)) (list (lambda nil 42)) (is (eql 42 (foo/inline))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-attributes nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-ATTRIBUTES", "input": "(with-attributes nil\n nil)", "output": "(defmacro WITH-ATTRIBUTES ...)", "macroexpand": "(let ((#:unit160 nil))\n (symbol-macrolet ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(caching-types\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by CACHING-TYPES", "input": "(caching-types\n 'some-name)", "output": "(defmacro CACHING-TYPES ...)", "macroexpand": "(call-with-disjoint-hash\n (lambda ()\n (call-with-subtype-hash\n (lambda ()\n (call-with-equiv-hash\n (lambda () (call-with-subtypep-cache (lambda () 'some-name))))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(caching-types\n nil\n nil)\n\nIssue: Macro call that should be transformed by CACHING-TYPES", "input": "(caching-types\n nil\n nil)", "output": "(defmacro CACHING-TYPES ...)", "macroexpand": "(call-with-disjoint-hash\n (lambda ()\n (call-with-subtype-hash\n (lambda ()\n (call-with-equiv-hash\n (lambda () (call-with-subtypep-cache (lambda () nil nil))))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(special-symbol-progv nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by SPECIAL-SYMBOL-PROGV", "input": "(special-symbol-progv nil\n :key\n nil)", "output": "(defmacro SPECIAL-SYMBOL-PROGV ...)", "macroexpand": "(let (#:symbol-list180)\n (tagbody\n #:retry181\n (setq #:symbol-list180 nil)\n (unless (every #'special-symbol-p #:symbol-list180)\n (cerror \"Retry to rebind the place(s).\"\n \"Attempt at rebinding one or more non-special places: ~S\" 'nil)\n (go #:retry181)))\n (dynamic-progv #:symbol-list180\n :key\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym initially :initially)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym initially :initially)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote initially) (quote synonym)) (quote :initially)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is (= 0 state))\n\nProblem: Macro call that should be transformed by is", "input": "(is (= 0 state))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e217 0) (#:a218 state)) (if (progn (= #:e217 #:a218)) (add-result (quote test-passed) :test-expr (quote (= 0 state))) (process-failure (quote (= 0 state)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote state) #:a218 (quote =) #:e217)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-element-maker :marker \"marker\" '(:id))\n\nPattern to recognize: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :marker \"marker\" '(:id))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :marker)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:id)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :marker missing))))) (defmethod make-svg-element ((element (eql :marker)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"marker\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(defmethod* nil)\n\nPattern to recognize: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil)", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(let* ((#:nil123 (ensure-generic*-function 'nil))\n (temp-method (defmethod #:nil122))\n (actual-gf\n (ensure-generic*-function 'nil :lambda-list\n (sb-mop:generic-function-lambda-list\n (symbol-function '#:nil122))\n :special-variables 'nil))\n (actual-method\n (add-method* #:nil123\n (make-instance 'method* :special-variables (list)\n :qualifiers 'nil :specializers\n (sb-mop:method-specializers temp-method)\n :lambda-list\n (sb-mop:method-lambda-list temp-method)\n :documentation\n (documentation temp-method t) :function\n (sb-mop:method-function temp-method)))))\n (declare (ignorable #:nil123)\n (ignore actual-gf))\n (setf (documentation actual-method t) (documentation temp-method t))\n actual-method)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-prepared-query query (conn sql) (and (dbi:fetch-all (execute-with-retry query binds) :format :plist) t))\n\nIssue: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (conn sql) (and (dbi:fetch-all (execute-with-retry query binds) :format :plist) t))", "output": "(defmacro with-prepared-query (query (conn sql &key use-prepare-cached) &body body)\n `(call-with-prepared-query ,conn ,sql (lambda (,query) ,@body) :use-prepare-cached ,use-prepare-cached))", "macroexpand": "(call-with-prepared-query conn sql (lambda (query) (and (dbi.driver:fetch-all (execute-with-retry query binds) :format :plist) t)) :use-prepare-cached nil)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n;; Manual gensym binding is verbose\n(let ((g1 (gensym))\n (g2 (gensym))\n (g3 (gensym)))\n `(let ((,g1 ,x)\n (,g2 ,y))\n (f ,g1 ,g2 ,g3)))\n;; The let-bindings for gensyms obscure the macro logic\n\nPattern to recognize: Manual gensym creation with let-bindings is verbose \u2014 want concise declaration of gensym-intended symbols", "input": ";; Manual gensym binding is verbose\n(let ((g1 (gensym))\n (g2 (gensym))\n (g3 (gensym)))\n `(let ((,g1 ,x)\n (,g2 ,y))\n (f ,g1 ,g2 ,g3)))\n;; The let-bindings for gensyms obscure the macro logic", "output": "(defmacro with-gensyms (syms &body body)\n `(let ,(mapcar #'(lambda (s)\n `(,s (gensym)))\n syms)\n ,@body))", "macroexpand": ";; (with-gensyms (g1 g2 g3)\n;; `(let ((,g1 ,x)\n;; (,g2 ,y))\n;; (f ,g1 ,g2 ,g3)))\n;; Expands to:\n;; (LET ((G1 (GENSYM)) (G2 (GENSYM)) (G3 (GENSYM)))\n;; `(LET ((,G1 ,X) (,G2 ,Y)) (F ,G1 ,G2 ,G3)))\n;;\n;; Much cleaner than manual gensym let-bindings", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-html-string (:div.some-class (:pre \"verbatim line one verbatim line two\") (:p \"Some following stuff\")))\n\nWhat needs to change: Macro call that should be transformed by with-html", "input": "(with-html-string (:div.some-class (:pre \"verbatim line one verbatim line two\") (:p \"Some following stuff\")))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:div.some-class (:pre \"verbatim line one verbatim line two\") (:p \"Some following stuff\"))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-custom-var (:end-of-string *end-of-string-handler*) (constantly \"\") \"Designator for a function of no arguments (called at encountering a closing quote for a String).\")\n\nIssue: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:end-of-string *end-of-string-handler*) (constantly \"\") \"Designator for a function of no arguments (called at encountering a closing quote for a String).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*end-of-string-handler* . :end-of-string)) *custom-vars* :test (function equal)) (defvar *end-of-string-handler* (constantly \"\") \"Designator for a function of no arguments (called at encountering a closing quote for a String).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(ok nil)\n\nPattern to recognize: Macro call that should be transformed by ok", "input": "(ok nil)", "output": "(defmacro ok (test &optional desc)\n (with-gensyms (duration result)\n (once-only (test desc)\n `(with-catching-errors (:expected T :description ,desc)\n (with-duration ((,duration ,result) ,test)\n (test ,result t ,desc\n :duration ,duration\n :test-fn (lambda (x y)\n (eq (not (null x)) y))\n :got-form ,test))))))", "macroexpand": "(let ((#:test146 nil) (#:desc147 nil)) (with-catching-errors (:expected t :description #:desc147) (with-duration ((#:duration144 #:result145) #:test146) (test #:result145 t #:desc147 :duration #:duration144 :test-fn (lambda (x y) (eq (not (null x)) y)) :got-form #:test146))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dict-of 'some-name)\n\nProblem: Macro call that should be transformed by DICT-OF", "input": "(dict-of 'some-name)", "output": "(defmacro DICT-OF ...)", "macroexpand": "(let ((#:dict134 (make-hash-table :test 'equal)))\n (do-for nil\n (multiple-value-call\n (lambda (#:k135 #:v136) (setf (gethash #:k135 #:dict134) #:v136))\n 'some-name))\n #:dict134)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(action (:traverse node-let node new-subs) (loop :for (name . expr) :in (node-let-bindings node) :do (when (find name subs :key #'ast-substitution-from) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-let\" name)) :do (when rename-bound-variables (push (make-ast-substitution :from name :to (make-node-variable :type (node-type expr) :value (gensym (symbol-name name)))) new-subs))) (make-node-let :type (node-type node) :bindings (loop :for (name . node) :in (node-let-bindings node) :collect (cons (if rename-bound-variables (node-variable-value (ast-substitution-to (find name new-subs :key #'ast-substitution-from))) name) (funcall *traverse* node new-subs))) :subexpr (funcall *traverse* (node-let-subexpr node) new-subs)))\n\nWhat needs to change: Macro call that should be transformed by action", "input": "(action (:traverse node-let node new-subs) (loop :for (name . expr) :in (node-let-bindings node) :do (when (find name subs :key #'ast-substitution-from) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-let\" name)) :do (when rename-bound-variables (push (make-ast-substitution :from name :to (make-node-variable :type (node-type expr) :value (gensym (symbol-name name)))) new-subs))) (make-node-let :type (node-type node) :bindings (loop :for (name . node) :in (node-let-bindings node) :collect (cons (if rename-bound-variables (node-variable-value (ast-substitution-to (find name new-subs :key #'ast-substitution-from))) name) (funcall *traverse* node new-subs))) :subexpr (funcall *traverse* (node-let-subexpr node) new-subs)))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :traverse) (quote node-let) (lambda (node new-subs) (declare (type node-let node)) (loop :for (name . expr) :in (node-let-bindings node) :do (when (find name subs :key (function ast-substitution-from)) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-let\" name)) :do (when rename-bound-variables (push (make-ast-substitution :from name :to (make-node-variable :type (node-type expr) :value (gensym (symbol-name name)))) new-subs))) (make-node-let :type (node-type node) :bindings (loop :for (name . node) :in (node-let-bindings node) :collect (cons (if rename-bound-variables (node-variable-value (ast-substitution-to (find name new-subs :key (function ast-substitution-from)))) name) (funcall *traverse* node new-subs))) :subexpr (funcall *traverse* (node-let-subexpr node) new-subs))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-type-map special-operator :special-operator)\n\nPattern to recognize: Macro call that should be transformed by define-simple-type-map", "input": "(define-simple-type-map special-operator :special-operator)", "output": "(defmacro define-simple-type-map (class type)\n `(defmethod type ((,class ,class))\n ',type))", "macroexpand": "(defmethod type ((special-operator special-operator)) (quote :special-operator))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some-<> (diamond-wand init (cddr exp) nil t))\n\nProblem: Macro call that should be transformed by some-<>", "input": "(some-<> (diamond-wand init (cddr exp) nil t))", "output": "(defmacro some-<> (init &body exps) (diamond-wand init exps nil t))", "macroexpand": "(block #:g126 (diamond-wand init (cddr exp) nil t))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:not-null unary-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:not-null unary-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (not-null-op (:include unary-op (name \"NOT NULL\")) (:constructor make-not-null-op (var))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-nth nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-NTH", "input": "(collect-nth nil nil)", "output": "(defmacro COLLECT-NTH ...)", "macroexpand": "(common-lisp:let* ((#:generator-398 (generator nil))\n #:items-390\n (#:counter-392 nil)\n (#:item-393 nil))\n (declare (type generator #:generator-398)\n (type (null-or fixnum) #:counter-392)\n (type (null-or t) #:item-393))\n (tagbody\n #:ll-399\n (setq #:items-390 (next-in #:generator-398 (go end)))\n (when (zerop #:counter-392) (setq #:item-393 #:items-390) (go end))\n (decf #:counter-392)\n (go #:ll-399)\n end)\n #:item-393)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-gensyms (parent-type term type string current-mode position position-foobage mode-wait new-position advance) `(let ((,parent-type (or (find-coloring-type ,parent) (and ,parent (error \"No such coloring type: ~S\" ,parent))))) (setf (find-coloring-type ,name) (make-instance 'coloring-type :fancy-name ',fancy-name :modes (append ',modes (if ,parent-type (coloring-type-modes ,parent-type))) :default-mode (or ',default-mode (if ,parent-type (coloring-type-default-mode ,parent-type))) ,@(if autodetect `(:autodetect-function ,autodetect)) :parent-type ,parent-type :visible (not ,invisible) :formatter-initial-values (lambda nil (list* ,@(mapcar #'(lambda (e) `(cons ',(car e) ,(second e))) formatter-variables) (if ,parent-type (funcall (coloring-type-formatter-initial-values ,parent-type)) nil))) :formatter-after-hook (lambda nil (symbol-macrolet ,(mapcar #'(lambda (e) `(,(car e) (cdr (assoc ',(car e) *formatter-local-variables*)))) formatter-variables) (concatenate 'string (funcall ,formatter-after-hook) (if ,parent-type (funcall (coloring-type-formatter-after-hook ,parent-type)) \"\")))) :term-formatter (symbol-macrolet ,(mapcar #'(lambda (e) `(,(car e) (cdr (assoc ',(car e) *formatter-local-variables*)))) formatter-variables) (lambda (,term) (labels ((call-parent-formatter (&optional (,type (car ,term)) (,string (cdr ,term))) (if ,parent-type (funcall (coloring-type-term-formatter ,parent-type) (cons ,type ,string)))) (call-formatter (&optional (,type (car ,term)) (,string (cdr ,term))) (funcall (case (first ,type) ,@formatters (t (lambda (,type text) (call-parent-formatter ,type text)))) ,type ,string))) (call-formatter)))) :transition-functions (list ,@(loop for transition in transitions collect (destructuring-bind (mode &rest table) transition `(cons ',mode (lambda (,current-mode ,string ,position) (let ((,mode-wait (constantly nil)) (,position-foobage ,position)) (with-scanning-functions ,string ,position-foobage ,current-mode ,mode-wait (let ((*reset-position* ,position)) (cond ,@table)) (values ,position-foobage ,current-mode (lambda (,new-position) (setf ,position-foobage ,new-position) (let ((,advance (nth-value 1 (funcall ,mode-wait ,position-foobage)))) (values ,position-foobage ,advance))))) ))))))))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-gensyms", "input": "(with-gensyms (parent-type term type string current-mode position position-foobage mode-wait new-position advance) `(let ((,parent-type (or (find-coloring-type ,parent) (and ,parent (error \"No such coloring type: ~S\" ,parent))))) (setf (find-coloring-type ,name) (make-instance 'coloring-type :fancy-name ',fancy-name :modes (append ',modes (if ,parent-type (coloring-type-modes ,parent-type))) :default-mode (or ',default-mode (if ,parent-type (coloring-type-default-mode ,parent-type))) ,@(if autodetect `(:autodetect-function ,autodetect)) :parent-type ,parent-type :visible (not ,invisible) :formatter-initial-values (lambda nil (list* ,@(mapcar #'(lambda (e) `(cons ',(car e) ,(second e))) formatter-variables) (if ,parent-type (funcall (coloring-type-formatter-initial-values ,parent-type)) nil))) :formatter-after-hook (lambda nil (symbol-macrolet ,(mapcar #'(lambda (e) `(,(car e) (cdr (assoc ',(car e) *formatter-local-variables*)))) formatter-variables) (concatenate 'string (funcall ,formatter-after-hook) (if ,parent-type (funcall (coloring-type-formatter-after-hook ,parent-type)) \"\")))) :term-formatter (symbol-macrolet ,(mapcar #'(lambda (e) `(,(car e) (cdr (assoc ',(car e) *formatter-local-variables*)))) formatter-variables) (lambda (,term) (labels ((call-parent-formatter (&optional (,type (car ,term)) (,string (cdr ,term))) (if ,parent-type (funcall (coloring-type-term-formatter ,parent-type) (cons ,type ,string)))) (call-formatter (&optional (,type (car ,term)) (,string (cdr ,term))) (funcall (case (first ,type) ,@formatters (t (lambda (,type text) (call-parent-formatter ,type text)))) ,type ,string))) (call-formatter)))) :transition-functions (list ,@(loop for transition in transitions collect (destructuring-bind (mode &rest table) transition `(cons ',mode (lambda (,current-mode ,string ,position) (let ((,mode-wait (constantly nil)) (,position-foobage ,position)) (with-scanning-functions ,string ,position-foobage ,current-mode ,mode-wait (let ((*reset-position* ,position)) (cond ,@table)) (values ,position-foobage ,current-mode (lambda (,new-position) (setf ,position-foobage ,new-position) (let ((,advance (nth-value 1 (funcall ,mode-wait ,position-foobage)))) (values ,position-foobage ,advance))))) ))))))))))", "output": "(defmacro with-gensyms ((&rest names) &body body)\n `(let ,(mapcar #'(lambda (name)\n (list name `(make-symbol ,(symbol-name name)))) names)\n ,@body))", "macroexpand": "(let ((parent-type (gensym #A((11) base-char . \"PARENT-TYPE\"))) (term (gensym #A((4) base-char . \"TERM\"))) (type (gensym #A((4) base-char . \"TYPE\"))) (string (gensym #A((6) base-char . \"STRING\"))) (current-mode (gensym #A((12) base-char . \"CURRENT-MODE\"))) (position (gensym #A((8) base-char . \"POSITION\"))) (position-foobage (gensym #A((16) base-char . \"POSITION-FOOBAGE\"))) (mode-wait (gensym #A((9) base-char . \"MODE-WAIT\"))) (new-position (gensym #A((12) base-char . \"NEW-POSITION\"))) (advance (gensym #A((7) base-char . \"ADVANCE\")))) (sb-int:quasiquote (let ((#S(sb-impl::comma :expr parent-type :kind 0) (or (find-coloring-type #S(sb-impl::comma :expr parent :kind 0)) (and #S(sb-impl::comma :expr parent :kind 0) (error \"No such coloring type: ~S\" #S(sb-impl::comma :expr parent :kind 0)))))) (setf (find-coloring-type #S(sb-impl::comma :expr name :kind 0)) (make-instance (quote coloring-type) :fancy-name (quote #S(sb-impl::comma :expr fancy-name :kind 0)) :modes (append (quote #S(sb-impl::comma :expr modes :kind 0)) (if #S(sb-impl::comma :expr parent-type :kind 0) (coloring-type-modes #S(sb-impl::comma :expr parent-type :kind 0)))) :default-mode (or (quote #S(sb-impl::comma :expr default-mode :kind 0)) (if #S(sb-impl::comma :expr parent-type :kind 0) (coloring-type-default-mode #S(sb-impl::comma :expr parent-type :kind 0)))) #S(sb-impl::comma :expr (if autodetect (sb-int:quasiquote (:autodetect-function #S(sb-impl::comma :expr autodetect :kind 0)))) :kind 2) :parent-type #S(sb-impl::comma :expr parent-type :kind 0) :visible (not #S(sb-impl::comma :expr invisible :kind 0)) :formatter-initial-values (lambda nil (list* #S(sb-impl::comma :expr (mapcar (function (lambda (e) (sb-int:quasiquote (cons (quote #S(sb-impl::comma :expr (car e) :kind 0)) #S(sb-impl::comma :expr (second e) :kind 0))))) formatter-variables) :kind 2) (if #S(sb-impl::comma :expr parent-type :kind 0) (funcall (coloring-type-formatter-initial-values #S(sb-impl::comma :expr parent-type :kind 0))) nil))) :formatter-after-hook (lambda nil (symbol-macrolet #S(sb-impl::comma :expr (mapcar (function (lambda (e) (sb-int:quasiquote (#S(sb-impl::comma :expr (car e) :kind 0) (cdr (assoc (quote #S(sb-impl::comma :expr (car e) :kind 0)) *formatter-local-variables*)))))) formatter-variables) :kind 0) (concatenate (quote string) (funcall #S(sb-impl::comma :expr formatter-after-hook :kind 0)) (if #S(sb-impl::comma :expr parent-type :kind 0) (funcall (coloring-type-formatter-after-hook #S(sb-impl::comma :expr parent-type :kind 0))) \"\")))) :term-formatter (symbol-macrolet #S(sb-impl::comma :expr (mapcar (function (lambda (e) (sb-int:quasiquote (#S(sb-impl::comma :expr (car e) :kind 0) (cdr (assoc (quote #S(sb-impl::comma :expr (car e) :kind 0)) *formatter-local-variables*)))))) formatter-variables) :kind 0) (lambda (#S(sb-impl::comma :expr term :kind 0)) (labels ((call-parent-formatter (&optional (#S(sb-impl::comma :expr type :kind 0) (car #S(sb-impl::comma :expr term :kind 0))) (#S(sb-impl::comma :expr string :kind 0) (cdr #S(sb-impl::comma :expr term :kind 0)))) (if #S(sb-impl::comma :expr parent-type :kind 0) (funcall (coloring-type-term-formatter #S(sb-impl::comma :expr parent-type :kind 0)) (cons #S(sb-impl::comma :expr type :kind 0) #S(sb-impl::comma :expr string :kind 0))))) (call-formatter (&optional (#S(sb-impl::comma :expr type :kind 0) (car #S(sb-impl::comma :expr term :kind 0))) (#S(sb-impl::comma :expr string :kind 0) (cdr #S(sb-impl::comma :expr term :kind 0)))) (funcall (case (first #S(sb-impl::comma :expr type :kind 0)) #S(sb-impl::comma :expr formatters :kind 2) (t (lambda (#S(sb-impl::comma :expr type :kind 0) text) (call-parent-formatter #S(sb-impl::comma :expr type :kind 0) text)))) #S(sb-impl::comma :expr type :kind 0) #S(sb-impl::comma :expr string :kind 0)))) (call-formatter)))) :transition-functions (list #S(sb-impl::comma :expr (loop for transition in transitions collect (destructuring-bind (mode &rest table) transition (sb-int:quasiquote (cons (quote #S(sb-impl::comma :expr mode :kind 0)) (lambda (#S(sb-impl::comma :expr current-mode :kind 0) #S(sb-impl::comma :expr string :kind 0) #S(sb-impl::comma :expr position :kind 0)) (let ((#S(sb-impl::comma :expr mode-wait :kind 0) (constantly nil)) (#S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr position :kind 0))) (with-scanning-functions #S(sb-impl::comma :expr string :kind 0) #S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr current-mode :kind 0) #S(sb-impl::comma :expr mode-wait :kind 0) (let ((*reset-position* #S(sb-impl::comma :expr position :kind 0))) (cond #S(sb-impl::comma :expr table :kind 2))) (values #S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr current-mode :kind 0) (lambda (#S(sb-impl::comma :expr new-position :kind 0)) (setf #S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr new-position :kind 0)) (let ((#S(sb-impl::comma :expr advance :kind 0) (nth-value 1 (funcall #S(sb-impl::comma :expr mode-wait :kind 0) #S(sb-impl::comma :expr position-foobage :kind 0))))) (values #S(sb-impl::comma :expr position-foobage :kind 0) #S(sb-impl::comma :expr advance :kind 0)))))))))))) :kind 2)))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defannotation ignore* (vars) (:alias ignore :inline t) \"Shorthand for (DECLARE (IGNORE ...)).\" (%declare-list-or-symbol vars 'ignore))\n\nProblem: Macro call that should be transformed by defannotation", "input": "(defannotation ignore* (vars) (:alias ignore :inline t) \"Shorthand for (DECLARE (IGNORE ...)).\" (%declare-list-or-symbol vars 'ignore))", "output": "(defmacro defannotation (name lambda-list options &body body)\n `(progn\n (set-annotation-options ',name ',options)\n (defmacro ,name ,lambda-list ,@body)))", "macroexpand": "(progn (set-annotation-options (quote ignore*) (quote (:alias ignore :inline t))) (defmacro ignore* (vars) \"Shorthand for (DECLARE (IGNORE ...)).\" (%declare-list-or-symbol vars (quote ignore))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(dreletf* nil\n nil)\n\nProblem: Macro call that should be transformed by DRELETF*", "input": "(dreletf* nil\n nil)", "output": "(defmacro DRELETF* ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(signal-syntax-error \"Too much choices in branch: ~S.\" parse-tree)\n\nWrite a macro that addresses: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Too much choices in branch: ~S.\" parse-tree)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Too much choices in branch: ~S.\" parse-tree)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(\u03c8 nil nil)\n\nProblem: Macro call that should be transformed by \u03a8", "input": "(\u03c8 nil nil)", "output": "(defmacro \u03a8 ...)", "macroexpand": "(mapcar (\u03bb nil) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield (dolist (x data) (yield x)))\n\nWhat needs to change: Macro call that should be transformed by with-yield", "input": "(with-yield (dolist (x data) (yield x)))", "output": "(defmacro with-yield (&body body)\n (let ((point (gensym))\n (current (gensym)))\n `(let (,point ,current)\n (with-call/cc\n\t (labels ((yield (&rest values)\n\t\t (setf ,current values)\n\t\t (let/cc k\n\t\t (setf ,point k))))\n\t ,@body\n\t (setf ,point nil)))\n (gen-lambda ()\n\t (cond ((null ,point)\n\t\t'generator-stop)\n\t (t\n\t\t(let ((current ,current))\n\t\t (funcall ,point nil)\n\t\t ;values-handler: see gen-lambda\n\t\t (apply #'values (funcall values-handler current)))))))))", "macroexpand": "(let (#:g139 #:g140) (with-call/cc (labels ((yield (&rest values) (setf #:g140 values) (let/cc k (setf #:g139 k)))) (dolist (x data) (yield x)) (setf #:g139 nil))) (gen-lambda nil (cond ((null #:g139) (quote generator-stop)) (t (let ((current #:g140)) (funcall #:g139 nil) (apply (function values) (funcall values-handler current)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ensure-getf options :special special)\n\nWhat needs to change: Macro call that should be transformed by ensure-getf", "input": "(ensure-getf options :special special)", "output": "(defmacro ensure-getf (place key &optional default)\n (once-only (key default)\n `(setf (getf ,place ,key) (getf ,place ,key ,default))))", "macroexpand": "(let ((#:key177 :special) (#:default178 special)) (setf (getf options #:key177) (getf options #:key177 #:default178)))", "category": "control-flow", "technique": "once-only", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(sif (car x) (setf it :oops) (setf it :yes!))\n\nIssue: Macro call that should be transformed by sif", "input": "(sif (car x) (setf it :oops) (setf it :yes!))", "output": "(defmacro sif (test then &optional else)\n \"Like IF, except binds the test form to IT (via SYMBOL-MACROLET) for\nthe scope of the then and else expressions. IT can be set with SETF\"\n `(symbolic if ,test ,then ,else))", "macroexpand": "(symbolic if (car x) (setf it :oops) (setf it :yes!))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(draw scene (:rect :x 75 :y 75 :height 30 :width 30) :fill \"purple\")\n\nWrite a macro that addresses: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x 75 :y 75 :height 30 :width 30) :fill \"purple\")", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g144 (funcall (function make-svg-element) :rect (append (list :x 75 :y 75 :height 30 :width 30) (list :fill \"purple\"))))) (add-element scene #:g144) #:g144)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(without-dependency-capture\n nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE", "input": "(without-dependency-capture\n nil\n nil)", "output": "(defmacro WITHOUT-DEPENDENCY-CAPTURE ...)", "macroexpand": "(let ((%dependent% nil))\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(list-of nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by LIST-OF", "input": "(list-of nil\n :key\n nil)", "output": "(defmacro LIST-OF ...)", "macroexpand": "(lc (nil :key nil) collect)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-sequences! ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))\n\nProblem: Macro call that should be transformed by do-sequences!", "input": "(do-sequences! ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))", "output": "(defmacro do-sequences! (name/seqs &body forms &environment env)\n \"Mutable version of DO-SEQUENCES.\n\n This is the same as DO-SEQUENCES however each NAME, is the name of\n a symbol-macro, that is introduced, which expands to the 'place',\n suitable for use with SETF, of the current sequence element, rather\n than a variable storing its value. This allows the elements of the\n sequence to be mutated.\n\n NOTE: This macro does not support destructuring of the sequence\n elements.\"\n\n (let-if ((name name/seqs)\n (seqs (first forms) name/seqs)\n (forms (rest forms) forms))\n (symbolp name/seqs)\n\n (let ((safety (cadr (assoc 'safety (declaration-information 'optimize env)))))\n `(,(if (> safety 2)\n 'do-sequences!-safe%\n 'do-sequences!-fast%)\n\n ,name\n ,seqs\n ,@forms))))", "macroexpand": "(do-sequences!-fast% nil ((item1 seq1 :start start1 :end end1) (item2 seq2 :start start2 :end end2)) (setf item1 item2))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(alist-bind (type width) form `(,@(parse-type type (aval :tag type)) :bitfield-p t :bit-width ,width))\n\nWhat needs to change: Macro call that should be transformed by alist-bind", "input": "(alist-bind (type width) form `(,@(parse-type type (aval :tag type)) :bitfield-p t :bit-width ,width))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist237 form)) (let ((type (aval :type #:alist237)) (width (aval :width #:alist237))) (sb-int:quasiquote (#S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2) :bitfield-p t :bit-width #S(sb-impl::comma :expr width :kind 0)))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(incf nil (progn))\n\nIssue: Macro call that should be transformed by INCF", "input": "(incf nil (progn))", "output": "(defmacro INCF ...)", "macroexpand": "(setq nil (+ (progn) nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defsynonym in :in)\n\nWrite a macro that addresses: Macro call that should be transformed by defsynonym", "input": "(defsynonym in :in)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote in) (quote synonym)) (quote :in)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(unwind-protect-case () (random 10) (:normal (push :normal result)) (:abort (push :abort result)) (:always (push :always result)))\n\nWrite a macro that addresses: Macro call that should be transformed by unwind-protect-case", "input": "(unwind-protect-case () (random 10) (:normal (push :normal result)) (:abort (push :abort result)) (:always (push :always result)))", "output": "(defmacro unwind-protect-case ((&optional abort-flag) protected-form &body clauses)\n \"Like CL:UNWIND-PROTECT, but you can specify the circumstances that\nthe cleanup CLAUSES are run.\n\n clauses ::= (:NORMAL form*)* | (:ABORT form*)* | (:ALWAYS form*)*\n\nClauses can be given in any order, and more than one clause can be\ngiven for each circumstance. The clauses whose denoted circumstance\noccured, are executed in the order the clauses appear.\n\nABORT-FLAG is the name of a variable that will be bound to T in\nCLAUSES if the PROTECTED-FORM aborted preemptively, and to NIL\notherwise.\n\nExamples:\n\n (unwind-protect-case ()\n (protected-form)\n (:normal (format t \\\"This is only evaluated if PROTECTED-FORM executed normally.~%\\\"))\n (:abort (format t \\\"This is only evaluated if PROTECTED-FORM aborted preemptively.~%\\\"))\n (:always (format t \\\"This is evaluated in either case.~%\\\")))\n\n (unwind-protect-case (aborted-p)\n (protected-form)\n (:always (perform-cleanup-if aborted-p)))\n\"\n (check-type abort-flag (or null symbol))\n (let ((gflag (gensym \"FLAG+\")))\n `(let ((,gflag t))\n (unwind-protect (multiple-value-prog1 ,protected-form (setf ,gflag nil))\n\t (let ,(and abort-flag `((,abort-flag ,gflag)))\n\t ,@(loop for (cleanup-kind . forms) in clauses\n\t\t collect (ecase cleanup-kind\n\t\t\t (:normal `(when (not ,gflag) ,@forms))\n\t\t\t (:abort `(when ,gflag ,@forms))\n\t\t\t (:always `(progn ,@forms)))))))))", "macroexpand": "(let ((#:flag+123 t)) (unwind-protect (multiple-value-prog1 (random 10) (setf #:flag+123 nil)) (let nil (when (not #:flag+123) (push :normal result)) (when #:flag+123 (push :abort result)) (progn (push :always result)))))", "category": "control-flow", "technique": "gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<> 'some-name)\n\nProblem: Macro call that should be transformed by -<>", "input": "(-<> 'some-name)", "output": "(defmacro -<> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(form &key key &aux (result NIL))\n\nWrite a macro that addresses: Macro call that should be transformed by for", "input": "(form &key key &aux (result NIL))", "output": "(defmacro for (&environment env bindings &body body)\n (let ((*environment* env))\n (multiple-value-bind (bind-init bind-forms bind-exit bind-post) (convert-bindings bindings)\n (multiple-value-bind (clause-init body-forms clause-exit) (convert-clauses body)\n `(with-interleaving\n ,@bind-init\n ,@clause-init\n (with-for-block ()\n (with-for-tagbody\n (progn ,@bind-forms\n ,@body-forms\n ,@bind-post)\n (return-for\n ,@clause-exit\n ,@bind-exit))))))))", "macroexpand": "(form &key key &aux (result nil))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(yield-all generator)\n\nWrite a macro that addresses: Macro call that should be transformed by yield-all", "input": "(yield-all generator)", "output": "(defmacro yield-all (generator)\n \"Walks through generator, re-yielding all of the items in it. Only meant for use inside of a defgenerator or with-yield block.\"\n (let ((x (gensym)))\n `(do-generator (,x ,generator)\n (yield ,x))))", "macroexpand": "(do-generator (#:g183 generator) (yield #:g183))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.7975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lret* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)\n\nWrite a macro that addresses: Macro call that should be transformed by lret*", "input": "(lret* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)", "output": "(defmacro lret* ((&rest bindings) &body body)\n \"Cf. `lret'.\"\n `(lret-aux let* ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((element-type (array-element-type vec)) (out (make-array length :element-type element-type))) (replace out vec) (fill out pad :start (length vec)) out)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(in-compile-time nil\n (progn))\n\nProblem: Macro call that should be transformed by IN-COMPILE-TIME", "input": "(in-compile-time nil\n (progn))", "output": "(defmacro IN-COMPILE-TIME ...)", "macroexpand": "(macrolet ((#:macro143 (&environment ())\n (progn)))\n (#:macro143))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-output-to-file (file-stream pathname :if-exists if-exists :if-does-not-exist if-does-not-exist :external-format external-format) (write-sequence string file-stream))\n\nPattern to recognize: Macro call that should be transformed by with-output-to-file", "input": "(with-output-to-file (file-stream pathname :if-exists if-exists :if-does-not-exist if-does-not-exist :external-format external-format) (write-sequence string file-stream))", "output": "(defmacro with-output-to-file ((stream-name file-name &rest args\n &key (direction nil direction-p)\n &allow-other-keys)\n\t\t\t &body body)\n \"Evaluate BODY with STREAM-NAME to an output stream on the file\nFILE-NAME. ARGS is sent as is to the call to OPEN except EXTERNAL-FORMAT,\nwhich is only sent to WITH-OPEN-FILE when it's not NIL.\"\n (declare (ignore direction))\n (when direction-p\n (error \"Can't specify :DIRECTION for WITH-OUTPUT-TO-FILE.\"))\n `(with-open-file* (,stream-name ,file-name :direction :output ,@args)\n ,@body))", "macroexpand": "(with-open-file* (file-stream pathname :direction :output :if-exists if-exists :if-does-not-exist if-does-not-exist :external-format external-format) (write-sequence string file-stream))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(>> (loop repeat 5 collecting (-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))))\n\nPattern to recognize: Macro call that should be transformed by >>", "input": "(>> (loop repeat 5 collecting (-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))))", "output": "(defmacro >> (&rest flow)\n \"See flow:serially\"\n `(serially ,@flow))", "macroexpand": "(serially (loop repeat 5 collecting (-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(>> (-> :p () 1) (-> :p (a) (+ a 1)) (-> :p (v) (setf result v) (mt:open-latch latch)))\n\nWrite a macro that addresses: Macro call that should be transformed by >>", "input": "(>> (-> :p () 1) (-> :p (a) (+ a 1)) (-> :p (v) (setf result v) (mt:open-latch latch)))", "output": "(defmacro >> (&rest flow)\n \"See flow:serially\"\n `(serially ,@flow))", "macroexpand": "(serially (-> :p nil 1) (-> :p (a) (+ a 1)) (-> :p (v) (setf result v) (cl-muth:open-latch latch)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:a> infix-op :sql-op-name \"@>\"))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:a> infix-op :sql-op-name \"@>\"))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (a>-op (:include infix-op (name \"@>\")) (:constructor make-a>-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda-coro\n nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by LAMBDA-CORO", "input": "(lambda-coro\n nil\n :key\n nil)", "output": "(defmacro LAMBDA-CORO ...)", "macroexpand": "(progn\n (defcoroutine #:name131\n (#:arg132)\n (macrolet ((yield (form)\n (let ((g!-it (gensym \"IT\")))\n `(progn\n (let ((,g!-it ,form))\n (cl-coroutine:yield ,g!-it))\n ,'#:arg132)))\n (last-yield-value ()\n '#:arg132))\n nil\n :key\n nil\n (coexit!)))\n (make-coroutine '#:name131))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some->> nil)\n\nIssue: Macro call that should be transformed by SOME->>", "input": "(some->> nil)", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:g125 nil))\n #:g125)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(signal-syntax-error \"Illegal back-reference: ~S.\" parse-tree)\n\nProblem: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Illegal back-reference: ~S.\" parse-tree)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Illegal back-reference: ~S.\" parse-tree)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(mvlet* ((left-cases right-cases (halves cases)) (split (caar right-cases))) `(if (< ,keyform ,split) ,(rec keyform left-cases) ,(rec keyform right-cases)))\n\nWhat needs to change: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((left-cases right-cases (halves cases)) (split (caar right-cases))) `(if (< ,keyform ,split) ,(rec keyform left-cases) ,(rec keyform right-cases)))", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(multiple-value-bind (left-cases right-cases) (halves cases) (mvlet* ((split (caar right-cases))) (sb-int:quasiquote (if (< #S(sb-impl::comma :expr keyform :kind 0) #S(sb-impl::comma :expr split :kind 0)) #S(sb-impl::comma :expr (rec keyform left-cases) :kind 0) #S(sb-impl::comma :expr (rec keyform right-cases) :kind 0)))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<> nil)\n\nProblem: Macro call that should be transformed by -<>", "input": "(-<> nil)", "output": "(defmacro -<> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(flow-lambda-macro (flow-context) (let ((fu-body `((flet ((continue-flow (&optional ,continue-arg) (capture-flow-value ,flow-context ,continue-arg) (dispatch-rest ,flow-context)) (interrupt-flow (&optional ,condi) (error ,condi))) (declare (ignorable (function continue-flow) (function interrupt-flow))) ,@body)))) (with-flow-function-macro (body-fu lambda-list fu-body) `(dispatch-asynchronously ,flow-context #',body-fu))))\n\nIssue: Macro call that should be transformed by flow-lambda-macro", "input": "(flow-lambda-macro (flow-context) (let ((fu-body `((flet ((continue-flow (&optional ,continue-arg) (capture-flow-value ,flow-context ,continue-arg) (dispatch-rest ,flow-context)) (interrupt-flow (&optional ,condi) (error ,condi))) (declare (ignorable (function continue-flow) (function interrupt-flow))) ,@body)))) (with-flow-function-macro (body-fu lambda-list fu-body) `(dispatch-asynchronously ,flow-context #',body-fu))))", "output": "(defmacro flow-lambda-macro ((flow-context) &body body)\n `(with-gensyms (,flow-context)\n `(%flow-lambda (,,flow-context)\n ,,@body)))", "macroexpand": "(with-gensyms (flow-context) (sb-int:quasiquote (%flow-lambda (#S(sb-impl::comma :expr flow-context :kind 0)) #S(sb-impl::comma :expr (let ((fu-body (sb-int:quasiquote ((flet ((continue-flow (&optional #S(sb-impl::comma :expr continue-arg :kind 0)) (capture-flow-value #S(sb-impl::comma :expr flow-context :kind 0) #S(sb-impl::comma :expr continue-arg :kind 0)) (dispatch-rest #S(sb-impl::comma :expr flow-context :kind 0))) (interrupt-flow (&optional #S(sb-impl::comma :expr condi :kind 0)) (error #S(sb-impl::comma :expr condi :kind 0)))) (declare (ignorable (function continue-flow) (function interrupt-flow))) #S(sb-impl::comma :expr body :kind 2)))))) (with-flow-function-macro (body-fu lambda-list fu-body) (sb-int:quasiquote (dispatch-asynchronously #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr body-fu :kind 0)))))) :kind 0))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-dispatch dispatch-for-+ (args specific-hooks) (reduce #'+ (mapcar (lambda (f) (apply f args)) specific-hooks)))\n\nWhat needs to change: Macro call that should be transformed by define-dispatch", "input": "(define-dispatch dispatch-for-+ (args specific-hooks) (reduce #'+ (mapcar (lambda (f) (apply f args)) specific-hooks)))", "output": "(defmacro define-dispatch (name lambda-list &body body)\n \"the lambda list should accept two arguments:\nthe list of arguments given by the current method call.\nthe specific hooks (as named or unamed functions) for the qualified method (that we will be dispatching from).\n\nyou should then use the arguments to dispatch the specific hooks as you wish in the body.\nif the body returns a result, by default the method will also return that result, this can be overriden with finalize-dispatch-method.\n\nSee finalize-dispatch-method\nSee dispatch\"\n `(let ((new-dispatch (make-dispatcher (lambda ,lambda-list ,@body))))\n (setf (gethash ',name *dispatch-table*)\n new-dispatch)))", "macroexpand": "(let ((new-dispatch (make-dispatcher (lambda (args specific-hooks) (reduce (function +) (mapcar (lambda (f) (apply f args)) specific-hooks)))))) (setf (gethash (quote dispatch-for-+) *dispatch-table*) new-dispatch))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-reader-case nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by WITH-READER-CASE", "input": "(with-reader-case nil\n :key\n nil)", "output": "(defmacro WITH-READER-CASE ...)", "macroexpand": "(let ()\n (let ((#:previous-case181 (readtable-case *readtable*)))\n (setf (readtable-case *readtable*) nil)\n (unwind-protect (progn :key nil)\n (setf (readtable-case *readtable*) #:previous-case181))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some-<>\n nil\n (progn))\n\nIssue: Macro call that should be transformed by SOME-<>", "input": "(some-<>\n nil\n (progn))", "output": "(defmacro SOME-<> ...)", "macroexpand": "(let* ((#:var178 nil)\n (#:var179\n (if #:var178\n (progn #:var178)\n nil)))\n #:var179)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(draw scene (:use :xlink-href (xlink-href columns)) :x (- (random 750) 25) :y (- (random 700) 25) :height size :width size :stroke \"rgb(232, 229, 148)\" :stroke-width 0.3 :fill (one-of *sandy-test-colors*))\n\nWhat needs to change: Macro call that should be transformed by draw", "input": "(draw scene (:use :xlink-href (xlink-href columns)) :x (- (random 750) 25) :y (- (random 700) 25) :height size :width size :stroke \"rgb(232, 229, 148)\" :stroke-width 0.3 :fill (one-of *sandy-test-colors*))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g148 (funcall (function make-svg-element) :use (append (list :xlink-href (xlink-href columns)) (list :x (- (random 750) 25) :y (- (random 700) 25) :height size :width size :stroke \"rgb(232, 229, 148)\" :stroke-width 0.3 :fill (one-of *sandy-test-colors*)))))) (add-element scene #:g148) #:g148)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(quasiquote-expand-1 'list (append (butlast x) (mapcar 'kwote (and last (single-arg (car last))))))\n\nWhat needs to change: Macro call that should be transformed by quasiquote", "input": "(quasiquote-expand-1 'list (append (butlast x) (mapcar 'kwote (and last (single-arg (car last))))))", "output": "(defmacro quasiquote (x) (quasiquote-expand x))", "macroexpand": "(quasiquote-expand-1 (quote list) (append (butlast x) (mapcar (quote kwote) (and last (single-arg (car last))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some->> 'some-name)\n\nIssue: Macro call that should be transformed by SOME->>", "input": "(some->> 'some-name)", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:|some124| 'some-name))\n #:|some124|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-value-binding repeating ((var 0) limit) (declare (type (integer 0) var limit)) `(when (< ,limit (incf ,var)) (end-for)))\n\nPattern to recognize: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding repeating ((var 0) limit) (declare (type (integer 0) var limit)) `(when (< ,limit (incf ,var)) (end-for)))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding repeating (var limit) (let ((#:limit178 (gensym #A((5) base-char . \"LIMIT\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:limit178 limit) (loop for #:var177 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var177 0))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:limit178 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote (integer 0)) :kind 0) #S(sb-impl::comma :expr var :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote (integer 0)) :kind 0) #S(sb-impl::comma :expr #:limit178 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((limit #:limit178)) (declare (ignorable limit)) (sb-int:quasiquote (when (< #S(sb-impl::comma :expr limit :kind 0) (incf #S(sb-impl::comma :expr var :kind 0))) (end-for)))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-simple-documentation-lookup compiler-macro cl:compiler-macro)\n\nProblem: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup compiler-macro cl:compiler-macro)", "output": "(defmacro define-simple-documentation-lookup (class documentation-type)\n `(defmethod documentation ((,class ,class))\n ,(if (eql documentation-type T)\n `(cl:documentation (object ,class) 'T)\n `(cl:documentation (designator ,class) ',documentation-type))))", "macroexpand": "(defmethod documentation ((compiler-macro compiler-macro)) (common-lisp:documentation (designator compiler-macro) (quote common-lisp:compiler-macro)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(inext nil)\n\nWhat needs to change: Macro call that should be transformed by INEXT", "input": "(inext nil)", "output": "(defmacro INEXT ...)", "macroexpand": "(let ((vals (multiple-value-list (funcall (i-coro nil) nil))))\n (if (not vals)\n (coexit!)\n (car vals)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ps-package-prefix 'some-name)\n\nIssue: Macro call that should be transformed by PS-PACKAGE-PREFIX", "input": "(ps-package-prefix 'some-name)", "output": "(defmacro PS-PACKAGE-PREFIX ...)", "macroexpand": "(gethash (find-package 'some-name) *package-prefix-table*)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder (:session :store (make-redis-store :namespace *namespace* :connection *connection*)) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session))))))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder (:session :store (make-redis-store :namespace *namespace* :connection *connection*)) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session))))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app238) (funcall (find-middleware :session) #:app238 :store (make-redis-store :namespace *namespace* :connection *connection*))))) :initial-value (to-app (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (#S(sb-impl::comma :expr (format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(signal-syntax-error \"No choices in branch: ~S.\" parse-tree)\n\nWrite a macro that addresses: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"No choices in branch: ~S.\" parse-tree)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"No choices in branch: ~S.\" parse-tree)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :g (value) (put value) (error 'skipping-condition))\n\nProblem: Macro call that should be transformed by ->", "input": "(-> :g (value) (put value) (error 'skipping-condition))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (value) (put value) (error (quote skipping-condition)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(as-> nil :key nil)\n\nProblem: Macro call that should be transformed by AS->", "input": "(as-> nil :key nil)", "output": "(defmacro AS-> ...)", "macroexpand": "(let* ((:key nil))\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-float-converters encode-float32 decode-float32 8 23 nil)\n\nIssue: Macro call that should be transformed by make-float-converters", "input": "(make-float-converters encode-float32 decode-float32 8 23 nil)", "output": "(defmacro make-float-converters (encoder-name\n decoder-name\n exponent-bits\n significand-bits\n support-nan-and-infinity-p)\n \"Writes an encoder and decoder function for floating point\nnumbers with the given amount of exponent and significand\nbits (plus an extra sign bit). If support-nan-and-infinity-p is\ntrue, the decoders will also understand these special cases. NaN\nis represented as :not-a-number, and the infinities as\n:positive-infinity and :negative-infinity. Note that this means\nthat the in- or output of these functions is not just floating\npoint numbers anymore, but also keywords.\"\n (let* ((total-bits (+ 1 exponent-bits significand-bits))\n (exponent-offset (1- (expt 2 (1- exponent-bits)))) ; (A)\n (sign-part `(ldb (byte 1 ,(1- total-bits)) bits))\n (exponent-part `(ldb (byte ,exponent-bits ,significand-bits) bits))\n (significand-part `(ldb (byte ,significand-bits 0) bits))\n (nan support-nan-and-infinity-p)\n (max-exponent (1- (expt 2 exponent-bits)))) ; (B)\n `(progn\n (defun ,encoder-name (float)\n ,@(unless nan `((declare (type float float))))\n (multiple-value-bind (sign significand exponent)\n (cond ,@(when nan `(((eq float :not-a-number)\n (values 0 1 ,max-exponent))\n ((eq float :positive-infinity)\n (values 0 0 ,max-exponent))\n ((eq float :negative-infinity)\n (values 1 0 ,max-exponent))))\n ((zerop float)\n (values 0 0 0))\n (t\n (multiple-value-bind (significand exponent sign)\n (decode-float float)\n (let ((exponent (+ (1- exponent) ,exponent-offset))\n (sign (if (= sign 1.0) 0 1)))\n (unless (< exponent ,(expt 2 exponent-bits))\n (error \"Floating point overflow when encoding ~A.\"\n float))\n (if (< exponent 0) ; (C)\n (values sign (ash (round (* ,(expt 2 significand-bits)\n significand))\n exponent)\n 0)\n (values sign (round (* ,(expt 2 significand-bits)\n (1- (* significand 2))))\n exponent))))))\n (let ((bits 0))\n (declare (type (unsigned-byte ,total-bits) bits))\n (setf ,sign-part sign\n ,exponent-part exponent\n ,significand-part significand)\n bits)))\n\n (defun ,decoder-name (bits)\n (declare (type (unsigned-byte ,total-bits) bits))\n (let* ((sign ,sign-part)\n (exponent ,exponent-part)\n (significand ,significand-part))\n ,@(when nan `((when (= exponent ,max-exponent)\n (return-from ,decoder-name\n (cond ((not (zerop significand)) :not-a-number)\n ((zerop sign) :positive-infinity)\n (t :negative-infinity))))))\n (if (zerop exponent) ; (D)\n (setf exponent 1)\n (setf (ldb (byte 1 ,significand-bits) significand) 1))\n (unless (zerop sign)\n (setf significand (- significand)))\n (scale-float (float significand ,(if (> total-bits 32) 1.0d0 1.0))\n (- exponent ,(+ exponent-offset significand-bits))))))))", "macroexpand": "(progn (defun encode-float32 (float) (declare (type float float)) (multiple-value-bind (sign significand exponent) (cond ((zerop float) (values 0 0 0)) (t (multiple-value-bind (significand exponent sign) (decode-float float) (let ((exponent (+ (1- exponent) 127)) (sign (if (= sign 1.0) 0 1))) (unless (< exponent 256) (error \"Floating point overflow when encoding ~A.\" float)) (if (< exponent 0) (values sign (ash (round (* 8388608 significand)) exponent) 0) (values sign (round (* 8388608 (1- (* significand 2)))) exponent)))))) (let ((bits 0)) (declare (type (unsigned-byte 32) bits)) (setf (ldb (byte 1 31) bits) sign (ldb (byte 8 23) bits) exponent (ldb (byte 23 0) bits) significand) bits))) (defun decode-float32 (bits) (declare (type (unsigned-byte 32) bits)) (let* ((sign (ldb (byte 1 31) bits)) (exponent (ldb (byte 8 23) bits)) (significand (ldb (byte 23 0) bits))) (if (zerop exponent) (setf exponent 1) (setf (ldb (byte 1 23) significand) 1)) (unless (zerop sign) (setf significand (- significand))) (scale-float (float significand 1.0) (- exponent 150)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(iterate\n nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ITERATE", "input": "(iterate\n nil\n :key\n nil)", "output": "(defmacro ITERATE ...)", "macroexpand": "(iter\n nil\n :key\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-notation bind-maybe ((sum (inc-maybe 1)) (str (maybe->string sum))) str)\n\nWhat needs to change: Macro call that should be transformed by do-notation", "input": "(do-notation bind-maybe ((sum (inc-maybe 1)) (str (maybe->string sum))) str)", "output": "(defmacro do-notation (bind-function expressions &body body)\n \"Given a BIND-FUNCTION and all the bind expressions, evaluate BODY.\"\n `(progn\n ,@(reduce (lambda (acc do-binding)\n\t\t (append `((,bind-function (lambda (,(car do-binding)) ,@acc)\n\t\t\t\t\t ,@(cdr do-binding)))))\n\t (reverse expressions)\n\t :initial-value body)))", "macroexpand": "(progn (bind-maybe (lambda (sum) (bind-maybe (lambda (str) str) (maybe->string sum))) (inc-maybe 1)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(c-assert (listp (kid-values self)))\n\nIssue: Macro call that should be transformed by c-assert", "input": "(c-assert (listp (kid-values self)))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (listp (kid-values self)) (c-break \"failed assertion: ~a\" (quote (listp (kid-values self))))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-condition deprecation-warning (style-warning) ((name :initarg :name :reader deprecated-name) (replacements :initarg :replacement :reader deprecated-name-replacement) (since :initarg :since :reader deprecated-since)) (:report (lambda (condition stream) (format stream \"~S is deprecated since CL-MUSTACHE version ~A. ~ Use ~S instead.\" (deprecated-name condition) (deprecated-since condition) (deprecated-name-replacement condition)))))\n\nWrite a macro that addresses: Macro call that should be transformed by define", "input": "(define-condition deprecation-warning (style-warning) ((name :initarg :name :reader deprecated-name) (replacements :initarg :replacement :reader deprecated-name-replacement) (since :initarg :since :reader deprecated-since)) (:report (lambda (condition stream) (format stream \"~S is deprecated since CL-MUSTACHE version ~A. ~ Use ~S instead.\" (deprecated-name condition) (deprecated-since condition) (deprecated-name-replacement condition)))))", "output": "(defmacro define (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "macroexpand": "(progn (sb-kernel::%define-condition (quote deprecation-warning) (quote (style-warning)) (sb-kernel::find-condition-layout (quote deprecation-warning) (quote (style-warning))) (list (sb-kernel::make-condition-slot :name (quote name) :initargs (quote (:name)) :readers (quote (deprecated-name)) :writers (quote nil) :initform-p (quote nil) :documentation (quote nil) :initform nil :initfunction nil :allocation (quote :instance)) (sb-kernel::make-condition-slot :name (quote replacements) :initargs (quote (:replacement)) :readers (quote (deprecated-name-replacement)) :writers (quote nil) :initform-p (quote nil) :documentation (quote nil) :initform nil :initfunction nil :allocation (quote :instance)) (sb-kernel::make-condition-slot :name (quote since) :initargs (quote (:since)) :readers (quote (deprecated-since)) :writers (quote nil) :initform-p (quote nil) :documentation (quote nil) :initform nil :initfunction nil :allocation (quote :instance))) (list) (quote (deprecated-since deprecated-name-replacement deprecated-name)) (quote nil) (sb-c:source-location)) (sb-kernel::%set-condition-report (quote deprecation-warning) (function (sb-int:named-lambda (sb-kernel::condition-report deprecation-warning) (condition stream) (declare (type condition condition) (type stream stream)) (funcall (function (lambda (condition stream) (format stream \"~S is deprecated since CL-MUSTACHE version ~A. ~ Use ~S instead.\" (deprecated-name condition) (deprecated-since condition) (deprecated-name-replacement condition)))) condition stream)))) (quote deprecation-warning))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*let nil)\n\nWrite a macro that addresses: Macro call that should be transformed by *LET", "input": "(*let nil)", "output": "(defmacro *LET ...)", "macroexpand": "(let* ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lret* ((type `(integer ,start (,end))) (len (- end start)) (vector (make-array len :element-type type))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (1+ n))))))\n\nIssue: Macro call that should be transformed by lret", "input": "(lret* ((type `(integer ,start (,end))) (len (- end start)) (vector (make-array len :element-type type))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (1+ n))))))", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((type (sb-int:quasiquote (integer #S(sb-impl::comma :expr start :kind 0) (#S(sb-impl::comma :expr end :kind 0))))) (len (- end start)) (vector (make-array len :element-type type))) (nlet lp ((i 0) (n start)) (declare (type array-index i n)) (if (= i len) vector (progn (setf (aref vector i) n) (lp (1+ i) (1+ n))))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"57P01\" admin-shutdown server-shutdown)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"57P01\" admin-shutdown server-shutdown)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition admin-shutdown (server-shutdown) nil) (setf (gethash \"57P01\" *error-table*) (quote admin-shutdown)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (some #'test-failure-p results))\n\nIssue: Macro call that should be transformed by is", "input": "(is (some #'test-failure-p results))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e232 (function test-failure-p)) (#:a233 results)) (if (progn (some #:e232 #:a233)) (add-result (quote test-passed) :test-expr (quote (some (function test-failure-p) results))) (process-failure (quote (some (function test-failure-p) results)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote results) #:a233 (quote some) #:e232)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-subclasses (ctype content) (publish ctype))\n\nWhat needs to change: Macro call that should be transformed by do-subclasses", "input": "(do-subclasses (ctype content) (publish ctype))", "output": "(defmacro do-subclasses ((var class) &body body)\n \"Iterate over the subclasses of CLASS performing BODY with VAR\nlexically bound to the current subclass.\"\n (alexandria:with-gensyms (klasses)\n `(let ((,klasses (all-subclasses (find-class ',class))))\n (loop for ,var in ,klasses do ,@body))))", "macroexpand": "(let ((#:klasses285 (all-subclasses (find-class (quote content))))) (loop for ctype in #:klasses285 do (publish ctype)))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-generator (g list-or-gen) (yield g) (push g accum))\n\nPattern to recognize: Macro call that should be transformed by do-generator", "input": "(do-generator (g list-or-gen) (yield g) (push g accum))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g156 list-or-gen)) (loop do (if-generator ((g) #:g156) (progn (yield g) (push g accum)) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-reader-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-READER-SYNTAX", "input": "(enable-reader-syntax)", "output": "(defmacro ENABLE-READER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (push *readtable* *previous-readtables*)\n (setq *readtable* (copy-readtable))\n (%enable-reader-syntax *readtable*))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> +period+ +digit-chunks+)\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> +period+ +digit-chunks+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset245) (multiple-value-bind (#:*>-res246 #:*>-next247) (funcall +period+ #:*>-offset245) (if (ok? #:*>-res246) (funcall +digit-chunks+ #:*>-next247) (fail #:*>-next247))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-cache (\"none\" :store storage) (error \"SHOULD BE ERROR\"))\n\nPattern to recognize: Macro call that should be transformed by with-cache", "input": "(with-cache (\"none\" :store storage) (error \"SHOULD BE ERROR\"))", "output": "(defmacro with-cache ((key &key store expire) &body body)\n \"If a cache indicated by KEY exists, this just returns the cache\nvalue without evaluating BODY. Otherwise, this evaluates BODY and\nstores the evaluated value into STORE with KEY and EXPIRE. KEY is a\nform that an evaluated value indicates the cache key.\n\nExample:\n\n (defun f (x)\n (with-cache (x *store*)\n (very-complex-computation x)))\"\n (once-only (key store expire)\n (with-gensyms (value exists-p)\n `(multiple-value-bind (,value ,exists-p)\n (getcache ,key ,store)\n (if ,exists-p\n ,value\n (let ((,value (progn ,@body)))\n (setcache ,key ,value ,store :expire ,expire)\n ,value))))))", "macroexpand": "(let ((#:key242 \"none\") (#:store243 storage) (#:expire244 nil)) (multiple-value-bind (#:value245 #:exists-p246) (getcache #:key242 #:store243) (if #:exists-p246 #:value245 (let ((#:value245 (progn (error \"SHOULD BE ERROR\")))) (setcache #:key242 #:value245 #:store243 :expire #:expire244) #:value245))))", "category": "anaphoric", "technique": "once-only,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(incf nil nil)\n\nPattern to recognize: Macro call that should be transformed by INCF", "input": "(incf nil nil)", "output": "(defmacro INCF ...)", "macroexpand": "(setq nil (+ nil nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-cache ((list x y z)) (if (<= x y) z (tak (tak/with-cache (1- x) y z) (tak/with-cache (1- y) z x) (tak/with-cache (1- z) x y))))\n\nProblem: Macro call that should be transformed by with-cache", "input": "(with-cache ((list x y z)) (if (<= x y) z (tak (tak/with-cache (1- x) y z) (tak/with-cache (1- y) z x) (tak/with-cache (1- z) x y))))", "output": "(defmacro with-cache ((key &key store expire) &body body)\n \"If a cache indicated by KEY exists, this just returns the cache\nvalue without evaluating BODY. Otherwise, this evaluates BODY and\nstores the evaluated value into STORE with KEY and EXPIRE. KEY is a\nform that an evaluated value indicates the cache key.\n\nExample:\n\n (defun f (x)\n (with-cache (x *store*)\n (very-complex-computation x)))\"\n (once-only (key store expire)\n (with-gensyms (value exists-p)\n `(multiple-value-bind (,value ,exists-p)\n (getcache ,key ,store)\n (if ,exists-p\n ,value\n (let ((,value (progn ,@body)))\n (setcache ,key ,value ,store :expire ,expire)\n ,value))))))", "macroexpand": "(let ((#:key227 (list x y z)) (#:store228 nil) (#:expire229 nil)) (multiple-value-bind (#:value230 #:exists-p231) (getcache #:key227 #:store228) (if #:exists-p231 #:value230 (let ((#:value230 (progn (if (<= x y) z (tak (tak/with-cache (1- x) y z) (tak/with-cache (1- y) z x) (tak/with-cache (1- z) x y)))))) (setcache #:key227 #:value230 #:store228 :expire #:expire229) #:value230))))", "category": "anaphoric", "technique": "once-only,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(signal-syntax-error \"Unknown flag token ~A.\" token)\n\nWhat needs to change: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Unknown flag token ~A.\" token)", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Unknown flag token ~A.\" token)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-iter iterator-chain-from-iter (curr-iter itail) (chain-from-iter (iterable-of-iterables) \"Yields the elements of the first iterable in `iterable`, then the second, etc. Equivalent to python's chain.from_iterable(), and conceptually equivalent to `(picl:apply #'picl:chain iterable-of-iterables)`. ``` (chain-from-iter (picl:map (lambda (x) (picl:range x))) (picl:count)) ;; 0, 0, 1, 0, 1, 2, 0, 1, 2, 3, etc ```\" (let ((iterable-of-iterables (make-iterator iterable-of-iterables))) (multiple-value-bind (curr-iter its-alive) (next iterable-of-iterables) (if its-alive (init-state (curr-iter (make-iterator curr-iter)) (itail iterable-of-iterables)) (empty-iterator))))) (multiple-value-bind (curr-item curr-alive) (next curr-iter) (if curr-alive (values curr-item t) (progn (multiple-value-bind (next-iter itail-alive) (next itail) (if itail-alive (progn (setf curr-iter (make-iterator next-iter)) (self)) (values nil nil)))))))\n\nWhat needs to change: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-chain-from-iter (curr-iter itail) (chain-from-iter (iterable-of-iterables) \"Yields the elements of the first iterable in `iterable`, then the second, etc. Equivalent to python's chain.from_iterable(), and conceptually equivalent to `(picl:apply #'picl:chain iterable-of-iterables)`. ``` (chain-from-iter (picl:map (lambda (x) (picl:range x))) (picl:count)) ;; 0, 0, 1, 0, 1, 2, 0, 1, 2, 3, etc ```\" (let ((iterable-of-iterables (make-iterator iterable-of-iterables))) (multiple-value-bind (curr-iter its-alive) (next iterable-of-iterables) (if its-alive (init-state (curr-iter (make-iterator curr-iter)) (itail iterable-of-iterables)) (empty-iterator))))) (multiple-value-bind (curr-item curr-alive) (next curr-iter) (if curr-alive (values curr-item t) (progn (multiple-value-bind (next-iter itail-alive) (next itail) (if itail-alive (progn (setf curr-iter (make-iterator next-iter)) (self)) (values nil nil)))))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname135 (&key curr-iter itail) (labels ((self nil (multiple-value-bind (curr-item curr-alive) (next curr-iter) (if curr-alive (values curr-item t) (progn (multiple-value-bind (next-iter itail-alive) (next itail) (if itail-alive (progn (setf curr-iter (make-iterator next-iter)) (self)) (values nil nil)))))))) (function self)))) (defun chain-from-iter (iterable-of-iterables) \"Yields the elements of the first iterable in `iterable`, then the second, etc. Equivalent to python's chain.from_iterable(), and conceptually equivalent to `(picl:apply #'picl:chain iterable-of-iterables)`. ``` (chain-from-iter (picl:map (lambda (x) (picl:range x))) (picl:count)) ;; 0, 0, 1, 0, 1, 2, 0, 1, 2, 3, etc ```\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname135)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (let ((iterable-of-iterables (make-iterator iterable-of-iterables))) (multiple-value-bind (curr-iter its-alive) (next iterable-of-iterables) (if its-alive (init-state (curr-iter (make-iterator curr-iter)) (itail iterable-of-iterables)) (empty-iterator)))))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defreply nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by DEFREPLY", "input": "(defreply nil\n :key\n nil)", "output": "(defmacro DEFREPLY ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel)\n (unless (fboundp 'nil)\n (warn 'automatic-message-creation :message-name 'nil)\n (ensure-message 'nil :lambda-list 'nil)))\n (ensure-reply 'nil :qualifiers '(:key) :lambda-list 'nil :participants (list)\n :documentation nil :function\n (lambda (#:args144 #:next-replies145 &rest #:more-args147)\n (declare\n (ignorable #:args144 #:next-replies145 #:more-args147))\n (flet ((next-reply-p ()\n (not (null #:next-replies145)))\n (call-next-reply (&rest args)\n (if (null #:next-replies145)\n (apply 'no-next-reply\n (getf #:more-args147 :message)\n (getf #:more-args147 :reply)\n (or args #:args144))\n (apply (reply-function (car #:next-replies145))\n (or args #:args144)\n (cdr #:next-replies145) #:more-args147))))\n (declare\n (ignorable (function next-reply-p)\n (function call-next-reply)))\n (flet ((#:reply-function146 ()\n (declare (ignorable))\n (block nil)))\n (declare (inline #:reply-function146))\n (apply #'#:reply-function146 #:args144))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-class-method nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEFINE-CLASS-METHOD", "input": "(define-class-method nil\n :key\n nil)", "output": "(defmacro DEFINE-CLASS-METHOD ...)", "macroexpand": "(progn\n (define-incongruent-method nil\n :key\n nil)\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (add-class-principal-method 'nil ':key)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(as-> nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by AS->", "input": "(as-> nil\n :key\n nil)", "output": "(defmacro AS-> ...)", "macroexpand": "(let* ((:key nil) (:key (nil)))\n :key)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is-true t)\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is-true t)", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(if t (add-result (quote test-passed) :test-expr (quote t)) (process-failure (quote t) \"~S did not return a true value\" (quote t)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defobject 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DEFOBJECT", "input": "(defobject 'some-name)", "output": "(defmacro DEFOBJECT ...)", "macroexpand": "(object :parents (list quote some-name) :properties (list))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(iterate)\n\nIssue: Macro call that should be transformed by ITERATE", "input": "(iterate)", "output": "(defmacro ITERATE ...)", "macroexpand": "(iter)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defsynonym never :never)\n\nWrite a macro that addresses: Macro call that should be transformed by defsynonym", "input": "(defsynonym never :never)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote never) (quote synonym)) (quote :never)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-simple-definition-resolver macro macro-function)\n\nProblem: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver macro macro-function)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver macro (macro #:package134) (when (ignore-errors (macro-function macro)) (list (make-instance (quote macro) :designator macro :package #:package134))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-option-expander shadow (package &rest symbols) (shadow symbols package))\n\nIssue: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander shadow (package &rest symbols) (shadow symbols package))", "output": "(defmacro define-option-expander (name (package &rest arguments) &body body)\n (let ((args (gensym \"ARGS\")))\n `(defmethod expand-option ((,(gensym \"TYPE\") (eql ,(intern (string name) \"KEYWORD\"))) ,package ,args)\n (destructuring-bind ,arguments ,args\n ,@body))))", "macroexpand": "(defmethod expand-option ((#:type128 (eql :shadow)) package #:args127) (destructuring-bind (&rest symbols) #:args127 (shadow symbols package)))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda-ematch0 ((list* var options) `(type ,(getf options :type) ,var)))\n\nWhat needs to change: Macro call that should be transformed by lambda-ematch0", "input": "(lambda-ematch0 ((list* var options) `(type ,(getf options :type) ,var)))", "output": "(defmacro lambda-ematch0 (&body clauses)\n (alexandria:with-gensyms (arg)\n `(lambda (,arg)\n (ematch0 ,arg\n ,@clauses))))", "macroexpand": "(lambda (#:arg167) (ematch0 #:arg167 ((list* var options) (sb-int:quasiquote (type #S(sb-impl::comma :expr (getf options :type) :kind 0) #S(sb-impl::comma :expr var :kind 0))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-rewrite cdadar (expr) `(cdr (cadar ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cdadar (expr) `(cdr (cadar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdadar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cadar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda-match\n nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by LAMBDA-MATCH", "input": "(lambda-match\n nil\n :key\n nil)", "output": "(defmacro LAMBDA-MATCH ...)", "macroexpand": "(lambda (#:arg149)\n (match #:arg149\n nil\n :key\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(receive (x) (values) x)\n\nWhat needs to change: Macro call that should be transformed by receive", "input": "(receive (x) (values) x)", "output": "(defmacro receive (formals expr &body body)\n \"Stricter version of `multiple-value-bind'.\n\nUse `receive' when you want to enforce that EXPR should return a\ncertain number of values, or a minimum number of values.\n\nIf FORMALS is a proper list, then EXPR must return exactly as many\nvalues -- no more and no less -- as there are variables in FORMALS.\n\nIf FORMALS is an improper list (VARS . REST), then EXPR must return at\nleast as many values as there are VARS, and any further values are\nbound, as a list, to REST.\n\nLastly, if FORMALS is a symbol, bind that symbol to all the values\nreturned by EXPR, as if by `multiple-value-list'.\n\nFrom Scheme (SRFI-8).\"\n ;; It's probably not worth stack-allocating the thunk.\n (cond ((null formals)\n `(multiple-value-call\n (lambda ()\n ,@body)\n ,expr))\n ((atom formals)\n ;; This could also be written:\n #+(or) `(let ((,formals (multiple-value-list ,expr)))\n ,@body)\n ;; But I want it to be possible to declare FORMALS to have\n ;; dynamic extent, and most Lisps support that for &rest\n ;; lists.\n `(multiple-value-call\n (lambda (&rest ,formals)\n ,@body)\n ,expr))\n ((proper-list-p formals)\n (when (intersection formals lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda ,formals\n ,@body)\n ,expr))\n (t (let* ((last (last formals))\n (vars (append (butlast formals)\n (list (car last))))\n (rest (cdr last)))\n (when (intersection (cons rest vars) lambda-list-keywords)\n (error \"Lambda list keywords in formals: ~a\" formals))\n `(multiple-value-call\n (lambda (,@vars &rest ,rest)\n ,@body)\n ,expr)))))", "macroexpand": "(multiple-value-call (lambda (x) x) (values))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do+ (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y :on-error (lambda (value cond) (setf error cond) value)) y))) (when error (multiple-value-bind (value success?) (try-update y) (is (eql value y)) (is (null success?)))))\n\nIssue: Macro call that should be transformed by do+", "input": "(do+ (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y :on-error (lambda (value cond) (setf error cond) value)) y))) (when error (multiple-value-bind (value success?) (try-update y) (is (eql value y)) (is (null success?)))))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (to 5)) (generating y (in #(0 1))) (collect (list x y)) (when (oddp x) (is (eql (try-update y :on-error (lambda (value cond) (setf error cond) value)) y))) (when error (multiple-value-bind (value success?) (try-update y) (is (eql value y)) (is (null success?)))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-neo4j-fun list-indexes ((type :node)) :get (:uri-spec (format nil \"index/~A\" (string-downcase (symbol-name type)))) (:status-handlers (200 (decode-neo4j-json-output body))))\n\nProblem: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun list-indexes ((type :node)) :get (:uri-spec (format nil \"index/~A\" (string-downcase (symbol-name type)))) (:status-handlers (200 (decode-neo4j-json-output body))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun list-indexes (&key (type :node)) (let ((uri (format nil \"index/~A\" (string-downcase (symbol-name type)))) (json (encode-neo4j-json-payload nil :string))) (make-neo4j-request :get uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defiter nil\n (progn))\n\nProblem: Macro call that should be transformed by DEFITER", "input": "(defiter nil\n (progn))", "output": "(defmacro DEFITER ...)", "macroexpand": "(defun nil (progn) (make-instance 'iterator :coro (lambda-coro)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-templated-dispatch nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFINE-TEMPLATED-DISPATCH", "input": "(define-templated-dispatch nil\n :key\n nil)", "output": "(defmacro DEFINE-TEMPLATED-DISPATCH ...)", "macroexpand": "(define-type-dispatch nil\n :key)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(caching-types)\n\nIssue: Macro call that should be transformed by CACHING-TYPES", "input": "(caching-types)", "output": "(defmacro CACHING-TYPES ...)", "macroexpand": "(call-with-disjoint-hash\n (lambda ()\n (call-with-subtype-hash\n (lambda ()\n (call-with-equiv-hash\n (lambda () (call-with-subtypep-cache (lambda ()))))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-<>>\n 'some-name)\n\nWhat needs to change: Macro call that should be transformed by -<>>", "input": "(-<>>\n 'some-name)", "output": "(defmacro -<>> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(->*\n nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by ->*", "input": "(->*\n nil\n (progn))", "output": "(defmacro ->* ...)", "macroexpand": "(let* ((#:var192 (progn)) (#:var193 (nil #:var192)))\n #:var193)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-class some-class (some super classes) ((slot1 :unbound :documentation \"zork\")) (1 2) (3 4))\n\nPattern to recognize: Macro call that should be transformed by define-class", "input": "(define-class some-class (some super classes) ((slot1 :unbound :documentation \"zork\")) (1 2) (3 4))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass some-class (some super classes) ((slot1 :accessor slot1 :initarg :slot1 :documentation \"zork\")) (1 2) (3 4)) (unless (fboundp (quote some-class-p)) (define-generic some-class-p (object) #A((75) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `some-class'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote some-class)))) (setf (documentation (quote slot1) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot SLOT1.\nzork\")) (ignore-errors (setf (documentation (fdefinition (quote slot1)) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot SLOT1.\nzork\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf slot1))) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot SLOT1.\nzork\"))) (find-class (quote some-class) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-modf-rewrite cdar (expr) `(cdr (car ,(second expr))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cdar (expr) `(cdr (car ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (car #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defstore example (object))\n\nWrite a macro that addresses: Macro call that should be transformed by defstore", "input": "(defstore example (object))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote example) (quote (object)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some->)\n\nProblem: Macro call that should be transformed by SOME->", "input": "(some->)", "output": "(defmacro SOME-> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-packages-unlocked 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-PACKAGES-UNLOCKED", "input": "(with-packages-unlocked 'some-name)", "output": "(defmacro WITH-PACKAGES-UNLOCKED ...)", "macroexpand": "(let ((#:|packages124| (locked-packages ''some-name)))\n (unlock-packages #:|packages124|)\n (unwind-protect (lock-packages #:|packages124|)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(answer foo 42)\n\nProblem: Macro call that should be transformed by answer", "input": "(answer foo 42)", "output": "(defmacro answer (call &body forms)\n (let ((name (if (listp call) (car call) call))\n (sym (gensym)))\n `(if-called\n ',name\n (let ((,sym (fdefinition ',name)))\n (declare (ignorable ,sym))\n (let ((times 0))\n (lambda (&rest args)\n (declare (ignorable args))\n ,(let ((cases\n `(case (prog1 times (incf times))\n ,.(loop\n for i from 0\n for (form . rest) on forms\n collect `(,(if rest i T) ,form)))))\n (if (listp call)\n `(trivia:match args\n ((list . ,(cdr call)) ,cases)\n (_ (unhandled)))\n cases))))))))", "macroexpand": "(if-called (quote foo) (let ((#:g162 (fdefinition (quote foo)))) (declare (ignorable #:g162)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (case (prog1 times (incf times)) (t 42))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defvar-compile-time *tagbody-tags* '() \"This must be globally NIL.\")\n\nWrite a macro that addresses: Macro call that should be transformed by defvar-compile-time", "input": "(defvar-compile-time *tagbody-tags* '() \"This must be globally NIL.\")", "output": "(defmacro defvar-compile-time (name &optional initial-value documentation)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,name ,initial-value ,documentation)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *tagbody-tags* (quote nil) \"This must be globally NIL.\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(f 'some-name)\n\nProblem: Macro call that should be transformed by F", "input": "(f 'some-name)", "output": "(defmacro F ...)", "macroexpand": "(lambda (quote some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(bdd-typecase 'some-name)\n\nWhat needs to change: Macro call that should be transformed by BDD-TYPECASE", "input": "(bdd-typecase 'some-name)", "output": "(defmacro BDD-TYPECASE ...)", "macroexpand": "((lambda (#:obj165)\n (declare (ignorable #:obj165))\n (block #:block166 (tagbody)))\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-hash nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-HASH", "input": "(collect-hash nil (progn))", "output": "(defmacro COLLECT-HASH ...)", "macroexpand": "(common-lisp:let* ((#:out-149 (make-hash-table)))\n (common-lisp:let ((#:generator-153 (generator (progn)))\n #:values-145\n (#:generator-151 (generator nil))\n #:keys-144)\n (declare (type generator #:generator-153)\n (type generator #:generator-151))\n (tagbody\n #:ll-154\n (setq #:values-145 (next-in #:generator-153 (go end)))\n (setq #:keys-144 (next-in #:generator-151 (go end)))\n (setf (gethash #:keys-144 #:out-149) #:values-145)\n (go #:ll-154)\n end)\n #:out-149))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error unknown-type-spec () (type-spec) \"Could not find the correct type for type-spec ~s~@[ ~a~]~%~a\" type-spec (when (typep type-spec 'v-type) (format nil \"~%It seems we recieved a type object instead of type spec\")) (let ((found (find-alternative-types-for-spec type-spec))) (if found (format nil \"~%Perhaps you meant one of these types?:~%~(~{~s~%~}~)\" found) \"\")))\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error unknown-type-spec () (type-spec) \"Could not find the correct type for type-spec ~s~@[ ~a~]~%~a\" type-spec (when (typep type-spec 'v-type) (format nil \"~%It seems we recieved a type object instead of type spec\")) (let ((found (find-alternative-types-for-spec type-spec))) (if found (format nil \"~%Perhaps you meant one of these types?:~%~(~{~s~%~}~)\" found) \"\")))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition unknown-type-spec (:error-type varjo-error :prefix \"Varjo\") (type-spec) \"Could not find the correct type for type-spec ~s~@[ ~a~]~%~a\" type-spec (when (typep type-spec (quote v-type)) (format nil \"~%It seems we recieved a type object instead of type spec\")) (let ((found (find-alternative-types-for-spec type-spec))) (if found (format nil \"~%Perhaps you meant one of these types?:~%~(~{~s~%~}~)\" found) \"\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-dynenv-macro nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEF-DYNENV-MACRO", "input": "(def-dynenv-macro nil\n nil)", "output": "(defmacro DEF-DYNENV-MACRO ...)", "macroexpand": "(defmacro nil (&environment #:env174) (with-dynenv #:env174))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deferror \"08007\" transaction-resolution-unknown)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"08007\" transaction-resolution-unknown)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition transaction-resolution-unknown (database-error) nil) (setf (gethash \"08007\" *error-table*) (quote transaction-resolution-unknown)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(failure NIL)\n\nProblem: Macro call that should be transformed by fail", "input": "(failure NIL)", "output": "(defmacro fail (form &optional (type 'error) description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(fail ,form ,type)\n :value-form '(capture-error ,form)\n :body (lambda () (capture-error ,form ,(maybe-unquote type)))\n :expected ',(maybe-unquote type)\n :comparison 'typep\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(failure nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(flow-lambda-macro (flow-context) `(flet ((,test-fu () ,live-test-form)) (dispatch-repeatedly ,flow-context #',test-fu ,flow-list)))\n\nIssue: Macro call that should be transformed by flow-lambda-macro", "input": "(flow-lambda-macro (flow-context) `(flet ((,test-fu () ,live-test-form)) (dispatch-repeatedly ,flow-context #',test-fu ,flow-list)))", "output": "(defmacro flow-lambda-macro ((flow-context) &body body)\n `(with-gensyms (,flow-context)\n `(%flow-lambda (,,flow-context)\n ,,@body)))", "macroexpand": "(with-gensyms (flow-context) (sb-int:quasiquote (%flow-lambda (#S(sb-impl::comma :expr flow-context :kind 0)) #S(sb-impl::comma :expr (sb-int:quasiquote (flet ((#S(sb-impl::comma :expr test-fu :kind 0) nil #S(sb-impl::comma :expr live-test-form :kind 0))) (dispatch-repeatedly #S(sb-impl::comma :expr flow-context :kind 0) (function #S(sb-impl::comma :expr test-fu :kind 0)) #S(sb-impl::comma :expr flow-list :kind 0)))) :kind 0))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym :reducing :reduce)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym :reducing :reduce)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :reducing) (quote synonym)) (quote :reduce)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-interleaving `(with-interleaving ,@(loop for part in (rest form) collect (remove-bindings bindings part))))\n\nWhat needs to change: Macro call that should be transformed by with-interleaving", "input": "(with-interleaving `(with-interleaving ,@(loop for part in (rest form) collect (remove-bindings bindings part))))", "output": "(defmacro with-interleaving (&body body)\n (let* ((root (copy-list (pop body)))\n (current root))\n (dolist (form body root)\n (let ((form (copy-list form)))\n (when form\n (setf (cdr (last current)) (cons form NIL))\n (setf current form))))))", "macroexpand": "(sb-int:quasiquote (with-interleaving #S(sb-impl::comma :expr (loop for part in (rest form) collect (remove-bindings bindings part)) :kind 2)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(f nil\n (progn))\n\nIssue: Macro call that should be transformed by F", "input": "(f nil\n (progn))", "output": "(defmacro F ...)", "macroexpand": "(lambda () (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(enable-readtime-wrapper-syntax nil (progn))\n\nIssue: Macro call that should be transformed by ENABLE-READTIME-WRAPPER-SYNTAX", "input": "(enable-readtime-wrapper-syntax nil (progn))", "output": "(defmacro ENABLE-READTIME-WRAPPER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-readtime-wrapper-syntax-in-readtable nil (progn))\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(quasiquote-expand-1 'list (butlast x))\n\nWhat needs to change: Macro call that should be transformed by quasiquote", "input": "(quasiquote-expand-1 'list (butlast x))", "output": "(defmacro quasiquote (x) (quasiquote-expand x))", "macroexpand": "(quasiquote-expand-1 (quote list) (butlast x))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7925} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defsynonym :with with)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym :with with)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :with) (quote synonym)) (quote with)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defstore example (a &optional (b (the real (compute-default a))) (c (the real (1+ b)))))\n\nWrite a macro that addresses: Macro call that should be transformed by defstore", "input": "(defstore example (a &optional (b (the real (compute-default a))) (c (the real (1+ b)))))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (defun a-init-function152 (a) (declare (ignorable a)) (the real (compute-default a))) (defun b-init-function154 (a b #:b?160) (declare (ignorable a b #:b?160)) (the real (1+ b))) (ensure-store (quote example) (quote (a &optional (b (the real (a-init-function152 a)) #:b?160) (c (the real (b-init-function154 a b #:b?160)) #:c?161))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(-<>> 'some-name)\n\nPattern to recognize: Macro call that should be transformed by -<>>", "input": "(-<>> 'some-name)", "output": "(defmacro -<>> ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(action (:traverse node-application node bound-variables) (unless (tracked-variable-p (node-application-rator node) bound-variables) (funcall *traverse* (node-application-rator node) bound-variables)) (loop :for rand :in (node-application-rands node) :do (funcall *traverse* rand bound-variables)) (traverse-keyword-rands (node-application-keyword-rands node) bound-variables) node)\n\nWhat needs to change: Macro call that should be transformed by action", "input": "(action (:traverse node-application node bound-variables) (unless (tracked-variable-p (node-application-rator node) bound-variables) (funcall *traverse* (node-application-rator node) bound-variables)) (loop :for rand :in (node-application-rands node) :do (funcall *traverse* rand bound-variables)) (traverse-keyword-rands (node-application-keyword-rands node) bound-variables) node)", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :traverse) (quote node-application) (lambda (node bound-variables) (declare (type node-application node)) (unless (tracked-variable-p (node-application-rator node) bound-variables) (funcall *traverse* (node-application-rator node) bound-variables)) (loop :for rand :in (node-application-rands node) :do (funcall *traverse* rand bound-variables)) (traverse-keyword-rands (node-application-keyword-rands node) bound-variables) node))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ps-doc\n 'some-name)\n\nWhat needs to change: Macro call that should be transformed by PS-DOC", "input": "(ps-doc\n 'some-name)", "output": "(defmacro PS-DOC ...)", "macroexpand": "\"'someName';\"", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(\u0192\u2192 nil nil)\n\nWhat needs to change: Macro call that should be transformed by \u0191\u2192", "input": "(\u0192\u2192 nil nil)", "output": "(defmacro \u0191\u2192 ...)", "macroexpand": "(defn nil nil (&optional \u03b1)\n (let ((\u03b1 (or \u03b1 t)))\n (cond)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-cruft %unassociate-name-from-readtable (name readtable) \"Remove the association between NAME and READTABLE\" #+ :allegro (let ((n (readtable-name-for-allegro name))) (assert (eq readtable (excl:named-readtable n))) (setf (excl:named-readtable n) nil)) #+ :common-lisp (progn (assert (eq readtable (gethash name *named-readtables*))) (remhash name *named-readtables*)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-cruft", "input": "(define-cruft %unassociate-name-from-readtable (name readtable) \"Remove the association between NAME and READTABLE\" #+ :allegro (let ((n (readtable-name-for-allegro name))) (assert (eq readtable (excl:named-readtable n))) (setf (excl:named-readtable n) nil)) #+ :common-lisp (progn (assert (eq readtable (gethash name *named-readtables*))) (remhash name *named-readtables*)))", "output": "(defmacro define-cruft (name lambda-list &body (docstring . alternatives))\n (assert (typep docstring 'string) (docstring) \"Docstring missing!\")\n (assert (not (null alternatives)))\n `(progn\n (declaim (inline ,name))\n (defun ,name ,lambda-list ,docstring ,(first alternatives))))", "macroexpand": "(progn (declaim (inline %unassociate-name-from-readtable)) (defun %unassociate-name-from-readtable (name readtable) \"Remove the association between NAME and READTABLE\" (progn (assert (eq readtable (gethash name *named-readtables*))) (remhash name *named-readtables*))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(-> :tag-2 ((a b)) (concatenate 'string a b \" World!\"))\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(-> :tag-2 ((a b)) (concatenate 'string a b \" World!\"))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :tag-2 ((a b)) (concatenate (quote string) a b \" World!\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(without-package-lock (:common-lisp #+lispworks :implementation) (defmethod documentation ((name symbol) (doc-type (eql 'readtable))) (let ((readtable (find-readtable name))) (and readtable (gethash readtable *readtable-to-docstring*)))) (defmethod documentation ((readtable readtable) (doc-type (eql 'readtable))) (gethash readtable *readtable-to-docstring*)) (defmethod (setf documentation) (docstring (name symbol) (doc-type (eql 'readtable))) (let ((readtable (find-readtable name))) (unless readtable (error 'readtable-does-not-exist :readtable-name name)) (setf (gethash readtable *readtable-to-docstring*) docstring))) (defmethod (setf documentation) (docstring (readtable readtable) (doc-type (eql 'readtable))) (setf (gethash readtable *readtable-to-docstring*) docstring)))\n\nPattern to recognize: Macro call that should be transformed by without-package-lock", "input": "(without-package-lock (:common-lisp #+lispworks :implementation) (defmethod documentation ((name symbol) (doc-type (eql 'readtable))) (let ((readtable (find-readtable name))) (and readtable (gethash readtable *readtable-to-docstring*)))) (defmethod documentation ((readtable readtable) (doc-type (eql 'readtable))) (gethash readtable *readtable-to-docstring*)) (defmethod (setf documentation) (docstring (name symbol) (doc-type (eql 'readtable))) (let ((readtable (find-readtable name))) (unless readtable (error 'readtable-does-not-exist :readtable-name name)) (setf (gethash readtable *readtable-to-docstring*) docstring))) (defmethod (setf documentation) (docstring (readtable readtable) (doc-type (eql 'readtable))) (setf (gethash readtable *readtable-to-docstring*) docstring)))", "output": "(defmacro without-package-lock ((&rest package-names) &body body)\n (declare (ignorable package-names))\n #+clisp\n (return-from without-package-lock\n `(ext:without-package-lock (,@package-names) ,@body))\n #+lispworks\n (return-from without-package-lock\n `(let ((hcl:*packages-for-warn-on-redefinition*\n (set-difference hcl:*packages-for-warn-on-redefinition*\n '(,@package-names)\n :key (lambda (package-designator)\n (if (packagep package-designator)\n (package-name package-designator)\n package-designator))\n :test #'string=)))\n ,@body))\n `(progn ,@body))", "macroexpand": "(progn (defmethod documentation ((name symbol) (doc-type (eql (quote readtable)))) (let ((readtable (find-readtable name))) (and readtable (gethash readtable *readtable-to-docstring*)))) (defmethod documentation ((readtable readtable) (doc-type (eql (quote readtable)))) (gethash readtable *readtable-to-docstring*)) (defmethod (setf documentation) (docstring (name symbol) (doc-type (eql (quote readtable)))) (let ((readtable (find-readtable name))) (unless readtable (error (quote readtable-does-not-exist) :readtable-name name)) (setf (gethash readtable *readtable-to-docstring*) docstring))) (defmethod (setf documentation) (docstring (readtable readtable) (doc-type (eql (quote readtable)))) (setf (gethash readtable *readtable-to-docstring*) docstring)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-component-testers (a b #'pathname-type) (components-are-member '(nil :wild :unspecific)) (components-are-string=))\n\nPattern to recognize: Macro call that should be transformed by with-component-testers", "input": "(with-component-testers (a b #'pathname-type) (components-are-member '(nil :wild :unspecific)) (components-are-string=))", "output": "(defmacro with-component-testers ((a b key) &body body)\n (let ((k (gensym)))\n `(let* ((,k ,key)\n (,a (funcall ,k ,a))\n (,b (funcall ,k ,b)))\n (labels ((components-are (test)\n (and (funcall test ,a) (funcall test ,b)))\n (components-are-member (values)\n (and (member ,a values :test #'eql)\n (member ,b values :test #'eql)\n (eql ,a ,b)))\n (components-are-string= ()\n (and (stringp ,a) (stringp ,b) (string= ,a ,b)))\n (components-are-every (test)\n (and (consp ,a)\n (consp ,b)\n (every test ,a ,b))))\n (declare (ignorable #'components-are #'components-are-member\n #'components-are-string= #'components-are-every))\n (if (or ,@body)\n (values t ,a ,b)\n nil)))))", "macroexpand": "(let* ((#:g147 (function pathname-type)) (a (funcall #:g147 a)) (b (funcall #:g147 b))) (labels ((components-are (test) (and (funcall test a) (funcall test b))) (components-are-member (values) (and (member a values :test (function eql)) (member b values :test (function eql)) (eql a b))) (components-are-string= nil (and (stringp a) (stringp b) (string= a b))) (components-are-every (test) (and (consp a) (consp b) (every test a b)))) (declare (ignorable (function components-are) (function components-are-member) (function components-are-string=) (function components-are-every))) (if (or (components-are-member (quote (nil :wild :unspecific))) (components-are-string=)) (values t a b) nil)))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(c? (when (kv-collector self) (funcall (kv-collector self) (^value))))\n\nPattern to recognize: Macro call that should be transformed by c?", "input": "(c? (when (kv-collector self) (funcall (kv-collector self) (^value))))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((when (kv-collector self) (funcall (kv-collector self) (^value))))) :value-state :unevaluated :rule (c-lambda (when (kv-collector self) (funcall (kv-collector self) (^value)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"23001\" restrict-violation integrity-violation)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"23001\" restrict-violation integrity-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition restrict-violation (integrity-violation) nil) (setf (gethash \"23001\" *error-table*) (quote restrict-violation)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(undefreply nil)\n\nProblem: Macro call that should be transformed by UNDEFREPLY", "input": "(undefreply nil)", "output": "(defmacro UNDEFREPLY ...)", "macroexpand": "(undefine-reply 'nil :qualifiers 'nil :participants `nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(when (node-slot shared) (make-proxy shared comma))\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when (node-slot shared) (make-proxy shared comma))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (node-slot shared) (make-proxy shared comma))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(keep-bops nil)\n\nProblem: Macro call that should be transformed by KEEP-BOPS", "input": "(keep-bops nil)", "output": "(defmacro KEEP-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn\n (init-binfix)\n (unless nil\n (setq *binfix*\n (delete nil\n (mapcar\n (lambda (bs)\n (setq bs\n (delete-if\n (lambda (b)\n (unless (member (car b) '(nil))\n (remprop (car b) 'properties)\n t))\n bs)))\n *binfix*)))\n (assign-properties))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(match0 (remove nil (list (hyphened) (concname) (nameonly))) ((list sym) sym) ((list) nil) (readers (ambiguous-slot-error \"Multiple candidates of the accessor function: ~{~a~^, ~}\" readers)))\n\nProblem: Macro call that should be transformed by match0", "input": "(match0 (remove nil (list (hyphened) (concname) (nameonly))) ((list sym) sym) ((list) nil) (readers (ambiguous-slot-error \"Multiple candidates of the accessor function: ~{~a~^, ~}\" readers)))", "output": "(defmacro match0 (*what* &body clauses &environment *env*)\n (once-only (*what*)\n (parse-patterns clauses)))", "macroexpand": "(let ((#:*what*158 (remove nil (list (hyphened) (concname) (nameonly))))) (declare (ignorable #:*what*158)) (if (and (consp #:*what*158) (let ((#:*what*159 (car #:*what*158))) (declare (ignorable #:*what*159)) t) (let ((#:*what*160 (cdr #:*what*158))) (declare (ignorable #:*what*160)) (equal #:*what*160 nil))) (let* ((#:*what*159 (car #:*what*158)) (sym #:*what*159) (#:*what*160 (cdr #:*what*158))) (declare (ignorable #:*what*160 sym #:*what*159)) sym) (if (null #:*what*158) (let* nil (declare (ignorable)) nil) (if t (let* ((readers #:*what*158)) (declare (ignorable readers)) (ambiguous-slot-error \"Multiple candidates of the accessor function: ~{~a~^, ~}\" readers)) nil))))", "category": "control-flow", "technique": "once-only", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(*let nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by *LET", "input": "(*let nil\n nil)", "output": "(defmacro *LET ...)", "macroexpand": "(let* ()\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-custom-var (:object-value *object-value-handler*))\n\nIssue: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:object-value *object-value-handler*))", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*object-value-handler* . :object-value)) *custom-vars* :test (function equal)) (defvar *object-value-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(assert-values (\"deleted foo\") (foo 'nothing) (foo+1 'nothing) (bar 2) (bar-1 1))\n\nWrite a macro that addresses: Macro call that should be transformed by assert-values", "input": "(assert-values (\"deleted foo\") (foo 'nothing) (foo+1 'nothing) (bar 2) (bar-1 1))", "output": "(defmacro assert-values ((desc) &body objects-and-values)\n `(progn\n (trc ,desc)\n ,@(loop for (obj val) in objects-and-values\n\t collect `(assert (eql (value ,obj) ,val)))))", "macroexpand": "(progn (trc \"deleted foo\") (assert (eql (value foo) (quote nothing))) (assert (eql (value foo+1) (quote nothing))) (assert (eql (value bar) 2)) (assert (eql (value bar-1) 1)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(\u03bb\u03bb)\n\nIssue: Macro call that should be transformed by \u039b\u039b", "input": "(\u03bb\u03bb)", "output": "(defmacro \u039b\u039b ...)", "macroexpand": "(lambda (&optional \u03b1) (cond))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect-product 'some-name)\n\nWhat needs to change: Macro call that should be transformed by COLLECT-PRODUCT", "input": "(collect-product 'some-name)", "output": "(defmacro COLLECT-PRODUCT ...)", "macroexpand": "(common-lisp:let* ((#:generator-131 (generator 'some-name))\n #:numbers-127\n (#:mul-128 1))\n (declare (type generator #:generator-131)\n (type number #:mul-128))\n (tagbody\n #:ll-132\n (setq #:numbers-127 (next-in #:generator-131 (go end)))\n (setq #:mul-128 (* #:mul-128 #:numbers-127))\n (go #:ll-132)\n end)\n #:mul-128)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-notation bind-maybe ((sum nothing) (str (maybe->string sum))) (print str))\n\nProblem: Macro call that should be transformed by do-notation", "input": "(do-notation bind-maybe ((sum nothing) (str (maybe->string sum))) (print str))", "output": "(defmacro do-notation (bind-function expressions &body body)\n \"Given a BIND-FUNCTION and all the bind expressions, evaluate BODY.\"\n `(progn\n ,@(reduce (lambda (acc do-binding)\n\t\t (append `((,bind-function (lambda (,(car do-binding)) ,@acc)\n\t\t\t\t\t ,@(cdr do-binding)))))\n\t (reverse expressions)\n\t :initial-value body)))", "macroexpand": "(progn (bind-maybe (lambda (sum) (bind-maybe (lambda (str) (print str)) (maybe->string sum))) nothing))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq))) (copy-node value (node-type node))))\n\nIssue: Macro call that should be transformed by action", "input": "(action (:after node-variable node bound-variables) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test #'eq))) (copy-node value (node-type node))))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-variable) (lambda (node bound-variables) (declare (type node-variable node)) (when (and (eq name (node-variable-value node)) (not (member name bound-variables :test (function eq)))) (copy-node value (node-type node)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defsynonym next :next)\n\nPattern to recognize: Macro call that should be transformed by defsynonym", "input": "(defsynonym next :next)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote next) (quote synonym)) (quote :next)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(count-of nil\n (progn))\n\nProblem: Macro call that should be transformed by COUNT-OF", "input": "(count-of nil\n (progn))", "output": "(defmacro COUNT-OF ...)", "macroexpand": "(lc (nil (progn)) count)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-cached-reader-conditionals)\n\nWhat needs to change: Macro call that should be transformed by WITH-CACHED-READER-CONDITIONALS", "input": "(with-cached-reader-conditionals)", "output": "(defmacro WITH-CACHED-READER-CONDITIONALS ...)", "macroexpand": "(call-with-cached-reader-conditionals (lambda ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*> (char #\\\\) (alt (<$ #\\newline (char #\\n)) (<$ #\\tab (char #\\t)) (<$ #\\return (char #\\r)) (<$ #\\backspace (char #\\b)) (<$ #\\page (char #\\f))))\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> (char #\\\\) (alt (<$ #\\newline (char #\\n)) (<$ #\\tab (char #\\t)) (<$ #\\return (char #\\r)) (<$ #\\backspace (char #\\b)) (<$ #\\page (char #\\f))))", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset197) (multiple-value-bind (#:*>-res198 #:*>-next199) (funcall (char #\\REVERSE_SOLIDUS) #:*>-offset197) (if (ok? #:*>-res198) (funcall (alt (<$ #\\Newline (char #\\LATIN_SMALL_LETTER_N)) (<$ #\\Tab (char #\\LATIN_SMALL_LETTER_T)) (<$ #\\Return (char #\\LATIN_SMALL_LETTER_R)) (<$ #\\Backspace (char #\\LATIN_SMALL_LETTER_B)) (<$ #\\Page (char #\\LATIN_SMALL_LETTER_F))) #:*>-next199) (fail #:*>-next199))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(some-<>>)\n\nProblem: Macro call that should be transformed by SOME-<>>", "input": "(some-<>>)", "output": "(defmacro SOME-<>> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(c? (1+ (^m-cyc2-a)))\n\nWhat needs to change: Macro call that should be transformed by c?", "input": "(c? (1+ (^m-cyc2-a)))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((1+ (^m-cyc2-a)))) :value-state :unevaluated :rule (c-lambda (1+ (^m-cyc2-a))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-yield-binds (if (cdr (conjunctive-op-expressions op)) (format nil (format nil \"(~~{~~A~~^ ~A ~~})\" (sql-op-name op)) (mapcar #'yield (conjunctive-op-expressions op))) (yield (car (conjunctive-op-expressions op)))))\n\nIssue: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (if (cdr (conjunctive-op-expressions op)) (format nil (format nil \"(~~{~~A~~^ ~A ~~})\" (sql-op-name op)) (mapcar #'yield (conjunctive-op-expressions op))) (yield (car (conjunctive-op-expressions op)))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (if (cdr (conjunctive-op-expressions op)) (format nil (format nil \"(~~{~~A~~^ ~A ~~})\" (sql-op-name op)) (mapcar (function yield) (conjunctive-op-expressions op))) (yield (car (conjunctive-op-expressions op))))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(parse-conjunctive-clauses client instance t)\n\nProblem: Macro call that should be transformed by parse-conjunctive-clauses", "input": "(parse-conjunctive-clauses client instance t)", "output": "(defmacro parse-conjunctive-clauses (client region read-name-p &rest args)\n (with-unique-names (clauses next)\n `(prog (,clauses)\n ,next\n (push (do-parse-clause ,client ,region *index* ,read-name-p ,@args)\n ,clauses)\n (when (maybe-parse-token :keywords '(:and))\n (go ,next))\n (return (nreverse ,clauses)))))", "macroexpand": "(prog (#:clauses122) #:next123 (push (do-parse-clause client instance *index* t) #:clauses122) (when (maybe-parse-token :keywords (quote (:and))) (go #:next123)) (return (nreverse #:clauses122)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(f nil\n nil)\n\nIssue: Macro call that should be transformed by F", "input": "(f nil\n nil)", "output": "(defmacro F ...)", "macroexpand": "(lambda () nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(special-symbol-progv nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by SPECIAL-SYMBOL-PROGV", "input": "(special-symbol-progv nil\n (progn))", "output": "(defmacro SPECIAL-SYMBOL-PROGV ...)", "macroexpand": "(let (#:symbol-list178)\n (tagbody\n #:retry179\n (setq #:symbol-list178 nil)\n (unless (every #'special-symbol-p #:symbol-list178)\n (cerror \"Retry to rebind the place(s).\"\n \"Attempt at rebinding one or more non-special places: ~S\" 'nil)\n (go #:retry179)))\n (dynamic-progv #:symbol-list178\n (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defmacro* nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFMACRO*", "input": "(defmacro* nil\n :key\n nil)", "output": "(defmacro DEFMACRO* ...)", "macroexpand": "(defmacro nil :key\n `(with-yield\n ,nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(c-assert (or (null (fm-parent kid)) (eql fm-parent (fm-parent kid))))\n\nProblem: Macro call that should be transformed by c-assert", "input": "(c-assert (or (null (fm-parent kid)) (eql fm-parent (fm-parent kid))))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (or (null (fm-parent kid)) (eql fm-parent (fm-parent kid))) (c-break \"failed assertion: ~a\" (quote (or (null (fm-parent kid)) (eql fm-parent (fm-parent kid)))))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.9375} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(odig nil)\n\nProblem: Macro call that should be transformed by ODIG", "input": "(odig nil)", "output": "(defmacro ODIG ...)", "macroexpand": "(odig 1 nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when (first in-decl) (pop in-decl-item))\n\nIssue: Macro call that should be transformed by when", "input": "(when (first in-decl) (pop in-decl-item))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (first in-decl) (pop in-decl-item))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(resolve\n 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by RESOLVE", "input": "(resolve\n 'some-name)", "output": "(defmacro RESOLVE ...)", "macroexpand": "(locally\n (declare)\n (multiple-value-bind (#:assignment155 #:unified-p156)\n (type-unify 'nil 'nil (list))\n (assert #:unified-p156 nil 'simple-type-error :format-control\n \"gtypes failed to unify to the actual types:~% ~a~% against~% ~a\"\n :format-arguments (list 'nil (list)))\n (let ()\n (declare (ignorable))\n 'some-name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun/1 getchar () (getc stdin))\n\nProblem: Macro call that should be transformed by defun/1", "input": "(defun/1 getchar () (getc stdin))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun getchar nil (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (getc stdin)) (defparameter getchar (vacietis.c:mkptr& (symbol-function (quote getchar)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def$frame nil :key nil)\n\nIssue: Macro call that should be transformed by DEF$FRAME", "input": "(def$frame nil :key nil)", "output": "(defmacro DEF$FRAME ...)", "macroexpand": "(def$flavor nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-wrap-attempt () name (define-foreign-type name (make-instance 'foreign-alias :name name :type (ensure-type type \"alias of type ~S to ~S\" type name))))\n\nProblem: Macro call that should be transformed by with-wrap-attempt", "input": "(with-wrap-attempt () name (define-foreign-type name (make-instance 'foreign-alias :name name :type (ensure-type type \"alias of type ~S to ~S\" type name))))", "output": "(defmacro with-wrap-attempt ((&optional format-control &rest format-args) wrappable-name &body body)\n `(call-with-wrap-attempt ,wrappable-name (lambda () ,@body) ,format-control (list ,@format-args)))", "macroexpand": "(call-with-wrap-attempt name (lambda nil (define-foreign-type name (make-instance (quote foreign-alias) :name name :type (ensure-type type \"alias of type ~S to ~S\" type name)))) nil (list))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-alias-binding append appending)\n\nPattern to recognize: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding append appending)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote append)) (quote appending)) (quote append))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-direct-binding over (var iterable &rest iterator-args) (let ((iterator (gensym \"ITERATOR\")) (next (gensym \"NEXT\")) (has-more (gensym \"HAS-MORE\")) (update (gensym \"UPDATE\")) (end (gensym \"END\"))) (values `(with-interleaving (let (,@(lambda-fiddle:extract-lambda-vars (enlist var)) (,iterator (make-iterator ,iterable ,@iterator-args)))) (multiple-value-bind (,next ,has-more ,update ,end) (step-functions ,iterator) (declare (ignore ,update))) (unwind-protect* (funcall ,end))) `(if (funcall ,has-more) (update ,var (funcall ,next)) (end-for)))))\n\nPattern to recognize: Macro call that should be transformed by define-direct-binding", "input": "(define-direct-binding over (var iterable &rest iterator-args) (let ((iterator (gensym \"ITERATOR\")) (next (gensym \"NEXT\")) (has-more (gensym \"HAS-MORE\")) (update (gensym \"UPDATE\")) (end (gensym \"END\"))) (values `(with-interleaving (let (,@(lambda-fiddle:extract-lambda-vars (enlist var)) (,iterator (make-iterator ,iterable ,@iterator-args)))) (multiple-value-bind (,next ,has-more ,update ,end) (step-functions ,iterator) (declare (ignore ,update))) (unwind-protect* (funcall ,end))) `(if (funcall ,has-more) (update ,var (funcall ,next)) (end-for)))))", "output": "(defmacro define-direct-binding (name args &body body)\n (let ((env (or (lambda-fiddle:environment-lambda-var args) (gensym \"ENVIRONMENT\"))))\n `(progn (setf (binding ',name)\n (lambda ,(lambda-fiddle:remove-environment-part args)\n (let ((,env *environment*))\n (declare (ignorable ,env))\n ,@body)))\n ',name)))", "macroexpand": "(progn (setf (binding (quote over)) (lambda (var iterable &rest iterator-args) (let ((#:environment127 *environment*)) (declare (ignorable #:environment127)) (let ((iterator (gensym \"ITERATOR\")) (next (gensym \"NEXT\")) (has-more (gensym \"HAS-MORE\")) (update (gensym \"UPDATE\")) (end (gensym \"END\"))) (values (sb-int:quasiquote (with-interleaving (let (#S(sb-impl::comma :expr (lambda-fiddle:extract-lambda-vars (enlist var)) :kind 2) (#S(sb-impl::comma :expr iterator :kind 0) (make-iterator #S(sb-impl::comma :expr iterable :kind 0) #S(sb-impl::comma :expr iterator-args :kind 2))))) (multiple-value-bind (#S(sb-impl::comma :expr next :kind 0) #S(sb-impl::comma :expr has-more :kind 0) #S(sb-impl::comma :expr update :kind 0) #S(sb-impl::comma :expr end :kind 0)) (step-functions #S(sb-impl::comma :expr iterator :kind 0)) (declare (ignore #S(sb-impl::comma :expr update :kind 0)))) (unwind-protect* (funcall #S(sb-impl::comma :expr end :kind 0))))) (sb-int:quasiquote (if (funcall #S(sb-impl::comma :expr has-more :kind 0)) (update #S(sb-impl::comma :expr var :kind 0) (funcall #S(sb-impl::comma :expr next :kind 0))) (end-for)))))))) (quote over))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-> nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by ->", "input": "(-> nil :key nil)", "output": "(defmacro -> ...)", "macroexpand": "(nil (:key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-instance* 'class (a b c) (when t (list :x x)))\n\nIssue: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class (a b c) (when t (list :x x)))", "output": "(defmacro make-instance* (class &rest arguments)\n \"Convenience macro on top of `make-instance'.\n\nConveniences:\n\n- First argument can be a (possibly empty) list of shortcut symbols,\n which is automatically converted into a KEYWORD+SYMBOL pairs where\n - KEYWORD is the same as shortcut name, but interned as keyword.\n - And SYMBOL is the same as shortcut.\n\n- The last argument can be an apply argument---arbitrary\n list-producing form, which will be used as the last argument\n to (apply #'make-instance ...) idiom.\n\nNote that using a singular shortcut list of apply argument is an\nambiguous case that will be interpreted in favor of apply argument. To\nforce either of interpretations, provide shortcuts and apply arguments\nexplicitly:\n(make-instance* 'class (a b c)) ;; BAD\n(make-instance* 'class (a b c) nil) ;; GOOD\n(make-instance* 'class (when t nil)) ;; BAD\n(make-instance* 'class () (when t nil)) ;; GOOD\n\nOtherwise, the behavior is equivalent to `make-instance'.\n\nExamples:\n\nShortcut args:\n\\(make-instance* 'class (a b c))\n=>\n\\(make-instance 'class :a a :b b :c c)\n\nLast form converted into `apply' argument:\n\\(make-instance* 'class :c c :b b (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :c c :b b (when something (list :a a)))\n\nShortcut arguments, regular arguments, and form for `apply':\n\\(make-instance* 'class (b c) :x x (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class :b b :c c :x x (when something (list :a a)))\n\nForm for `apply' (notice the empty shortcuts---these are required for\nunambiguous parsing):\n\\(make-instance* 'class () (when something (list :a a)))\n=>\n\\(apply #'make-instance 'class (when something (list :a a)))\n\nRegular `make-instance'-like use:\n\\(make-instance* 'class :a a-value :b b-value)\n=>\n\\(make-instance 'class :a a-value :b b-value)\"\n (when (and (= 1 (length arguments))\n (listp (first arguments)))\n (style-warn \"Body of MAKE-INSTANCE* contains a single list-like form ~a.\n\nIf you meant APPLY args, add empty shortcuts list:\n(make-instance* 'class () (apply-form))\n\nIf you meant shortcut list, add empty APPLY args:\n(make-instance* 'class (shortcuts) nil)\n\nInterpreting as APPLY args for now, but this behavior may change in\nthe future.\" arguments))\n (let* ((shortcuts-p (and (listp (first arguments))\n (> (length arguments) 1)))\n (shortcuts (when shortcuts-p\n (first arguments)))\n (arguments (if shortcuts-p\n (rest arguments)\n arguments))\n (last-appendable-form-p (oddp (length arguments)))\n (last-appendable-form (when last-appendable-form-p\n (first (last arguments))))\n (arguments (if last-appendable-form-p\n (butlast arguments)\n arguments)))\n `(,@(if last-appendable-form-p\n `(apply #'make-instance)\n `(make-instance))\n ,class\n ,@(loop for shortcut in shortcuts\n append (list (intern (symbol-name shortcut) :keyword)\n shortcut))\n ,@arguments\n ,@(when last-appendable-form-p\n (list last-appendable-form)))))", "macroexpand": "(apply (function make-instance) (quote class) :a a :b b :c c (when t (list :x x)))", "category": "anaphoric", "technique": "nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9624999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-case-aware-find-symbol find-pp-operator-name #:with-c-syntax.preprocess-operator)\n\nWhat needs to change: Macro call that should be transformed by define-case-aware-find-symbol", "input": "(define-case-aware-find-symbol find-pp-operator-name #:with-c-syntax.preprocess-operator)", "output": "(defmacro define-case-aware-find-symbol\n (finder-function-name package-name\n &key (upcased-package-name (format nil \"~A.~A\" (string package-name) '#:UPCASED))\n (docstring\n (format nil \"Find a symbol in `~A' package having a same NAME. If not found, returns `nil'.\"\n package-name)))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defpackage ,upcased-package-name\n (:use)\n (:intern\n ,@(loop for sym being the external-symbol of package-name\n collect (string-upcase (symbol-name sym)))))\n ,@(loop for sym being the external-symbol of package-name\n for upcased = (string-upcase (symbol-name sym))\n collect `(setf (symbol-value (find-symbol ,upcased ',upcased-package-name))\n ',sym))\n (defun ,finder-function-name (string &optional (readtable-case (readtable-case *readtable*)))\n ,@(if docstring `(,docstring))\n (ecase readtable-case\n ((:upcase :invert)\n (if-let ((up-sym (find-symbol string ',upcased-package-name)))\n (symbol-value up-sym)))\n ((:downcase :preserve)\n (find-symbol string ',package-name))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defpackage #A((41) base-char . \"WITH-C-SYNTAX.PREPROCESS-OPERATOR.UPCASED\") (:use) (:intern #A((7) base-char . \"DEFINED\") #A((7) base-char . \"_PRAGMA\"))) (setf (symbol-value (find-symbol #A((7) base-char . \"DEFINED\") (quote #A((41) base-char . \"WITH-C-SYNTAX.PREPROCESS-OPERATOR.UPCASED\")))) (quote with-c-syntax.preprocess-operator:|defined|)) (setf (symbol-value (find-symbol #A((7) base-char . \"_PRAGMA\") (quote #A((41) base-char . \"WITH-C-SYNTAX.PREPROCESS-OPERATOR.UPCASED\")))) (quote with-c-syntax.preprocess-operator:|_Pragma|)) (defun find-pp-operator-name (string &optional (readtable-case (readtable-case *readtable*))) #A((109) base-char . \"Find a symbol in `WITH-C-SYNTAX.PREPROCESS-OPERATOR' package having a same NAME. If not found, returns `nil'.\") (ecase readtable-case ((:upcase :invert) (if-let ((up-sym (find-symbol string (quote #A((41) base-char . \"WITH-C-SYNTAX.PREPROCESS-OPERATOR.UPCASED\"))))) (symbol-value up-sym))) ((:downcase :preserve) (find-symbol string (quote #:with-c-syntax.preprocess-operator))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> (string \"M\u0101lum\") (char #\\,))\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> (string \"M\u0101lum\") (char #\\,))", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset203) (multiple-value-bind (#:*>-res204 #:*>-next205) (funcall (string \"M\u0101lum\") #:*>-offset203) (if (ok? #:*>-res204) (funcall (char #\\COMMA) #:*>-next205) (fail #:*>-next205))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-<> nil :key nil)\n\nProblem: Macro call that should be transformed by -<>", "input": "(-<> nil :key nil)", "output": "(defmacro -<> ...)", "macroexpand": "(nil (:key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield (dolist (x data) (yield x (1+ x))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield", "input": "(with-yield (dolist (x data) (yield x (1+ x))))", "output": "(defmacro with-yield (&body body)\n (let ((point (gensym))\n (current (gensym)))\n `(let (,point ,current)\n (with-call/cc\n\t (labels ((yield (&rest values)\n\t\t (setf ,current values)\n\t\t (let/cc k\n\t\t (setf ,point k))))\n\t ,@body\n\t (setf ,point nil)))\n (gen-lambda ()\n\t (cond ((null ,point)\n\t\t'generator-stop)\n\t (t\n\t\t(let ((current ,current))\n\t\t (funcall ,point nil)\n\t\t ;values-handler: see gen-lambda\n\t\t (apply #'values (funcall values-handler current)))))))))", "macroexpand": "(let (#:g143 #:g144) (with-call/cc (labels ((yield (&rest values) (setf #:g144 values) (let/cc k (setf #:g143 k)))) (dolist (x data) (yield x (1+ x))) (setf #:g143 nil))) (gen-lambda nil (cond ((null #:g143) (quote generator-stop)) (t (let ((current #:g144)) (funcall #:g143 nil) (apply (function values) (funcall values-handler current)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(->>\n nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by ->>", "input": "(->>\n nil\n (progn))", "output": "(defmacro ->> ...)", "macroexpand": "(let* ((#:var185 nil) (#:var186 (progn #:var185)))\n #:var186)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(draw scene (:rect :x 0 :y 0 :height \"100%\" :width \"100%\") :fill (xlink-href pattern))\n\nPattern to recognize: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x 0 :y 0 :height \"100%\" :width \"100%\") :fill (xlink-href pattern))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g154 (funcall (function make-svg-element) :rect (append (list :x 0 :y 0 :height \"100%\" :width \"100%\") (list :fill (xlink-href pattern)))))) (add-element scene #:g154) #:g154)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-yield-binds (if *inside-insert-into* (apply #'format nil \"(~{~A~^, ~}) VALUES (~{~A~^, ~})\" (loop for (k v) on (set=-clause-args clause) by #'cddr collect (yield-arg k) into keys collect (yield-arg v) into values finally (return (list keys values)))) (format nil \"SET ~{~A = ~A~^, ~}\" (mapcar #'yield-arg (set=-clause-args clause)))))\n\nProblem: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (if *inside-insert-into* (apply #'format nil \"(~{~A~^, ~}) VALUES (~{~A~^, ~})\" (loop for (k v) on (set=-clause-args clause) by #'cddr collect (yield-arg k) into keys collect (yield-arg v) into values finally (return (list keys values)))) (format nil \"SET ~{~A = ~A~^, ~}\" (mapcar #'yield-arg (set=-clause-args clause)))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (if *inside-insert-into* (apply (function format) nil \"(~{~A~^, ~}) VALUES (~{~A~^, ~})\" (loop for (k v) on (set=-clause-args clause) by (function cddr) collect (yield-arg k) into keys collect (yield-arg v) into values finally (return (list keys values)))) (format nil \"SET ~{~A = ~A~^, ~}\" (mapcar (function yield-arg) (set=-clause-args clause))))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defpattern alist (&rest args) `(and ,@(loop for (key . value) in args collect `(assoc ,key ,value))))\n\nWhat needs to change: Macro call that should be transformed by defpattern", "input": "(defpattern alist (&rest args) `(and ,@(loop for (key . value) in args collect `(assoc ,key ,value))))", "output": "(defmacro defpattern (name lambda-list &body body)\n \"Defines a derived pattern specifier named NAME. This is analogous\nto DEFTYPE.\n\nExamples:\n\n ;; Defines a LIST pattern.\n (defpattern list (&rest args)\n (when args\n `(cons ,(car args) (list ,@(cdr args)))))\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (pattern-expand-function ',name) (lambda ,lambda-list ,@body))))", "macroexpand": "(%defpattern alist (quote &rest) (quote args) (lambda (quasiquote (and #S(sb-impl::comma :expr (loop for (key . value) in args collect (quasiquote (assoc #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr value :kind 0)))) :kind 2)))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(mvlet nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by MVLET", "input": "(mvlet nil\n :key\n nil)", "output": "(defmacro MVLET ...)", "macroexpand": "(progn :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(cond-> 'some-name)\n\nWhat needs to change: Macro call that should be transformed by COND->", "input": "(cond-> 'some-name)", "output": "(defmacro COND-> ...)", "macroexpand": "(let* ((#:|cond134| 'some-name))\n #:|cond134|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(xor nil nil nil)\n\nWhat needs to change: Macro call that should be transformed by xor", "input": "(xor nil nil nil)", "output": "(defmacro xor (&rest datums)\n \"Evaluates its arguments one at a time, from left to right. If more than one\nargument evaluates to a true value no further DATUMS are evaluated, and NIL is\nreturned as both primary and secondary value. If exactly one argument\nevaluates to true, its value is returned as the primary value after all the\narguments have been evaluated, and T is returned as the secondary value. If no\narguments evaluate to true NIL is returned as primary, and T as secondary\nvalue.\"\n (with-gensyms (xor tmp true)\n `(let (,tmp ,true)\n (declare (ignorable ,tmp))\n (block ,xor\n ,@(mapcar (lambda (datum)\n `(if (setf ,tmp ,datum)\n (if ,true\n (return-from ,xor (values nil nil))\n (setf ,true ,tmp))))\n datums)\n (return-from ,xor (values ,true t))))))", "macroexpand": "(let (#:tmp147 #:true148) (declare (ignorable #:tmp147)) (block #:xor146 (if (setf #:tmp147 nil) (if #:true148 (return-from #:xor146 (values nil nil)) (setf #:true148 #:tmp147))) (if (setf #:tmp147 nil) (if #:true148 (return-from #:xor146 (values nil nil)) (setf #:true148 #:tmp147))) (if (setf #:tmp147 nil) (if #:true148 (return-from #:xor146 (values nil nil)) (setf #:true148 #:tmp147))) (return-from #:xor146 (values #:true148 t))))", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.835} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(deferror \"55006\" object-in-use object-state-error)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"55006\" object-in-use object-state-error)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition object-in-use (object-state-error) nil) (setf (gethash \"55006\" *error-table*) (quote object-in-use)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(while nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by WHILE", "input": "(while nil\n (progn))", "output": "(defmacro WHILE ...)", "macroexpand": "(loop while nil\n do (progn (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclass/a dbd-mysql (dbi-driver) ())\n\nWrite a macro that addresses: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbd-mysql (dbi-driver) ())", "output": "(defmacro defclass/a (name superclasses slots &rest class-options)\n `(progn\n (defclass ,name ,superclasses ,slots ,@class-options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (defclass dbd-mysql (dbi-driver) nil) (deftype nil (quote dbd-mysql)) (setf (find-class (quote )) (find-class (quote dbd-mysql))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-connection (execute (create-table :user ((id :type :bigint :primary-key t) (name :type '(:varchar 32)) (email :type '(:varchar 255)) (status :type '(:varchar 20)) (created_at :type :datetime) (updated_at :type :datetime)))) (execute (create-table :tweet ((id :type :bigint :primary-key t) (user_id :type :bigint) (body :type :text) (created_at :type :datetime)))) (execute (insert-into :user (set= :id 1 :name \"nitro_idiot\" :email \"e.arrows@gmail.com\" :status \"normal\" :created_at (princ-to-string *now*)))) (execute (insert-into :tweet (set= :id 1 :user_id 1 :body \"Hi.\" :created_at (princ-to-string *now*)))) (execute (insert-into :tweet (set= :id 2 :user_id 1 :body \"Is it working?\" :created_at (princ-to-string *now*)))))\n\nWhat needs to change: Macro call that should be transformed by with-connection", "input": "(with-connection (execute (create-table :user ((id :type :bigint :primary-key t) (name :type '(:varchar 32)) (email :type '(:varchar 255)) (status :type '(:varchar 20)) (created_at :type :datetime) (updated_at :type :datetime)))) (execute (create-table :tweet ((id :type :bigint :primary-key t) (user_id :type :bigint) (body :type :text) (created_at :type :datetime)))) (execute (insert-into :user (set= :id 1 :name \"nitro_idiot\" :email \"e.arrows@gmail.com\" :status \"normal\" :created_at (princ-to-string *now*)))) (execute (insert-into :tweet (set= :id 1 :user_id 1 :body \"Hi.\" :created_at (princ-to-string *now*)))) (execute (insert-into :tweet (set= :id 2 :user_id 1 :body \"Is it working?\" :created_at (princ-to-string *now*)))))", "output": "(defmacro with-connection (&body body)\n `(let ((*connection* (connect-cached :sqlite3 :database-name *db-path*)))\n ,@body))", "macroexpand": "(let ((execute (connect (create-table :user ((id :type :bigint :primary-key t) (name :type (quote (:varchar 32))) (email :type (quote (:varchar 255))) (status :type (quote (:varchar 20))) (created_at :type :datetime) (updated_at :type :datetime)))))) (unwind-protect (progn (execute (create-table :tweet ((id :type :bigint :primary-key t) (user_id :type :bigint) (body :type :text) (created_at :type :datetime)))) (execute (insert-into :user (set= :id 1 :name \"nitro_idiot\" :email \"e.arrows@gmail.com\" :status \"normal\" :created_at (princ-to-string *now*)))) (execute (insert-into :tweet (set= :id 1 :user_id 1 :body \"Hi.\" :created_at (princ-to-string *now*)))) (execute (insert-into :tweet (set= :id 2 :user_id 1 :body \"Is it working?\" :created_at (princ-to-string *now*))))) (disconnect execute)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(gen-lambda-with-sticky-stop () (unless (cdr ldata) (get-next)) (setf ldata (cdr ldata)) (if (eq (car ldata) 'generator-stop) (sticky-stop) (apply #'values (ensure-list (car ldata)))))\n\nIssue: Macro call that should be transformed by gen-lambda", "input": "(gen-lambda-with-sticky-stop () (unless (cdr ldata) (get-next)) (setf ldata (cdr ldata)) (if (eq (car ldata) 'generator-stop) (sticky-stop) (apply #'values (ensure-list (car ldata)))))", "output": "(defmacro gen-lambda (params &body rest)\n \"Version of lambda that wraps the anonymous function in an instance of the basic-generator class. This allows the lambda to be identified as a generator by its type. Basic-generator objects are derived from funcallable-standard-class, therefore they can be called as functions.\"\n `(let ((values-handler (create-values-handler)))\n (declare (ignorable values-handler))\n (make-instance \n 'basic-generator \n :function (lambda ,params ,@rest))))", "macroexpand": "(make-instance (quote basic-generator) :function (sticky-stop-lambda nil (unless (cdr ldata) (get-next)) (setf ldata (cdr ldata)) (if (eq (car ldata) (quote generator-stop)) (sticky-stop) (apply (function values) (ensure-list (car ldata))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(let-syntax common-lisp:nil)\n\nProblem: Macro call that should be transformed by LET-SYNTAX", "input": "(let-syntax common-lisp:nil)", "output": "(defmacro LET-SYNTAX ...)", "macroexpand": "(common-lisp:progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(bind (((:struct metabang-bind-test-1- a c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (ensure-same '(4 1 3) (list values a c) :test 'equal))\n\nPattern to recognize: Macro call that should be transformed by bind", "input": "(bind (((:struct metabang-bind-test-1- a c) (make-metabang-bind-test-1 :a 1 :b 2 :c 3))) (ensure-same '(4 1 3) (list values a c) :test 'equal))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-189| (make-metabang-bind-test-1 :a 1 :b 2 :c 3)) (a (metabang-bind-test-1-a #:|values-189|)) (c (metabang-bind-test-1-c #:|values-189|))) (declare (ignorable #:|values-189|)) (progn (ensure-same (quote (4 1 3)) (list values a c) :test (quote equal))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(cond->\n nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by COND->", "input": "(cond->\n nil\n nil)", "output": "(defmacro COND-> ...)", "macroexpand": "(let* ((#:var127 nil)\n (#:var128\n (if nil\n (->\n #:var127)\n #:var127)))\n #:var128)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-sequences! ((place seq :start start :end end) (new new)) (setf place new))\n\nProblem: Macro call that should be transformed by do-sequences!", "input": "(do-sequences! ((place seq :start start :end end) (new new)) (setf place new))", "output": "(defmacro do-sequences! (name/seqs &body forms &environment env)\n \"Mutable version of DO-SEQUENCES.\n\n This is the same as DO-SEQUENCES however each NAME, is the name of\n a symbol-macro, that is introduced, which expands to the 'place',\n suitable for use with SETF, of the current sequence element, rather\n than a variable storing its value. This allows the elements of the\n sequence to be mutated.\n\n NOTE: This macro does not support destructuring of the sequence\n elements.\"\n\n (let-if ((name name/seqs)\n (seqs (first forms) name/seqs)\n (forms (rest forms) forms))\n (symbolp name/seqs)\n\n (let ((safety (cadr (assoc 'safety (declaration-information 'optimize env)))))\n `(,(if (> safety 2)\n 'do-sequences!-safe%\n 'do-sequences!-fast%)\n\n ,name\n ,seqs\n ,@forms))))", "macroexpand": "(do-sequences!-fast% nil ((place seq :start start :end end) (new new)) (setf place new))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-documentation-lookup function cl:function)\n\nWhat needs to change: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup function cl:function)", "output": "(defmacro define-simple-documentation-lookup (class documentation-type)\n `(defmethod documentation ((,class ,class))\n ,(if (eql documentation-type T)\n `(cl:documentation (object ,class) 'T)\n `(cl:documentation (designator ,class) ',documentation-type))))", "macroexpand": "(defmethod documentation ((function function)) (common-lisp:documentation (designator function) (quote common-lisp:function)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-quote-char (sxql:yield sql))\n\nPattern to recognize: Macro call that should be transformed by with-quote-char", "input": "(with-quote-char (sxql:yield sql))", "output": "(defmacro with-quote-char (&body body)\n `(let ((sxql:*quote-character* (or sxql:*quote-character*\n (connection-quote-character *connection*))))\n ,@body))", "macroexpand": "(let ((sxql/sql-type:*quote-character* (or sxql/sql-type:*quote-character* (connection-quote-character *connection*)))) (sxql/sql-type:yield sql))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-component make)\n\nIssue: Macro call that should be transformed by define-component", "input": "(define-component make)", "output": "(defmacro define-component (name &key input-type output-type compile-function)\n \"Define an ASDF component.\"\n `(progn\n (defclass ,name (source-file)\n ((type :initform ,input-type)\n (output :reader output :initarg :output)))\n\n (defmethod perform ((o load-op) (component ,name)) t)\n\n (defmethod output-files ((operation compile-op) (component ,name))\n (list\n (output-pathname component ,output-type)))\n\n (defmethod perform ((o compile-op) (component ,name))\n (funcall ,compile-function\n (component-pathname component)\n (output-pathname component ,output-type)))\n\n (import ',name :asdf)))", "macroexpand": "(progn (defclass make (source-file) ((type :initform nil) (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component make)) t) (defmethod output-files ((operation compile-op) (component make)) (list (output-pathname component nil))) (defmethod perform ((o compile-op) (component make)) (funcall nil (component-pathname component) (output-pathname component nil))) (import (quote make) :asdf))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclause-driver (for var in list &optional by (step ''cdr)) \"Elements of a list\" (top-level-check) (let* ((on-var (make-var-and-binding 'list list :type 'list)) (setqs (do-dsetq var `(car ,on-var))) (test `(if (endp ,on-var) (go ,*loop-end*)))) (setq *loop-end-used?* t) (return-driver-code :next (list test setqs (generate-function-step-code on-var step)) :variable var)))\n\nProblem: Macro call that should be transformed by defclause", "input": "(defclause-driver (for var in list &optional by (step ''cdr)) \"Elements of a list\" (top-level-check) (let* ((on-var (make-var-and-binding 'list list :type 'list)) (setqs (do-dsetq var `(car ,on-var))) (test `(if (endp ,on-var) (go ,*loop-end*)))) (setq *loop-end-used?* t) (return-driver-code :next (list test setqs (generate-function-step-code on-var step)) :variable var)))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-for-in-5 (&key ((:for var)) ((:in list)) ((:by step) (quote (quote cdr))) generate) \"Elements of a list\" (top-level-check) (let* ((on-var (make-var-and-binding (quote list) list :type (quote list))) (setqs (do-dsetq var (sb-int:quasiquote (car #S(sb-impl::comma :expr on-var :kind 0))))) (test (sb-int:quasiquote (if (endp #S(sb-impl::comma :expr on-var :kind 0)) (go #S(sb-impl::comma :expr *loop-end* :kind 0)))))) (setq *loop-end-used?* t) (return-driver-code :next (list test setqs (generate-function-step-code on-var step)) :variable var))) (install-clause-info (quote (for :in)) (quote (for :in &optional :by)) (quote clause-for-in-5) \"Elements of a list\" t) (quote (for var in list &optional by (step (quote (quote cdr))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(make-$instance nil :key nil)\n\nProblem: Macro call that should be transformed by MAKE-$INSTANCE", "input": "(make-$instance nil :key nil)", "output": "(defmacro MAKE-$INSTANCE ...)", "macroexpand": "(let ((class (symbol-value nil)))\n (funcall (mcs-slot-value class (index-of-basicnew-fn)) class :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-object-lookup class find-class)\n\nIssue: Macro call that should be transformed by define-simple-object-lookup", "input": "(define-simple-object-lookup class find-class)", "output": "(defmacro define-simple-object-lookup (class lookup-function &body body)\n `(defmethod object ((,class ,class))\n ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function (designator ,class)))))", "macroexpand": "(defmethod object ((class class)) (find-class (designator class)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(f_\n nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by F_", "input": "(f_\n nil\n :key\n nil)", "output": "(defmacro F_ ...)", "macroexpand": "(lambda (_) nil :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(eswitch (x :test =) (12 :oops) (13.0 :yay))\n\nWhat needs to change: Macro call that should be transformed by eswitch", "input": "(eswitch (x :test =) (12 :oops) (13.0 :yay))", "output": "(defmacro eswitch (&whole whole (object &key (test 'eql) (key 'identity))\n &body clauses)\n \"Like SWITCH, but signals an error if no key matches.\"\n (generate-switch-body whole object clauses test key '(error)))", "macroexpand": "(let ((#:value132 (identity x))) (cond ((= #:value132 12) :oops) ((= #:value132 13.0) :yay) (t (error \"No keys match in SWITCH. Testing against ~S with ~S.\" #:value132 (quote =)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-rewrite caaar (expr) `(car (caar ,(second expr))))\n\nIssue: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite caaar (expr) `(car (caar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote caaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (caar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-neo4j-fun set-relationship-property (relationship-id property value) :put (:uri-spec (format nil \"relationship/~A/properties/~A\" relationship-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:encode value :string) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'relationship-not-found-error :uri uri))))\n\nIssue: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun set-relationship-property (relationship-id property value) :put (:uri-spec (format nil \"relationship/~A/properties/~A\" relationship-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:encode value :string) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json)) (404 (error 'relationship-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun set-relationship-property (&key relationship-id property value) (let ((uri (format nil \"relationship/~A/properties/~A\" relationship-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (json (encode-neo4j-json-payload value :string))) (make-neo4j-request :put uri json (list (list 204 (lambda (body uri json) (values t body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))) (list 404 (lambda (body uri json) (error (quote relationship-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(iterate nil (progn))\n\nIssue: Macro call that should be transformed by ITERATE", "input": "(iterate nil (progn))", "output": "(defmacro ITERATE ...)", "macroexpand": "(progn (tagbody #:ll-252 ((lambda () (progn))) (go #:ll-252)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do+ (for y (to x)) (collect y) (when (= x y) (update x)))\n\nWhat needs to change: Macro call that should be transformed by do+", "input": "(do+ (for y (to x)) (collect y) (when (= x y) (update x)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for y (to x)) (collect y) (when (= x y) (update x)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-infix-reader)\n\nPattern to recognize: Macro call that should be transformed by ENABLE-INFIX-READER", "input": "(enable-infix-reader)", "output": "(defmacro ENABLE-INFIX-READER ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (push *readtable* *readtables*)\n (setq *readtable* (copy-readtable))\n (set-macro-character #\\LEFT_CURLY_BRACKET #'infix-reader nil)\n (set-macro-character #\\RIGHT_CURLY_BRACKET #'infix-end nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(bind ((instance (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3)) ((:slots a (my-c c) (the-b b)) instance)) (setf a :changed) (list (slot-value instance 'a) the-b my-c))\n\nWrite a macro that addresses: Macro call that should be transformed by bind", "input": "(bind ((instance (make-instance 'metabang-bind-class-1 :a 1 :b 2 :c 3)) ((:slots a (my-c c) (the-b b)) instance)) (setf a :changed) (list (slot-value instance 'a) the-b my-c))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((instance (make-instance (quote metabang-bind-class-1) :a 1 :b 2 :c 3)) (#:|values-171| instance)) (declare (ignorable #:|values-171|)) (with-slots ((a a) (my-c c) (the-b b)) #:|values-171| (progn (setf a :changed) (list (slot-value instance (quote a)) the-b my-c))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(collect nil)\n\nIssue: Macro call that should be transformed by COLLECT", "input": "(collect nil)", "output": "(defmacro COLLECT ...)", "macroexpand": "(common-lisp:let* ((#:generator-581 (generator nil))\n #:items-576\n (#:lastcons-577 (list nil))\n (#:lst-578 #:lastcons-577))\n (declare (type generator #:generator-581)\n (type cons #:lastcons-577)\n (type list #:lst-578))\n (tagbody\n #:ll-582\n (setq #:items-576 (next-in #:generator-581 (go end)))\n (setq #:lastcons-577 (setf (cdr #:lastcons-577) (cons #:items-576 nil)))\n (go #:ll-582)\n end)\n (cdr #:lst-578))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when initializer `(make-nodelist ,initializer))\n\nProblem: Macro call that should be transformed by when", "input": "(when initializer `(make-nodelist ,initializer))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if initializer (sb-int:quasiquote (make-nodelist #S(sb-impl::comma :expr initializer :kind 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-env [struct 'a])\n\nPattern to recognize: Macro call that should be transformed by with-env", "input": "(with-env [struct 'a])", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g132) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g132 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [struct (quote a]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g132)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(action (:after node-let node) (multiple-value-bind (new-node new-changed?) (maybe-collapse-alias-let node) (when new-changed? (setf changed? t) new-node)))\n\nWrite a macro that addresses: Macro call that should be transformed by action", "input": "(action (:after node-let node) (multiple-value-bind (new-node new-changed?) (maybe-collapse-alias-let node) (when new-changed? (setf changed? t) new-node)))", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-let) (lambda (node) (declare (type node-let node)) (multiple-value-bind (new-node new-changed?) (maybe-collapse-alias-let node) (when new-changed? (setf changed? t) new-node))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(swhen x (setf it :ok))\n\nProblem: Macro call that should be transformed by swhen", "input": "(swhen x (setf it :ok))", "output": "(defmacro swhen (test &body body)\n \"Like WHEN, except binds the test form to IT (via SYMBOL-MACROLET) for the\nscope of the body. IT can be set with SETF.\"\n `(symbolic when ,test ,@body))", "macroexpand": "(symbolic when x (setf it :ok))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lambda+ 'some-name)\n\nProblem: Macro call that should be transformed by LAMBDA+", "input": "(lambda+ 'some-name)", "output": "(defmacro LAMBDA+ ...)", "macroexpand": "(lambda (#:g129 #:g130) (let+ ('#:g129 (some-name #:g130))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-iter iterator-product (item-vec indices lengths stopped) (product (&rest iterables) \"Cartesian product of input iterables, returned as vectors in lexicographic order. Due to the awkwardness in mixing `&rest` and `&key` parameters in lambda lists, this function does not implement the `repeat` argument supported in [Python's version](https://docs.python.org/3/library/itertools.html#itertools.product). Use `picl:nfold-product` instead. ``` (product '(1 2) '(3 4)) ;; #(1 3), #(1 4), #(2 3), #(2 4) ```\" (loop with item-vec = (make-array (length iterables)) with lengths = (make-array (length iterables)) for i below (length item-vec) for iter in iterables do (setf (aref item-vec i) (iter-to-vec iter)) (setf (aref lengths i) (length (aref item-vec i))) minimizing (aref lengths i) into min-len finally (return (if (zerop min-len) (empty-iterator) (init-state item-vec lengths (indices (make-array (length item-vec) :initial-element 0))))))) (if stopped (values nil nil) (multiple-value-prog1 (loop with product = (make-array (length indices)) for i below (length indices) for ii = (aref indices i) do (setf (aref product i) (aref (aref item-vec i) ii)) finally (return (values product t))) (labels ((next-combo (i) (if (< i 0) (setf stopped t) (progn (incf (aref indices i)) (when (>= (aref indices i) (aref lengths i)) (setf (aref indices i) 0) (next-combo (1- i))))))) (next-combo (1- (length indices)))))))\n\nPattern to recognize: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-product (item-vec indices lengths stopped) (product (&rest iterables) \"Cartesian product of input iterables, returned as vectors in lexicographic order. Due to the awkwardness in mixing `&rest` and `&key` parameters in lambda lists, this function does not implement the `repeat` argument supported in [Python's version](https://docs.python.org/3/library/itertools.html#itertools.product). Use `picl:nfold-product` instead. ``` (product '(1 2) '(3 4)) ;; #(1 3), #(1 4), #(2 3), #(2 4) ```\" (loop with item-vec = (make-array (length iterables)) with lengths = (make-array (length iterables)) for i below (length item-vec) for iter in iterables do (setf (aref item-vec i) (iter-to-vec iter)) (setf (aref lengths i) (length (aref item-vec i))) minimizing (aref lengths i) into min-len finally (return (if (zerop min-len) (empty-iterator) (init-state item-vec lengths (indices (make-array (length item-vec) :initial-element 0))))))) (if stopped (values nil nil) (multiple-value-prog1 (loop with product = (make-array (length indices)) for i below (length indices) for ii = (aref indices i) do (setf (aref product i) (aref (aref item-vec i) ii)) finally (return (values product t))) (labels ((next-combo (i) (if (< i 0) (setf stopped t) (progn (incf (aref indices i)) (when (>= (aref indices i) (aref lengths i)) (setf (aref indices i) 0) (next-combo (1- i))))))) (next-combo (1- (length indices)))))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname125 (&key item-vec indices lengths stopped) (labels ((self nil (if stopped (values nil nil) (multiple-value-prog1 (loop with product = (make-array (length indices)) for i below (length indices) for ii = (aref indices i) do (setf (aref product i) (aref (aref item-vec i) ii)) finally (return (values product t))) (labels ((next-combo (i) (if (< i 0) (setf stopped t) (progn (incf (aref indices i)) (when (>= (aref indices i) (aref lengths i)) (setf (aref indices i) 0) (next-combo (1- i))))))) (next-combo (1- (length indices)))))))) (function self)))) (defun product (&rest iterables) \"Cartesian product of input iterables, returned as vectors in lexicographic order. Due to the awkwardness in mixing `&rest` and `&key` parameters in lambda lists, this function does not implement the `repeat` argument supported in [Python's version](https://docs.python.org/3/library/itertools.html#itertools.product). Use `picl:nfold-product` instead. ``` (product '(1 2) '(3 4)) ;; #(1 3), #(1 4), #(2 3), #(2 4) ```\" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname125)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (loop with item-vec = (make-array (length iterables)) with lengths = (make-array (length iterables)) for i below (length item-vec) for iter in iterables do (setf (aref item-vec i) (iter-to-vec iter)) (setf (aref lengths i) (length (aref item-vec i))) minimizing (aref lengths i) into min-len finally (return (if (zerop min-len) (empty-iterator) (init-state item-vec lengths (indices (make-array (length item-vec) :initial-element 0)))))))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(augment final-code final)\n\nIssue: Macro call that should be transformed by augment", "input": "(augment final-code final)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf final-code (nconc final-code final))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-definition-resolver type-definition (designator) (eql :defined (sb-int:info :type :kind designator)))\n\nIssue: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver type-definition (designator) (eql :defined (sb-int:info :type :kind designator)))", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver type-definition (type-definition #:package144) (when (ignore-errors (let ((designator type-definition)) (eql :defined (sb-int:info :type :kind designator)))) (list (make-instance (quote type-definition) :designator type-definition :package #:package144))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> +tag-start+ +peek-no-slash+)\n\nIssue: Macro call that should be transformed by *>", "input": "(*> +tag-start+ +peek-no-slash+)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset262) (multiple-value-bind (#:*>-res263 #:*>-next264) (funcall +tag-start+ #:*>-offset262) (if (ok? #:*>-res263) (funcall +peek-no-slash+ #:*>-next264) (fail #:*>-next264))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(collect-append 'some-name)\n\nIssue: Macro call that should be transformed by COLLECT-APPEND", "input": "(collect-append 'some-name)", "output": "(defmacro COLLECT-APPEND ...)", "macroexpand": "(common-lisp:let* ((#:generator-230 (generator 'some-name))\n #:items-225\n (#:lst-226 nil)\n (#:list-227 nil))\n (declare (type generator #:generator-230)\n (type list #:lst-226)\n (type list #:list-227))\n (tagbody\n #:ll-231\n (setq #:items-225 (next-in #:generator-230 (go end)))\n (when #:items-225\n (common-lisp:multiple-value-bind (copy lastcons)\n (copy-list-last #:items-225)\n (when #:list-227 (rplacd #:list-227 copy))\n (setq #:list-227 lastcons)\n (when (null #:lst-226) (setq #:lst-226 copy))))\n (go #:ll-231)\n end)\n #:lst-226)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(alist-bind (name id fields) form (let ((sym (foreign-type-symbol name :cenum *package*))) (when (symbol-package sym) (pushnew sym *foreign-other-exports-list*)) `(progn ,@(parse-enum-to-const fields) (define-foreign-enum ',sym ,id ',(parse-enum-fields fields)))))\n\nWrite a macro that addresses: Macro call that should be transformed by alist-bind", "input": "(alist-bind (name id fields) form (let ((sym (foreign-type-symbol name :cenum *package*))) (when (symbol-package sym) (pushnew sym *foreign-other-exports-list*)) `(progn ,@(parse-enum-to-const fields) (define-foreign-enum ',sym ,id ',(parse-enum-fields fields)))))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist243 form)) (let ((name (aval :name #:alist243)) (id (aval :id #:alist243)) (fields (aval :fields #:alist243))) (let ((sym (foreign-type-symbol name :cenum *package*))) (when (symbol-package sym) (pushnew sym *foreign-other-exports-list*)) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (parse-enum-to-const fields) :kind 2) (define-foreign-enum (quote #S(sb-impl::comma :expr sym :kind 0)) #S(sb-impl::comma :expr id :kind 0) (quote #S(sb-impl::comma :expr (parse-enum-fields fields) :kind 0))))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ltbdd-with-new-hash nil\n nil)\n\nIssue: Macro call that should be transformed by LTBDD-WITH-NEW-HASH", "input": "(ltbdd-with-new-hash nil\n nil)", "output": "(defmacro LTBDD-WITH-NEW-HASH ...)", "macroexpand": "(bdd-call-with-new-hash (lambda () nil) :bdd-node-type\n '(or lisp-type-bdd-node bdd-leaf))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(atomically nil () (decf counter))\n\nProblem: Macro call that should be transformed by atomically", "input": "(atomically nil () (decf counter))", "output": "(defmacro atomically (invariant &body args)\n \"Encloses atomic flow block of code that can be dispatched\nconcurrently. Non-consing.\"\n (destructuring-bind (opts lambda-list body) (parse-atomic-block-args args)\n (flow-lambda-macro (flow-context)\n (with-flow-function-macro (body-fu lambda-list body)\n `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts)))))", "macroexpand": "(%flow-lambda (#:flow-context153) (%with-flow-function (#:body-fu154 nil (decf counter)) (dispatch-atomically #:flow-context153 (function #:body-fu154) nil)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defstore example (&key (a (init-a)) (b a)))\n\nIssue: Macro call that should be transformed by defstore", "input": "(defstore example (&key (a (init-a)) (b a)))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (defun a-init-function152 nil (declare (ignorable)) (init-a)) (defun b-init-function154 (a #:a?156) (declare (ignorable a #:a?156)) a) (ensure-store (quote example) (quote (&key (a (the t (a-init-function152)) #:a?156) (b (the t (b-init-function154 a #:a?156)) #:b?157))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-screamer-package :screamer-user)\n\nProblem: Macro call that should be transformed by define-screamer-package", "input": "(define-screamer-package :screamer-user)", "output": "(defmacro define-screamer-package (defined-package-name &body options)\n \"Convenience wrapper around DEFPACKAGE. Passes its argument directly\nto DEFPACKAGE, and automatically injects two additional options:\n\n \\(:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p)\n \\(:use :cl :screamer)\"\n `(defpackage ,defined-package-name\n ,@options\n (:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p)\n (:use :cl :screamer)))", "macroexpand": "(defpackage :screamer-user (:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p) (:use :cl :screamer))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-decoder-simple-clos-semantics (is (equal-objects-p (json:make-object '((hello . \"hej\") (hi . \"tjena\")) nil) (decode-json-from-string input))) (is-false (#-cmu identity #+cmu symbol-package (class-name (class-of (decode-json-from-string input))))) (is (equal-objects-p (decode-json-from-string \"{ }\") (json:make-object nil nil))))\n\nIssue: Macro call that should be transformed by with-decoder-simple-clos-semantics", "input": "(with-decoder-simple-clos-semantics (is (equal-objects-p (json:make-object '((hello . \"hej\") (hi . \"tjena\")) nil) (decode-json-from-string input))) (is-false (#-cmu identity #+cmu symbol-package (class-name (class-of (decode-json-from-string input))))) (is (equal-objects-p (decode-json-from-string \"{ }\") (json:make-object nil nil))))", "output": "(defmacro with-decoder-simple-clos-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-CLOS-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-clos-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-clos-semantics) (is (equal-objects-p (make-object (quote ((hello . \"hej\") (hi . \"tjena\"))) nil) (decode-json-from-string input))) (is-false (identity (class-name (class-of (decode-json-from-string input))))) (is (equal-objects-p (decode-json-from-string \"{ }\") (make-object nil nil))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-op (:a< infix-op :sql-op-name \"@<\"))\n\nWrite a macro that addresses: Macro call that should be transformed by define-op", "input": "(define-op (:a< infix-op :sql-op-name \"@<\"))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (a<-op (:include infix-op (name \"@<\")) (:constructor make-a<-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclause-driver (for var next next) \"General driver; VAR is set to value of NEXT\" (return-driver-code :variable var :next (list (do-dsetq var (walk-expr next)))))\n\nIssue: Macro call that should be transformed by defclause", "input": "(defclause-driver (for var next next) \"General driver; VAR is set to value of NEXT\" (return-driver-code :variable var :next (list (do-dsetq var (walk-expr next)))))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-for-next-8 (&key ((:for var)) ((:next next)) generate) \"General driver; VAR is set to value of NEXT\" (return-driver-code :variable var :next (list (do-dsetq var (walk-expr next))))) (install-clause-info (quote (for :next)) (quote (for :next)) (quote clause-for-next-8) \"General driver; VAR is set to value of NEXT\" t) (quote (for var next next)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error invalid-v-defun-template () (func-name template) \"Template passed to v-def-glsl-template-fun must be a format string: ~a~%~a~%\" func-name template)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error invalid-v-defun-template () (func-name template) \"Template passed to v-def-glsl-template-fun must be a format string: ~a~%~a~%\" func-name template)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition invalid-v-defun-template (:error-type varjo-error :prefix \"Varjo\") (func-name template) \"Template passed to v-def-glsl-template-fun must be a format string: ~a~%~a~%\" func-name template)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> :g (a) (put a))\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> :g (a) (put a))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (a) (put a))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-destructured-lambda-form nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-DESTRUCTURED-LAMBDA-FORM", "input": "(with-destructured-lambda-form nil\n nil)", "output": "(defmacro WITH-DESTRUCTURED-LAMBDA-FORM ...)", "macroexpand": "(destructuring-bind\n (#:function121 #:name122 #:qualifiers123 #:lambda-list124 #:docstring125\n #:declarations126 #:forms127)\n (split-lambda-form nil)\n (declare\n (ignore #:function121 #:name122 #:qualifiers123 #:lambda-list124\n #:docstring125 #:declarations126 #:forms127)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(static-method-function-test-hook)\n\nWhat needs to change: Macro call that should be transformed by static-method-function-test-hook", "input": "(static-method-function-test-hook)", "output": "(defmacro static-method-function-test-hook ()\n \"A form of this macro is inserted in method functions, in order to\n allow test code to be inserted.\"\n\n nil)", "macroexpand": "nil", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-error none-type-in-out-vars () (glsl-name) \"One of the values being returned from the shader (~s) is of type :none.\" glsl-name)\n\nPattern to recognize: Macro call that should be transformed by define-error", "input": "(define-error none-type-in-out-vars () (glsl-name) \"One of the values being returned from the shader (~s) is of type :none.\" glsl-name)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition none-type-in-out-vars (:error-type varjo-error :prefix \"Varjo\") (glsl-name) \"One of the values being returned from the shader (~s) is of type :none.\" glsl-name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclause minimizing (form &key (test ''<) saving in) \"Same as optimizing but with < as the default test.\" `(optimizing ,form :test ,test :saving ,saving :in ,in))\n\nIssue: Macro call that should be transformed by defclause", "input": "(defclause minimizing (form &key (test ''<) saving in) \"Same as optimizing but with < as the default test.\" `(optimizing ,form :test ,test :saving ,saving :in ,in))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro minimizing (form &key (test (quote (quote <))) saving in) \"Same as optimizing but with < as the default test.\" (sb-int:quasiquote (optimizing #S(sb-impl::comma :expr form :kind 0) :test #S(sb-impl::comma :expr test :kind 0) :saving #S(sb-impl::comma :expr saving :kind 0) :in #S(sb-impl::comma :expr in :kind 0)))) (pushnew (quote minimizing) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-method pathname-name 1 (new-val path) (make-pathname :name new-val :defaults path))\n\nWhat needs to change: Macro call that should be transformed by define-modf-method", "input": "(define-modf-method pathname-name 1 (new-val path) (make-pathname :name new-val :defaults path))", "output": "(defmacro define-modf-method (name nth-arg (new-val &rest args) &body body)\n \"Define a new modf method. It inverts NAME forms by modifying the NTH-ARG\nterm of the arguments of the place form in the MODF macro. This method can\nspecialize on any of ARGS.\"\n ;; Side effect in a macro, I know. How can you do this via EVAL-WHEN if I\n ;; want it to run even if not a toplevel macro?\n (setf (gethash name *modf-nth-arg*)\n nth-arg)\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-nth-arg*)\n ,nth-arg))\n (defmethod ,(intern (modf-name name) :modf) (,new-val ,@args)\n ,@body)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote pathname-name) *modf-nth-arg*) 1)) (defmethod |BUILDER:COMMON-LISP:PATHNAME-NAME| (new-val path) (make-pathname :name new-val :defaults path)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(-> nil (value) (setf result value) (mt:open-latch latch))\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(-> nil (value) (setf result value) (mt:open-latch latch))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically nil (value) (setf result value) (cl-muth:open-latch latch))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-rules nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-RULES", "input": "(with-rules nil)", "output": "(defmacro WITH-RULES ...)", "macroexpand": "(dolist (nil (alexandria:hash-table-keys cl-rules.core::*rules*)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-unique-names (this-s) (let ((current-s (get s-indicator current-s-indicator))) (setf (get s-indicator current-s-indicator) this-s) `(symbol-macrolet ((,this-s (internal-symbol-macrolet ((it ,current-s)) ,test)) (it ,this-s)) (,operation it ,@other-args))))\n\nPattern to recognize: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (this-s) (let ((current-s (get s-indicator current-s-indicator))) (setf (get s-indicator current-s-indicator) this-s) `(symbol-macrolet ((,this-s (internal-symbol-macrolet ((it ,current-s)) ,test)) (it ,this-s)) (,operation it ,@other-args))))", "output": "(defmacro with-unique-names ((&rest bindings) &body body)\n `(let ,(mapcar #'(lambda (binding)\n\t\t (destructuring-bind (var prefix)\n\t\t\t (if (consp binding) binding (list binding binding))\n\t\t `(,var (gensym ,(string prefix)))))\n\t\t bindings)\n ,@body))", "macroexpand": "(let ((this-s (gensym #A((7) base-char . \"THIS-S-\")))) (let ((current-s (get s-indicator current-s-indicator))) (setf (get s-indicator current-s-indicator) this-s) (quasiquote (symbol-macrolet ((#S(sb-impl::comma :expr this-s :kind 0) (internal-symbol-macrolet ((it #S(sb-impl::comma :expr current-s :kind 0))) #S(sb-impl::comma :expr test :kind 0))) (it #S(sb-impl::comma :expr this-s :kind 0))) (#S(sb-impl::comma :expr operation :kind 0) it #S(sb-impl::comma :expr other-args :kind 2))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(bind ((obj (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5)) ((:accessors a c e) obj)) (setf a :a c :c) (list (e obj) (c obj) (a obj)))\n\nWhat needs to change: Macro call that should be transformed by bind", "input": "(bind ((obj (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5)) ((:accessors a c e) obj)) (setf a :a c :c) (list (e obj) (c obj) (a obj)))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((obj (make-instance (quote metabang-bind-class-2) :a 1 :b 2 :c 3 :d 4 :e 5)) (#:|values-176| obj)) (declare (ignorable #:|values-176|)) (with-accessors ((a a) (c c) (e e)) #:|values-176| (progn (setf a :a c :c) (list (e obj) (c obj) (a obj)))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-definition-resolver structure designator-structure-p)\n\nPattern to recognize: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver structure designator-structure-p)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver structure (structure #:package139) (when (ignore-errors (designator-structure-p structure)) (list (make-instance (quote structure) :designator structure :package #:package139))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(->* nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by ->*", "input": "(->* nil (progn))", "output": "(defmacro ->* ...)", "macroexpand": "(-> (progn) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-condition/a dbi-operational-error (dbi-database-error) () (:documentation \"Exception for errors related to the database's operation which are not necessarily under the control of the programmer. This includes such things as unexpected disconnect, datasource name not found, transaction could not be processed, a memory allocation error occured during processing, etc.\"))\n\nWhat needs to change: Macro call that should be transformed by define-condition/a", "input": "(define-condition/a dbi-operational-error (dbi-database-error) () (:documentation \"Exception for errors related to the database's operation which are not necessarily under the control of the programmer. This includes such things as unexpected disconnect, datasource name not found, transaction could not be processed, a memory allocation error occured during processing, etc.\"))", "output": "(defmacro define-condition/a (name parent-types slots &body options)\n `(progn\n (define-condition ,name ,parent-types ,slots ,@options)\n (deftype ,(intern (format nil \"<~A>\" (symbol-name name))) () ',name)\n (setf (find-class ',(intern (format nil \"<~A>\" (symbol-name name))))\n (find-class ',name))))", "macroexpand": "(progn (define-condition dbi-operational-error (dbi-database-error) nil (:documentation \"Exception for errors related to the database's operation which are not necessarily under the control of the programmer. This includes such things as unexpected disconnect, datasource name not found, transaction could not be processed, a memory allocation error occured during processing, etc.\")) (deftype nil (quote dbi-operational-error)) (setf (find-class (quote )) (find-class (quote dbi-operational-error))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(answer foo 1 2 3)\n\nProblem: Macro call that should be transformed by answer", "input": "(answer foo 1 2 3)", "output": "(defmacro answer (call &body forms)\n (let ((name (if (listp call) (car call) call))\n (sym (gensym)))\n `(if-called\n ',name\n (let ((,sym (fdefinition ',name)))\n (declare (ignorable ,sym))\n (let ((times 0))\n (lambda (&rest args)\n (declare (ignorable args))\n ,(let ((cases\n `(case (prog1 times (incf times))\n ,.(loop\n for i from 0\n for (form . rest) on forms\n collect `(,(if rest i T) ,form)))))\n (if (listp call)\n `(trivia:match args\n ((list . ,(cdr call)) ,cases)\n (_ (unhandled)))\n cases))))))))", "macroexpand": "(if-called (quote foo) (let ((#:g163 (fdefinition (quote foo)))) (declare (ignorable #:g163)) (let ((times 0)) (lambda (&rest args) (declare (ignorable args)) (case (prog1 times (incf times)) (0 1) (1 2) (t 3))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defjs reduce5(k vals) (let ((sum 0)) (dolist (c vals) (incf sum c)) (return sum)))\n\nPattern to recognize: Macro call that should be transformed by defjs", "input": "(defjs reduce5(k vals) (let ((sum 0)) (dolist (c vals) (incf sum c)) (return sum)))", "output": "(defmacro defjs (name args &body body)\n \"Define client side javascript. Works like defun; body is in lisp, with parenscript\n additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. \n macro creates a lisp function which sends the javascript function over to the mongo \n server to be evaluated. Result is processed and returned to the reader. \n This will execute 10 times on the server :\n (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))\"\n `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))\n (setf (gethash ',name *js-definitions*) js-body)\n (defun ,name ,args\n (get-element \"retval\" (car (docs (db.eval js-body ,@args)))))))", "macroexpand": "(let* ((js-body (parenscript:ps (lambda (k vals) (let ((sum 0)) (dolist (c vals) (incf sum c)) (return sum)))))) (setf (gethash (quote reduce5) *js-definitions*) js-body) (defun reduce5 (k vals) (get-element \"retval\" (car (docs (db.eval js-body k vals))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-column-type serial () :integer)\n\nWrite a macro that addresses: Macro call that should be transformed by define-column-type", "input": "(define-column-type serial () :integer)", "output": "(defmacro define-column-type (type-symbol lambda-list &body body)\n (let ((type (gensym \"TYPE\"))\n (args (gensym \"ARGS\")))\n `(defmethod cltype-to-dbtype ((,type (eql ',type-symbol)) &rest ,args)\n (declare (ignore ,type))\n (destructuring-bind ,lambda-list ,args\n ,@body))))", "macroexpand": "(defmethod cltype-to-dbtype ((#:type224 (eql (quote serial))) &rest #:args225) (declare (ignore #:type224)) (destructuring-bind nil #:args225 :integer))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with* nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH*", "input": "(with* nil)", "output": "(defmacro WITH* ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(signal-syntax-error \"Empty character class.\")\n\nWhat needs to change: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Empty character class.\")", "output": "(defmacro signal-syntax-error (format-control &rest format-arguments)\n `(signal-syntax-error* nil ,format-control ,@format-arguments))", "macroexpand": "(signal-syntax-error* nil \"Empty character class.\")", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7925} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-readtime-wrapper-syntax nil nil)\n\nProblem: Macro call that should be transformed by ENABLE-READTIME-WRAPPER-SYNTAX", "input": "(enable-readtime-wrapper-syntax nil nil)", "output": "(defmacro ENABLE-READTIME-WRAPPER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-readtime-wrapper-syntax-in-readtable nil nil)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error emit-type-mismatch () (sets) \"Some of the emit statements emit different types:~{~%~a~}\" (mapcar (lambda (x) (map 'list #'type->type-spec x)) sets))\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error emit-type-mismatch () (sets) \"Some of the emit statements emit different types:~{~%~a~}\" (mapcar (lambda (x) (map 'list #'type->type-spec x)) sets))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition emit-type-mismatch (:error-type varjo-error :prefix \"Varjo\") (sets) \"Some of the emit statements emit different types:~{~%~a~}\" (mapcar (lambda (x) (map (quote list) (function type->type-spec) x)) sets))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(printing-unreadably (id name) (class/std employee name id salary))\n\nIssue: Macro call that should be transformed by printing-unreadably", "input": "(printing-unreadably (id name) (class/std employee name id salary))", "output": "(defmacro printing-unreadably (fields-list class-std-form\n &key (type t) (identity t))\n \"Automatically generates the unreadable printing boiler plate to print classes and its fields (from FIELDS-LIST).\"\n (let ((g!stream (gensym \"STREAM\"))\n (name (cadr class-std-form)))\n `(progn ,class-std-form\n (defmethod print-object ((,name ,name) ,g!stream)\n (print-unreadable-object (,name ,g!stream\n :type ,type\n :identity ,identity)\n (format ,g!stream\n ,(format nil \"~{~a: ~~s~^,~^ ~}\" fields-list)\n ,@(mapcar (lambda (a1)\n `(,a1 ,name))\n fields-list)))))))", "macroexpand": "(progn (class/std employee name id salary) (defmethod print-object ((employee employee) #:stream125) (print-unreadable-object (employee #:stream125 :type t :identity t) (format #:stream125 #A((16) base-char . \"ID: ~s, NAME: ~s\") (id employee) (name employee)))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"0A\" feature-not-supported)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"0A\" feature-not-supported)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition feature-not-supported (database-error) nil) (setf (gethash \"0A\" *error-table*) (quote feature-not-supported)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g)))\n\nProblem: Macro call that should be transformed by do-generator", "input": "(do-generators ((g (some-numbers)) (:list l data :fill-value 0)) (yield (+ l g)))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g175 (multi-gen (some-numbers) (list (list->generator data) :fill-value 0)))) (loop do (destructuring-bind (#:g177 . #:g176) (multiple-value-list (next-generator-value #:g175)) (unless #:g177 (return)) (let ((g (elt (elt #:g176 0) 0)) (l (elt (elt #:g176 1) 0))) (yield (+ l g))))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-advisable nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFUN-ADVISABLE", "input": "(defun-advisable nil\n (progn))", "output": "(defmacro DEFUN-ADVISABLE ...)", "macroexpand": "(let ((#:oldfn135\n (handler-case (symbol-function 'nil) (undefined-function nil nil))))\n (defun nil (progn))\n (make-advisable 'nil :arguments '(progn))\n (when\n (and #:oldfn135\n (not (eql (advisable-function-arguments #:oldfn135) :not-provided))\n (equal (advisable-function-arguments #:oldfn135) '(progn)))\n (copy-advice #:oldfn135 (symbol-function 'nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lret (x y) (declare (ignore x)) 1)\n\nWrite a macro that addresses: Macro call that should be transformed by lret", "input": "(lret (x y) (declare (ignore x)) 1)", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let (x y) (declare (ignore x)) 1)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-alias-binding count counting)\n\nIssue: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding count counting)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote count)) (quote counting)) (quote count))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(all-of nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by ALL-OF", "input": "(all-of nil\n :key\n nil)", "output": "(defmacro ALL-OF ...)", "macroexpand": "(lc (nil :key nil) always)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-standard-definer-options nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-STANDARD-DEFINER-OPTIONS", "input": "(with-standard-definer-options nil)", "output": "(defmacro WITH-STANDARD-DEFINER-OPTIONS ...)", "macroexpand": "`(progn\n ,@(when (getf -options- :export)\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',nil)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defcategory :debug (or :debug :info))\n\nWrite a macro that addresses: Macro call that should be transformed by defcategory", "input": "(defcategory :debug (or :debug :info))", "output": "(defmacro defcategory (category &optional expands-as set)\n `(defcategory-fn ',category ',expands-as ,set))", "macroexpand": "(defcategory-fn (quote :debug) (quote (or :debug :info)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7925} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(,*xsb* \"--nobanner\" \"--quietload\" \"--noprompt\" \"-e\" ,(format nil \"consult('~a').\" input-file) ,@args) :input input :output output :error error))\n\nPattern to recognize: Macro call that should be transformed by with-temp", "input": "(with-temp (input-file :tmpdir d :template \"XXXXXX.prolog\" :debug (<= 1 *debug-prolog*)) (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print `(,*xsb* \"--nobanner\" \"--quietload\" \"--noprompt\" \"-e\" ,(format nil \"consult('~a').\" input-file) ,@args) :input input :output output :error error))", "output": "(defmacro with-temp ((var &key directory template (tmpdir \"/tmp/\") debug) &body body)\n \"Create a temporary file, then remove the file by unwind-protect.\nMost arguments are analogous to mktemp.\nWhen DIRECTORY is non-nil, creates a directory instead.\nDEBUG is a form.\nWhen evaluated to non-nil, it does not remove the directory so that you can investigate what happened inside the directory.\nIt may be evaluated multiple times.\"\n (with-gensyms (command)\n `(let ((,var (uiop:run-program\n (let ((,command (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\"\n ,tmpdir ,directory ,template)))\n (when ,debug\n (format *error-output* \"~&; ~a~%\" ,command))\n ,command)\n :output '(:string :stripped t))))\n (unwind-protect\n (progn ,@body)\n (if ,debug\n (format *error-output* \"~&; not removing ~a for debugging~%\" ,var)\n (uiop:run-program (format nil \"rm -rf ~a\" (namestring ,var)) :ignore-error-status t))))))", "macroexpand": "(let ((input-file (uiop/run-program:run-program (let ((#:command178 (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\" d nil \"XXXXXX.prolog\"))) (when (<= 1 *debug-prolog*) (format *error-output* \"~&; ~a~%\" #:command178)) #:command178) :output (quote (:string :stripped t))))) (unwind-protect (progn (with-open-file (s input-file :direction :output :if-does-not-exist :error) (dolist (r rules) (print-rule s r))) (run-command-with-debug-print (sb-int:quasiquote (#S(sb-impl::comma :expr *xsb* :kind 0) \"--nobanner\" \"--quietload\" \"--noprompt\" \"-e\" #S(sb-impl::comma :expr (format nil \"consult('~a').\" input-file) :kind 0) #S(sb-impl::comma :expr args :kind 2))) :input input :output output :error error)) (if (<= 1 *debug-prolog*) (format *error-output* \"~&; not removing ~a for debugging~%\" input-file) (uiop/run-program:run-program (format nil \"rm -rf ~a\" (namestring input-file)) :ignore-error-status t))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8624999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(matrix-ccase nil)\n\nIssue: Macro call that should be transformed by MATRIX-CCASE", "input": "(matrix-ccase nil)", "output": "(defmacro MATRIX-CCASE ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(ps\n 'some-name)\n\nPattern to recognize: Macro call that should be transformed by PS", "input": "(ps\n 'some-name)", "output": "(defmacro PS ...)", "macroexpand": "\"'someName';\"", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"57\" operator-intervention)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"57\" operator-intervention)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition operator-intervention (database-error) nil) (setf (gethash \"57\" *error-table*) (quote operator-intervention)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defhandler lambda (lambda lambda-list &rest body) (apply 'dump-fbinding lambda lambda-list body))\n\nPattern to recognize: Macro call that should be transformed by defhandler", "input": "(defhandler lambda (lambda lambda-list &rest body) (apply 'dump-fbinding lambda lambda-list body))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-lambda (lambda lambda-list &rest body) (apply (quote dump-fbinding) lambda lambda-list body)) (setf (gethash (quote lambda) *form-handler*) (quote hander-lambda)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dynamic-wind)\n\nWrite a macro that addresses: Macro call that should be transformed by DYNAMIC-WIND", "input": "(dynamic-wind)", "output": "(defmacro DYNAMIC-WIND ...)", "macroexpand": "(flet ((#:dynamic-wind-thunk213 (#:proceed-thunk214)\n (macrolet ((proceed (&body #:proceed-body215)\n `(if ,'#:proceed-thunk214\n (funcall (the function ,'#:proceed-thunk214))\n (progn ,@#:proceed-body215)))))))\n (declare (inline #:dynamic-wind-thunk213))\n (let ((*dynamic-wind-stack*\n (cons #'#:dynamic-wind-thunk213 *dynamic-wind-stack*)))\n (#:dynamic-wind-thunk213 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(fgather-next nil nil)\n\nIssue: Macro call that should be transformed by FGATHER-NEXT", "input": "(fgather-next nil nil)", "output": "(defmacro FGATHER-NEXT ...)", "macroexpand": "(nil nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(xor tmp true)\n\nPattern to recognize: Macro call that should be transformed by xor", "input": "(xor tmp true)", "output": "(defmacro xor (&rest datums)\n \"Evaluates its arguments one at a time, from left to right. If more than one\nargument evaluates to a true value no further DATUMS are evaluated, and NIL is\nreturned as both primary and secondary value. If exactly one argument\nevaluates to true, its value is returned as the primary value after all the\narguments have been evaluated, and T is returned as the secondary value. If no\narguments evaluate to true NIL is returned as primary, and T as secondary\nvalue.\"\n (with-gensyms (xor tmp true)\n `(let (,tmp ,true)\n (declare (ignorable ,tmp))\n (block ,xor\n ,@(mapcar (lambda (datum)\n `(if (setf ,tmp ,datum)\n (if ,true\n (return-from ,xor (values nil nil))\n (setf ,true ,tmp))))\n datums)\n (return-from ,xor (values ,true t))))))", "macroexpand": "(let (#:tmp138 #:true139) (declare (ignorable #:tmp138)) (block #:xor137 (if (setf #:tmp138 tmp) (if #:true139 (return-from #:xor137 (values nil nil)) (setf #:true139 #:tmp138))) (if (setf #:tmp138 true) (if #:true139 (return-from #:xor137 (values nil nil)) (setf #:true139 #:tmp138))) (return-from #:xor137 (values #:true139 t))))", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.835} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclause stop-when (condition) \"Synonym for until.\" `(until ,condition))\n\nIssue: Macro call that should be transformed by defclause", "input": "(defclause stop-when (condition) \"Synonym for until.\" `(until ,condition))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro stop-when (condition) \"Synonym for until.\" (sb-int:quasiquote (until #S(sb-impl::comma :expr condition :kind 0)))) (pushnew (quote stop-when) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause (finding expr minimizing min-expr &optional into variable) \"Return value which minimizes expression\" (return-find-extremum-code expr min-expr variable :min))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause (finding expr minimizing min-expr &optional into variable) \"Return value which minimizes expression\" (return-find-extremum-code expr min-expr variable :min))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-finding-minimizing-17 (&key ((:finding expr)) ((:minimizing min-expr)) ((:into variable))) \"Return value which minimizes expression\" (return-find-extremum-code expr min-expr variable :min)) (install-clause-info (quote (finding :minimizing)) (quote (finding :minimizing &optional :into)) (quote clause-finding-minimizing-17) \"Return value which minimizes expression\" nil) (quote (finding expr minimizing min-expr &optional into variable)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun/1 frexp (x nptr) (let ((n (ceiling (log (abs x) 2)))) (setf (deref* nptr) n) (/ x (expt 2 n))))\n\nWhat needs to change: Macro call that should be transformed by defun/1", "input": "(defun/1 frexp (x nptr) (let ((n (ceiling (log (abs x) 2)))) (setf (deref* nptr) n) (/ x (expt 2 n))))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun frexp (x nptr) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (let ((n (ceiling (log (abs x) 2)))) (setf (deref* nptr) n) (/ x (expt 2 n)))) (defparameter frexp (vacietis.c:mkptr& (symbol-function (quote frexp)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(newq nil)\n\nWhat needs to change: Macro call that should be transformed by NEWQ", "input": "(newq nil)", "output": "(defmacro NEWQ ...)", "macroexpand": "(new 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do* () (progn))\n\nWhat needs to change: Macro call that should be transformed by DO*", "input": "(do* () (progn))", "output": "(defmacro DO* ...)", "macroexpand": "(block nil\n (let* ()\n (declare (ignorable))\n (tagbody\n (go #:g189)\n #:g188\n (tagbody)\n (setq)\n #:g189\n (unless progn (go #:g188))\n (return-from nil (progn)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-active-layers* 'some-name)\n\nProblem: Macro call that should be transformed by WITH-ACTIVE-LAYERS*", "input": "(with-active-layers* 'some-name)", "output": "(defmacro WITH-ACTIVE-LAYERS* ...)", "macroexpand": "(dynamic-wind\n :proceed\n #:proceed212\n (%with-active-layers 'some-name\n (#:proceed212)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lret* ((y 1) (y 2)) (declare (ignorable y)) 3)\n\nProblem: Macro call that should be transformed by lret*", "input": "(lret* ((y 1) (y 2)) (declare (ignorable y)) 3)", "output": "(defmacro lret* ((&rest bindings) &body body)\n \"Cf. `lret'.\"\n `(lret-aux let* ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((y 1) (y 2)) (declare (ignorable y)) 3)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-custom-var (:aggregate-scope *aggregate-scope-variables*) nil \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON aggregate value (Object, Array or String).\")\n\nWrite a macro that addresses: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:aggregate-scope *aggregate-scope-variables*) nil \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON aggregate value (Object, Array or String).\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*aggregate-scope-variables* . :aggregate-scope)) *custom-vars* :test (function equal)) (defvar *aggregate-scope-variables* nil \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON aggregate value (Object, Array or String).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-env [clos-object 'a])\n\nWrite a macro that addresses: Macro call that should be transformed by with-env", "input": "(with-env [clos-object 'a])", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g131) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g131 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [clos-object (quote a]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g131)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do+ (returning 1) (returning 2 3) (returning (values 4 5) 6) (returning 7) (terminate))\n\nIssue: Macro call that should be transformed by do+", "input": "(do+ (returning 1) (returning 2 3) (returning (values 4 5) 6) (returning 7) (terminate))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (returning 1) (returning 2 3) (returning (values 4 5) 6) (returning 7) (terminate))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(when (eql (info-size) 0) (format stream \";\"))\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when (eql (info-size) 0) (format stream \";\"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (eql (info-size) 0) (format stream \";\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(sccase (car x) (:y (setf it :no)) (:x (setf it :yes)))\n\nIssue: Macro call that should be transformed by sccase", "input": "(sccase (car x) (:y (setf it :no)) (:x (setf it :yes)))", "output": "(defmacro sccase (keyform &body cases)\n \"Like CCASE, except binds the keyform to IT (via SYMBOL-MACROLET) for the\nscope of the cases. IT can be set with SETF.\"\n `(symbolic ccase ,keyform ,@cases))", "macroexpand": "(symbolic ccase (car x) (:y (setf it :no)) (:x (setf it :yes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-<>)\n\nWrite a macro that addresses: Macro call that should be transformed by -<>", "input": "(-<>)", "output": "(defmacro -<> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(max-of nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by MAX-OF", "input": "(max-of nil\n (progn))", "output": "(defmacro MAX-OF ...)", "macroexpand": "(lc (nil (progn)) maximize)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(js)\n\nPattern to recognize: Macro call that should be transformed by JS", "input": "(js)", "output": "(defmacro JS ...)", "macroexpand": "(ps)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defvar-compile-time *screamer?* nil \"This must be NIL except when defining internal Screamer functions.\")\n\nWrite a macro that addresses: Macro call that should be transformed by defvar-compile-time", "input": "(defvar-compile-time *screamer?* nil \"This must be NIL except when defining internal Screamer functions.\")", "output": "(defmacro defvar-compile-time (name &optional initial-value documentation)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,name ,initial-value ,documentation)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defvar *screamer?* nil \"This must be NIL except when defining internal Screamer functions.\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(the-part nil nil)\n\nProblem: Macro call that should be transformed by THE-PART", "input": "(the-part nil nil)", "output": "(defmacro THE-PART ...)", "macroexpand": "(send part nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(some->>)\n\nPattern to recognize: Macro call that should be transformed by SOME->>", "input": "(some->>)", "output": "(defmacro SOME->> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(fail \"This is supposed to fail\")\n\nProblem: Macro call that should be transformed by fail", "input": "(fail \"This is supposed to fail\")", "output": "(defmacro fail (&rest message-args)\n \"Simply generate a FAIL.\"\n `(process-failure ',message-args\n ,@message-args))", "macroexpand": "(process-failure (quote (\"This is supposed to fail\")) \"This is supposed to fail\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-templated-dispatch nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-TEMPLATED-DISPATCH", "input": "(define-templated-dispatch nil\n (progn))", "output": "(defmacro DEFINE-TEMPLATED-DISPATCH ...)", "macroexpand": "(define-type-dispatch nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(unwind-protect nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by UNWIND-PROTECT", "input": "(unwind-protect nil\n (progn))", "output": "(defmacro UNWIND-PROTECT ...)", "macroexpand": "(common-lisp:unwind-protect (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defhandler let* (let* bindings &rest body) (if (not bindings) (e `(locally ,@body)) (destructuring-bind (first &rest rest) bindings (e `(let (,first) ,@(if rest `((,let* ,rest ,@body)) body))))))\n\nIssue: Macro call that should be transformed by defhandler", "input": "(defhandler let* (let* bindings &rest body) (if (not bindings) (e `(locally ,@body)) (destructuring-bind (first &rest rest) bindings (e `(let (,first) ,@(if rest `((,let* ,rest ,@body)) body))))))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-let* (let* bindings &rest body) (if (not bindings) (e (sb-int:quasiquote (locally #S(sb-impl::comma :expr body :kind 2)))) (destructuring-bind (first &rest rest) bindings (e (sb-int:quasiquote (let (#S(sb-impl::comma :expr first :kind 0)) #S(sb-impl::comma :expr (if rest (sb-int:quasiquote ((#S(sb-impl::comma :expr let* :kind 0) #S(sb-impl::comma :expr rest :kind 0) #S(sb-impl::comma :expr body :kind 2)))) body) :kind 2))))))) (setf (gethash (quote let*) *form-handler*) (quote hander-let*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(disable-curly-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by DISABLE-CURLY-SYNTAX", "input": "(disable-curly-syntax)", "output": "(defmacro DISABLE-CURLY-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (unless *original-readtable* (error \"Curly syntax not enabled.\"))\n (setf *readtable* *original-readtable*\n *original-readtable* nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ct-let nil)\n\nProblem: Macro call that should be transformed by CT-LET", "input": "(ct-let nil)", "output": "(defmacro CT-LET ...)", "macroexpand": "(cond\n (*within-captured-dynenv*\n (let ()\n (let ((#:new-var-space146\n (reduce\n (lambda (#:accum147 #:item148)\n (destructuring-bind\n (#:name149 . #:value150)\n #:item148\n (update-alist #:name149 #:value150 #:accum147)))\n (list) :initial-value *var-space*)))\n `(symbol-macrolet ((var-space ,#:new-var-space146))\n ,(let ((*var-space* #:new-var-space146)))))))\n (t\n (error\n \"No macrodynamic environment has been captured to establish CT-LET bindings.\")))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-iter iterator-nfold-product (iterable-length product-length item-vec indices stopped) (nfold-product (n iterable) \"Computes the n-fold Cartesian product of an iterable with itself. Essentially equivalent to `(apply #'product (iter-to-list (tee n iterable))`, but with much better memory usage ``` (nfold-product 3 '(1 2)) ;; #(1 1 1), #(1 1 2), #(1 2 1), #(1 2 2), #(2 1 1), #(2 1 2), #(2 2 1), #(2 2 2) ``` \" (let* ((item-vec (iter-to-vec iterable)) (iterable-length (length item-vec))) (if (zerop iterable-length) (empty-iterator) (init-state iterable-length item-vec (product-length n) (indices (make-array n :initial-element 0)))))) (if stopped (values nil nil) (multiple-value-prog1 (loop with product = (make-array product-length) for i below product-length for ii = (aref indices i) do (setf (aref product i) (aref item-vec ii)) finally (return (values product t))) (labels ((next-combo (i) (if (< i 0) (setf stopped t) (progn (incf (aref indices i)) (when (>= (aref indices i) iterable-length) (setf (aref indices i) 0) (next-combo (1- i))))))) (next-combo (1- product-length))))))\n\nPattern to recognize: Macro call that should be transformed by def-iter", "input": "(def-iter iterator-nfold-product (iterable-length product-length item-vec indices stopped) (nfold-product (n iterable) \"Computes the n-fold Cartesian product of an iterable with itself. Essentially equivalent to `(apply #'product (iter-to-list (tee n iterable))`, but with much better memory usage ``` (nfold-product 3 '(1 2)) ;; #(1 1 1), #(1 1 2), #(1 2 1), #(1 2 2), #(2 1 1), #(2 1 2), #(2 2 1), #(2 2 2) ``` \" (let* ((item-vec (iter-to-vec iterable)) (iterable-length (length item-vec))) (if (zerop iterable-length) (empty-iterator) (init-state iterable-length item-vec (product-length n) (indices (make-array n :initial-element 0)))))) (if stopped (values nil nil) (multiple-value-prog1 (loop with product = (make-array product-length) for i below product-length for ii = (aref indices i) do (setf (aref product i) (aref item-vec ii)) finally (return (values product t))) (labels ((next-combo (i) (if (< i 0) (setf stopped t) (progn (incf (aref indices i)) (when (>= (aref indices i) iterable-length) (setf (aref indices i) 0) (next-combo (1- i))))))) (next-combo (1- product-length))))))", "output": "(defmacro def-iter (name state-vars (constructor-name constructor-params &body constructor-body)\n &body next-body)\n \"An anaphoric convenience macro which can be re-implemented to change how iterators are\n structured. Exposes the local `init-state` macro within `constructor-body`\n\n If you don't want to-use this macro (which I totally understand) just write constructors for your\n iterators returning 0-argument closures representing the `next` function and you'll be fine. This\n macro just helped me get through a lot of waffling during development\n\n Parameters\n ----------\n `name` is a synbol naming the iterator's backing state. However it's actually\n ignored, since PICL doesn't currently expose iterators' backing state\n\n `state-vars` is a list of symbols naming the iterator's state variables.\n\n The `constructor-name/params/body` will be `defun`'d to create the user-facing constructor\n function. In `constructor-body`, the return value should be an iterator or a call to local\n `init-state` macro\n\n `next-body` The definition of the `next` function for this iterator, which will be run in a\n lexical environment consisting of the state vars\n\n Both `constructor-body` and `next-body` are defined in the lexical environment of the `def-iter`\n form, and as such can access any lexical bindings not shadowed by the `constructor-params` and\n `state-vars` respectively\n\n The local `init-state` macro.\n ----------------------------\n The arguments to `init-state` should be of the form `(statevar-symbol value-form)`or\n `statevar-symbol`. In the first case, the value of `value-form` will be used to initialize the\n state variable named by `symbol`. In the second case, `statevar-symbol` is also used as the\n corresponding `value-form`\n\n Example\n -------\n What follows is a sample implementation of the `count` iterator using this macro\n ```\n (def-iter ignored-backing-name (curr-val step)\n (count (start step)\n (init-state (curr-val start) step))\n (prog1 curr-val (incf curr-val step))))\n ````\"\n\n (declare (ignore name))\n (alexandria:with-gensyms (next-fname)\n (let ((docstring \"Function had no docstring, so this one was inserted\"))\n (when (and (cdr constructor-body) (stringp (car constructor-body)))\n (setf docstring (car constructor-body)\n constructor-body (cdr constructor-body)))\n `(labels ((,next-fname (&key ,@state-vars)\n (labels ((self () ,@next-body)) #'self)))\n (defun ,constructor-name ,constructor-params\n ,docstring\n (macrolet\n ((init-state (&rest argspecs)\n (list 'apply '#',next-fname\n (apply #'append\n '(list )\n (mapcar (lambda (aspec)\n (if (symbolp aspec)\n (list (alx:make-keyword aspec) aspec)\n (destructuring-bind (aname adef) aspec\n (list (alx:make-keyword aname) adef))))\n argspecs)))))\n ,@constructor-body))))))", "macroexpand": "(labels ((#:next-fname126 (&key iterable-length product-length item-vec indices stopped) (labels ((self nil (if stopped (values nil nil) (multiple-value-prog1 (loop with product = (make-array product-length) for i below product-length for ii = (aref indices i) do (setf (aref product i) (aref item-vec ii)) finally (return (values product t))) (labels ((next-combo (i) (if (< i 0) (setf stopped t) (progn (incf (aref indices i)) (when (>= (aref indices i) iterable-length) (setf (aref indices i) 0) (next-combo (1- i))))))) (next-combo (1- product-length))))))) (function self)))) (defun nfold-product (n iterable) \"Computes the n-fold Cartesian product of an iterable with itself. Essentially equivalent to `(apply #'product (iter-to-list (tee n iterable))`, but with much better memory usage ``` (nfold-product 3 '(1 2)) ;; #(1 1 1), #(1 1 2), #(1 2 1), #(1 2 2), #(2 1 1), #(2 1 2), #(2 2 1), #(2 2 2) ``` \" (macrolet ((init-state (&rest argspecs) (list (quote apply) (quote (function #:next-fname126)) (apply (function append) (quote (list)) (mapcar (lambda (aspec) (if (symbolp aspec) (list (alx:make-keyword aspec) aspec) (destructuring-bind (aname adef) aspec (list (alx:make-keyword aname) adef)))) argspecs))))) (let* ((item-vec (iter-to-vec iterable)) (iterable-length (length item-vec))) (if (zerop iterable-length) (empty-iterator) (init-state iterable-length item-vec (product-length n) (indices (make-array n :initial-element 0))))))))", "category": "anaphoric", "technique": "macrolet,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-screamer-package :screamer-tests (:use :cl :hu.dwim.stefil) (:export #:test-screamer #:screamer-tests))\n\nProblem: Macro call that should be transformed by define-screamer-package", "input": "(define-screamer-package :screamer-tests (:use :cl :hu.dwim.stefil) (:export #:test-screamer #:screamer-tests))", "output": "(defmacro define-screamer-package (defined-package-name &body options)\n \"Convenience wrapper around DEFPACKAGE. Passes its argument directly\nto DEFPACKAGE, and automatically injects two additional options:\n\n \\(:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p)\n \\(:use :cl :screamer)\"\n `(defpackage ,defined-package-name\n ,@options\n (:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p)\n (:use :cl :screamer)))", "macroexpand": "(defpackage :screamer-tests (:use :cl :hu.dwim.stefil) (:export #:test-screamer #:screamer-tests) (:shadowing-import-from :screamer :defun :multiple-value-bind :y-or-n-p) (:use :cl :screamer))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(destructuring-match nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DESTRUCTURING-MATCH", "input": "(destructuring-match nil)", "output": "(defmacro DESTRUCTURING-MATCH ...)", "macroexpand": "(let ((#:form nil))\n (block #:done\n (let ((#:done\n (lambda (&rest values)\n (declare (dynamic-extent values))\n (return-from #:done (values-list values)))))\n (tagbody))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-matches-as-strings (match regex target-string (nreverse result-list) :start start :end end :sharedp sharedp) (push match result-list))\n\nProblem: Macro call that should be transformed by do-matches", "input": "(do-matches-as-strings (match regex target-string (nreverse result-list) :start start :end end :sharedp sharedp) (push match result-list))", "output": "(defmacro do-matches ((match-start match-end regex\n target-string\n &optional result-form\n &key start end)\n &body body)\n \"Iterates over TARGET-STRING and tries to match REGEX as often as\npossible evaluating BODY with MATCH-START and MATCH-END bound to the\nstart/end positions of each match in turn. After the last match,\nreturns RESULT-FORM if provided or NIL otherwise. An implicit block\nnamed NIL surrounds DO-MATCHES; RETURN may be used to terminate the\nloop immediately. If REGEX matches an empty string the scan is\ncontinued one position behind this match. BODY may start with\ndeclarations.\"\n ;; this is a simplified form of DO-SCANS - we just provide two dummy\n ;; vars and ignore them\n (with-unique-names (reg-starts reg-ends)\n `(do-scans (,match-start ,match-end\n ,reg-starts ,reg-ends\n ,regex ,target-string\n ,result-form\n :start ,start :end ,end)\n ,@body)))", "macroexpand": "(let ((#:target-string141 target-string)) (let ((#:substr-fn144 (if sharedp (function nsubseq) (function subseq)))) (do-matches (#:match-start142 #:match-end143 regex #:target-string141 (nreverse result-list) :start start :end end) (let ((match (funcall #:substr-fn144 #:target-string141 #:match-start142 #:match-end143))) (push match result-list)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(c-assert (eql :nascent (md-state self)))\n\nPattern to recognize: Macro call that should be transformed by c-assert", "input": "(c-assert (eql :nascent (md-state self)))", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless (eql :nascent (md-state self)) (c-break \"failed assertion: ~a\" (quote (eql :nascent (md-state self))))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.8999999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(def-neo4j-fun get-paths (node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) :post (:uri-spec (format nil \"node/~A/paths\" node-id)) (:encode (list (list (cons \"to\" to-node-id) :node-url) (list (cons \"relationships\" relationships)) (list (cons \"max_depth\" max-depth)) (list (cons \"algorithm\" (case algorithm (:shortest-path \"shortestPath\") (:all-paths \"allPaths\") (:all-simple-paths \"allSimplePaths\") (:dijkstra \"dijkstra\"))))) :object) (:status-handlers (200 (decode-neo4j-json-output body)) (204 (error 'path-not-found-error :uri uri))))\n\nProblem: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-paths (node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) :post (:uri-spec (format nil \"node/~A/paths\" node-id)) (:encode (list (list (cons \"to\" to-node-id) :node-url) (list (cons \"relationships\" relationships)) (list (cons \"max_depth\" max-depth)) (list (cons \"algorithm\" (case algorithm (:shortest-path \"shortestPath\") (:all-paths \"allPaths\") (:all-simple-paths \"allSimplePaths\") (:dijkstra \"dijkstra\"))))) :object) (:status-handlers (200 (decode-neo4j-json-output body)) (204 (error 'path-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-paths (&key node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) (let ((uri (format nil \"node/~A/paths\" node-id)) (json (encode-neo4j-json-payload (list (list (cons \"to\" to-node-id) :node-url) (list (cons \"relationships\" relationships)) (list (cons \"max_depth\" max-depth)) (list (cons \"algorithm\" (case algorithm (:shortest-path \"shortestPath\") (:all-paths \"allPaths\") (:all-simple-paths \"allSimplePaths\") (:dijkstra \"dijkstra\"))))) :object))) (make-neo4j-request :post uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 204 (lambda (body uri json) (error (quote path-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-cfun c-calloc)\n\nPattern to recognize: Macro call that should be transformed by define-cfun", "input": "(define-cfun c-calloc)", "output": "(defmacro define-cfun (name-or-function &optional (package *package*))\n (when-let ((fun (find-function name-or-function)))\n (with-wrap-attempt (\"function ~S\" name-or-function) name-or-function\n (with-slots (name type c-symbol fields) fun\n (let* ((fun-name (intern (symbol-name name) package))\n (param-names (mapcar #'foreign-type-name fields))\n (param-syms (mapcar (lambda (x) (gensym (symbol-name x))) param-names))\n (make-function-p (not (foreign-function-variadic-p fun)))\n (maybe-cbv-return\n (when (cbv-return-p fun)\n (list 'return-value))))\n (with-gensyms (!fun !fields rest)\n (let ((form\n (if make-function-p\n `(defun ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n ,(let ((!fun (find-function name-or-function)))\n (with-slots ((!fields fields)) !fun\n (foreign-to-ffi\n (and (car !fields) (foreign-type (car !fields)))\n param-syms\n param-names\n !fields\n (make-foreign-funcall !fun (and maybe-cbv-return 'return-value)\n param-syms (when (foreign-function-variadic-p fun) rest))))))\n `(defmacro ,fun-name (,@maybe-cbv-return\n ,@param-names ,@(when (foreign-function-variadic-p fun) `(&rest ,rest)))\n ,@(when maybe-cbv-return `((declare (ignorable ,@maybe-cbv-return))))\n (let ((,!fun (find-function ',name-or-function)))\n (with-slots ((,!fields fields)) ,!fun\n (foreign-to-ffi\n (and (car ,!fields) (foreign-type (car ,!fields)))\n ',param-syms\n (list ,@param-names)\n ,!fields\n (make-foreign-funcall ,!fun ,(and maybe-cbv-return 'return-value)\n ',param-syms ,(when (foreign-function-variadic-p fun) rest)))))))))\n `(progn\n ,@(when (foreign-function-cbv-p fun)\n (list (funcall *build-libffi-definition* fun)))\n ,form))))))))", "macroexpand": "(progn (defun c-calloc (nmemb size) (let ((#:nmemb204 nmemb)) (declare (ignorable #:nmemb204)) (let ((#:size205 size)) (declare (ignorable #:size205)) (cffi-sys:%foreign-funcall \"calloc\" (:unsigned-long-long #:nmemb204 :unsigned-long-long #:size205 :pointer) :convention :cdecl)))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defstore nxpy (y x &optional (a 1) (b 1)))\n\nIssue: Macro call that should be transformed by defstore", "input": "(defstore nxpy (y x &optional (a 1) (b 1)))", "output": "(defmacro defstore (store-name store-lambda-list &body body &environment env)\n (let* ((store-class-name (second (find :store-class body :key #'first)))\n (store-class (etypecase store-class-name\n (null (find-class 'standard-store))\n (symbol (find-class store-class-name))))\n (form (apply #'defstore-using-class store-class store-name store-lambda-list\n :environment env\n (mapcan #'(lambda (item)\n (cond ((eql (first item) :store-class)\n `(:store-class ',store-class-name))\n ((and (member (first item) '(:documentation :specialization-class)))\n (if (= 2 (length item))\n item\n (error \"Invalid store definition option: ~W.\" item)))\n (t\n (list (first item) (rest item)))))\n body))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ,form)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (ensure-store (quote nxpy) (quote (y x &optional (a 1 #:a?149) (b 1 #:b?150))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-rewrite third (expr) `(caddr ,(second expr)))\n\nIssue: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite third (expr) `(caddr ,(second expr)))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote third) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (caddr #S(sb-impl::comma :expr (second expr) :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (not (slot-value parent 'tail-qualifiers)) (format stream \" \"))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (not (slot-value parent 'tail-qualifiers)) (format stream \" \"))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (not (slot-value parent (quote tail-qualifiers))) (format stream \" \"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n;; Threading a value through multiple dependent checks\n(let ((user (find-user id)))\n (if user\n (let ((orders (get-orders user)))\n (if orders\n (let ((latest (first orders)))\n (if latest\n (process latest)\n :no-orders))\n :no-orders))\n :no-user))\n;; Deeply nested ifs obscure the linear flow\n\nWrite a macro that addresses: Threading a value through dependent operations creates deep if-nesting \u2014 want linear, pipeline-like syntax", "input": ";; Threading a value through multiple dependent checks\n(let ((user (find-user id)))\n (if user\n (let ((orders (get-orders user)))\n (if orders\n (let ((latest (first orders)))\n (if latest\n (process latest)\n :no-orders))\n :no-orders))\n :no-user))\n;; Deeply nested ifs obscure the linear flow", "output": "(defmacro aand (&rest args)\n (cond ((null args) t)\n ((null (cdr args)) (car args))\n (t `(aif ,(car args) (aand ,@(cdr args))))))", "macroexpand": ";; (aand (find-user id)\n;; (get-orders it)\n;; (first it)\n;; (process it))\n;;\n;; Each form's result is bound to 'it' for the next form.\n;; If any form returns nil, the chain stops and returns nil.\n;; Linear, readable, no nesting.", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9874999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(integer-reader 8)\n\nWhat needs to change: Macro call that should be transformed by integer-reader", "input": "(integer-reader 8)", "output": "(defmacro integer-reader (bytes)\n \"Create a function to read integers from a binary stream.\"\n (let ((bits (* bytes 8)))\n (labels ((return-form (signed)\n (if signed\n `(if (logbitp ,(1- bits) result)\n (dpb result (byte ,(1- bits) 0) -1)\n result)\n `result))\n (generate-reader (signed)\n `(defun ,(integer-reader-name bytes signed) (socket)\n (declare (type stream socket)\n #.*optimize*)\n ,(if (= bytes 1)\n `(let ((result (the (unsigned-byte 8) (read-byte socket))))\n (declare (type (unsigned-byte 8) result))\n ,(return-form signed))\n `(let ((result 0))\n (declare (type (unsigned-byte ,bits) result))\n ,@(loop :for byte :from (1- bytes) :downto 0\n :collect `(setf (ldb (byte 8 ,(* 8 byte))\n result)\n (the (unsigned-byte 8)\n (read-byte socket))))\n ,(return-form signed))))))\n `(progn\n ;; This causes weird errors on SBCL in some circumstances. Disabled for now.\n ;; (declaim (inline ,(integer-reader-name bytes t)\n ;; ,(integer-reader-name bytes nil)))\n (declaim (ftype (function (t) (signed-byte ,bits))\n ,(integer-reader-name bytes t)))\n ,(generate-reader t)\n (declaim (ftype (function (t) (unsigned-byte ,bits))\n ,(integer-reader-name bytes nil)))\n ,(generate-reader nil)))))", "macroexpand": "(progn (declaim (ftype (function (t) (signed-byte 64)) read-int8)) (defun read-int8 (socket) (declare (type stream socket) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (let ((result 0)) (declare (type (unsigned-byte 64) result)) (setf (ldb (byte 8 56) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 48) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 40) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 32) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 24) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 16) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 8) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 0) result) (the (unsigned-byte 8) (read-byte socket))) (if (logbitp 63 result) (dpb result (byte 63 0) -1) result))) (declaim (ftype (function (t) (unsigned-byte 64)) read-uint8)) (defun read-uint8 (socket) (declare (type stream socket) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (let ((result 0)) (declare (type (unsigned-byte 64) result)) (setf (ldb (byte 8 56) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 48) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 40) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 32) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 24) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 16) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 8) result) (the (unsigned-byte 8) (read-byte socket))) (setf (ldb (byte 8 0) result) (the (unsigned-byte 8) (read-byte socket))) result)))", "category": "dsl", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:>= infix-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:>= infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (>=-op (:include infix-op (name \">=\")) (:constructor make->=-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun+ nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFUN+", "input": "(defun+ nil\n nil)", "output": "(defmacro DEFUN+ ...)", "macroexpand": "(defun nil () (let+ nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun-compile-time cps-convert-function-name (function-name) (if (symbolp function-name) (intern (format nil \"~A-NONDETERMINISTIC\" (string function-name)) (symbol-package function-name)) `(setf ,(intern (format nil \"~A-NONDETERMINISTIC\" (string (second function-name))) (symbol-package (second function-name))))))\n\nIssue: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time cps-convert-function-name (function-name) (if (symbolp function-name) (intern (format nil \"~A-NONDETERMINISTIC\" (string function-name)) (symbol-package function-name)) `(setf ,(intern (format nil \"~A-NONDETERMINISTIC\" (string (second function-name))) (symbol-package (second function-name))))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun cps-convert-function-name (function-name) (if (symbolp function-name) (intern (format nil \"~A-NONDETERMINISTIC\" (string function-name)) (symbol-package function-name)) (sb-int:quasiquote (setf #S(sb-impl::comma :expr (intern (format nil \"~A-NONDETERMINISTIC\" (string (second function-name))) (symbol-package (second function-name))) :kind 0))))) (eval-when (:compile-toplevel) (compile (quote cps-convert-function-name))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(let-syntax common-lisp:nil (common-lisp:progn))\n\nPattern to recognize: Macro call that should be transformed by LET-SYNTAX", "input": "(let-syntax common-lisp:nil (common-lisp:progn))", "output": "(defmacro LET-SYNTAX ...)", "macroexpand": "(common-lisp:progn (common-lisp:progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(augment steppers step)\n\nWhat needs to change: Macro call that should be transformed by augment", "input": "(augment steppers step)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf steppers (nconc steppers step))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list ,@body))\n\nProblem: Macro call that should be transformed by destructure-specialized-lambda-list", "input": "(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list ,@body))", "output": "(defmacro destructure-specialized-lambda-list (descriptive-lambda-list-sym vanilla-lambda-list-sym type-list-sym specialized-lambda-list &body body)\n \"if specialized-lambda-list is ((a integer) b):\ndescriptive-lambda-list will be ((x integer) (x t))\ntype-list will be (integer t) and vanilla-lambda-list is (a b)\"\n (let ((item (gensym)))\n `(let* ((,descriptive-lambda-list-sym\n (loop :for ,item :in ,specialized-lambda-list\n :if (listp ,item)\n :collect ,item\n :else :collect (list ,item t)))\n (,vanilla-lambda-list-sym (mapcar #'first ,descriptive-lambda-list-sym))\n (,type-list-sym (mapcar #'second ,descriptive-lambda-list-sym)))\n (declare (ignorable ,descriptive-lambda-list-sym ,vanilla-lambda-list-sym ,type-list-sym))\n ,@body)))", "macroexpand": "(let* ((descriptive-lambda-list (loop :for #:g127 :in specialized-lambda-list :if (listp #:g127) :collect #:g127 :else :collect (list #:g127 t))) (vanilla-lambda-list (mapcar (function first) descriptive-lambda-list)) (type-list (mapcar (function second) descriptive-lambda-list))) (declare (ignorable descriptive-lambda-list vanilla-lambda-list type-list)) (sb-int:quasiquote (%lay-method-base-for-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(disable-infix-reader)\n\nWhat needs to change: Macro call that should be transformed by DISABLE-INFIX-READER", "input": "(disable-infix-reader)", "output": "(defmacro DISABLE-INFIX-READER ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setq *readtable* (pop *readtables*)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym for :for)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym for :for)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote for) (quote synonym)) (quote :for)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-syntax-error* (1- (lexer-pos lexer)) \"Character '~A' may not follow '(?<'.\" next-char )\n\nIssue: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (1- (lexer-pos lexer)) \"Character '~A' may not follow '(?<'.\" next-char )", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos (1- (lexer-pos lexer)) :format-control \"Character '~A' may not follow '(?<'.\" :format-arguments (list next-char))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define BUFSIZ 512)\n\nIssue: Macro call that should be transformed by define", "input": "(define BUFSIZ 512)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote bufsiz) *preprocessor-defines*) #A((3) base-char . \"512\"))) (defparameter bufsiz 512))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-rewrite cdaadr (expr) `(cdr (caadr ,(second expr))))\n\nIssue: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cdaadr (expr) `(cdr (caadr ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote cdaadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (caadr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(letrec* ((f (constantly t)) (a (funcall f))) (is-true a))\n\nProblem: Macro call that should be transformed by letrec*", "input": "(letrec* ((f (constantly t)) (a (funcall f))) (is-true a))", "output": "(defmacro letrec* ((&rest bindings) &body body)\n \"Like LETREC, but the bindings are evaluated in order.\nSee Waddell et al., *Fixing Letrec* for motivation.\n\nCf. `fbindrec*'.\"\n `(letrec-with setq ,bindings\n ,@body))", "macroexpand": "(letrec-with setq ((f (constantly t)) (a (funcall f))) (is-true a))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(gather-next nil nil)\n\nProblem: Macro call that should be transformed by GATHER-NEXT", "input": "(gather-next nil nil)", "output": "(defmacro GATHER-NEXT ...)", "macroexpand": "(common-lisp:funcall nil nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(bind ((#2a((a b c) (d e f)) #2a((1 2 3) (4 5 6)))) (list a b c d e f))\n\nProblem: Macro call that should be transformed by bind", "input": "(bind ((#2a((a b c) (d e f)) #2a((1 2 3) (4 5 6)))) (list a b c d e f))", "output": "(defmacro bind ((&rest bindings) &body body)\n \"Bind is a replacement for let*, destructuring-bind, multiple-value-bind and more. \n\nAn example is probably the best way to describe its syntax:\n\n \\(bind \\(\\(a 2\\)\n \\(\\(b &rest args &key \\(c 2\\) &allow-other-keys\\) '\\(:a :c 5 :d 10 :e 54\\)\\)\n \\(\\(:values d e\\) \\(truncate 4.5\\)\\)\n \\(\\(:structure xxx- slot1 slot2\\) \\(make-xxx\\)\\)\n \\(\\(:flet name \\(arg1 arg2\\)\\) \\(+ arg1 arg2\\)\\)\\)\n \\(list a b c d e args\\)\\)\n\nSimple bindings are as in let*. Destructuring is done if the first item\nin a binding is a list. Multiple value binding is done if the first item\nin a binding is a list and the first item in the list is ':values'. Other\nforms have their own syntax. For example, :structure first has the conc\nname and then slot names whereas :flet has the function name and a list\nof arguments and then the function body (in an implicit progn).\"\n (let (declarations)\n (loop while (and (consp (car body)) (eq (caar body) 'declare)) do\n (push (first body) declarations)\n (setf body (rest body)))\n (if bindings\n\t(let ((*all-declarations* (bind-expand-declarations (nreverse declarations))))\n\t (prog1\n\t (bind-macro-helper bindings body)\n\t (check-for-unused-variable-declarations *all-declarations*)))\n `(locally\n ,@declarations\n ,@body))))", "macroexpand": "(let* ((#:|values-167| #2A((1 2 3) (4 5 6))) (a (row-major-aref #:|values-167| 0)) (b (row-major-aref #:|values-167| 1)) (c (row-major-aref #:|values-167| 2)) (d (row-major-aref #:|values-167| 3)) (e (row-major-aref #:|values-167| 4)) (f (row-major-aref #:|values-167| 5))) (declare (ignorable #:|values-167|)) (progn (list a b c d e f)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ps-once-only nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by PS-ONCE-ONLY", "input": "(ps-once-only nil\n :key\n nil)", "output": "(defmacro PS-ONCE-ONLY ...)", "macroexpand": "(let* ()\n `(let* ()\n ,(let* ()\n :key\n nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(match maybe m ((just x) x) (nothing else))\n\nWrite a macro that addresses: Macro call that should be transformed by match", "input": "(match maybe m ((just x) x) (nothing else))", "output": "(defmacro match (adt obj &body clauses)\n \"Perform pattern matching on OBJ with (adt-type) ADT.\n\nEach clause must have the following syntax:\n\n := | '_'\n := '_'\n | ( *)\n := ( )\n\nThe symbol '_' denotes a wildcard, as well as a fallthough.\n\nNote that pattern matching is only shallow (patterns are one-level\ndeep).\n\"\n (assert (symbolp adt)\n (adt)\n \"MATCH requires a symbol for the first argument. Given ~S.\"\n adt)\n\n (let ((ctors (mapcar #'car (get-constructors adt)))\n (types (mapcar (lambda (clause)\n (ensure-car (car clause)))\n clauses))\n (once (gensym \"OBJ-\")))\n\n ;; Check for duplicate matches.\n (let ((dupes (duplicates types)))\n (when dupes\n (warn \"Duplicate matching clauses exist. Duplicate pattern ~\n constructors:~{ ~S~}\"\n dupes)))\n\n ;; Check for match exhaustiveness.\n (unless (some #'wild? types)\n (let ((diff (set-difference ctors types)))\n (when diff\n (warn \"Non-exhaustive match on ~A data ~\n type. Missing cases:~{ ~S~}\" adt diff))))\n\n ;; Generate the matching code.\n `(let ((,once ,obj))\n (check-type ,once ,adt)\n (etypecase ,once\n ,@(loop :for (bindings . body) :in clauses\n :collect (let ((type (ensure-car bindings)))\n (if (wild? type)\n `(t ,@body)\n `(,type\n (with-data ,(ensure-list bindings)\n ,once\n ,@body)))))))))", "macroexpand": "(let ((#:obj-147 m)) (check-type #:obj-147 maybe) (etypecase #:obj-147 (just (with-data (just x) #:obj-147 x)) (nothing (with-data (nothing) #:obj-147 else))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dig 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by DIG", "input": "(dig 'some-name)", "output": "(defmacro DIG ...)", "macroexpand": "(dig 1 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(as->* nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by AS->*", "input": "(as->* nil nil)", "output": "(defmacro AS->* ...)", "macroexpand": "(as-> nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (slot-boundp item slot) (when (eq (slot-value item slot) nil) (setf subnodes (remove slot subnodes))) (let ((position (position slot subnodes))) (setf (slot-value node-copy slot) (if position (nth position subnode-copies) (slot-value item slot)))))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (slot-boundp item slot) (when (eq (slot-value item slot) nil) (setf subnodes (remove slot subnodes))) (let ((position (position slot subnodes))) (setf (slot-value node-copy slot) (if position (nth position subnode-copies) (slot-value item slot)))))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (slot-boundp item slot) (progn (when (eq (slot-value item slot) nil) (setf subnodes (remove slot subnodes))) (let ((position (position slot subnodes))) (setf (slot-value node-copy slot) (if position (nth position subnode-copies) (slot-value item slot))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-env [str 0])\n\nWhat needs to change: Macro call that should be transformed by with-env", "input": "(with-env [str 0])", "output": "(defmacro with-env (&body body)\n (let ((body-value (gensym)))\n `(let (,body-value)\n (defclass foo () ((a :initform 3)))\n (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s)))\n (defmethod (setf get-val) (new-value (object foo) &rest slot/s)\n (setf (slot-value object (car slot/s)) new-value))\n (defstruct bar a)\n (setq ,body-value\n (let ((str (alexandria:copy-array \"abcde\"))\n (vec (alexandria:copy-array #(a b c d e)))\n (arr (alexandria:copy-array #2A((1 2 3)\n (4 5 6))))\n (list (copy-list '(a b c d e)))\n (ht (eval (read-from-string \"{'a 'b 'c 'd}\")))\n (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\")))\n (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\")))\n (assoc-list (copy-tree '((a . 1) (b . 2))))\n (plist (copy-list '(:a 4 :c 5)))\n (clos-object (make-instance 'foo))\n (struct (make-bar :a 3)))\n (declare (ignorable str vec arr list ht ht-eq ht-equalp\n assoc-list plist clos-object struct))\n ,@body))\n (setf (find-class 'foo nil) nil)\n (setf (find-class 'bar nil) nil)\n ,body-value))", "macroexpand": "(let (#:g123) (defclass foo nil ((a :initform 3))) (defmethod get-val ((object foo) &rest slot/s) (slot-value object (car slot/s))) (defmethod (setf get-val) (new-value (object foo) &rest slot/s) (setf (slot-value object (car slot/s)) new-value)) (defstruct bar a) (setq #:g123 (let ((str (alexandria:copy-array \"abcde\")) (vec (alexandria:copy-array #(a b c d e))) (arr (alexandria:copy-array #2A((1 2 3) (4 5 6)))) (list (copy-list (quote (a b c d e)))) (ht (eval (read-from-string \"{'a 'b 'c 'd}\"))) (ht-eq (eval (read-from-string \"{eq \\\"a\\\" 1\n \\\"b\\\" 2}\"))) (ht-equalp (eval (read-from-string \"{equalp '(1 2 3) \\\"a\\\"\n '(4 5 6) \\\"b\\\"}\"))) (assoc-list (copy-tree (quote ((a . 1) (b . 2))))) (plist (copy-list (quote (:a 4 :c 5)))) (clos-object (make-instance (quote foo))) (struct (make-bar :a 3))) (declare (ignorable str vec arr list ht ht-eq ht-equalp assoc-list plist clos-object struct)) [str 0])) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g123)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(without-symbol-access\n nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS", "input": "(without-symbol-access\n nil\n nil)", "output": "(defmacro WITHOUT-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* nil))\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(matrix-typecase nil)\n\nPattern to recognize: Macro call that should be transformed by MATRIX-TYPECASE", "input": "(matrix-typecase nil)", "output": "(defmacro MATRIX-TYPECASE ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-definition-resolver symbol-macro designator-symbol-macro-p)\n\nPattern to recognize: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver symbol-macro designator-symbol-macro-p)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver symbol-macro (symbol-macro #:package141) (when (ignore-errors (designator-symbol-macro-p symbol-macro)) (list (make-instance (quote symbol-macro) :designator symbol-macro :package #:package141))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n($/ \"[_]*.mr.\" \"i\")\n\nIssue: Macro call that should be transformed by $/", "input": "($/ \"[_]*.mr.\" \"i\")", "output": "(defmacro $/ (regex options)\n `(make-bson-regex (empty-str ,regex) ,options))", "macroexpand": "(make-bson-regex (empty-str \"[_]*.mr.\") \"i\")", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cond->)\n\nIssue: Macro call that should be transformed by COND->", "input": "(cond->)", "output": "(defmacro COND-> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-sharp-boolean-syntax)\n\nProblem: Macro call that should be transformed by ENABLE-SHARP-BOOLEAN-SYNTAX", "input": "(enable-sharp-boolean-syntax)", "output": "(defmacro ENABLE-SHARP-BOOLEAN-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-sharp-boolean-syntax-in-readtable)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(collect-file nil nil)\n\nPattern to recognize: Macro call that should be transformed by COLLECT-FILE", "input": "(collect-file nil nil)", "output": "(defmacro COLLECT-FILE ...)", "macroexpand": "(common-lisp:let* ((#:generator-542 (generator nil)) #:items-536 (#:out-538 t))\n (declare (type generator #:generator-542)\n (type boolean #:out-538))\n (with-open-file (#:outfile-535 nil :direction :output)\n (tagbody\n #:ll-543\n (setq #:items-536 (next-in #:generator-542 (go end)))\n (common-lisp:funcall #'print #:items-536 #:outfile-535)\n (go #:ll-543)\n end))\n #:out-538)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-readtime-wrapper-syntax 'some-name)\n\nProblem: Macro call that should be transformed by ENABLE-READTIME-WRAPPER-SYNTAX", "input": "(enable-readtime-wrapper-syntax 'some-name)", "output": "(defmacro ENABLE-READTIME-WRAPPER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-readtime-wrapper-syntax-in-readtable 'some-name #\\RIGHT_CURLY_BRACKET)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(true \"Happy\")\n\nIssue: Macro call that should be transformed by true", "input": "(true \"Happy\")", "output": "(defmacro true (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(true ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected 'T\n :comparison 'geq\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (true \"Happy\")) :value-form (quote \"Happy\") :body (lambda nil \"Happy\") :expected (quote t) :comparison (quote geq)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defhandler labels (labels bindings &rest body) `(with-imposed-bindings (,labels ,(clean-fbindings bindings) ,(declare-fbindings-ignorable bindings) (list* ',labels ,(dump-fbindings bindings) (m-list ,@body)))))\n\nIssue: Macro call that should be transformed by defhandler", "input": "(defhandler labels (labels bindings &rest body) `(with-imposed-bindings (,labels ,(clean-fbindings bindings) ,(declare-fbindings-ignorable bindings) (list* ',labels ,(dump-fbindings bindings) (m-list ,@body)))))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-labels (labels bindings &rest body) (sb-int:quasiquote (with-imposed-bindings (#S(sb-impl::comma :expr labels :kind 0) #S(sb-impl::comma :expr (clean-fbindings bindings) :kind 0) #S(sb-impl::comma :expr (declare-fbindings-ignorable bindings) :kind 0) (list* (quote #S(sb-impl::comma :expr labels :kind 0)) #S(sb-impl::comma :expr (dump-fbindings bindings) :kind 0) (m-list #S(sb-impl::comma :expr body :kind 2))))))) (setf (gethash (quote labels) *form-handler*) (quote hander-labels)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(some->> nil)\n\nWhat needs to change: Macro call that should be transformed by SOME->>", "input": "(some->> nil)", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:|some120| nil))\n #:|some120|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-binary-op-mapping-definer define-comparison-ops `(progn (defmethod ,op ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (,cl (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod ,op ((x number) (y number)) (if (,cl x y) 1 0))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-binary-op-mapping-definer", "input": "(define-binary-op-mapping-definer define-comparison-ops `(progn (defmethod ,op ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (,cl (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod ,op ((x number) (y number)) (if (,cl x y) 1 0))))", "output": "(defmacro define-binary-op-mapping-definer (name &body body)\n `(defmacro ,name (&rest map)\n `(progn ,@(loop for (vacietis cl) on map by #'cddr collect\n (let ((op (find-symbol (symbol-name vacietis) '#:vacietis.c)))\n ,@body)))))", "macroexpand": "(defmacro define-comparison-ops (&rest map) (sb-int:quasiquote (progn #S(sb-impl::comma :expr (loop for (vacietis cl) on map by (function cddr) collect (let ((op (find-symbol (symbol-name vacietis) (quote #:vacietis.c)))) (sb-int:quasiquote (progn (defmethod #S(sb-impl::comma :expr op :kind 0) ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (#S(sb-impl::comma :expr cl :kind 0) (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod #S(sb-impl::comma :expr op :kind 0) ((x number) (y number)) (if (#S(sb-impl::comma :expr cl :kind 0) x y) 1 0)))))) :kind 2))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(false (sleep 1))\n\nWrite a macro that addresses: Macro call that should be transformed by false", "input": "(false (sleep 1))", "output": "(defmacro false (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(false ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected 'NIL\n :comparison 'geq\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (false (sleep 1))) :value-form (quote (sleep 1)) :body (lambda nil (sleep 1)) :expected (quote nil) :comparison (quote geq)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (with-effective-qualifier generic-function qualifier `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list (dispatch ,generic-function ,qualifier ,specialized-lambda-list) ,@body)))\n\nWhat needs to change: Macro call that should be transformed by destructure-specialized-lambda-list", "input": "(destructure-specialized-lambda-list descriptive-lambda-list vanilla-lambda-list type-list specialized-lambda-list (with-effective-qualifier generic-function qualifier `(%lay-method-base-for-dispatch ,generic-function ,qualifier ,type-list ,descriptive-lambda-list (dispatch ,generic-function ,qualifier ,specialized-lambda-list) ,@body)))", "output": "(defmacro destructure-specialized-lambda-list (descriptive-lambda-list-sym vanilla-lambda-list-sym type-list-sym specialized-lambda-list &body body)\n \"if specialized-lambda-list is ((a integer) b):\ndescriptive-lambda-list will be ((x integer) (x t))\ntype-list will be (integer t) and vanilla-lambda-list is (a b)\"\n (let ((item (gensym)))\n `(let* ((,descriptive-lambda-list-sym\n (loop :for ,item :in ,specialized-lambda-list\n :if (listp ,item)\n :collect ,item\n :else :collect (list ,item t)))\n (,vanilla-lambda-list-sym (mapcar #'first ,descriptive-lambda-list-sym))\n (,type-list-sym (mapcar #'second ,descriptive-lambda-list-sym)))\n (declare (ignorable ,descriptive-lambda-list-sym ,vanilla-lambda-list-sym ,type-list-sym))\n ,@body)))", "macroexpand": "(let* ((descriptive-lambda-list (loop :for #:g125 :in specialized-lambda-list :if (listp #:g125) :collect #:g125 :else :collect (list #:g125 t))) (vanilla-lambda-list (mapcar (function first) descriptive-lambda-list)) (type-list (mapcar (function second) descriptive-lambda-list))) (declare (ignorable descriptive-lambda-list vanilla-lambda-list type-list)) (with-effective-qualifier generic-function qualifier (sb-int:quasiquote (%lay-method-base-for-dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) (dispatch #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr specialized-lambda-list :kind 0)) #S(sb-impl::comma :expr body :kind 2)))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defmethod* nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil\n nil)", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(defmethod nil (the t ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(mvlet* ((x)) x)\n\nPattern to recognize: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((x)) x)", "output": "(defmacro mvlet* ((&rest bindings) &body body &environment env)\n \"Expand a series of nested `multiple-value-bind' forms.\n\n`mvlet*' is similar in intent to Scheme\u2019s `let-values', but with a\ndifferent and less parenthesis-intensive syntax. Each binding is a\nlist of\n\n (var var*... expr)\n\nA simple example should suffice to show both the implementation and\nthe motivation:\n\n (defun uptime (seconds)\n (mvlet* ((minutes seconds (truncate seconds 60))\n (hours minutes (truncate minutes 60))\n (days hours (truncate hours 24)))\n (declare ((integer 0 *) days hours minutes seconds))\n (fmt \\\"~d day~:p, ~d hour~:p, ~d minute~:p, ~d second~:p\\\"\n days hours minutes seconds)))\n\nNote that declarations work just like `let*'.\"\n (cond ((null bindings)\n `(locally ,@body))\n ((every #'simple-binding-p bindings)\n `(let* ,bindings ,@body))\n (t (multiple-value-bind (body decls)\n (parse-body body)\n (let* ((bindings (canonicalize-bindings bindings))\n (mvbinds (member-if-not #'simple-binding-p bindings))\n (simple-binds (ldiff bindings mvbinds)))\n (if simple-binds\n (multiple-value-bind (local other)\n (partition-declarations (mapcar #'car simple-binds) decls env)\n `(let* ,simple-binds\n ,@local\n (mvlet* ,mvbinds\n ,@other\n ,@body)))\n (let* ((vars (butlast (car bindings)))\n (expr (lastcar (car bindings))))\n (multiple-value-bind (local other)\n (partition-declarations vars decls env)\n `(multiple-value-bind ,vars\n ,expr\n ,@local\n (mvlet* ,(cdr bindings)\n ,@other\n ,@body))))))))))", "macroexpand": "(let* ((x)) x)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(form-fiddle:lambda-forms `(lambda () ,@body))\n\nIssue: Macro call that should be transformed by for", "input": "(form-fiddle:lambda-forms `(lambda () ,@body))", "output": "(defmacro for (&environment env bindings &body body)\n (let ((*environment* env))\n (multiple-value-bind (bind-init bind-forms bind-exit bind-post) (convert-bindings bindings)\n (multiple-value-bind (clause-init body-forms clause-exit) (convert-clauses body)\n `(with-interleaving\n ,@bind-init\n ,@clause-init\n (with-for-block ()\n (with-for-tagbody\n (progn ,@bind-forms\n ,@body-forms\n ,@bind-post)\n (return-for\n ,@clause-exit\n ,@bind-exit))))))))", "macroexpand": "(form-fiddle:lambda-forms (sb-int:quasiquote (lambda nil #S(sb-impl::comma :expr body :kind 2))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-syntax-error* error-pos \"No character for hex-code ~X.\" number)\n\nIssue: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* error-pos \"No character for hex-code ~X.\" number)", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos error-pos :format-control \"No character for hex-code ~X.\" :format-arguments (list number))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(nth-value-or 1 (values 1 nil 1) (values 2 2 2))\n\nWhat needs to change: Macro call that should be transformed by nth-value-or", "input": "(nth-value-or 1 (values 1 nil 1) (values 2 2 2))", "output": "(defmacro nth-value-or (nth-value &body forms)\n \"Evaluates FORM arguments one at a time, until the NTH-VALUE returned by one\nof the forms is true. It then returns all the values returned by evaluating\nthat form. If none of the forms return a true nth value, this form returns\nNIL.\"\n (once-only (nth-value)\n (with-gensyms (values)\n `(let ((,values (multiple-value-list ,(first forms))))\n (if (nth ,nth-value ,values)\n (values-list ,values)\n ,(if (rest forms)\n `(nth-value-or ,nth-value ,@(rest forms))\n nil))))))", "macroexpand": "(let ((#:nth-value149 1)) (let ((#:values150 (multiple-value-list (values 1 nil 1)))) (if (nth #:nth-value149 #:values150) (values-list #:values150) (nth-value-or #:nth-value149 (values 2 2 2)))))", "category": "anaphoric", "technique": "once-only,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.85} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defdata (point :mutable t) (rect float float))\n\nProblem: Macro call that should be transformed by defdata", "input": "(defdata (point :mutable t) (rect float float))", "output": "(defmacro defdata (adt-name &body constructors)\n \"Define a new ADT. ADT-name has the following grammar:\n\nADT-NAME := \n | ( *)\n\nThere is no difference between specifying it as a symbol or as a\nsingleton list. There are two possible options, specified as a\nproperty list:\n\n * :MUTABLE {T, NIL} (default: NIL): Specifies whether the fields\n of the type are mutable, allowing the use of SET-DATA.\n\n * :INCLUDE : Specifies whether another defined ADT\n should be inherited.\n\nConstructors is a list of clauses with the following grammar:\n\n := \n | ( *)\n\nEach clause defines a constructor for the ADT. Nullary constructors\nwill define constants and all other constructors will define\nfunctions.\"\n ;; Do some extreme sanity checking.\n (assert\n (or\n ;; Must be a symbol, or...\n (symbolp adt-name)\n (and\n ;; a list that is...\n (listp adt-name)\n ;; non-empty\n (not (null adt-name))\n ;; whose first element is a symbol (the name of the adt)\n (symbolp (first adt-name))\n ;; and the rest is a property list\n (property-list-p (rest adt-name))))\n (adt-name)\n \"ADT-NAME must either be a symbol, a singleton list with the ADT ~\n name as a symbol, or a list of two elements with the ADT name ~\n and :MUTABLE respectively. Given ~S.\"\n adt-name)\n (let ((valid-options (list ':mutable ':include)))\n (when (and (listp adt-name) (= (mod (length (rest adt-name)) 2) 0))\n (loop for opt in (rest adt-name) by #'cddr do\n\t (when (not (member opt valid-options))\n\t (error \"Option ~A is not valid, valid options are member of ~A.\" opt valid-options)))))\n\n (let ((adt-name (ensure-car adt-name))\n (mutable? (and (listp adt-name)\n (getf (rest adt-name) ':mutable)\n t))\n (include (or (and (listp adt-name)\n (getf (rest adt-name) ':include))\n 'algebraic-data-type))\n (object (gensym \"OBJECT-\"))\n (stream (gensym \"STREAM-\"))\n (depth (gensym \"DEPTH-\"))\n (env (gensym \"ENVIRONMENT-\"))\n (documentation\n (when (stringp (car constructors))\n (pop constructors))))\n\n ;; Sanity check that INCLUDE is a proper algebraic data type.\n (assert (algebraic-data-type-p include)\n ()\n \"When defining the algebraic data type ~S, the :INCLUDE option ~\n was specified with ~S, which is not another algebraic data ~\n type.\"\n adt-name\n include)\n\n ;; Add constructors and their arity to the database.\n (flet ((constructor-and-arity (ctor)\n (if (listp ctor)\n (list (first ctor) (length (rest ctor)))\n (list ctor 0))))\n (set-constructors adt-name (append (get-constructors include)\n (mapcar #'constructor-and-arity constructors))))\n\n (flet ((make-printer (name &optional (nfields 0))\n \"Make a printer function for the structs.\"\n `(lambda (,object ,stream ,depth)\n (declare (ignore ,depth)\n (ignorable ,object))\n ;; We don't check *PRINT-READABLY* because these can\n ;; be readably printed always, provided the arguments\n ;; can be printed readably.\n ;;\n ;; However, we do respect a convenience option\n ;; *PRINT-ADT-READABLY* in case someone finds the\n ;; printing of the #. to be annoying.\n (when *print-adt-readably*\n (write-string \"#.\" ,stream))\n ,(when (plusp nfields)\n `(write-char #\\( ,stream))\n (prin1 ',name ,stream)\n ,@(when (plusp nfields)\n (loop :for i :below nfields\n :append (list\n `(write-char #\\Space ,stream)\n `(prin1 (,(field name i) ,object)\n ,stream))))\n ,(when (plusp nfields)\n `(write-char #\\) ,stream)))))\n ;; Define everything.\n (let ((component-documentation\n ;; Force the adt-name symbol to print with a package\n ;; prefix\n (let ((*package* (find-package :keyword)))\n (format nil \"A component of ADT ~S\" adt-name))))\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ;; Define the data type.\n (defstruct (,adt-name (:constructor nil)\n (:copier nil)\n (:predicate nil)\n (:include ,include))\n ,@(unsplice documentation))\n\n ;; Define each of the field constructors.\n ,@(loop :for ctor :in (unwrap-singletons constructors)\n :collect\n (etypecase ctor\n ;; Nullary constructor\n (symbol `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defstruct\n (,ctor\n (:include ,adt-name)\n (:constructor ,(internal ctor))\n (:copier nil)\n (:predicate nil)\n (:print-function ,(make-printer ctor)))\n ,component-documentation))\n #+sbcl (declaim (sb-ext:freeze-type ,ctor))\n (defmethod make-load-form ((,object ,ctor) &optional ,env)\n (make-load-form-saving-slots ,object\n :slot-names nil\n :environment ,env))\n (define-constant ,ctor (,(internal ctor))\n ,component-documentation)\n (fmakunbound ',(internal ctor))))\n\n ;; N-ary constructors\n (list (let* ((ctor-name (first ctor))\n (field-types (rest ctor))\n (field-names (gen-names (length field-types))))\n `(progn\n (defstruct (,ctor-name\n (:include ,adt-name)\n (:constructor ,ctor-name (,@field-names))\n (:conc-name ,ctor-name)\n (:copier nil)\n (:predicate nil)\n (:print-function\n ,(make-printer ctor-name\n (length field-names))))\n ,component-documentation\n ,@(mapcar (lambda (name type)\n `(,name (error \"Unspecified field.\")\n :type ,type\n ,@(if mutable?\n nil\n '(:read-only t))))\n field-names\n field-types))\n #+sbcl (declaim (sb-ext:freeze-type ,ctor-name))\n (defmethod make-load-form ((,object ,ctor-name) &optional ,env)\n (make-load-form-saving-slots ,object\n :slot-names ',field-names\n :environment ,env)))))))\n ;; Return the type name\n ',adt-name)))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defstruct (point (:constructor nil) (:copier nil) (:predicate nil) (:include algebraic-data-type))) (progn (defstruct (rect (:include point) (:constructor rect (%0 %1)) (:conc-name rect) (:copier nil) (:predicate nil) (:print-function (lambda (#:object-141 #:stream-142 #:depth-143) (declare (ignore #:depth-143) (ignorable #:object-141)) (when *print-adt-readably* (write-string \"#.\" #:stream-142)) (write-char #\\LEFT_PARENTHESIS #:stream-142) (prin1 (quote rect) #:stream-142) (write-char #\\Space #:stream-142) (prin1 (rect%0 #:object-141) #:stream-142) (write-char #\\Space #:stream-142) (prin1 (rect%1 #:object-141) #:stream-142) (write-char #\\RIGHT_PARENTHESIS #:stream-142)))) #A((48) base-char . \"A component of ADT CL-ALGEBRAIC-DATA-TYPE::POINT\") (%0 (error \"Unspecified field.\") :type float) (%1 (error \"Unspecified field.\") :type float)) (declaim (sb-ext:freeze-type rect)) (defmethod make-load-form ((#:object-141 rect) &optional #:environment-144) (make-load-form-saving-slots #:object-141 :slot-names (quote (%0 %1)) :environment #:environment-144))) (quote point))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.825} {"instruction": "Generate a defmacro form that transforms code like this:\n(defvar* nil nil)\n\nPattern to recognize: Macro call that should be transformed by DEFVAR*", "input": "(defvar* nil nil)", "output": "(defmacro DEFVAR* ...)", "macroexpand": "(defvar/param defvar nil nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-definition-resolver special-operator special-operator-p)\n\nWhat needs to change: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver special-operator special-operator-p)", "output": "(defmacro define-simple-definition-resolver (class lookup-function &body body)\n (let ((package (gensym \"PACKAGE\")))\n `(define-definition-resolver ,class (,class ,package)\n (when (ignore-errors ,(if body\n `(let ((,(first lookup-function) ,class))\n ,@body)\n `(,lookup-function ,class)))\n (list (make-instance ',class :designator ,class :package ,package))))))", "macroexpand": "(define-definition-resolver special-operator (special-operator #:package131) (when (ignore-errors (special-operator-p special-operator)) (list (make-instance (quote special-operator) :designator special-operator :package #:package131))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(newq nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by NEWQ", "input": "(newq nil nil)", "output": "(defmacro NEWQ ...)", "macroexpand": "(new 'nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when shared `(make-node ,shared))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when shared `(make-node ,shared))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if shared (sb-int:quasiquote (make-node #S(sb-impl::comma :expr shared :kind 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(case nil (progn))\n\nProblem: Macro call that should be transformed by CASE", "input": "(case nil (progn))", "output": "(defmacro CASE ...)", "macroexpand": "(let ((#:nil nil))\n (declare (ignorable #:nil))\n (cond ((eql #:nil 'progn) nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-html-string (:link :rel :stylesheet))\n\nIssue: Macro call that should be transformed by with-html", "input": "(with-html-string (:link :rel :stylesheet))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:link :rel :stylesheet)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> :p (a) (+ a 1))\n\nIssue: Macro call that should be transformed by ->", "input": "(-> :p (a) (+ a 1))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :p (a) (+ a 1))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-yield (loop for line = (read-line stream nil 'eof) until (eq line 'eof) do (yield line)))\n\nIssue: Macro call that should be transformed by with-yield", "input": "(with-yield (loop for line = (read-line stream nil 'eof) until (eq line 'eof) do (yield line)))", "output": "(defmacro with-yield (&body body)\n (let ((point (gensym))\n (current (gensym)))\n `(let (,point ,current)\n (with-call/cc\n\t (labels ((yield (&rest values)\n\t\t (setf ,current values)\n\t\t (let/cc k\n\t\t (setf ,point k))))\n\t ,@body\n\t (setf ,point nil)))\n (gen-lambda ()\n\t (cond ((null ,point)\n\t\t'generator-stop)\n\t (t\n\t\t(let ((current ,current))\n\t\t (funcall ,point nil)\n\t\t ;values-handler: see gen-lambda\n\t\t (apply #'values (funcall values-handler current)))))))))", "macroexpand": "(let (#:g135 #:g136) (with-call/cc (labels ((yield (&rest values) (setf #:g136 values) (let/cc k (setf #:g135 k)))) (loop for line = (read-line stream nil (quote eof)) until (eq line (quote eof)) do (yield line)) (setf #:g135 nil))) (gen-lambda nil (cond ((null #:g135) (quote generator-stop)) (t (let ((current #:g136)) (funcall #:g135 nil) (apply (function values) (funcall values-handler current)))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(of-type symbol 'foo)\n\nIssue: Macro call that should be transformed by of-type", "input": "(of-type symbol 'foo)", "output": "(defmacro of-type (type form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(of-type ,type ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected ',(maybe-unquote type)\n :comparison 'typep\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (of-type symbol (quote foo))) :value-form (quote (quote foo)) :body (lambda nil (quote foo)) :expected (quote symbol) :comparison (quote typep)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ematch0 more (nil nil) ((list* gen sub more) (let ((newsub (correct-pattern sub))) (list* gen newsub (let ((*lexvars* (append (variables newsub) *lexvars*))) (%correct-more-patterns more))))))\n\nIssue: Macro call that should be transformed by ematch0", "input": "(ematch0 more (nil nil) ((list* gen sub more) (let ((newsub (correct-pattern sub))) (list* gen newsub (let ((*lexvars* (append (variables newsub) *lexvars*))) (%correct-more-patterns more))))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 more (nil nil) ((list* gen sub more) (let ((newsub (correct-pattern sub))) (list* gen newsub (let ((*lexvars* (append (variables newsub) *lexvars*))) (%correct-more-patterns more))))) (_ (error \"level0 match error!\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-form-fields (name) form (print (field-value name)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-form", "input": "(with-form-fields (name) form (print (field-value name)))", "output": "(defmacro with-form (form &body body)\n \"Bind *FORM* to FORM and evaluate BODY in that context.\"\n `(call-with-form ,form (lambda () ,@body)))", "macroexpand": "(let ((name (get-field form (quote name)))) (print (field-value name)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error no-version-in-context () (env) \"No supported version found in context:~%~a\" (v-context env))\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error no-version-in-context () (env) \"No supported version found in context:~%~a\" (v-context env))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition no-version-in-context (:error-type varjo-error :prefix \"Varjo\") (env) \"No supported version found in context:~%~a\" (v-context env))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-wcs-math-error-handling ((quot rem) (ftruncate x y)) (check-wcs-math-result) rem)\n\nWhat needs to change: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling ((quot rem) (ftruncate x y)) (check-wcs-math-result) rem)", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g254 x) (#:g255 y) (#:g256 (list #:g254 #:g255))) (declare (ignorable #:g255) (type list #:g256) (dynamic-extent #:g256)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (quot rem) (call-with-wcs-math-error-handler (quote ftruncate) #:g256) (flet ((check-wcs-math-result (&optional (ret quot) (arg-list #:g256)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result) rem))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(keep-bops nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by KEEP-BOPS", "input": "(keep-bops nil :key nil)", "output": "(defmacro KEEP-BOPS ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn\n (init-binfix)\n (unless nil\n (setq *binfix*\n (delete nil\n (mapcar\n (lambda (bs)\n (setq bs\n (delete-if\n (lambda (b)\n (unless (member (car b) '(nil :key nil))\n (remprop (car b) 'properties)\n t))\n bs)))\n *binfix*)))\n (assign-properties))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n($ \"value-1\" 610)\n\nWhat needs to change: Macro call that should be transformed by $", "input": "($ \"value-1\" 610)", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(kv \"value-1\" 610)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(cond-<>)\n\nPattern to recognize: Macro call that should be transformed by COND-<>", "input": "(cond-<>)", "output": "(defmacro COND-<> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n($> \"l\" -900)\n\nPattern to recognize: Macro call that should be transformed by $>", "input": "($> \"l\" -900)", "output": "(defmacro $> (&rest args)\n `($op \"$gt\" ,@args))", "macroexpand": "($op \"$gt\" \"l\" -900)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(without-dependency-capture)\n\nProblem: Macro call that should be transformed by WITHOUT-DEPENDENCY-CAPTURE", "input": "(without-dependency-capture)", "output": "(defmacro WITHOUT-DEPENDENCY-CAPTURE ...)", "macroexpand": "(let ((%dependent% nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(do+ (options :atomic-updates nil) (for k (in '(a b c d e))) (for x (across #(1 2 3 4) :index index)) (returning (list x k :index index)))\n\nPattern to recognize: Macro call that should be transformed by do+", "input": "(do+ (options :atomic-updates nil) (for k (in '(a b c d e))) (for x (across #(1 2 3 4) :index index)) (returning (list x k :index index)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (options :atomic-updates nil) (for k (in (quote (a b c d e)))) (for x (across #(1 2 3 4) :index index)) (returning (list x k :index index)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-readtime-wrapper-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-READTIME-WRAPPER-SYNTAX", "input": "(enable-readtime-wrapper-syntax)", "output": "(defmacro ENABLE-READTIME-WRAPPER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-readtime-wrapper-syntax-in-readtable #\\LEFT_CURLY_BRACKET\n #\\RIGHT_CURLY_BRACKET)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defhandler sb-int:named-lambda (named-lambda name lambda-list &rest body) `(list* ',named-lambda ,(apply 'dump-fbinding name lambda-list body)))\n\nIssue: Macro call that should be transformed by defhandler", "input": "(defhandler sb-int:named-lambda (named-lambda name lambda-list &rest body) `(list* ',named-lambda ,(apply 'dump-fbinding name lambda-list body)))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-named-lambda (named-lambda name lambda-list &rest body) (sb-int:quasiquote (list* (quote #S(sb-impl::comma :expr named-lambda :kind 0)) #S(sb-impl::comma :expr (apply (quote dump-fbinding) name lambda-list body) :kind 0)))) (setf (gethash (quote sb-int:named-lambda) *form-handler*) (quote hander-named-lambda)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is-true nil)\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is-true nil)", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(if nil (add-result (quote test-passed) :test-expr (quote nil)) (process-failure (quote nil) \"~S did not return a true value\" (quote nil)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(member (first tree) stop-on :test #'eq)\n\nIssue: Macro call that should be transformed by m", "input": "(member (first tree) stop-on :test #'eq)", "output": "(defmacro m (form &environment *env*)\n (e form))", "macroexpand": "(member (first tree) stop-on :test (function eq))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"08006\" connection-failure)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"08006\" connection-failure)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition connection-failure (database-error) nil) (setf (gethash \"08006\" *error-table*) (quote connection-failure)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym nil (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFSYNONYM", "input": "(defsynonym nil (progn))", "output": "(defmacro DEFSYNONYM ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (get 'nil 'iterate::synonym) '(progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(assert-values (\"assert fresh initialization\") (foo 'nothing) (foo+1 'nothing) (bar 'nothing) (bar-1 'nothing))\n\nProblem: Macro call that should be transformed by assert-values", "input": "(assert-values (\"assert fresh initialization\") (foo 'nothing) (foo+1 'nothing) (bar 'nothing) (bar-1 'nothing))", "output": "(defmacro assert-values ((desc) &body objects-and-values)\n `(progn\n (trc ,desc)\n ,@(loop for (obj val) in objects-and-values\n\t collect `(assert (eql (value ,obj) ,val)))))", "macroexpand": "(progn (trc \"assert fresh initialization\") (assert (eql (value foo) (quote nothing))) (assert (eql (value foo+1) (quote nothing))) (assert (eql (value bar) (quote nothing))) (assert (eql (value bar-1) (quote nothing))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(iterate:display-iterate-clauses)\n\nWhat needs to change: Macro call that should be transformed by iter", "input": "(iterate:display-iterate-clauses)", "output": "(defmacro iter (&body body &environment env)\n \"Jonathan Amsterdam's powerful and extensible iteration facility,\nproviding multiple accumulation, generators, memory of previous\niterations, over 50 clauses to start with and a Lisp-like syntax.\nEvaluate (iterate:display-iterate-clauses) for an overview of clauses\"\n (let* ((*env* env)\n\t (*result-var* (genvar 'result))\n\t (*type-alist* nil)\n\t (*declare-variables* *always-declare-variables*)\n\t (*bindings* nil)\n\t (*internal-variables* nil)\n\t (*previous-vars-alist* nil)\n\t (*declarations* nil)\n\t (*loop-body-wrappers* nil)\n\t (*accum-var-alist* nil)\n\t (*shared-bindings-alist* nil)\n\t (*top-level?* t)\n\t (*binding-context?* nil)\n\t (*temps* nil)\n\t (*temps-in-use* nil)\n\t (*driver-info-alist* nil)\n\t (*loop-name* (if (symbolp (car body))\n\t\t\t (car body)\n\t\t\t (gensym \"ITERATE\")))\n\t (*block-name* (if (symbolp (car body))\n\t\t\t (pop body)\n\t\t\t nil))\n\t (*loop-top* (symbol-append 'loop-top- *block-name*))\n\t (*loop-step* (symbol-append 'loop-step- *block-name*))\n\t (*loop-end* (symbol-append 'loop-end- *block-name*))\n\t (*loop-step-used?* nil)\n\t (*loop-end-used?* nil))\n (process-top-level-decls body)\n (multiple-value-bind (body decls init-code steppers final-code final-prot)\n\t(walk-list body)\n (multiple-value-bind (init step)\n\t (insert-previous-code)\n\t(augment init-code init)\n\t(augment steppers step))\n (prepend (default-driver-code) body)\n (let* ((it-bod `(block ,*loop-name*\n\t\t\t(tagbody\n\t\t\t (progn ,.init-code)\n\t\t\t ,*loop-top*\n\t\t\t (progn ,.body)\n\t\t\t ,.(if *loop-step-used?* (list *loop-step*))\n\t\t\t (progn ,.steppers)\n\t\t\t (go ,*loop-top*)\n\t\t\t ,.(if *loop-end-used?* (list *loop-end*))\n\t\t\t (progn ,.final-code))\n\t\t\t,(if (member *result-var* *bindings* :key #'car)\n\t\t\t *result-var*\n\t\t\t nil)))\n\t (it-bod (if (eql *block-name* nil)\n\t\t\t `(block nil ,it-bod)\n\t\t\t it-bod)))\n\t(wrap-form *loop-body-wrappers*\n\t\t `(let* ,(nreverse *bindings*)\n\t\t ,.(if *declarations*\n\t\t\t `((declare .,*declarations*)))\n\t\t ,.decls\n\t\t ,(if final-prot\n\t\t\t `(unwind-protect ,it-bod .,final-prot)\n\t\t\t it-bod)))))))", "macroexpand": "(display-iterate-clauses)", "category": "anaphoric", "technique": "tagbody-go,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.85} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-class some-class (some super classes) ((slot1 :unbound)) (:accessor-name-package (find-package :nclasses/test.dummy)))\n\nWhat needs to change: Macro call that should be transformed by define-class", "input": "(define-class some-class (some super classes) ((slot1 :unbound)) (:accessor-name-package (find-package :nclasses/test.dummy)))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass some-class (some super classes) ((slot1 :accessor slot1 :initarg :slot1))) (unless (fboundp (quote some-class-p)) (define-generic some-class-p (object) #A((75) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `some-class'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote some-class)))) (setf (documentation (quote slot1) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\")) (ignore-errors (setf (documentation (fdefinition (quote slot1)) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf slot1))) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot SLOT1.\"))) (find-class (quote some-class) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-function aref 1 (new-val array &rest idx) (let ((new-arr (alexandria:copy-array array))) (setf (apply #'aref new-arr idx) new-val) new-arr))\n\nPattern to recognize: Macro call that should be transformed by define-modf-function", "input": "(define-modf-function aref 1 (new-val array &rest idx) (let ((new-arr (alexandria:copy-array array))) (setf (apply #'aref new-arr idx) new-val) new-arr))", "output": "(defmacro define-modf-function (name nth-arg (new-val &rest args) &body body)\n \"Define a new modf function. It inverts NAME forms by modifying the NTH-ARG\nterm of the arguments of the place form in the MODF macro.\"\n ;; Side effect in a macro, I know. How can you do this via EVAL-WHEN if I\n ;; want it to run even if not a toplevel macro?\n (setf (gethash name *modf-nth-arg*)\n nth-arg)\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-nth-arg*)\n ,nth-arg))\n (defun ,(intern (modf-name name) :modf) (,new-val ,@args)\n ,@body)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote aref) *modf-nth-arg*) 1)) (defun |BUILDER:COMMON-LISP:AREF| (new-val array &rest idx) (let ((new-arr (alexandria:copy-array array))) (setf (apply (function aref) new-arr idx) new-val) new-arr)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-packages-unlocked nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by WITH-PACKAGES-UNLOCKED", "input": "(with-packages-unlocked nil\n :key\n nil)", "output": "(defmacro WITH-PACKAGES-UNLOCKED ...)", "macroexpand": "(let ((#:|packages123| (locked-packages 'nil)))\n (unlock-packages #:|packages123|)\n (unwind-protect :key nil (lock-packages #:|packages123|)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause across (vector &rest args &key index start end by) \"Synonym for in-vector.\" (declare (ignore index start end by)) `(in-vector ,vector ,@args))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause across (vector &rest args &key index start end by) \"Synonym for in-vector.\" (declare (ignore index start end by)) `(in-vector ,vector ,@args))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro across (vector &rest args &key index start end by) \"Synonym for in-vector.\" (declare (ignore index start end by)) (sb-int:quasiquote (in-vector #S(sb-impl::comma :expr vector :kind 0) #S(sb-impl::comma :expr args :kind 2)))) (pushnew (quote across) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-value-binding ranging ((var (if ascending (- from by) (+ from by))) from to &key (by 1) &aux (ascending (< from to))) (declare (type real var from to by) (type boolean ascending)) (declare (ignore from)) `(cond (,ascending (incf ,var ,by) (when (< ,to ,var) (end-for))) (T (decf ,var ,by) (when (< ,var ,to) (end-for)))))\n\nWhat needs to change: Macro call that should be transformed by define-value-binding", "input": "(define-value-binding ranging ((var (if ascending (- from by) (+ from by))) from to &key (by 1) &aux (ascending (< from to))) (declare (type real var from to by) (type boolean ascending)) (declare (ignore from)) `(cond (,ascending (incf ,var ,by) (when (< ,to ,var) (end-for))) (T (decf ,var ,by) (when (< ,var ,to) (end-for)))))", "output": "(defmacro define-value-binding (name (var &rest args) &body body)\n (let ((vars (lambda-fiddle:extract-lambda-vars (lambda-fiddle:remove-aux-part args))))\n (emit-binding-definition name var args body :extra-vars vars)))", "macroexpand": "(define-direct-binding ranging (var from to &key (by 1)) (let ((#:ascending171 (gensym #A((9) base-char . \"ASCENDING\"))) (#:from168 (gensym #A((4) base-char . \"FROM\"))) (#:to169 (gensym #A((2) base-char . \"TO\"))) (#:by170 (gensym #A((2) base-char . \"BY\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:from168 from) (list #:to169 to) (list #:by170 by) (list #:ascending171 (list (quote <) #:from168 #:to169)) (loop for #:var167 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var167 (list (quote if) #:ascending171 (list (quote -) #:from168 #:by170) (list (quote +) #:from168 #:by170))))) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:ascending171 :kind 0) #S(sb-impl::comma :expr #:from168 :kind 0) #S(sb-impl::comma :expr #:to169 :kind 0) #S(sb-impl::comma :expr #:by170 :kind 0))) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote real) :kind 0) #S(sb-impl::comma :expr var :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote real) :kind 0) #S(sb-impl::comma :expr #:from168 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote real) :kind 0) #S(sb-impl::comma :expr #:to169 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote real) :kind 0) #S(sb-impl::comma :expr #:by170 :kind 0)))) :kind 0) #S(sb-impl::comma :expr (sb-int:quasiquote (declare (type #S(sb-impl::comma :expr (quote boolean) :kind 0) #S(sb-impl::comma :expr #:ascending171 :kind 0)))) :kind 0)) #S(sb-impl::comma :expr nil :kind 0))) (let ((ascending #:ascending171) (from #:from168) (to #:to169) (by #:by170)) (declare (ignorable ascending from to by)) (declare (ignore from)) (sb-int:quasiquote (cond (#S(sb-impl::comma :expr ascending :kind 0) (incf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr by :kind 0)) (when (< #S(sb-impl::comma :expr to :kind 0) #S(sb-impl::comma :expr var :kind 0)) (end-for))) (t (decf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr by :kind 0)) (when (< #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr to :kind 0)) (end-for)))))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(as->* 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by AS->*", "input": "(as->* 'some-name)", "output": "(defmacro AS->* ...)", "macroexpand": "(as-> 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-html-string (:li (:div :class \"status col-xs-2 col-md-1\" (:span :class \"text-success\" (:a :href \"https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200\" 200)))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-html", "input": "(with-html-string (:li (:div :class \"status col-xs-2 col-md-1\" (:span :class \"text-success\" (:a :href \"https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200\" 200)))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:li (:div :class \"status col-xs-2 col-md-1\" (:span :class \"text-success\" (:a :href \"https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200\" 200))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(iterate\n 'some-name)\n\nPattern to recognize: Macro call that should be transformed by ITERATE", "input": "(iterate\n 'some-name)", "output": "(defmacro ITERATE ...)", "macroexpand": "(iter\n 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-error if-form-type-mismatch () (test-form then-form then-type else-form else-type) \"The result if ~a is true is ~a which has type ~a however the false case returns ~a which has type ~a This is incompatible\" test-form then-form then-type else-form else-type)\n\nPattern to recognize: Macro call that should be transformed by define-error", "input": "(define-error if-form-type-mismatch () (test-form then-form then-type else-form else-type) \"The result if ~a is true is ~a which has type ~a however the false case returns ~a which has type ~a This is incompatible\" test-form then-form then-type else-form else-type)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition if-form-type-mismatch (:error-type varjo-error :prefix \"Varjo\") (test-form then-form then-type else-form else-type) \"The result if ~a is true is ~a which has type ~a however the false case returns ~a which has type ~a This is incompatible\" test-form then-form then-type else-form else-type)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-class foo-type-infer () ((name \"foo\") (nickname street-name) (age 1) (height 2.0) (width 2 :type number) (lisper t) (nil-is-not-bool nil) (empty-list '()) (nonempty-list '(1 2 3)) (mark :foo) (binding :unbound) (sym 'sims) (fun #'list) (composite (error \"Should not eval, type should not be inferred\"))) (:automatic-types-p t))\n\nWhat needs to change: Macro call that should be transformed by define-class", "input": "(define-class foo-type-infer () ((name \"foo\") (nickname street-name) (age 1) (height 2.0) (width 2 :type number) (lisper t) (nil-is-not-bool nil) (empty-list '()) (nonempty-list '(1 2 3)) (mark :foo) (binding :unbound) (sym 'sims) (fun #'list) (composite (error \"Should not eval, type should not be inferred\"))) (:automatic-types-p t))", "output": "(defmacro define-class (name supers slots &rest options)\n \"Convenience wrapper of `defclass'.\n\nIt automates a lot of boilerplate (like exporting all the accessors of a class)\nplus adds some new features.\n\n\n\nSlot options:\n\n- The initform can be specified as the second value.\n\n- `:accessor', `:reader' and `:writer' can be set to either a name, NIL or T.\n If NIL, the method is not generated.\n If T, the method is generated using the `:accessor-name-transformer' class option value.\n\n- The `:export' option allows to control the slot-name export on a per-slot basis.\n\n\n\nNew class options (defaults are NIL unless specified):\n\n- `:slot-definition-transformer' (default: `default-slot-definition-transformer').\n A function that takes a SLOT-DEFINITION and returns a new one.\n\n- `:accessor-name-package': The package of the generated accessors. See\n `:accessor-name-transformer'. Some special values are accepted:\n - `:slot-name': The package of the slot-name.\n - `:default': The current package.\n\n- `:accessor-name-transformer' (default `default-accessor-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol). Other transformer: `dwim-accessor-name-transformer'.\n\n- `:automatic-accessors-p': Whether to generate accessor names automatically for\n all slots.\n\n As a special case, the accessor is not generated if all following conditions are met:\n - `:accessor-name-package' is `:slot-name',\n - slot name package is different from current package,\n - if the `:accessor' slot option is not provided,\n\n\n- `:initarg-name-transformer' (default: `default-initarg-name-transformer'.)\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the accessor\n name (a symbol.\n\n- `:automatic-initargs-p' (default: T): Whether to generate accessor names\n automatically for all slots.\n\n- `:predicate-name-transformer' (default: `default-predicate-name-transformer').\n\n A function of (SLOT-NAME SLOT-DEFINITION) arguments that returns the predicate\n name (a symbol).\n\n- `:automatic-predicates-p' (default: T): Whether to generate a predicate\n for the class.\n\n- `:type-inference' (default: `default-type-inference').\n\n Function that returns the type of a slot definition (with an initform). It\n takes 3 arguments:\n\n - The initform.\n - The slot name.\n - The rest of the slot definition.\n\n- `:automatic-types-p': Whether to generate the type automatically for all\n slots. The type can still be specified manually with the `:type' slot option.\n\n- Self-explanatory export options (all NIL by default):\n - `:export-class-name-p'\n - `:export-accessor-names-p'\n - `:export-slot-names-p'\n - `:export-predicate-name'\"\n (build-defclass-like-expansion\n name supers slots options\n (lambda (processed-slots clean-options)\n `(defclass ,name ,supers\n ,processed-slots\n ,@clean-options))))", "macroexpand": "(progn (defclass foo-type-infer nil ((name :initform \"foo\" :accessor name :initarg :name :type string) (nickname :initform street-name :accessor nickname :initarg :nickname) (age :initform 1 :accessor age :initarg :age :type integer) (height :initform 2.0 :accessor height :initarg :height :type number) (width :initform 2 :accessor width :initarg :width :type number) (lisper :initform t :accessor lisper :initarg :lisper :type boolean) (nil-is-not-bool :initform nil :accessor nil-is-not-bool :initarg :nil-is-not-bool) (empty-list :initform (quote nil) :accessor empty-list :initarg :empty-list :type list) (nonempty-list :initform (quote (1 2 3)) :accessor nonempty-list :initarg :nonempty-list :type list) (mark :initform :foo :accessor mark :initarg :mark :type keyword) (binding :accessor binding :initarg :binding) (sym :initform (quote sims) :accessor sym :initarg :sym :type symbol) (fun :initform (function list) :accessor fun :initarg :fun :type function) (composite :initform (error \"Should not eval, type should not be inferred\") :accessor composite :initarg :composite))) (unless (fboundp (quote foo-type-infer-p)) (define-generic foo-type-infer-p (object) #A((79) base-char . \"Auto-generated predicate for whether OBJECT is an instance of `foo-type-infer'.\") (declare (sb-ext:muffle-conditions style-warning)) (typep object (quote foo-type-infer)))) (setf (documentation (quote composite) (quote function)) #A((52) base-char . \"Auto-generated accessor function for slot COMPOSITE.\")) (ignore-errors (setf (documentation (fdefinition (quote composite)) (quote function)) #A((52) base-char . \"Auto-generated accessor function for slot COMPOSITE.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf composite))) (quote function)) #A((52) base-char . \"Auto-generated accessor function for slot COMPOSITE.\"))) (setf (documentation (quote fun) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot FUN.\")) (ignore-errors (setf (documentation (fdefinition (quote fun)) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot FUN.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf fun))) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot FUN.\"))) (setf (documentation (quote sym) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot SYM.\")) (ignore-errors (setf (documentation (fdefinition (quote sym)) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot SYM.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf sym))) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot SYM.\"))) (setf (documentation (quote binding) (quote function)) #A((50) base-char . \"Auto-generated accessor function for slot BINDING.\")) (ignore-errors (setf (documentation (fdefinition (quote binding)) (quote function)) #A((50) base-char . \"Auto-generated accessor function for slot BINDING.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf binding))) (quote function)) #A((50) base-char . \"Auto-generated accessor function for slot BINDING.\"))) (setf (documentation (quote mark) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot MARK.\")) (ignore-errors (setf (documentation (fdefinition (quote mark)) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot MARK.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf mark))) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot MARK.\"))) (setf (documentation (quote nonempty-list) (quote function)) #A((56) base-char . \"Auto-generated accessor function for slot NONEMPTY-LIST.\")) (ignore-errors (setf (documentation (fdefinition (quote nonempty-list)) (quote function)) #A((56) base-char . \"Auto-generated accessor function for slot NONEMPTY-LIST.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf nonempty-list))) (quote function)) #A((56) base-char . \"Auto-generated accessor function for slot NONEMPTY-LIST.\"))) (setf (documentation (quote empty-list) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot EMPTY-LIST.\")) (ignore-errors (setf (documentation (fdefinition (quote empty-list)) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot EMPTY-LIST.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf empty-list))) (quote function)) #A((53) base-char . \"Auto-generated accessor function for slot EMPTY-LIST.\"))) (setf (documentation (quote nil-is-not-bool) (quote function)) #A((58) base-char . \"Auto-generated accessor function for slot NIL-IS-NOT-BOOL.\")) (ignore-errors (setf (documentation (fdefinition (quote nil-is-not-bool)) (quote function)) #A((58) base-char . \"Auto-generated accessor function for slot NIL-IS-NOT-BOOL.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf nil-is-not-bool))) (quote function)) #A((58) base-char . \"Auto-generated accessor function for slot NIL-IS-NOT-BOOL.\"))) (setf (documentation (quote lisper) (quote function)) #A((49) base-char . \"Auto-generated accessor function for slot LISPER.\")) (ignore-errors (setf (documentation (fdefinition (quote lisper)) (quote function)) #A((49) base-char . \"Auto-generated accessor function for slot LISPER.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf lisper))) (quote function)) #A((49) base-char . \"Auto-generated accessor function for slot LISPER.\"))) (setf (documentation (quote width) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot WIDTH.\")) (ignore-errors (setf (documentation (fdefinition (quote width)) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot WIDTH.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf width))) (quote function)) #A((48) base-char . \"Auto-generated accessor function for slot WIDTH.\"))) (setf (documentation (quote height) (quote function)) #A((49) base-char . \"Auto-generated accessor function for slot HEIGHT.\")) (ignore-errors (setf (documentation (fdefinition (quote height)) (quote function)) #A((49) base-char . \"Auto-generated accessor function for slot HEIGHT.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf height))) (quote function)) #A((49) base-char . \"Auto-generated accessor function for slot HEIGHT.\"))) (setf (documentation (quote age) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\")) (ignore-errors (setf (documentation (fdefinition (quote age)) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf age))) (quote function)) #A((46) base-char . \"Auto-generated accessor function for slot AGE.\"))) (setf (documentation (quote nickname) (quote function)) #A((51) base-char . \"Auto-generated accessor function for slot NICKNAME.\")) (ignore-errors (setf (documentation (fdefinition (quote nickname)) (quote function)) #A((51) base-char . \"Auto-generated accessor function for slot NICKNAME.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf nickname))) (quote function)) #A((51) base-char . \"Auto-generated accessor function for slot NICKNAME.\"))) (setf (documentation (quote name) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\")) (ignore-errors (setf (documentation (fdefinition (quote name)) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\"))) (ignore-errors (setf (documentation (fdefinition (quote (setf name))) (quote function)) #A((47) base-char . \"Auto-generated accessor function for slot NAME.\"))) (find-class (quote foo-type-infer) nil))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-declaration nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFINE-DECLARATION", "input": "(define-declaration nil\n nil)", "output": "(defmacro DEFINE-DECLARATION ...)", "macroexpand": "(sb-cltl2:define-declaration nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-unique-js-names 'some-name)\n\nIssue: Macro call that should be transformed by WITH-UNIQUE-JS-NAMES", "input": "(with-unique-js-names 'some-name)", "output": "(defmacro WITH-UNIQUE-JS-NAMES ...)", "macroexpand": "(with-ps-gensyms 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with* nil\n (progn))\n\nProblem: Macro call that should be transformed by WITH*", "input": "(with* nil\n (progn))", "output": "(defmacro WITH* ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(dlet nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DLET", "input": "(dlet nil\n (progn))", "output": "(defmacro DLET ...)", "macroexpand": "(dynamic-let nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-html-string (:html (:head) (:body (:a \"hai\"))))\n\nWhat needs to change: Macro call that should be transformed by with-html", "input": "(with-html-string (:html (:head) (:body (:a \"hai\"))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:html (:head) (:body (:a \"hai\")))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-attributes nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by WITH-ATTRIBUTES", "input": "(with-attributes nil\n (progn))", "output": "(defmacro WITH-ATTRIBUTES ...)", "macroexpand": "(let ((#:unit161 (progn)))\n (symbol-macrolet ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(make-name-transformer \\\"FOO-\\\" name \\\"-BAR\\\") Use the slot name directly: :accessor-name-transformer (make-name-transformer name)\" `(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol ,@(mapcar (lambda (el) (if (and (symbolp el) (string= (symbol-name el) \"NAME\")) 'name el)) elements))))\n\nProblem: Macro call that should be transformed by make-name-transformer", "input": "(make-name-transformer \\\"FOO-\\\" name \\\"-BAR\\\") Use the slot name directly: :accessor-name-transformer (make-name-transformer name)\" `(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol ,@(mapcar (lambda (el) (if (and (symbolp el) (string= (symbol-name el) \"NAME\")) 'name el)) elements))))", "output": "(defmacro make-name-transformer (&rest elements)\n \"Return an accessor name transformer.\nThe unquoted `name' symbol argument is substituted for the slot name.\nClass option examples:\n\n :accessor-name-transformer (make-name-transformer \\\"FOO-\\\" name \\\"-BAR\\\")\n\nUse the slot name directly:\n\n :accessor-name-transformer (make-name-transformer name)\"\n `(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol ,@(mapcar (lambda (el)\n (if (and (symbolp el)\n (string= (symbol-name el) \"NAME\"))\n 'name\n el))\n elements))))", "macroexpand": "(lambda (name definition) (declare (ignorable definition)) (concatenate-symbol |\"FOO-\"| name |\"-BAR\"|))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(aif 1 (sif it it))\n\nPattern to recognize: Macro call that should be transformed by aif", "input": "(aif 1 (sif it it))", "output": "(defmacro aif (test then &optional else)\n \"Like IF, except binds the result of the test to IT (via LET) for\nthe scope of the then and else expressions.\" \n `(anaphoric if ,test ,then ,else))", "macroexpand": "(anaphoric if 1 (sif it it) nil)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-dispatch dispatch-for-no-result (args specific-hooks) (mapc (lambda (f) (apply f args)) specific-hooks))\n\nIssue: Macro call that should be transformed by define-dispatch", "input": "(define-dispatch dispatch-for-no-result (args specific-hooks) (mapc (lambda (f) (apply f args)) specific-hooks))", "output": "(defmacro define-dispatch (name lambda-list &body body)\n \"the lambda list should accept two arguments:\nthe list of arguments given by the current method call.\nthe specific hooks (as named or unamed functions) for the qualified method (that we will be dispatching from).\n\nyou should then use the arguments to dispatch the specific hooks as you wish in the body.\nif the body returns a result, by default the method will also return that result, this can be overriden with finalize-dispatch-method.\n\nSee finalize-dispatch-method\nSee dispatch\"\n `(let ((new-dispatch (make-dispatcher (lambda ,lambda-list ,@body))))\n (setf (gethash ',name *dispatch-table*)\n new-dispatch)))", "macroexpand": "(let ((new-dispatch (make-dispatcher (lambda (args specific-hooks) (mapc (lambda (f) (apply f args)) specific-hooks))))) (setf (gethash (quote dispatch-for-no-result) *dispatch-table*) new-dispatch))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(true 4)\n\nIssue: Macro call that should be transformed by true", "input": "(true 4)", "output": "(defmacro true (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(true ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected 'T\n :comparison 'geq\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (true 4)) :value-form (quote 4) :body (lambda nil 4) :expected (quote t) :comparison (quote geq)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Generate a defmacro form that transforms code like this:\n(finalize-savepoint :rolled-back (call-next-method conn identifier))\n\nPattern to recognize: Macro call that should be transformed by finalize-savepoint", "input": "(finalize-savepoint :rolled-back (call-next-method conn identifier))", "output": "(defmacro finalize-savepoint (new-state &body body)\n `(let ((state (get-transaction-state conn)))\n (unless (typep state 'savepoint-state)\n (error \"Please, use release-savepoint inside of with-savepoint block.\"))\n (unless (equal (get-identifier state)\n identifier)\n ;; TODO: probably optional `identifier' parameter\n ;; is excessive and should be removed?\n (error \"Identifier mismatch\"))\n\n (multiple-value-prog1\n (progn ,@body)\n (setf (get-state state)\n ,new-state))))", "macroexpand": "(let ((state (get-transaction-state conn))) (unless (typep state (quote savepoint-state)) (error \"Please, use release-savepoint inside of with-savepoint block.\")) (unless (equal (get-identifier state) identifier) (error \"Identifier mismatch\")) (multiple-value-prog1 (progn (call-next-method conn identifier)) (setf (get-state state) :rolled-back)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(builder (when t `(:sample :out ,(lambda (out) (format t \"Got: ~a\" out)))) *app*)\n\nProblem: Macro call that should be transformed by builder", "input": "(builder (when t `(:sample :out ,(lambda (out) (format t \"Got: ~a\" out)))) *app*)", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (let ((#:res183 (when t (sb-int:quasiquote (:sample :out #S(sb-impl::comma :expr (lambda (out) (format t \"Got: ~a\" out)) :kind 0)))))) (typecase #:res183 (keyword (find-middleware #:res183)) (cons (if (keywordp (car #:res183)) (let ((#:res-mw182 (find-middleware (car #:res183)))) (lambda (#:app181) (apply #:res-mw182 #:app181 (cdr #:res183)))) #:res183)) (standard-object (lambda (#:app181) (funcall (intern (string :wrap) :clack.middleware) #:res183 #:app181))) (otherwise #:res183))))) :initial-value (to-app *app*) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error unknown-variable-type () (name) \"Could not establish the type of the variable: ~s\" name)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error unknown-variable-type () (name) \"Could not establish the type of the variable: ~s\" name)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition unknown-variable-type (:error-type varjo-error :prefix \"Varjo\") (name) \"Could not establish the type of the variable: ~s\" name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(aggregate-scope-progv *array-scope-variables* (aggregate-scope-progv *aggregate-scope-variables* (funcall *beginning-of-array-handler*) (multiple-value-bind (type token) (peek-json-token stream) (if (and (eql type :punct) (char= token #\\])) (progn (read-json-token stream) (return-from decode-json-array (funcall *end-of-array-handler*))) (funcall *array-member-handler* (funcall *internal-decoder* stream)))) (loop (multiple-value-bind (type token) (read-json-token stream) (if (eql type :punct) (case token (#\\] (return-from decode-json-array (funcall *end-of-array-handler*))) (#\\, (setq token nil)))) (if token (json-syntax-error stream \"Token out of place in Array on JSON input: `~A'\" token))) (funcall *array-member-handler* (funcall *internal-decoder* stream)))))\n\nProblem: Macro call that should be transformed by aggregate-scope-progv", "input": "(aggregate-scope-progv *array-scope-variables* (aggregate-scope-progv *aggregate-scope-variables* (funcall *beginning-of-array-handler*) (multiple-value-bind (type token) (peek-json-token stream) (if (and (eql type :punct) (char= token #\\])) (progn (read-json-token stream) (return-from decode-json-array (funcall *end-of-array-handler*))) (funcall *array-member-handler* (funcall *internal-decoder* stream)))) (loop (multiple-value-bind (type token) (read-json-token stream) (if (eql type :punct) (case token (#\\] (return-from decode-json-array (funcall *end-of-array-handler*))) (#\\, (setq token nil)))) (if token (json-syntax-error stream \"Token out of place in Array on JSON input: `~A'\" token))) (funcall *array-member-handler* (funcall *internal-decoder* stream)))))", "output": "(defmacro aggregate-scope-progv (variables &body body)\n \"Establish a dynamic environment where all VARIABLES are freshly\nbound (to their current values), and execute BODY in it, returning the\nresult.\"\n `(progv ,variables (mapcar #'symbol-value ,variables)\n ,@body))", "macroexpand": "(progv *array-scope-variables* (mapcar (function symbol-value) *array-scope-variables*) (aggregate-scope-progv *aggregate-scope-variables* (funcall *beginning-of-array-handler*) (multiple-value-bind (type token) (peek-json-token stream) (if (and (eql type :punct) (char= token #\\RIGHT_SQUARE_BRACKET)) (progn (read-json-token stream) (return-from decode-json-array (funcall *end-of-array-handler*))) (funcall *array-member-handler* (funcall *internal-decoder* stream)))) (loop (multiple-value-bind (type token) (read-json-token stream) (if (eql type :punct) (case token (#\\RIGHT_SQUARE_BRACKET (return-from decode-json-array (funcall *end-of-array-handler*))) (#\\COMMA (setq token nil)))) (if token (json-syntax-error stream \"Token out of place in Array on JSON input: `~A'\" token))) (funcall *array-member-handler* (funcall *internal-decoder* stream)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(builder (when t :sample) *app*)\n\nIssue: Macro call that should be transformed by builder", "input": "(builder (when t :sample) *app*)", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (let ((#:res180 (when t :sample))) (typecase #:res180 (keyword (find-middleware #:res180)) (cons (if (keywordp (car #:res180)) (let ((#:res-mw179 (find-middleware (car #:res180)))) (lambda (#:app178) (apply #:res-mw179 #:app178 (cdr #:res180)))) #:res180)) (standard-object (lambda (#:app178) (funcall (intern (string :wrap) :clack.middleware) #:res180 #:app178))) (otherwise #:res180))))) :initial-value (to-app *app*) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(send nil nil)\n\nIssue: Macro call that should be transformed by SEND", "input": "(send nil nil)", "output": "(defmacro SEND ...)", "macroexpand": "(send (slot-value nil 'nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defrule nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEFRULE", "input": "(defrule nil\n nil)", "output": "(defmacro DEFRULE ...)", "macroexpand": "(setf (gethash #A((3) base-char . \"NIL\") cl-rules.core::*rules*)\n '#S(cl-rules.core::rule\n :name #A((3) base-char . \"NIL\")\n :conditions (#S(cl-rules.core::condn\n :name #A((3) base-char . \"NIL\")\n :args nil))\n :actions nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define TMP_MAX 1024)\n\nProblem: Macro call that should be transformed by define", "input": "(define TMP_MAX 1024)", "output": "(defmacro define (name value &rest docstring)\n \"Like a #define but also visible to Lisp code.\"\n `(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defvar ,(pp-defines *package*) (make-hash-table))\n (setf (gethash ',name ,(pp-defines *package*)) ,(prin1-to-string value)))\n (defparameter ,name ,value ,@docstring)))", "macroexpand": "(progn (eval-when (:compile-toplevel :load-toplevel :execute) (defvar *preprocessor-defines* (make-hash-table)) (setf (gethash (quote tmp_max) *preprocessor-defines*) #A((4) base-char . \"1024\"))) (defparameter tmp_max 1024))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (= result 0))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (= result 0))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e173 result) (#:a174 0)) (if (progn (= #:e173 #:a174)) (add-result (quote test-passed) :test-expr (quote (= result 0))) (process-failure (quote (= result 0)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote 0) #:a174 (quote =) #:e173)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-definition-resolver transform (designator package) (let ((fun-info (when (symbolp designator) (sb-int:info :function :info designator)))) (when fun-info (loop for transform in (sb-c::fun-info-transforms fun-info) collect (make-instance 'transform :designator designator :package package :transform transform)))))\n\nProblem: Macro call that should be transformed by define-definition-resolver", "input": "(define-definition-resolver transform (designator package) (let ((fun-info (when (symbolp designator) (sb-int:info :function :info designator)))) (when fun-info (loop for transform in (sb-c::fun-info-transforms fun-info) collect (make-instance 'transform :designator designator :package package :transform transform)))))", "output": "(defmacro define-definition-resolver (name args &body body)\n `(progn (setf (definition-resolver ',name)\n (lambda ,args ,@body))\n ',name))", "macroexpand": "(progn (setf (definition-resolver (quote transform)) (lambda (designator package) (let ((fun-info (when (symbolp designator) (sb-int:info :function :info designator)))) (when fun-info (loop for transform in (sb-c::fun-info-transforms fun-info) collect (make-instance (quote transform) :designator designator :package package :transform transform)))))) (quote transform))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect nil nil)\n\nWhat needs to change: Macro call that should be transformed by COLLECT", "input": "(collect nil nil)", "output": "(defmacro COLLECT ...)", "macroexpand": "(common-lisp:let* ((#:generator-591 (generator nil))\n #:items-584\n #:seq-585\n (#:limit-586\n (common-lisp:multiple-value-bind (x y)\n (decode-seq-type (list 'quote nil))\n (declare (ignore x))\n y))\n (#:lst-587 nil))\n (declare (type generator #:generator-591)\n (type (null-or nonnegative-integer) #:limit-586)\n (type list #:lst-587))\n (tagbody\n #:ll-592\n (setq #:items-584 (next-in #:generator-591 (go end)))\n (setq #:lst-587 (cons #:items-584 #:lst-587))\n (go #:ll-592)\n end)\n (common-lisp:let ((num (length #:lst-587)))\n (declare (type nonnegative-integer num))\n (setq #:seq-585 (make-sequence nil (or #:limit-586 num)))\n (do ((i (1- num) (1- i)))\n ((minusp i))\n (setf (elt #:seq-585 i) (pop #:lst-587))))\n #:seq-585)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-mapping-collector 'some-name)\n\nPattern to recognize: Macro call that should be transformed by WITH-MAPPING-COLLECTOR", "input": "(with-mapping-collector 'some-name)", "output": "(defmacro WITH-MAPPING-COLLECTOR ...)", "macroexpand": "(let ((#:col125 (make-collector)))\n (map-aggregation (#:col125 (lambda some-name))\n (flet ((quote (&rest #:flet-args126) (apply #:col125 #:flet-args126))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(none-of 'some-name)\n\nWhat needs to change: Macro call that should be transformed by NONE-OF", "input": "(none-of 'some-name)", "output": "(defmacro NONE-OF ...)", "macroexpand": "(lc ('some-name) never)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-reducer 'some-name)\n\nIssue: Macro call that should be transformed by WITH-REDUCER", "input": "(with-reducer 'some-name)", "output": "(defmacro WITH-REDUCER ...)", "macroexpand": "(let ((#:reducer128\n (make-reducer some-name :initial-value (or nil nil) :place-setter nil)))\n (flet ((quote (&rest items) (apply #:reducer128 items)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(integer-writer 2)\n\nWrite a macro that addresses: Macro call that should be transformed by integer-writer", "input": "(integer-writer 2)", "output": "(defmacro integer-writer (bytes)\n \"Create a function to write integers to a binary stream.\"\n (let ((bits (* 8 bytes)))\n `(progn\n (declaim (inline ,(integer-writer-name bytes t)\n ,(integer-writer-name bytes nil)))\n (defun ,(integer-writer-name bytes nil) (socket value)\n (declare (type stream socket)\n (type (unsigned-byte ,bits) value)\n #.*optimize*)\n ,@(if (= bytes 1)\n `((write-byte value socket))\n (loop :for byte :from (1- bytes) :downto 0\n :collect `(write-byte (ldb (byte 8 ,(* byte 8)) value)\n socket)))\n (values))\n (defun ,(integer-writer-name bytes t) (socket value)\n (declare (type stream socket)\n (type (signed-byte ,bits) value)\n #.*optimize*)\n ,@(if (= bytes 1)\n `((write-byte (ldb (byte 8 0) value) socket))\n (loop :for byte :from (1- bytes) :downto 0\n :collect `(write-byte (ldb (byte 8 ,(* byte 8)) value)\n socket)))\n (values)))))", "macroexpand": "(progn (declaim (inline write-int2 write-uint2)) (defun write-uint2 (socket value) (declare (type stream socket) (type (unsigned-byte 16) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 8) value) socket) (write-byte (ldb (byte 8 0) value) socket) (values)) (defun write-int2 (socket value) (declare (type stream socket) (type (signed-byte 16) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 8) value) socket) (write-byte (ldb (byte 8 0) value) socket) (values)))", "category": "efficiency", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-reader-case nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-READER-CASE", "input": "(with-reader-case nil\n (progn))", "output": "(defmacro WITH-READER-CASE ...)", "macroexpand": "(let ()\n (let ((#:previous-case180 (readtable-case *readtable*)))\n (setf (readtable-case *readtable*) nil)\n (unwind-protect (progn (progn))\n (setf (readtable-case *readtable*) #:previous-case180))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(def-neo4j-fun create-index ((type :node) name config) :post (:uri-spec (format nil \"index/~A\" (string-downcase (symbol-name type)))) (:encode (cons (cons :name name) config) :string) (:status-handlers (201 (decode-neo4j-json-output body))))\n\nIssue: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun create-index ((type :node) name config) :post (:uri-spec (format nil \"index/~A\" (string-downcase (symbol-name type)))) (:encode (cons (cons :name name) config) :string) (:status-handlers (201 (decode-neo4j-json-output body))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun create-index (&key (type :node) name config) (let ((uri (format nil \"index/~A\" (string-downcase (symbol-name type)))) (json (encode-neo4j-json-payload (cons (cons :name name) config) :string))) (make-neo4j-request :post uri json (list (list 201 (lambda (body uri json) (decode-neo4j-json-output body))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defstruct-compile-time function-record function-name (lambda-list nil) (body nil) (callees nil) (deterministic? t) (old-deterministic? nil) (screamer? *screamer?*))\n\nPattern to recognize: Macro call that should be transformed by defstruct-compile-time", "input": "(defstruct-compile-time function-record function-name (lambda-list nil) (body nil) (callees nil) (deterministic? t) (old-deterministic? nil) (screamer? *screamer?*))", "output": "(defmacro defstruct-compile-time (options &body items)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (defstruct ,options ,@items)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defstruct function-record function-name (lambda-list nil) (body nil) (callees nil) (deterministic? t) (old-deterministic? nil) (screamer? *screamer?*)))", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-alias-binding update updating)\n\nWrite a macro that addresses: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding update updating)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote update)) (quote updating)) (quote update))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(declare-deprecated-operators nil (progn))\n\nWhat needs to change: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS", "input": "(declare-deprecated-operators nil (progn))", "output": "(defmacro DECLARE-DEPRECATED-OPERATORS ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (define-compiler-macro nil\n (&whole form &rest arguments)\n (declare (ignore arguments))\n (let ((where-from (or *compile-file-truename* *load-truename*)))\n (when *deprecation-warnings*\n (warn 'deprecation-warning :operator-name 'nil :source-file where-from\n :source-form form))\n (when where-from\n (pushnew where-from (gethash 'nil *deprecation-locations*) :test\n #'equalp))\n form))\n (define-compiler-macro (progn)\n (&whole form &rest arguments)\n (declare (ignore arguments))\n (let ((where-from (or *compile-file-truename* *load-truename*)))\n (when *deprecation-warnings*\n (warn 'deprecation-warning :operator-name '(progn) :source-file\n where-from :source-form form))\n (when where-from\n (pushnew where-from (gethash '(progn) *deprecation-locations*) :test\n #'equalp))\n form))\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(loop-on-custom (key var value) customizations collect (list var value))\n\nProblem: Macro call that should be transformed by loop-on-custom", "input": "(loop-on-custom (key var value) customizations collect (list var value))", "output": "(defmacro loop-on-custom ((key var &optional value) &rest clauses)\n (if value\n (destructuring-bind (key-args . clauses) clauses\n `(loop for (,key ,value) on ,key-args by #'cddr\n for ,var = (custom-key-to-variable ,key)\n if ,var ,@clauses))\n `(loop for (,var . ,key) in *custom-vars*\n ,@clauses)))", "macroexpand": "(loop for (key value) on customizations by (function cddr) for var = (custom-key-to-variable key) if var collect (list var value))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error not-core-type-error () (type-name) \"Type ~a is not a core type and thus cannot end up in glsl src code It must end up being used or converted to something that resolves to a glsl type.\" type-name)\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error not-core-type-error () (type-name) \"Type ~a is not a core type and thus cannot end up in glsl src code It must end up being used or converted to something that resolves to a glsl type.\" type-name)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition not-core-type-error (:error-type varjo-error :prefix \"Varjo\") (type-name) \"Type ~a is not a core type and thus cannot end up in glsl src code It must end up being used or converted to something that resolves to a glsl type.\" type-name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(send 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by SEND", "input": "(send 'some-name)", "output": "(defmacro SEND ...)", "macroexpand": "'some-name", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause hash-entries-of (hash-table) \"Iterates over the entries of a hash table. The iteration variables must be specified as (key value), for example: (for (lemma definitions) (hash-entries-of the-english-vocabulary)).\" (unless (and (listp *iteration-variable*) (= 2 (length *iteration-variable*))) (error \"Invalid variable specification for hash-entry, expected (key value) but got ~S\" *iteration-variable*)) (let ((iterator (gensym \"HASH-TABLE-ITERATOR\")) (test (gensym \"TEST\")) (key (car *iteration-variable*)) (value (cadr *iteration-variable*))) `(,(make-wrapper :function (lambda (body) `(with-hash-table-iterator (,iterator ,hash-table) ,body))) ,(make-iteration :bindings (list test key value) :initializations `((setf (values ,test ,key ,value) (,iterator))) :steps `((setf (values ,test ,key ,value) (,iterator))) :postconditions `((not (null ,test)))))))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause hash-entries-of (hash-table) \"Iterates over the entries of a hash table. The iteration variables must be specified as (key value), for example: (for (lemma definitions) (hash-entries-of the-english-vocabulary)).\" (unless (and (listp *iteration-variable*) (= 2 (length *iteration-variable*))) (error \"Invalid variable specification for hash-entry, expected (key value) but got ~S\" *iteration-variable*)) (let ((iterator (gensym \"HASH-TABLE-ITERATOR\")) (test (gensym \"TEST\")) (key (car *iteration-variable*)) (value (cadr *iteration-variable*))) `(,(make-wrapper :function (lambda (body) `(with-hash-table-iterator (,iterator ,hash-table) ,body))) ,(make-iteration :bindings (list test key value) :initializations `((setf (values ,test ,key ,value) (,iterator))) :steps `((setf (values ,test ,key ,value) (,iterator))) :postconditions `((not (null ,test)))))))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro hash-entries-of (hash-table) \"Iterates over the entries of a hash table. The iteration variables must be specified as (key value), for example: (for (lemma definitions) (hash-entries-of the-english-vocabulary)).\" (unless (and (listp *iteration-variable*) (= 2 (length *iteration-variable*))) (error \"Invalid variable specification for hash-entry, expected (key value) but got ~S\" *iteration-variable*)) (let ((iterator (gensym \"HASH-TABLE-ITERATOR\")) (test (gensym \"TEST\")) (key (car *iteration-variable*)) (value (cadr *iteration-variable*))) (sb-int:quasiquote (#S(sb-impl::comma :expr (make-wrapper :function (lambda (body) (sb-int:quasiquote (with-hash-table-iterator (#S(sb-impl::comma :expr iterator :kind 0) #S(sb-impl::comma :expr hash-table :kind 0)) #S(sb-impl::comma :expr body :kind 0))))) :kind 0) #S(sb-impl::comma :expr (make-iteration :bindings (list test key value) :initializations (sb-int:quasiquote ((setf (values #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr value :kind 0)) (#S(sb-impl::comma :expr iterator :kind 0))))) :steps (sb-int:quasiquote ((setf (values #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr key :kind 0) #S(sb-impl::comma :expr value :kind 0)) (#S(sb-impl::comma :expr iterator :kind 0))))) :postconditions (sb-int:quasiquote ((not (null #S(sb-impl::comma :expr test :kind 0)))))) :kind 0))))) (pushnew (quote hash-entries-of) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (= 3 c))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (= 3 c))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e274 3) (#:a275 c)) (if (progn (= #:e274 #:a275)) (add-result (quote test-passed) :test-expr (quote (= 3 c))) (process-failure (quote (= 3 c)) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote c) #:a275 (quote =) #:e274)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-ps-gensyms nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by WITH-PS-GENSYMS", "input": "(with-ps-gensyms nil\n (progn))", "output": "(defmacro WITH-PS-GENSYMS ...)", "macroexpand": "(let* ()\n (progn))", "category": "control-flow", "technique": "gensym", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-test fixture :fix (*read-default-float-format*) (is = 0.0f0 (read-from-string \"0.0\")) (setf *read-default-float-format* 'double-float) (is = 0.0d0 (read-from-string \"0.0\")))\n\nProblem: Macro call that should be transformed by define-test", "input": "(define-test fixture :fix (*read-default-float-format*) (is = 0.0f0 (read-from-string \"0.0\")) (setf *read-default-float-format* 'double-float) (is = 0.0d0 (read-from-string \"0.0\")))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote fixture) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote fixture) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (is = 0.0 (read-from-string \"0.0\"))) (lambda nil (setf *read-default-float-format* (quote double-float))) (lambda nil (is = 0.0d0 (read-from-string \"0.0\")))) :parent (quote nil) (quote :fix) (quote (*read-default-float-format*)))) (quote fixture))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(f0\n nil)\n\nPattern to recognize: Macro call that should be transformed by F0", "input": "(f0\n nil)", "output": "(defmacro F0 ...)", "macroexpand": "(lambda () nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(augment init-code init)\n\nWhat needs to change: Macro call that should be transformed by augment", "input": "(augment init-code init)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf init-code (nconc init-code init))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(finish (error \"NOPE\"))\n\nProblem: Macro call that should be transformed by finish", "input": "(finish (error \"NOPE\"))", "output": "(defmacro finish (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'finishing-result\n :expression '(finish ,form)\n :body (lambda () ,form)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote finishing-result) :expression (quote (finish (error \"NOPE\"))) :body (lambda nil (error \"NOPE\"))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(enable-quasi-quoted-list-syntax)\n\nWhat needs to change: Macro call that should be transformed by ENABLE-QUASI-QUOTED-LIST-SYNTAX", "input": "(enable-quasi-quoted-list-syntax)", "output": "(defmacro ENABLE-QUASI-QUOTED-LIST-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-list-syntax-in-readtable :start-character #\\GRAVE_ACCENT\n :end-character nil\n :unquote-character #\\COMMA\n :splice-character #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP\n :transformation-pipeline nil\n :dispatched-quasi-quote-name nil)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(alet 43 (slet it it))\n\nProblem: Macro call that should be transformed by alet", "input": "(alet 43 (slet it it))", "output": "(defmacro alet (form &body body)\n \"Binds the FORM to IT (via LET) in the scope of the BODY.\"\n `(anaphoric ignore-first ,form (progn ,@body)))", "macroexpand": "(anaphoric ignore-first 43 (progn (slet it it)))", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Generate a defmacro form that transforms code like this:\n(*> +opt-fws+ #'ccontent)\n\nPattern to recognize: Macro call that should be transformed by *>", "input": "(*> +opt-fws+ #'ccontent)", "output": "(defmacro *> (parser &rest parsers)\n \"Combination of parsers yielding the result of the rightmost one.\"\n (let ((offset (gensym \"*>-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res (gensym \"*>-RES\"))\n (next (gensym \"*>-NEXT\")))\n `(multiple-value-bind (,res ,next) ,i\n (if (ok? ,res)\n (funcall ,p ,next)\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:*>-offset143) (multiple-value-bind (#:*>-res144 #:*>-next145) (funcall +opt-fws+ #:*>-offset143) (if (ok? #:*>-res144) (funcall (function ccontent) #:*>-next145) (fail #:*>-next145))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-version-syntax)\n\nProblem: Macro call that should be transformed by enable-version-syntax", "input": "(enable-version-syntax)", "output": "(defmacro enable-version-syntax ()\n \"Enable version reader syntax.\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (%enable-version-syntax)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (%enable-version-syntax))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(when body `(make-block ,body))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when body `(make-block ,body))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if body (sb-int:quasiquote (make-block #S(sb-impl::comma :expr body :kind 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(skip \"Not ready yet\" (false T) (is = 5 6))\n\nPattern to recognize: Macro call that should be transformed by skip", "input": "(skip \"Not ready yet\" (false T) (is = 5 6))", "output": "(defmacro skip (desc &body tests)\n `(with-forced-status (:skipped ,@(if (listp desc) desc (list desc)))\n ,@tests))", "macroexpand": "(with-forced-status (:skipped \"Not ready yet\") (false t) (is = 5 6))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n;; Manual gensym creation is boilerplate-heavy\n(defmacro with-temp (var &body body)\n (let ((g (gensym)))\n `(let ((,g ,var))\n ,@body)))\n;; Every macro needs this pattern - repetitive and error-prone\n\nIssue: Repeated gensym boilerplate in macro definitions \u2014 want automatic gensym creation from naming convention", "input": ";; Manual gensym creation is boilerplate-heavy\n(defmacro with-temp (var &body body)\n (let ((g (gensym)))\n `(let ((,g ,var))\n ,@body)))\n;; Every macro needs this pattern - repetitive and error-prone", "output": "(defun g!-symbol-p (s)\n (and (symbolp s)\n (> (length (symbol-name s)) 2)\n (string= (symbol-name s)\n \"G!\"\n :start1 0\n :end1 2)))\n\n(defmacro defmacro/g! (name args &rest body)\n (let ((syms (remove-duplicates\n (remove-if-not #'g!-symbol-p\n (flatten body)))))\n (multiple-value-bind (body declarations docstring)\n (parse-body body :documentation t)\n `(defmacro ,name ,args\n ,@(when docstring\n (list docstring))\n ,@declarations\n (let ,(mapcar\n (lambda (s)\n `(,s (gensym ,(subseq\n (symbol-name s)\n 2))))\n syms)\n ,@body)))))", "macroexpand": ";; Usage:\n;; (defmacro/g! with-temp (g!var &body body)\n;; `(let ((,g!var ,g!var))\n;; ,@body))\n;;\n;; g!var is automatically gensym'd to #:VAR1234 at expansion time\n;; No capture risk - gensym is uninterned", "category": "capture-management", "technique": "gensym,code-walking", "complexity": "advanced", "quality_score": 0.9874999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defcategory :warning (or :warning :error))\n\nWhat needs to change: Macro call that should be transformed by defcategory", "input": "(defcategory :warning (or :warning :error))", "output": "(defmacro defcategory (category &optional expands-as set)\n `(defcategory-fn ',category ',expands-as ,set))", "macroexpand": "(defcategory-fn (quote :warning) (quote (or :warning :error)) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7925} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(matrix-ctypecase nil)\n\nWhat needs to change: Macro call that should be transformed by MATRIX-CTYPECASE", "input": "(matrix-ctypecase nil)", "output": "(defmacro MATRIX-CTYPECASE ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars)))\n\nWrite a macro that addresses: Macro call that should be transformed by do-generator", "input": "(do-generator-value-list (vars (apply #'multi-gen generators)) (apply #'yield (mapcar #'car vars)))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g157 (apply (function multi-gen) generators))) (loop do (if-generator (vars #:g157) (progn (apply (function yield) (mapcar (function car) vars))) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-yield-binds (format nil \"~A~:[~; IF NOT EXISTS~] ~A (~%~{ ~A~^,~%~}~%)\" (sql-statement-name statement) (create-table-statement-if-not-exists statement) (yield (create-table-statement-table statement)) (mapcar #'yield (sql-composed-statement-children statement))))\n\nIssue: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"~A~:[~; IF NOT EXISTS~] ~A (~%~{ ~A~^,~%~}~%)\" (sql-statement-name statement) (create-table-statement-if-not-exists statement) (yield (create-table-statement-table statement)) (mapcar #'yield (sql-composed-statement-children statement))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"~A~:[~; IF NOT EXISTS~] ~A (~%~{ ~A~^,~%~}~%)\" (sql-statement-name statement) (create-table-statement-if-not-exists statement) (yield (create-table-statement-table statement)) (mapcar (function yield) (sql-composed-statement-children statement)))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lambda* 'some-name)\n\nProblem: Macro call that should be transformed by LAMBDA*", "input": "(lambda* 'some-name)", "output": "(defmacro LAMBDA* ...)", "macroexpand": "(lambda (quote some-name) (with-yield))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-> :tag-1 () \", concurrent\")\n\nWhat needs to change: Macro call that should be transformed by ->", "input": "(-> :tag-1 () \", concurrent\")", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :tag-1 nil \", concurrent\")", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(single-line-mode-p flags)\n\nProblem: Macro call that should be transformed by single-line-mode-p", "input": "(single-line-mode-p flags)", "output": "(defmacro single-line-mode-p (flags)\n \"Accessor macro to extract the third flag out of a three-element flag list.\"\n `(third ,flags))", "macroexpand": "(third flags)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(resolving\n nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by RESOLVING", "input": "(resolving\n nil\n nil)", "output": "(defmacro RESOLVING ...)", "macroexpand": "(resolve\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(deferror \"23503\" foreign-key-violation integrity-violation)\n\nProblem: Macro call that should be transformed by deferror", "input": "(deferror \"23503\" foreign-key-violation integrity-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition foreign-key-violation (integrity-violation) nil) (setf (gethash \"23503\" *error-table*) (quote foreign-key-violation)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do-iterator 'some-name)\n\nIssue: Macro call that should be transformed by DO-ITERATOR", "input": "(do-iterator 'some-name)", "output": "(defmacro DO-ITERATOR ...)", "macroexpand": "(iterate-for-effects some-name (lambda (quote)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-mocks () (answer foo 3 (call-previous)) (is (eql 3 (foo))) (is (eq 'foo (foo))))\n\nWhat needs to change: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (answer foo 3 (call-previous)) (is (eql 3 (foo))) (is (eq 'foo (foo))))", "output": "(defmacro with-mocks ((&key (recordp T)) &body body)\n \"Execute BODY in a new mocking context. Invocations will be recorded\nif RECORDP is set (default true).\"\n `(call-with-mocks\n (lambda () ,@body)\n :recordp ,recordp))", "macroexpand": "(call-with-mocks (lambda nil (answer foo 3 (call-previous)) (is (eql 3 (foo))) (is (eq (quote foo) (foo)))) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(lret* ((y 1) (y 2)) (declare (ignorable y)) 3)\n\nPattern to recognize: Macro call that should be transformed by lret", "input": "(lret* ((y 1) (y 2)) (declare (ignorable y)) 3)", "output": "(defmacro lret ((&rest bindings) &body body)\n \"Return the initial value of the last binding in BINDINGS. The idea\nis to create something, initialize it, and then return it.\n\n (lret ((x 1)\n (y (make-array 1)))\n (setf (aref y 0) x))\n => #(1)\n\nNote that the value returned is the value initially bound. Subsequent\nassignments are ignored.\n\n (lret ((x 1))\n (setf x 2))\n => 1\n\nFurthermore, on Lisps that support it, the variable may be made\nread-only, making assignment a compiler-time error.\n\n`lret' may seem trivial, but it fufills the highest purpose a macro\ncan: it eliminates a whole class of bugs (initializing an object, but\nforgetting to return it).\n\nCf. `aprog1' in Anaphora.\"\n `(lret-aux let ,bindings\n ,@body))", "macroexpand": "(lret-aux let* ((y 1) (y 2)) (declare (ignorable y)) 3)", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(alist-bind (type size) form `((:array ,@(parse-type type (aval :tag type)) ,size)))\n\nIssue: Macro call that should be transformed by alist-bind", "input": "(alist-bind (type size) form `((:array ,@(parse-type type (aval :tag type)) ,size)))", "output": "(defmacro alist-bind ((&rest vars) alist &body body)\n \"Inefficient but doesn't really matter here\"\n (once-only (alist)\n `(let (,@(mapcar (lambda (x)\n (if (consp x)\n `(,(car x) (aval ,(cadr x) ,alist))\n `(,x (aval ,(make-keyword x) ,alist))))\n vars))\n ,@body)))", "macroexpand": "(let ((#:alist236 form)) (let ((type (aval :type #:alist236)) (size (aval :size #:alist236))) (sb-int:quasiquote ((:array #S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2) #S(sb-impl::comma :expr size :kind 0))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defgenerator icount (n &optional (step 1)) \"Make a generator that returns evenly spaced values starting with n. Step can be fractional. Eg: (counter 10) -> 10 11 12 13 14 ... (counter 2.5 0.5) -> 2.5 3.0 3.5 ...\" (unless (numberp n) (error \"n must be a number\")) (unless (numberp step) (error \"step must be a number\")) (loop for i from n by step do (yield i)))\n\nProblem: Macro call that should be transformed by defgenerator", "input": "(defgenerator icount (n &optional (step 1)) \"Make a generator that returns evenly spaced values starting with n. Step can be fractional. Eg: (counter 10) -> 10 11 12 13 14 ... (counter 2.5 0.5) -> 2.5 3.0 3.5 ...\" (unless (numberp n) (error \"n must be a number\")) (unless (numberp step) (error \"step must be a number\")) (loop for i from n by step do (yield i)))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun icount (n &optional (step 1)) \"Make a generator that returns evenly spaced values starting with n. Step can be fractional. Eg: (counter 10) -> 10 11 12 13 14 ... (counter 2.5 0.5) -> 2.5 3.0 3.5 ...\" (with-yield (unless (numberp n) (error \"n must be a number\")) (unless (numberp step) (error \"step must be a number\")) (loop for i from n by step do (yield i))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(who-ps-html nil nil)\n\nProblem: Macro call that should be transformed by WHO-PS-HTML", "input": "(who-ps-html nil nil)", "output": "(defmacro WHO-PS-HTML ...)", "macroexpand": "(stringify nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-generator (g generator) (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil))))))\n\nPattern to recognize: Macro call that should be transformed by do-generator", "input": "(do-generator (g generator) (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil))))))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g162 generator)) (loop do (if-generator ((g) #:g162) (progn (let ((currkey (funcall key g))) (if (funcall comp last currkey) (push g res) (progn (when res (yield last (nreverse res))) (setf last currkey) (setf res (cons g nil)))))) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Generate a defmacro form that transforms code like this:\n(draw scene (:path :d (path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))) :fill \"none\" :stroke \"blue\" :stroke-width 5)\n\nPattern to recognize: Macro call that should be transformed by draw", "input": "(draw scene (:path :d (path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))) :fill \"none\" :stroke \"blue\" :stroke-width 5)", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g161 (funcall (function make-svg-element) :path (append (list :d (path (move-to 100 400) (line-to-r 50 -25) (arc-to-r 25 25 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 50 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 75 -30 0 1 50 -25) (line-to-r 50 -25) (arc-to-r 25 100 -30 0 1 50 -25) (line-to-r 50 -25) (vertical-to-r 50))) (list :fill \"none\" :stroke \"blue\" :stroke-width 5))))) (add-element scene #:g161) #:g161)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(fgatherlet nil\n nil)\n\nIssue: Macro call that should be transformed by FGATHERLET", "input": "(fgatherlet nil\n nil)", "output": "(defmacro FGATHERLET ...)", "macroexpand": "(flet ()\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(secase (car x) (:y (setf it :no)) (:x (setf it :yes)))\n\nWrite a macro that addresses: Macro call that should be transformed by secase", "input": "(secase (car x) (:y (setf it :no)) (:x (setf it :yes)))", "output": "(defmacro secase (keyform &body cases)\n \"Like ECASE, except binds the keyform to IT (via SYMBOL-MACROLET) for the\nscope of the cases. IT can be set with SETF.\"\n `(symbolic ecase ,keyform ,@cases))", "macroexpand": "(symbolic ecase (car x) (:y (setf it :no)) (:x (setf it :yes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(c? (klin self))\n\nPattern to recognize: Macro call that should be transformed by c?", "input": "(c? (klin self))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(make-c-dependent :code (quote ((klin self))) :value-state :unevaluated :rule (c-lambda (klin self)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(declare-deprecated-operators nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS", "input": "(declare-deprecated-operators nil :key nil)", "output": "(defmacro DECLARE-DEPRECATED-OPERATORS ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (define-compiler-macro nil\n (&whole form &rest arguments)\n (declare (ignore arguments))\n (let ((where-from (or *compile-file-truename* *load-truename*)))\n (when *deprecation-warnings*\n (warn 'deprecation-warning :operator-name 'nil :source-file where-from\n :source-form form))\n (when where-from\n (pushnew where-from (gethash 'nil *deprecation-locations*) :test\n #'equalp))\n form))\n (define-compiler-macro :key\n (&whole form &rest arguments)\n (declare (ignore arguments))\n (let ((where-from (or *compile-file-truename* *load-truename*)))\n (when *deprecation-warnings*\n (warn 'deprecation-warning :operator-name ':key :source-file where-from\n :source-form form))\n (when where-from\n (pushnew where-from (gethash ':key *deprecation-locations*) :test\n #'equalp))\n form))\n (define-compiler-macro nil\n (&whole form &rest arguments)\n (declare (ignore arguments))\n (let ((where-from (or *compile-file-truename* *load-truename*)))\n (when *deprecation-warnings*\n (warn 'deprecation-warning :operator-name 'nil :source-file where-from\n :source-form form))\n (when where-from\n (pushnew where-from (gethash 'nil *deprecation-locations*) :test\n #'equalp))\n form))\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defaction nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by DEFACTION", "input": "(defaction nil\n :key\n nil)", "output": "(defmacro DEFACTION ...)", "macroexpand": "(setf (gethash #A((3) base-char . \"NIL\") cl-rules.core::*actions*)\n (lambda :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n;; Regex matching with captures requires manual multiple-value-bind\n(multiple-value-bind (matchp captures)\n (cl-ppcre:scan-to-strings \"_(\\\\w+)@(\\\\w+)\\\\.com_\" email)\n (if matchp\n (let ((user (aref captures 0))\n (domain (aref captures 1)))\n (format t \"~a at ~a~%\" user domain))\n :invalid))\n\n;; Verbose: bind result, extract captures by index, branch - repetitive\n\nWrite a macro that addresses: Regex matching with named captures requires verbose destructuring \u2014 want $1, $2, ... anaphors bound to capture groups", "input": ";; Regex matching with captures requires manual multiple-value-bind\n(multiple-value-bind (matchp captures)\n (cl-ppcre:scan-to-strings \"_(\\\\w+)@(\\\\w+)\\\\.com_\" email)\n (if matchp\n (let ((user (aref captures 0))\n (domain (aref captures 1)))\n (format t \"~a at ~a~%\" user domain))\n :invalid))\n\n;; Verbose: bind result, extract captures by index, branch - repetitive", "output": "#+cl-ppcre\n(defun dollar-symbol-p (s)\n (and (symbolp s)\n (> (length (symbol-name s)) 1)\n (string= (symbol-name s)\n \"$\"\n :start1 0\n :end1 1)\n (ignore-errors (parse-integer (subseq (symbol-name s) 1)))))\n\n(defmacro! if-match ((match-regex str) then &optional else)\n (let* ((dollars (remove-duplicates\n (remove-if-not #'dollar-symbol-p\n (flatten then))))\n (top (or (car (sort (mapcar #'dollar-symbol-p dollars) #'>))\n 0)))\n `(multiple-value-bind (,g!matches ,g!captures) (,match-regex ,str)\n (declare (ignorable ,g!matches ,g!captures))\n (let ((,g!captures-len (length ,g!captures)))\n (declare (ignorable ,g!captures-len))\n (symbol-macrolet ,(mapcar #`(,(symb \"$\" a1)\n (if (< ,g!captures-len ,a1)\n (error \"Too few matchs: ~a unbound.\" ,(mkstr \"$\" a1))\n (aref ,g!captures ,(1- a1))))\n (loop for i from 1 to top collect i))\n (if ,g!matches\n ,then\n ,else))))))", "macroexpand": ";; (if-match (#~m_(\\\\w+)@(\\\\w+)\\\\.com_ email)\n;; (format t \"~a at ~a~%\" $1 $2)\n;; :invalid)\n;;\n;; $1, $2 bound to capture groups via symbol-macrolet\n;; Out-of-bounds $N signals a clear error at runtime\n;; Nested if-match works - each has its own capture bindings", "category": "control-flow", "technique": "symbol-macrolet,gensym,code-walking", "complexity": "advanced", "quality_score": 1.0} {"instruction": "Generate a defmacro form that transforms code like this:\n(deferror \"08P01\" protocol-violation)\n\nPattern to recognize: Macro call that should be transformed by deferror", "input": "(deferror \"08P01\" protocol-violation)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition protocol-violation (database-error) nil) (setf (gethash \"08P01\" *error-table*) (quote protocol-violation)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-last 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-LAST", "input": "(collect-last 'some-name)", "output": "(defmacro COLLECT-LAST ...)", "macroexpand": "(common-lisp:let* ((#:generator-533 (generator 'some-name))\n #:items-527\n (#:item-529 nil))\n (declare (type generator #:generator-533)\n (type (null-or t) #:item-529))\n (tagbody\n #:ll-534\n (setq #:items-527 (next-in #:generator-533 (go end)))\n (setq #:item-529 #:items-527)\n (go #:ll-534)\n end)\n #:item-529)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-generic generic (a b &key c) (declare (ignorable a b c)))\n\nPattern to recognize: Macro call that should be transformed by define-generic", "input": "(define-generic generic (a b &key c) (declare (ignorable a b c)))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:method (a b &key c) (declare (ignorable a b c)))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lexpr-$send nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by LEXPR-$SEND", "input": "(lexpr-$send nil (progn))", "output": "(defmacro LEXPR-$SEND ...)", "macroexpand": "(apply #'send-message nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(cond-<>>\n nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by COND-<>>", "input": "(cond-<>>\n nil\n (progn))", "output": "(defmacro COND-<>> ...)", "macroexpand": "(let* ((#:var157 nil)\n (#:var158\n (if progn\n (-<>>\n #:var157)\n #:var157)))\n #:var158)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(set-bop nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by SET-BOP", "input": "(set-bop nil :key nil)", "output": "(defmacro SET-BOP ...)", "macroexpand": "(eval-when (:load-toplevel :compile-toplevel :execute)\n (progn\n (save-binfix)\n (mapc\n (lambda (ops)\n (mapc\n (lambda (op1)\n (when (eq (car op1) 'nil)\n (setf (cadr op1) ':key)\n (unless nil (setf (cddr op1) '(nil)))))\n ops))\n *binfix*)\n (assign-properties)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-rewrite caar (expr) `(car (car ,(second expr))))\n\nPattern to recognize: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite caar (expr) `(car (car ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote caar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (car #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) (1- val)))\n\nProblem: Macro call that should be transformed by c?-with-stored", "input": "(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) (1- val)))", "output": "(defmacro c?-with-stored ((var key store &optional default) &body body)\n `(c? (bwhen-c-stored (,var ,key ,store ,default)\n\t ,@body)))", "macroexpand": "(c? (bwhen-c-stored (v :bar store (quote nothing)) (bwhen (val (value v)) (1- val))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-hamt set (:test test :hash hash :table table) (flet ((%remove (table x) (%hamt-remove table x (funcall hash x) 0 test))) (make-instance 'hash-set :test test :hash hash :table (reduce #'%remove xs :initial-value table))))\n\nIssue: Macro call that should be transformed by with-hamt", "input": "(with-hamt set (:test test :hash hash :table table) (flet ((%remove (table x) (%hamt-remove table x (funcall hash x) 0 test))) (make-instance 'hash-set :test test :hash hash :table (reduce #'%remove xs :initial-value table))))", "output": "(defmacro with-hamt (hamt (&key test hash table) &body body)\n \"Accessing HAMT slots\"\n `(with-accessors ((,test hamt-test)\n (,hash hamt-hash)\n (,table hamt-table))\n ,hamt\n ,@body))", "macroexpand": "(with-accessors ((test hamt-test) (hash hamt-hash) (table hamt-table)) set (flet ((%remove (table x) (%hamt-remove table x (funcall hash x) 0 test))) (make-instance (quote hash-set) :test test :hash hash :table (reduce (function %remove) xs :initial-value table))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-generic generic ((a a) (b b) &key (c nil)) (+ a b))\n\nPattern to recognize: Macro call that should be transformed by define-generic", "input": "(define-generic generic ((a a) (b b) &key (c nil)) (+ a b))", "output": "(defmacro define-generic (name (&rest arglist) &body body)\n \"Convenience macro to define generics as if they were methods.\nARGLIST can be a method arglist, in which case it's parsed into\ngeneric function arglist by removing method-specific args.\n\nBODY can be a list of `defgeneric' options (processed as-is, even\n:method ones) intermixed with other Lisp forms:\n- If there's a docstring as the first form, it's processed into\n :documentation option of `defgeneric'.\n- If there are non-option forms, they are put together into a separate\n :method option under ARGLIST.\n- If there's a `declare' form:\n - If it's generic-friendly (optimize for speed or space), then it's\n put into both generic body and :method body (if any).\n - Otherwise it's only put into :method (creating it if necessary).\n- If there's an `:export-generic-name-p' boolean option, export (T) or\n don't export (NIL) the generic symbol.\n\nExample:\n\n\\(define-generic add ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\")))\n=>\n\\(defgeneric add (a b &key &allow-other-keys)\n (:method ((a integer) (b integer) &key coerce-to-fixnum &allow-other-keys)\n (if coerce-to-fixnum\n (coerce (+ a b) 'fixnum)\n (+ a b)))\n (:method ((a string) (b integer))\n (error \\\"Cannot use `add' on strings!\\\"))\n (:documentation \\\"Adds A and B, coercing them to fixnum if the sum is too big.\\\"))\"\n (multiple-value-bind (body declarations documentation)\n (uiop:parse-body body :documentation t)\n (when (and (= 1 (length body))\n (stringp (first body)))\n (style-warn \"Body of DEFINE-GENERIC contains a single string:\n~s.\nIt's interpreted as a method body by default.\n\nIf you meant this string to be a generic docstring, and not a method\nbody, add an explicit NIL or some other body form:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n 'body-form)\n\nIf you meant it as a body form, do nothing, or provide explicit\ndocumentation or any other option:\n(define-generic name (arg1 arg2)\n \\\"Docstring\\\"\n (:documentation \\\"Real docstring\\\"))\" (first body)))\n (let* ((generic-declarations (remove-if (lambda (d)\n (or (> (length d) 2)\n (not (eq 'optimize (first (second d))))\n (notevery (lambda (o)\n (let ((feature (first (uiop:ensure-list o))))\n (or (eq feature 'speed)\n (eq feature 'space))))\n (rest (second d)))))\n declarations))\n (options (remove-if-not (lambda (form)\n (keywordp (first (uiop:ensure-list form))))\n body))\n (method-body (remove-if (lambda (f) (member f options :test #'equal)) body))\n (export-generic-name-p (find :export-generic-name-p options :key #'first))\n (options (remove export-generic-name-p options :test #'equal))\n (export-p (if export-generic-name-p\n (second export-generic-name-p)\n *export-generic-name-p*))\n (generalized-arglist (generalize-arglist arglist)))\n (when (and (not (equal generalized-arglist arglist))\n (every #'null (list method-body options)))\n (style-warn \"Specialized arglist used without method body in define-generic: ~a\" arglist))\n `(prog1\n (defgeneric ,name ,generalized-arglist\n ,@generic-declarations\n ,@(when (or method-body\n (not (equal generic-declarations\n declarations)))\n `((:method ,arglist\n ,@declarations\n ,@method-body)))\n ,@options\n ,@(when documentation\n `((:documentation ,documentation))))\n ;; FIXME: Maybe only export if package of generic function name\n ;; matches *PACKAGE*?\n ,@(when export-p\n `((eval-when (:compile-toplevel :load-toplevel :execute)\n (export ',name ,(package-name *package*)))))\n ,@(let ((documentation (or documentation\n (second (first (member :documentation options :key #'first))))))\n (when documentation\n `((setf (documentation ',name 'function) ,documentation)\n (setf (documentation (fdefinition ',name) 'function) ,documentation))))))))", "macroexpand": "(prog1 (defgeneric generic (a b &key c) (:method ((a a) (b b) &key (c nil)) (+ a b))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(fmap #'1+ (ok (in \"\") 1))\n\nProblem: Macro call that should be transformed by fmap", "input": "(fmap #'1+ (ok (in \"\") 1))", "output": "(defmacro fmap (f thing)\n \"Apply a pure function to the inner contents of some parsing operation, if the\nparsing itself was successful.\"\n `(multiple-value-bind (res next) ,thing\n (if (failure? res)\n (fail next)\n (values (funcall ,f res) next))))", "macroexpand": "(multiple-value-bind (res next) (ok (in \"\") 1) (if (failure? res) (fail next) (values (funcall (function 1+) res) next)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dict-of nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DICT-OF", "input": "(dict-of nil :key nil)", "output": "(defmacro DICT-OF ...)", "macroexpand": "(let ((#:dict131 (make-hash-table :test 'equal)))\n (do-for (:key nil)\n (multiple-value-call\n (lambda (#:k132 #:v133) (setf (gethash #:k132 #:dict131) #:v133))\n nil))\n #:dict131)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-op (:not-in infix-list-op))\n\nProblem: Macro call that should be transformed by define-op", "input": "(define-op (:not-in infix-list-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (not-in-op (:include infix-list-op (name \"NOT IN\")) (:constructor make-not-in-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defhandler catch (catch tag &rest body) `(list ',catch ,(e tag) ,@(e-list body)))\n\nWrite a macro that addresses: Macro call that should be transformed by defhandler", "input": "(defhandler catch (catch tag &rest body) `(list ',catch ,(e tag) ,@(e-list body)))", "output": "(defmacro defhandler (symbol lambda-list &body body)\n (let ((syms (force-list symbol)))\n (let ((func (intern (format nil \"~A~A\" 'hander- (first syms)))))\n `(progn\n (defun ,func ,lambda-list\n ,@body)\n (setf\n ,@(loop for sym in syms\n collect `(gethash ',sym *form-handler*)\n collect `',func))))))", "macroexpand": "(progn (defun hander-catch (catch tag &rest body) (sb-int:quasiquote (list (quote #S(sb-impl::comma :expr catch :kind 0)) #S(sb-impl::comma :expr (e tag) :kind 0) #S(sb-impl::comma :expr (e-list body) :kind 2)))) (setf (gethash (quote catch) *form-handler*) (quote hander-catch)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-mustache-character #\\> (make-instance 'partial-tag :text arg-text))\n\nIssue: Macro call that should be transformed by define", "input": "(define-mustache-character #\\> (make-instance 'partial-tag :text arg-text))", "output": "(defmacro define (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "macroexpand": "(set-mustache-character #\\GREATER-THAN_SIGN (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote partial-tag) :text arg-text)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defannotation annotation (options function-definition-form) (:arity 2) (let ((name (definition-form-symbol (progn-form-last function-definition-form)))) `(progn (set-annotation-options ',name ',options) ,function-definition-form)))\n\nIssue: Macro call that should be transformed by defannotation", "input": "(defannotation annotation (options function-definition-form) (:arity 2) (let ((name (definition-form-symbol (progn-form-last function-definition-form)))) `(progn (set-annotation-options ',name ',options) ,function-definition-form)))", "output": "(defmacro defannotation (name lambda-list options &body body)\n `(progn\n (set-annotation-options ',name ',options)\n (defmacro ,name ,lambda-list ,@body)))", "macroexpand": "(progn (set-annotation-options (quote annotation) (quote (:arity 2))) (defmacro annotation (options function-definition-form) (let ((name (definition-form-symbol (progn-form-last function-definition-form)))) (sb-int:quasiquote (progn (set-annotation-options (quote #S(sb-impl::comma :expr name :kind 0)) (quote #S(sb-impl::comma :expr options :kind 0))) #S(sb-impl::comma :expr function-definition-form :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-sharp-number-syntax)\n\nPattern to recognize: Macro call that should be transformed by ENABLE-SHARP-NUMBER-SYNTAX", "input": "(enable-sharp-number-syntax)", "output": "(defmacro ENABLE-SHARP-NUMBER-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-sharp-number-syntax-in-readtable)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-bug no-args-remove-in-unrep-inlining () (func args args-code) \" Sorry that you have hit this bug, if you have time please copy this error, your stack trace and (if possible) the code that triggered this error and raise an issue at https://github.com/cbaggers/varjo/issues Thankyou, and our apologies. ---- When trying to compile the function ~a we knew we had to inline as a local function to to one of the arguments being of an unrepresentable type. However No arguments were identified for moving from the function to the surrounding let. func: ~a args: ~a args-code: ~a \" (slot-value func 'name) func args args-code)\n\nPattern to recognize: Macro call that should be transformed by define-bug", "input": "(define-bug no-args-remove-in-unrep-inlining () (func args args-code) \" Sorry that you have hit this bug, if you have time please copy this error, your stack trace and (if possible) the code that triggered this error and raise an issue at https://github.com/cbaggers/varjo/issues Thankyou, and our apologies. ---- When trying to compile the function ~a we knew we had to inline as a local function to to one of the arguments being of an unrepresentable type. However No arguments were identified for moving from the function to the surrounding let. func: ~a args: ~a args-code: ~a \" (slot-value func 'name) func args args-code)", "output": "(defmacro define-bug (name (&key (error-type 'varjo-error) (prefix \"Varjo Bug\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition no-args-remove-in-unrep-inlining (:error-type varjo-error :prefix \"Varjo Bug\") (func args args-code) \" Sorry that you have hit this bug, if you have time please copy this error, your stack trace and (if possible) the code that triggered this error and raise an issue at https://github.com/cbaggers/varjo/issues Thankyou, and our apologies. ---- When trying to compile the function ~a we knew we had to inline as a local function to to one of the arguments being of an unrepresentable type. However No arguments were identified for moving from the function to the surrounding let. func: ~a args: ~a args-code: ~a \" (slot-value func (quote name)) func args args-code)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(do-combinations 'some-name)\n\nProblem: Macro call that should be transformed by DO-COMBINATIONS", "input": "(do-combinations 'some-name)", "output": "(defmacro DO-COMBINATIONS ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(false NIL)\n\nWrite a macro that addresses: Macro call that should be transformed by false", "input": "(false NIL)", "output": "(defmacro false (form &optional description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(false ,form)\n :value-form ',form\n :body (lambda () ,form)\n :expected 'NIL\n :comparison 'geq\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote comparison-result) :expression (quote (false nil)) :value-form (quote nil) :body (lambda nil nil) :expected (quote nil) :comparison (quote geq)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defjs map3() (emit this.name (ps:create :count 1)))\n\nWhat needs to change: Macro call that should be transformed by defjs", "input": "(defjs map3() (emit this.name (ps:create :count 1)))", "output": "(defmacro defjs (name args &body body)\n \"Define client side javascript. Works like defun; body is in lisp, with parenscript\n additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. \n macro creates a lisp function which sends the javascript function over to the mongo \n server to be evaluated. Result is processed and returned to the reader. \n This will execute 10 times on the server :\n (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))\"\n `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))\n (setf (gethash ',name *js-definitions*) js-body)\n (defun ,name ,args\n (get-element \"retval\" (car (docs (db.eval js-body ,@args)))))))", "macroexpand": "(let* ((js-body (parenscript:ps (lambda nil (emit this.name (parenscript:create :count 1)))))) (setf (gethash (quote map3) *js-definitions*) js-body) (defun map3 nil (get-element \"retval\" (car (docs (db.eval js-body))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error stage-order-error () (stage-type) \"stage of type ~s is not valid at this place in the pipeline, this is either out of order or a stage of this type already exists\" stage-type)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error stage-order-error () (stage-type) \"stage of type ~s is not valid at this place in the pipeline, this is either out of order or a stage of this type already exists\" stage-type)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition stage-order-error (:error-type varjo-error :prefix \"Varjo\") (stage-type) \"stage of type ~s is not valid at this place in the pipeline, this is either out of order or a stage of this type already exists\" stage-type)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(c-assert fm-parent)\n\nWrite a macro that addresses: Macro call that should be transformed by c-assert", "input": "(c-assert fm-parent)", "output": "(defmacro c-assert (assertion &optional places fmt$ &rest fmt-args)\n (declare (ignorable assertion places fmt$ fmt-args))\n #+(or)`(progn) \n `(unless *stop*\n (unless ,assertion\n ,(if fmt$\n `(c-break ,fmt$ ,@fmt-args)\n `(c-break \"failed assertion: ~a\" ',assertion)))))", "macroexpand": "(unless *stop* (unless fm-parent (c-break \"failed assertion: ~a\" (quote fm-parent))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.885} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(letv)\n\nIssue: Macro call that should be transformed by LETV", "input": "(letv)", "output": "(defmacro LETV ...)", "macroexpand": "(block nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-error symbol-unidentified (:error-type varjo-critical-error) (sym) \"Symbol '~s' is unidentified. ~@[However the symbol is valid in these stages: ~{~%- ~a~}~]\" sym (mapcar #'string-downcase (mapcar #'string (find-stages-that-have-var sym))))\n\nPattern to recognize: Macro call that should be transformed by define-error", "input": "(define-error symbol-unidentified (:error-type varjo-critical-error) (sym) \"Symbol '~s' is unidentified. ~@[However the symbol is valid in these stages: ~{~%- ~a~}~]\" sym (mapcar #'string-downcase (mapcar #'string (find-stages-that-have-var sym))))", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition symbol-unidentified (:error-type varjo-critical-error :prefix \"Varjo\") (sym) \"Symbol '~s' is unidentified. ~@[However the symbol is valid in these stages: ~{~%- ~a~}~]\" sym (mapcar (function string-downcase) (mapcar (function string) (find-stages-that-have-var sym))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defannotation doc (docstring definition-form) (:arity 2) \"Add DOCSTRING documentation for DEFINITION-FORM.\" (progn-form-replace-last (lambda (definition-form) (case (definition-form-type definition-form) ((defvar defparameter defconstant defun defmethod defmacro deftype define-compiler-macro) (destructuring-bind (def name arg . body) definition-form `(,def ,name ,arg ,docstring ,@body))) ((defstruct) (destructuring-bind (def name-and-options . slots) definition-form `(,def ,name-and-options ,docstring ,@slots))) ((defclass define-condition) (destructuring-bind (def name supers slots . opts) definition-form (pushnew `(:documentation ,docstring) opts :key #'car) `(,def ,name ,supers ,slots ,@opts))) ((defgeneric) (destructuring-bind (def name args . opts) definition-form (pushnew `(:documentation ,docstring) opts :key #'car) `(,def ,name ,args ,@opts))) (t (error \"Documentation not supported: ~a\" definition-form)))) definition-form))\n\nWhat needs to change: Macro call that should be transformed by defannotation", "input": "(defannotation doc (docstring definition-form) (:arity 2) \"Add DOCSTRING documentation for DEFINITION-FORM.\" (progn-form-replace-last (lambda (definition-form) (case (definition-form-type definition-form) ((defvar defparameter defconstant defun defmethod defmacro deftype define-compiler-macro) (destructuring-bind (def name arg . body) definition-form `(,def ,name ,arg ,docstring ,@body))) ((defstruct) (destructuring-bind (def name-and-options . slots) definition-form `(,def ,name-and-options ,docstring ,@slots))) ((defclass define-condition) (destructuring-bind (def name supers slots . opts) definition-form (pushnew `(:documentation ,docstring) opts :key #'car) `(,def ,name ,supers ,slots ,@opts))) ((defgeneric) (destructuring-bind (def name args . opts) definition-form (pushnew `(:documentation ,docstring) opts :key #'car) `(,def ,name ,args ,@opts))) (t (error \"Documentation not supported: ~a\" definition-form)))) definition-form))", "output": "(defmacro defannotation (name lambda-list options &body body)\n `(progn\n (set-annotation-options ',name ',options)\n (defmacro ,name ,lambda-list ,@body)))", "macroexpand": "(progn (set-annotation-options (quote doc) (quote (:arity 2))) (defmacro doc (docstring definition-form) \"Add DOCSTRING documentation for DEFINITION-FORM.\" (progn-form-replace-last (lambda (definition-form) (case (definition-form-type definition-form) ((defvar defparameter defconstant defun defmethod defmacro deftype define-compiler-macro) (destructuring-bind (def name arg . body) definition-form (sb-int:quasiquote (#S(sb-impl::comma :expr def :kind 0) #S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr arg :kind 0) #S(sb-impl::comma :expr docstring :kind 0) #S(sb-impl::comma :expr body :kind 2))))) ((defstruct) (destructuring-bind (def name-and-options . slots) definition-form (sb-int:quasiquote (#S(sb-impl::comma :expr def :kind 0) #S(sb-impl::comma :expr name-and-options :kind 0) #S(sb-impl::comma :expr docstring :kind 0) #S(sb-impl::comma :expr slots :kind 2))))) ((defclass define-condition) (destructuring-bind (def name supers slots . opts) definition-form (pushnew (sb-int:quasiquote (:documentation #S(sb-impl::comma :expr docstring :kind 0))) opts :key (function car)) (sb-int:quasiquote (#S(sb-impl::comma :expr def :kind 0) #S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr supers :kind 0) #S(sb-impl::comma :expr slots :kind 0) #S(sb-impl::comma :expr opts :kind 2))))) ((defgeneric) (destructuring-bind (def name args . opts) definition-form (pushnew (sb-int:quasiquote (:documentation #S(sb-impl::comma :expr docstring :kind 0))) opts :key (function car)) (sb-int:quasiquote (#S(sb-impl::comma :expr def :kind 0) #S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr args :kind 0) #S(sb-impl::comma :expr opts :kind 2))))) (t (error \"Documentation not supported: ~a\" definition-form)))) definition-form)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(make-float-converters encode-float64 decode-float64 11 52 nil)\n\nWrite a macro that addresses: Macro call that should be transformed by make-float-converters", "input": "(make-float-converters encode-float64 decode-float64 11 52 nil)", "output": "(defmacro make-float-converters (encoder-name\n decoder-name\n exponent-bits\n significand-bits\n support-nan-and-infinity-p)\n \"Writes an encoder and decoder function for floating point\nnumbers with the given amount of exponent and significand\nbits (plus an extra sign bit). If support-nan-and-infinity-p is\ntrue, the decoders will also understand these special cases. NaN\nis represented as :not-a-number, and the infinities as\n:positive-infinity and :negative-infinity. Note that this means\nthat the in- or output of these functions is not just floating\npoint numbers anymore, but also keywords.\"\n (let* ((total-bits (+ 1 exponent-bits significand-bits))\n (exponent-offset (1- (expt 2 (1- exponent-bits)))) ; (A)\n (sign-part `(ldb (byte 1 ,(1- total-bits)) bits))\n (exponent-part `(ldb (byte ,exponent-bits ,significand-bits) bits))\n (significand-part `(ldb (byte ,significand-bits 0) bits))\n (nan support-nan-and-infinity-p)\n (max-exponent (1- (expt 2 exponent-bits)))) ; (B)\n `(progn\n (defun ,encoder-name (float)\n ,@(unless nan `((declare (type float float))))\n (multiple-value-bind (sign significand exponent)\n (cond ,@(when nan `(((eq float :not-a-number)\n (values 0 1 ,max-exponent))\n ((eq float :positive-infinity)\n (values 0 0 ,max-exponent))\n ((eq float :negative-infinity)\n (values 1 0 ,max-exponent))))\n ((zerop float)\n (values 0 0 0))\n (t\n (multiple-value-bind (significand exponent sign)\n (decode-float float)\n (let ((exponent (+ (1- exponent) ,exponent-offset))\n (sign (if (= sign 1.0) 0 1)))\n (unless (< exponent ,(expt 2 exponent-bits))\n (error \"Floating point overflow when encoding ~A.\"\n float))\n (if (< exponent 0) ; (C)\n (values sign (ash (round (* ,(expt 2 significand-bits)\n significand))\n exponent)\n 0)\n (values sign (round (* ,(expt 2 significand-bits)\n (1- (* significand 2))))\n exponent))))))\n (let ((bits 0))\n (declare (type (unsigned-byte ,total-bits) bits))\n (setf ,sign-part sign\n ,exponent-part exponent\n ,significand-part significand)\n bits)))\n\n (defun ,decoder-name (bits)\n (declare (type (unsigned-byte ,total-bits) bits))\n (let* ((sign ,sign-part)\n (exponent ,exponent-part)\n (significand ,significand-part))\n ,@(when nan `((when (= exponent ,max-exponent)\n (return-from ,decoder-name\n (cond ((not (zerop significand)) :not-a-number)\n ((zerop sign) :positive-infinity)\n (t :negative-infinity))))))\n (if (zerop exponent) ; (D)\n (setf exponent 1)\n (setf (ldb (byte 1 ,significand-bits) significand) 1))\n (unless (zerop sign)\n (setf significand (- significand)))\n (scale-float (float significand ,(if (> total-bits 32) 1.0d0 1.0))\n (- exponent ,(+ exponent-offset significand-bits))))))))", "macroexpand": "(progn (defun encode-float64 (float) (declare (type float float)) (multiple-value-bind (sign significand exponent) (cond ((zerop float) (values 0 0 0)) (t (multiple-value-bind (significand exponent sign) (decode-float float) (let ((exponent (+ (1- exponent) 1023)) (sign (if (= sign 1.0) 0 1))) (unless (< exponent 2048) (error \"Floating point overflow when encoding ~A.\" float)) (if (< exponent 0) (values sign (ash (round (* 4503599627370496 significand)) exponent) 0) (values sign (round (* 4503599627370496 (1- (* significand 2)))) exponent)))))) (let ((bits 0)) (declare (type (unsigned-byte 64) bits)) (setf (ldb (byte 1 63) bits) sign (ldb (byte 11 52) bits) exponent (ldb (byte 52 0) bits) significand) bits))) (defun decode-float64 (bits) (declare (type (unsigned-byte 64) bits)) (let* ((sign (ldb (byte 1 63) bits)) (exponent (ldb (byte 11 52) bits)) (significand (ldb (byte 52 0) bits))) (if (zerop exponent) (setf exponent 1) (setf (ldb (byte 1 52) significand) 1)) (unless (zerop sign) (setf significand (- significand))) (scale-float (float significand 1.0d0) (- exponent 1075)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(psetf)\n\nIssue: Macro call that should be transformed by PSETF", "input": "(psetf)", "output": "(defmacro PSETF ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) val))\n\nPattern to recognize: Macro call that should be transformed by c?", "input": "(c?-with-stored (v :bar store 'nothing) (bwhen (val (value v)) val))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(c? (bwhen-c-stored (v :bar store (quote nothing)) (bwhen (val (value v)) val)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(drelet nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DRELET", "input": "(drelet nil\n (progn))", "output": "(defmacro DRELET ...)", "macroexpand": "(dynamic-relet nil\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun/1 gets (str) (fgets-is-dumb str most-positive-fixnum stdin t))\n\nPattern to recognize: Macro call that should be transformed by defun/1", "input": "(defun/1 gets (str) (fgets-is-dumb str most-positive-fixnum stdin t))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun gets (str) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (fgets-is-dumb str most-positive-fixnum stdin t)) (defparameter gets (vacietis.c:mkptr& (symbol-function (quote gets)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(mvlet nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by MVLET", "input": "(mvlet nil\n nil)", "output": "(defmacro MVLET ...)", "macroexpand": "(progn nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dynamic-relet* nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DYNAMIC-RELET*", "input": "(dynamic-relet* nil)", "output": "(defmacro DYNAMIC-RELET* ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(some-> nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by SOME->", "input": "(some-> nil :key nil)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:g144 nil)\n (#:g144\n (if (null #:g144)\n nil\n (-> #:g144 :key))))\n (if (null #:g144)\n nil\n (-> #:g144 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-library libwinpthread)\n\nWrite a macro that addresses: Macro call that should be transformed by define-library", "input": "(define-library libwinpthread)", "output": "(defmacro define-library (name &body initargs)\n #+cffi\n `(change-class (cffi::get-foreign-library ',name)\n 'library\n ,@initargs)\n #-cffi\n `(make-instance 'library ,@initargs))", "macroexpand": "(change-class (cffi::get-foreign-library (quote libwinpthread)) (quote library))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun-compile-time walk-function (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper FUNCTION: ~S\" form)) (unless (= (length form) 2) (error \"FUNCTION must have one argument: ~S\" form)) (cond ((lambda-expression? (second form)) (if (and reduce-function nested?) (funcall reduce-function (funcall map-function form 'function-lambda) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (second form)) environment) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (peal-off-documentation-string-and-declarations (rest (rest (second form))) t))))) (funcall map-function form 'function-lambda))) ((valid-function-name? (second form)) (cond ((symbolp (second form)) (if (or (special-operator-p (second form)) (macro-function (second form) environment)) (error \"You can't reference the FUNCTION of a special form or~%~ macro: ~S\" form) (funcall map-function form 'function-symbol))) (t (funcall map-function form 'function-setf)))) (t (error \"Invalid argument to FUNCTION: ~S\" form))))\n\nIssue: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-function (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper FUNCTION: ~S\" form)) (unless (= (length form) 2) (error \"FUNCTION must have one argument: ~S\" form)) (cond ((lambda-expression? (second form)) (if (and reduce-function nested?) (funcall reduce-function (funcall map-function form 'function-lambda) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (second form)) environment) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (peal-off-documentation-string-and-declarations (rest (rest (second form))) t))))) (funcall map-function form 'function-lambda))) ((valid-function-name? (second form)) (cond ((symbolp (second form)) (if (or (special-operator-p (second form)) (macro-function (second form) environment)) (error \"You can't reference the FUNCTION of a special form or~%~ macro: ~S\" form) (funcall map-function form 'function-symbol))) (t (funcall map-function form 'function-setf)))) (t (error \"Invalid argument to FUNCTION: ~S\" form))))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-function (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper FUNCTION: ~S\" form)) (unless (= (length form) 2) (error \"FUNCTION must have one argument: ~S\" form)) (cond ((lambda-expression? (second form)) (if (and reduce-function nested?) (funcall reduce-function (funcall map-function form (quote function-lambda)) (funcall reduce-function (walk-lambda-list map-function reduce-function screamer? partial? nested? (second (second form)) environment) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (peal-off-documentation-string-and-declarations (rest (rest (second form))) t))))) (funcall map-function form (quote function-lambda)))) ((valid-function-name? (second form)) (cond ((symbolp (second form)) (if (or (special-operator-p (second form)) (macro-function (second form) environment)) (error \"You can't reference the FUNCTION of a special form or~%~ macro: ~S\" form) (funcall map-function form (quote function-symbol)))) (t (funcall map-function form (quote function-setf))))) (t (error \"Invalid argument to FUNCTION: ~S\" form)))) (eval-when (:compile-toplevel) (compile (quote walk-function))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect-max 'some-name)\n\nWhat needs to change: Macro call that should be transformed by COLLECT-MAX", "input": "(collect-max 'some-name)", "output": "(defmacro COLLECT-MAX ...)", "macroexpand": "(common-lisp:let* ((#:generator-387 (generator 'some-name))\n #:numbers-381\n (#:number-383 nil))\n (declare (type generator #:generator-387))\n (tagbody\n #:ll-388\n (setq #:numbers-381 (next-in #:generator-387 (go end)))\n (if (or (null #:number-383) (< #:number-383 #:numbers-381))\n (setq #:number-383 #:numbers-381))\n (go #:ll-388)\n end)\n (if (null #:number-383)\n (setq #:number-383 nil))\n #:number-383)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(builder :session (lambda (env) (when (string= (getf env :path-info) \"/expire\") (setf (getf (getf env :lack.session.options) :expire) t)) '(200 () (\"hi\"))))\n\nIssue: Macro call that should be transformed by builder", "input": "(builder :session (lambda (env) (when (string= (getf env :path-info) \"/expire\") (setf (getf (getf env :lack.session.options) :expire) t)) '(200 () (\"hi\"))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (find-middleware :session))) :initial-value (to-app (lambda (env) (when (string= (getf env :path-info) \"/expire\") (setf (getf (getf env :lack.session.options) :expire) t)) (quote (200 nil (\"hi\"))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n($op* op l)\n\nWrite a macro that addresses: Macro call that should be transformed by $op*", "input": "($op* op l)", "output": "(defmacro $op* (op &rest args)\n (let ((keys (gensym))\n\t(key (gensym))\n\t(kvc (gensym))\n\t(val (gensym)))\n `(multiple-value-bind (,keys ,val) (op-split (unwrap (list ($exp+ ,@args))))\n (let ((,kvc (kv (car ,keys) (kv ,op ,val))))\n\t (dolist (,key (cdr ,keys))\n\t (setf ,kvc (kv ,kvc (kv ,key (kv ,op ,val)))))\n\t ,kvc))))", "macroexpand": "(multiple-value-bind (#:g321 #:g324) (op-split (unwrap (list ($exp+ l)))) (let ((#:g323 (kv (car #:g321) (kv op #:g324)))) (dolist (#:g322 (cdr #:g321)) (setf #:g323 (kv #:g323 (kv #:g322 (kv op #:g324))))) #:g323))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(some->> 'some-name)\n\nWhat needs to change: Macro call that should be transformed by SOME->>", "input": "(some->> 'some-name)", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:g129 'some-name))\n #:g129)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html (:doctype) (:html (:body (:div (:p lorem-ipsum (:span) (:a :href \"\" :data-instant t \"Hello\") lorem-ipsum)))))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html (:doctype) (:html (:body (:div (:p lorem-ipsum (:span) (:a :href \"\" :data-instant t \"Hello\") lorem-ipsum)))))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(let ((*html* (ensure-html-stream *html*))) (progn (doctype) (with-tag (:html :lang *html-lang*) (with-tag (:body) (with-tag (:div) (with-tag (:p) lorem-ipsum (with-tag (:span)) (with-tag (:a :href \"\" :data-instant t) \"Hello\") lorem-ipsum))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(undefcategory :debug)\n\nPattern to recognize: Macro call that should be transformed by undefcategory", "input": "(undefcategory :debug)", "output": "(defmacro undefcategory (category &optional set)\n `(undefcategory-fn ',category ,set))", "macroexpand": "(undefcategory-fn (quote :debug) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7775} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(signal-syntax-error* (1- (lexer-pos lexer)) \"Character '~A' may not follow '(?'.\" next-char)\n\nProblem: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (1- (lexer-pos lexer)) \"Character '~A' may not follow '(?'.\" next-char)", "output": "(defmacro signal-syntax-error* (pos format-control &rest format-arguments)\n `(error 'ppcre-syntax-error\n :pos ,pos\n :format-control ,format-control\n :format-arguments (list ,@format-arguments)))", "macroexpand": "(error (quote ppcre-syntax-error) :pos (1- (lexer-pos lexer)) :format-control \"Character '~A' may not follow '(?'.\" :format-arguments (list next-char))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-> :g () (put 0) 1)\n\nWhat needs to change: Macro call that should be transformed by ->", "input": "(-> :g () (put 0) 1)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g nil (put 0) 1)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> :p (a) (declare (type fixnum a)) (the fixnum (+ a i)))\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> :p (a) (declare (type fixnum a)) (the fixnum (+ a i)))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :p (a) (declare (type fixnum a)) (the fixnum (+ a i)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-interpreter oid:+char+ \"char\" int 1)\n\nWrite a macro that addresses: Macro call that should be transformed by define-interpreter", "input": "(define-interpreter oid:+char+ \"char\" int 1)", "output": "(defmacro define-interpreter (oid name fields &body value)\n \"Shorthand for defining binary readers.\"\n (declare (ignore name)) ;; Names are there just for clarity\n `(set-sql-reader ,oid (binary-reader ,fields ,@value) :binary-p t))", "macroexpand": "(set-sql-reader cl-postgres-oid:+char+ (binary-reader int 1) :binary-p t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(aand 1 t (values it 2))\n\nWhat needs to change: Macro call that should be transformed by aand", "input": "(aand 1 t (values it 2))", "output": "(defmacro aand (first &rest rest)\n \"Like AND, except binds the first argument to IT (via LET) for the\nscope of the rest of the arguments.\"\n `(anaphoric and ,first ,@rest))", "macroexpand": "(anaphoric and 1 t (values it 2))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-decoder-simple-list-semantics (is (equalp (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"frob\\\"}\")) '((:bar . 46) (:xyzzy . t) (:quux . 98) (:prototype . ((:lisp-package . \"jsonTest\") (:lisp-class . \"frob\")))))))\n\nPattern to recognize: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (is (equalp (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"frob\\\"}\")) '((:bar . 46) (:xyzzy . t) (:quux . 98) (:prototype . ((:lisp-package . \"jsonTest\") (:lisp-class . \"frob\")))))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (is (equalp (decode-json-from-string (format nil input \"{\\\"lispPackage\\\":\\\"jsonTest\\\", \\\"lispClass\\\":\\\"frob\\\"}\")) (quote ((:bar . 46) (:xyzzy . t) (:quux . 98) (:prototype (:lisp-package . \"jsonTest\") (:lisp-class . \"frob\")))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(f_n\n nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by F_N", "input": "(f_n\n nil\n nil)", "output": "(defmacro F_N ...)", "macroexpand": "(lambda (&rest _) nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-forced-status (:failed) (false NIL))\n\nProblem: Macro call that should be transformed by with-forced-status", "input": "(with-forced-status (:failed) (false NIL))", "output": "(defmacro with-forced-status ((status &optional description &rest format-args) &body tests)\n `(eval-in-context\n *context*\n (make-instance 'controlling-result\n :expression ,status\n :child-status ,status\n :body (lambda () ,@tests)\n ,@(when description\n `(:description (format NIL ,description ,@format-args))))))", "macroexpand": "(eval-in-context *context* (make-instance (quote controlling-result) :expression :failed :child-status :failed :body (lambda nil (false nil))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-wcs-math-error-handling ((quot rem) (fround x y)) (check-wcs-math-result) rem)\n\nPattern to recognize: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling ((quot rem) (fround x y)) (check-wcs-math-result) rem)", "output": "(defmacro with-wcs-math-error-handling\n ((var-or-var-list\n (function x &optional (y nil y-supplied-p))\n &rest keyargs\n &key underflow-value)\n &body body)\n (declare (ignorable underflow-value))\n (let ((x_ (gensym)) (y_ (gensym)) (args_ (gensym))\n (var-list (ensure-list var-or-var-list)))\n `(let* ((,x_ ,x)\n (,y_ ,y)\n (,args_ (list ,x_ ,@(if y-supplied-p `(,y_)))))\n (declare (ignorable ,y_)\n (type list ,args_)\n (dynamic-extent ,args_))\n (catch 'return-from-with-wcs-math-error-handling\n (multiple-value-bind ,var-list\n (call-with-wcs-math-error-handler ',function ,args_\n ,@keyargs)\n (flet ((check-wcs-math-result\n (&optional (ret ,(first var-list))\n (arg-list ,args_))\n (check-wcs-math-result ret arg-list)))\n ,@body))))))", "macroexpand": "(let* ((#:g257 x) (#:g258 y) (#:g259 (list #:g257 #:g258))) (declare (ignorable #:g258) (type list #:g259) (dynamic-extent #:g259)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (quot rem) (call-with-wcs-math-error-handler (quote fround) #:g259) (flet ((check-wcs-math-result (&optional (ret quot) (arg-list #:g259)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result) rem))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda () :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by LAMBDA", "input": "(lambda () :key nil)", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda () :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(gathering nil)\n\nWhat needs to change: Macro call that should be transformed by GATHERING", "input": "(gathering nil)", "output": "(defmacro GATHERING ...)", "macroexpand": "(common-lisp:let ()\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-preprocessor-state-slots (state) (when if-section-skip-reason (begin-if-section state '(:skipped :if) nil) (return-from process-preprocessing-directive nil)) (unless (preprocessor-token-exists-p directive-token-list) (raise-no-preprocessor-token-error directive-symbol)) (let ((result (eval-if-expression directive-symbol directive-token-list state))) (begin-if-section state directive-token-list result)))\n\nProblem: Macro call that should be transformed by with-preprocessor-state-slots", "input": "(with-preprocessor-state-slots (state) (when if-section-skip-reason (begin-if-section state '(:skipped :if) nil) (return-from process-preprocessing-directive nil)) (unless (preprocessor-token-exists-p directive-token-list) (raise-no-preprocessor-token-error directive-symbol)) (let ((result (eval-if-expression directive-symbol directive-token-list state))) (begin-if-section state directive-token-list result)))", "output": "(defmacro with-preprocessor-state-slots ((state) &body body)\n `(with-accessors ((file-pathname pp-state-file-pathname)\n (token-list pp-state-token-list)\n (result-list pp-state-result-list)\n (line-number pp-state-line-number)\n (tokens-in-line pp-state-tokens-in-line)\n (macro-alist pp-state-macro-alist)\n (if-section-stack pp-state-if-section-stack)\n (if-section-skip-reason pp-state-if-section-skip-reason)\n (include-stack pp-state-include-stack))\n ,state\n ,@body))", "macroexpand": "(with-accessors ((file-pathname pp-state-file-pathname) (token-list pp-state-token-list) (result-list pp-state-result-list) (line-number pp-state-line-number) (tokens-in-line pp-state-tokens-in-line) (macro-alist pp-state-macro-alist) (if-section-stack pp-state-if-section-stack) (if-section-skip-reason pp-state-if-section-skip-reason) (include-stack pp-state-include-stack)) state (when if-section-skip-reason (begin-if-section state (quote (:skipped :if)) nil) (return-from process-preprocessing-directive nil)) (unless (preprocessor-token-exists-p directive-token-list) (raise-no-preprocessor-token-error directive-symbol)) (let ((result (eval-if-expression directive-symbol directive-token-list state))) (begin-if-section state directive-token-list result)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(builder (:mount \"/admin\" (lambda (env) `(200 () (\"admin\" ,(getf env :path-info))))) *app*)\n\nWhat needs to change: Macro call that should be transformed by builder", "input": "(builder (:mount \"/admin\" (lambda (env) `(200 () (\"admin\" ,(getf env :path-info))))) *app*)", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app172) (funcall (find-middleware :mount) #:app172 \"/admin\" (lambda (env) (sb-int:quasiquote (200 nil (\"admin\" #S(sb-impl::comma :expr (getf env :path-info) :kind 0))))))))) :initial-value (to-app *app*) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda () nil)\n\nWrite a macro that addresses: Macro call that should be transformed by LAMBDA", "input": "(lambda () nil)", "output": "(defmacro LAMBDA ...)", "macroexpand": "#'(lambda () nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (not (plusp 1)))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (not (plusp 1)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:v197 1)) (if (not (plusp #:v197)) (add-result (quote test-passed) :test-expr (quote (not (plusp 1)))) (process-failure (quote (not (plusp 1))) \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\" (quote 1) #:v197 (quote plusp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(labels* nil)\n\nWrite a macro that addresses: Macro call that should be transformed by LABELS*", "input": "(labels* nil)", "output": "(defmacro LABELS* ...)", "macroexpand": "(labels nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause-driver (for var-spec &sequence) \"Numbers\" (top-level-check) (if with-index (clause-error \"WITH-INDEX should not be specified for this clause\")) (check-sequence-keywords from upfrom downfrom to downto above below nil) (let* ((var (extract-var var-spec)) (initial (or from upfrom downfrom 0)) (limit (or to downto above below)) (step-func (if (or downfrom downto above) '- '+)) (test-func (cond (to '>) (downto '<) (below '>=) (above '<=))) (limit-var (if (and limit (not (constant? limit))) (make-var-and-binding 'limit limit :using-type-of (if (expression-type limit) limit var)))) (step-var (if (not (constantp by)) (make-var-and-binding 'step by :using-type-of by))) (step-thing (or step-var by)) (limit-code (or limit-var limit)) (init-val (eval-const-expr (list (if (eq step-func '+) '- '+) initial step-thing))) (test (if limit (progn (setq *loop-end-used?* t) `((if (,test-func ,var ,limit-code) (go ,*loop-end*)))) nil)) (next `((setq ,var (,step-func ,var ,step-thing)) .,test))) (make-binding var-spec init-val :type 'number) (return-driver-code :next next :variable var)))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause-driver (for var-spec &sequence) \"Numbers\" (top-level-check) (if with-index (clause-error \"WITH-INDEX should not be specified for this clause\")) (check-sequence-keywords from upfrom downfrom to downto above below nil) (let* ((var (extract-var var-spec)) (initial (or from upfrom downfrom 0)) (limit (or to downto above below)) (step-func (if (or downfrom downto above) '- '+)) (test-func (cond (to '>) (downto '<) (below '>=) (above '<=))) (limit-var (if (and limit (not (constant? limit))) (make-var-and-binding 'limit limit :using-type-of (if (expression-type limit) limit var)))) (step-var (if (not (constantp by)) (make-var-and-binding 'step by :using-type-of by))) (step-thing (or step-var by)) (limit-code (or limit-var limit)) (init-val (eval-const-expr (list (if (eq step-func '+) '- '+) initial step-thing))) (test (if limit (progn (setq *loop-end-used?* t) `((if (,test-func ,var ,limit-code) (go ,*loop-end*)))) nil)) (next `((setq ,var (,step-func ,var ,step-thing)) .,test))) (make-binding var-spec init-val :type 'number) (return-driver-code :next next :variable var)))", "output": "(defmacro defclause (clause-template &body body)\n (define-clause 'defun clause-template body nil))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (defun clause-for-3 (&key ((:for var-spec)) ((:from from)) ((:upfrom upfrom)) ((:downfrom downfrom)) ((:to to)) ((:downto downto)) ((:above above)) ((:below below)) ((:by by) 1) ((:with-index with-index)) generate) \"Numbers\" (top-level-check) (if with-index (clause-error \"WITH-INDEX should not be specified for this clause\")) (check-sequence-keywords from upfrom downfrom to downto above below nil) (let* ((var (extract-var var-spec)) (initial (or from upfrom downfrom 0)) (limit (or to downto above below)) (step-func (if (or downfrom downto above) (quote -) (quote +))) (test-func (cond (to (quote >)) (downto (quote <)) (below (quote >=)) (above (quote <=)))) (limit-var (if (and limit (not (constant? limit))) (make-var-and-binding (quote limit) limit :using-type-of (if (expression-type limit) limit var)))) (step-var (if (not (constantp by)) (make-var-and-binding (quote step) by :using-type-of by))) (step-thing (or step-var by)) (limit-code (or limit-var limit)) (init-val (eval-const-expr (list (if (eq step-func (quote +)) (quote -) (quote +)) initial step-thing))) (test (if limit (progn (setq *loop-end-used?* t) (sb-int:quasiquote ((if (#S(sb-impl::comma :expr test-func :kind 0) #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr limit-code :kind 0)) (go #S(sb-impl::comma :expr *loop-end* :kind 0)))))) nil)) (next (sb-int:quasiquote ((setq #S(sb-impl::comma :expr var :kind 0) (#S(sb-impl::comma :expr step-func :kind 0) #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr step-thing :kind 0))) . #S(sb-impl::comma :expr test :kind 0))))) (make-binding var-spec init-val :type (quote number)) (return-driver-code :next next :variable var))) (install-clause-info (quote (for)) (quote (for &optional :from :upfrom :downfrom :to :downto :above :below :by :with-index)) (quote clause-for-3) \"Numbers\" t) (quote (for var-spec &optional :from from :upfrom upfrom :downfrom downfrom :to to :downto downto :above above :below below :by (by 1) :with-index with-index)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(enable-quasi-quote-syntax nil nil)\n\nIssue: Macro call that should be transformed by ENABLE-QUASI-QUOTE-SYNTAX", "input": "(enable-quasi-quote-syntax nil nil)", "output": "(defmacro ENABLE-QUASI-QUOTE-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quote-syntax-in-readtable nil nil :nested-quasi-quote-wrapper\n quasi-quote-wrapper :start-character nil\n :dispatch-character nil :end-character\n nil :unquote-character #\\COMMA\n :splice-character #\\COMMERCIAL_AT\n :destructive-splice-character\n #\\FULL_STOP :dispatched-quasi-quote-name\n nil :toplevel-reader-wrapper #'identity\n :unquote-readtable-case nil :body-reader\n nil :readtable-case nil)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-modf-rewrite fifth (expr) `(car (cddddr ,(second expr))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite fifth (expr) `(car (cddddr ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote fifth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cddddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun/1 tolower (c) (char-downcase (code-char c)))\n\nPattern to recognize: Macro call that should be transformed by defun/1", "input": "(defun/1 tolower (c) (char-downcase (code-char c)))", "output": "(defmacro defun/1 (name arglist &body body)\n \"Lisp-1 defun; makes function pointers work.\"\n `(progn\n (defun ,name ,arglist\n (declare (optimize (speed 0) (debug 3)\n ;; FIXME: Why do minor warnings result in load errors?\n #+sbcl (sb-ext:inhibit-warnings 3)))\n \n ,@body)\n (defparameter ,name (vacietis.c:mkptr& (symbol-function ',name)))))", "macroexpand": "(progn (defun tolower (c) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (char-downcase (code-char c))) (defparameter tolower (vacietis.c:mkptr& (symbol-function (quote tolower)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-method-combination% and :operator and :identity-with-one-argument t)\n\nProblem: Macro call that should be transformed by define-method-combination%", "input": "(define-method-combination% and :operator and :identity-with-one-argument t)", "output": "(defmacro define-method-combination% (name &rest args)\n \"Define a method-combination for the static-dispatch system only.\n\n Arguments are of the same form as to CL:DEFINE-METHOD-COMBINATION.\"\n\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf\n (combination-function ',name)\n ,(match args\n ((or nil\n (list* (and (type symbol) (not nil)) _))\n\n (destructuring-bind (&key (operator name) (identity-with-one-argument nil))\n args\n\n `(method-combination-function-short ,name ,operator ,identity-with-one-argument)))\n\n (_\n `(method-combination-function ,name ,@args))))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (combination-function (quote and)) (method-combination-function-short and and t)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(doseq! (item seq :start start :end end) (setf item value))\n\nWhat needs to change: Macro call that should be transformed by doseq", "input": "(doseq! (item seq :start start :end end) (setf item value))", "output": "(defmacro doseq (name/seq &body body)\n \"Iterate over the elements of a single sequence SEQUENCE.\n\n Same as DO-SEQUENCES but for the special case of iterating over a\n single sequence.\n\n The macro arguments can be in one of the following two forms:\n\n 1. (NAME (ELEMENT SEQUENCE &REST ARGS) &BODY BODY)\n\n 2. ((ELEMENT SEQUENCE &REST ARGS) &BODY BODY)\n\n NAME is the block name, NIL if not given.\n\n ELEMENT is the variable to which each element of the sequence is\n bound.\n\n SEQUENCE is the sequence, with ARGS being the remaining arguments\n passed to the ITERATOR function.\n\n BODY is the list of forms evaluated on each iteration.\"\n\n (let-if ((name name/seq)\n (seq (first body) name/seq)\n (body (rest body) body))\n (symbolp name/seq)\n\n (destructuring-bind (element sequence &rest args) seq\n `(do-sequences ,name\n ((,element ,sequence ,@args))\n ,@body))))", "macroexpand": "(do-sequences! nil ((item seq :start start :end end)) (setf item value))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-neo4j-fun get-path (node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) :post (:uri-spec (format nil \"node/~A/path\" node-id)) (:encode (list (list (cons \"to\" to-node-id) :node-url) (list (cons \"relationships\" relationships)) (list (cons \"max_depth\" max-depth)) (list (cons \"algorithm\" (case algorithm (:shortest-path \"shortestPath\") (:all-paths \"allPaths\") (:all-simple-paths \"allSimplePaths\") (:dijkstra \"dijkstra\"))))) :object) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'path-not-found-error :uri uri))))\n\nWhat needs to change: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun get-path (node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) :post (:uri-spec (format nil \"node/~A/path\" node-id)) (:encode (list (list (cons \"to\" to-node-id) :node-url) (list (cons \"relationships\" relationships)) (list (cons \"max_depth\" max-depth)) (list (cons \"algorithm\" (case algorithm (:shortest-path \"shortestPath\") (:all-paths \"allPaths\") (:all-simple-paths \"allSimplePaths\") (:dijkstra \"dijkstra\"))))) :object) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'path-not-found-error :uri uri))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun get-path (&key node-id to-node-id relationships (max-depth 3) (algorithm :shortest-path)) (let ((uri (format nil \"node/~A/path\" node-id)) (json (encode-neo4j-json-payload (list (list (cons \"to\" to-node-id) :node-url) (list (cons \"relationships\" relationships)) (list (cons \"max_depth\" max-depth)) (list (cons \"algorithm\" (case algorithm (:shortest-path \"shortestPath\") (:all-paths \"allPaths\") (:all-simple-paths \"allSimplePaths\") (:dijkstra \"dijkstra\"))))) :object))) (make-neo4j-request :post uri json (list (list 200 (lambda (body uri json) (decode-neo4j-json-output body))) (list 404 (lambda (body uri json) (error (quote path-not-found-error) :uri uri))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-decoder-simple-list-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :cl-user))))\n\nIssue: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :cl-user))))", "output": "(defmacro with-decoder-simple-list-semantics (&body body)\n \"Execute BODY in a dynamic environement where the decoder semantics\nis such as set by SET-DECODER-SIMPLE-LIST-SEMANTICS.\"\n `(with-shadowed-custom-vars\n (set-decoder-simple-list-semantics)\n ,@body))", "macroexpand": "(with-shadowed-custom-vars (set-decoder-simple-list-semantics) (setf x (decode-json-from-string \"{\\\"x\\\":1}\")) (is (equal (symbol-package (caar x)) (find-package :cl-user))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-error invalid-form-list () (code) \"Tried to compile form however the first element of the form was a list: ~s\" code)\n\nPattern to recognize: Macro call that should be transformed by define-error", "input": "(define-error invalid-form-list () (code) \"Tried to compile form however the first element of the form was a list: ~s\" code)", "output": "(defmacro define-error (name (&key (error-type 'varjo-error) (prefix \"Varjo\"))\n (&rest args) error-string &body body)\n `(defcondition ,name (:error-type ,error-type :prefix ,prefix) ,args\n ,error-string ,@body))", "macroexpand": "(defcondition invalid-form-list (:error-type varjo-error :prefix \"Varjo\") (code) \"Tried to compile form however the first element of the form was a list: ~s\" code)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(augment arglist (list 'generate))\n\nWrite a macro that addresses: Macro call that should be transformed by augment", "input": "(augment arglist (list 'generate))", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf arglist (nconc arglist (list (quote generate))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(lambda* nil)\n\nProblem: Macro call that should be transformed by LAMBDA*", "input": "(lambda* nil)", "output": "(defmacro LAMBDA* ...)", "macroexpand": "(lambda () (the t nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-file-name-lock-held () (format nil \"~:@(~36,8,'0R~)\" (random (expt 36 8) *name-random-state*)))\n\nIssue: Macro call that should be transformed by with-file-name-lock-held", "input": "(with-file-name-lock-held () (format nil \"~:@(~36,8,'0R~)\" (random (expt 36 8) *name-random-state*)))", "output": "(defmacro with-file-name-lock-held (() &body body)\n `(bordeaux-threads:with-lock-held (*create-file-name-lock*)\n ,@body))", "macroexpand": "(bordeaux-threads:with-lock-held (*create-file-name-lock*) (format nil \"~:@(~36,8,'0R~)\" (random (expt 36 8) *name-random-state*)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym finally :finally)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym finally :finally)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote finally) (quote synonym)) (quote :finally)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause symbols-in (package-or-packages &rest symbol-types) \"Iterates over the symbols in one or more packages. Symbol-types follows the specification of cl:with-package-iterator.\" (let ((variables (ensure-list *iteration-variable*)) (package-list (ensure-list package-or-packages)) (symbol-types (or symbol-types '(:external))) (iterator (gensym \"PACKAGE-ITERATOR\")) (test (gensym \"TEST\"))) (unless (<= 1 (length variables) 3) (error \"Invalid variable specification for package entry, expected (symbol &optional accessibility package) but got ~S\" *iteration-variable*)) `(,(make-wrapper :function (lambda (body) `(with-package-iterator (,iterator (list ,@package-list) ,@symbol-types) ,body))) ,(make-iteration :bindings `(,test ,@variables) :initializations `((setf (values ,test ,@variables) (,iterator))) :steps `((setf (values ,test ,@variables) (,iterator))) :postconditions `((not (null ,test)))))))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause symbols-in (package-or-packages &rest symbol-types) \"Iterates over the symbols in one or more packages. Symbol-types follows the specification of cl:with-package-iterator.\" (let ((variables (ensure-list *iteration-variable*)) (package-list (ensure-list package-or-packages)) (symbol-types (or symbol-types '(:external))) (iterator (gensym \"PACKAGE-ITERATOR\")) (test (gensym \"TEST\"))) (unless (<= 1 (length variables) 3) (error \"Invalid variable specification for package entry, expected (symbol &optional accessibility package) but got ~S\" *iteration-variable*)) `(,(make-wrapper :function (lambda (body) `(with-package-iterator (,iterator (list ,@package-list) ,@symbol-types) ,body))) ,(make-iteration :bindings `(,test ,@variables) :initializations `((setf (values ,test ,@variables) (,iterator))) :steps `((setf (values ,test ,@variables) (,iterator))) :postconditions `((not (null ,test)))))))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro symbols-in (package-or-packages &rest symbol-types) \"Iterates over the symbols in one or more packages. Symbol-types follows the specification of cl:with-package-iterator.\" (let ((variables (ensure-list *iteration-variable*)) (package-list (ensure-list package-or-packages)) (symbol-types (or symbol-types (quote (:external)))) (iterator (gensym \"PACKAGE-ITERATOR\")) (test (gensym \"TEST\"))) (unless (<= 1 (length variables) 3) (error \"Invalid variable specification for package entry, expected (symbol &optional accessibility package) but got ~S\" *iteration-variable*)) (sb-int:quasiquote (#S(sb-impl::comma :expr (make-wrapper :function (lambda (body) (sb-int:quasiquote (with-package-iterator (#S(sb-impl::comma :expr iterator :kind 0) (list #S(sb-impl::comma :expr package-list :kind 2)) #S(sb-impl::comma :expr symbol-types :kind 2)) #S(sb-impl::comma :expr body :kind 0))))) :kind 0) #S(sb-impl::comma :expr (make-iteration :bindings (sb-int:quasiquote (#S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr variables :kind 2))) :initializations (sb-int:quasiquote ((setf (values #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr variables :kind 2)) (#S(sb-impl::comma :expr iterator :kind 0))))) :steps (sb-int:quasiquote ((setf (values #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr variables :kind 2)) (#S(sb-impl::comma :expr iterator :kind 0))))) :postconditions (sb-int:quasiquote ((not (null #S(sb-impl::comma :expr test :kind 0)))))) :kind 0))))) (pushnew (quote symbols-in) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(collect-nth nil (progn))\n\nWhat needs to change: Macro call that should be transformed by COLLECT-NTH", "input": "(collect-nth nil (progn))", "output": "(defmacro COLLECT-NTH ...)", "macroexpand": "(common-lisp:let* ((#:generator-409 (generator (progn)))\n #:items-401\n (#:counter-403 nil)\n (#:item-404 nil))\n (declare (type generator #:generator-409)\n (type (null-or fixnum) #:counter-403)\n (type (null-or t) #:item-404))\n (tagbody\n #:ll-410\n (setq #:items-401 (next-in #:generator-409 (go end)))\n (when (zerop #:counter-403) (setq #:item-404 #:items-401) (go end))\n (decf #:counter-403)\n (go #:ll-410)\n end)\n #:item-404)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-yield-binds (format nil \"ALTER COLUMN ~A~:[~; TYPE ~:*~A~]~:[~; SET DEFAULT ~:*~A~]~:[~; DROP DEFAULT~]~A\" (yield (alter-column-clause-column-name clause)) (and (alter-column-clause-type clause) (let ((*use-placeholder* nil)) (yield (alter-column-clause-type clause)))) (and (alter-column-clause-set-default clause) (yield (alter-column-clause-set-default clause))) (alter-column-clause-drop-default clause) (cond ((eq (alter-column-clause-not-null clause) :unspecified) \"\") ((alter-column-clause-not-null clause) \" SET NOT NULL\") (T \" DROP NOT NULL\"))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"ALTER COLUMN ~A~:[~; TYPE ~:*~A~]~:[~; SET DEFAULT ~:*~A~]~:[~; DROP DEFAULT~]~A\" (yield (alter-column-clause-column-name clause)) (and (alter-column-clause-type clause) (let ((*use-placeholder* nil)) (yield (alter-column-clause-type clause)))) (and (alter-column-clause-set-default clause) (yield (alter-column-clause-set-default clause))) (alter-column-clause-drop-default clause) (cond ((eq (alter-column-clause-not-null clause) :unspecified) \"\") ((alter-column-clause-not-null clause) \" SET NOT NULL\") (T \" DROP NOT NULL\"))))", "output": "(defmacro with-yield-binds (&body body)\n `(let ((*bind-values* nil)\n (*use-global-bind-values* t))\n (values\n (progn ,@body)\n (loop for bind in (reverse *bind-values*)\n append bind))))", "macroexpand": "(let ((*bind-values* nil) (*use-global-bind-values* t)) (values (progn (format nil \"ALTER COLUMN ~A~:[~; TYPE ~:*~A~]~:[~; SET DEFAULT ~:*~A~]~:[~; DROP DEFAULT~]~A\" (yield (alter-column-clause-column-name clause)) (and (alter-column-clause-type clause) (let ((*use-placeholder* nil)) (yield (alter-column-clause-type clause)))) (and (alter-column-clause-set-default clause) (yield (alter-column-clause-set-default clause))) (alter-column-clause-drop-default clause) (cond ((eq (alter-column-clause-not-null clause) :unspecified) \"\") ((alter-column-clause-not-null clause) \" SET NOT NULL\") (t \" DROP NOT NULL\")))) (loop for bind in (reverse *bind-values*) append bind)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do+ outer-loop (do+ inner-loop (do+ (terminate outer-loop 3))))\n\nWrite a macro that addresses: Macro call that should be transformed by do+", "input": "(do+ outer-loop (do+ inner-loop (do+ (terminate outer-loop 3))))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil outer-loop (do+ inner-loop (do+ (terminate outer-loop 3))))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-color (:cyan :stream stream) (with-additional-indent (reporter stream \"- \") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream))\n\nWrite a macro that addresses: Macro call that should be transformed by with-color", "input": "(with-color (:cyan :stream stream) (with-additional-indent (reporter stream \"- \") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream))", "output": "(defmacro with-color ((color &rest args) &body body)\n (cond\n ((or (eq color :gray)\n (eq color :grey))\n `(if *enable-colors*\n (with-gray ,(or (getf args :stream) t) ,@body)\n (progn ,@body)))\n (T `(if *enable-colors*\n (if (or (eq ,color :gray)\n (eq ,color :grey)\n (eq ,color cl-colors:+gray+)\n (eq ,color cl-colors:+grey+))\n (with-gray ,(or (getf args :stream) t) ,@body)\n (cl-ansi-text:with-color (,color ,@args) ,@body))\n (progn ,@body)))))", "macroexpand": "(if *enable-colors* (if (or (eq :cyan :gray) (eq :cyan :grey) (eq :cyan +gray+) (eq :cyan +grey+)) (with-gray stream (with-additional-indent (reporter stream \"- \") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream)) (cl-ansi-text:with-color (:cyan :stream stream) (with-additional-indent (reporter stream \"- \") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream))) (progn (with-additional-indent (reporter stream \"- \") (let ((description (possible-report-description report))) (when description (format/indent reporter stream description)))) (terpri stream)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n($send nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by $SEND", "input": "($send nil (progn))", "output": "(defmacro $SEND ...)", "macroexpand": "(send-message nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-shell-component myth :input-type \"myth\" :output-type \"css\" :shell-command \"myth\")\n\nWrite a macro that addresses: Macro call that should be transformed by define-shell-component", "input": "(define-shell-component myth :input-type \"myth\" :output-type \"css\" :shell-command \"myth\")", "output": "(defmacro define-shell-component (name &key input-type output-type shell-command)\n \"Define an ASDF component that's compiled by running a shell command.\"\n `(define-component ,name\n :input-type ,input-type\n :output-type ,output-type\n :compile-function (lambda (input-pathname output-pathname)\n (inferior-shell:run (list ,@(ensure-list shell-command)\n input-pathname\n output-pathname)\n :show t))))", "macroexpand": "(define-component myth :input-type \"myth\" :output-type \"css\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run (list \"myth\" input-pathname output-pathname) :show t)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-global-var nil nil)\n\nWhat needs to change: Macro call that should be transformed by DEFINE-GLOBAL-VAR", "input": "(define-global-var nil nil)", "output": "(defmacro DEFINE-GLOBAL-VAR ...)", "macroexpand": "(sb-ext:defglobal nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-html-string (:x-y \"Hello\"))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:x-y \"Hello\"))", "output": "(defmacro with-html (&body body &environment env)\n \"Interpret BODY as HTML. Consult README.txt for the syntax.\"\n `(let ((*html* (ensure-html-stream *html*)))\n ,(if (and (null (cdr body)) (atom (car body)))\n (car body)\n `(progn ,@(parse-html body env)))))", "macroexpand": "(with-output-to-string (*html*) (with-html (:x-y \"Hello\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(reduced-typecase 'some-name)\n\nWhat needs to change: Macro call that should be transformed by REDUCED-TYPECASE", "input": "(reduced-typecase 'some-name)", "output": "(defmacro REDUCED-TYPECASE ...)", "macroexpand": "(typecase 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) (1+ val)))\n\nWrite a macro that addresses: Macro call that should be transformed by c?", "input": "(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) (1+ val)))", "output": "(defmacro c? (&body body)\n `(make-c-dependent\n :code ',body\n :value-state :unevaluated\n :rule (c-lambda ,@body)))", "macroexpand": "(c? (bwhen-c-stored (v :foo store (quote nothing)) (bwhen (val (value v)) (1+ val))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-final-class nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by DEFINE-FINAL-CLASS", "input": "(define-final-class nil :key nil)", "output": "(defmacro DEFINE-FINAL-CLASS ...)", "macroexpand": "(defclass nil :key nil (:metaclass final-class))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(assoc-cdr :authorization--endpoint disc)\n\nWhat needs to change: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr :authorization--endpoint disc)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc :authorization--endpoint disc :test (function eql)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))\n\nProblem: Macro call that should be transformed by ->", "input": "(-> :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :p (a) (declare (type fixnum a)) (the fixnum (1+ a)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-yield)\n\nWhat needs to change: Macro call that should be transformed by WITH-YIELD", "input": "(with-yield)", "output": "(defmacro WITH-YIELD ...)", "macroexpand": "(isolate-cont\n (enable-yield\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause initially (&rest forms) \"Evaluates before the first iteration.\" (mapcar (lambda (form) (make-initialization :form form)) forms))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause initially (&rest forms) \"Evaluates before the first iteration.\" (mapcar (lambda (form) (make-initialization :form form)) forms))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro initially (&rest forms) \"Evaluates before the first iteration.\" (mapcar (lambda (form) (make-initialization :form form)) forms)) (pushnew (quote initially) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-<>\n nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by -<>", "input": "(-<>\n nil\n nil)", "output": "(defmacro -<> ...)", "macroexpand": "(let* ((#:var204 nil) (#:var205 (nil #:var204)))\n #:var205)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(cond->> 'some-name)\n\nPattern to recognize: Macro call that should be transformed by COND->>", "input": "(cond->> 'some-name)", "output": "(defmacro COND->> ...)", "macroexpand": "(let* ((#:|cond139| 'some-name))\n #:|cond139|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defvariant nil\n nil)\n\nIssue: Macro call that should be transformed by DEFVARIANT", "input": "(defvariant nil\n nil)", "output": "(defmacro DEFVARIANT ...)", "macroexpand": "(progn\n (defstruct (nil (:constructor nil)))\n (defstruct (nil-nil (:include nil)))\n (defmacro match-nil (expr &body match-cases)\n #A((34) base-char . \"Match values of variant type: NIL.\")\n (let ((expr-var (gensym \"-val\")))\n `(let ((,expr-var ,expr))\n ,(build-dispatch `,'nil `,'(nil) match-cases expr-var)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-indentation (with-xml-group-element (s \"tspan\" opts) (string->xml s text)))\n\nPattern to recognize: Macro call that should be transformed by with-indentation", "input": "(with-indentation (with-xml-group-element (s \"tspan\" opts) (string->xml s text)))", "output": "(defmacro with-indentation (&body body)\n `(let ((*indent-level* (+ *indent-level* *indent-spacing*)))\n ,@body))", "macroexpand": "(let ((*indent-level* (+ *indent-level* *indent-spacing*))) (with-xml-group-element (s \"tspan\" opts) (string->xml s text)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(builder (:backtrace :output *test-error-output* :result-on-error '(500 (:content-type \"text/plain\") (\"Internal Server Error\"))) (lambda (env) (declare (ignore env)) (error \"Error occured\")))\n\nIssue: Macro call that should be transformed by builder", "input": "(builder (:backtrace :output *test-error-output* :result-on-error '(500 (:content-type \"text/plain\") (\"Internal Server Error\"))) (lambda (env) (declare (ignore env)) (error \"Error occured\")))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app196) (funcall (find-middleware :backtrace) #:app196 :output *test-error-output* :result-on-error (quote (500 (:content-type \"text/plain\") (\"Internal Server Error\"))))))) :initial-value (to-app (lambda (env) (declare (ignore env)) (error \"Error occured\"))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(draw group (:line :x1 x :y1 y :x2 dx :y2 dy))\n\nPattern to recognize: Macro call that should be transformed by draw", "input": "(draw group (:line :x1 x :y1 y :x2 dx :y2 dy))", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g158 (funcall (function make-svg-element) :line (append (list :x1 x :y1 y :x2 dx :y2 dy) (list))))) (add-element group #:g158) #:g158)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :one () (increment))\n\nProblem: Macro call that should be transformed by ->", "input": "(-> :one () (increment))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :one nil (increment))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ps-html nil)\n\nIssue: Macro call that should be transformed by PS-HTML", "input": "(ps-html nil)", "output": "(defmacro PS-HTML ...)", "macroexpand": "(stringify nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-slots nil\n (progn))\n\nIssue: Macro call that should be transformed by WITH-SLOTS", "input": "(with-slots nil\n (progn))", "output": "(defmacro WITH-SLOTS ...)", "macroexpand": "(let ((#:g179 (progn)))\n (declare (ignorable #:g179))\n (symbol-macrolet ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym :finding :find)\n\nWhat needs to change: Macro call that should be transformed by defsynonym", "input": "(defsynonym :finding :find)", "output": "(defmacro defsynonym (symbol synonym)\n \"Set SYNONYM for a SYMBOL. \"\n `(eval-always\n (setf (get ',symbol 'synonym) ',synonym)))", "macroexpand": "(eval-always (setf (get (quote :finding) (quote synonym)) (quote :find)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(deferror \"22012\" db-division-by-zero data-exception)\n\nPattern to recognize: Macro call that should be transformed by deferror", "input": "(deferror \"22012\" db-division-by-zero data-exception)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition db-division-by-zero (data-exception) nil) (setf (gethash \"22012\" *error-table*) (quote db-division-by-zero)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-test subtest :parent example (fail (error \"An expected failure.\")) (fail (warn \"An expected warning.\") warning))\n\nIssue: Macro call that should be transformed by define-test", "input": "(define-test subtest :parent example (fail (error \"An expected failure.\")) (fail (warn \"An expected warning.\") warning))", "output": "(defmacro define-test (name &body arguments-and-body)\n (destructuring-bind (nparent name) (if (listp name) name (list NIL name))\n (form-fiddle:with-body-options (body options parent home (test-class 'test) (compile-at :compile-time) defun) arguments-and-body\n (let ((body (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test #'eql))\n (defs (remove 'define-test body :key (lambda (a) (when (listp a) (car a))) :test-not #'eql))\n (home-form (or home `(find-package ,(package-name *package*)))))\n (when (and parent nparent)\n (error \"Cannot specify parent through name and through a keyword argument at the same time!\"))\n `(let ((*package* (find-package ,(package-name *package*)))) ; Make sure package stays consistent throughout initialisation.\n (setf (find-test ',name ,home-form)\n (ensure-test ',test-class\n :name ',name\n :home ,home-form\n :tests (list ,@(loop for form in body\n collect (ecase compile-at\n (:compile-time `(lambda () ,form))\n (:execute `(lambda () (call-compile ',form))))))\n :parent ',(or parent nparent)\n ,@(loop for option in options\n collect `',option)))\n ,@(loop for (def subname . body) in defs\n collect `(,def (,name ,subname)\n :home ,home\n ,@body))\n ,@(when defun\n `((defun ,(if (stringp name) (read-symbol name) name) (&rest test-args)\n (apply #'test (find-test ',name ,home-form) test-args))))\n ',name)))))", "macroexpand": "(let ((*package* (find-package #A((9) base-char . \"PARACHUTE\")))) (setf (find-test (quote subtest) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote subtest) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (fail (error \"An expected failure.\"))) (lambda nil (fail (warn \"An expected warning.\") warning))) :parent (quote example))) (quote subtest))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclause summing-to-and-returning (vars &optional result-processor) \"Same as summing-to, but also returns the value of each at the end of the loop.\" `((summing-to ,vars ,result-processor) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))\n\nIssue: Macro call that should be transformed by defclause", "input": "(defclause summing-to-and-returning (vars &optional result-processor) \"Same as summing-to, but also returns the value of each at the end of the loop.\" `((summing-to ,vars ,result-processor) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro summing-to-and-returning (vars &optional result-processor) \"Same as summing-to, but also returns the value of each at the end of the loop.\" (sb-int:quasiquote ((summing-to #S(sb-impl::comma :expr vars :kind 0) #S(sb-impl::comma :expr result-processor :kind 0)) #S(sb-impl::comma :expr (mapcar (lambda (var) (sb-int:quasiquote (returning #S(sb-impl::comma :expr var :kind 0)))) (ensure-list vars)) :kind 2)))) (pushnew (quote summing-to-and-returning) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(action (:after node-match) #'apply-lift)\n\nProblem: Macro call that should be transformed by action", "input": "(action (:after node-match) #'apply-lift)", "output": "(defmacro action ((when type &rest args) &body body)\n \"Construct an action block, turning `body` into a lambda function\naccepting `args` if `args` are provided. If there are no `args`, then\n`body` is assumed to be a function object and is used directly with\n`when` and `type` to create an `action` instance. Otherwise, the first\nargument in `args` is declared to be a node of type `type`, and the\n`args` and `body` are used to generate a lambda function.\"\n (check-type when keyword)\n (check-type type symbol)\n (assert (subtypep type 'node))\n (assert (or (not (endp args)) (= 1 (length body))))\n (if (endp args)\n `(make-action ',when ',type ,@body)\n `(make-action ',when ',type\n (lambda (,@args)\n (declare (type ,type ,(first args)))\n ,@body))))", "macroexpand": "(make-action (quote :after) (quote node-match) (function apply-lift))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-handle-interrupt (lambda () (format *error-output* \"Interrupted\")) (prog1 (apply #'clack.handler:run app server :port port :debug debug :use-thread use-thread (delete-from-plist args :server :port :debug :use-thread)) (when (and use-thread (not silent)) (format t \"~&~:(~A~) server is started.~%Listening on ~A:~A.~%\" server address port))))\n\nProblem: Macro call that should be transformed by with-handle-interrupt", "input": "(with-handle-interrupt (lambda () (format *error-output* \"Interrupted\")) (prog1 (apply #'clack.handler:run app server :port port :debug debug :use-thread use-thread (delete-from-plist args :server :port :debug :use-thread)) (when (and use-thread (not silent)) (format t \"~&~:(~A~) server is started.~%Listening on ~A:~A.~%\" server address port))))", "output": "(defmacro with-handle-interrupt (int-handler &body body)\n (let ((main (gensym \"MAIN\")))\n `(flet ((,main () ,@body))\n #+(or sbcl ccl clisp allegro ecl)\n (handler-case\n (let (#+ccl (ccl:*break-hook* (lambda (condition hook)\n (declare (ignore hook))\n (error condition))))\n (,main))\n (#+sbcl sb-sys:interactive-interrupt\n #+ccl ccl:interrupt-signal-condition\n #+clisp system::simple-interrupt-condition\n #+ecl ext:interactive-interrupt\n #+allegro excl:interrupt-signal\n ()\n (funcall ,int-handler)))\n #-(or sbcl ccl clisp allegro ecl)\n (,main))))", "macroexpand": "(flet ((#:main163 nil (prog1 (apply (function run) app server :port port :debug debug :use-thread use-thread (delete-from-plist args :server :port :debug :use-thread)) (when (and use-thread (not silent)) (format t \"~&~:(~A~) server is started.~%Listening on ~A:~A.~%\" server address port))))) (handler-case (let nil (#:main163)) (sb-sys:interactive-interrupt nil (funcall (lambda nil (format *error-output* \"Interrupted\"))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(acond (:foo))\n\nWrite a macro that addresses: Macro call that should be transformed by acond", "input": "(acond (:foo))", "output": "(defmacro acond (&body clauses)\n \"Like COND, except result of each test-form is bound to IT (via LET) for the\nscope of the corresponding clause.\"\n (labels ((rec (clauses)\n\t (if clauses\n\t\t (destructuring-bind ((test &body body) . rest) clauses\n\t\t (if body\n\t\t `(anaphoric if ,test (progn ,@body) ,(rec rest))\n\t\t `(anaphoric if ,test it ,(rec rest))))\n\t\t nil)))\n (rec clauses)))", "macroexpand": "(let ((#:it :foo)) (if #:it #:it (acond)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (or (typep (node-slot expression) 'function-call) (typep (node-slot expression) 'infix-expression) (typep (node-slot expression) 'prefix-expression) (typep (node-slot expression) 'postfix-expression)) (format stream \"~&~a\" indent))\n\nProblem: Macro call that should be transformed by when", "input": "(when (or (typep (node-slot expression) 'function-call) (typep (node-slot expression) 'infix-expression) (typep (node-slot expression) 'prefix-expression) (typep (node-slot expression) 'postfix-expression)) (format stream \"~&~a\" indent))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (or (typep (node-slot expression) (quote function-call)) (typep (node-slot expression) (quote infix-expression)) (typep (node-slot expression) (quote prefix-expression)) (typep (node-slot expression) (quote postfix-expression))) (format stream \"~&~a\" indent))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defgenerator product (&rest lists) \"Iterates through each of the supplied lists with nested dolists, yielding an element from each for every iteration of the innermost loop. The yielded values cycle in an odometer-like fashion, with the first value changing seldom and the last changing on every yield. Eg: (product '(a b c d) '(x y)) -(values)-> (a x) (a y) (b x) (b y) (c x) (c y)... \" (labels ((listholder (lists) (if (null lists) (lambda (stack) (apply #'yield (reverse stack))) (let ((nextfunc (listholder (cdr lists)))) (lambda (stack) (dolist (itm (car lists)) (funcall nextfunc (cons itm stack)))))))) (funcall (listholder lists) nil)))\n\nWhat needs to change: Macro call that should be transformed by defgenerator", "input": "(defgenerator product (&rest lists) \"Iterates through each of the supplied lists with nested dolists, yielding an element from each for every iteration of the innermost loop. The yielded values cycle in an odometer-like fashion, with the first value changing seldom and the last changing on every yield. Eg: (product '(a b c d) '(x y)) -(values)-> (a x) (a y) (b x) (b y) (c x) (c y)... \" (labels ((listholder (lists) (if (null lists) (lambda (stack) (apply #'yield (reverse stack))) (let ((nextfunc (listholder (cdr lists)))) (lambda (stack) (dolist (itm (car lists)) (funcall nextfunc (cons itm stack)))))))) (funcall (listholder lists) nil)))", "output": "(defmacro defgenerator (name arguments &body body)\n (multiple-value-bind (remaining-forms declarations doc-string)\n (alexandria:parse-body body :documentation t)\n `(defun ,name ,arguments\n ,doc-string\n ,@declarations\n (with-yield\n\t ,@remaining-forms))))", "macroexpand": "(defun product (&rest lists) \"Iterates through each of the supplied lists with nested dolists, yielding an element from each for every iteration of the innermost loop. The yielded values cycle in an odometer-like fashion, with the first value changing seldom and the last changing on every yield. Eg: (product '(a b c d) '(x y)) -(values)-> (a x) (a y) (b x) (b y) (c x) (c y)... \" (with-yield (labels ((listholder (lists) (if (null lists) (lambda (stack) (apply (function yield) (reverse stack))) (let ((nextfunc (listholder (cdr lists)))) (lambda (stack) (dolist (itm (car lists)) (funcall nextfunc (cons itm stack)))))))) (funcall (listholder lists) nil))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(iterate nil)\n\nWhat needs to change: Macro call that should be transformed by ITERATE", "input": "(iterate nil)", "output": "(defmacro ITERATE ...)", "macroexpand": "(progn (tagbody #:ll-246 ((lambda ())) (go #:ll-246)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is-true (with-*test-dribble* nil (explain! (run 'is1))))\n\nIssue: Macro call that should be transformed by is-true", "input": "(is-true (with-*test-dribble* nil (explain! (run 'is1))))", "output": "(defmacro is-true (condition &rest reason-args)\n \"Like IS this check generates a pass if CONDITION returns true\n and a failure if CONDITION returns false. Unlike IS this check\n does not inspect CONDITION to determine how to report the\n failure.\"\n `(if ,condition\n (add-result 'test-passed :test-expr ',condition)\n (process-failure ',condition\n ,@(or reason-args\n `(\"~S did not return a true value\" ',condition)))))", "macroexpand": "(if (with-*test-dribble* nil (explain! (run (quote is1)))) (add-result (quote test-passed) :test-expr (quote (with-*test-dribble* nil (explain! (run (quote is1)))))) (process-failure (quote (with-*test-dribble* nil (explain! (run (quote is1))))) \"~S did not return a true value\" (quote (with-*test-dribble* nil (explain! (run (quote is1)))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (first in-decl) (push nil in-decl-item))\n\nProblem: Macro call that should be transformed by when", "input": "(when (first in-decl) (push nil in-decl-item))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (first in-decl) (push nil in-decl-item))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(the nil nil)\n\nProblem: Macro call that should be transformed by THE", "input": "(the nil nil)", "output": "(defmacro THE ...)", "macroexpand": "(send self nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defjs hello (x y) (return (+ x y)))\n\nIssue: Macro call that should be transformed by defjs", "input": "(defjs hello (x y) (return (+ x y)))", "output": "(defmacro defjs (name args &body body)\n \"Define client side javascript. Works like defun; body is in lisp, with parenscript\n additions, like return. So (defjs hello (x y) (return (+ x y))) defines an adder. \n macro creates a lisp function which sends the javascript function over to the mongo \n server to be evaluated. Result is processed and returned to the reader. \n This will execute 10 times on the server :\n (mapcar (lambda (x) (hello 10 x)) (list 1 2 3 4 5 6 7 8 9 10))\"\n `(let* ((js-body (parenscript:ps (lambda ,args ,@body))))\n (setf (gethash ',name *js-definitions*) js-body)\n (defun ,name ,args\n (get-element \"retval\" (car (docs (db.eval js-body ,@args)))))))", "macroexpand": "(let* ((js-body (parenscript:ps (lambda (x y) (return (+ x y)))))) (setf (gethash (quote hello) *js-definitions*) js-body) (defun hello (x y) (get-element \"retval\" (car (docs (db.eval js-body x y))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(do+ (for x (in '(1 2 3))) (do+ (for y (in '(a b))) (collect (list x y) :into foo)))\n\nPattern to recognize: Macro call that should be transformed by do+", "input": "(do+ (for x (in '(1 2 3))) (do+ (for y (in '(a b))) (collect (list x y) :into foo)))", "output": "(defmacro do+ (&body body)\n \"High-level, extensible iteration construct. Refer to the manual for syntax and semantics.\"\n `(do+/internal nil ,@body))", "macroexpand": "(do+/internal nil (for x (in (quote (1 2 3)))) (do+ (for y (in (quote (a b)))) (collect (list x y) :into foo)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8999999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda+ nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by LAMBDA+", "input": "(lambda+ nil\n :key\n nil)", "output": "(defmacro LAMBDA+ ...)", "macroexpand": "(lambda ()\n (let+ nil\n :key\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(check-cursor-attached cluffer:beginning-of-buffer-p (cursor))\n\nIssue: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:beginning-of-buffer-p (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:beginning-of-buffer-p :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(the 'some-name)\n\nPattern to recognize: Macro call that should be transformed by THE", "input": "(the 'some-name)", "output": "(defmacro THE ...)", "macroexpand": "(send self 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(fgathering nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by FGATHERING", "input": "(fgathering nil\n :key\n nil)", "output": "(defmacro FGATHERING ...)", "macroexpand": "(flet ()\n :key\n nil\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-sql-logging (mapc #'execute-sql (table-definition class)))\n\nIssue: Macro call that should be transformed by with-sql-logging", "input": "(with-sql-logging (mapc #'execute-sql (table-definition class)))", "output": "(defmacro with-sql-logging (&body body)\n `(let ((*mito-logger-stream* *mito-migration-logger-stream*))\n (with-trace-sql ,@body)))", "macroexpand": "(let ((*mito-logger-stream* *mito-migration-logger-stream*)) (with-trace-sql (mapc (function execute-sql) (table-definition class))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(destructuring-bind () nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DESTRUCTURING-BIND", "input": "(destructuring-bind () nil)", "output": "(defmacro DESTRUCTURING-BIND ...)", "macroexpand": "(sb-int:binding* ((nil (sb-c::check-ds-list nil 0 0 'nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda-ignoring-_ (exp1 _ exp2) `(,op ,exp1 ,exp2))\n\nPattern to recognize: Macro call that should be transformed by lambda-ignoring-_", "input": "(lambda-ignoring-_ (exp1 _ exp2) `(,op ,exp1 ,exp2))", "output": "(defmacro lambda-ignoring-_ (lambda-list &body body)\n \"Works like `cl:lambda' macro except automatically `declare's\n `ignore' for parameters beginning with '_' character.\"\n (let ((ignored-parameters\n (collect-_-symbol-in-lambda-list lambda-list)))\n (unless ignored-parameters\n (warn \"No ignored parameters in: ~A\" lambda-list))\n (multiple-value-bind (body decls doc)\n (parse-body body :documentation t)\n `(lambda ,lambda-list\n ,@ (if doc `(,doc))\n (declare (ignore ,@ignored-parameters))\n ,@decls\n ,@body))))", "macroexpand": "(lambda (exp1 _ exp2) (declare (ignore _)) (sb-int:quasiquote (#S(sb-impl::comma :expr op :kind 0) #S(sb-impl::comma :expr exp1 :kind 0) #S(sb-impl::comma :expr exp2 :kind 0))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(atomically nil () (symbol-name 'this))\n\nWhat needs to change: Macro call that should be transformed by atomically", "input": "(atomically nil () (symbol-name 'this))", "output": "(defmacro atomically (invariant &body args)\n \"Encloses atomic flow block of code that can be dispatched\nconcurrently. Non-consing.\"\n (destructuring-bind (opts lambda-list body) (parse-atomic-block-args args)\n (flow-lambda-macro (flow-context)\n (with-flow-function-macro (body-fu lambda-list body)\n `(dispatch-atomically ,flow-context #',body-fu ,invariant ,@opts)))))", "macroexpand": "(%flow-lambda (#:flow-context155) (%with-flow-function (#:body-fu156 nil (symbol-name (quote this))) (dispatch-atomically #:flow-context155 (function #:body-fu156) nil)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-context (context) (call-next-method))\n\nPattern to recognize: Macro call that should be transformed by with-context", "input": "(with-context (context) (call-next-method))", "output": "(defmacro with-context ((context) &body body)\n `(let* ((*context* ,context)\n (*request* (context :request))\n (*response* (context :response))\n (*session* (context :session)))\n ,@body))", "macroexpand": "(let* ((*context* context) (*request* (context :request)) (*response* (context :response)) (*session* (context :session))) (call-next-method))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-matches (match-start match-end regex target-string (nreverse result-list) :start start :end end) (push match-start result-list) (push match-end result-list))\n\nWhat needs to change: Macro call that should be transformed by do-matches", "input": "(do-matches (match-start match-end regex target-string (nreverse result-list) :start start :end end) (push match-start result-list) (push match-end result-list))", "output": "(defmacro do-matches ((match-start match-end regex\n target-string\n &optional result-form\n &key start end)\n &body body)\n \"Iterates over TARGET-STRING and tries to match REGEX as often as\npossible evaluating BODY with MATCH-START and MATCH-END bound to the\nstart/end positions of each match in turn. After the last match,\nreturns RESULT-FORM if provided or NIL otherwise. An implicit block\nnamed NIL surrounds DO-MATCHES; RETURN may be used to terminate the\nloop immediately. If REGEX matches an empty string the scan is\ncontinued one position behind this match. BODY may start with\ndeclarations.\"\n ;; this is a simplified form of DO-SCANS - we just provide two dummy\n ;; vars and ignore them\n (with-unique-names (reg-starts reg-ends)\n `(do-scans (,match-start ,match-end\n ,reg-starts ,reg-ends\n ,regex ,target-string\n ,result-form\n :start ,start :end ,end)\n ,@body)))", "macroexpand": "(do-scans (match-start match-end #:reg-starts139 #:reg-ends140 regex target-string (nreverse result-list) :start start :end end) (push match-start result-list) (push match-end result-list))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-rewrite caaaar (expr) `(car (caaar ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite caaaar (expr) `(car (caaar ,(second expr))))", "output": "(defmacro define-modf-rewrite (name (expr) &body body)\n \"Define a new rewrite rule. If a form starting with NAME is encountered, call\nthe defined function to return a form that we can deal with (i.e. one defined\nvia DEFINE-MODF-EXPANDER, DEFINE-MODF-FUNCTION, and DEFINE-MODF-METHOD).\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (gethash ',name *modf-rewrites*)\n (lambda (,expr)\n ,@body))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf (gethash (quote caaaar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (caaar #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-mustache-character #\\/ (make-instance 'section-end-tag :text arg-text :start start))\n\nWrite a macro that addresses: Macro call that should be transformed by define", "input": "(define-mustache-character #\\/ (make-instance 'section-end-tag :text arg-text :start start))", "output": "(defmacro define (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "macroexpand": "(set-mustache-character #\\SOLIDUS (lambda (raw-text arg-text escapep start end) (declare (ignorable raw-text arg-text escapep start end) (type simple-string raw-text arg-text) (boolean escapep) (offset start end)) (make-instance (quote section-end-tag) :text arg-text :start start)))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(f nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by F", "input": "(f nil\n :key\n nil)", "output": "(defmacro F ...)", "macroexpand": "(lambda () :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-component js-minify :input-type \"js\" :output-type \"min.js\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `(\"yui-compressor\" ,input-pathname \"-o\" ,output-pathname) :show t)))\n\nIssue: Macro call that should be transformed by define-component", "input": "(define-component js-minify :input-type \"js\" :output-type \"min.js\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `(\"yui-compressor\" ,input-pathname \"-o\" ,output-pathname) :show t)))", "output": "(defmacro define-component (name &key input-type output-type compile-function)\n \"Define an ASDF component.\"\n `(progn\n (defclass ,name (source-file)\n ((type :initform ,input-type)\n (output :reader output :initarg :output)))\n\n (defmethod perform ((o load-op) (component ,name)) t)\n\n (defmethod output-files ((operation compile-op) (component ,name))\n (list\n (output-pathname component ,output-type)))\n\n (defmethod perform ((o compile-op) (component ,name))\n (funcall ,compile-function\n (component-pathname component)\n (output-pathname component ,output-type)))\n\n (import ',name :asdf)))", "macroexpand": "(progn (defclass js-minify (source-file) ((type :initform \"js\") (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component js-minify)) t) (defmethod output-files ((operation compile-op) (component js-minify)) (list (output-pathname component \"min.js\"))) (defmethod perform ((o compile-op) (component js-minify)) (funcall (lambda (input-pathname output-pathname) (inferior-shell:run (sb-int:quasiquote (\"yui-compressor\" #S(sb-impl::comma :expr input-pathname :kind 0) \"-o\" #S(sb-impl::comma :expr output-pathname :kind 0))) :show t)) (component-pathname component) (output-pathname component \"min.js\"))) (import (quote js-minify) :asdf))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun-compile-time walk-multiple-value-prog1 (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper MULTIPLE-VALUE-PROG1: ~S\" form)) (unless (>= (length form) 2) (error \"MULTIPLE-VALUE-PROG1 must have at least one argument, a FORM: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'multiple-value-prog1) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'multiple-value-prog1)))\n\nPattern to recognize: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time walk-multiple-value-prog1 (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper MULTIPLE-VALUE-PROG1: ~S\" form)) (unless (>= (length form) 2) (error \"MULTIPLE-VALUE-PROG1 must have at least one argument, a FORM: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form 'multiple-value-prog1) (reduce reduce-function (mapcar #'(lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment)) (rest form)))) (funcall map-function form 'multiple-value-prog1)))", "output": "(defmacro defun-compile-time (function-name lambda-list &body body)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (cl:defun ,function-name ,lambda-list ,@body)\n (eval-when (:compile-toplevel) (compile ',function-name))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (common-lisp:defun walk-multiple-value-prog1 (map-function reduce-function screamer? partial? nested? form environment) (unless (null (rest (last form))) (error \"Improper MULTIPLE-VALUE-PROG1: ~S\" form)) (unless (>= (length form) 2) (error \"MULTIPLE-VALUE-PROG1 must have at least one argument, a FORM: ~S\" form)) (if reduce-function (funcall reduce-function (funcall map-function form (quote multiple-value-prog1)) (reduce reduce-function (mapcar (function (lambda (subform) (walk map-function reduce-function screamer? partial? nested? subform environment))) (rest form)))) (funcall map-function form (quote multiple-value-prog1)))) (eval-when (:compile-toplevel) (compile (quote walk-multiple-value-prog1))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-open-temporary-file (f :keep keep) (pathname f))\n\nProblem: Macro call that should be transformed by with-open-temporary-file", "input": "(with-open-temporary-file (f :keep keep) (pathname f))", "output": "(defmacro with-open-temporary-file ((stream &rest args &key keep &allow-other-keys) &body body)\n \"Create a temporary file using OPEN-TEMPORARY with ARGS and run BODY\n with STREAM bound to the temporary file stream. Returns the values\n returned by BODY. By default, the file is deleted when BODY is\n exited. If a true value is passed in KEEP, the file is not deleted\n when the body is exited. See OPEN-TEMPORARY for more permitted\n options.\"\n `(with-open-stream (,stream (open-temporary ,@(alexandria:remove-from-plist args :keep)))\n #+sbcl\n (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note))\n ,(if (and (constantp keep)\n keep)\n `(progn ,@body)\n `(unwind-protect\n (progn ,@body)\n (unless ,keep\n (close ,stream)\n (delete-file (pathname ,stream)))))))", "macroexpand": "(with-open-stream (f (open-temporary)) (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note)) (unwind-protect (progn (pathname f)) (unless keep (close f) (delete-file (pathname f)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclause returning (&rest forms) \"Returns each form in as the value of the do+ form when the loop ends. If multiple forms are specified, by one or more RETURNING clauses, multiple values are returned, in the order the corresponding forms appear lexically. If one of the is (cl:values ...), then each value will be returned as if the values were spelled as direct arguments of the RETURNING form.\" (let (result-clauses) (dolist (form forms) (if (and (listp form) (eq 'values (car form))) (dolist (form (cdr form)) (push (make-result :form form) result-clauses)) (push (make-result :form form) result-clauses))) (nreverse result-clauses)))\n\nProblem: Macro call that should be transformed by defclause", "input": "(defclause returning (&rest forms) \"Returns each form in as the value of the do+ form when the loop ends. If multiple forms are specified, by one or more RETURNING clauses, multiple values are returned, in the order the corresponding forms appear lexically. If one of the is (cl:values ...), then each value will be returned as if the values were spelled as direct arguments of the RETURNING form.\" (let (result-clauses) (dolist (form forms) (if (and (listp form) (eq 'values (car form))) (dolist (form (cdr form)) (push (make-result :form form) result-clauses)) (push (make-result :form form) result-clauses))) (nreverse result-clauses)))", "output": "(defmacro defclause (name arglist &body body)\n \"Same as cl:defmacro, but additionally records in *clauses* as a known clause macro.\"\n `(progn\n (defmacro ,name ,arglist ,@body)\n (pushnew ',name *clauses*)))", "macroexpand": "(progn (defmacro returning (&rest forms) \"Returns each form in as the value of the do+ form when the loop ends. If multiple forms are specified, by one or more RETURNING clauses, multiple values are returned, in the order the corresponding forms appear lexically. If one of the is (cl:values ...), then each value will be returned as if the values were spelled as direct arguments of the RETURNING form.\" (let (result-clauses) (dolist (form forms) (if (and (listp form) (eq (quote values) (car form))) (dolist (form (cdr form)) (push (make-result :form form) result-clauses)) (push (make-result :form form) result-clauses))) (nreverse result-clauses))) (pushnew (quote returning) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(next-in nil)\n\nProblem: Macro call that should be transformed by NEXT-IN", "input": "(next-in nil)", "output": "(defmacro NEXT-IN ...)", "macroexpand": "(do-next-in nil #'(lambda ()))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(pop-last-preprocessor-directive-token directive-token-list directive-symbol)\n\nIssue: Macro call that should be transformed by pop-last-preprocessor-directive-token", "input": "(pop-last-preprocessor-directive-token directive-token-list directive-symbol)", "output": "(defmacro pop-last-preprocessor-directive-token (token-list directive-name)\n \"For #ifdef, #ifndef, and #undef\"\n (with-gensyms (dsym_)\n `(let ((,dsym_ ,directive-name))\n (prog1 (pop-preprocessor-directive-token ,token-list ,dsym_)\n (check-no-preprocessor-token ,token-list ,dsym_)))))", "macroexpand": "(let ((#:dsym_269 directive-symbol)) (prog1 (pop-preprocessor-directive-token directive-token-list #:dsym_269) (check-no-preprocessor-token directive-token-list #:dsym_269)))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :heh () (funcall #'%continue))\n\nProblem: Macro call that should be transformed by ->", "input": "(-> :heh () (funcall #'%continue))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :heh nil (funcall (function %continue)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defstruct*\n nil\n (progn))\n\nIssue: Macro call that should be transformed by DEFSTRUCT*", "input": "(defstruct*\n nil\n (progn))", "output": "(defmacro DEFSTRUCT* ...)", "macroexpand": "(progn\n (defclass nil nil ((progn :initform nil :initarg :progn :accessor nil-progn)))\n (defun make-nil (&rest structure-ext.as-class::args)\n (apply #'make-instance 'nil structure-ext.as-class::args))\n (defgeneric copy-nil\n (structure-ext.as-class::arg))\n (defmethod copy-nil ((structure-ext.as-class::arg nil))\n (let ((structure-ext.as-class::obj\n (make-instance (class-of structure-ext.as-class::arg))))\n (dolist\n (structure-ext.as-class::slot\n (structure-ext.as-class::slots<=obj structure-ext.as-class::arg))\n (if (slot-boundp structure-ext.as-class::arg\n structure-ext.as-class::slot)\n (setf (slot-value structure-ext.as-class::obj\n structure-ext.as-class::slot)\n (slot-value structure-ext.as-class::arg\n structure-ext.as-class::slot))\n (slot-makunbound structure-ext.as-class::obj\n structure-ext.as-class::slot)))\n structure-ext.as-class::obj))\n (defun nil-p (structure-ext.as-class::arg)\n (typep structure-ext.as-class::arg 'nil))\n 'nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(draw scene (:rect :x 30 :y 300 :width 400 :height 150) :fill \"rgb(230,230,230)\" :stroke \"black\")\n\nWrite a macro that addresses: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x 30 :y 300 :width 400 :height 150) :fill \"rgb(230,230,230)\" :stroke \"black\")", "output": "(defmacro draw (scene (shape &rest params) &rest opts)\n (let ((element (gensym)))\n `(let ((,element (funcall #'make-svg-element ,shape (append (list ,@params) (list ,@opts)))))\n (add-element ,scene ,element)\n ,element)))", "macroexpand": "(let ((#:g165 (funcall (function make-svg-element) :rect (append (list :x 30 :y 300 :width 400 :height 150) (list :fill \"rgb(230,230,230)\" :stroke \"black\"))))) (add-element scene #:g165) #:g165)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(builder (:session :store (make-dbi-store :connector (lambda () *conn*))) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session))))))))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder (:session :store (make-dbi-store :connector (lambda () *conn*))) (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) `(200 (:content-type \"text/plain\") (,(format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session))))))))", "output": "(defmacro builder (&rest app-or-middlewares)\n (let ((middlewares (butlast app-or-middlewares)))\n `(reduce #'funcall\n (remove-if\n #'null\n (list\n ,@(loop for mw in middlewares\n when mw\n collect (convert-to-middleware-form mw))))\n :initial-value (to-app ,(car (last app-or-middlewares)))\n :from-end t)))", "macroexpand": "(reduce (function funcall) (remove-if (function null) (list (lambda (#:app232) (funcall (find-middleware :session) #:app232 :store (make-dbi-store :connector (lambda nil *conn*)))))) :initial-value (to-app (lambda (env) (unless (gethash :counter (getf env :lack.session)) (setf (gethash :counter (getf env :lack.session)) 0)) (sb-int:quasiquote (200 (:content-type \"text/plain\") (#S(sb-impl::comma :expr (format nil \"Hello, you've been here for ~Ath times!\" (incf (gethash :counter (getf env :lack.session)))) :kind 0)))))) :from-end t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(next-in nil (progn))\n\nProblem: Macro call that should be transformed by NEXT-IN", "input": "(next-in nil (progn))", "output": "(defmacro NEXT-IN ...)", "macroexpand": "(do-next-in nil #'(lambda () (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-custom-var (:string-scope *string-scope-variables*) nil \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON String.\")\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:string-scope *string-scope-variables*) nil \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON String.\")", "output": "(defmacro define-custom-var ((key name) &rest other-args)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (progn (pushnew '(,name . ,key) *custom-vars* :test #'equal)\n (defvar ,name ,@other-args))))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (progn (pushnew (quote (*string-scope-variables* . :string-scope)) *custom-vars* :test (function equal)) (defvar *string-scope-variables* nil \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON String.\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(asif (incf (car x)) it (list :oops it))\n\nWhat needs to change: Macro call that should be transformed by asif", "input": "(asif (incf (car x)) it (list :oops it))", "output": "(defmacro asif (test then &optional else)\n \"Like IF, except binds the result of the test to IT (via LET) for\nthe the scope of the then-expression, and the test form to IT (via\nSYMBOL-MACROLET) for the scope of the else-expression. Within scope of\nthe else-expression, IT can be set with SETF.\"\n `(let ((it ,test))\n (if it\n\t ,then\n\t (symbolic ignore-first ,test ,else))))", "macroexpand": "(let ((it (incf (car x)))) (if it it (symbolic ignore-first (incf (car x)) (list :oops it))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is (= 6 (length results)))\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is (= 6 (length results)))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(let ((#:e202 6) (#:a203 (length results))) (if (progn (= #:e202 #:a203)) (add-result (quote test-passed) :test-expr (quote (= 6 (length results)))) (process-failure (quote (= 6 (length results))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (length results)) #:a203 (quote =) #:e202)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defcategory :critical)\n\nProblem: Macro call that should be transformed by defcategory", "input": "(defcategory :critical)", "output": "(defmacro defcategory (category &optional expands-as set)\n `(defcategory-fn ',category ',expands-as ,set))", "macroexpand": "(defcategory-fn (quote :critical) (quote nil) nil)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.7775} {"instruction": "Generate a defmacro form that transforms code like this:\n(deferror \"22007\" invalid-datetime-format data-exception)\n\nPattern to recognize: Macro call that should be transformed by deferror", "input": "(deferror \"22007\" invalid-datetime-format data-exception)", "output": "(defmacro deferror (code typename &optional (superclass 'database-error))\n `(progn (define-condition ,typename (,superclass) ())\n (setf (gethash ,code *error-table*) ',typename)))", "macroexpand": "(progn (define-condition invalid-datetime-format (data-exception) nil) (setf (gethash \"22007\" *error-table*) (quote invalid-datetime-format)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(when (first in-decl) (setf (first in-decl-item) nil))\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when (first in-decl) (setf (first in-decl-item) nil))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (first in-decl) (setf (first in-decl-item) nil))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-or 'some-name)\n\nProblem: Macro call that should be transformed by COLLECT-OR", "input": "(collect-or 'some-name)", "output": "(defmacro COLLECT-OR ...)", "macroexpand": "(common-lisp:let* ((#:generator-332 (generator 'some-name))\n #:bools-328\n (#:bool-329 nil))\n (declare (type generator #:generator-332))\n (tagbody\n #:ll-333\n (setq #:bools-328 (next-in #:generator-332 (go end)))\n (if (setq #:bool-329 #:bools-328)\n (go end))\n (go #:ll-333)\n end)\n #:bool-329)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda* nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by LAMBDA*", "input": "(lambda* nil\n (progn))", "output": "(defmacro LAMBDA* ...)", "macroexpand": "(lambda ()\n (with-yield\n (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(maybe-do-not-silence-errors (handler-case (call-next-method) (error (err) (warn \"Unhandled error when evaluating ~a:~% ~a~%\" (or (ignore-errors (format-result result :oneline)) result) err) (setf (description result) (format NIL \"The test failed to evaluate properly:~% ~a\" err)) (setf (status result) :failed))))\n\nProblem: Macro call that should be transformed by maybe-do-not-silence-errors", "input": "(maybe-do-not-silence-errors (handler-case (call-next-method) (error (err) (warn \"Unhandled error when evaluating ~a:~% ~a~%\" (or (ignore-errors (format-result result :oneline)) result) err) (setf (description result) (format NIL \"The test failed to evaluate properly:~% ~a\" err)) (setf (status result) :failed))))", "output": "(defmacro maybe-do-not-silence-errors (&body body)\n `(if *silence-plain-compilation-errors-p*\n ,@body\n (let ((ok nil))\n (unwind-protect\n (multiple-value-prog1\n (call-next-method)\n (setf ok t))\n (unless ok (setf (status result) :failed))))))", "macroexpand": "(if *silence-plain-compilation-errors-p* (handler-case (call-next-method) (error (err) (warn \"Unhandled error when evaluating ~a:~% ~a~%\" (or (ignore-errors (format-result result :oneline)) result) err) (setf (description result) (format nil \"The test failed to evaluate properly:~% ~a\" err)) (setf (status result) :failed))) (let ((ok nil)) (unwind-protect (multiple-value-prog1 (call-next-method) (setf ok t)) (unless ok (setf (status result) :failed)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(terminate)\n\nWrite a macro that addresses: Macro call that should be transformed by TERMINATE", "input": "(terminate)", "output": "(defmacro TERMINATE ...)", "macroexpand": "(finish)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(@ nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by @", "input": "(@ nil nil)", "output": "(defmacro @ ...)", "macroexpand": "(message-oo.mangle::nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(in-readtable nil)\n\nPattern to recognize: Macro call that should be transformed by IN-READTABLE", "input": "(in-readtable nil)", "output": "(defmacro IN-READTABLE ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf *readtable* (ensure-readtable 'nil))\n (when (or (find-package :swank) (find-package :slynk))\n (editor-hints.named-readtables::%frob-swank-readtable-alist *package*\n *readtable*))\n *readtable*)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-op (:!= infix-op))\n\nWhat needs to change: Macro call that should be transformed by define-op", "input": "(define-op (:!= infix-op))", "output": "(defmacro define-op ((op-name struct-type &key sql-op-name include-slots (package (find-package '#:sxql/operator))) &body body)\n (check-type op-name symbol)\n (let ((struct-name (intern (concatenate 'string (symbol-name op-name) #.(string :-op)) package)))\n `(defstruct (,struct-name (:include ,struct-type\n (name ,(or sql-op-name\n (with-output-to-string (s)\n (loop for c across (symbol-name op-name)\n if (char= c #\\-)\n do (write-char #\\Space s)\n else\n do (write-char c s)))))\n ,@include-slots)\n (:constructor ,(intern (concatenate 'string\n #.(string :make-)\n (symbol-name op-name)\n #.(string :-op))\n package)\n ,(ecase struct-type\n ((unary-op\n unary-splicing-op\n unary-postfix-op) '(var))\n ((infix-op\n infix-splicing-op\n infix-list-op) '(left right))\n (conjunctive-op '(&rest expressions)))))\n ,@body)))", "macroexpand": "(defstruct (!=-op (:include infix-op (name \"!=\")) (:constructor make-!=-op (left right))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(is-true (with-*test-dribble* nil (explain! (run 'is1))))\n\nProblem: Macro call that should be transformed by is", "input": "(is-true (with-*test-dribble* nil (explain! (run 'is1))))", "output": "(defmacro is (test &rest reason-args)\n \"The DWIM checking operator.\n\nIf TEST returns a true value a test-passed result is generated,\notherwise a test-failure result is generated. The reason, unless\nREASON-ARGS is provided, is generated based on the form of TEST:\n\n (predicate expected actual) - Means that we want to check\n whether, according to PREDICATE, the ACTUAL value is\n in fact what we EXPECTED.\n\n (predicate value) - Means that we want to ensure that VALUE\n satisfies PREDICATE.\n\n Wrapping the TEST form in a NOT simply produces a negated reason\n string.\"\n (assert (listp test)\n (test)\n \"Argument to IS must be a list, not ~S\" test)\n (let (bindings effective-test default-reason-args)\n (with-gensyms (e a v)\n (flet ((process-entry (predicate expected actual &optional negatedp)\n ;; make sure EXPECTED is holding the entry that starts with 'values\n (when (and (consp actual)\n (eq (car actual) 'values))\n (assert (not (and (consp expected)\n (eq (car expected) 'values))) ()\n \"Both the expected and actual part is a values expression.\")\n (rotatef expected actual))\n (let ((setf-forms))\n (if (and (consp expected)\n (eq (car expected) 'values))\n (progn\n (setf expected (copy-list expected))\n (setf setf-forms (loop for cell = (rest expected) then (cdr cell)\n for i from 0\n while cell\n when (eq (car cell) '*)\n collect `(setf (elt ,a ,i) nil)\n and do (setf (car cell) nil)))\n (setf bindings (list (list e `(list ,@(rest expected)))\n (list a `(multiple-value-list ,actual)))))\n (setf bindings (list (list e expected)\n (list a actual))))\n (setf effective-test `(progn\n ,@setf-forms\n ,(if negatedp\n `(not (,predicate ,e ,a))\n `(,predicate ,e ,a)))))))\n (list-match-case test\n ((not (?predicate ?expected ?actual))\n (process-entry ?predicate ?expected ?actual t)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\"\n `',?actual a `',?predicate e)))\n ((not (?satisfies ?value))\n (setf bindings (list (list v ?value))\n effective-test `(not (,?satisfies ,v))\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which satisfies ~2&~S~2% (it should not)\"\n `',?value v `',?satisfies)))\n ((?predicate ?expected ?actual)\n (process-entry ?predicate ?expected ?actual)\n (setf default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\"\n `',?actual a `',?predicate e)))\n ((?satisfies ?value)\n (setf bindings (list (list v ?value))\n effective-test `(,?satisfies ,v)\n default-reason-args\n (list \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\"\n `',?value v `',?satisfies)))\n (?_\n (setf bindings '()\n effective-test test\n default-reason-args (list \"~2&~S~2% was NIL.\" `',test)))))\n `(let ,bindings\n (if ,effective-test\n (add-result 'test-passed :test-expr ',test)\n (process-failure ',test\n ,@(or reason-args default-reason-args)))))))", "macroexpand": "(if (with-*test-dribble* nil (explain! (run (quote is1)))) (add-result (quote test-passed) :test-expr (quote (with-*test-dribble* nil (explain! (run (quote is1)))))) (process-failure (quote (with-*test-dribble* nil (explain! (run (quote is1))))) \"~S did not return a true value\" (quote (with-*test-dribble* nil (explain! (run (quote is1)))))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(make-name-transformer nil)\n\nProblem: Macro call that should be transformed by MAKE-NAME-TRANSFORMER", "input": "(make-name-transformer nil)", "output": "(defmacro MAKE-NAME-TRANSFORMER ...)", "macroexpand": "(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defalias path:= (a b) cl-fad:pathname-equal)\n\nProblem: Macro call that should be transformed by defalias", "input": "(defalias path:= (a b) cl-fad:pathname-equal)", "output": "(defmacro defalias (name args realname)\n `(progn\n (defun ,name ,args\n ,(if (eql '&rest (first args))\n `(apply #',realname ,(second args))\n `(,realname ,@args)))\n (define-compiler-macro ,name (&rest args)\n (list* ',realname args))))", "macroexpand": "(progn (defun path:= (a b) (pathname-equal a b)) (define-compiler-macro path:= (&rest args) (list* (quote pathname-equal) args)))", "category": "control-flow", "technique": "compiler-macro", "complexity": "advanced", "quality_score": 0.9075} {"instruction": "Define a macro that eliminates this repetitive pattern:\n($ \"$max\" ($ \"value-1\" 610))\n\nIssue: Macro call that should be transformed by $", "input": "($ \"$max\" ($ \"value-1\" 610))", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(kv \"$max\" ($ \"value-1\" 610))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(def-neo4j-fun set-node-property (node-id property value) :put (:uri-spec (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:encode value :string) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json))))\n\nWrite a macro that addresses: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun set-node-property (node-id property value) :put (:uri-spec (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (:encode value :string) (:status-handlers (204 (values t body)) (400 (error 'invalid-data-sent-error :uri uri :json json))))", "output": "(defmacro def-neo4j-fun (name lambda-list method &rest args)\n `(progn\n (defun ,name (&key ,@lambda-list)\n (let ((uri ,(cadr (assoc :uri-spec args)))\n (json (encode-neo4j-json-payload ,@(aif (assoc :encode args)\n (cdr it)\n (list '() :string)))))\n (make-neo4j-request ,method uri json\n (list ,@(mapcar (lambda (handler)\n `(list ,(car handler) (lambda (body uri json)\n ,(cadr handler))))\n (cdr (assoc :status-handlers args)))))))))", "macroexpand": "(progn (defun set-node-property (&key node-id property value) (let ((uri (format nil \"node/~A/properties/~A\" node-id (if (symbolp property) (string-downcase (symbol-name property)) property))) (json (encode-neo4j-json-payload value :string))) (make-neo4j-request :put uri json (list (list 204 (lambda (body uri json) (values t body))) (list 400 (lambda (body uri json) (error (quote invalid-data-sent-error) :uri uri :json json))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(case-insensitive-mode-p flags)\n\nProblem: Macro call that should be transformed by case-insensitive-mode-p", "input": "(case-insensitive-mode-p flags)", "output": "(defmacro case-insensitive-mode-p (flags)\n \"Accessor macro to extract the first flag out of a three-element flag list.\"\n `(first ,flags))", "macroexpand": "(first flags)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(check-cursor-attached cluffer:end-of-line (cursor))\n\nProblem: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:end-of-line (cursor))", "output": "(defmacro check-cursor-attached (name arguments)\n (let ((args (substitute '(cursor cluffer:cursor) 'cursor arguments)))\n `(defmethod ,name :before ,args\n (declare (ignore ,@(set-difference (remove 'cursor arguments)\n lambda-list-keywords)))\n (unless (cluffer:cursor-attached-p cursor)\n (error 'cluffer:cursor-detached)))))", "macroexpand": "(defmethod cluffer:end-of-line :before ((cursor cluffer:cursor)) (declare (ignore)) (unless (cluffer:cursor-attached-p cursor) (error (quote cluffer:cursor-detached))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-accumulation-binding collecting (var form &aux (head (cons NIL NIL)) (tail head)) (declare (type list var) (type cons head tail)) `(setf ,tail (setf (cdr ,tail) (cons ,form NIL)) ,var (cdr ,head)))\n\nIssue: Macro call that should be transformed by define-accumulation-binding", "input": "(define-accumulation-binding collecting (var form &aux (head (cons NIL NIL)) (tail head)) (declare (type list var) (type cons head tail)) `(setf ,tail (setf (cdr ,tail) (cons ,form NIL)) ,var (cdr ,head)))", "output": "(defmacro define-accumulation-binding (name (var &rest args) &body body)\n `(define-form-binding ,name (,var ,@args)\n ,@(form-fiddle:lambda-declarations `(lambda () ,@body))\n (values\n (progn ,@(form-fiddle:lambda-forms `(lambda () ,@body)))\n (delist var))))", "macroexpand": "(define-form-binding collecting (var form &aux (head (cons nil nil)) (tail head)) (declare (type list var) (type cons head tail)) (values (progn (sb-int:quasiquote (setf #S(sb-impl::comma :expr tail :kind 0) (setf (cdr #S(sb-impl::comma :expr tail :kind 0)) (cons #S(sb-impl::comma :expr form :kind 0) nil)) #S(sb-impl::comma :expr var :kind 0) (cdr #S(sb-impl::comma :expr head :kind 0))))) (delist var)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(do-generator-value-list (vals (apply #'multi-gen generators)) (yield (apply function (mapcar #'car vals))))\n\nIssue: Macro call that should be transformed by do-generator", "input": "(do-generator-value-list (vals (apply #'multi-gen generators)) (yield (apply function (mapcar #'car vals))))", "output": "(defmacro do-generator ((var &rest vars-and-generator) &body body)\n \"Steps through the specified generator, binding the value it returns to var, then executing the body for each step. If multiple variables are specified and the generator returns multiple values, the extra values will be bound to the extra variables.\"\n (let ((g (gensym)))\n `(let ((,g ,(car (last vars-and-generator))))\n (loop \n\t do (if-generator ((,var ,@(butlast vars-and-generator)) ,g)\n\t\t\t (progn\n\t\t\t ,@body)\n\t\t\t (return))))))", "macroexpand": "(let ((#:g165 (apply (function multi-gen) generators))) (loop do (if-generator (vals #:g165) (progn (yield (apply function (mapcar (function car) vals)))) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-reader-case nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by WITH-READER-CASE", "input": "(with-reader-case nil\n nil)", "output": "(defmacro WITH-READER-CASE ...)", "macroexpand": "(let ()\n (let ((#:previous-case179 (readtable-case *readtable*)))\n (setf (readtable-case *readtable*) nil)\n (unwind-protect (progn nil)\n (setf (readtable-case *readtable*) #:previous-case179))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (not (gethash operatorXX name-map)))\n\nProblem: Macro call that should be transformed by when", "input": "(when (not (gethash operatorXX name-map)))", "output": "(defmacro when (test &body forms)\n `(if ,test\n\t ,(cl:if (cadr forms)\n\t\t\t `(progn ,@forms)\n\t\t\t (car forms))))", "macroexpand": "(if (not (gethash operatorxx name-map)) nil)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(match (list 1 2 3) (list x y z) (+ x y z))\n\nIssue: Macro call that should be transformed by match", "input": "(match (list 1 2 3) (list x y z) (+ x y z))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(let ((#:var151 (list 1 2 3))) (declare (ignorable #:var151)) (%or (%or (let ((list #:var151)) x y z) (let ((+ #:var151)) x y z) (fail)) nil))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-element-maker :use \"use\" '(:xlink-href))\n\nWrite a macro that addresses: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :use \"use\" '(:xlink-href))", "output": "(defmacro define-element-maker (element name required-attributes)\n `(progn\n (defmethod assert-required-attributes ((element (eql ,element)) attributes)\n (declare (ignore element))\n (unless (evenp (length attributes))\n (warn \"attribute list may be missing data: ~A\" attributes))\n (let ((missing (set-difference ,required-attributes attributes)))\n\t (when missing\n\t (error 'missing-attributes :message (format nil \"~A missing attributes: ~{~A~^ ~}\" ,element missing)))))\n (defmethod make-svg-element ((element (eql ,element)) attributes)\n (when *check-required-attributes*\n (assert-required-attributes element attributes))\n (make-instance 'svg-element :name ,name :attributes attributes))))", "macroexpand": "(progn (defmethod assert-required-attributes ((element (eql :use)) attributes) (declare (ignore element)) (unless (evenp (length attributes)) (warn \"attribute list may be missing data: ~A\" attributes)) (let ((missing (set-difference (quote (:xlink-href)) attributes))) (when missing (error (quote missing-attributes) :message (format nil \"~A missing attributes: ~{~A~^ ~}\" :use missing))))) (defmethod make-svg-element ((element (eql :use)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"use\" :attributes attributes)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(match 1 (x x))\n\nPattern to recognize: Macro call that should be transformed by match", "input": "(match 1 (x x))", "output": "(defmacro match (arg &body clauses)\n \"Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN\n. BODY) where PATTERN is a pattern specifier and BODY is an implicit\nprogn. If ARG matches some PATTERN, `match` then evaluates\nthe corresponding BODY and returns the evaluated value. If no pattern matches,\nthen returns NIL.\n\nEvaluating a form (FAIL) in the clause body causes the latest pattern\nmatching to fail. For example,\n\n (match 1\n (x (if (eql x 1)\n (fail)\n x))\n (_ 'ok))\n\nreturns OK, because the form (FAIL) in the first clause is\nevaluated.\n\nIf BODY starts with the symbols WHEN or UNLESS, then the next form\nwill be used to introduce (FAIL). That is,\n\n (match list ((list x) when (oddp x) x))\n (match list ((list x) unless (evenp x) x))\n\nwill be translated to\n\n (match list ((list x) (if (oddp x) x (fail))))\n (match list ((list x) (if (evenp x) (fail) x)))\n\nExamples:\n\n (match 1 (1 1))\n => 1\n (match 1 (2 2))\n => 2\n (match 1 (x x))\n => 1\n (match (list 1 2 3)\n (list x y z) (+ x y z))\n => 6\"\n (compile-match-1 arg clauses nil))", "macroexpand": "(let ((#:var150 1)) (declare (ignorable #:var150)) (%or (%or (let ((x #:var150)) x) (fail)) nil))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.8975} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-<>>)\n\nIssue: Macro call that should be transformed by -<>>", "input": "(-<>>)", "output": "(defmacro -<>> ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825}