{"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-all-tags)\n\nWhat needs to change: Macro call that should be transformed by define-all-tags", "input": "(define-all-tags)", "output": "(defmacro define-all-tags ()\n `(progn\n ,@(loop for tag in (hash-table-keys *html5-elements*)\n collect `(define-tag ,tag))))", "macroexpand": "(progn (define-tag :vkern) (define-tag :view) (define-tag :use) (define-tag :tspan) (define-tag :tref) (define-tag :textpath) (define-tag :text) (define-tag :symbol) (define-tag :switch) (define-tag :stop) (define-tag :set) (define-tag :rect) (define-tag :radialgradient) (define-tag :polyline) (define-tag :polygon) (define-tag :pattern) (define-tag :path) (define-tag :mpath) (define-tag :missing-glyph) (define-tag :metadata) (define-tag :mask) (define-tag :marker) (define-tag :lineargradient) (define-tag :line) (define-tag :image) (define-tag :hkern) (define-tag :glyphref) (define-tag :glyph) (define-tag :g) (define-tag :foreignobject) (define-tag :font-face-uri) (define-tag :font-face-src) (define-tag :font-face-name) (define-tag :font-face-format) (define-tag :font-face) (define-tag :font) (define-tag :filter) (define-tag :feturbulence) (define-tag :fetile) (define-tag :fespotlight) (define-tag :fespecularlighting) (define-tag :fepointlight) (define-tag :feoffset) (define-tag :femorphology) (define-tag :femergenode) (define-tag :femerge) (define-tag :feimage) (define-tag :fegaussianblur) (define-tag :fefuncr) (define-tag :fefuncg) (define-tag :fefuncb) (define-tag :fefunca) (define-tag :feflood) (define-tag :fedropshadow) (define-tag :fedistantlight) (define-tag :fedisplacementmap) (define-tag :fediffuselighting) (define-tag :feconvolvematrix) (define-tag :fecomposite) (define-tag :fecomponenttransfer) (define-tag :fecolormatrix) (define-tag :feblend) (define-tag :ellipse) (define-tag :desc) (define-tag :defs) (define-tag :cursor) (define-tag :clippath) (define-tag :circle) (define-tag :animatetransform) (define-tag :animatemotion) (define-tag :animate) (define-tag :wbr) (define-tag :video) (define-tag :var) (define-tag :ul) (define-tag :u) (define-tag :track) (define-tag :tr) (define-tag :title) (define-tag :time) (define-tag :thead) (define-tag :th) (define-tag :tfoot) (define-tag :textarea) (define-tag :template) (define-tag :td) (define-tag :tbody) (define-tag :table) (define-tag :sup) (define-tag :summary) (define-tag :svg) (define-tag :sub) (define-tag :style) (define-tag :strong) (define-tag :span) (define-tag :source) (define-tag :small) (define-tag :select) (define-tag :section) (define-tag :script) (define-tag :samp) (define-tag :s) (define-tag :ruby) (define-tag :rt) (define-tag :rp) (define-tag :q) (define-tag :progress) (define-tag :pre) (define-tag :picture) (define-tag :param) (define-tag :p) (define-tag :output) (define-tag :option) (define-tag :optgroup) (define-tag :ol) (define-tag :object) (define-tag :noscript) (define-tag :nav) (define-tag :meter) (define-tag :meta) (define-tag :menu) (define-tag :math) (define-tag :mark) (define-tag :map) (define-tag :main) (define-tag :link) (define-tag :li) (define-tag :legend) (define-tag :label) (define-tag :keygen) (define-tag :kbd) (define-tag :ins) (define-tag :input) (define-tag :img) (define-tag :iframe) (define-tag :i) (define-tag :html) (define-tag :hr) (define-tag :hgroup) (define-tag :header) (define-tag :h6) (define-tag :h5) (define-tag :h4) (define-tag :h3) (define-tag :h2) (define-tag :h1) (define-tag :head) (define-tag :form) (define-tag :footer) (define-tag :figure) (define-tag :figcaption) (define-tag :fieldset) (define-tag :embed) (define-tag :em) (define-tag :dt) (define-tag :dl) (define-tag :div) (define-tag :dialog) (define-tag :dfn) (define-tag :details) (define-tag :del) (define-tag :dd) (define-tag :datalist) (define-tag :data) (define-tag :command) (define-tag :colgroup) (define-tag :col) (define-tag :code) (define-tag :cite) (define-tag :caption) (define-tag :canvas) (define-tag :button) (define-tag :br) (define-tag :body) (define-tag :blockquote) (define-tag :bdo) (define-tag :bdi) (define-tag :base) (define-tag :b) (define-tag :audio) (define-tag :aside) (define-tag :article) (define-tag :area) (define-tag :address) (define-tag :abbr) (define-tag :a))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-modf-rewrite cadadr (expr) `(car (cdadr ,(second expr))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cadadr (expr) `(car (cdadr ,(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 cadadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cdadr #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(draw scene (:rect :x 10 :y 10 :width 3980 :height 1980) :fill \"none\" :stroke \"blue\" :stroke-width 10)\n\nWrite a macro that addresses: Macro call that should be transformed by draw", "input": "(draw scene (:rect :x 10 :y 10 :width 3980 :height 1980) :fill \"none\" :stroke \"blue\" :stroke-width 10)", "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 ((#:g152 (funcall (function make-svg-element) :rect (append (list :x 10 :y 10 :width 3980 :height 1980) (list :fill \"none\" :stroke \"blue\" :stroke-width 10))))) (add-element scene #:g152) #:g152)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(for nil\n nil)\n\nProblem: Macro call that should be transformed by FOR", "input": "(for nil\n nil)", "output": "(defmacro FOR ...)", "macroexpand": "(let ((#:|generator!120| nil))\n (assert (typep #:|generator!120| 'generator!))\n (unwind-protect\n (loop :while (has-next-p #:|generator!120|)\n :do (let ((nil (next #:|generator!120|))))))\n (stop #:|generator!120|))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(actypecase 0 (string it))\n\nWhat needs to change: Macro call that should be transformed by actypecase", "input": "(actypecase 0 (string 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 0 (string it))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(gathering nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by GATHERING", "input": "(gathering nil\n :key\n nil)", "output": "(defmacro GATHERING ...)", "macroexpand": "(common-lisp:let ()\n :key\n nil\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(action (:before node-let) #'add-local-funs)\n\nPattern to recognize: Macro call that should be transformed by action", "input": "(action (:before node-let) #'add-local-funs)", "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 :before) (quote node-let) (function add-local-funs))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-api ensure-readtable (name &optional (default nil default-p)) (named-readtable-designator &optional (or named-readtable-designator null) => readtable) \"Looks up the readtable specified by NAME and returns it if it's found. If it is not found, it registers the readtable designated by DEFAULT under the name represented by NAME; or if no default argument is given, it signals an error of type READTABLE-DOES-NOT-EXIST instead.\" (cond ((find-readtable name)) ((not default-p) (error 'readtable-does-not-exist :readtable-name name)) (t (setf (find-readtable name) (ensure-readtable default)))))\n\nPattern to recognize: Macro call that should be transformed by define-api", "input": "(define-api ensure-readtable (name &optional (default nil default-p)) (named-readtable-designator &optional (or named-readtable-designator null) => readtable) \"Looks up the readtable specified by NAME and returns it if it's found. If it is not found, it registers the readtable designated by DEFAULT under the name represented by NAME; or if no default argument is given, it signals an error of type READTABLE-DOES-NOT-EXIST instead.\" (cond ((find-readtable name)) ((not default-p) (error 'readtable-does-not-exist :readtable-name name)) (t (setf (find-readtable name) (ensure-readtable default)))))", "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 &optional (or named-readtable-designator null)) (values readtable &optional)) ensure-readtable)) (locally (declare (sb-ext:muffle-conditions style-warning)) (defun ensure-readtable (name &optional (default nil default-p)) \"Looks up the readtable specified by NAME and returns it if it's found. If it is not found, it registers the readtable designated by DEFAULT under the name represented by NAME; or if no default argument is given, it signals an error of type READTABLE-DOES-NOT-EXIST instead.\" (locally (declare (sb-ext:unmuffle-conditions style-warning)) (cond ((find-readtable name)) ((not default-p) (error (quote readtable-does-not-exist) :readtable-name name)) (t (setf (find-readtable name) (ensure-readtable default))))))))", "category": "efficiency", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(pop-preprocessor-directive-token tmp-token-list directive-symbol)\n\nWrite a macro that addresses: Macro call that should be transformed by pop-preprocessor-directive-token", "input": "(pop-preprocessor-directive-token tmp-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_266 (check-and-pop-pp-directive-token-1 tmp-token-list directive-symbol t))) (if (eq +whitespace-marker+ #:head_266) (check-and-pop-pp-directive-token-1 tmp-token-list directive-symbol t) #:head_266))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defclause-driver (for var in-file filename &optional using (reader '#'read)) \"Forms in a file\" (top-level-check) (return-stream-driver-code var filename reader :file generate))\n\nIssue: Macro call that should be transformed by defclause", "input": "(defclause-driver (for var in-file filename &optional using (reader '#'read)) \"Forms in a file\" (top-level-check) (return-stream-driver-code var filename reader :file 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-file-6 (&key ((:for var)) ((:in-file filename)) ((:using reader) (quote (function read))) generate) \"Forms in a file\" (top-level-check) (return-stream-driver-code var filename reader :file generate)) (install-clause-info (quote (for :in-file)) (quote (for :in-file &optional :using)) (quote clause-for-in-file-6) \"Forms in a file\" t) (quote (for var in-file filename &optional using (reader (quote (function read))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ematch0 slots ((list) nil) ((list* (list name pattern) rest) (list* (list name pattern) (parse-slots rest))) ((list something) (etypecase something (keyword (error \"the last slot is a keyword!\")) (symbol (list (list something something))))) ((list something next) (etypecase something (keyword (list (list something next))) (symbol (list* (list something something) (parse-slots (list next)))))) ((list* something next rest) (etypecase something (keyword (list* (list something next) (parse-slots rest))) (symbol (list* (list something something) (parse-slots (list* next rest)))))))\n\nProblem: Macro call that should be transformed by ematch0", "input": "(ematch0 slots ((list) nil) ((list* (list name pattern) rest) (list* (list name pattern) (parse-slots rest))) ((list something) (etypecase something (keyword (error \"the last slot is a keyword!\")) (symbol (list (list something something))))) ((list something next) (etypecase something (keyword (list (list something next))) (symbol (list* (list something something) (parse-slots (list next)))))) ((list* something next rest) (etypecase something (keyword (list* (list something next) (parse-slots rest))) (symbol (list* (list something something) (parse-slots (list* next rest)))))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 slots ((list) nil) ((list* (list name pattern) rest) (list* (list name pattern) (parse-slots rest))) ((list something) (etypecase something (keyword (error \"the last slot is a keyword!\")) (symbol (list (list something something))))) ((list something next) (etypecase something (keyword (list (list something next))) (symbol (list* (list something something) (parse-slots (list next)))))) ((list* something next rest) (etypecase something (keyword (list* (list something next) (parse-slots rest))) (symbol (list* (list something something) (parse-slots (list* next 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(defstore example (a &rest args))\n\nWrite a macro that addresses: Macro call that should be transformed by defstore", "input": "(defstore example (a &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 (a &rest args)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defjsmacro nil nil)\n\nProblem: Macro call that should be transformed by DEFJSMACRO", "input": "(defjsmacro nil nil)", "output": "(defmacro DEFJSMACRO ...)", "macroexpand": "(defpsmacro 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(with-yield\n nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by WITH-YIELD", "input": "(with-yield\n nil\n (progn))", "output": "(defmacro WITH-YIELD ...)", "macroexpand": "(isolate-cont\n (enable-yield\n nil\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(define-alias-binding nconc nconcing)\n\nProblem: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding nconc nconcing)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote nconc)) (quote nconcing)) (quote nconc))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(match* (s1 s2) (((list* (list 'eql o1) s1) (list* (list 'eql o2) s2)) (if (eql o1 o2) (specializer< s1 s2) :equal)) (((list* (list 'eql _) _) _) :less) ((_ (list* (list 'eql _) _)) :greater) (((list* type1 s1) (list* type2 s2)) (let ((class1 (find-class type1)) (class2 (find-class type2))) (ensure-finalized class1) (ensure-finalized class2) (let ((prec1 (rest (class-precedence-list class1))) (prec2 (rest (class-precedence-list class2)))) (cond ((member class2 prec1) :less) ((member class1 prec2) :greater) ((eq class1 class2) (specializer< s1 s2)) (t (or (when (and s1 s2) (let ((order (specializer< s1 s2))) (unless (eq order :equal) order))) (if (string< (class-name class1) (class-name class2)) :less :greater))))))))\n\nWrite a macro that addresses: Macro call that should be transformed by match*", "input": "(match* (s1 s2) (((list* (list 'eql o1) s1) (list* (list 'eql o2) s2)) (if (eql o1 o2) (specializer< s1 s2) :equal)) (((list* (list 'eql _) _) _) :less) ((_ (list* (list 'eql _) _)) :greater) (((list* type1 s1) (list* type2 s2)) (let ((class1 (find-class type1)) (class2 (find-class type2))) (ensure-finalized class1) (ensure-finalized class2) (let ((prec1 (rest (class-precedence-list class1))) (prec2 (rest (class-precedence-list class2)))) (cond ((member class2 prec1) :less) ((member class1 prec2) :greater) ((eq class1 class2) (specializer< s1 s2)) (t (or (when (and s1 s2) (let ((order (specializer< s1 s2))) (unless (eq order :equal) order))) (if (string< (class-name class1) (class-name class2)) :less :greater))))))))", "output": "(defmacro match* ((&rest things) &body clauses)\n `(multiple-value-match (values ,@things)\n ,@clauses))", "macroexpand": "(multiple-value-match (values s1 s2) (((list* (list (quote eql) o1) s1) (list* (list (quote eql) o2) s2)) (if (eql o1 o2) (specializer< s1 s2) :equal)) (((list* (list (quote eql) _) _) _) :less) ((_ (list* (list (quote eql) _) _)) :greater) (((list* type1 s1) (list* type2 s2)) (let ((class1 (find-class type1)) (class2 (find-class type2))) (ensure-finalized class1) (ensure-finalized class2) (let ((prec1 (rest (class-precedence-list class1))) (prec2 (rest (class-precedence-list class2)))) (cond ((member class2 prec1) :less) ((member class1 prec2) :greater) ((eq class1 class2) (specializer< s1 s2)) (t (or (when (and s1 s2) (let ((order (specializer< s1 s2))) (unless (eq order :equal) order))) (if (string< (class-name class1) (class-name class2)) :less :greater))))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defun-compile-time form-callees (form environment) (walk #'(lambda (form form-type) (case form-type ((function-symbol function-setf) (list (second form))) ((symbol-call setf-call) (list (first form))) (otherwise '()))) #'(lambda (&optional (x nil x?) y) (if x? (union x y :test #'equal) '())) t nil t form environment))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time form-callees (form environment) (walk #'(lambda (form form-type) (case form-type ((function-symbol function-setf) (list (second form))) ((symbol-call setf-call) (list (first form))) (otherwise '()))) #'(lambda (&optional (x nil x?) y) (if x? (union x y :test #'equal) '())) t nil t form 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 form-callees (form environment) (walk (function (lambda (form form-type) (case form-type ((function-symbol function-setf) (list (second form))) ((symbol-call setf-call) (list (first form))) (otherwise (quote nil))))) (function (lambda (&optional (x nil x?) y) (if x? (union x y :test (function equal)) (quote nil)))) t nil t form environment)) (eval-when (:compile-toplevel) (compile (quote form-callees))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:union-all conjunctive-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:union-all 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-all-op (:include conjunctive-op (name \"UNION ALL\")) (:constructor make-union-all-op (&rest expressions))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"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(is (stringp s))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (stringp 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 ((#:v255 s)) (if (stringp #:v255) (add-result (quote test-passed) :test-expr (quote (stringp s))) (process-failure (quote (stringp s)) \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\" (quote s) #:v255 (quote stringp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defstore example (&rest args))\n\nIssue: Macro call that should be transformed by defstore", "input": "(defstore example (&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 (&rest args)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(mvlet* nil\n nil)\n\nIssue: 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(do-notation bind-either ((sum (inc-either 1)) (str (either->string sum))) str)\n\nWrite a macro that addresses: Macro call that should be transformed by do-notation", "input": "(do-notation bind-either ((sum (inc-either 1)) (str (either->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-either (lambda (sum) (bind-either (lambda (str) str) (either->string sum))) (inc-either 1)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-option-expander documentation (package documentation) (setf (documentation package T) documentation))\n\nWrite a macro that addresses: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander documentation (package documentation) (setf (documentation package T) documentation))", "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 ((#:type124 (eql :documentation)) package #:args123) (destructuring-bind (documentation) #:args123 (setf (documentation package t) documentation)))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(static-dispatch-test-hook)\n\nProblem: Macro call that should be transformed by static-dispatch-test-hook", "input": "(static-dispatch-test-hook)", "output": "(defmacro static-dispatch-test-hook ()\n \"A form of this macro is inserted in the output of the\n STATIC-DISPATCH compiler macro, in order to allow certain test code\n to be inserted, by shadowing this macro using MACROLET. The\n global expands to NIL.\"\n\n nil)", "macroexpand": "nil", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.79} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-effective-qualifier generic-function qualifier `(progn (%load-specializers-to-table ,generic-function ,type-list ,qualifier) ,(remove :unqualified `(defmethod ,generic-function ,qualifier ,descriptive-lambda-list ,@body) :end (if (eql :unqualified qualifier) 3 0))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-effective-qualifier", "input": "(with-effective-qualifier generic-function qualifier `(progn (%load-specializers-to-table ,generic-function ,type-list ,qualifier) ,(remove :unqualified `(defmethod ,generic-function ,qualifier ,descriptive-lambda-list ,@body) :end (if (eql :unqualified qualifier) 3 0))))", "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))) (sb-int:quasiquote (progn (%load-specializers-to-table #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr type-list :kind 0) #S(sb-impl::comma :expr qualifier :kind 0)) #S(sb-impl::comma :expr (remove :unqualified (sb-int:quasiquote (defmethod #S(sb-impl::comma :expr generic-function :kind 0) #S(sb-impl::comma :expr qualifier :kind 0) #S(sb-impl::comma :expr descriptive-lambda-list :kind 0) #S(sb-impl::comma :expr body :kind 2))) :end (if (eql :unqualified qualifier) 3 0)) :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-option-expander local-nicknames (package &rest nicknames) (loop for (nickname name) in nicknames do (trivial-package-local-nicknames:add-package-local-nickname nickname name package)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander local-nicknames (package &rest nicknames) (loop for (nickname name) in nicknames do (trivial-package-local-nicknames:add-package-local-nickname nickname name 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 ((#:type140 (eql :local-nicknames)) package #:args139) (destructuring-bind (&rest nicknames) #:args139 (loop for (nickname name) in nicknames do (sb-ext:add-package-local-nickname nickname name package))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(switch (13 :test =) (12 :oops) (13.0 :yay))\n\nWrite a macro that addresses: Macro call that should be transformed by switch", "input": "(switch (13 :test =) (12 :oops) (13.0 :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 ((#:value129 (identity 13))) (cond ((= #:value129 12) :oops) ((= #:value129 13.0) :yay) (t nil)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(action (:traverse node-for node new-subs) (let ((loop-subs new-subs)) (loop :for binding :in (node-for-bindings node) :for name := (node-for-binding-name binding) :do (when (find name subs :key #'ast-substitution-from) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-for\" name)) :do (when rename-bound-variables (push (make-ast-substitution :from name :to (make-node-variable :type (node-for-binding-type binding) :value (gensym (symbol-name name)))) loop-subs))) (make-node-for :type (node-type node) :label (node-for-label node) :bindings (loop :for binding :in (node-for-bindings node) :for name := (node-for-binding-name binding) :collect (make-node-for-binding :name (if rename-bound-variables (node-variable-value (ast-substitution-to (find name loop-subs :key #'ast-substitution-from))) name) :type (node-for-binding-type binding) :init (funcall *traverse* (node-for-binding-init binding) new-subs) :step (and (node-for-binding-step binding) (funcall *traverse* (node-for-binding-step binding) loop-subs)))) :sequential-p (node-for-sequential-p node) :returns (and (node-for-returns node) (funcall *traverse* (node-for-returns node) loop-subs)) :termination-kind (node-for-termination-kind node) :termination-expr (and (node-for-termination-expr node) (funcall *traverse* (node-for-termination-expr node) loop-subs)) :body (funcall *traverse* (node-for-body node) loop-subs))))\n\nProblem: Macro call that should be transformed by action", "input": "(action (:traverse node-for node new-subs) (let ((loop-subs new-subs)) (loop :for binding :in (node-for-bindings node) :for name := (node-for-binding-name binding) :do (when (find name subs :key #'ast-substitution-from) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-for\" name)) :do (when rename-bound-variables (push (make-ast-substitution :from name :to (make-node-variable :type (node-for-binding-type binding) :value (gensym (symbol-name name)))) loop-subs))) (make-node-for :type (node-type node) :label (node-for-label node) :bindings (loop :for binding :in (node-for-bindings node) :for name := (node-for-binding-name binding) :collect (make-node-for-binding :name (if rename-bound-variables (node-variable-value (ast-substitution-to (find name loop-subs :key #'ast-substitution-from))) name) :type (node-for-binding-type binding) :init (funcall *traverse* (node-for-binding-init binding) new-subs) :step (and (node-for-binding-step binding) (funcall *traverse* (node-for-binding-step binding) loop-subs)))) :sequential-p (node-for-sequential-p node) :returns (and (node-for-returns node) (funcall *traverse* (node-for-returns node) loop-subs)) :termination-kind (node-for-termination-kind node) :termination-expr (and (node-for-termination-expr node) (funcall *traverse* (node-for-termination-expr node) loop-subs)) :body (funcall *traverse* (node-for-body node) loop-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-for) (lambda (node new-subs) (declare (type node-for node)) (let ((loop-subs new-subs)) (loop :for binding :in (node-for-bindings node) :for name := (node-for-binding-name binding) :do (when (find name subs :key (function ast-substitution-from)) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-for\" name)) :do (when rename-bound-variables (push (make-ast-substitution :from name :to (make-node-variable :type (node-for-binding-type binding) :value (gensym (symbol-name name)))) loop-subs))) (make-node-for :type (node-type node) :label (node-for-label node) :bindings (loop :for binding :in (node-for-bindings node) :for name := (node-for-binding-name binding) :collect (make-node-for-binding :name (if rename-bound-variables (node-variable-value (ast-substitution-to (find name loop-subs :key (function ast-substitution-from)))) name) :type (node-for-binding-type binding) :init (funcall *traverse* (node-for-binding-init binding) new-subs) :step (and (node-for-binding-step binding) (funcall *traverse* (node-for-binding-step binding) loop-subs)))) :sequential-p (node-for-sequential-p node) :returns (and (node-for-returns node) (funcall *traverse* (node-for-returns node) loop-subs)) :termination-kind (node-for-termination-kind node) :termination-expr (and (node-for-termination-expr node) (funcall *traverse* (node-for-termination-expr node) loop-subs)) :body (funcall *traverse* (node-for-body node) loop-subs)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym :search :find)\n\nWhat needs to change: 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": "You are a Common Lisp macro expert. Given this code pattern:\n(with nil\n :key\n nil)\n\nWrite a macro that addresses: 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": "Create a Common Lisp macro for the following transformation. Before code:\n(check-declaration-env nil)\n\nWhat needs to change: Macro call that should be transformed by CHECK-DECLARATION-ENV", "input": "(check-declaration-env nil)", "output": "(defmacro CHECK-DECLARATION-ENV ...)", "macroexpand": "(let ()\n (let ((#:new120 (%check-declaration-env nil nil nil)))\n (setq nil #:new120)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(alet (1+ 1) (1+ it))\n\nProblem: Macro call that should be transformed by alet", "input": "(alet (1+ 1) (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 (1+ it)))", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(augment free-vars (free-vars (second binding) bound-vars))\n\nIssue: Macro call that should be transformed by augment", "input": "(augment free-vars (free-vars (second binding) bound-vars))", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf free-vars (nconc free-vars (free-vars (second binding) bound-vars)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-dynenv nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-DYNENV", "input": "(with-dynenv nil\n nil)", "output": "(defmacro WITH-DYNENV ...)", "macroexpand": "(multiple-value-bind (#:var-expansion126 #:var-expanded-p127)\n (macroexpand-1 'var-space nil)\n (multiple-value-bind (#:fun-expansion128 #:fun-expanded-p129)\n (macroexpand-1 'fun-space nil)\n (let ((*var-space* (when #:var-expanded-p127 #:var-expansion126))\n (*fun-space* (when #:fun-expanded-p129 #:fun-expansion128))\n (*within-captured-dynenv* t))\n nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\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\nIssue: 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 `(progn\n (define-method-combination% ,name ,@args)\n (c2mop:define-method-combination ,name ,@args)))", "macroexpand": "(define-method-combination% 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": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-component dot :input-type \"dot\" :output-type \"png\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `(\"dot\" \"-Tpng\" ,input-pathname \"-o\" ,output-pathname) :show t)))\n\nWhat needs to change: Macro call that should be transformed by define-component", "input": "(define-component dot :input-type \"dot\" :output-type \"png\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run `(\"dot\" \"-Tpng\" ,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 dot (source-file) ((type :initform \"dot\") (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component dot)) t) (defmethod output-files ((operation compile-op) (component dot)) (list (output-pathname component \"png\"))) (defmethod perform ((o compile-op) (component dot)) (funcall (lambda (input-pathname output-pathname) (inferior-shell:run (sb-int:quasiquote (\"dot\" \"-Tpng\" #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 \"png\"))) (import (quote dot) :asdf))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-max nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-MAX", "input": "(collect-max nil (progn))", "output": "(defmacro COLLECT-MAX ...)", "macroexpand": "(common-lisp:let* ((#:generator-366 (generator (progn)))\n #:items-356\n (#:generator-364 (generator nil))\n #:numbers-355\n (#:number-358 nil)\n #:result-359)\n (declare (type generator #:generator-366)\n (type generator #:generator-364)\n (type (null-or t) #:result-359))\n (tagbody\n #:ll-367\n (setq #:items-356 (next-in #:generator-366 (go end)))\n (setq #:numbers-355 (next-in #:generator-364 (go end)))\n (if (or (null #:number-358) (< #:number-358 #:numbers-355))\n (setq #:number-358 #:numbers-355\n #:result-359 #:items-356))\n (go #:ll-367)\n end)\n (if (null #:number-358)\n (setq #:result-359 nil))\n #:result-359)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(unwind-protect nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by UNWIND-PROTECT", "input": "(unwind-protect nil\n :key\n nil)", "output": "(defmacro UNWIND-PROTECT ...)", "macroexpand": "(common-lisp:unwind-protect :key nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-comparison-ops == = < < > > <= <= >= >=)\n\nIssue: Macro call that should be transformed by define", "input": "(define-comparison-ops == = < < > > <= <= >= >=)", "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 (progn (defmethod vacietis.c:== ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (= (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:== ((x number) (y number)) (if (= x y) 1 0))) (progn (defmethod vacietis.c:< ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (< (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:< ((x number) (y number)) (if (< x y) 1 0))) (progn (defmethod vacietis.c:> ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (> (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:> ((x number) (y number)) (if (> x y) 1 0))) (progn (defmethod vacietis.c:<= ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (<= (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:<= ((x number) (y number)) (if (<= x y) 1 0))) (progn (defmethod vacietis.c:>= ((x memptr) (y memptr)) (if (and (eq (memptr-mem x) (memptr-mem y)) (>= (memptr-ptr x) (memptr-ptr y))) 1 0)) (defmethod vacietis.c:>= ((x number) (y number)) (if (>= x y) 1 0))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause for (var-or-vars iteration &environment env) \"General iteration clause. Its actual behaviour is controlled by ITERATION, a macro form that FOR expands with *ITERATION-VARIABLE* bound to VAR. Example: in (for x (in '(1 2 3))), IN is a macro that expands into clauses that make use of *ITERATION-VARIABLE*, which is bound to the symbol X in the example. For certain iteration macros, VAR can be a lambda-list as well, in which case destructuring is applied. Example: (for (x &optional y) (in-list '((1 2) (3)))).\" (let ((*iteration-variable* var-or-vars)) (macroexpand iteration env)))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause for (var-or-vars iteration &environment env) \"General iteration clause. Its actual behaviour is controlled by ITERATION, a macro form that FOR expands with *ITERATION-VARIABLE* bound to VAR. Example: in (for x (in '(1 2 3))), IN is a macro that expands into clauses that make use of *ITERATION-VARIABLE*, which is bound to the symbol X in the example. For certain iteration macros, VAR can be a lambda-list as well, in which case destructuring is applied. Example: (for (x &optional y) (in-list '((1 2) (3)))).\" (let ((*iteration-variable* var-or-vars)) (macroexpand iteration 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 for (var-or-vars iteration &environment env) \"General iteration clause. Its actual behaviour is controlled by ITERATION, a macro form that FOR expands with *ITERATION-VARIABLE* bound to VAR. Example: in (for x (in '(1 2 3))), IN is a macro that expands into clauses that make use of *ITERATION-VARIABLE*, which is bound to the symbol X in the example. For certain iteration macros, VAR can be a lambda-list as well, in which case destructuring is applied. Example: (for (x &optional y) (in-list '((1 2) (3)))).\" (let ((*iteration-variable* var-or-vars)) (macroexpand iteration env))) (pushnew (quote for) *clauses*))", "category": "control-flow", "technique": "", "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": "Generate a defmacro form that transforms code like this:\n(define-custom-var (:object-scope *object-scope-variables*) '(*internal-decoder*) \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON Object.\")\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:object-scope *object-scope-variables*) '(*internal-decoder*) \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON 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-scope-variables* . :object-scope)) *custom-vars* :test (function equal)) (defvar *object-scope-variables* (quote (*internal-decoder*)) \"A list of symbols naming dynamic variables which should be re-bound in the scope of every JSON Object.\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lambda-match)\n\nWrite a macro that addresses: Macro call that should be transformed by LAMBDA-MATCH", "input": "(lambda-match)", "output": "(defmacro LAMBDA-MATCH ...)", "macroexpand": "(lambda (#:arg145) (match #:arg145))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define _IOLBF 2)\n\nIssue: Macro call that should be transformed by define", "input": "(define _IOLBF 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 _iolbf) *preprocessor-defines*) #A((1) base-char . \"2\"))) (defparameter _iolbf 2))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (= 2 (add-2 0)))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (= 2 (add-2 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 ((#:e137 2) (#:a138 (add-2 0))) (if (progn (= #:e137 #:a138)) (add-result (quote test-passed) :test-expr (quote (= 2 (add-2 0)))) (process-failure (quote (= 2 (add-2 0))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (add-2 0)) #:a138 (quote =) #:e137)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-autoload-on-missing (let ((*standard-output* (make-broadcast-stream)) (*error-output* (make-broadcast-stream))) (asdf:load-system driver-system :verbose nil)))\n\nProblem: Macro call that should be transformed by with-autoload-on-missing", "input": "(with-autoload-on-missing (let ((*standard-output* (make-broadcast-stream)) (*error-output* (make-broadcast-stream))) (asdf:load-system driver-system :verbose nil)))", "output": "(defmacro with-autoload-on-missing (&body body)\n (let ((retrying (gensym))\n (e (gensym)))\n `(let ((,retrying (make-hash-table :test 'equal)))\n (handler-bind ((asdf:missing-component\n (lambda (,e)\n (unless (gethash (asdf::missing-requires ,e) ,retrying)\n (setf (gethash (asdf::missing-requires ,e) ,retrying) t)\n (when (find :quicklisp *features*)\n (uiop:symbol-call '#:ql-dist '#:ensure-installed\n (uiop:symbol-call '#:ql-dist '#:find-system\n (asdf::missing-requires ,e)))\n (invoke-restart (find-restart 'asdf:retry ,e)))))))\n ,@body))))", "macroexpand": "(let ((#:g158 (make-hash-table :test (quote equal)))) (handler-bind ((asdf/find-component:missing-component (lambda (#:g159) (unless (gethash (asdf/find-component:missing-requires #:g159) #:g158) (setf (gethash (asdf/find-component:missing-requires #:g159) #:g158) t) (when (find :quicklisp *features*) (uiop/package:symbol-call (quote #:ql-dist) (quote #:ensure-installed) (uiop/package:symbol-call (quote #:ql-dist) (quote #:find-system) (asdf/find-component:missing-requires #:g159))) (invoke-restart (find-restart (quote asdf/session:retry) #:g159))))))) (let ((*standard-output* (make-broadcast-stream)) (*error-output* (make-broadcast-stream))) (asdf/operate:load-system driver-system :verbose nil))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-prepared-query query (conn (format nil \"SELECT pg_get_viewdef('~A'::regclass) AS def\" table-name)) (let ((results (dbi:execute query))) (string-right-trim '(#\\Space #\\;) (string-left-trim '(#\\Space) (first (first (dbi:fetch-all results :format :values)))))))\n\nPattern to recognize: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (conn (format nil \"SELECT pg_get_viewdef('~A'::regclass) AS def\" table-name)) (let ((results (dbi:execute query))) (string-right-trim '(#\\Space #\\;) (string-left-trim '(#\\Space) (first (first (dbi:fetch-all results :format :values)))))))", "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 pg_get_viewdef('~A'::regclass) AS def\" table-name) (lambda (query) (let ((results (dbi.driver:execute query))) (string-right-trim (quote (#\\Space #\\SEMICOLON)) (string-left-trim (quote (#\\Space)) (first (first (dbi.driver:fetch-all results :format :values))))))) :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(coexit!)\n\nProblem: Macro call that should be transformed by COEXIT!", "input": "(coexit!)", "output": "(defmacro COEXIT! ...)", "macroexpand": "(coexit (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-> :g (a) (values (+ a 5) -1))\n\nWhat needs to change: Macro call that should be transformed by ->", "input": "(-> :g (a) (values (+ a 5) -1))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (a) (values (+ a 5) -1))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-hook (:build uiop) () (unless uiop/image:*image-dumped-p* (setf uiop/image:*image-dumped-p* T) (setf uiop/image::*image-restored-p* :in-regress) (uiop/image:call-image-dump-hook) (setf uiop/image::*image-restored-p* NIL)))\n\nIssue: Macro call that should be transformed by define-hook", "input": "(define-hook (:build uiop) () (unless uiop/image:*image-dumped-p* (setf uiop/image:*image-dumped-p* T) (setf uiop/image::*image-restored-p* :in-regress) (uiop/image:call-image-dump-hook) (setf uiop/image::*image-restored-p* NIL)))", "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 :build (quote uiop)) (make-instance (quote hook) :name (quote uiop) :type :build)))) (setf (hook-priority uiop) 0) (setf (hook-function uiop) (flet ((uiop (&key &allow-other-keys) (unless uiop/image:*image-dumped-p* (setf uiop/image:*image-dumped-p* t) (setf uiop/image::*image-restored-p* :in-regress) (uiop/image:call-image-dump-hook) (setf uiop/image::*image-restored-p* nil)))) (function uiop))) (setf (hook :build (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(defclause from (initial-value &key to by while (using ''+)) \"Iterates from a given initial value to an optional maximum. Every iteration increments/decrements the value applying the function (by default +) to the previous value and (by default 1 or -1, depending on whether to >= from or not). Similarly, the function is used to determine if has been reached or surpassed. is a function of two arguments, the current value and the value of , and as soon as it returns false, the loop is terminated. defaults to a function that returns true only if has been specified and, letting cur be the current value, (<= (min to from) cur (max to from)).\" (let* ((diff (gensym \"FROM-DIFF\")) (to-evaled (gensym \"FROM-TO\")) (initial-evaled (gensym \"FROM-FROM\")) (while (or while (when to `(lambda (cur to &aux (from ,initial-evaled)) (let ((max (max to from)) (min (min to from))) (<= min cur max))))))) (list (make-simple-iteration :var to-evaled :init to) (make-simple-iteration :var initial-evaled :init initial-value) (make-simple-iteration :var diff :init (if by by `(if ,to-evaled (let ((signum (signum (- ,to-evaled ,initial-evaled)))) (if (zerop signum) +1 signum)) +1))) (make-initialization :form `(when (and ,to-evaled (not (zerop (- ,to-evaled ,initial-evaled))) (not (= (signum (- ,to-evaled ,initial-evaled)) (signum ,diff)))) (terminate))) (make-simple-iteration :init initial-evaled :step `(funcall ,using ,*iteration-variable* ,diff) :postcondition (when while `(funcall ,while ,*iteration-variable* ,to-evaled))))))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause from (initial-value &key to by while (using ''+)) \"Iterates from a given initial value to an optional maximum. Every iteration increments/decrements the value applying the function (by default +) to the previous value and (by default 1 or -1, depending on whether to >= from or not). Similarly, the function is used to determine if has been reached or surpassed. is a function of two arguments, the current value and the value of , and as soon as it returns false, the loop is terminated. defaults to a function that returns true only if has been specified and, letting cur be the current value, (<= (min to from) cur (max to from)).\" (let* ((diff (gensym \"FROM-DIFF\")) (to-evaled (gensym \"FROM-TO\")) (initial-evaled (gensym \"FROM-FROM\")) (while (or while (when to `(lambda (cur to &aux (from ,initial-evaled)) (let ((max (max to from)) (min (min to from))) (<= min cur max))))))) (list (make-simple-iteration :var to-evaled :init to) (make-simple-iteration :var initial-evaled :init initial-value) (make-simple-iteration :var diff :init (if by by `(if ,to-evaled (let ((signum (signum (- ,to-evaled ,initial-evaled)))) (if (zerop signum) +1 signum)) +1))) (make-initialization :form `(when (and ,to-evaled (not (zerop (- ,to-evaled ,initial-evaled))) (not (= (signum (- ,to-evaled ,initial-evaled)) (signum ,diff)))) (terminate))) (make-simple-iteration :init initial-evaled :step `(funcall ,using ,*iteration-variable* ,diff) :postcondition (when while `(funcall ,while ,*iteration-variable* ,to-evaled))))))", "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 from (initial-value &key to by while (using (quote (quote +)))) \"Iterates from a given initial value to an optional maximum. Every iteration increments/decrements the value applying the function (by default +) to the previous value and (by default 1 or -1, depending on whether to >= from or not). Similarly, the function is used to determine if has been reached or surpassed. is a function of two arguments, the current value and the value of , and as soon as it returns false, the loop is terminated. defaults to a function that returns true only if has been specified and, letting cur be the current value, (<= (min to from) cur (max to from)).\" (let* ((diff (gensym \"FROM-DIFF\")) (to-evaled (gensym \"FROM-TO\")) (initial-evaled (gensym \"FROM-FROM\")) (while (or while (when to (sb-int:quasiquote (lambda (cur to &aux (from #S(sb-impl::comma :expr initial-evaled :kind 0))) (let ((max (max to from)) (min (min to from))) (<= min cur max)))))))) (list (make-simple-iteration :var to-evaled :init to) (make-simple-iteration :var initial-evaled :init initial-value) (make-simple-iteration :var diff :init (if by by (sb-int:quasiquote (if #S(sb-impl::comma :expr to-evaled :kind 0) (let ((signum (signum (- #S(sb-impl::comma :expr to-evaled :kind 0) #S(sb-impl::comma :expr initial-evaled :kind 0))))) (if (zerop signum) 1 signum)) 1)))) (make-initialization :form (sb-int:quasiquote (when (and #S(sb-impl::comma :expr to-evaled :kind 0) (not (zerop (- #S(sb-impl::comma :expr to-evaled :kind 0) #S(sb-impl::comma :expr initial-evaled :kind 0)))) (not (= (signum (- #S(sb-impl::comma :expr to-evaled :kind 0) #S(sb-impl::comma :expr initial-evaled :kind 0))) (signum #S(sb-impl::comma :expr diff :kind 0))))) (terminate)))) (make-simple-iteration :init initial-evaled :step (sb-int:quasiquote (funcall #S(sb-impl::comma :expr using :kind 0) #S(sb-impl::comma :expr *iteration-variable* :kind 0) #S(sb-impl::comma :expr diff :kind 0))) :postcondition (when while (sb-int:quasiquote (funcall #S(sb-impl::comma :expr while :kind 0) #S(sb-impl::comma :expr *iteration-variable* :kind 0) #S(sb-impl::comma :expr to-evaled :kind 0)))))))) (pushnew (quote from) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n;; Exporting closure variables requires building pandoric protocol manually\n(let ((a 0))\n (let ((b 1))\n (let (this self)\n (setq\n this (lambda (n) (incf a n) (setq b (* b n)))\n self (dlambda\n (:pandoric-get (sym)\n (case sym\n ((a) a)\n ((b) b)\n (t (error \"Unknown: ~a\" sym))))\n (:pandoric-set (sym val)\n (case sym\n ((a) (setq a val))\n ((b) (setq b val))))\n (t (&rest args) (apply this args)))))))\n\n;; Manual self construction for every closure is painful\n\nPattern to recognize: Need to export closure variables through pandoric protocol, but manually building the self dlambda for each set of variables is repetitive", "input": ";; Exporting closure variables requires building pandoric protocol manually\n(let ((a 0))\n (let ((b 1))\n (let (this self)\n (setq\n this (lambda (n) (incf a n) (setq b (* b n)))\n self (dlambda\n (:pandoric-get (sym)\n (case sym\n ((a) a)\n ((b) b)\n (t (error \"Unknown: ~a\" sym))))\n (:pandoric-set (sym val)\n (case sym\n ((a) (setq a val))\n ((b) (setq b val))))\n (t (&rest args) (apply this args)))))))\n\n;; Manual self construction for every closure is painful", "output": "(defmacro plambda (largs pargs &rest body)\n (let ((pargs (mapcar #'list pargs)))\n `(let (this self)\n (setq\n this (lambda ,largs ,@body)\n self (dlambda\n (:pandoric-get (sym)\n ,(pandoriclet-get pargs))\n (:pandoric-set (sym val)\n ,(pandoriclet-set pargs))\n (t (&rest args)\n (apply this args)))))))", "macroexpand": ";; (let ((a 0))\n;; (let ((b 1))\n;; (plambda (n) (a b)\n;; (incf a n)\n;; (setq b (* b n)))))\n;;\n;; Now:\n;; (with-pandoric (a b) closure\n;; (format t \"a=~a b=~a~%\" a b))\n;; a and b are accessible through the pandoric protocol", "category": "dispatch", "technique": "dlambda,nested-backquote", "complexity": "advanced", "quality_score": 0.975} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> +comment+ +skip-all-space+)\n\nIssue: Macro call that should be transformed by *>", "input": "(*> +comment+ +skip-all-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 (#:*>-offset248) (multiple-value-bind (#:*>-res249 #:*>-next250) (funcall +comment+ #:*>-offset248) (if (ok? #:*>-res249) (funcall +skip-all-space+ #:*>-next250) (fail #:*>-next250))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(if-generator (vals gen) (loop for val in vals for j from 0 do (push val (elt stor j))) (if fail-if-short (error 'insufficient-items :format-control \"Insufficient items in generator\") (return (apply #'values (mapcar #'reverse stor)))))\n\nIssue: Macro call that should be transformed by if-generator", "input": "(if-generator (vals gen) (loop for val in vals for j from 0 do (push val (elt stor j))) (if fail-if-short (error 'insufficient-items :format-control \"Insufficient items in generator\") (return (apply #'values (mapcar #'reverse stor)))))", "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 ((vals (multiple-value-list (funcall gen)))) (if (eq (quote generator-stop) (car vals)) (if fail-if-short (error (quote insufficient-items) :format-control \"Insufficient items in generator\") (return (apply (function values) (mapcar (function reverse) stor)))) (loop for val in vals for j from 0 do (push val (elt stor j)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-case-preserving-syntax)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-CASE-PRESERVING-SYNTAX", "input": "(enable-case-preserving-syntax)", "output": "(defmacro ENABLE-CASE-PRESERVING-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-case-preserving-syntax-in-readtable :start-character #\\COMMA\n :dispatch-character #\\NUMBER_SIGN\n :readtable-case :preserve :packages\n 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(if-it (mismatch suffix string :from-end t :test test :end2 (when -end (- (length string) -end))) (zerop it) t)\n\nWrite a macro that addresses: Macro call that should be transformed by if-it", "input": "(if-it (mismatch suffix string :from-end t :test test :end2 (when -end (- (length string) -end))) (zerop it) t)", "output": "(defmacro if-it (test then &optional else)\n \"Like IF. IT is bound to TEST.\"\n `(let ((it ,test))\n (if it ,then ,else)))", "macroexpand": "(let ((it (mismatch suffix string :from-end t :test test :end2 (when -end (- (length string) -end))))) (if it (zerop it) t))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-feature-cond-syntax)\n\nProblem: Macro call that should be transformed by ENABLE-FEATURE-COND-SYNTAX", "input": "(enable-feature-cond-syntax)", "output": "(defmacro ENABLE-FEATURE-COND-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-feature-cond-syntax-in-readtable :start-character #\\ASTERISK\n :dispatch-character #\\NUMBER_SIGN\n :end-character nil :readtable-case nil)\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(macroexpand-convention (form) (if (consp form) (expand-export-structure-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-structure-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-structure-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(do-notation bind-either ((sum (left 1)) (str (either->string sum))) (print str))\n\nWhat needs to change: Macro call that should be transformed by do-notation", "input": "(do-notation bind-either ((sum (left 1)) (str (either->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-either (lambda (sum) (bind-either (lambda (str) (print str)) (either->string sum))) (left 1)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defjs map1() (if (< this.k 90) (emit this.name 1) (emit this.k 99)))\n\nProblem: Macro call that should be transformed by defjs", "input": "(defjs map1() (if (< this.k 90) (emit this.name 1) (emit this.k 99)))", "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 (if (< this.k 90) (emit this.name 1) (emit this.k 99)))))) (setf (gethash (quote map1) *js-definitions*) js-body) (defun map1 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(destructuring-bind () :key nil)\n\nProblem: Macro call that should be transformed by DESTRUCTURING-BIND", "input": "(destructuring-bind () :key nil)", "output": "(defmacro DESTRUCTURING-BIND ...)", "macroexpand": "(sb-int:binding* ((nil (sb-c::check-ds-list :key 0 0 'nil)))\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(when-let (x (opaque :ok)) (setf x (cons x x)) x)\n\nWrite a macro that addresses: Macro call that should be transformed by when-let", "input": "(when-let (x (opaque :ok)) (setf x (cons x x)) x)", "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 (opaque :ok))) (when (and x) (setf x (cons x x)) x))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defgenerator some-numbers () (loop for i from 1 upto 3 do (yield i)) (dotimes (j 3) (yield (- 10 j))))\n\nWrite a macro that addresses: Macro call that should be transformed by defgenerator", "input": "(defgenerator some-numbers () (loop for i from 1 upto 3 do (yield i)) (dotimes (j 3) (yield (- 10 j))))", "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 some-numbers nil nil (with-yield (loop for i from 1 upto 3 do (yield i)) (dotimes (j 3) (yield (- 10 j)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(def-neo4j-fun create-relationship (node-id to-node-id relationship-type properties) :post (:uri-spec (format nil \"node/~A/relationships\" node-id)) (:encode (list to-node-id relationship-type properties) :relationship) (:status-handlers (201 (decode-neo4j-json-output 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 create-relationship (node-id to-node-id relationship-type properties) :post (:uri-spec (format nil \"node/~A/relationships\" node-id)) (:encode (list to-node-id relationship-type properties) :relationship) (:status-handlers (201 (decode-neo4j-json-output 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 create-relationship (&key node-id to-node-id relationship-type properties) (let ((uri (format nil \"node/~A/relationships\" node-id)) (json (encode-neo4j-json-payload (list to-node-id relationship-type properties) :relationship))) (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))) (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": "Write a Common Lisp macro to handle this code pattern:\n(def-slot-annotation optional (init-form) (unless (plist-member slot-options :initarg) (setf (getf slot-options :initarg) (make-keyword slot-name))) (unless (plist-member slot-options :initform) (setf (getf slot-options :initform) init-form)))\n\nProblem: Macro call that should be transformed by def-slot-annotation", "input": "(def-slot-annotation optional (init-form) (unless (plist-member slot-options :initarg) (setf (getf slot-options :initarg) (make-keyword slot-name))) (unless (plist-member slot-options :initform) (setf (getf slot-options :initform) init-form)))", "output": "(defmacro def-slot-annotation (name args &body body)\n (with-gensyms (slot-specifier)\n `(defannotation ,name ,(append args (list slot-specifier))\n (:inline t :arity ,(1+ (length args)))\n (destructuring-bind (slot-name . slot-options)\n (if (consp ,slot-specifier)\n ,slot-specifier\n (list ,slot-specifier))\n ,@body\n (cons slot-name slot-options)))))", "macroexpand": "(defannotation optional (init-form #:slot-specifier122) (:inline t :arity 2) (destructuring-bind (slot-name . slot-options) (if (consp #:slot-specifier122) #:slot-specifier122 (list #:slot-specifier122)) (unless (plist-member slot-options :initarg) (setf (getf slot-options :initarg) (make-keyword slot-name))) (unless (plist-member slot-options :initform) (setf (getf slot-options :initform) init-form)) (cons slot-name slot-options)))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(f_\n nil)\n\nIssue: Macro call that should be transformed by F_", "input": "(f_\n nil)", "output": "(defmacro F_ ...)", "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(action (:traverse node-let) #'propagate-constants-node-let)\n\nWhat needs to change: Macro call that should be transformed by action", "input": "(action (:traverse node-let) #'propagate-constants-node-let)", "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) (function propagate-constants-node-let))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lret ((x 1) (y (make-array 1))) (setf (aref y 0) x))\n\nWhat needs to change: Macro call that should be transformed by lret", "input": "(lret ((x 1) (y (make-array 1))) (setf (aref y 0) 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 (make-array 1))) (setf (aref y 0) x))", "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(make-stream-method pp-xml-value (s (value float) &optional colon-p at-p) (declare (ignore colon-p at-p)) (if (< (- (abs value) *precision-epsilon*) 0.00000001) (format s \"0\") (format s \"~v$\" *float-format-precision* value)))\n\nWrite a macro that addresses: Macro call that should be transformed by make-stream-method", "input": "(make-stream-method pp-xml-value (s (value float) &optional colon-p at-p) (declare (ignore colon-p at-p)) (if (< (- (abs value) *precision-epsilon*) 0.00000001) (format s \"0\") (format s \"~v$\" *float-format-precision* value)))", "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-value ((s stream) (value float) &optional colon-p at-p) (declare (ignore colon-p at-p)) (if (< (- (abs value) *precision-epsilon*) 1.0e-8) (format s \"0\") (format s \"~v$\" *float-format-precision* value))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(is equal \"A\" (string :a))\n\nWhat needs to change: Macro call that should be transformed by is", "input": "(is equal \"A\" (string :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 equal \"A\" (string :a))) :value-form (quote (string :a)) :body (lambda nil (string :a)) :expected \"A\" :comparison (quote equal)))", "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 (typep (car evaluated) 'node) (setf asts evaluated))\n\nWhat needs to change: Macro call that should be transformed by when", "input": "(when (typep (car evaluated) 'node) (setf 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 evaluated))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (eql (top-info) 'destructor) (format stream \"~~\"))\n\nProblem: Macro call that should be transformed by when", "input": "(when (eql (top-info) 'destructor) (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 destructor)) (format stream \"~~\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-layered-class nil)\n\nIssue: Macro call that should be transformed by DEFINE-LAYERED-CLASS", "input": "(define-layered-class nil)", "output": "(defmacro DEFINE-LAYERED-CLASS ...)", "macroexpand": "(defclass nil nil nil (:metaclass layered-class) (:in-layer . 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-unique-names (body) (let ((body `(tagbody ,@(prologue-forms body-clause) ,@(step-intro-forms body-clause t) ,@(step-outro-forms body-clause t) ,body ,@(body-forms body-clause) ,@(step-intro-forms body-clause nil) ,@(step-outro-forms body-clause nil) (go ,body) ,*epilogue-tag* ,@(epilogue-forms body-clause) (return-from ,*loop-name* ,*accumulation-variable*))) (afterword (afterword-forms body-clause))) (if afterword `((unwind-protect ,body ,@afterword)) `(,body))))\n\nWhat needs to change: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (body) (let ((body `(tagbody ,@(prologue-forms body-clause) ,@(step-intro-forms body-clause t) ,@(step-outro-forms body-clause t) ,body ,@(body-forms body-clause) ,@(step-intro-forms body-clause nil) ,@(step-outro-forms body-clause nil) (go ,body) ,*epilogue-tag* ,@(epilogue-forms body-clause) (return-from ,*loop-name* ,*accumulation-variable*))) (afterword (afterword-forms body-clause))) (if afterword `((unwind-protect ,body ,@afterword)) `(,body))))", "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 ((body (gensym #A((4) base-char . \"BODY\")))) (let ((body (quasiquote (tagbody #S(sb-impl::comma :expr (prologue-forms body-clause) :kind 2) #S(sb-impl::comma :expr (step-intro-forms body-clause t) :kind 2) #S(sb-impl::comma :expr (step-outro-forms body-clause t) :kind 2) #S(sb-impl::comma :expr body :kind 0) #S(sb-impl::comma :expr (body-forms body-clause) :kind 2) #S(sb-impl::comma :expr (step-intro-forms body-clause nil) :kind 2) #S(sb-impl::comma :expr (step-outro-forms body-clause nil) :kind 2) (go #S(sb-impl::comma :expr body :kind 0)) #S(sb-impl::comma :expr *epilogue-tag* :kind 0) #S(sb-impl::comma :expr (epilogue-forms body-clause) :kind 2) (return-from #S(sb-impl::comma :expr *loop-name* :kind 0) #S(sb-impl::comma :expr *accumulation-variable* :kind 0))))) (afterword (afterword-forms body-clause))) (if afterword (quasiquote ((unwind-protect #S(sb-impl::comma :expr body :kind 0) #S(sb-impl::comma :expr afterword :kind 2)))) (quasiquote (#S(sb-impl::comma :expr body :kind 0))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(macroexpand-convention (form) (if (consp form) (expand-export-form-using-head (first form) form) form))\n\nPattern to recognize: Macro call that should be transformed by macroexpand-convention", "input": "(macroexpand-convention (form) (if (consp form) (expand-export-form-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-form-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(in-package nil)\n\nWhat needs to change: Macro call that should be transformed by IN-PACKAGE", "input": "(in-package nil)", "output": "(defmacro IN-PACKAGE ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setq *package*\n (sb-int:find-undeleted-package-or-lose #A((3) base-char . \"NIL\"))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(sif (list 1 2 3) (sif (car it) (setf it 'a) :foo))\n\nWhat needs to change: Macro call that should be transformed by sif", "input": "(sif (list 1 2 3) (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 (list 1 2 3) (sif (car it) (setf it (quote a)) :foo) nil)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(when (eql (info-size) 0) (format stream \"~&\"))\n\nWrite a macro that addresses: 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": "Write a Common Lisp macro to handle this code pattern:\n(doseq (item seq) (accumulate collector item))\n\nProblem: Macro call that should be transformed by doseq", "input": "(doseq (item seq) (accumulate collector item))", "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)) (accumulate collector item))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do-files (file (find-theme theme) \"tmpl\") (compile-template :common-lisp-backend file))\n\nWrite a macro that addresses: Macro call that should be transformed by do-files", "input": "(do-files (file (find-theme theme) \"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-p288 (file) (string= (pathname-type file) \"tmpl\"))) (cl-fad:walk-directory (find-theme theme) (lambda (file) (compile-template :common-lisp-backend file)) :follow-symlinks nil :test (if \"tmpl\" (function #:extension-p288) (constantly t))))", "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-shared-method nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFINE-SHARED-METHOD", "input": "(define-shared-method nil\n (progn))", "output": "(defmacro DEFINE-SHARED-METHOD ...)", "macroexpand": "(define-incongruent-method incongruent-methods.methods::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(with-html-string (:div (:section (:h2 (:p \"hello\")))))\n\nWhat needs to change: Macro call that should be transformed by with-html", "input": "(with-html-string (:div (:section (:h2 (:p \"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 (:div (:section (:h2 (:p \"hello\"))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(action (:after node-variable) #'propagate-constants-node-variable)\n\nProblem: Macro call that should be transformed by action", "input": "(action (:after node-variable) #'propagate-constants-node-variable)", "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) (function propagate-constants-node-variable))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(unwind-protect-case (aborted-p) (random 42) (:always (setq result aborted-p)))\n\nIssue: Macro call that should be transformed by unwind-protect-case", "input": "(unwind-protect-case (aborted-p) (random 42) (:always (setq result aborted-p)))", "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+127 t)) (unwind-protect (multiple-value-prog1 (random 42) (setf #:flag+127 nil)) (let ((aborted-p #:flag+127)) (progn (setq result aborted-p)))))", "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(make-name-transformer nil nil)\n\nProblem: Macro call that should be transformed by MAKE-NAME-TRANSFORMER", "input": "(make-name-transformer nil nil)", "output": "(defmacro MAKE-NAME-TRANSFORMER ...)", "macroexpand": "(lambda (name definition)\n (declare (ignorable definition))\n (concatenate-symbol nil 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-simple-definition-resolver constant designator-constant-p)\n\nWhat needs to change: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver constant designator-constant-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 constant (constant #:package140) (when (ignore-errors (designator-constant-p constant)) (list (make-instance (quote constant) :designator constant :package #:package140))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-timeout (time-limit test) (loop for test in (tests test) do (funcall test)))\n\nProblem: Macro call that should be transformed by with-timeout", "input": "(with-timeout (time-limit test) (loop for test in (tests test) do (funcall test)))", "output": "(defmacro with-timeout (timeout &body body)\n #+(and clisp mt)\n `(mt:with-timeout (,timeout (error 'timeout))\n ,@body)\n #+(or allegro cmucl)\n `(mp:with-timeout (,timeout (error 'timeout))\n ,@body)\n #+sbcl\n `(sb-ext:with-timeout ,timeout\n ,@body)\n #-(or allegro (and clisp mt) cmucl sbcl)\n `(progn\n ,@body))", "macroexpand": "(sb-ext:with-timeout (time-limit test) (loop for test in (tests test) do (funcall test)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ps-html nil :key nil)\n\nIssue: Macro call that should be transformed by PS-HTML", "input": "(ps-html nil :key nil)", "output": "(defmacro PS-HTML ...)", "macroexpand": "(stringify nil #A((11) base-char . \"\") nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(nlet nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by NLET", "input": "(nlet nil\n (progn))", "output": "(defmacro NLET ...)", "macroexpand": "(let* ((progn nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-accumulation-binding counting ((var 0) form) (declare (type (integer 0) var)) `(when ,form (incf ,var)))\n\nPattern to recognize: Macro call that should be transformed by define-accumulation-binding", "input": "(define-accumulation-binding counting ((var 0) form) (declare (type (integer 0) var)) `(when ,form (incf ,var)))", "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 counting ((var 0) form) (declare (type (integer 0) var)) (values (progn (sb-int:quasiquote (when #S(sb-impl::comma :expr form :kind 0) (incf #S(sb-impl::comma :expr var :kind 0))))) (delist var)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(ct-flet nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by CT-FLET", "input": "(ct-flet nil\n nil)", "output": "(defmacro CT-FLET ...)", "macroexpand": "(cond (*within-captured-dynenv* (progn nil))\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": "Write a Common Lisp macro to handle this code pattern:\n(defclause generating (var iteration) \"Lazy version of FOR. The user must call UPDATE or TRY-UPDATE in the body of the DO+ form in order to compute new values for the variable(s). Initialization, instead, is *always* performed eagerly.\" (make-generator :name (if (symbolp var) var (extract-variables var)) :clauses `(for ,var ,iteration)))\n\nProblem: Macro call that should be transformed by defclause", "input": "(defclause generating (var iteration) \"Lazy version of FOR. The user must call UPDATE or TRY-UPDATE in the body of the DO+ form in order to compute new values for the variable(s). Initialization, instead, is *always* performed eagerly.\" (make-generator :name (if (symbolp var) var (extract-variables var)) :clauses `(for ,var ,iteration)))", "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 generating (var iteration) \"Lazy version of FOR. The user must call UPDATE or TRY-UPDATE in the body of the DO+ form in order to compute new values for the variable(s). Initialization, instead, is *always* performed eagerly.\" (make-generator :name (if (symbolp var) var (extract-variables var)) :clauses (sb-int:quasiquote (for #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr iteration :kind 0))))) (pushnew (quote generating) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-mocks () (answer foo 1 2 3) (is (eql 1 (foo))) (is (eql 2 (foo))) (is (eql 3 (foo))) (is (eql 3 (foo))))\n\nIssue: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (answer foo 1 2 3) (is (eql 1 (foo))) (is (eql 2 (foo))) (is (eql 3 (foo))) (is (eql 3 (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 1 2 3) (is (eql 1 (foo))) (is (eql 2 (foo))) (is (eql 3 (foo))) (is (eql 3 (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(dig nil)\n\nProblem: Macro call that should be transformed by DIG", "input": "(dig nil)", "output": "(defmacro DIG ...)", "macroexpand": "(dig 1 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* ((#:|some122| nil) (#:|some122| (when #:|some122| (progn #:|some122|))))\n #:|some122|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(alist-bind (tag name id) form (let (symbol-type) (cond ((string= tag \":struct\") (setf tag :struct) (setf symbol-type :cstruct)) ((string= tag \":union\") (setf tag :union) (setf symbol-type :cunion)) ((string= tag \":enum\") (setf tag :enum) (setf symbol-type :cenum)) (t (error \"Unknown tag for MAKE-RECORD-REF: ~S\" tag))) `((,tag (,(if (and (string= name \"\") (> id 0)) nil (foreign-type-symbol name symbol-type *package*)) ,@(when (and (string= name \"\") (> id 0)) `(:id ,id)))))))\n\nPattern to recognize: Macro call that should be transformed by alist-bind", "input": "(alist-bind (tag name id) form (let (symbol-type) (cond ((string= tag \":struct\") (setf tag :struct) (setf symbol-type :cstruct)) ((string= tag \":union\") (setf tag :union) (setf symbol-type :cunion)) ((string= tag \":enum\") (setf tag :enum) (setf symbol-type :cenum)) (t (error \"Unknown tag for MAKE-RECORD-REF: ~S\" tag))) `((,tag (,(if (and (string= name \"\") (> id 0)) nil (foreign-type-symbol name symbol-type *package*)) ,@(when (and (string= name \"\") (> id 0)) `(:id ,id)))))))", "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 ((#:alist233 form)) (let ((tag (aval :tag #:alist233)) (name (aval :name #:alist233)) (id (aval :id #:alist233))) (let (symbol-type) (cond ((string= tag \":struct\") (setf tag :struct) (setf symbol-type :cstruct)) ((string= tag \":union\") (setf tag :union) (setf symbol-type :cunion)) ((string= tag \":enum\") (setf tag :enum) (setf symbol-type :cenum)) (t (error \"Unknown tag for MAKE-RECORD-REF: ~S\" tag))) (sb-int:quasiquote ((#S(sb-impl::comma :expr tag :kind 0) (#S(sb-impl::comma :expr (if (and (string= name \"\") (> id 0)) nil (foreign-type-symbol name symbol-type *package*)) :kind 0) #S(sb-impl::comma :expr (when (and (string= name \"\") (> id 0)) (sb-int:quasiquote (:id #S(sb-impl::comma :expr id :kind 0)))) :kind 2))))))))", "category": "control-flow", "technique": "once-only", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-quasi-quoted-bivalent-to-binary-emitting-form-syntax nil)\n\nWrite a macro that addresses: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-TO-BINARY-EMITTING-FORM-SYNTAX", "input": "(enable-quasi-quoted-bivalent-to-binary-emitting-form-syntax nil)", "output": "(defmacro ENABLE-QUASI-QUOTED-BIVALENT-TO-BINARY-EMITTING-FORM-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-bivalent-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 \"biv\"\n :encoding\n *default-character-encoding*)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(min-of nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by MIN-OF", "input": "(min-of nil\n :key\n nil)", "output": "(defmacro MIN-OF ...)", "macroexpand": "(lc (nil :key nil) minimize)", "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 (:real *real-handler*))\n\nWhat needs to change: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:real *real-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 (*real-handler* . :real)) *custom-vars* :test (function equal)) (defvar *real-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(deferror \"55P03\" lock-not-available object-state-error)\n\nWhat needs to change: Macro call that should be transformed by deferror", "input": "(deferror \"55P03\" lock-not-available 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 lock-not-available (object-state-error) nil) (setf (gethash \"55P03\" *error-table*) (quote lock-not-available)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"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))) (run-command-with-debug-print `(\"swipl\" \"--quiet\" \"-l\" ,input-file ,@args) :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))) (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 ((d (uiop/run-program:run-program (let ((#:command175 (format nil \"mktemp --tmpdir='~a' ~@[-d~*~] ~@[~a~]\" \"/tmp/\" t nil))) (when (<= 1 *debug-prolog*) (format *error-output* \"~&; ~a~%\" #:command175)) #:command175) :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 (\"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~%\" 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": "Define a macro that eliminates this repetitive pattern:\n(defpattern list (&rest args) (when args `(cons ,(car args) (list ,@(cdr args)))))\n\nIssue: Macro call that should be transformed by defpattern", "input": "(defpattern list (&rest args) (when args `(cons ,(car args) (list ,@(cdr args)))))", "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 list (quote &rest) (quote args) (lambda (when args (quasiquote (cons #S(sb-impl::comma :expr (car args) :kind 0) (list #S(sb-impl::comma :expr (cdr args) :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(when specifier `(specifier (make-nodelist ,specifier)))\n\nPattern to recognize: Macro call that should be transformed by when", "input": "(when specifier `(specifier (make-nodelist ,specifier)))", "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 specifier (sb-int:quasiquote (specifier (make-nodelist #S(sb-impl::comma :expr specifier :kind 0)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-syntax-error* (lexer-pos lexer) \"Character missing after '\\\\c'\")\n\nIssue: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (lexer-pos lexer) \"Character missing after '\\\\c'\")", "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 \"Character missing after '\\\\c'\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(check-cursor-attached cluffer:line (cursor))\n\nIssue: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer: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: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.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(alist-bind (name type bit-size bit-offset bit-alignment) field (let ((symbol (foreign-type-symbol name field-type *package*))) (list* symbol `(,@(parse-type type (aval :tag type)) ,@(when (eq field-type :cfield) `(:bit-size ,bit-size :bit-offset ,bit-offset :bit-alignment ,bit-alignment))))))\n\nWrite a macro that addresses: Macro call that should be transformed by alist-bind", "input": "(alist-bind (name type bit-size bit-offset bit-alignment) field (let ((symbol (foreign-type-symbol name field-type *package*))) (list* symbol `(,@(parse-type type (aval :tag type)) ,@(when (eq field-type :cfield) `(:bit-size ,bit-size :bit-offset ,bit-offset :bit-alignment ,bit-alignment))))))", "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 ((#:alist240 field)) (let ((name (aval :name #:alist240)) (type (aval :type #:alist240)) (bit-size (aval :bit-size #:alist240)) (bit-offset (aval :bit-offset #:alist240)) (bit-alignment (aval :bit-alignment #:alist240))) (let ((symbol (foreign-type-symbol name field-type *package*))) (list* symbol (sb-int:quasiquote (#S(sb-impl::comma :expr (parse-type type (aval :tag type)) :kind 2) #S(sb-impl::comma :expr (when (eq field-type :cfield) (sb-int:quasiquote (:bit-size #S(sb-impl::comma :expr bit-size :kind 0) :bit-offset #S(sb-impl::comma :expr bit-offset :kind 0) :bit-alignment #S(sb-impl::comma :expr bit-alignment :kind 0)))) :kind 2)))))))", "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 x (in '(1 2 3 4))) (for z (previous y)) (for y (previous x)) (collect (list x y z)))\n\nProblem: Macro call that should be transformed by do+", "input": "(do+ (for x (in '(1 2 3 4))) (for z (previous y)) (for y (previous x)) (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 z (previous y)) (for y (previous x)) (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(is-values (values 1 2 nil 3) '(1 2 nil 3))\n\nProblem: Macro call that should be transformed by is-values", "input": "(is-values (values 1 2 nil 3) '(1 2 nil 3))", "output": "(defmacro is-values (got expected &rest args)\n `(is (multiple-value-list ,got) ,expected ,@args))", "macroexpand": "(is (multiple-value-list (values 1 2 nil 3)) (quote (1 2 nil 3)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(lret ((out (make-array (array-dimensions array) :element-type element-type))) (map-into (%flatten out) fn (%flatten array)))\n\nWhat needs to change: Macro call that should be transformed by lret", "input": "(lret ((out (make-array (array-dimensions array) :element-type element-type))) (map-into (%flatten out) fn (%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 (array-dimensions array) :element-type element-type))) (map-into (%flatten out) fn (%flatten array)))", "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(list-of 'some-name)\n\nWhat needs to change: Macro call that should be transformed by LIST-OF", "input": "(list-of 'some-name)", "output": "(defmacro LIST-OF ...)", "macroexpand": "(lc ('some-name) collect)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-sum nil (progn))\n\nProblem: Macro call that should be transformed by COLLECT-SUM", "input": "(collect-sum nil (progn))", "output": "(defmacro COLLECT-SUM ...)", "macroexpand": "(compiler-let ((*optimize-series-expressions* nil)) (collect-sum nil (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(append-at-end nil :key nil)\n\nPattern to recognize: Macro call that should be transformed by APPEND-AT-END", "input": "(append-at-end nil :key nil)", "output": "(defmacro APPEND-AT-END ...)", "macroexpand": "(dolist (#:a122 nil)\n (typecase #:a122\n (list (collect-at-end nil :key #:a122))\n (t\n (let ((c (cons #:a122 nil)))\n (when (null nil) (setf nil c))\n (unless (null :key) (setf (cdr :key) c))\n (setf :key (last c))))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defgenerator ifilter (predicate generator) \"Emits only those items in generator that are true by predicate. The generator equivalent of remove-if-not\" (do-generator (g generator) (when (funcall predicate g) (yield g))))\n\nIssue: Macro call that should be transformed by defgenerator", "input": "(defgenerator ifilter (predicate generator) \"Emits only those items in generator that are true by predicate. The generator equivalent of remove-if-not\" (do-generator (g generator) (when (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 (predicate generator) \"Emits only those items in generator that are true by predicate. The generator equivalent of remove-if-not\" (with-yield (do-generator (g generator) (when (funcall predicate g) (yield g)))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-custom-var (:array-type *json-array-type*) 'vector)\n\nProblem: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:array-type *json-array-type*) 'vector)", "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-array-type* . :array-type)) *custom-vars* :test (function equal)) (defvar *json-array-type* (quote vector))))", "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 :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DRELETF", "input": "(dreletf nil\n :key\n nil)", "output": "(defmacro DRELETF ...)", "macroexpand": "(let ((#:symbol-store234\n (with-symbol-access\n (list))))\n (special-symbol-reprogv #:symbol-store234\n (list)\n (locally (declare (special)) :key nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(newq nil (progn))\n\nIssue: Macro call that should be transformed by NEWQ", "input": "(newq nil (progn))", "output": "(defmacro NEWQ ...)", "macroexpand": "(new 'nil (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclass/a dbi-driver () () (:documentation \"Base class for DB driver.\"))\n\nProblem: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbi-driver () () (:documentation \"Base class for DB 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 dbi-driver nil nil (:documentation \"Base class for DB driver.\")) (deftype nil (quote dbi-driver)) (setf (find-class (quote )) (find-class (quote dbi-driver))))", "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 'some-name)\n\nWhat needs to change: Macro call that should be transformed by LAMBDA-MATCH", "input": "(lambda-match\n 'some-name)", "output": "(defmacro LAMBDA-MATCH ...)", "macroexpand": "(lambda (#:arg150)\n (match #:arg150\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(with-access-values nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-ACCESS-VALUES", "input": "(with-access-values nil\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* ())", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.7549999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(collect-alist nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-ALIST", "input": "(collect-alist nil nil)", "output": "(defmacro COLLECT-ALIST ...)", "macroexpand": "(common-lisp:let* ((#:generator-430 (generator nil))\n #:values-423\n (#:generator-428 (generator nil))\n #:keys-422\n (#:alist-424 nil))\n (declare (type generator #:generator-430)\n (type generator #:generator-428)\n (type list #:alist-424))\n (tagbody\n #:ll-431\n (setq #:values-423 (next-in #:generator-430 (go end)))\n (setq #:keys-422 (next-in #:generator-428 (go end)))\n (setq #:alist-424 (cons (cons #:keys-422 #:values-423) #:alist-424))\n (go #:ll-431)\n end)\n #:alist-424)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(declare-deprecated-operators nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS", "input": "(declare-deprecated-operators nil 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 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": "Write a Common Lisp macro to handle this code pattern:\n(log-message z z)\n\nProblem: Macro call that should be transformed by log-message", "input": "(log-message z z)", "output": "(defmacro log-message (category description &rest arguments)\n `(log-manager-message (log-manager) ,category ,description ,@arguments))", "macroexpand": "(log-manager-message (log-manager) z z)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(signal-syntax-error* (1- (lexer-pos lexer)) \"Quantifier '~A' not allowed.\" next-char)\n\nPattern to recognize: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (1- (lexer-pos lexer)) \"Quantifier '~A' not allowed.\" 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 \"Quantifier '~A' not allowed.\" :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(while 'some-name)\n\nWhat needs to change: Macro call that should be transformed by WHILE", "input": "(while 'some-name)", "output": "(defmacro WHILE ...)", "macroexpand": "(loop while 'some-name\n do (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-reader-syntax (hash-table) (is (equalp (alexandria:plist-hash-table '(:a 1 :b 2) :test 'equalp) (er \"{:a 1 :b 2}\"))) (is (equalp (alexandria:plist-hash-table '(:a 1 :b 2) :test 'eq) (er \"{eq :a 1 :b 2}\"))) (is (equalp (alexandria:plist-hash-table '(\"a\" 1.0 \"b\" 2) :test 'equalp) (er \"{\\\"a\\\" 1 \\\"b\\\" 2}\"))))\n\nProblem: Macro call that should be transformed by with-reader-syntax", "input": "(with-reader-syntax (hash-table) (is (equalp (alexandria:plist-hash-table '(:a 1 :b 2) :test 'equalp) (er \"{:a 1 :b 2}\"))) (is (equalp (alexandria:plist-hash-table '(:a 1 :b 2) :test 'eq) (er \"{eq :a 1 :b 2}\"))) (is (equalp (alexandria:plist-hash-table '(\"a\" 1.0 \"b\" 2) :test 'equalp) (er \"{\\\"a\\\" 1 \\\"b\\\" 2}\"))))", "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 hash-table)))) (is (equalp (alexandria:plist-hash-table (quote (:a 1 :b 2)) :test (quote equalp)) (er \"{:a 1 :b 2}\"))) (is (equalp (alexandria:plist-hash-table (quote (:a 1 :b 2)) :test (quote eq)) (er \"{eq :a 1 :b 2}\"))) (is (equalp (alexandria:plist-hash-table (quote (\"a\" 1.0 \"b\" 2)) :test (quote equalp)) (er \"{\\\"a\\\" 1 \\\"b\\\" 2}\"))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is \"<~S>\" \"<~S>\")\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is \"<~S>\" \"<~S>\")", "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 ((#:expected171 \"<~S>\")) (let* ((#:new-args169 (list)) (#:desc170 (parse-description-and-test #:new-args169))) (with-catching-errors (:description #:desc170 :expected #:expected171) (with-duration ((#:duration167 #:result168) \"<~S>\") (test #:result168 #:expected171 #:new-args169 :duration #:duration167)))))", "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(define-test finish (finish T) (finish (error \"NOPE\")))\n\nProblem: Macro call that should be transformed by define-test", "input": "(define-test finish (finish T) (finish (error \"NOPE\")))", "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 finish) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote finish) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (finish t)) (lambda nil (finish (error \"NOPE\")))) :parent (quote nil))) (quote finish))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(flet* nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by FLET*", "input": "(flet* nil\n :key\n nil)", "output": "(defmacro FLET* ...)", "macroexpand": "(flet ()\n :key\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* ((#:g138 nil))\n #:g138)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dotable (item _ set2) (add# item set))\n\nWhat needs to change: Macro call that should be transformed by dotable", "input": "(dotable (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 ((#:table166 set2)) (block nil (etypecase #:table166 (hash-table (maphash (lambda (item _) (declare (ignore rutils.bind:_)) (|ADD#| item set)) #:table166)) (list (if (alistp #:table166) (dolist (#:g165 #:table166) (destructuring-bind (item . _) #:g165 (declare (ignore _)) (|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.825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-generator (val generator) (yield (apply function val)))\n\nWhat needs to change: Macro call that should be transformed by do-generator", "input": "(do-generator (val generator) (yield (apply function val)))", "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 ((#:g166 generator)) (loop do (if-generator ((val) #:g166) (progn (yield (apply function val))) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-env (setp 5 [clos-object 'a]))\n\nIssue: Macro call that should be transformed by with-env", "input": "(with-env (setp 5 [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 (#:g138) (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 #:g138 (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 5 [clos-object (quote a])))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g138)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"42P01\" undefined-table syntax-error-or-access-violation)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"42P01\" undefined-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 undefined-table (syntax-error-or-access-violation) nil) (setf (gethash \"42P01\" *error-table*) (quote undefined-table)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(declare-unary-operator 'some-name)\n\nIssue: Macro call that should be transformed by DECLARE-UNARY-OPERATOR", "input": "(declare-unary-operator 'some-name)", "output": "(defmacro DECLARE-UNARY-OPERATOR ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (infix-math/data::save-unary-operator ''some-name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(do-subclasses (itype index) (discover itype))\n\nPattern to recognize: Macro call that should be transformed by do-subclasses", "input": "(do-subclasses (itype index) (discover itype))", "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 ((#:klasses284 (all-subclasses (find-class (quote index))))) (loop for itype in #:klasses284 do (discover itype)))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(adding-smart-slot-methods obj slot (:= (slot-value obj slot) val))\n\nProblem: Macro call that should be transformed by adding-smart-slot-methods", "input": "(adding-smart-slot-methods obj slot (:= (slot-value obj slot) val))", "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) val) (simple-error (#:g155) (let ((#:g156 (class-of obj)) (#:g157 (symbol-name slot))) (dolist (#:g158 (sb-mop:class-slots #:g156) (error #:g155)) (let ((#:g158 (sb-mop:slot-definition-name #:g158))) (when (string= #:g157 (symbol-name #:g158)) (add-method (ensure-generic-function (quote smart-slot-value)) (make-instance (quote standard-method) :specializers (list #:g156 (sb-mop:intern-eql-specializer slot)) :lambda-list (quote (obj slot)) :function (lambda (#:g159 _) (declare (ignorable _)) (slot-value (first #:g159) #:g158)))) (add-method (ensure-generic-function (quote smart-set-slot-value)) (make-instance (quote standard-method) :specializers (list #:g156 (sb-mop:intern-eql-specializer slot) (find-class (quote t))) :lambda-list (quote (obj slot #:g160)) :function (lambda (#:g159 _) (declare (ignorable _)) (:= (slot-value (first #:g159) #:g158) (third #:g159))))) (let ((slot #:g158)) (return (:= (slot-value obj slot) val)))))))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ct-flet nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by CT-FLET", "input": "(ct-flet nil\n :key\n nil)", "output": "(defmacro CT-FLET ...)", "macroexpand": "(cond (*within-captured-dynenv* (progn :key nil))\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": "Define a macro that eliminates this repetitive pattern:\n(define nil)\n\nIssue: Macro call that should be transformed by DEFINE", "input": "(define nil)", "output": "(defmacro DEFINE ...)", "macroexpand": "(eval-when (:load-toplevel :execute)\n (check-if-bound 'nil)\n (setf (get 'nil 'read-macro)\n (lambda (#:stream145) (let ((*standard-input* #:stream145)))))\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 env-parent-context-mismatch () (env-a env-b) \"Attempting to make an environment with different context to it's parent ~s~%~s~%~s\" (cons (v-context env-a) (v-context env-b)) env-a env-b)\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error env-parent-context-mismatch () (env-a env-b) \"Attempting to make an environment with different context to it's parent ~s~%~s~%~s\" (cons (v-context env-a) (v-context 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 env-parent-context-mismatch (:error-type varjo-error :prefix \"Varjo\") (env-a env-b) \"Attempting to make an environment with different context to it's parent ~s~%~s~%~s\" (cons (v-context env-a) (v-context env-b)) env-a env-b)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\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\nPattern to recognize: Macro call that should be transformed by gen-lambda-with-sticky-stop", "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-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 (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": "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-variable node new-subs) (alexandria:when-let ((res (or (find (node-variable-value node) subs :key #'ast-substitution-from) (find (node-variable-value node) new-subs :key #'ast-substitution-from)))) (ast-substitution-to res)))\n\nWrite a macro that addresses: Macro call that should be transformed by action", "input": "(action (:after node-variable node new-subs) (alexandria:when-let ((res (or (find (node-variable-value node) subs :key #'ast-substitution-from) (find (node-variable-value node) new-subs :key #'ast-substitution-from)))) (ast-substitution-to res)))", "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 new-subs) (declare (type node-variable node)) (alexandria:when-let ((res (or (find (node-variable-value node) subs :key (function ast-substitution-from)) (find (node-variable-value node) new-subs :key (function ast-substitution-from))))) (ast-substitution-to res))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-expander car 1 (expr val new-val) (declare (ignore expr)) `(cons ,new-val (cdr ,val)))\n\nWhat needs to change: Macro call that should be transformed by define-modf-expander", "input": "(define-modf-expander car 1 (expr val new-val) (declare (ignore expr)) `(cons ,new-val (cdr ,val)))", "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 car) *modf-nth-arg*) 1 (gethash (quote car) *modf-expansions*) (lambda (expr val new-val) (declare (ignore expr)) (sb-int:quasiquote (cons #S(sb-impl::comma :expr new-val :kind 0) (cdr #S(sb-impl::comma :expr val :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(true 2)\n\nPattern to recognize: Macro call that should be transformed by true", "input": "(true 2)", "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 2)) :value-form (quote 2) :body (lambda nil 2) :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(defstruct-compile-time (variable (:print-function print-variable) (:predicate variable?) (:constructor make-variable-internal)) name (noticers nil) (enumerated-domain t) (enumerated-antidomain nil) value (possibly-integer? t) (possibly-noninteger-real? t) (possibly-nonreal-number? t) (possibly-boolean? t) (possibly-nonboolean-nonnumber? t) (lower-bound nil) (upper-bound nil))\n\nWhat needs to change: Macro call that should be transformed by defstruct-compile-time", "input": "(defstruct-compile-time (variable (:print-function print-variable) (:predicate variable?) (:constructor make-variable-internal)) name (noticers nil) (enumerated-domain t) (enumerated-antidomain nil) value (possibly-integer? t) (possibly-noninteger-real? t) (possibly-nonreal-number? t) (possibly-boolean? t) (possibly-nonboolean-nonnumber? t) (lower-bound nil) (upper-bound nil))", "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 (variable (:print-function print-variable) (:predicate variable?) (:constructor make-variable-internal)) name (noticers nil) (enumerated-domain t) (enumerated-antidomain nil) value (possibly-integer? t) (possibly-noninteger-real? t) (possibly-nonreal-number? t) (possibly-boolean? t) (possibly-nonboolean-nonnumber? t) (lower-bound nil) (upper-bound nil)))", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cond-> 'some-name)\n\nIssue: Macro call that should be transformed by COND->", "input": "(cond-> 'some-name)", "output": "(defmacro COND-> ...)", "macroexpand": "(let* ((#:g140 'some-name))\n #:g140)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(emit nil)\n\nProblem: Macro call that should be transformed by EMIT", "input": "(emit nil)", "output": "(defmacro EMIT ...)", "macroexpand": "(let ((#:ast181 nil))\n (progn\n (assert (typep #:ast181 'delayed-emitting) nil\n \"Something went awry around the quasi quoted stuff, EMIT got a ~S.\"\n #:ast181)\n (funcall #:ast181)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-custom-var (:array-type *json-array-type*) 'vector \"The Lisp sequence type to which JSON Arrays are to be coerced.\")\n\nIssue: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:array-type *json-array-type*) 'vector \"The Lisp sequence type to which JSON Arrays are to be coerced.\")", "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-array-type* . :array-type)) *custom-vars* :test (function equal)) (defvar *json-array-type* (quote vector) \"The Lisp sequence type to which JSON Arrays are to be coerced.\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-modf-rewrite funcall (expr) (cons (cadadr expr) (cddr expr)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite funcall (expr) (cons (cadadr expr) (cddr 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 funcall) *modf-rewrites*) (lambda (expr) (cons (cadadr expr) (cddr expr)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(c? (when (< (depth self) 4) (loop repeat (1+ (depth self)) collecting (make-kid 'bftree :depth (1+ (depth self))))))\n\nPattern to recognize: Macro call that should be transformed by c?", "input": "(c? (when (< (depth self) 4) (loop repeat (1+ (depth self)) collecting (make-kid 'bftree :depth (1+ (depth 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 ((when (< (depth self) 4) (loop repeat (1+ (depth self)) collecting (make-kid (quote bftree) :depth (1+ (depth self))))))) :value-state :unevaluated :rule (c-lambda (when (< (depth self) 4) (loop repeat (1+ (depth self)) collecting (make-kid (quote bftree) :depth (1+ (depth self)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(do-generators ((a (repeat 2)) (:list b '(4 5 6)) (c (list->generator '(8 9)) :fill-value 30)) (print (* a (+ b c))))\n\nWhat needs to change: Macro call that should be transformed by do-generators", "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-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 ((#:g126 (multi-gen (repeat 2) (list->generator (quote (4 5 6))) (list (list->generator (quote (8 9))) :fill-value 30)))) (loop do (destructuring-bind (#:g128 . #:g127) (multiple-value-list (next-generator-value #:g126)) (unless #:g128 (return)) (let ((a (elt (elt #:g127 0) 0)) (b (elt (elt #:g127 1) 0)) (c (elt (elt #:g127 2) 0))) (print (* a (+ b c)))))))", "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(with-yield\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-YIELD", "input": "(with-yield\n nil)", "output": "(defmacro WITH-YIELD ...)", "macroexpand": "(isolate-cont\n (enable-yield\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(defmacro/ps nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by DEFMACRO/PS", "input": "(defmacro/ps nil\n :key\n nil)", "output": "(defmacro DEFMACRO/PS ...)", "macroexpand": "(progn (defmacro nil :key nil) (import-macros-from-lisp 'nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(\u03c8 nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by \u03a8", "input": "(\u03c8 nil (progn))", "output": "(defmacro \u03a8 ...)", "macroexpand": "(mapcar (\u03bb (progn)) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defconstant +newline+ (make-string 1 :initial-element #\\Newline) \"Used for indentation.\")\n\nPattern to recognize: Macro call that should be transformed by defconstant", "input": "(defconstant +newline+ (make-string 1 :initial-element #\\Newline) \"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 +newline+) (make-string 1 :initial-element #\\Newline) (sb-c:source-location) (quote \"Used for indentation.\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(when (not (slot-value (node-slot parameters) 'nodes)) (format stream \"void\"))\n\nProblem: Macro call that should be transformed by when", "input": "(when (not (slot-value (node-slot parameters) 'nodes)) (format stream \"void\"))", "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 (node-slot parameters) (quote nodes))) (format stream \"void\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(do+ (with (x 1)) (terminate nil x))\n\nWrite a macro that addresses: Macro call that should be transformed by do+", "input": "(do+ (with (x 1)) (terminate nil 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 (with (x 1)) (terminate nil x))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "basic", "quality_score": 0.8624999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(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\nPattern to recognize: Macro call that should be transformed by with-output-to-file", "input": "(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-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* (output to :direction :output :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(with-foreign-pointer-as-string ((buf buf-size) 255) (foreign-funcall \"snprintf\" :pointer buf :int buf-size :string \"%d %f #x%x!\" :int 666 :double (coerce pi 'double-float) :unsigned-int #xcafebabe :void))\n\nWhat needs to change: Macro call that should be transformed by with-foreign-pointer", "input": "(with-foreign-pointer-as-string ((buf buf-size) 255) (foreign-funcall \"snprintf\" :pointer buf :int buf-size :string \"%d %f #x%x!\" :int 666 :double (coerce pi 'double-float) :unsigned-int #xcafebabe :void))", "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 ((buf buf-size) 255) (foreign-funcall \"snprintf\" :pointer buf :int buf-size :string \"%d %f #x%x!\" :int 666 :double (coerce pi (quote double-float)) :unsigned-int 3405691582 :void))", "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-alist-cache content-type-cache)\n\nWhat needs to change: Macro call that should be transformed by define-alist-cache", "input": "(define-alist-cache content-type-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-type-cache*) (defun lookup-in-content-type-cache (elt) (when (boundp (quote *content-type-cache*)) (assoc-value *content-type-cache* elt))) (defun (setf lookup-in-content-type-cache) (val elt) (when (boundp (quote *content-type-cache*)) (setf (assoc-value *content-type-cache* elt) val)) val))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-cached-reader-conditionals\n nil\n :key\n nil)\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 :key\n nil)", "output": "(defmacro WITH-CACHED-READER-CONDITIONALS ...)", "macroexpand": "(call-with-cached-reader-conditionals (lambda () nil :key nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(action (:before node-direct-application node new-subs) (when (find (node-direct-application-rator node) subs :key #'ast-substitution-from) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-direct-application\" (node-direct-application-rator node))) (alexandria:when-let ((res (find (node-direct-application-rator node) new-subs :key #'ast-substitution-from))) (make-node-direct-application :type (node-type node) :properties (node-properties node) :rator-type (node-direct-application-rator-type node) :rator (node-variable-value (ast-substitution-to res)) :rands (node-direct-application-rands node) :keyword-rands (node-direct-application-keyword-rands node))))\n\nIssue: Macro call that should be transformed by action", "input": "(action (:before node-direct-application node new-subs) (when (find (node-direct-application-rator node) subs :key #'ast-substitution-from) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-direct-application\" (node-direct-application-rator node))) (alexandria:when-let ((res (find (node-direct-application-rator node) new-subs :key #'ast-substitution-from))) (make-node-direct-application :type (node-type node) :properties (node-properties node) :rator-type (node-direct-application-rator-type node) :rator (node-variable-value (ast-substitution-to res)) :rands (node-direct-application-rands node) :keyword-rands (node-direct-application-keyword-rands 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 :before) (quote node-direct-application) (lambda (node new-subs) (declare (type node-direct-application node)) (when (find (node-direct-application-rator node) subs :key (function ast-substitution-from)) (util:coalton-bug \"Failure to apply ast substitution on variable ~A to node-direct-application\" (node-direct-application-rator node))) (alexandria:when-let ((res (find (node-direct-application-rator node) new-subs :key (function ast-substitution-from)))) (make-node-direct-application :type (node-type node) :properties (node-properties node) :rator-type (node-direct-application-rator-type node) :rator (node-variable-value (ast-substitution-to res)) :rands (node-direct-application-rands node) :keyword-rands (node-direct-application-keyword-rands node)))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(make-stream-method pp-xml-value (s value &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" value))\n\nWhat needs to change: Macro call that should be transformed by make-stream-method", "input": "(make-stream-method pp-xml-value (s value &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" value))", "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-value ((s stream) value &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~A\" value)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-cache (\"none\" :expire 2 :store storage) (error \"SHOULD BE ERROR\"))\n\nProblem: Macro call that should be transformed by with-cache", "input": "(with-cache (\"none\" :expire 2 :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 ((#:key262 \"none\") (#:store263 storage) (#:expire264 2)) (multiple-value-bind (#:value265 #:exists-p266) (getcache #:key262 #:store263) (if #:exists-p266 #:value265 (let ((#:value265 (progn (error \"SHOULD BE ERROR\")))) (setcache #:key262 #:value265 #:store263 :expire #:expire264) #:value265))))", "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(define-custom-var (:end-of-array *end-of-array-handler*))\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:end-of-array *end-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 (*end-of-array-handler* . :end-of-array)) *custom-vars* :test (function equal)) (defvar *end-of-array-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(if-it (mismatch prefix string :test test :start2 start) (= it (length prefix)) t)\n\nPattern to recognize: Macro call that should be transformed by if-it", "input": "(if-it (mismatch prefix string :test test :start2 start) (= it (length prefix)) t)", "output": "(defmacro if-it (test then &optional else)\n \"Like IF. IT is bound to TEST.\"\n `(let ((it ,test))\n (if it ,then ,else)))", "macroexpand": "(let ((it (mismatch prefix string :test test :start2 start))) (if it (= it (length prefix)) t))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-decoder-simple-list-semantics (let ((good-symbols \"{\\\"car\\\":1,\\\"cdr\\\":2}\") (bad-symbols \"{\\\"could-be\\\":1,\\\"a-denial-of-service-attack\\\":2}\") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* #'safe-json-intern)) (is (equal '((car . 1) (cdr . 2)) (decode-json-from-string good-symbols))) (signals unknown-symbol-error (decode-json-from-string bad-symbols))))\n\nProblem: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (let ((good-symbols \"{\\\"car\\\":1,\\\"cdr\\\":2}\") (bad-symbols \"{\\\"could-be\\\":1,\\\"a-denial-of-service-attack\\\":2}\") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* #'safe-json-intern)) (is (equal '((car . 1) (cdr . 2)) (decode-json-from-string good-symbols))) (signals unknown-symbol-error (decode-json-from-string bad-symbols))))", "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 ((good-symbols \"{\\\"car\\\":1,\\\"cdr\\\":2}\") (bad-symbols \"{\\\"could-be\\\":1,\\\"a-denial-of-service-attack\\\":2}\") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* (function safe-json-intern))) (is (equal (quote ((car . 1) (cdr . 2))) (decode-json-from-string good-symbols))) (signals unknown-symbol-error (decode-json-from-string bad-symbols))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(letrec ((x 1) (y (lambda () y))) (is (functionp y)) (is (functionp (funcall y))) (is (numberp x)))\n\nWhat needs to change: Macro call that should be transformed by letrec", "input": "(letrec ((x 1) (y (lambda () y))) (is (functionp y)) (is (functionp (funcall y))) (is (numberp 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 1) (y (lambda nil y))) (is (functionp y)) (is (functionp (funcall y))) (is (numberp x)))", "category": "anaphoric", "technique": "anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-generic generic (a b &key c) (declare (optimize speed (space 2))) (declare (ignorable a b c)) (+ 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))) (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) (declare (optimize speed (space 2))) (:method (a b &key c) (declare (optimize speed (space 2))) (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(declare-deprecated-operators nil)\n\nProblem: Macro call that should be transformed by DECLARE-DEPRECATED-OPERATORS", "input": "(declare-deprecated-operators 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 (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defjsmacro nil :key nil)\n\nIssue: Macro call that should be transformed by DEFJSMACRO", "input": "(defjsmacro nil :key nil)", "output": "(defmacro DEFJSMACRO ...)", "macroexpand": "(defpsmacro 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(define-modf-rewrite seventh (expr) `(caddr (cddddr ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite seventh (expr) `(caddr (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 seventh) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (caddr (cddddr #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(*> (string \"!!!\") (take-until (char #\\')))\n\nIssue: Macro call that should be transformed by *>", "input": "(*> (string \"!!!\") (take-until (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 (#:*>-offset122) (multiple-value-bind (#:*>-res123 #:*>-next124) (funcall (string \"!!!\") #:*>-offset122) (if (ok? #:*>-res123) (funcall (take-until (char #\\APOSTROPHE)) #:*>-next124) (fail #:*>-next124))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"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": "Define a macro that eliminates this repetitive pattern:\n(with-rules nil\n (progn))\n\nIssue: Macro call that should be transformed by WITH-RULES", "input": "(with-rules nil\n (progn))", "output": "(defmacro WITH-RULES ...)", "macroexpand": "(dolist (nil (alexandria:hash-table-keys cl-rules.core::*rules*)) (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 (node-slot initializer) (make-proxy initializer initializer))\n\nWrite a macro that addresses: Macro call that should be transformed by when", "input": "(when (node-slot initializer) (make-proxy initializer 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) (make-proxy initializer initializer))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-shadowed-custom-vars (let ((*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (dotimes (x count) (let ((discard-soon (with-fp-overflow-handler (invoke-restart 'placeholder :infty) (with-no-char-handler (invoke-restart 'substitute-char #\\?) (decode-json-from-string json-string))))) (funcall #'identity discard-soon)))))\n\nIssue: Macro call that should be transformed by with-shadowed-custom-vars", "input": "(with-shadowed-custom-vars (let ((*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (dotimes (x count) (let ((discard-soon (with-fp-overflow-handler (invoke-restart 'placeholder :infty) (with-no-char-handler (invoke-restart 'substitute-char #\\?) (decode-json-from-string json-string))))) (funcall #'identity discard-soon)))))", "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 ((*json-identifier-name-to-lisp* (function simplified-camel-case-to-lisp))) (dotimes (x count) (let ((discard-soon (with-fp-overflow-handler (invoke-restart (quote placeholder) :infty) (with-no-char-handler (invoke-restart (quote substitute-char) #\\QUESTION_MARK) (decode-json-from-string json-string))))) (funcall (function identity) discard-soon)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(who-ps-html 'some-name)\n\nWhat needs to change: Macro call that should be transformed by WHO-PS-HTML", "input": "(who-ps-html 'some-name)", "output": "(defmacro WHO-PS-HTML ...)", "macroexpand": "(stringify \"someName\")", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"42P03\" duplicate-cursor syntax-error-or-access-violation)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"42P03\" duplicate-cursor 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-cursor (syntax-error-or-access-violation) nil) (setf (gethash \"42P03\" *error-table*) (quote duplicate-cursor)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(mvlet* ((simple decls (partn simple decls)) (complex decls (partn complex decls)) (lambda decls (partn lambda decls))) (values simple complex lambda decls))\n\nWrite a macro that addresses: Macro call that should be transformed by mvlet*", "input": "(mvlet* ((simple decls (partn simple decls)) (complex decls (partn complex decls)) (lambda decls (partn lambda decls))) (values simple complex lambda decls))", "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 (simple decls) (partn simple decls) (mvlet* ((complex decls (partn complex decls)) (lambda decls (partn lambda decls))) (values simple complex lambda decls)))", "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(with-yield-binds (format nil \"ON CONFLICT ~:[~;ON CONSTRAINT ~]~A DO UPDATE ~A~@[ ~A~]\" (eq (type-of (on-conflict-do-update-clause-conflict-target clause)) 'sql-symbol) (yield (on-conflict-do-update-clause-conflict-target clause)) (yield (on-conflict-do-update-clause-update-set clause)) (and (on-conflict-do-update-clause-where-condition clause) (yield (on-conflict-do-update-clause-where-condition clause)))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-yield-binds", "input": "(with-yield-binds (format nil \"ON CONFLICT ~:[~;ON CONSTRAINT ~]~A DO UPDATE ~A~@[ ~A~]\" (eq (type-of (on-conflict-do-update-clause-conflict-target clause)) 'sql-symbol) (yield (on-conflict-do-update-clause-conflict-target clause)) (yield (on-conflict-do-update-clause-update-set clause)) (and (on-conflict-do-update-clause-where-condition clause) (yield (on-conflict-do-update-clause-where-condition 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 CONFLICT ~:[~;ON CONSTRAINT ~]~A DO UPDATE ~A~@[ ~A~]\" (eq (type-of (on-conflict-do-update-clause-conflict-target clause)) (quote sql-symbol)) (yield (on-conflict-do-update-clause-conflict-target clause)) (yield (on-conflict-do-update-clause-update-set clause)) (and (on-conflict-do-update-clause-where-condition clause) (yield (on-conflict-do-update-clause-where-condition 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(->*)\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(dynenv-macrolet nil\n nil)\n\nProblem: Macro call that should be transformed by DYNENV-MACROLET", "input": "(dynenv-macrolet nil\n nil)", "output": "(defmacro DYNENV-MACROLET ...)", "macroexpand": "(macrolet ()\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(jbind string \"hello\" string)\n\nWhat needs to change: Macro call that should be transformed by jbind", "input": "(jbind string \"hello\" string)", "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-form127 \"hello\") (string #:bind-form127)) (declare (ignorable #:bind-form127 string)) string)", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8099999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(jbind false nil nil)\n\nWhat needs to change: Macro call that should be transformed by jbind", "input": "(jbind false nil nil)", "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-form126 nil) (false #:bind-form126)) (declare (ignorable #:bind-form126 false)) nil)", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.8099999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-error out-var-name-taken () (out-var-name) \"The variable name '~a' is already taken and so cannot be used~%for an out variable\" out-var-name)\n\nWhat needs to change: Macro call that should be transformed by define-error", "input": "(define-error out-var-name-taken () (out-var-name) \"The variable name '~a' is already taken and so cannot be used~%for an out variable\" out-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 out-var-name-taken (:error-type varjo-error :prefix \"Varjo\") (out-var-name) \"The variable name '~a' is already taken and so cannot be used~%for an out variable\" out-var-name)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-print-object/std foo2)\n\nWhat needs to change: Macro call that should be transformed by define-print-object/std", "input": "(define-print-object/std foo2)", "output": "(defmacro define-print-object/std (class)\n \"Define a print-object method for objects of class CLASS.\n\n Print all slots with their values. Prints \\\"UNBOUND\\\", as a string, when slots are unbound.\n\n Usage:\n\n (defclass/std test () ((a b)))\n\n (print-object/std test)\n\n The macro expands to:\n\n (DEFMETHOD PRINT-OBJECT ((OBJ TEST) STREAM)\n (PRINT-UNREADABLE-OBJECT (OBJ STREAM :TYPE T :IDENTITY T)\n (FORMAT STREAM \\\"~{~a~^ ~}\\\" (COLLECT-OBJECT-SLOTS OBJ))))\n\"\n `(defmethod print-object ((obj ,class) stream)\n (print-unreadable-object (obj stream :type t :identity t)\n (format stream \"~{~a~^ ~}\"\n (collect-object-slots obj)))))", "macroexpand": "(defmethod print-object ((obj foo2) stream) (print-unreadable-object (obj stream :type t :identity t) (format stream \"~{~a~^ ~}\" (collect-object-slots obj))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-value-symbol-macro-binding updating ((var (current iterator)) iterable &rest iterator-args &aux (iterator (apply #'make-iterator iterable iterator-args))) `(if (has-more ,iterator) (next ,iterator) (end-for)))\n\nWrite a macro that addresses: Macro call that should be transformed by define-value-symbol-macro-binding", "input": "(define-value-symbol-macro-binding updating ((var (current iterator)) iterable &rest iterator-args &aux (iterator (apply #'make-iterator iterable iterator-args))) `(if (has-more ,iterator) (next ,iterator) (end-for)))", "output": "(defmacro define-value-symbol-macro-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 :symbol-macro-p T)))", "macroexpand": "(define-direct-binding updating (var iterable &rest iterator-args) (let ((#:iterator182 (gensym #A((8) base-char . \"ITERATOR\"))) (#:iterable180 (gensym #A((8) base-char . \"ITERABLE\"))) (#:iterator-args181 (gensym #A((13) base-char . \"ITERATOR-ARGS\")))) (values* (sb-int:quasiquote (with-interleaving (let* #S(sb-impl::comma :expr (list* (list #:iterable180 iterable) (list #:iterator-args181 (list* (quote list) iterator-args)) (list #:iterator182 (list (quote apply) (list (quote function) (quote make-iterator)) #:iterable180 #:iterator-args181)) nil) :kind 0) (declare (ignorable #S(sb-impl::comma :expr #:iterator182 :kind 0) #S(sb-impl::comma :expr #:iterable180 :kind 0) #S(sb-impl::comma :expr #:iterator-args181 :kind 0)))) #S(sb-impl::comma :expr (sb-int:quasiquote (symbol-macrolet #S(sb-impl::comma :expr (loop for #:var179 in (lambda-fiddle:extract-lambda-vars (enlist var)) collect (list #:var179 (list (quote current) #:iterator182))) :kind 0))) :kind 0))) (let ((iterator #:iterator182) (iterable #:iterable180) (iterator-args #:iterator-args181)) (declare (ignorable iterator iterable iterator-args)) (sb-int:quasiquote (if (has-more #S(sb-impl::comma :expr iterator :kind 0)) (next #S(sb-impl::comma :expr iterator :kind 0)) (end-for)))))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-collectors nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by WITH-COLLECTORS", "input": "(with-collectors nil\n (progn))", "output": "(defmacro WITH-COLLECTORS ...)", "macroexpand": "(progn (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(flet ((,test-fu () ,live-test-form)) (dispatch-repeatedly ,flow-context #',test-fu ,flow-list))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-flow-let-macro", "input": "(with-flow-let-macro (flow-list flow) (flow-lambda-macro (flow-context) `(flet ((,test-fu () ,live-test-form)) (dispatch-repeatedly ,flow-context #',test-fu ,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 (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": "You are a Common Lisp macro expert. Given this code pattern:\n(accase (car x) (:x (setf it :foo)))\n\nWrite a macro that addresses: Macro call that should be transformed by accase", "input": "(accase (car x) (:x (setf it :foo)))", "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) (:x (setf it :foo)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(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\nPattern to recognize: Macro call that should be transformed by with-color", "input": "(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-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 \") (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))))) (cl-ansi-text: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)))))) (progn (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": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(all-of nil\n nil)\n\nIssue: Macro call that should be transformed by ALL-OF", "input": "(all-of nil\n nil)", "output": "(defmacro ALL-OF ...)", "macroexpand": "(lc (nil nil) always)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(*> #'any #'any #'eof)\n\nPattern to recognize: Macro call that should be transformed by *>", "input": "(*> #'any #'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 (#:*>-offset164) (multiple-value-bind (#:*>-res167 #:*>-next168) (multiple-value-bind (#:*>-res165 #:*>-next166) (funcall (function any) #:*>-offset164) (if (ok? #:*>-res165) (funcall (function any) #:*>-next166) (fail #:*>-next166))) (if (ok? #:*>-res167) (funcall (function eof) #:*>-next168) (fail #:*>-next168))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(unwind-protect-case () (return-from foof 42) (:normal (push :normal result3)) (:abort (push :abort result3)) (:always (push :always result3)))\n\nWrite a macro that addresses: Macro call that should be transformed by unwind-protect-case", "input": "(unwind-protect-case () (return-from foof 42) (:normal (push :normal result3)) (:abort (push :abort result3)) (:always (push :always result3)))", "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+126 t)) (unwind-protect (multiple-value-prog1 (return-from foof 42) (setf #:flag+126 nil)) (let nil (when (not #:flag+126) (push :normal result3)) (when #:flag+126 (push :abort result3)) (progn (push :always result3)))))", "category": "control-flow", "technique": "gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(check-cursor-attached cluffer:cursor-position (cursor))\n\nWhat needs to change: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:cursor-position (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:cursor-position :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(builder (:mount \"/mount1\" (lambda (env) (is-path-info env \"/\" \"string=.\") response)) (:mount \"/mount2\" (lambda (env) (is-path-info env \"/test\" \"subseq.\") response)) (lambda (env) (is-path-info env \"/test\" \"t.\") response))\n\nWrite a macro that addresses: Macro call that should be transformed by builder", "input": "(builder (:mount \"/mount1\" (lambda (env) (is-path-info env \"/\" \"string=.\") response)) (:mount \"/mount2\" (lambda (env) (is-path-info env \"/test\" \"subseq.\") response)) (lambda (env) (is-path-info env \"/test\" \"t.\") response))", "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 (#:app212) (funcall (find-middleware :mount) #:app212 \"/mount1\" (lambda (env) (is-path-info env \"/\" \"string=.\") response))) (lambda (#:app214) (funcall (find-middleware :mount) #:app214 \"/mount2\" (lambda (env) (is-path-info env \"/test\" \"subseq.\") response))))) :initial-value (to-app (lambda (env) (is-path-info env \"/test\" \"t.\") response)) :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(setdocs (type unknown-arguments \"Used to represent an unknown list of arguments. Instances of this class are printed as #\") (type unavailable-argument \"Used to represent an argument that isn't available in the environment. Instances of this class are printed as #\"))\n\nProblem: Macro call that should be transformed by setdocs", "input": "(setdocs (type unknown-arguments \"Used to represent an unknown list of arguments. Instances of this class are printed as #\") (type unavailable-argument \"Used to represent an argument that isn't available in the environment. Instances of this class are printed as #\"))", "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 unknown-arguments) (quote type)) \"Used to represent an unknown list of arguments. Instances of this class are printed as #\") (setf (documentation (quote unavailable-argument) (quote type)) \"Used to represent an argument that isn't available in the environment. Instances of this class are printed as #\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defvar nil)\n\nIssue: Macro call that should be transformed by DEFVAR", "input": "(defvar 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)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(as-> nil nil)\n\nProblem: Macro call that should be transformed by AS->", "input": "(as-> nil nil)", "output": "(defmacro AS-> ...)", "macroexpand": "(let* ((nil 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(integer-writer 8)\n\nWrite a macro that addresses: Macro call that should be transformed by integer-writer", "input": "(integer-writer 8)", "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-int8 write-uint8)) (defun write-uint8 (socket value) (declare (type stream socket) (type (unsigned-byte 64) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 56) value) socket) (write-byte (ldb (byte 8 48) value) socket) (write-byte (ldb (byte 8 40) value) socket) (write-byte (ldb (byte 8 32) value) socket) (write-byte (ldb (byte 8 24) value) socket) (write-byte (ldb (byte 8 16) value) socket) (write-byte (ldb (byte 8 8) value) socket) (write-byte (ldb (byte 8 0) value) socket) (values)) (defun write-int8 (socket value) (declare (type stream socket) (type (signed-byte 64) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 56) value) socket) (write-byte (ldb (byte 8 48) value) socket) (write-byte (ldb (byte 8 40) value) socket) (write-byte (ldb (byte 8 32) value) socket) (write-byte (ldb (byte 8 24) value) socket) (write-byte (ldb (byte 8 16) value) socket) (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": "Define a macro that eliminates this repetitive pattern:\n(-> :g (b) (+ b 7))\n\nIssue: Macro call that should be transformed by ->", "input": "(-> :g (b) (+ b 7))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (b) (+ b 7))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(draw canvas (:ellipse :cx x :cy y :rx rx :ry ry) :stroke-opacity (* 0.8 (/ n length)))\n\nWhat needs to change: Macro call that should be transformed by draw", "input": "(draw canvas (:ellipse :cx x :cy y :rx rx :ry ry) :stroke-opacity (* 0.8 (/ n length)))", "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 ((#:g163 (funcall (function make-svg-element) :ellipse (append (list :cx x :cy y :rx rx :ry ry) (list :stroke-opacity (* 0.8 (/ n length))))))) (add-element canvas #:g163) #:g163)", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(loop-on-custom (key var value) customizations append (list var value))\n\nProblem: Macro call that should be transformed by loop-on-custom", "input": "(loop-on-custom (key var value) customizations append (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 append (list var value))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(enable-quasi-quoted-binary-to-binary-emitting-form-syntax 'some-name)\n\nPattern to recognize: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BINARY-TO-BINARY-EMITTING-FORM-SYNTAX", "input": "(enable-quasi-quoted-binary-to-binary-emitting-form-syntax 'some-name)", "output": "(defmacro ENABLE-QUASI-QUOTED-BINARY-TO-BINARY-EMITTING-FORM-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-binary-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 \"bin\")\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-compile-struct sql-clause)\n\nIssue: Macro call that should be transformed by define-compile-struct", "input": "(define-compile-struct sql-clause)", "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-clause-compiled (:include sql-clause)) (sql nil :type string) (bind nil :type list)) (defmethod find-compile-function ((object sql-clause)) (function make-sql-clause-compiled)) (defmethod print-object ((object sql-clause-compiled) stream) (format stream \"#\" (sql-clause-compiled-sql object) (sql-clause-compiled-bind object))) (defmethod yield ((object sql-clause-compiled)) (values (sql-clause-compiled-sql object) (sql-clause-compiled-bind object))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(augment *step* step)\n\nWhat needs to change: Macro call that should be transformed by augment", "input": "(augment *step* step)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf *step* (nconc *step* step))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"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": "(@ (message-oo.mangle::key 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(gatherlet nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by GATHERLET", "input": "(gatherlet nil\n nil)", "output": "(defmacro GATHERLET ...)", "macroexpand": "(common-lisp:let ()\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(action (:after node-application node) (when (eq name (node-rator-name node)) (incf count)) (values))\n\nWhat needs to change: Macro call that should be transformed by action", "input": "(action (:after node-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-application) (lambda (node) (declare (type node-application node)) (when (eq name (node-rator-name node)) (incf count)) (values)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defguarantee make-instance ((class contracted-class) &key &allow-other-keys) (passes-invariants-p (results)))\n\nWrite a macro that addresses: Macro call that should be transformed by defguarantee", "input": "(defguarantee make-instance ((class contracted-class) &key &allow-other-keys) (passes-invariants-p (results)))", "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": "(progn (ensure-contracted-function (quote make-instance) (quote (class &key &allow-other-keys))) (defmethod make-instance :guarantee #A((31) base-char . \"(PASSES-INVARIANTS-P (RESULTS))\") ((class contracted-class) &key &allow-other-keys) (declare (ignorable class)) (passes-invariants-p (results))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(as->* nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by AS->*", "input": "(as->* nil\n :key\n nil)", "output": "(defmacro AS->* ...)", "macroexpand": "(let* ((nil nil) (nil :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(defmacro+ps nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by DEFMACRO+PS", "input": "(defmacro+ps nil\n :key\n nil)", "output": "(defmacro DEFMACRO+PS ...)", "macroexpand": "(progn\n (defmacro nil :key nil)\n (defpsmacro 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(undefreply 'some-name)\n\nPattern to recognize: Macro call that should be transformed by UNDEFREPLY", "input": "(undefreply 'some-name)", "output": "(defmacro UNDEFREPLY ...)", "macroexpand": "(undefine-reply ''some-name :qualifiers 'nil :participants `nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (= 0 (add-2 0)))\n\nIssue: Macro call that should be transformed by is", "input": "(is (= 0 (add-2 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 ((#:e146 0) (#:a147 (add-2 0))) (if (progn (= #:e146 #:a147)) (add-result (quote test-passed) :test-expr (quote (= 0 (add-2 0)))) (process-failure (quote (= 0 (add-2 0))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (add-2 0)) #:a147 (quote =) #:e146)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(c?-with-stored (v :foo store 'nothing) (bwhen (val (value v)) val))\n\nIssue: Macro call that should be transformed by c?", "input": "(c?-with-stored (v :foo 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 :foo store (quote nothing)) (bwhen (val (value v)) val)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-destructured-lambda-form nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by WITH-DESTRUCTURED-LAMBDA-FORM", "input": "(with-destructured-lambda-form nil\n (progn))", "output": "(defmacro WITH-DESTRUCTURED-LAMBDA-FORM ...)", "macroexpand": "(destructuring-bind\n (#:function128 #:name129 #:qualifiers130 #:lambda-list131 #:docstring132\n #:declarations133 #:forms134)\n (split-lambda-form (progn))\n (declare\n (ignore #:function128 #:name129 #:qualifiers130 #:lambda-list131\n #:docstring132 #:declarations133 #:forms134)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(aif (+ 1 1) (+ 1 it) :never)\n\nIssue: Macro call that should be transformed by aif", "input": "(aif (+ 1 1) (+ 1 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 (+ 1 1) (+ 1 it) :never)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(cond-<>\n 'some-name)\n\nWhat needs to change: 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(setdocs (type restart \"Class container for restart information. See NAME See REPORT See RESTART See OBJECT See INTERACTIVE See TEST See INVOKE\") (function name \"Returns the restart's symbol. Use this for INVOKE-RESTART. See RESTART\") (function report \"Returns the report string describing the restart's effects. See RESTART\") (function restart \"Returns a symbol to the restart-function or a direct function-object. See RESTART\") (function object \"Returns the platform-internal restart object. See RESTART\") (function interactive \"Returns the interactive restart function. See RESTART\") (function test \"Returns the restart test function. See RESTART\") (function invoke \"Invoke the restart that the restart object references. See RESTART\"))\n\nIssue: Macro call that should be transformed by setdocs", "input": "(setdocs (type restart \"Class container for restart information. See NAME See REPORT See RESTART See OBJECT See INTERACTIVE See TEST See INVOKE\") (function name \"Returns the restart's symbol. Use this for INVOKE-RESTART. See RESTART\") (function report \"Returns the report string describing the restart's effects. See RESTART\") (function restart \"Returns a symbol to the restart-function or a direct function-object. See RESTART\") (function object \"Returns the platform-internal restart object. See RESTART\") (function interactive \"Returns the interactive restart function. See RESTART\") (function test \"Returns the restart test function. See RESTART\") (function invoke \"Invoke the restart that the restart object references. See RESTART\"))", "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 restart) (quote type)) \"Class container for restart information. See NAME See REPORT See RESTART See OBJECT See INTERACTIVE See TEST See INVOKE\") (setf (documentation (quote name) (quote function)) \"Returns the restart's symbol. Use this for INVOKE-RESTART. See RESTART\") (setf (documentation (quote report) (quote function)) \"Returns the report string describing the restart's effects. See RESTART\") (setf (documentation (quote restart) (quote function)) \"Returns a symbol to the restart-function or a direct function-object. See RESTART\") (setf (documentation (quote object) (quote function)) \"Returns the platform-internal restart object. See RESTART\") (setf (documentation (quote interactive) (quote function)) \"Returns the interactive restart function. See RESTART\") (setf (documentation (quote test) (quote function)) \"Returns the restart test function. See RESTART\") (setf (documentation (quote invoke) (quote function)) \"Invoke the restart that the restart object references. See RESTART\"))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(ps-doc)\n\nWrite a macro that addresses: Macro call that should be transformed by PS-DOC", "input": "(ps-doc)", "output": "(defmacro PS-DOC ...)", "macroexpand": "\"\"", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> +doctype+ +skip-space+)\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> +doctype+ +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 (#:*>-offset265) (multiple-value-bind (#:*>-res266 #:*>-next267) (funcall +doctype+ #:*>-offset265) (if (ok? #:*>-res266) (funcall +skip-space+ #:*>-next267) (fail #:*>-next267))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-error multi-func-stemcells () (func-name) \"Multiple functions found named ~a that match arguments.~%However varjo cannot decide which function to use because n of the arguments passed in are of stemcell type\" func-name)\n\nProblem: Macro call that should be transformed by define-error", "input": "(define-error multi-func-stemcells () (func-name) \"Multiple functions found named ~a that match arguments.~%However varjo cannot decide which function to use because n of the arguments passed in are of stemcell type\" 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 multi-func-stemcells (:error-type varjo-error :prefix \"Varjo\") (func-name) \"Multiple functions found named ~a that match arguments.~%However varjo cannot decide which function to use because n of the arguments passed in are of stemcell type\" 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(ps)\n\nWhat needs to change: Macro call that should be transformed by PS", "input": "(ps)", "output": "(defmacro PS ...)", "macroexpand": "\"\"", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-modf-expander cdr 1 (expr val new-val) (declare (ignore expr)) `(cons (car ,val) ,new-val))\n\nIssue: Macro call that should be transformed by define-modf-expander", "input": "(define-modf-expander cdr 1 (expr val new-val) (declare (ignore expr)) `(cons (car ,val) ,new-val))", "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 cdr) *modf-nth-arg*) 1 (gethash (quote cdr) *modf-expansions*) (lambda (expr val new-val) (declare (ignore expr)) (sb-int:quasiquote (cons (car #S(sb-impl::comma :expr val :kind 0)) #S(sb-impl::comma :expr new-val :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-compile-struct sxql/composer:select-query-state)\n\nWrite a macro that addresses: Macro call that should be transformed by define-compile-struct", "input": "(define-compile-struct sxql/composer:select-query-state)", "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 (select-query-state-compiled (:include select-query-state)) (sql nil :type string) (bind nil :type list)) (defmethod find-compile-function ((object select-query-state)) (function make-select-query-state-compiled)) (defmethod print-object ((object select-query-state-compiled) stream) (format stream \"#\" (select-query-state-compiled-sql object) (select-query-state-compiled-bind object))) (defmethod yield ((object select-query-state-compiled)) (values (select-query-state-compiled-sql object) (select-query-state-compiled-bind object))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(bind (((:accessors-read-only a c e) (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5))) (list e c a))\n\nPattern to recognize: Macro call that should be transformed by bind", "input": "(bind (((:accessors-read-only a c e) (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5))) (list e c 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-173| (make-instance (quote metabang-bind-class-2) :a 1 :b 2 :c 3 :d 4 :e 5)) (a (a #:|values-173|)) (c (c #:|values-173|)) (e (e #:|values-173|))) (declare (ignorable #:|values-173|)) (progn (list e c 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(with-standard-definer-options nil\n :key\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-STANDARD-DEFINER-OPTIONS", "input": "(with-standard-definer-options nil\n :key\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 ,:key\n ,nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(in-readtable pax:macro)\n\nIssue: Macro call that should be transformed by in-readtable", "input": "(in-readtable pax:macro)", "output": "(defmacro in-readtable (name)\n \"Set *READTABLE* to the readtable referred to by the symbol NAME and\n return the readtable. This may signal READTABLE-DOES-NOT-EXIST.\n\n - Everything IN-READTABLE does is also performed at [compile time][\n pax:clhs] if the call appears as a [top level form][ pax:clhs].\n\n - The effects of IN-READTABLE are file-local since both COMPILE-FILE\n and LOAD rebind *READTABLE*.\"\n (check-type name symbol)\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n ;; NB. The :LOAD-TOPLEVEL is needed for cases like (DEFVAR *FOO*\n ;; (GET-MACRO-CHARACTER #\\\"))\n (setf *readtable* (ensure-readtable ',name))\n (when (or (find-package :swank) (find-package :slynk))\n (%frob-swank-readtable-alist *package* *readtable*))\n *readtable*))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (setf *readtable* (ensure-readtable (quote mgl-pax:macro))) (when (or (find-package :swank) (find-package :slynk)) (%frob-swank-readtable-alist *package* *readtable*)) *readtable*)", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(make-name-transformer \"FOO-\" name \"-BAR\")\n\nPattern to recognize: Macro call that should be transformed by make-name-transformer", "input": "(make-name-transformer \"FOO-\" name \"-BAR\")", "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.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defstore example (&rest args &key (a 0) (b (the integer (init-b args))) (c 0)))\n\nWrite a macro that addresses: Macro call that should be transformed by defstore", "input": "(defstore example (&rest args &key (a 0) (b (the integer (init-b args))) (c 0)))", "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 (args a #:a?166) (declare (ignorable args a #:a?166)) (the integer (init-b args))) (ensure-store (quote example) (quote (&rest args &key (a 0 #:a?166) (b (the integer (a-init-function152 args a #:a?166)) #:b?167) (c 0 #:c?168))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-table-name table-name-b (yield-only-contents clause-b))\n\nIssue: Macro call that should be transformed by with-table-name", "input": "(with-table-name table-name-b (yield-only-contents 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-only-contents clause-b))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defjs reduce8(k vals) (let ((arr (make-array)) (index 0)) (dolist (c vals) (setf (aref arr index) c) (incf index 1)) (return (ps:create :retval (aref arr 5)))))\n\nProblem: Macro call that should be transformed by defjs", "input": "(defjs reduce8(k vals) (let ((arr (make-array)) (index 0)) (dolist (c vals) (setf (aref arr index) c) (incf index 1)) (return (ps:create :retval (aref arr 5)))))", "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 ((arr (make-array)) (index 0)) (dolist (c vals) (setf (aref arr index) c) (incf index 1)) (return (parenscript:create :retval (aref arr 5)))))))) (setf (gethash (quote reduce8) *js-definitions*) js-body) (defun reduce8 (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": "Write a Common Lisp macro to handle this code pattern:\n(with-hamt set (:test test :hash hash :table table) (%hamt-lookup table x (funcall hash x) 0 test))\n\nProblem: Macro call that should be transformed by with-hamt", "input": "(with-hamt set (:test test :hash hash :table table) (%hamt-lookup table x (funcall hash x) 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)) set (%hamt-lookup table x (funcall hash x) 0 test))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(<*> (string \"hi\") (string \"bye\"))\n\nWrite a macro that addresses: Macro call that should be transformed by <*", "input": "(<*> (string \"hi\") (string \"bye\"))", "output": "(defmacro <* (parser &rest parsers)\n \"Combination of parsers yielding the result of the leftmost one.\"\n (let ((offset (gensym \"<*-OFFSET\")))\n `(lambda (,offset)\n ,(reduce (lambda (i p)\n (let ((res0 (gensym \"<*-RES\"))\n (next (gensym \"<*-NEXT\")))\n `(multiple-value-bind (,res0 ,next) ,i\n (if (ok? ,res0)\n (multiple-value-bind (res next) (funcall ,p ,next)\n (if (ok? res)\n (values ,res0 next)\n (fail next)))\n (fail ,next)))))\n parsers\n :initial-value `(funcall ,parser ,offset)))))", "macroexpand": "(lambda (#:<*>-offset268) (multiple-value-bind (#:<*>-res269 #:<*>-next270) (funcall (string \"hi\") #:<*>-offset268) (if (failure? #:<*>-res269) (fail #:<*>-next270) (fmap (lambda (xs) (cons #:<*>-res269 xs)) (multiple-value-bind (#:<*>-res271 #:<*>-next272) (funcall (string \"bye\") #:<*>-next270) (if (failure? #:<*>-res271) (fail #:<*>-next272) (fmap (lambda (xs) (cons #:<*>-res271 xs)) (ok #:<*>-next272 nil))))))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-yield (loop for line = (read-line file nil 'eof) until (eq line 'eof) do (yield line)) (close file))\n\nPattern to recognize: Macro call that should be transformed by with-yield", "input": "(with-yield (loop for line = (read-line file nil 'eof) until (eq line 'eof) do (yield line)) (close file))", "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 (#:g137 #:g138) (with-call/cc (labels ((yield (&rest values) (setf #:g138 values) (let/cc k (setf #:g137 k)))) (loop for line = (read-line file nil (quote eof)) until (eq line (quote eof)) do (yield line)) (close file) (setf #:g137 nil))) (gen-lambda nil (cond ((null #:g137) (quote generator-stop)) (t (let ((current #:g138)) (funcall #:g137 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(defclause (nconcing expr &optional into var at (place 'end)) \"Nconc into a list\" (return-collection-code :variable var :expression expr :start-operation 'nconc :place place :one-element nil))\n\nPattern to recognize: Macro call that should be transformed by defclause", "input": "(defclause (nconcing expr &optional into var at (place 'end)) \"Nconc into a list\" (return-collection-code :variable var :expression expr :start-operation 'nconc :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-nconcing-19 (&key ((:nconcing expr)) ((:into var)) ((:at place) (quote end))) \"Nconc into a list\" (return-collection-code :variable var :expression expr :start-operation (quote nconc) :place place :one-element nil)) (install-clause-info (quote (nconcing)) (quote (nconcing &optional :into :at)) (quote clause-nconcing-19) \"Nconc into a list\" nil) (quote (nconcing expr &optional into var at (place (quote end)))))", "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 check-lambda-list-internal (lambda-list &optional mode) (cond ((null lambda-list)) ((member (first lambda-list) *ordered-lambda-list-keywords* :test #'eq) (check-lambda-list-internal (rest lambda-list) (first lambda-list))) (t (let ((parameter (first lambda-list))) (ecase mode ((nil) (unless (symbolp parameter) (error \"Invalid parameter: ~S\" parameter))) (&optional (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2) (and (= (length parameter) 3) (symbolp (third parameter)))) (symbolp (first parameter)))) (error \"Invalid &OPTIONAL parameter: ~S\" parameter))) (&rest (unless (symbolp parameter) (error \"Invalid &REST parameter: ~S\" parameter))) (&key (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2) (and (= (length parameter) 3) (symbolp (third parameter)))) (or (symbolp (first parameter)) (and (consp (first parameter)) (null (rest (last (first parameter)))) (= (length (first parameter)) 2) (symbolp (first (first parameter))) (symbolp (second (first parameter))))))) (error \"Invalid &KEY parameter: ~S\" parameter))) (&aux (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2)) (symbolp (first parameter)))) (error \"Invalid &AUX parameter: ~S\" parameter))))) (check-lambda-list-internal (rest lambda-list) mode))))\n\nProblem: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time check-lambda-list-internal (lambda-list &optional mode) (cond ((null lambda-list)) ((member (first lambda-list) *ordered-lambda-list-keywords* :test #'eq) (check-lambda-list-internal (rest lambda-list) (first lambda-list))) (t (let ((parameter (first lambda-list))) (ecase mode ((nil) (unless (symbolp parameter) (error \"Invalid parameter: ~S\" parameter))) (&optional (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2) (and (= (length parameter) 3) (symbolp (third parameter)))) (symbolp (first parameter)))) (error \"Invalid &OPTIONAL parameter: ~S\" parameter))) (&rest (unless (symbolp parameter) (error \"Invalid &REST parameter: ~S\" parameter))) (&key (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2) (and (= (length parameter) 3) (symbolp (third parameter)))) (or (symbolp (first parameter)) (and (consp (first parameter)) (null (rest (last (first parameter)))) (= (length (first parameter)) 2) (symbolp (first (first parameter))) (symbolp (second (first parameter))))))) (error \"Invalid &KEY parameter: ~S\" parameter))) (&aux (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2)) (symbolp (first parameter)))) (error \"Invalid &AUX parameter: ~S\" parameter))))) (check-lambda-list-internal (rest lambda-list) 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 check-lambda-list-internal (lambda-list &optional mode) (cond ((null lambda-list)) ((member (first lambda-list) *ordered-lambda-list-keywords* :test (function eq)) (check-lambda-list-internal (rest lambda-list) (first lambda-list))) (t (let ((parameter (first lambda-list))) (ecase mode ((nil) (unless (symbolp parameter) (error \"Invalid parameter: ~S\" parameter))) (&optional (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2) (and (= (length parameter) 3) (symbolp (third parameter)))) (symbolp (first parameter)))) (error \"Invalid &OPTIONAL parameter: ~S\" parameter))) (&rest (unless (symbolp parameter) (error \"Invalid &REST parameter: ~S\" parameter))) (&key (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2) (and (= (length parameter) 3) (symbolp (third parameter)))) (or (symbolp (first parameter)) (and (consp (first parameter)) (null (rest (last (first parameter)))) (= (length (first parameter)) 2) (symbolp (first (first parameter))) (symbolp (second (first parameter))))))) (error \"Invalid &KEY parameter: ~S\" parameter))) (&aux (unless (or (symbolp parameter) (and (consp parameter) (null (rest (last parameter))) (or (= (length parameter) 1) (= (length parameter) 2)) (symbolp (first parameter)))) (error \"Invalid &AUX parameter: ~S\" parameter))))) (check-lambda-list-internal (rest lambda-list) mode)))) (eval-when (:compile-toplevel) (compile (quote check-lambda-list-internal))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-element-maker :mask \"mask\" '(:id))\n\nIssue: Macro call that should be transformed by define-element-maker", "input": "(define-element-maker :mask \"mask\" '(: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 :mask)) 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~^ ~}\" :mask missing))))) (defmethod make-svg-element ((element (eql :mask)) attributes) (when *check-required-attributes* (assert-required-attributes element attributes)) (make-instance (quote svg-element) :name \"mask\" :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(signal-syntax-error \"Unknown token ~A in parse tree.\" parse-tree)\n\nWhat needs to change: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Unknown token ~A in parse tree.\" 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 \"Unknown token ~A in parse tree.\" parse-tree)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Generate a defmacro form that transforms code like this:\n(cond-> nil)\n\nPattern to recognize: Macro call that should be transformed by COND->", "input": "(cond-> nil)", "output": "(defmacro COND-> ...)", "macroexpand": "(let* ((#:|cond130| nil))\n #:|cond130|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defgenerator takewhile (predicate generator) \"Emits items from generator until predicate fails. Eg: (takewhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 1 4\" (do-generator (item generator) (unless (funcall predicate item) (return)) (yield item)))\n\nPattern to recognize: Macro call that should be transformed by defgenerator", "input": "(defgenerator takewhile (predicate generator) \"Emits items from generator until predicate fails. Eg: (takewhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 1 4\" (do-generator (item generator) (unless (funcall predicate item) (return)) (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 takewhile (predicate generator) \"Emits items from generator until predicate fails. Eg: (takewhile (lambda (x) (< x 5)) (list->generator '(1 4 6 4 1))) -> 1 4\" (with-yield (do-generator (item generator) (unless (funcall predicate item) (return)) (yield item))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-unique-names (value repeat) `((,name (,value) (tagbody ,repeat (cond ((consp ,value) (rplacd ,tail (setq ,tail (cons (car ,value) nil))) (setq ,value (cdr ,value)) (go ,repeat)) (t (rplacd ,tail ,value)))))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-unique-names", "input": "(with-unique-names (value repeat) `((,name (,value) (tagbody ,repeat (cond ((consp ,value) (rplacd ,tail (setq ,tail (cons (car ,value) nil))) (setq ,value (cdr ,value)) (go ,repeat)) (t (rplacd ,tail ,value)))))))", "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\"))) (repeat (gensym #A((6) base-char . \"REPEAT\")))) (quasiquote ((#S(sb-impl::comma :expr name :kind 0) (#S(sb-impl::comma :expr value :kind 0)) (tagbody #S(sb-impl::comma :expr repeat :kind 0) (cond ((consp #S(sb-impl::comma :expr value :kind 0)) (rplacd #S(sb-impl::comma :expr tail :kind 0) (setq #S(sb-impl::comma :expr tail :kind 0) (cons (car #S(sb-impl::comma :expr value :kind 0)) nil))) (setq #S(sb-impl::comma :expr value :kind 0) (cdr #S(sb-impl::comma :expr value :kind 0))) (go #S(sb-impl::comma :expr repeat :kind 0))) (t (rplacd #S(sb-impl::comma :expr tail :kind 0) #S(sb-impl::comma :expr value :kind 0)))))))))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-hook (:build clear-asdf most-negative-fixnum) () (asdf:clear-configuration) (setf (fdefinition 'asdf:upgrade-asdf) (lambda ())) #+quicklisp (setf ql:*local-project-directories* ()) (dolist (system (asdf:already-loaded-systems)) (asdf:register-immutable-system system) (asdf:clear-system system)))\n\nIssue: Macro call that should be transformed by define-hook", "input": "(define-hook (:build clear-asdf most-negative-fixnum) () (asdf:clear-configuration) (setf (fdefinition 'asdf:upgrade-asdf) (lambda ())) #+quicklisp (setf ql:*local-project-directories* ()) (dolist (system (asdf:already-loaded-systems)) (asdf:register-immutable-system system) (asdf:clear-system system)))", "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 ((clear-asdf (or (hook :build (quote clear-asdf)) (make-instance (quote hook) :name (quote clear-asdf) :type :build)))) (setf (hook-priority clear-asdf) most-negative-fixnum) (setf (hook-function clear-asdf) (flet ((clear-asdf (&key &allow-other-keys) (uiop/configuration:clear-configuration) (setf (fdefinition (quote asdf/upgrade:upgrade-asdf)) (lambda nil)) (setf quicklisp-client:*local-project-directories* nil) (dolist (system (asdf/operate:already-loaded-systems)) (asdf/system-registry:register-immutable-system system) (asdf/system-registry:clear-system system)))) (function clear-asdf))) (setf (hook :build (quote clear-asdf)) clear-asdf) (setf (docstring clear-asdf) nil) (quote clear-asdf))", "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 nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by LAMBDA-CORO", "input": "(lambda-coro\n nil\n nil)", "output": "(defmacro LAMBDA-CORO ...)", "macroexpand": "(progn\n (defcoroutine #:name127\n (#:arg128)\n (macrolet ((yield (form)\n (let ((g!-it (gensym \"IT\")))\n `(progn\n (let ((,g!-it ,form))\n (cl-coroutine:yield ,g!-it))\n ,'#:arg128)))\n (last-yield-value ()\n '#:arg128))\n nil\n nil\n (coexit!)))\n (make-coroutine '#:name127))", "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 :key nil)\n\nWhat needs to change: Macro call that should be transformed by COLLECT-FILE", "input": "(collect-file nil :key nil)", "output": "(defmacro COLLECT-FILE ...)", "macroexpand": "(common-lisp:let* ((#:generator-560 (generator :key)) #:items-554 (#:out-556 t))\n (declare (type generator #:generator-560)\n (type boolean #:out-556))\n (with-open-file (#:outfile-553 nil :direction :output)\n (tagbody\n #:ll-561\n (setq #:items-554 (next-in #:generator-560 (go end)))\n (common-lisp:funcall nil #:items-554 #:outfile-553)\n (go #:ll-561)\n end))\n #:out-556)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(advisable-lambda nil)\n\nPattern to recognize: Macro call that should be transformed by ADVISABLE-LAMBDA", "input": "(advisable-lambda nil)", "output": "(defmacro ADVISABLE-LAMBDA ...)", "macroexpand": "(make-instance 'advisable-function :main #'(lambda ()) :arguments 'nil\n :dispatcher-generator\n #'(lambda (#:fobj122)\n #'(lambda ()\n #A((29) base-char . \"Advisable function dispatcher\")\n (let ((#:fixed123 (append)))\n (apply-before #:fobj122 #:fixed123)\n (multiple-value-prog1\n (apply-around #:fobj122 #:fixed123)\n (apply-after #:fobj122 #:fixed123))))))", "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 () (answer (foo 1) 2) (answer (foo 2) 3) (answer foo 42) (is (eql 2 (foo 1))) (is (eql 2 (foo 1))) (is (eql 3 (foo 2))) (is (eql 3 (foo 2))) (is (eql 42 (foo))) (is (eql 42 (foo 'foo))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (answer (foo 1) 2) (answer (foo 2) 3) (answer foo 42) (is (eql 2 (foo 1))) (is (eql 2 (foo 1))) (is (eql 3 (foo 2))) (is (eql 3 (foo 2))) (is (eql 42 (foo))) (is (eql 42 (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 1) 2) (answer (foo 2) 3) (answer foo 42) (is (eql 2 (foo 1))) (is (eql 2 (foo 1))) (is (eql 3 (foo 2))) (is (eql 3 (foo 2))) (is (eql 42 (foo))) (is (eql 42 (foo (quote foo))))) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(->\n nil\n nil)\n\nIssue: Macro call that should be transformed by ->", "input": "(->\n nil\n nil)", "output": "(defmacro -> ...)", "macroexpand": "(let* ((#:var148 nil) (#:var149 (nil #:var148)))\n #:var149)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(iter\n nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by ITER", "input": "(iter\n nil\n nil)", "output": "(defmacro ITER ...)", "macroexpand": "(let* ()\n (block nil\n (block nil\n (tagbody\n (progn)\n loop-top-nil\n (progn nil)\n (progn)\n (go loop-top-nil)\n (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(*> +many-comments+ +opt-fws+)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> +many-comments+ +opt-fws+)", "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 (#:*>-offset140) (multiple-value-bind (#:*>-res141 #:*>-next142) (funcall +many-comments+ #:*>-offset140) (if (ok? #:*>-res141) (funcall +opt-fws+ #:*>-next142) (fail #:*>-next142))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defvariant nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFVARIANT", "input": "(defvariant nil\n (progn))", "output": "(defmacro DEFVARIANT ...)", "macroexpand": "(progn\n (defstruct (nil (:constructor nil)))\n (defstruct (nil-progn (: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 `,'((progn)) match-cases expr-var)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(disable-dot-syntax)\n\nProblem: Macro call that should be transformed by DISABLE-DOT-SYNTAX", "input": "(disable-dot-syntax)", "output": "(defmacro disable-dot-syntax ()\n \"Restore readtable which was active before last call to If there was no such call, the standard\nreadtable is used.\"\n `(eval-when (:compile-toplevel :load-toplevel :execute)\n (%disable-dot-syntax)))", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute) (%disable-dot-syntax))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(aif (list 1 2 3) (sif (car it) (setf it 'a) :foo))\n\nWhat needs to change: Macro call that should be transformed by aif", "input": "(aif (list 1 2 3) (sif (car it) (setf it 'a) :foo))", "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 (list 1 2 3) (sif (car it) (setf it (quote a)) :foo) nil)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defrequirement add (&rest addends) \"all args < 10\" (every (lambda (n) (< n 10)) addends))\n\nIssue: Macro call that should be transformed by defrequirement", "input": "(defrequirement add (&rest addends) \"all args < 10\" (every (lambda (n) (< n 10)) addends))", "output": "(defmacro defrequirement (name (&rest lambda-list) &body body)\n \"Adds a precondition 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-precondition-checks-disabled\n (declare (ignore name lambda-list body))\n #+qpq-precondition-checks-disabled\n (values)\n #-qpq-precondition-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 :require\n ,(format nil \"~A\"\n (or doc-string\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 :require ,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 :require (&rest addends) (declare (ignorable addends)) \"all args < 10\" (every (lambda (n) (< n 10)) addends)) (progn (ensure-contracted-function (quote add) (quote (&rest addends))) (defmethod add :require #A((13) base-char . \"all args < 10\") (&rest addends) (declare (ignorable addends)) \"all args < 10\" (every (lambda (n) (< n 10)) addends))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-$instance nil nil)\n\nIssue: Macro call that should be transformed by MAKE-$INSTANCE", "input": "(make-$instance nil nil)", "output": "(defmacro MAKE-$INSTANCE ...)", "macroexpand": "(let ((class (symbol-value nil)))\n (funcall (mcs-slot-value class (index-of-basicnew-fn)) class nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-method-combination% nconc :operator nconc :identity-with-one-argument t)\n\nIssue: Macro call that should be transformed by define-method-combination%", "input": "(define-method-combination% nconc :operator nconc :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 nconc)) (method-combination-function-short nconc nconc t)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(select-dao class (where-and fields-and-values class) (sxql:limit 1))\n\nWrite a macro that addresses: Macro call that should be transformed by select-dao", "input": "(select-dao class (where-and fields-and-values class) (sxql:limit 1))", "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 ((#:class253 class)) (locally (declare (sb-ext:disable-package-locks where)) (progn (setf #:class253 (ensure-class #:class253)) (let* ((*sql-symbol-conversion* (function unlispify)) (#:sql248 (select :* (from (make-sql-symbol (table-name #:class253))))) (#:include-classes251 (quote nil))) (macrolet ((where (expression) (sb-int:quasiquote (make-clause :where #S(sb-impl::comma :expr (expand-op expression (quote #:class253)) :kind 0))))) (declare (sb-ext:muffle-conditions sb-ext:code-deletion-note)) (flet ((includes (&rest classes) (appendf #:include-classes251 (mapcar (function ensure-class) classes)) nil) (joins (foreign-class &key (type :inner)) (let ((foreign-class (ensure-class foreign-class))) (add-child #:sql248 (ecase type (:inner (inner-join (make-sql-symbol (table-name foreign-class)) :on (make-join-condition #:class253 foreign-class))) (:left (left-join (make-sql-symbol (table-name foreign-class)) :on (make-join-condition #:class253 foreign-class))))) nil))) (dolist (#:clause249 (list (where-and fields-and-values class) (limit 1))) (when #:clause249 (add-child #:sql248 #:clause249))) (let ((#:results250 (select-by-sql #:class253 #:sql248))) (unless *want-cursor* (dolist (#:foreign-class252 (remove-duplicates #:include-classes251)) (include-foreign-objects #:foreign-class252 #:results250))) (values #:results250 #:sql248))))))))", "category": "capture-management", "technique": "macrolet,once-only,gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.9624999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-rewrite caadar (expr) `(car (cadar ,(second expr))))\n\nPattern to recognize: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite caadar (expr) `(car (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 caadar) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cadar #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(is (not (< 0 1)))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (not (< 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 ((#:e198 0) (#:a199 1)) (if (progn (not (< #:e198 #:a199))) (add-result (quote test-passed) :test-expr (quote (not (< 0 1)))) (process-failure (quote (not (< 0 1))) \"~2&~S~2% evaluated to ~2&~S~2% which is ~2&~S~2%to ~2&~S~2% (it should not be)\" (quote 1) #:a199 (quote <) #:e198)))", "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-reader-syntax (string) (is (string-equal \"5.0d0\" (er \"(let ((a 5.0d0)) $a)\"))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-reader-syntax", "input": "(with-reader-syntax (string) (is (string-equal \"5.0d0\" (er \"(let ((a 5.0d0)) $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 string)))) (is (string-equal \"5.0d0\" (er \"(let ((a 5.0d0)) $a)\"))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(lret () 1)\n\nWrite a macro that addresses: 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": "Create a Common Lisp macro for the following transformation. Before code:\n(with-mocks () (answer (foo 1) 42) (answer foo 23) (is (eql 42 (foo 1))))\n\nWhat needs to change: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (answer (foo 1) 42) (answer foo 23) (is (eql 42 (foo 1))))", "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 1) 42) (answer foo 23) (is (eql 42 (foo 1)))) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(unwind-protect-case (aborted-p) (protected-form) (:always (perform-cleanup-if aborted-p)))\n\nWrite a macro that addresses: Macro call that should be transformed by unwind-protect-case", "input": "(unwind-protect-case (aborted-p) (protected-form) (:always (perform-cleanup-if aborted-p)))", "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+122 t)) (unwind-protect (multiple-value-prog1 (protected-form) (setf #:flag+122 nil)) (let ((aborted-p #:flag+122)) (progn (perform-cleanup-if aborted-p)))))", "category": "control-flow", "technique": "gensym,recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-neo4j-fun cypher-query (statements) :post (:uri-spec \"transaction/commit\") (:encode statements :statements) (:status-handlers (200 (decode-neo4j-json-output body)) (404 (error 'node-not-found-error :uri uri))))\n\nPattern to recognize: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun cypher-query (statements) :post (:uri-spec \"transaction/commit\") (:encode statements :statements) (: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 cypher-query (&key statements) (let ((uri \"transaction/commit\") (json (encode-neo4j-json-payload statements :statements))) (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": "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.6825} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defannotation notinline* (name) (:alias notinline :inline t) \"Shorthand for (DECLARE (NOTINLINE ...)).\" (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type '(defun defmethod))) `(progn (declaim (notinline ,symbol)) ,name) `(declare (notinline ,name)))))\n\nWrite a macro that addresses: Macro call that should be transformed by defannotation", "input": "(defannotation notinline* (name) (:alias notinline :inline t) \"Shorthand for (DECLARE (NOTINLINE ...)).\" (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type '(defun defmethod))) `(progn (declaim (notinline ,symbol)) ,name) `(declare (notinline ,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 notinline*) (quote (:alias notinline :inline t))) (defmacro notinline* (name) \"Shorthand for (DECLARE (NOTINLINE ...)).\" (let ((symbol (definition-form-symbol name)) (type (definition-form-type name))) (if (and symbol (member type (quote (defun defmethod)))) (sb-int:quasiquote (progn (declaim (notinline #S(sb-impl::comma :expr symbol :kind 0))) #S(sb-impl::comma :expr name :kind 0))) (sb-int:quasiquote (declare (notinline #S(sb-impl::comma :expr name :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(*> +consume-ws-crlf+ +skipws1+)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> +consume-ws-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 (#:*>-offset131) (multiple-value-bind (#:*>-res132 #:*>-next133) (funcall +consume-ws-crlf+ #:*>-offset131) (if (ok? #:*>-res132) (funcall +skipws1+ #:*>-next133) (fail #:*>-next133))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"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": "(special-symbol-progv (with-symbol-access\n (list))\n (list)\n (locally (declare (special)) nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some->\n nil\n nil)\n\nIssue: Macro call that should be transformed by SOME->", "input": "(some->\n nil\n nil)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:var169 nil)\n (#:var170\n (if #:var169\n (nil #:var169)\n nil)))\n #:var170)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(ematch0 or1 ((list* 'or1 or-subpatterns) (list* 'or1 (mapcar (lambda (or-sp) `(and ,or-sp ,@guard1-patterns)) or-subpatterns))))\n\nWhat needs to change: Macro call that should be transformed by ematch0", "input": "(ematch0 or1 ((list* 'or1 or-subpatterns) (list* 'or1 (mapcar (lambda (or-sp) `(and ,or-sp ,@guard1-patterns)) or-subpatterns))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 or1 ((list* (quote or1) or-subpatterns) (list* (quote or1) (mapcar (lambda (or-sp) (sb-int:quasiquote (and #S(sb-impl::comma :expr or-sp :kind 0) #S(sb-impl::comma :expr guard1-patterns :kind 2)))) or-subpatterns))) (_ (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(defclass/std computer (gadget) ((screen mouse keyboard :a :type string :with) (bluetooth touchpad :wi :std :unbound) (speaker microphone :r) (place :@@ :with-prefix :doc \"Where it is\" :r) (owner :static :std \"Me\" :w)))\n\nWrite a macro that addresses: Macro call that should be transformed by defclass/std", "input": "(defclass/std computer (gadget) ((screen mouse keyboard :a :type string :with) (bluetooth touchpad :wi :std :unbound) (speaker microphone :r) (place :@@ :with-prefix :doc \"Where it is\" :r) (owner :static :std \"Me\" :w)))", "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 computer (gadget) ((screen :accessor computer-screen :type string) (mouse :accessor computer-mouse :type string) (keyboard :accessor computer-keyboard :type string) (bluetooth :writer bluetooth :initarg :bluetooth) (touchpad :writer touchpad :initarg :touchpad) (speaker :reader speaker :initform nil) (microphone :reader microphone :initform nil) (place :reader computer-place :initform nil :allocation :class :documentation \"Where it is\") (owner :writer owner :initform \"Me\" :allocation :class)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.95} {"instruction": "Generate a defmacro form that transforms code like this:\n(defpattern nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by DEFPATTERN", "input": "(defpattern nil\n (progn))", "output": "(defmacro DEFPATTERN ...)", "macroexpand": "(eval-always\n (setf (get 'nil 'cl-match-pattern)\n (lambda (#:g133)\n (lett (progn)\n #:g133))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(fail 'happy)\n\nProblem: Macro call that should be transformed by fail", "input": "(fail 'happy)", "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 (quote happy) error)) :value-form (quote (capture-error (quote happy))) :body (lambda nil (capture-error (quote happy) error)) :expected (quote error) :comparison (quote typep)))", "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($map-reduce \"foo\" m r :out \"testit\" :query ($> \"l\" -900))\n\nWrite a macro that addresses: Macro call that should be transformed by $map-reduce", "input": "($map-reduce \"foo\" m r :out \"testit\" :query ($> \"l\" -900))", "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\" 0) (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(compile-time-report-wrap-failures)\n\nIssue: Macro call that should be transformed by compile-time-report-wrap-failures", "input": "(compile-time-report-wrap-failures)", "output": "(defmacro compile-time-report-wrap-failures ()\n (report-wrap-failures 'compile-time *error-output*))", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6975} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-declaration nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-DECLARATION", "input": "(define-declaration nil\n nil)", "output": "(defmacro DEFINE-DECLARATION ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (proclaim '(declaration nil))\n (flet ((sb-cltl2::func ()\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": "You are a Common Lisp macro expert. Given this code pattern:\n;; Anonymous recursion requires explicit labels every time\n(labels ((self (n)\n (if (> n 0)\n (cons n (self (- n 1)))\n nil)))\n #'self)\n\n;; labels boilerplate obscures the recursive logic\n\nWrite a macro that addresses: Need anonymous recursion without writing labels boilerplate \u2014 want implicit 'self' for recursion", "input": ";; Anonymous recursion requires explicit labels every time\n(labels ((self (n)\n (if (> n 0)\n (cons n (self (- n 1)))\n nil)))\n #'self)\n\n;; labels boilerplate obscures the recursive logic", "output": "(defmacro alambda (parms &body body)\n `(labels ((self ,parms ,@body))\n #'self))", "macroexpand": ";; (alambda (n)\n;; (if (> n 0)\n;; (cons n (self (- n 1)))\n;; nil))\n;; Expands to:\n;; (LABELS ((SELF (N)\n;; (IF (> N 0)\n;; (CONS N (SELF (- N 1)))\n;; NIL)))\n;; #'SELF)", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(setf nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by SETF", "input": "(setf nil nil)", "output": "(defmacro SETF ...)", "macroexpand": "(setq nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(-> :g (a) (+ a 3))\n\nPattern to recognize: Macro call that should be transformed by ->", "input": "(-> :g (a) (+ a 3))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (a) (+ a 3))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defclause maximizing (form &key (test ''>) saving in) \"Synonym for optimizing.\" `(optimizing ,form :test ,test :saving ,saving :in ,in))\n\nProblem: Macro call that should be transformed by defclause", "input": "(defclause maximizing (form &key (test ''>) saving in) \"Synonym for optimizing.\" `(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 maximizing (form &key (test (quote (quote >))) saving in) \"Synonym for optimizing.\" (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 maximizing) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(signal-syntax-error \"Unknown token ~A in parse-tree.\" token)\n\nIssue: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Unknown token ~A in parse-tree.\" 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 token ~A in parse-tree.\" token)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Generate a defmacro form that transforms code like this:\n(some-> nil nil)\n\nPattern to recognize: Macro call that should be transformed by SOME->", "input": "(some-> nil nil)", "output": "(defmacro SOME-> ...)", "macroexpand": "(let* ((#:g142 nil))\n (if (null #:g142)\n nil\n (-> #:g142 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(drelet nil\n :key\n nil)\n\nPattern to recognize: 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": "Define a macro that eliminates this repetitive pattern:\n(without-symbol-access\n nil)\n\nIssue: Macro call that should be transformed by WITHOUT-SYMBOL-ACCESS", "input": "(without-symbol-access\n nil)", "output": "(defmacro WITHOUT-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* nil))\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(cardinality-case 'some-name)\n\nIssue: Macro call that should be transformed by CARDINALITY-CASE", "input": "(cardinality-case 'some-name)", "output": "(defmacro CARDINALITY-CASE ...)", "macroexpand": "(let ((#:cardinality131 'some-name))\n (typecase #:cardinality131))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\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\nIssue: Macro call that should be transformed by do-generator-value-list", "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-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 ((#:g180 (apply (function multi-gen) (loop for g in gens collect (list g :fill-value fillspec))))) (loop do (if-generator (vars #:g180) (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(make-obsolete mustache-render render \"0.10.0\")\n\nProblem: Macro call that should be transformed by make-obsolete", "input": "(make-obsolete mustache-render 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 (&rest args) \"Render TEMPLATE with optional CONTEXT to *OUTPUT-STREAM* or OUTPUT-STREAM\" (warn (quote deprecation-warning) :name (quote mustache-render) :replacement (quote render) :since \"0.10.0\") (apply (quote render) args))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(assert-values (\"baz w/o lookup\") (baz 'no-lookup))\n\nIssue: Macro call that should be transformed by assert-values", "input": "(assert-values (\"baz w/o lookup\") (baz 'no-lookup))", "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 \"baz w/o lookup\") (assert (eql (value baz) (quote no-lookup))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(fail-compile (defun foo () (frob)) style-warning)\n\nIssue: Macro call that should be transformed by fail-compile", "input": "(fail-compile (defun foo () (frob)) style-warning)", "output": "(defmacro fail-compile (form &optional (type 'error) description &rest format-args)\n `(eval-in-context\n *context*\n (make-instance 'comparison-result\n :expression '(fail-expansion ,form)\n :value-form '(nth-value 3 (try-compile ',form ',type))\n :body (lambda () (nth-value 3 (try-compile ',form ',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-expansion (defun foo nil (frob)))) :value-form (quote (nth-value 3 (try-compile (quote (defun foo nil (frob))) (quote style-warning)))) :body (lambda nil (nth-value 3 (try-compile (quote (defun foo nil (frob))) (quote style-warning)))) :expected (quote style-warning) :comparison (quote typep)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defun/1 fwrite (mem element_size count fd) (handler-case (let ((start (memptr-ptr mem))) (write-sequence (memptr-mem mem) (fd-stream fd) :start start :end (+ start (* element_size count))) count) (error () (setf (ferror fd) EIO) 0)))\n\nWrite a macro that addresses: Macro call that should be transformed by defun/1", "input": "(defun/1 fwrite (mem element_size count fd) (handler-case (let ((start (memptr-ptr mem))) (write-sequence (memptr-mem mem) (fd-stream fd) :start start :end (+ start (* element_size count))) count) (error () (setf (ferror fd) EIO) 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 fwrite (mem element_size count fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (let ((start (memptr-ptr mem))) (write-sequence (memptr-mem mem) (fd-stream fd) :start start :end (+ start (* element_size count))) count) (error nil (setf (ferror fd) eio) 0))) (defparameter fwrite (vacietis.c:mkptr& (symbol-function (quote fwrite)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"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(define-alias-binding repeat repeating)\n\nWhat needs to change: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding repeat repeating)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote repeat)) (quote repeating)) (quote repeat))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-yield (iterate (for (x) in-generator (some-numbers)) (yield (1+ x))))\n\nIssue: Macro call that should be transformed by with-yield", "input": "(with-yield (iterate (for (x) in-generator (some-numbers)) (yield (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 (#:g151 #:g152) (with-call/cc (labels ((yield (&rest values) (setf #:g152 values) (let/cc k (setf #:g151 k)))) (iterate (for (x) in-generator (some-numbers)) (yield (1+ x))) (setf #:g151 nil))) (gen-lambda nil (cond ((null #:g151) (quote generator-stop)) (t (let ((current #:g152)) (funcall #:g151 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(pass)\n\nPattern to recognize: Macro call that should be transformed by pass", "input": "(pass)", "output": "(defmacro pass (&rest message-args)\n \"Simply generate a PASS.\"\n `(add-result 'test-passed\n :test-expr ',message-args\n ,@(when message-args\n `(:reason (format nil ,@message-args)))))", "macroexpand": "(add-result (quote test-passed) :test-expr (quote nil))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(auto-permute-typecase nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by AUTO-PERMUTE-TYPECASE", "input": "(auto-permute-typecase nil\n nil)", "output": "(defmacro AUTO-PERMUTE-TYPECASE ...)", "macroexpand": "(typecase nil ())", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> (take 3) (take 2))\n\nIssue: Macro call that should be transformed by *>", "input": "(*> (take 3) (take 2))", "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 (#:*>-offset209) (multiple-value-bind (#:*>-res210 #:*>-next211) (funcall (take 3) #:*>-offset209) (if (ok? #:*>-res210) (funcall (take 2) #:*>-next211) (fail #:*>-next211))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(atypecase 1.0 (integer (+ 2 it)) (float (1- it)))\n\nWrite a macro that addresses: Macro call that should be transformed by atypecase", "input": "(atypecase 1.0 (integer (+ 2 it)) (float (1- it)))", "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 1.0 (integer (+ 2 it)) (float (1- it)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-preprocessor-state-slots (state) (when if-section-skip-reason (return-from process-preprocessing-directive nil)) (multiple-value-bind (header-name header-type) (parse-header-name directive-token-list directive-symbol t macro-alist state) (let* ((pathname (ecase header-type (:q-char-sequence (find-include-header-file header-name)) (:h-char-sequence (find-include-
-file header-name)))) (included-tokens (tokenize-included-source-file pathname state))) (push-include-state state) (pop-next-newline token-list) (setf token-list (nconc included-tokens token-list)))))\n\nProblem: 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)) (multiple-value-bind (header-name header-type) (parse-header-name directive-token-list directive-symbol t macro-alist state) (let* ((pathname (ecase header-type (:q-char-sequence (find-include-header-file header-name)) (:h-char-sequence (find-include-
-file header-name)))) (included-tokens (tokenize-included-source-file pathname state))) (push-include-state state) (pop-next-newline token-list) (setf token-list (nconc included-tokens token-list)))))", "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)) (multiple-value-bind (header-name header-type) (parse-header-name directive-token-list directive-symbol t macro-alist state) (let* ((pathname (ecase header-type (:q-char-sequence (find-include-header-file header-name)) (:h-char-sequence (find-include-
-file header-name)))) (included-tokens (tokenize-included-source-file pathname state))) (push-include-state state) (pop-next-newline token-list) (setf token-list (nconc included-tokens token-list)))))", "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-postgres (dbi-driver) ())\n\nWhat needs to change: Macro call that should be transformed by defclass/a", "input": "(defclass/a dbd-postgres (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-postgres (dbi-driver) nil) (deftype nil (quote dbd-postgres)) (setf (find-class (quote )) (find-class (quote dbd-postgres))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-access nil\n :key\n nil)\n\nProblem: Macro call that should be transformed by WITH-ACCESS", "input": "(with-access nil\n :key\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 ((#:|val243| :key))\n (declare (ignorable #:|val243|))\n (symbol-macrolet ()\n nil))", "category": "dispatch", "technique": "symbol-macrolet,gensym", "complexity": "intermediate", "quality_score": 0.895} {"instruction": "Define a macro that eliminates this repetitive pattern:\n;; Building a closure with mutable behavior requires manual forwarding\n(let ((counter 0)\n (impl (lambda (n) (incf counter n))))\n (lambda (&rest args)\n (apply impl args)))\n\n;; To change behavior: build an entirely new closure\n\nIssue: Need mutable closure behavior changeable at runtime, with implicit 'this' pointing to current implementation", "input": ";; Building a closure with mutable behavior requires manual forwarding\n(let ((counter 0)\n (impl (lambda (n) (incf counter n))))\n (lambda (&rest args)\n (apply impl args)))\n\n;; To change behavior: build an entirely new closure", "output": "(defmacro alet (letargs &rest body)\n `(let ((this) ,@letargs)\n (setq this ,@(last body))\n ,@(butlast body)\n (lambda (&rest params)\n (apply this params))))", "macroexpand": ";; (alet ((acc 0))\n;; (format t \"Initialized~%\")\n;; (lambda (n) (incf acc n)))\n;;\n;; Returns a forwarding closure where 'this' can be swapped.\n;; The lambda inside can (setq this #'new-fn) to hotpatch.", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.95} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(dreletf* nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DRELETF*", "input": "(dreletf* nil)", "output": "(defmacro DRELETF* ...)", "macroexpand": "(progn)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(class-stealth-mixins 'some-name)\n\nIssue: Macro call that should be transformed by CLASS-STEALTH-MIXINS", "input": "(class-stealth-mixins 'some-name)", "output": "(defmacro CLASS-STEALTH-MIXINS ...)", "macroexpand": "(gethash 'some-name *stealth-mixins*)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-prepared-query query (conn \"SELECT last_insert_rowid() 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_rowid() 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_rowid() 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": "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 $", "input": "($map-reduce \"foo\" m r :query ($> \"l\" -9))", "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 nil nil (concatenate (quote string) \"mr.\" \"foo\"))) (kv \"verbose\" t) (kv \"limit\" 0) (kv \"keeptemp\" nil) (kv \"query\" ($> \"l\" -9))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(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\nPattern to recognize: Macro call that should be transformed by with-effective-qualifier", "input": "(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 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))) (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": "", "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* ((#:var120 nil) (#:var121 (nil #:var120)))\n #:var121)", "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 second (expr) `(cadr ,(second expr)))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite second (expr) `(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 second) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cadr #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(make-obsolete mustache-type version \"0.10.0\")\n\nPattern to recognize: Macro call that should be transformed by make-obsolete", "input": "(make-obsolete mustache-type 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-type (&rest args) #A((31) base-char . \"Return the CL-MUSTACHE version.\") (warn (quote deprecation-warning) :name (quote mustache-type) :replacement (quote version) :since \"0.10.0\") (apply (quote version) args))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-error flow-id-must-be-specified-co (:error-type varjo-critical-error) () \"code objects must be given a flow id when created\")\n\nPattern to recognize: Macro call that should be transformed by define-error", "input": "(define-error flow-id-must-be-specified-co (:error-type varjo-critical-error) () \"code objects 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-co (:error-type varjo-critical-error :prefix \"Varjo\") nil \"code objects must be given a flow id when created\")", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(infix)\n\nWrite a macro that addresses: Macro call that should be transformed by INFIX", "input": "(infix)", "output": "(defmacro INFIX ...)", "macroexpand": "nil", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-additional-indent (reporter stream \"\u2713 \") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (with-color (:gray :stream stream) (format/indent reporter stream description))) (when duration (format stream \" \") (print-duration stream duration (slot-value report 'slow-threshold)))) (terpri stream))\n\nPattern to recognize: Macro call that should be transformed by with-additional-indent", "input": "(with-additional-indent (reporter stream \"\u2713 \") (let ((description (possible-report-description report)) (duration (slot-value report 'duration))) (when description (with-color (:gray :stream stream) (format/indent reporter stream description))) (when duration (format stream \" \") (print-duration stream duration (slot-value report 'slow-threshold)))) (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* (+ *additional-indent* 2))) (declare (ignorable first-line-indent)) (write-string \"\u2713 \" stream) (let ((description (possible-report-description report)) (duration (slot-value report (quote duration)))) (when description (with-color (:gray :stream stream) (format/indent reporter stream description))) (when duration (format stream \" \") (print-duration stream duration (slot-value report (quote slow-threshold))))) (terpri stream)))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-cached-reader-conditionals\n nil)\n\nWhat needs to change: Macro call that should be transformed by WITH-CACHED-READER-CONDITIONALS", "input": "(with-cached-reader-conditionals\n nil)", "output": "(defmacro WITH-CACHED-READER-CONDITIONALS ...)", "macroexpand": "(call-with-cached-reader-conditionals (lambda () nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-prepared-query query (conn (format nil \"SELECT pg_get_serial_sequence('~A', '~A')\" table-name column)) (let ((seq (first (dbi:fetch (dbi:execute query) :format :values)))) (if (eq seq :null) nil seq)))\n\nPattern to recognize: Macro call that should be transformed by with-prepared-query", "input": "(with-prepared-query query (conn (format nil \"SELECT pg_get_serial_sequence('~A', '~A')\" table-name column)) (let ((seq (first (dbi:fetch (dbi:execute query) :format :values)))) (if (eq seq :null) nil seq)))", "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 pg_get_serial_sequence('~A', '~A')\" table-name column) (lambda (query) (let ((seq (first (dbi.driver:fetch (dbi.driver:execute query) :format :values)))) (if (eq seq :null) nil seq))) :use-prepare-cached nil)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(fail-compile (defun foo () (frob)) style-warning)\n\nWhat needs to change: Macro call that should be transformed by fail", "input": "(fail-compile (defun foo () (frob)) style-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-expansion (defun foo nil (frob)))) :value-form (quote (nth-value 3 (try-compile (quote (defun foo nil (frob))) (quote style-warning)))) :body (lambda nil (nth-value 3 (try-compile (quote (defun foo nil (frob))) (quote style-warning)))) :expected (quote style-warning) :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(defsynonym :minimize :min)\n\nProblem: Macro call that should be transformed by defsynonym", "input": "(defsynonym :minimize :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 :minimize) (quote synonym)) (quote :min)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-binary-op-mapping-definer define-binary-ops `(progn (declaim (inline ,op)) (defun ,op (x y) (,cl x y))))\n\nProblem: Macro call that should be transformed by define-binary-op-mapping-definer", "input": "(define-binary-op-mapping-definer define-binary-ops `(progn (declaim (inline ,op)) (defun ,op (x y) (,cl x y))))", "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-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(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))\n (let ((some-name))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(assoc-cdr :first-name uinfo)\n\nIssue: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr :first-name uinfo)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc :first-name 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(ps-once-only nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by PS-ONCE-ONLY", "input": "(ps-once-only nil\n nil)", "output": "(defmacro PS-ONCE-ONLY ...)", "macroexpand": "(let* ()\n `(let* ()\n ,(let* ()\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-bug invalid-special-function-arg-spec (:error-type varjo-critical-error) (name spec) \"The special function named ~s has an invalid argument spec: ~a Please report this bug on github\" name spec)\n\nWrite a macro that addresses: Macro call that should be transformed by define-bug", "input": "(define-bug invalid-special-function-arg-spec (:error-type varjo-critical-error) (name spec) \"The special function named ~s has an invalid argument spec: ~a Please report this bug on github\" name spec)", "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 invalid-special-function-arg-spec (:error-type varjo-critical-error :prefix \"Varjo Bug\") (name spec) \"The special function named ~s has an invalid argument spec: ~a Please report this bug on github\" name spec)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-decoder-simple-list-semantics (flet ((safe-symbols-parsing (name) (or (find-symbol name *json-symbols-package*) (error \"unknown symbols not allowed\")))) (let ((good-symbols \"{\\\"car\\\":1,\\\"cdr\\\":2}\") (bad-symbols \"{\\\"could-be\\\":1,\\\"a-denial-of-service-attack\\\":2}\") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* #'safe-symbols-parsing)) (is (equal '((car . 1) (cdr . 2)) (decode-json-from-string good-symbols))) (signals error (decode-json-from-string bad-symbols)))))\n\nPattern to recognize: Macro call that should be transformed by with-decoder-simple-list-semantics", "input": "(with-decoder-simple-list-semantics (flet ((safe-symbols-parsing (name) (or (find-symbol name *json-symbols-package*) (error \"unknown symbols not allowed\")))) (let ((good-symbols \"{\\\"car\\\":1,\\\"cdr\\\":2}\") (bad-symbols \"{\\\"could-be\\\":1,\\\"a-denial-of-service-attack\\\":2}\") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* #'safe-symbols-parsing)) (is (equal '((car . 1) (cdr . 2)) (decode-json-from-string good-symbols))) (signals error (decode-json-from-string bad-symbols)))))", "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) (flet ((safe-symbols-parsing (name) (or (find-symbol name *json-symbols-package*) (error \"unknown symbols not allowed\")))) (let ((good-symbols \"{\\\"car\\\":1,\\\"cdr\\\":2}\") (bad-symbols \"{\\\"could-be\\\":1,\\\"a-denial-of-service-attack\\\":2}\") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* (function safe-symbols-parsing))) (is (equal (quote ((car . 1) (cdr . 2))) (decode-json-from-string good-symbols))) (signals error (decode-json-from-string bad-symbols)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-simple-documentation-lookup type cl:type)\n\nIssue: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup type cl:type)", "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 ((type type)) (common-lisp:documentation (designator type) (quote common-lisp:type)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-accumulation-binding reducing ((var *unbound*) form &key (by NIL by-p)) (unless by-p (error \":BY argument required for REDUCING binding.\")) `(cond ((eq ,var *unbound*) (setf ,var ,form)) (T (setf ,var (funcall ,by ,var ,form)))))\n\nWrite a macro that addresses: Macro call that should be transformed by define-accumulation-binding", "input": "(define-accumulation-binding reducing ((var *unbound*) form &key (by NIL by-p)) (unless by-p (error \":BY argument required for REDUCING binding.\")) `(cond ((eq ,var *unbound*) (setf ,var ,form)) (T (setf ,var (funcall ,by ,var ,form)))))", "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 reducing ((var *unbound*) form &key (by nil by-p)) (values (progn (unless by-p (error \":BY argument required for REDUCING binding.\")) (sb-int:quasiquote (cond ((eq #S(sb-impl::comma :expr var :kind 0) *unbound*) (setf #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr form :kind 0))) (t (setf #S(sb-impl::comma :expr var :kind 0) (funcall #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr var :kind 0) #S(sb-impl::comma :expr form :kind 0))))))) (delist var)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-html (:table (dotimes (i 1000) (:tr (dotimes (i 10) (:td (1+ i)))))))\n\nPattern to recognize: Macro call that should be transformed by with-html", "input": "(with-html (:table (dotimes (i 1000) (:tr (dotimes (i 10) (:td (1+ i)))))))", "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 (with-tag (:table) (dotimes (i 1000) (with-tag (:tr) (dotimes (i 10) (with-tag (:td) (1+ i))))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-case-aware-token-p-function pp-stdc-pragma-p find-pragma-name with-c-syntax.pragma-name:|STDC|)\n\nPattern to recognize: Macro call that should be transformed by define-case-aware-token-p-function", "input": "(define-case-aware-token-p-function pp-stdc-pragma-p find-pragma-name with-c-syntax.pragma-name:|STDC|)", "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-stdc-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:stdc))))", "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 could-not-find-function (:error-type varjo-critical-error) (name) \"No function called '~s' was found in this environment\" name)\n\nWrite a macro that addresses: Macro call that should be transformed by define-error", "input": "(define-error could-not-find-function (:error-type varjo-critical-error) (name) \"No function called '~s' was 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-function (:error-type varjo-critical-error :prefix \"Varjo\") (name) \"No function called '~s' was found in this environment\" name)", "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": "Write a Common Lisp macro to handle this code pattern:\n(with-standard-readtable\n nil\n nil)\n\nProblem: Macro call that should be transformed by WITH-STANDARD-READTABLE", "input": "(with-standard-readtable\n nil\n nil)", "output": "(defmacro WITH-STANDARD-READTABLE ...)", "macroexpand": "(bind ((*readtable* (with-standard-io-syntax (copy-readtable *readtable*))))\n nil\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(action (:after node-application node) (multiple-value-bind (new-node new-changed?) (maybe-sink-application-into-rator node) (when new-changed? (setf changed? t) new-node)))\n\nIssue: Macro call that should be transformed by action", "input": "(action (:after node-application node) (multiple-value-bind (new-node new-changed?) (maybe-sink-application-into-rator 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-application) (lambda (node) (declare (type node-application node)) (multiple-value-bind (new-node new-changed?) (maybe-sink-application-into-rator node) (when new-changed? (setf changed? t) new-node))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n($op* op l)\n\nWhat needs to change: Macro call that should be transformed by $", "input": "($op* op l)", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(multiple-value-bind (#:g329 #:g332) (op-split (unwrap (list ($exp+ l)))) (let ((#:g331 (kv (car #:g329) (kv op #:g332)))) (dolist (#:g330 (cdr #:g329)) (setf #:g331 (kv #:g331 (kv #:g330 (kv op #:g332))))) #:g331))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(ensure-getf options :ignorable ignorable)\n\nPattern to recognize: Macro call that should be transformed by ensure-getf", "input": "(ensure-getf options :ignorable ignorable)", "output": "(defmacro ensure-getf (place key &optional default)\n (once-only (key default)\n `(setf (getf ,place ,key) (getf ,place ,key ,default))))", "macroexpand": "(let ((#:key173 :ignorable) (#:default174 ignorable)) (setf (getf options #:key173) (getf options #:key173 #:default174)))", "category": "control-flow", "technique": "once-only", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(action (:after node-direct-application) #'apply-specialization)\n\nPattern to recognize: Macro call that should be transformed by action", "input": "(action (:after node-direct-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-direct-application) (function apply-specialization))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(rem-bops nil)\n\nWrite a macro that addresses: Macro call that should be transformed by REM-BOPS", "input": "(rem-bops nil)", "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": "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": "(block #:match123)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(sctypecase (car x) (string (setf it :ok)))\n\nProblem: Macro call that should be transformed by sctypecase", "input": "(sctypecase (car x) (string (setf it :ok)))", "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) (string (setf it :ok)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-env [ht-equalp (copy-list '(4 5 6))])\n\nProblem: Macro call that should be transformed by with-env", "input": "(with-env [ht-equalp (copy-list '(4 5 6))])", "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 (#:g126) (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 #:g126 (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)) [ht-equalp (copy-list (quote (4 5 6))) ])) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g126)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defmessage nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFMESSAGE", "input": "(defmessage nil nil)", "output": "(defmacro DEFMESSAGE ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel) (proclaim `(ftype function ,'nil)))\n (aprog1 (ensure-message 'nil :lambda-list 'nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(some->> nil :key nil)\n\nIssue: Macro call that should be transformed by SOME->>", "input": "(some->> nil :key nil)", "output": "(defmacro SOME->> ...)", "macroexpand": "(let* ((#:g128 nil)\n (#:g128\n (if (null #:g128)\n nil\n (->> #:g128 :key))))\n (if (null #:g128)\n nil\n (->> #:g128 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/1 fflush (fd) (unless (eql fd NULL) (finish-output (fd-stream fd))) 0)\n\nWrite a macro that addresses: Macro call that should be transformed by defun/1", "input": "(defun/1 fflush (fd) (unless (eql fd NULL) (finish-output (fd-stream 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 fflush (fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (unless (eql fd null) (finish-output (fd-stream fd))) 0) (defparameter fflush (vacietis.c:mkptr& (symbol-function (quote fflush)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(def-slot-annotation required () (when (plist-member slot-options :initform) (error \"Required slot ~A must not have :initform\" slot-name)) (unless (plist-member slot-options :initarg) (setf (getf slot-options :initarg) (make-keyword slot-name))) (setf (getf slot-options :initform) `(required-argument ,(getf slot-options :initarg))))\n\nWrite a macro that addresses: Macro call that should be transformed by def-slot-annotation", "input": "(def-slot-annotation required () (when (plist-member slot-options :initform) (error \"Required slot ~A must not have :initform\" slot-name)) (unless (plist-member slot-options :initarg) (setf (getf slot-options :initarg) (make-keyword slot-name))) (setf (getf slot-options :initform) `(required-argument ,(getf slot-options :initarg))))", "output": "(defmacro def-slot-annotation (name args &body body)\n (with-gensyms (slot-specifier)\n `(defannotation ,name ,(append args (list slot-specifier))\n (:inline t :arity ,(1+ (length args)))\n (destructuring-bind (slot-name . slot-options)\n (if (consp ,slot-specifier)\n ,slot-specifier\n (list ,slot-specifier))\n ,@body\n (cons slot-name slot-options)))))", "macroexpand": "(defannotation required (#:slot-specifier123) (:inline t :arity 1) (destructuring-bind (slot-name . slot-options) (if (consp #:slot-specifier123) #:slot-specifier123 (list #:slot-specifier123)) (when (plist-member slot-options :initform) (error \"Required slot ~A must not have :initform\" slot-name)) (unless (plist-member slot-options :initarg) (setf (getf slot-options :initarg) (make-keyword slot-name))) (setf (getf slot-options :initform) (sb-int:quasiquote (required-argument #S(sb-impl::comma :expr (getf slot-options :initarg) :kind 0)))) (cons slot-name slot-options)))", "category": "capture-management", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"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": "(defun nil (progn) (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(define-language nil nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFINE-LANGUAGE", "input": "(define-language nil nil)", "output": "(defmacro DEFINE-LANGUAGE ...)", "macroexpand": "(progn\n (eval-when (:compile-toplevel :load-toplevel :execute)\n (defclass nil (nil) nil))\n (define-language-macro 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 nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by -<>", "input": "(-<>\n nil\n (progn))", "output": "(defmacro -<> ...)", "macroexpand": "(let* ((#:var206 nil) (#:var207 (progn #:var206)))\n #:var207)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(fmap (lambda (chars) (destructuring-bind (a b c d) chars (code-char (+ (* 4096 (digit-char-p a 16)) (* 256 (digit-char-p b 16)) (* 16 (digit-char-p c 16)) (digit-char-p d 16))))) (funcall (*> (char #\\\\) (alt (char #\\u) (char #\\U)) (count 4 #'hex)) offset))\n\nIssue: Macro call that should be transformed by fmap", "input": "(fmap (lambda (chars) (destructuring-bind (a b c d) chars (code-char (+ (* 4096 (digit-char-p a 16)) (* 256 (digit-char-p b 16)) (* 16 (digit-char-p c 16)) (digit-char-p d 16))))) (funcall (*> (char #\\\\) (alt (char #\\u) (char #\\U)) (count 4 #'hex)) 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 (*> (char #\\REVERSE_SOLIDUS) (alt (char #\\LATIN_SMALL_LETTER_U) (char #\\LATIN_CAPITAL_LETTER_U)) (count 4 (function hex))) offset) (if (failure? res) (fail next) (values (funcall (lambda (chars) (destructuring-bind (a b c d) chars (code-char (+ (* 4096 (digit-char-p a 16)) (* 256 (digit-char-p b 16)) (* 16 (digit-char-p c 16)) (digit-char-p d 16))))) 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-find-c-readtable-name-methods c-reader-level-1 1)\n\nProblem: Macro call that should be transformed by define-find-c-readtable-name-methods", "input": "(define-find-c-readtable-name-methods c-reader-level-1 1)", "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 1)) (readtable-case (eql nil))) (quote c-reader-level-1)) (defmethod find-c-readtable-name ((level (eql 1)) (readtable-case (eql :upcase))) (quote c-reader-level-1-upcase)) (defmethod find-c-readtable-name ((level (eql 1)) (readtable-case (eql :downcase))) (quote c-reader-level-1-downcase)) (defmethod find-c-readtable-name ((level (eql 1)) (readtable-case (eql :preserve))) (quote c-reader-level-1-preserve)) (defmethod find-c-readtable-name ((level (eql 1)) (readtable-case (eql :invert))) (quote c-reader-level-1-invert)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n;; Explicit continuation-passing is verbose\n(defun fact-cps (n cont)\n (if (zerop n)\n (funcall cont 1)\n (fact-cps (- n 1)\n (lambda (x) (funcall cont (* n x))))))\n\n;; Every function must take an explicit continuation parameter.\n;; Every call must thread the continuation through.\n;; Simple sequential code becomes deeply nested.\n\nIssue: Manual continuation-passing style requires explicit continuation parameters and nested lambdas \u2014 want syntactic sugar for CPS", "input": ";; Explicit continuation-passing is verbose\n(defun fact-cps (n cont)\n (if (zerop n)\n (funcall cont 1)\n (fact-cps (- n 1)\n (lambda (x) (funcall cont (* n x))))))\n\n;; Every function must take an explicit continuation parameter.\n;; Every call must thread the continuation through.\n;; Simple sequential code becomes deeply nested.", "output": "(defmacro =lambda (parms &body body)\n `#'(lambda (*cont* ,@parms) ,@body))\n\n(defmacro =defun (name parms &body body)\n (let ((f (intern (concatenate 'string\n \"=\" (symbol-name name)))))\n `(progn\n (defmacro ,name ,parms\n `(,',f *cont* ,,@parms))\n (defun ,f (*cont* ,@parms) ,@body))))\n\n(defmacro =bind (parms expr &body body)\n `(let ((*cont* #'(lambda ,parms ,@body))) ,expr))\n\n(defmacro =values (&rest retvals)\n `(funcall *cont* ,@retvals))", "macroexpand": ";; (=defun fact (n)\n;; (if (zerop n)\n;; (=values 1)\n;; (=bind (x) (fact (- n 1))\n;; (=values (* n x)))))\n;;\n;; =lambda: creates a CPS function (takes *cont* as first arg)\n;; =defun: defines a CPS function + a macro for clean call syntax\n;; =bind: captures *cont* as the rest of the computation\n;; =values: sends values to the current continuation\n;;\n;; The code looks sequential but compiles to CPS.\n;; =bind marks where a continuation is captured.", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.975} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-shell-component less :input-type \"less\" :output-type \"css\" :shell-command \"lessc\")\n\nIssue: Macro call that should be transformed by define-shell-component", "input": "(define-shell-component less :input-type \"less\" :output-type \"css\" :shell-command \"lessc\")", "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 less :input-type \"less\" :output-type \"css\" :compile-function (lambda (input-pathname output-pathname) (inferior-shell:run (list \"lessc\" 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(lret ((vect (prepare-int-range start stop step))) (fill-int-range! vect start stop step))\n\nProblem: Macro call that should be transformed by lret", "input": "(lret ((vect (prepare-int-range start stop step))) (fill-int-range! vect start stop 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 ((vect (prepare-int-range start stop step))) (fill-int-range! vect start stop step))", "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(is (every #'test-failure-p results))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (every #'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 ((#:e208 (function test-failure-p)) (#:a209 results)) (if (progn (every #:e208 #:a209)) (add-result (quote test-passed) :test-expr (quote (every (function test-failure-p) results))) (process-failure (quote (every (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) #:a209 (quote every) #:e208)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(-> :p (v) (setf result v) (mt:open-latch latch))\n\nWrite a macro that addresses: Macro call that should be transformed by ->", "input": "(-> :p (v) (setf result v) (mt:open-latch latch))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :p (v) (setf result v) (cl-muth:open-latch latch))", "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 (:raw \"Very very very very very very very very very very very very very very very very very very very very very very very very long line\"))\n\nProblem: Macro call that should be transformed by with-html", "input": "(with-html-string (:raw \"Very very very very very very very very very very very very very very very very very very very very very very very very long line\"))", "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 (:raw \"Very very very very very very very very very very very very very very very very very very very very very very very very long line\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(-> :g () (mt:open-latch latch))\n\nWhat needs to change: Macro call that should be transformed by ->", "input": "(-> :g () (mt:open-latch latch))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g nil (cl-muth:open-latch latch))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(*> +consume-space+ +close-brace+)\n\nWrite a macro that addresses: Macro call that should be transformed by *>", "input": "(*> +consume-space+ +close-brace+)", "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 (#:*>-offset181) (multiple-value-bind (#:*>-res182 #:*>-next183) (funcall +consume-space+ #:*>-offset181) (if (ok? #:*>-res182) (funcall +close-brace+ #:*>-next183) (fail #:*>-next183))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-hash nil nil)\n\nProblem: Macro call that should be transformed by COLLECT-HASH", "input": "(collect-hash nil nil)", "output": "(defmacro COLLECT-HASH ...)", "macroexpand": "(common-lisp:let* ((#:out-138 (make-hash-table)))\n (common-lisp:let ((#:generator-142 (generator nil))\n #:values-134\n (#:generator-140 (generator nil))\n #:keys-133)\n (declare (type generator #:generator-142)\n (type generator #:generator-140))\n (tagbody\n #:ll-143\n (setq #:values-134 (next-in #:generator-142 (go end)))\n (setq #:keys-133 (next-in #:generator-140 (go end)))\n (setf (gethash #:keys-133 #:out-138) #:values-134)\n (go #:ll-143)\n end)\n #:out-138))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(form &aux (result T))\n\nWhat needs to change: Macro call that should be transformed by for", "input": "(form &aux (result T))", "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 &aux (result t))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defsynonym maximize :max)\n\nWrite a macro that addresses: 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": "Define a macro that eliminates this repetitive pattern:\n(regex-apropos-aux (regex packages case-insensitive) (print-symbol-info symbol))\n\nIssue: Macro call that should be transformed by regex-apropos-aux", "input": "(regex-apropos-aux (regex packages case-insensitive) (print-symbol-info symbol))", "output": "(defmacro regex-apropos-aux ((regex packages case-insensitive &optional return-form)\n &body body)\n \"Auxiliary macro used by REGEX-APROPOS and REGEX-APROPOS-LIST.\nLoops through PACKAGES and executes BODY with SYMBOL bound to each\nsymbol which matches REGEX. Optionally evaluates and returns\nRETURN-FORM at the end. If CASE-INSENSITIVE is true and REGEX isn't\nalready a scanner, a case-insensitive scanner is used.\"\n (with-rebinding (regex)\n (with-unique-names (scanner %packages hash)\n `(let* ((,scanner (create-scanner ,regex\n :case-insensitive-mode\n (and ,case-insensitive\n (not (functionp ,regex)))))\n (,%packages (or ,packages\n (list-all-packages)))\n (,hash (make-hash-table :test #'eq)))\n (do-with-all-symbols (symbol ,%packages)\n (unless (gethash symbol ,hash)\n (when (scan ,scanner (symbol-name symbol))\n (setf (gethash symbol ,hash) t)\n ,@body)))\n ,return-form))))", "macroexpand": "(let ((#:regex149 regex)) (let* ((#:scanner150 (create-scanner #:regex149 :case-insensitive-mode (and case-insensitive (not (functionp #:regex149))))) (#:%packages151 (or packages (list-all-packages))) (#:hash154 (make-hash-table :test (function eq)))) (with-package-iterator (#:next152 #:%packages151 :external :internal :inherited) (loop (multiple-value-bind (#:morep153 symbol) (#:next152) (unless #:morep153 (return nil)) (unless (gethash symbol #:hash154) (when (scan #:scanner150 (symbol-name symbol)) (setf (gethash symbol #:hash154) t) (print-symbol-info symbol))))))))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(sum-of nil\n nil)\n\nWrite a macro that addresses: Macro call that should be transformed by SUM-OF", "input": "(sum-of nil\n nil)", "output": "(defmacro SUM-OF ...)", "macroexpand": "(lc (nil 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(is-print (princ \"ABCDEFGH\") \"ABCDEFGHIJKLMNO\")\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is-print (princ \"ABCDEFGH\") \"ABCDEFGHIJKLMNO\")", "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 ((#:expected175 \"ABCDEFGHIJKLMNO\") (#:desc176 nil)) (with-catching-errors (:description #:desc176 :expected #:expected175) (let* (#:duration173 (#:output172 (with-output-to-string (*standard-output*) (with-duration ((#:duration-inner174 #:output172) (princ \"ABCDEFGH\")) (declare (ignore #:output172)) (setq #:duration173 #:duration-inner174))))) (test #:output172 #:expected175 #:desc176 :duration #:duration173 :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": "Write a Common Lisp macro to handle this code pattern:\n(sunless x (setf it :oops))\n\nProblem: Macro call that should be transformed by sunless", "input": "(sunless x (setf it :oops))", "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 :oops))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defgeneric nil nil)\n\nProblem: Macro call that should be transformed by DEFGENERIC", "input": "(defgeneric nil nil)", "output": "(defmacro DEFGENERIC ...)", "macroexpand": "(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(define-shell-component sass :input-type \"scss\" :output-type \"css\" :shell-command \"sass\")\n\nPattern to recognize: Macro call that should be transformed by define-shell-component", "input": "(define-shell-component sass :input-type \"scss\" :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 :input-type \"scss\" :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": "Create a Common Lisp macro for the following transformation. Before code:\n(define-simple-error-for sffi-continuable-error)\n\nWhat needs to change: Macro call that should be transformed by define-simple-error-for", "input": "(define-simple-error-for sffi-continuable-error)", "output": "(defmacro define-simple-error-for (base-type &key name object-initarg)\n \"Define a simple error subclassing from BASE-TYPE and a corresponding\nfunction, analogous to ERROR, but also optionally taking the object \nagainst which to err, and passing it to ERROR via the OBJECT-INITARG\nkeyword. The name of the simple error is constructed by prepending\n'SIMPLE-' to BASE-TYPE.\nWhether or not the error signaller will require and pass the\nobject is specified by OBJECT-INITARG being non-NIL.\"\n `(define-simple-condition-for ,base-type :object-initarg ,object-initarg :simple-condition-type simple-error :signaler error\n ,@(when name `(:name ,name))))", "macroexpand": "(define-simple-condition-for sffi-continuable-error :object-initarg nil :simple-condition-type simple-error :signaler error)", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(quasiquote nil nil)\n\nIssue: Macro call that should be transformed by QUASIQUOTE", "input": "(quasiquote nil nil)", "output": "(defmacro QUASIQUOTE ...)", "macroexpand": "(let ((#:source122 nil))\n (%quote #:source122 'nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defjs at() (let ((arr (make-array))) (setf (aref arr 0) 10) (setf (aref arr 1) 20) (setf (aref arr 2) 30) (setf (aref arr 4) 40) (setf (aref arr 5) 80) (return (aref arr 2))))\n\nProblem: Macro call that should be transformed by defjs", "input": "(defjs at() (let ((arr (make-array))) (setf (aref arr 0) 10) (setf (aref arr 1) 20) (setf (aref arr 2) 30) (setf (aref arr 4) 40) (setf (aref arr 5) 80) (return (aref arr 2))))", "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 ((arr (make-array))) (setf (aref arr 0) 10) (setf (aref arr 1) 20) (setf (aref arr 2) 30) (setf (aref arr 4) 40) (setf (aref arr 5) 80) (return (aref arr 2))))))) (setf (gethash (quote at) *js-definitions*) js-body) (defun at 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(with-trace-sql (execute-with-retry query binds))\n\nPattern to recognize: Macro call that should be transformed by with-trace-sql", "input": "(with-trace-sql (execute-with-retry query binds))", "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*))) (execute-with-retry query binds))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(assoc-cdr :userinfo--endpoint disc)\n\nWhat needs to change: Macro call that should be transformed by assoc-cdr", "input": "(assoc-cdr :userinfo--endpoint disc)", "output": "(defmacro assoc-cdr (key alist &optional (test '#'eql))\n `(cdr (assoc ,key ,alist :test ,test)))", "macroexpand": "(cdr (assoc :userinfo--endpoint disc :test (function eql)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"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": "Create a Common Lisp macro for the following transformation. Before code:\n(ps-to-stream nil)\n\nWhat needs to change: Macro call that should be transformed by PS-TO-STREAM", "input": "(ps-to-stream nil)", "output": "(defmacro PS-TO-STREAM ...)", "macroexpand": "(let ((*parenscript-stream* nil))\n (write-string \"\" *parenscript-stream*))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(compiler-macro-lambda (a) `(1- ,a))\n\nPattern to recognize: Macro call that should be transformed by compiler-macro-lambda", "input": "(compiler-macro-lambda (a) `(1- ,a))", "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-lambda146) (#:expr #:env) (declare (sb-c::lambda-list (a))) (declare (ignore #:env)) (sb-int:named-ds-bind (:macro #:compiler-macro-lambda146 . define-compiler-macro) (a) (sb-c::compiler-macro-args #:expr) (declare (sb-c::constant-value a) (sb-c::no-compiler-macro #:compiler-macro-lambda146)) (block #:compiler-macro-lambda146 (sb-int:quasiquote (1- #S(sb-impl::comma :expr a :kind 0))))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(bind (((:labels doit (x)) (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 (((:labels doit (x)) (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) (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": "You are a Common Lisp macro expert. Given this code pattern:\n(defsynonym :thereis :there-is)\n\nWrite a macro that addresses: 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.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(ematch0 tests (nil more-patterns) ((list* test t-rest) `(,intersection (guard1 ,(first syms) ,test ,@(first more-patterns) ,@(wrap-test (rest syms) t-rest (rest more-patterns))))))\n\nPattern to recognize: Macro call that should be transformed by ematch0", "input": "(ematch0 tests (nil more-patterns) ((list* test t-rest) `(,intersection (guard1 ,(first syms) ,test ,@(first more-patterns) ,@(wrap-test (rest syms) t-rest (rest more-patterns))))))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 tests (nil more-patterns) ((list* test t-rest) (sb-int:quasiquote (#S(sb-impl::comma :expr intersection :kind 0) (guard1 #S(sb-impl::comma :expr (first syms) :kind 0) #S(sb-impl::comma :expr test :kind 0) #S(sb-impl::comma :expr (first more-patterns) :kind 2) #S(sb-impl::comma :expr (wrap-test (rest syms) t-rest (rest more-patterns)) :kind 2))))) (_ (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(define-simple-documentation-lookup method-combination cl:method-combination)\n\nWhat needs to change: Macro call that should be transformed by define-simple-documentation-lookup", "input": "(define-simple-documentation-lookup method-combination cl:method-combination)", "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 ((method-combination method-combination)) (common-lisp:documentation (designator method-combination) (quote common-lisp:method-combination)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(augment body-code (funcall body-during form body))\n\nProblem: Macro call that should be transformed by augment", "input": "(augment body-code (funcall body-during form body))", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf body-code (nconc body-code (funcall body-during form body)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defstore example (a b))\n\nWhat needs to change: Macro call that should be transformed by defstore", "input": "(defstore example (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 example) (quote (a b)))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(enable-reader-syntax nil :key nil)\n\nProblem: Macro call that should be transformed by ENABLE-READER-SYNTAX", "input": "(enable-reader-syntax nil :key 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 :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(->> 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": "You are a Common Lisp macro expert. Given this code pattern:\n(defproto nil :key nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFPROTO", "input": "(defproto nil :key 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 :key)\n :properties (list) :nickname 'nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(symbol-value-in-$instance nil (progn))\n\nPattern to recognize: Macro call that should be transformed by SYMBOL-VALUE-IN-$INSTANCE", "input": "(symbol-value-in-$instance nil (progn))", "output": "(defmacro SYMBOL-VALUE-IN-$INSTANCE ...)", "macroexpand": "(slot-value 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(match ARG (PATTERN) (otherwise BODY...))\n\nWhat needs to change: Macro call that should be transformed by match", "input": "(match ARG (PATTERN) (otherwise 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.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(specializing nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by SPECIALIZING", "input": "(specializing nil\n nil)", "output": "(defmacro SPECIALIZING ...)", "macroexpand": "(let ((#:table147 (load-time-value (table 66))))\n (declare (optimize (speed 3) (debug 0) (safety 0)))\n (progn (funcall (the (function nil *) #:table147))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(peek b)\n\nWhat needs to change: Macro call that should be transformed by peek", "input": "(peek b)", "output": "(defmacro peek (form)\n \"Read the value of cells without triggering a recomputation.\n\nFORM is evaluated in a context such that when the value of a cell is\nreferenced it is not registered as an argument cell of the cell in\nwhich the PEEK form is evaluated. This means that the value of the\ncell, in which the PEEK form is evaluated, will not be recomputed when\nthe values of the cells referenced in FORM change.\n\nIn the following example\n\n.. code-block::\n\n (defcell a 0)\n (defcell b 1)\n\n (defcell sum (+ a (peek b))\n\nthe SUM cell references the value of A directly and *peeks* the value\nof B (using PEEK). Changing the value of A will cause the value of the\nSUM cell to be recomputed. However, changing the value of B will not\ncause the value of SUM to be computed.\n\n.. important::\n\n This macro has no effect if CELL is referenced outside a PEEK form\n within the same cell definition.\n\n .. code-block::\n\n (defcell sum (+ b (peek b))\n\n In this example, PEEK has no effect because the SUM cell references\n B outside a PEEK form.\n\n\"\n\n (with-gensyms (arg-cell\n did-change\n observer-arg\n tracker\n update\n will-update)\n\n (let* ((key ``(peek ,(argument-key ,arg-cell)))\n (observer-record\n `(make-observer\n :key ,key\n :will-update #',will-update\n :update #',update)))\n\n `(flet ((,update (,arg-cell ,did-change)\n (declare (ignore ,arg-cell ,did-change)))\n (,will-update (,arg-cell)\n (declare (ignore ,arg-cell))))\n\n (let ((,tracker *track-cell-callback*))\n (with-tracker\n ((,arg-cell)\n (let ((*track-cell-callback* ,tracker))\n (track-argument\n (make-argument\n :key ,key\n :add-observer (lambda (,observer-arg)\n (declare (ignore ,observer-arg))\n (call-add-observer ,arg-cell ,observer-record))\n :remove-observer (lambda (,observer-arg)\n (declare (ignore ,observer-arg))\n (call-remove-observer ,arg-cell ,observer-record))))))\n\n ,form))))))", "macroexpand": "(flet ((#:update148 (#:arg-cell144 #:did-change145) (declare (ignore #:arg-cell144 #:did-change145))) (#:will-update149 (#:arg-cell144) (declare (ignore #:arg-cell144)))) (let ((#:tracker147 *track-cell-callback*)) (with-tracker ((#:arg-cell144) (let ((*track-cell-callback* #:tracker147)) (track-argument (make-argument :key (sb-int:quasiquote (peek #S(sb-impl::comma :expr (argument-key #:arg-cell144) :kind 0))) :add-observer (lambda (#:observer-arg146) (declare (ignore #:observer-arg146)) (call-add-observer #:arg-cell144 (make-observer :key (sb-int:quasiquote (peek #S(sb-impl::comma :expr (argument-key #:arg-cell144) :kind 0))) :will-update (function #:will-update149) :update (function #:update148)))) :remove-observer (lambda (#:observer-arg146) (declare (ignore #:observer-arg146)) (call-remove-observer #:arg-cell144 (make-observer :key (sb-int:quasiquote (peek #S(sb-impl::comma :expr (argument-key #:arg-cell144) :kind 0))) :will-update (function #:will-update149) :update (function #:update148)))))))) b)))", "category": "anaphoric", "technique": "gensym,nested-backquote,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.8474999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define FILENAME_MAX 1024)\n\nWrite a macro that addresses: Macro call that should be transformed by define", "input": "(define FILENAME_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 filename_max) *preprocessor-defines*) #A((4) base-char . \"1024\"))) (defparameter filename_max 1024))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause options (&rest args &key name atomic-updates) (declare (ignore name atomic-updates)) (make-options :map args))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause options (&rest args &key name atomic-updates) (declare (ignore name atomic-updates)) (make-options :map 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 options (&rest args &key name atomic-updates) (declare (ignore name atomic-updates)) (make-options :map args)) (pushnew (quote options) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-capped-stack () (etypecase destination ((eql T) (present thing *standard-output*)) ((eql NIL) (with-output-to-string (stream) (present thing stream))) (stream (present-object thing destination))))\n\nWrite a macro that addresses: Macro call that should be transformed by with-capped-stack", "input": "(with-capped-stack () (etypecase destination ((eql T) (present thing *standard-output*)) ((eql NIL) (with-output-to-string (stream) (present thing stream))) (stream (present-object thing destination))))", "output": "(defmacro with-capped-stack (() &body body)\n `(stack-capper (lambda () ,@body)))", "macroexpand": "(stack-capper (lambda nil (etypecase destination ((eql t) (present thing *standard-output*)) ((eql nil) (with-output-to-string (stream) (present thing stream))) (stream (present-object thing destination)))))", "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 nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFINE-LAYERED-CLASS", "input": "(define-layered-class nil\n (progn))", "output": "(defmacro DEFINE-LAYERED-CLASS ...)", "macroexpand": "(defclass nil (progn) nil (:metaclass layered-class) (:in-layer . t))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(gen-lambda-with-sticky-stop () (multiple-value-bind (res signal) (funcall source) (if signal res (sticky-stop))))\n\nIssue: Macro call that should be transformed by gen-lambda-with-sticky-stop", "input": "(gen-lambda-with-sticky-stop () (multiple-value-bind (res signal) (funcall source) (if signal 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 (multiple-value-bind (res signal) (funcall source) (if signal res (sticky-stop)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defjs reduce1(k vals) (return (aref vals 0)))\n\nWhat needs to change: Macro call that should be transformed by defjs", "input": "(defjs reduce1(k vals) (return (aref vals 0)))", "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 (aref vals 0)))))) (setf (gethash (quote reduce1) *js-definitions*) js-body) (defun reduce1 (k vals) (get-element \"retval\" (car (docs (db.eval js-body k vals))))))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(f0\n 'some-name)\n\nIssue: Macro call that should be transformed by F0", "input": "(f0\n 'some-name)", "output": "(defmacro F0 ...)", "macroexpand": "(lambda () 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(c? )\n\nProblem: Macro call that should be transformed by c?", "input": "(c? )", "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 nil) :value-state :unevaluated :rule (c-lambda))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-table-name nil (yield (as-op-right op)))\n\nPattern to recognize: Macro call that should be transformed by with-table-name", "input": "(with-table-name nil (yield (as-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 (as-op-right op)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(\u03c8 nil)\n\nPattern to recognize: Macro call that should be transformed by \u03a8", "input": "(\u03c8 nil)", "output": "(defmacro \u03a8 ...)", "macroexpand": "(mapcar (\u03bb) nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(with-html-string (:p :attrs attrs \"bar\"))\n\nIssue: Macro call that should be transformed by with-html", "input": "(with-html-string (:p :attrs attrs \"bar\"))", "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 :attrs attrs \"bar\")))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(~> (flow:atomically :tag-0 () \"Hello\") (-> :tag-1 () \", concurrent\"))\n\nWhat needs to change: Macro call that should be transformed by ~>", "input": "(~> (flow:atomically :tag-0 () \"Hello\") (-> :tag-1 () \", concurrent\"))", "output": "(defmacro ~> (&rest body)\n \"See flow:concurrently\"\n `(concurrently ,@body))", "macroexpand": "(concurrently (atomically :tag-0 nil \"Hello\") (-> :tag-1 nil \", concurrent\"))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-stream nil (progn))\n\nProblem: Macro call that should be transformed by COLLECT-STREAM", "input": "(collect-stream nil (progn))", "output": "(defmacro COLLECT-STREAM ...)", "macroexpand": "(common-lisp:let* ((#:generator-482 (generator (progn))) #:items-477)\n (declare (type generator #:generator-482))\n (tagbody\n #:ll-483\n (setq #:items-477 (next-in #:generator-482 (go end)))\n (common-lisp:funcall #'print #:items-477 nil)\n (go #:ll-483)\n end)\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(define nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEFINE", "input": "(define nil\n nil)", "output": "(defmacro DEFINE ...)", "macroexpand": "(eval-when (:load-toplevel :execute)\n (check-if-bound 'nil)\n (setf (get 'nil 'read-macro)\n (lambda (#:stream146)\n (let ((*standard-input* #:stream146))\n 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(action (:after node-application) #'lift-static-dict)\n\nWhat needs to change: Macro call that should be transformed by action", "input": "(action (:after node-application) #'lift-static-dict)", "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 lift-static-dict))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(scond ((car x) (setf it :nono)) ((car y) (setf it :yes)))\n\nIssue: Macro call that should be transformed by scond", "input": "(scond ((car x) (setf it :nono)) ((car y) (setf it :yes)))", "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 (car x) (progn (setf it :nono)) (symbolic if (car y) (progn (setf it :yes)) nil))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(dreletf* 'some-name)\n\nWhat needs to change: Macro call that should be transformed by DRELETF*", "input": "(dreletf* 'some-name)", "output": "(defmacro DRELETF* ...)", "macroexpand": "(dreletf ('nil)\n (dreletf ((some-name 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(*> (char #\\H) (char #\\e))\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> (char #\\H) (char #\\e))", "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 (#:*>-offset206) (multiple-value-bind (#:*>-res207 #:*>-next208) (funcall (char #\\LATIN_CAPITAL_LETTER_H) #:*>-offset206) (if (ok? #:*>-res207) (funcall (char #\\LATIN_SMALL_LETTER_E) #:*>-next208) (fail #:*>-next208))))", "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-took-usec took-usec (fetch-using-connection conn query))\n\nWhat needs to change: Macro call that should be transformed by with-took-usec", "input": "(with-took-usec took-usec (fetch-using-connection conn query))", "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-unixtime171 #:before-usec172) (sb-ext:get-time-of-day) (multiple-value-prog1 (progn (fetch-using-connection conn query)) (multiple-value-bind (#:after-unixtime173 #:after-usec174) (sb-ext:get-time-of-day) (setf took-usec (+ (* (- #:after-unixtime173 #:before-unixtime171) 1000000) (- #:after-usec174 #:before-usec172))))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(signals (error \"The form ~S is expected to signal an ~S\" '(error \"an error\") 'error) (error \"an error\"))\n\nPattern to recognize: Macro call that should be transformed by signals", "input": "(signals (error \"The form ~S is expected to signal an ~S\" '(error \"an error\") '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 #:g286 (handler-bind ((error (lambda (c) (declare (ignore c)) (add-result (quote test-passed) :test-expr (quote error)) (return-from #:g286 t)))) (block nil (error \"an error\"))) (process-failure (quote error) \"The form ~S is expected to signal an ~S\" (quote (error \"an error\")) (quote error)) (return-from #:g286 nil))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(letrec-syntax common-lisp:nil)\n\nIssue: Macro call that should be transformed by LETREC-SYNTAX", "input": "(letrec-syntax common-lisp:nil)", "output": "(defmacro LETREC-SYNTAX ...)", "macroexpand": "(common-lisp:macrolet 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(collect-first 'some-name)\n\nWhat needs to change: Macro call that should be transformed by COLLECT-FIRST", "input": "(collect-first 'some-name)", "output": "(defmacro COLLECT-FIRST ...)", "macroexpand": "(common-lisp:let* ((#:generator-640 (generator 'some-name))\n #:items-634\n (#:item-636 nil))\n (declare (type generator #:generator-640)\n (type (null-or t) #:item-636))\n (tagbody\n #:ll-641\n (setq #:items-634 (next-in #:generator-640 (go end)))\n (setq #:item-636 #:items-634)\n end)\n #:item-636)", "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 (not (member nil old-kids)))\n\nWrite a macro that addresses: Macro call that should be transformed by c-assert", "input": "(c-assert (not (member nil 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 (not (member nil old-kids)) (c-break \"failed assertion: ~a\" (quote (not (member nil old-kids))))))", "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(defclause to (final-value &key (from 0) by while using) \"Variation over from.\" `(from ,from :to ,final-value :by ,by ,@(when while `(:while ,while)) ,@(when using `(:using ,using))))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause to (final-value &key (from 0) by while using) \"Variation over from.\" `(from ,from :to ,final-value :by ,by ,@(when while `(:while ,while)) ,@(when using `(:using ,using))))", "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 to (final-value &key (from 0) by while using) \"Variation over from.\" (sb-int:quasiquote (from #S(sb-impl::comma :expr from :kind 0) :to #S(sb-impl::comma :expr final-value :kind 0) :by #S(sb-impl::comma :expr by :kind 0) #S(sb-impl::comma :expr (when while (sb-int:quasiquote (:while #S(sb-impl::comma :expr while :kind 0)))) :kind 2) #S(sb-impl::comma :expr (when using (sb-int:quasiquote (:using #S(sb-impl::comma :expr using :kind 0)))) :kind 2)))) (pushnew (quote 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(defparam nil (progn))\n\nWhat needs to change: Macro call that should be transformed by DEFPARAM", "input": "(defparam nil (progn))", "output": "(defmacro DEFPARAM ...)", "macroexpand": "(setf (gethash #A((3) base-char . \"NIL\") cl-rules.core::*parameters*) (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(is (string= result (dummy-strcat (subseq result 0 split-point) (subseq result split-point))))\n\nPattern to recognize: Macro call that should be transformed by is", "input": "(is (string= result (dummy-strcat (subseq result 0 split-point) (subseq result split-point))))", "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 ((#:e167 result) (#:a168 (dummy-strcat (subseq result 0 split-point) (subseq result split-point)))) (if (progn (string= #:e167 #:a168)) (add-result (quote test-passed) :test-expr (quote (string= result (dummy-strcat (subseq result 0 split-point) (subseq result split-point))))) (process-failure (quote (string= result (dummy-strcat (subseq result 0 split-point) (subseq result split-point)))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (dummy-strcat (subseq result 0 split-point) (subseq result split-point))) #:a168 (quote string=) #:e167)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(defcell b 1)\n\nPattern to recognize: Macro call that should be transformed by defcell", "input": "(defcell b 1)", "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% b 1)", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-alias-binding maximize maximizing)\n\nPattern to recognize: Macro call that should be transformed by define-alias-binding", "input": "(define-alias-binding maximize maximizing)", "output": "(defmacro define-alias-binding (name referenced-binding-name)\n `(progn (setf (binding ',name) ',referenced-binding-name)\n ',name))", "macroexpand": "(progn (setf (binding (quote maximize)) (quote maximizing)) (quote maximize))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(is (integerp a))\n\nIssue: Macro call that should be transformed by is", "input": "(is (integerp 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 ((#:v124 a)) (if (integerp #:v124) (add-result (quote test-passed) :test-expr (quote (integerp a))) (process-failure (quote (integerp a)) \"~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%\" (quote a) #:v124 (quote integerp))))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defclause collecting-into-and-returning (vars &rest args &key initially by finally) \"Same as collecting-into, but also returns the value of each at the end of the loop.\" (declare (ignore initially by finally)) `((collecting-into ,vars ,@args) ,@(mapcar (lambda (var) `(returning ,var)) (ensure-list vars))))\n\nWhat needs to change: Macro call that should be transformed by defclause", "input": "(defclause collecting-into-and-returning (vars &rest args &key initially by finally) \"Same as collecting-into, but also returns the value of each at the end of the loop.\" (declare (ignore initially by finally)) `((collecting-into ,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 collecting-into-and-returning (vars &rest args &key initially by finally) \"Same as collecting-into, but also returns the value of each at the end of the loop.\" (declare (ignore initially by finally)) (sb-int:quasiquote ((collecting-into #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 collecting-into-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(c-assert (not (find c *call-stack*)))\n\nWrite a macro that addresses: Macro call that should be transformed by c-assert", "input": "(c-assert (not (find c *call-stack*)))", "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 (not (find c *call-stack*)) (c-break \"failed assertion: ~a\" (quote (not (find c *call-stack*))))))", "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-mocks () (register-mock 'foo) (register-mock 'bar) (bt:make-thread (lambda () (foo) (bar))) (is (assert-cond (lambda () (and (equal '((foo)) (invocations 'foo)) (equal '((bar)) (invocations 'bar)))) .5)))\n\nWhat needs to change: Macro call that should be transformed by with-mocks", "input": "(with-mocks () (register-mock 'foo) (register-mock 'bar) (bt:make-thread (lambda () (foo) (bar))) (is (assert-cond (lambda () (and (equal '((foo)) (invocations 'foo)) (equal '((bar)) (invocations 'bar)))) .5)))", "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)) (register-mock (quote bar)) (bordeaux-threads:make-thread (lambda nil (foo) (bar))) (is (assert-cond (lambda nil (and (equal (quote ((foo))) (invocations (quote foo))) (equal (quote ((bar))) (invocations (quote bar))))) 0.5))) :recordp t)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\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\nPattern to recognize: Macro call that should be transformed by define", "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 (name template)\n \"Define a named renderer of string TEMPLATE.\"\n `(setf (symbol-function ',name)\n (compile-template ,template)))", "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": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(signal-syntax-error \"Register 0 doesn't exist: ~S.\" parse-tree)\n\nProblem: Macro call that should be transformed by signal-syntax-error", "input": "(signal-syntax-error \"Register 0 doesn't exist: ~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 \"Register 0 doesn't exist: ~S.\" parse-tree)", "category": "control-flow", "technique": "recursive-expansion", "complexity": "basic", "quality_score": 0.83} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-simple-definition-resolver package find-package)\n\nPattern to recognize: Macro call that should be transformed by define-simple-definition-resolver", "input": "(define-simple-definition-resolver package find-package)", "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 package (package #:package132) (when (ignore-errors (find-package package)) (list (make-instance (quote package) :designator package :package #:package132))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-global-parameter* nil (progn))\n\nIssue: Macro call that should be transformed by DEFINE-GLOBAL-PARAMETER*", "input": "(define-global-parameter* nil (progn))", "output": "(defmacro DEFINE-GLOBAL-PARAMETER* ...)", "macroexpand": "(progn\n (setf (get 'nil +value-key+) (progn))\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": "Create a Common Lisp macro for the following transformation. Before code:\n(lambda-match\n nil)\n\nWhat needs to change: Macro call that should be transformed by LAMBDA-MATCH", "input": "(lambda-match\n nil)", "output": "(defmacro LAMBDA-MATCH ...)", "macroexpand": "(lambda (#:arg146)\n (match #:arg146\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(compiler-macro-lambda (a) `(1+ ,a))\n\nPattern to recognize: Macro call that should be transformed by compiler-macro-lambda", "input": "(compiler-macro-lambda (a) `(1+ ,a))", "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-lambda148) (#:expr #:env) (declare (sb-c::lambda-list (a))) (declare (ignore #:env)) (sb-int:named-ds-bind (:macro #:compiler-macro-lambda148 . define-compiler-macro) (a) (sb-c::compiler-macro-args #:expr) (declare (sb-c::constant-value a) (sb-c::no-compiler-macro #:compiler-macro-lambda148)) (block #:compiler-macro-lambda148 (sb-int:quasiquote (1+ #S(sb-impl::comma :expr a :kind 0))))))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defjsmacro)\n\nIssue: Macro call that should be transformed by DEFJSMACRO", "input": "(defjsmacro)", "output": "(defmacro DEFJSMACRO ...)", "macroexpand": "(defpsmacro)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(with-sql-logging (mapc #'execute-sql (migration-expressions class)))\n\nProblem: Macro call that should be transformed by with-sql-logging", "input": "(with-sql-logging (mapc #'execute-sql (migration-expressions 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) (migration-expressions class))))", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-wcs-math-error-handling (ret (log x (float 10 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 (log x (float 10 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* ((#:g224 x) (#:g225 (float 10 x)) (#:g226 (list #:g224 #:g225))) (declare (ignorable #:g225) (type list #:g226) (dynamic-extent #:g226)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote log) #:g226) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g226)) (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(letmatch nil\n nil)\n\nWhat needs to change: Macro call that should be transformed by LETMATCH", "input": "(letmatch nil\n nil)", "output": "(defmacro LETMATCH ...)", "macroexpand": "(ifmatch (nil nil nil (error \"LETMATCH: mismatch.\")))", "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* ((#:g126 nil))\n (if (null #:g126)\n nil\n (->> #:g126 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lexpr-$send nil :key nil)\n\nIssue: Macro call that should be transformed by LEXPR-$SEND", "input": "(lexpr-$send nil :key nil)", "output": "(defmacro LEXPR-$SEND ...)", "macroexpand": "(apply #'send-message 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(destructuring-match nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by DESTRUCTURING-MATCH", "input": "(destructuring-match nil\n (progn))", "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\n (funcall\n (lambda (#:thing #:fail)\n (let ((progn #:thing) (#:thing 'nil))\n (if (not (null #:thing))\n (org.tfeb.dsm/impl::fail #:fail \"extra arguments\")\n (locally (multiple-value-call #:done (progn))))))\n #:form\n (lambda (message arguments)\n (declare (ignore message arguments))\n (go #:next)))\n #:next))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(alter nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by ALTER", "input": "(alter nil (progn))", "output": "(defmacro ALTER ...)", "macroexpand": "(compiler-let ((*optimize-series-expressions* nil)) (alter nil (progn)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(deferror \"42501\" insufficient-privilege syntax-error-or-access-violation)\n\nIssue: Macro call that should be transformed by deferror", "input": "(deferror \"42501\" insufficient-privilege 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 insufficient-privilege (syntax-error-or-access-violation) nil) (setf (gethash \"42501\" *error-table*) (quote insufficient-privilege)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"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": "(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(with-decoder-simple-list-semantics (let ((*json-symbols-package* 'json-test)) (decode-json-from-string encoded)))\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* 'json-test)) (decode-json-from-string encoded)))", "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* (quote json-test))) (decode-json-from-string encoded)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun/1 fputs (str fd) (handler-case (progn (write-string (char*-to-string str) (fd-stream fd)) 0) (error () (setf (ferror fd) EIO) EOF)))\n\nPattern to recognize: Macro call that should be transformed by defun/1", "input": "(defun/1 fputs (str fd) (handler-case (progn (write-string (char*-to-string str) (fd-stream fd)) 0) (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 fputs (str fd) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (handler-case (progn (write-string (char*-to-string str) (fd-stream fd)) 0) (error nil (setf (ferror fd) eio) eof))) (defparameter fputs (vacietis.c:mkptr& (symbol-function (quote fputs)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun-compile-time indirect-callers-internal (function-names callers) (if (null function-names) callers (let ((function-name (first function-names))) (if (member function-name callers :test #'equal) (indirect-callers-internal (rest function-names) callers) (indirect-callers-internal (rest function-names) (indirect-callers-internal (callers function-name) (cons function-name callers)))))))\n\nIssue: Macro call that should be transformed by defun-compile-time", "input": "(defun-compile-time indirect-callers-internal (function-names callers) (if (null function-names) callers (let ((function-name (first function-names))) (if (member function-name callers :test #'equal) (indirect-callers-internal (rest function-names) callers) (indirect-callers-internal (rest function-names) (indirect-callers-internal (callers function-name) (cons function-name callers)))))))", "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-internal (function-names callers) (if (null function-names) callers (let ((function-name (first function-names))) (if (member function-name callers :test (function equal)) (indirect-callers-internal (rest function-names) callers) (indirect-callers-internal (rest function-names) (indirect-callers-internal (callers function-name) (cons function-name callers))))))) (eval-when (:compile-toplevel) (compile (quote indirect-callers-internal))))", "category": "control-flow", "technique": "", "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) c1) ((:structure metabang-bind-test-1- a b (second-c c)) c2)) (list my-a c a b second-c))\n\nIssue: Macro call that should be transformed by bind", "input": "(bind (((:structure metabang-bind-test-1- (my-a a) c) c1) ((:structure metabang-bind-test-1- a b (second-c c)) c2)) (list my-a c a b second-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-193| c1) (my-a (metabang-bind-test-1-a #:|values-193|)) (c (metabang-bind-test-1-c #:|values-193|)) (#:|values-192| c2) (a (metabang-bind-test-1-a #:|values-192|)) (b (metabang-bind-test-1-b #:|values-192|)) (second-c (metabang-bind-test-1-c #:|values-192|))) (declare (ignorable #:|values-193|)) (declare (ignorable #:|values-192|)) (progn (list my-a c a b second-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(with-flow-function-macro (body-fu lambda-list fu-body) `(dispatch-asynchronously ,flow-context #',body-fu))\n\nWhat needs to change: Macro call that should be transformed by with-flow-function-macro", "input": "(with-flow-function-macro (body-fu lambda-list fu-body) `(dispatch-asynchronously ,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 fu-body :kind 2)) #S(sb-impl::comma :expr (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": "Define a macro that eliminates this repetitive pattern:\n(define-component parenscript :input-type \"lisp\" :output-type \"js\" :compile-function (lambda (input-pathname output-pathname) (with-open-file (stream output-pathname :direction :output :if-exists :supersede :if-does-not-exist :create) (write-string (parenscript:ps-compile-file input-pathname) stream))))\n\nIssue: Macro call that should be transformed by define-component", "input": "(define-component parenscript :input-type \"lisp\" :output-type \"js\" :compile-function (lambda (input-pathname output-pathname) (with-open-file (stream output-pathname :direction :output :if-exists :supersede :if-does-not-exist :create) (write-string (parenscript:ps-compile-file input-pathname) stream))))", "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 parenscript (source-file) ((type :initform \"lisp\") (output :reader output :initarg :output))) (defmethod perform ((o load-op) (component parenscript)) t) (defmethod output-files ((operation compile-op) (component parenscript)) (list (output-pathname component \"js\"))) (defmethod perform ((o compile-op) (component parenscript)) (funcall (lambda (input-pathname output-pathname) (with-open-file (stream output-pathname :direction :output :if-exists :supersede :if-does-not-exist :create) (write-string (parenscript:ps-compile-file input-pathname) stream))) (component-pathname component) (output-pathname component \"js\"))) (import (quote parenscript) :asdf))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(untrace$method 'some-name)\n\nWhat needs to change: Macro call that should be transformed by UNTRACE$METHOD", "input": "(untrace$method 'some-name)", "output": "(defmacro UNTRACE$METHOD ...)", "macroexpand": "(mcs-untrace quote 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* start-pos \"Missing right bracket to close character class.\")\n\nWrite a macro that addresses: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* start-pos \"Missing right bracket to close character class.\")", "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 start-pos :format-control \"Missing right bracket to close character class.\" :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-xml-group-element (s \"tspan\" opts) (string->xml s text))\n\nWrite a macro that addresses: Macro call that should be transformed by with-xml-group-element", "input": "(with-xml-group-element (s \"tspan\" opts) (string->xml s text))", "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 ((#:|stream134| s) (#:|element135| \"tspan\")) (begin-group->xml #:|stream134| #:|element135| opts) (with-indentation (string->xml s text)) (end-group->xml #:|stream134| #:|element135|))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-mustache-character #\\! (make-instance 'comment-tag :text \"\"))\n\nPattern to recognize: Macro call that should be transformed by define", "input": "(define-mustache-character #\\! (make-instance 'comment-tag :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 #\\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": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(*> +consume-ws+ +any-crlf+)\n\nIssue: Macro call that should be transformed by *>", "input": "(*> +consume-ws+ +any-crlf+)", "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 (#:*>-offset128) (multiple-value-bind (#:*>-res129 #:*>-next130) (funcall +consume-ws+ #:*>-offset128) (if (ok? #:*>-res129) (funcall +any-crlf+ #:*>-next130) (fail #:*>-next130))))", "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-symbol-access\n nil\n (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by WITH-SYMBOL-ACCESS", "input": "(with-symbol-access\n nil\n (progn))", "output": "(defmacro WITH-SYMBOL-ACCESS ...)", "macroexpand": "(let ((*symbol-access* t))\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(enable-quasi-quoted-bivalent-to-binary-emitting-form-syntax 'some-name)\n\nPattern to recognize: Macro call that should be transformed by ENABLE-QUASI-QUOTED-BIVALENT-TO-BINARY-EMITTING-FORM-SYNTAX", "input": "(enable-quasi-quoted-bivalent-to-binary-emitting-form-syntax 'some-name)", "output": "(defmacro ENABLE-QUASI-QUOTED-BIVALENT-TO-BINARY-EMITTING-FORM-SYNTAX ...)", "macroexpand": "(eval-when (:compile-toplevel :execute)\n (setf *readtable* (copy-readtable *readtable*))\n (set-quasi-quoted-bivalent-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 \"biv\" :encoding *default-character-encoding*)\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is (= 0 (add-4 -4)))\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is (= 0 (add-4 -4)))", "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 ((#:e143 0) (#:a144 (add-4 -4))) (if (progn (= #:e143 #:a144)) (add-result (quote test-passed) :test-expr (quote (= 0 (add-4 -4)))) (process-failure (quote (= 0 (add-4 -4))) \"~2&~S~2% evaluated to ~2&~S~2% which is not ~2&~S~2% to ~2&~S~2%\" (quote (add-4 -4)) #:a144 (quote =) #:e143)))", "category": "capture-management", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(\u0192\u0192 nil)\n\nWrite a macro that addresses: Macro call that should be transformed by \u0191\u0191", "input": "(\u0192\u0192 nil)", "output": "(defmacro \u0191\u0191 ...)", "macroexpand": "(defun nil (&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(*> +consume-space+ +close-bracket+)\n\nProblem: Macro call that should be transformed by *>", "input": "(*> +consume-space+ +close-bracket+)", "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 (#:*>-offset175) (multiple-value-bind (#:*>-res176 #:*>-next177) (funcall +consume-space+ #:*>-offset175) (if (ok? #:*>-res176) (funcall +close-bracket+ #:*>-next177) (fail #:*>-next177))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :g (v) v)\n\nProblem: Macro call that should be transformed by ->", "input": "(-> :g (v) v)", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (v) v)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(js nil :key nil)\n\nWhat needs to change: Macro call that should be transformed by JS", "input": "(js nil :key nil)", "output": "(defmacro JS ...)", "macroexpand": "(ps\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(def-neo4j-fun del-node-properties (node-id) :delete (:uri-spec (format nil \"node/~A/properties\" node-id)) (:status-handlers (204 (values t body)) (404 (error 'node-not-found-error :uri uri))))\n\nPattern to recognize: Macro call that should be transformed by def-neo4j-fun", "input": "(def-neo4j-fun del-node-properties (node-id) :delete (:uri-spec (format nil \"node/~A/properties\" node-id)) (:status-handlers (204 (values t 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 del-node-properties (&key node-id) (let ((uri (format nil \"node/~A/properties\" 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))))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defvariant nil)\n\nWhat needs to change: Macro call that should be transformed by DEFVARIANT", "input": "(defvariant nil)", "output": "(defmacro DEFVARIANT ...)", "macroexpand": "(progn\n (defstruct (nil (:constructor 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-output-to-file (stream pathname :if-exists if-exists :if-does-not-exist if-does-not-exist :element-type '(unsigned-byte 8)) (write-sequence bytes stream))\n\nPattern to recognize: Macro call that should be transformed by with-output-to-file", "input": "(with-output-to-file (stream pathname :if-exists if-exists :if-does-not-exist if-does-not-exist :element-type '(unsigned-byte 8)) (write-sequence bytes 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* (stream pathname :direction :output :if-exists if-exists :if-does-not-exist if-does-not-exist :element-type (quote (unsigned-byte 8))) (write-sequence bytes stream))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-html-string (:div (:section (:tag :name :h2 (:p \"hello\")))))\n\nPattern to recognize: Macro call that should be transformed by with-html", "input": "(with-html-string (:div (:section (:tag :name :h2 (:p \"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 (:div (:section (:tag :name :h2 (:p \"hello\"))))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"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 \"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) (fill out pad :end offset) 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(->> nil nil)\n\nWhat needs to change: 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": "Define a macro that eliminates this repetitive pattern:\n(check-cursor-attached cluffer:end-of-line-p (cursor))\n\nIssue: Macro call that should be transformed by check-cursor-attached", "input": "(check-cursor-attached cluffer:end-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:end-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": "Write a Common Lisp macro to handle this code pattern:\n(with-form-field-values (name) form (print name))\n\nProblem: Macro call that should be transformed by with-form", "input": "(with-form-field-values (name) form (print 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 (field-value (get-field form (quote name))))) (print name))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(lambda-coro\n nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by LAMBDA-CORO", "input": "(lambda-coro\n nil\n (progn))", "output": "(defmacro LAMBDA-CORO ...)", "macroexpand": "(progn\n (defcoroutine #:name129\n (#:arg130)\n (macrolet ((yield (form)\n (let ((g!-it (gensym \"IT\")))\n `(progn\n (let ((,g!-it ,form))\n (cl-coroutine:yield ,g!-it))\n ,'#:arg130)))\n (last-yield-value ()\n '#:arg130))\n nil\n (progn)\n (coexit!)))\n (make-coroutine '#:name129))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defun-speedy %ascii-string-to-octets (string) (let ((result (make-array (length string) :element-type '(unsigned-byte 8)))) (declare (type octets result)) (dotimes (i (length string) result) (declare (type fixnum i)) (setf (aref result i) (char-code (aref string i))))))\n\nWhat needs to change: Macro call that should be transformed by defun-speedy", "input": "(defun-speedy %ascii-string-to-octets (string) (let ((result (make-array (length string) :element-type '(unsigned-byte 8)))) (declare (type octets result)) (dotimes (i (length string) result) (declare (type fixnum i)) (setf (aref result i) (char-code (aref string i))))))", "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))) (let ((result (make-array (length string) :element-type (quote (unsigned-byte 8))))) (declare (type octets result)) (dotimes (i (length string) result) (declare (type fixnum i)) (setf (aref result i) (char-code (aref string i)))))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(match0 (coerce (subseq name (- l 2) l) 'list) ((list #\\- #\\P) (when-let ((typesym (find-symbol (subseq name 0 (- l 2)) (symbol-package fn-sym)))) (if (subtypep typesym t) typesym t))) ((list _ #\\P) (when-let ((typesym (find-symbol (subseq name 0 (- l 1)) (symbol-package fn-sym)))) (if (subtypep typesym t) typesym t))))\n\nWrite a macro that addresses: Macro call that should be transformed by match0", "input": "(match0 (coerce (subseq name (- l 2) l) 'list) ((list #\\- #\\P) (when-let ((typesym (find-symbol (subseq name 0 (- l 2)) (symbol-package fn-sym)))) (if (subtypep typesym t) typesym t))) ((list _ #\\P) (when-let ((typesym (find-symbol (subseq name 0 (- l 1)) (symbol-package fn-sym)))) (if (subtypep typesym t) typesym t))))", "output": "(defmacro match0 (*what* &body clauses &environment *env*)\n (once-only (*what*)\n (parse-patterns clauses)))", "macroexpand": "(let ((#:*what*149 (coerce (subseq name (- l 2) l) (quote list)))) (declare (ignorable #:*what*149)) (if (and (consp #:*what*149) (let ((#:*what*150 (car #:*what*149))) (declare (ignorable #:*what*150)) (equal #:*what*150 #\\HYPHEN-MINUS)) (let ((#:*what*151 (cdr #:*what*149))) (declare (ignorable #:*what*151)) (and (consp #:*what*151) (let ((#:*what*152 (car #:*what*151))) (declare (ignorable #:*what*152)) (equal #:*what*152 #\\LATIN_CAPITAL_LETTER_P)) (let ((#:*what*153 (cdr #:*what*151))) (declare (ignorable #:*what*153)) (equal #:*what*153 nil))))) (let* ((#:*what*150 (car #:*what*149)) (#:*what*151 (cdr #:*what*149)) (#:*what*152 (car #:*what*151)) (#:*what*153 (cdr #:*what*151))) (declare (ignorable #:*what*153 #:*what*152 #:*what*151 #:*what*150)) (when-let ((typesym (find-symbol (subseq name 0 (- l 2)) (symbol-package fn-sym)))) (if (subtypep typesym t) typesym t))) (if (and (consp #:*what*149) (let ((#:*what*154 (car #:*what*149))) (declare (ignorable #:*what*154)) t) (let ((#:*what*155 (cdr #:*what*149))) (declare (ignorable #:*what*155)) (and (consp #:*what*155) (let ((#:*what*156 (car #:*what*155))) (declare (ignorable #:*what*156)) (equal #:*what*156 #\\LATIN_CAPITAL_LETTER_P)) (let ((#:*what*157 (cdr #:*what*155))) (declare (ignorable #:*what*157)) (equal #:*what*157 nil))))) (let* ((#:*what*154 (car #:*what*149)) (#:*what*155 (cdr #:*what*149)) (#:*what*156 (car #:*what*155)) (#:*what*157 (cdr #:*what*155))) (declare (ignorable #:*what*157 #:*what*156 #:*what*155 #:*what*154)) (when-let ((typesym (find-symbol (subseq name 0 (- l 1)) (symbol-package fn-sym)))) (if (subtypep typesym t) typesym t))) 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(do-generator (item generator) (unless (funcall predicate item) (return)) (yield item))\n\nWrite a macro that addresses: Macro call that should be transformed by do-generator", "input": "(do-generator (item generator) (unless (funcall predicate item) (return)) (yield 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 ((#:g161 generator)) (loop do (if-generator ((item) #:g161) (progn (unless (funcall predicate item) (return)) (yield item)) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defstruct-compile-time (nondeterministic-function (:print-function print-nondeterministic-function) (:predicate nondeterministic-function?-internal)) function)\n\nIssue: Macro call that should be transformed by defstruct-compile-time", "input": "(defstruct-compile-time (nondeterministic-function (:print-function print-nondeterministic-function) (:predicate nondeterministic-function?-internal)) function)", "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 (nondeterministic-function (:print-function print-nondeterministic-function) (:predicate nondeterministic-function?-internal)) function))", "category": "anaphoric", "technique": "anaphor", "complexity": "basic", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-option-expander use (package &rest packages) (use-package packages package))\n\nProblem: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander use (package &rest packages) (use-package packages 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 ((#:type126 (eql :use)) package #:args125) (destructuring-bind (&rest packages) #:args125 (use-package packages package)))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"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": "Generate a defmacro form that transforms code like this:\n(with-table node hash depth (bitmap array bits index hit) (if (not hit) node (let ((new-node (%hamt-remove (aref array index) key hash (1+ depth) test))) (cond (new-node (make-instance (type-of node) :bitmap bitmap :table (vec-update array index new-node))) ((= bitmap 1) nil) (t (make-instance (type-of node) :bitmap (logxor bitmap (ash 1 bits)) :table (vec-remove array index)))))))\n\nPattern to recognize: Macro call that should be transformed by with-table", "input": "(with-table node hash depth (bitmap array bits index hit) (if (not hit) node (let ((new-node (%hamt-remove (aref array index) key hash (1+ depth) test))) (cond (new-node (make-instance (type-of node) :bitmap bitmap :table (vec-update array index new-node))) ((= bitmap 1) nil) (t (make-instance (type-of node) :bitmap (logxor bitmap (ash 1 bits)) :table (vec-remove array index)))))))", "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 (not hit) node (let ((new-node (%hamt-remove (aref array index) key hash (1+ depth) test))) (cond (new-node (make-instance (type-of node) :bitmap bitmap :table (vec-update array index new-node))) ((= bitmap 1) nil) (t (make-instance (type-of node) :bitmap (logxor bitmap (ash 1 bits)) :table (vec-remove array index)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-package (package (or identifier *package*)) (cond ((not package) (error 'module-not-found :requested identifier)) (T (or (resolve-module package) (error 'not-a-module :requested package)))))\n\nPattern to recognize: Macro call that should be transformed by with-package", "input": "(with-package (package (or identifier *package*)) (cond ((not package) (error 'module-not-found :requested identifier)) (T (or (resolve-module package) (error 'not-a-module :requested package)))))", "output": "(defmacro with-package ((var &optional (package var)) &body body)\n `(let ((,var (ensure-package ,package)))\n ,@body))", "macroexpand": "(let ((package (ensure-package (or identifier *package*)))) (cond ((not package) (error (quote module-not-found) :requested identifier)) (t (or (resolve-module package) (error (quote not-a-module) :requested package)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(%proper-list-p var 'cons)\n\nWhat needs to change: Macro call that should be transformed by %proper-list-p", "input": "(%proper-list-p var 'cons)", "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 var (null (return t)) (cons (if (or nil (typep (car var) (quote cons))) (setq var (cdr var)) (return))) (t (return))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(defaction nil\n (progn))\n\nProblem: Macro call that should be transformed by DEFACTION", "input": "(defaction nil\n (progn))", "output": "(defmacro DEFACTION ...)", "macroexpand": "(setf (gethash #A((3) base-char . \"NIL\") cl-rules.core::*actions*)\n (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(deferror \"23\" integrity-violation)\n\nWrite a macro that addresses: Macro call that should be transformed by deferror", "input": "(deferror \"23\" 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 integrity-violation (database-error) nil) (setf (gethash \"23\" *error-table*) (quote integrity-violation)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8374999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(ct-let nil\n nil)\n\nProblem: Macro call that should be transformed by CT-LET", "input": "(ct-let nil\n nil)", "output": "(defmacro CT-LET ...)", "macroexpand": "(cond\n (*within-captured-dynenv*\n (let ()\n (let ((#:new-var-space151\n (reduce\n (lambda (#:accum152 #:item153)\n (destructuring-bind\n (#:name154 . #:value155)\n #:item153\n (update-alist #:name154 #:value155 #:accum152)))\n (list) :initial-value *var-space*)))\n `(symbol-macrolet ((var-space ,#:new-var-space151))\n ,(let ((*var-space* #:new-var-space151))\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(f_\n 'some-name)\n\nWhat needs to change: Macro call that should be transformed by F_", "input": "(f_\n 'some-name)", "output": "(defmacro F_ ...)", "macroexpand": "(lambda (_) 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"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* ((#:|some125| nil))\n #:|some125|)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(alist-bind (name inline parameters return-type variadic) form (unless inline (let ((sym (foreign-type-symbol name :cfun *package*))) (let ((cfun-fields (parse-fields parameters :cparam))) (push sym *foreign-function-list*) `(define-foreign-function '(,sym ,name ,@(when variadic '(:variadic-p t))) ',@(parse-type return-type (aval :tag return-type)) ',cfun-fields)))))\n\nProblem: Macro call that should be transformed by alist-bind", "input": "(alist-bind (name inline parameters return-type variadic) form (unless inline (let ((sym (foreign-type-symbol name :cfun *package*))) (let ((cfun-fields (parse-fields parameters :cparam))) (push sym *foreign-function-list*) `(define-foreign-function '(,sym ,name ,@(when variadic '(:variadic-p t))) ',@(parse-type return-type (aval :tag return-type)) ',cfun-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 ((#:alist244 form)) (let ((name (aval :name #:alist244)) (inline (aval :inline #:alist244)) (parameters (aval :parameters #:alist244)) (return-type (aval :return-type #:alist244)) (variadic (aval :variadic #:alist244))) (unless inline (let ((sym (foreign-type-symbol name :cfun *package*))) (let ((cfun-fields (parse-fields parameters :cparam))) (push sym *foreign-function-list*) (sb-int:quasiquote (define-foreign-function (quote (#S(sb-impl::comma :expr sym :kind 0) #S(sb-impl::comma :expr name :kind 0) #S(sb-impl::comma :expr (when variadic (quote (:variadic-p t))) :kind 2))) (quote #S(sb-impl::comma :expr (parse-type return-type (aval :tag return-type)) :kind 2)) (quote #S(sb-impl::comma :expr cfun-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-modf-rewrite cadr (expr) `(car (cdr ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cadr (expr) `(car (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 cadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cdr #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(sor (elt-like 0 cell) (setf it 1))\n\nIssue: Macro call that should be transformed by sor", "input": "(sor (elt-like 0 cell) (setf it 1))", "output": "(defmacro sor (first &rest rest)\n \"Like OR, except binds the first argument to IT (via SYMBOL-MACROLET) for\nthe scope of the rest of the arguments. IT can be set with SETF.\"\n `(symbolic or ,first ,@rest))", "macroexpand": "(symbolic or (elt-like 0 cell) (setf it 1))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(augment *special-clause-alist* (list (cons symbol doc-string)))\n\nIssue: Macro call that should be transformed by augment", "input": "(augment *special-clause-alist* (list (cons symbol doc-string)))", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf *special-clause-alist* (nconc *special-clause-alist* (list (cons symbol doc-string))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(js-inline nil nil)\n\nIssue: Macro call that should be transformed by JS-INLINE", "input": "(js-inline nil nil)", "output": "(defmacro JS-INLINE ...)", "macroexpand": "(js-inline* '(progn nil nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n($unset \"k\" \"l\")\n\nProblem: Macro call that should be transformed by $", "input": "($unset \"k\" \"l\")", "output": "(defmacro $ (&rest args)\n `(kv ,@args))", "macroexpand": "(kv \"$unset\" (construct-container* 1 (unwrap ($exp+ \"k\" \"l\"))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(while nil)\n\nProblem: Macro call that should be transformed by WHILE", "input": "(while nil)", "output": "(defmacro WHILE ...)", "macroexpand": "(loop while nil\n do (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(signal-reader-error \"Expected } after hex code\")\n\nWrite a macro that addresses: Macro call that should be transformed by signal-reader-error", "input": "(signal-reader-error \"Expected } after hex 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 \"Expected } after hex code\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"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 (let+ nil\n nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(augment *finalp* finalp)\n\nIssue: Macro call that should be transformed by augment", "input": "(augment *finalp* finalp)", "output": "(defmacro augment (var stuff)\n `(setf ,var (nconc ,var ,stuff)))", "macroexpand": "(setf *finalp* (nconc *finalp* finalp))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(signal-syntax-error* (lexer-pos lexer) \"Expected end of string.\")\n\nPattern to recognize: Macro call that should be transformed by signal-syntax-error*", "input": "(signal-syntax-error* (lexer-pos lexer) \"Expected end of string.\")", "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 end of string.\" :format-arguments (list))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-custom-var (:string-char *string-char-handler*))\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:string-char *string-char-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 (*string-char-handler* . :string-char)) *custom-vars* :test (function equal)) (defvar *string-char-handler*)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(doseq (elem sequence :from-end from-end :start start :end end) (when (funcall test (funcall key elem)) (return (compute-pos pos))) (incf pos))\n\nWhat needs to change: 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)) (return (compute-pos pos))) (incf pos))", "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)) (return (compute-pos pos))) (incf pos))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-custom-var (:array-member *array-member-handler*) (constantly t) \"Designator for a function of 1 arbitrary argument (decoded member of Array).\")\n\nPattern to recognize: Macro call that should be transformed by define-custom-var", "input": "(define-custom-var (:array-member *array-member-handler*) (constantly t) \"Designator for a function of 1 arbitrary argument (decoded member of 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-member-handler* . :array-member)) *custom-vars* :test (function equal)) (defvar *array-member-handler* (constantly t) \"Designator for a function of 1 arbitrary argument (decoded member of Array).\")))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-cruft %find-readtable (name) \"Return the readtable named NAME.\" #+ :allegro (excl:named-readtable (readtable-name-for-allegro name) nil) #+ :common-lisp (values (gethash name *named-readtables* nil)))\n\nPattern to recognize: Macro call that should be transformed by define-cruft", "input": "(define-cruft %find-readtable (name) \"Return the readtable named NAME.\" #+ :allegro (excl:named-readtable (readtable-name-for-allegro name) nil) #+ :common-lisp (values (gethash name *named-readtables* 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 %find-readtable)) (defun %find-readtable (name) \"Return the readtable named NAME.\" (values (gethash name *named-readtables* nil))))", "category": "efficiency", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(mapcar 'binding-to-symbol bindings)\n\nPattern to recognize: Macro call that should be transformed by m", "input": "(mapcar 'binding-to-symbol bindings)", "output": "(defmacro m (form &environment *env*)\n (e form))", "macroexpand": "(mapcar (quote binding-to-symbol) bindings)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(doseq 'some-name)\n\nWrite a macro that addresses: Macro call that should be transformed by DOSEQ", "input": "(doseq 'some-name)", "output": "(defmacro doseq ((var seq-form &optional result-form) &body body)\n \"doseq iterates over the elements of an sequence and binds value-var to successive values\nand then evaluates body as a tagbody that can include declarations. Finally the result-form\nis returned after the iteration completes.\"\n #+clisp\n `(ext:doseq (,var ,seq-form ,result-form)\n ,@body)\n #+sbcl\n `(sb-sequence:dosequence (,var ,seq-form ,result-form)\n ,@body)\n #-(or clisp sbcl)\n `(doseq* (,(gensym) ,var ,seq-form ,result-form)\n ,@body))", "macroexpand": "(sb-sequence:dosequence (quote some-name nil))", "category": "anaphoric", "technique": "gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.835} {"instruction": "Generate a defmacro form that transforms code like this:\n(with-env (setp 4 [arr 0 2]))\n\nPattern to recognize: Macro call that should be transformed by with-env", "input": "(with-env (setp 4 [arr 0 2]))", "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 (#:g133) (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 #:g133 (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 4 [arr 0 2]))) (setf (find-class (quote foo) nil) nil) (setf (find-class (quote bar) nil) nil) #:g133)", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"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 (defmacro nil ()) (import-macros-from-lisp 'nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(action (:after node-direct-application) #'validate-candidate)\n\nIssue: Macro call that should be transformed by action", "input": "(action (:after node-direct-application) #'validate-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-direct-application) (function validate-candidate))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(flet* nil\n (progn))\n\nWhat needs to change: Macro call that should be transformed by FLET*", "input": "(flet* nil\n (progn))", "output": "(defmacro FLET* ...)", "macroexpand": "(flet ()\n (progn))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(max-of nil\n :key\n nil)\n\nIssue: Macro call that should be transformed by MAX-OF", "input": "(max-of nil\n :key\n nil)", "output": "(defmacro MAX-OF ...)", "macroexpand": "(lc (nil :key nil) maximize)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(bind (((:accessors-r/o (my-a a) (my-c c) (d the-d)) (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5))) (list d my-c my-a))\n\nWhat needs to change: Macro call that should be transformed by bind", "input": "(bind (((:accessors-r/o (my-a a) (my-c c) (d the-d)) (make-instance 'metabang-bind-class-2 :a 1 :b 2 :c 3 :d 4 :e 5))) (list d my-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-175| (make-instance (quote metabang-bind-class-2) :a 1 :b 2 :c 3 :d 4 :e 5)) (my-a (a #:|values-175|)) (my-c (c #:|values-175|)) (d (the-d #:|values-175|))) (declare (ignorable #:|values-175|)) (progn (list d my-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(signal-reader-error \"No character for char-code #x~X\" number)\n\nProblem: Macro call that should be transformed by signal-reader-error", "input": "(signal-reader-error \"No character for char-code #x~X\" number)", "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 number))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(ct-let nil\n (progn))\n\nPattern to recognize: Macro call that should be transformed by CT-LET", "input": "(ct-let nil\n (progn))", "output": "(defmacro CT-LET ...)", "macroexpand": "(cond\n (*within-captured-dynenv*\n (let ()\n (let ((#:new-var-space156\n (reduce\n (lambda (#:accum157 #:item158)\n (destructuring-bind\n (#:name159 . #:value160)\n #:item158\n (update-alist #:name159 #:value160 #:accum157)))\n (list) :initial-value *var-space*)))\n `(symbol-macrolet ((var-space ,#:new-var-space156))\n ,(let ((*var-space* #:new-var-space156))\n (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(defannotation optimize* (quality) (:alias optimize :inline t) \"Shorthand for (DECLARE (OPTIMIZE ...)).\" `(declare (optimize ,quality)))\n\nProblem: Macro call that should be transformed by defannotation", "input": "(defannotation optimize* (quality) (:alias optimize :inline t) \"Shorthand for (DECLARE (OPTIMIZE ...)).\" `(declare (optimize ,quality)))", "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 optimize*) (quote (:alias optimize :inline t))) (defmacro optimize* (quality) \"Shorthand for (DECLARE (OPTIMIZE ...)).\" (sb-int:quasiquote (declare (optimize #S(sb-impl::comma :expr quality :kind 0))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-op (:distinct unary-splicing-op))\n\nPattern to recognize: Macro call that should be transformed by define-op", "input": "(define-op (:distinct unary-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 (distinct-op (:include unary-splicing-op (name \"DISTINCT\")) (:constructor make-distinct-op (var))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(drelet 'some-name)\n\nIssue: 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": "Create a Common Lisp macro for the following transformation. Before code:\n(sum x :to total)\n\nWhat needs to change: Macro call that should be transformed by sum", "input": "(sum x :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": "(collect x :into total)", "category": "dsl", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(\u03bb)\n\nProblem: Macro call that should be transformed by \u039b", "input": "(\u03bb)", "output": "(defmacro \u039b ...)", "macroexpand": "(lambda (&optional \u03b1) (cond))", "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) (when (funcall predicate g) (yield g)))\n\nPattern to recognize: Macro call that should be transformed by do-generator", "input": "(do-generator (g generator) (when (funcall predicate g) (yield 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 ((#:g163 generator)) (loop do (if-generator ((g) #:g163) (progn (when (funcall predicate g) (yield g))) (return))))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "intermediate", "quality_score": 0.85} {"instruction": "Generate a defmacro form that transforms code like this:\n(defpattern plist (&rest args) `(and ,@(loop for (key . value) in (plist-alist args) collect `(property ,key ,value))))\n\nPattern to recognize: Macro call that should be transformed by defpattern", "input": "(defpattern plist (&rest args) `(and ,@(loop for (key . value) in (plist-alist args) collect `(property ,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 plist (quote &rest) (quote args) (lambda (quasiquote (and #S(sb-impl::comma :expr (loop for (key . value) in (plist-alist args) collect (quasiquote (property #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": "Generate a defmacro form that transforms code like this:\n(defun/1 tmpnam (str) (let ((newname (string-to-char* (symbol-name (gensym))))) (if (eql str NULL) newname (progn (replace str newname :end1 (length newname)) str))))\n\nPattern to recognize: Macro call that should be transformed by defun/1", "input": "(defun/1 tmpnam (str) (let ((newname (string-to-char* (symbol-name (gensym))))) (if (eql str NULL) newname (progn (replace str newname :end1 (length newname)) str))))", "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 tmpnam (str) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (let ((newname (string-to-char* (symbol-name (gensym))))) (if (eql str null) newname (progn (replace str newname :end1 (length newname)) str)))) (defparameter tmpnam (vacietis.c:mkptr& (symbol-function (quote tmpnam)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(when (eql (top-sign) 'skip-first-attribute) (pop-sign))\n\nIssue: Macro call that should be transformed by when", "input": "(when (eql (top-sign) 'skip-first-attribute) (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-attribute)) (pop-sign))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(lambda-ignoring-_ (dspecs inits _t) (finalize-decl-specs dspecs) `(,dspecs ,(mapcar (lambda (i) (finalize-init-declarator dspecs i)) inits)))\n\nIssue: Macro call that should be transformed by lambda-ignoring-_", "input": "(lambda-ignoring-_ (dspecs inits _t) (finalize-decl-specs dspecs) `(,dspecs ,(mapcar (lambda (i) (finalize-init-declarator dspecs i)) inits)))", "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 inits _t) (declare (ignore _t)) (finalize-decl-specs dspecs) (sb-int:quasiquote (#S(sb-impl::comma :expr dspecs :kind 0) #S(sb-impl::comma :expr (mapcar (lambda (i) (finalize-init-declarator dspecs i)) inits) :kind 0))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(enable-quasi-quoted-bivalent-to-bivalent-emitting-form-syntax 'some-name)\n\nWrite a macro that addresses: 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 'some-name)", "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\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 \"biv\")\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defclause until (condition) \"Specifies a termination clause for the loop. When, at the beginning of an iteration, the clause evaluates to true, the loop stops.\" (make-termination :condition condition))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause until (condition) \"Specifies a termination clause for the loop. When, at the beginning of an iteration, the clause evaluates to true, the loop stops.\" (make-termination :condition 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 until (condition) \"Specifies a termination clause for the loop. When, at the beginning of an iteration, the clause evaluates to true, the loop stops.\" (make-termination :condition condition)) (pushnew (quote until) *clauses*))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(fgathering nil\n nil)\n\nProblem: Macro call that should be transformed by FGATHERING", "input": "(fgathering nil\n nil)", "output": "(defmacro FGATHERING ...)", "macroexpand": "(flet ()\n nil\n (values))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defmethod* nil :key nil)\n\nIssue: Macro call that should be transformed by DEFMETHOD*", "input": "(defmethod* nil :key nil)", "output": "(defmacro DEFMETHOD* ...)", "macroexpand": "(let* ((#:nil129 (ensure-generic*-function 'nil))\n (temp-method (defmethod #:nil128 nil))\n (actual-gf\n (ensure-generic*-function 'nil :lambda-list\n (sb-mop:generic-function-lambda-list\n (symbol-function '#:nil128))\n :special-variables 'nil))\n (actual-method\n (add-method* #:nil129\n (make-instance 'method* :special-variables (list)\n :qualifiers '(:key) :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 #:nil129)\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(acond ((= 1 2) :no) (nil :nono) (t :yes))\n\nProblem: Macro call that should be transformed by acond", "input": "(acond ((= 1 2) :no) (nil :nono) (t :yes))", "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 (= 1 2))) (if #:it (let ((it #:it)) (declare (ignorable it)) :no) (acond (nil :nono) (t :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-accumulation-binding maximizing (var form &key key) (let ((result (gensym \"RESULT\"))) `(let ((,result ,form)) (when (or (not ,var) (< ,(if key `(funcall ,key ,var) var) ,(if key `(funcall ,key ,result) result))) (setf ,var ,result)))))\n\nWhat needs to change: Macro call that should be transformed by define-accumulation-binding", "input": "(define-accumulation-binding maximizing (var form &key key) (let ((result (gensym \"RESULT\"))) `(let ((,result ,form)) (when (or (not ,var) (< ,(if key `(funcall ,key ,var) var) ,(if key `(funcall ,key ,result) result))) (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 maximizing (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 var :kind 0))) 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))) (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(symbol-value-in-$instance nil nil)\n\nProblem: Macro call that should be transformed by SYMBOL-VALUE-IN-$INSTANCE", "input": "(symbol-value-in-$instance nil nil)", "output": "(defmacro SYMBOL-VALUE-IN-$INSTANCE ...)", "macroexpand": "(slot-value nil nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7675} {"instruction": "Generate a defmacro form that transforms code like this:\n(define-modf-rewrite caaadr (expr) `(car (caadr ,(second expr))))\n\nPattern to recognize: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite caaadr (expr) `(car (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 caaadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (caadr #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(defobject nil)\n\nWrite a macro that addresses: Macro call that should be transformed by DEFOBJECT", "input": "(defobject nil)", "output": "(defmacro DEFOBJECT ...)", "macroexpand": "(object :parents (list) :properties (list))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(collect-plist nil nil)\n\nProblem: Macro call that should be transformed by COLLECT-PLIST", "input": "(collect-plist nil nil)", "output": "(defmacro COLLECT-PLIST ...)", "macroexpand": "(common-lisp:let* ((#:generator-190 (generator nil))\n #:values-183\n (#:generator-188 (generator nil))\n #:indicators-182\n (#:plist-184 nil))\n (declare (type generator #:generator-190)\n (type generator #:generator-188)\n (type list #:plist-184))\n (tagbody\n #:ll-191\n (setq #:values-183 (next-in #:generator-190 (go end)))\n (setq #:indicators-182 (next-in #:generator-188 (go end)))\n (setq #:plist-184 (list* #:indicators-182 #:values-183 #:plist-184))\n (go #:ll-191)\n end)\n #:plist-184)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"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": "Write a Common Lisp macro to handle this code pattern:\n(with-reader-case nil)\n\nProblem: Macro call that should be transformed by WITH-READER-CASE", "input": "(with-reader-case nil)", "output": "(defmacro WITH-READER-CASE ...)", "macroexpand": "(let ()\n (let ((#:previous-case178 (readtable-case *readtable*)))\n (setf (readtable-case *readtable*) nil)\n (unwind-protect (progn)\n (setf (readtable-case *readtable*) #:previous-case178))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(with-*test-dribble* nil (explain! (run 'is1)))\n\nWrite a macro that addresses: Macro call that should be transformed by with-*test-dribble*", "input": "(with-*test-dribble* nil (explain! (run 'is1)))", "output": "(defmacro with-*test-dribble* (stream &body body)\n `(let ((*test-dribble* ,stream))\n (declare (special *test-dribble*))\n ,@body))", "macroexpand": "(let ((*test-dribble* nil)) (declare (special *test-dribble*)) (explain! (run (quote is1))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Generate a defmacro form that transforms code like this:\n(mvlet* nil\n (progn))\n\nPattern to recognize: 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": "Write a Common Lisp macro to handle this code pattern:\n(matrix-etypecase 'some-name)\n\nProblem: Macro call that should be transformed by MATRIX-ETYPECASE", "input": "(matrix-etypecase 'some-name)", "output": "(defmacro MATRIX-ETYPECASE ...)", "macroexpand": "(let ((#:g246 quote))\n (etypecase #:g246))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(o> (progn (decf test-calls-left) (< *flow-value* iterations)) (-> nil (value) (1+ value)))\n\nIssue: Macro call that should be transformed by o>", "input": "(o> (progn (decf test-calls-left) (< *flow-value* iterations)) (-> nil (value) (1+ value)))", "output": "(defmacro o> (condition &body body)\n \"See flow:repeatedly\"\n `(repeatedly ,condition\n ,@body))", "macroexpand": "(repeatedly (progn (decf test-calls-left) (< *flow-value* iterations)) (-> nil (value) (1+ value)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(builder (:backtrace :result-on-error (lambda (condition) (if (typep condition 'test-error) '(503 (:content-type \"text/plain\") (\"Service Temporary Unavailable\")) '(500 (:content-type \"text/plain\") (\"Internal Server Error\"))))) (lambda (env) (if (string= (getf env :path-info) \"/503\") (error 'test-error) (error \"Error occured\"))))\n\nIssue: Macro call that should be transformed by builder", "input": "(builder (:backtrace :result-on-error (lambda (condition) (if (typep condition 'test-error) '(503 (:content-type \"text/plain\") (\"Service Temporary Unavailable\")) '(500 (:content-type \"text/plain\") (\"Internal Server Error\"))))) (lambda (env) (if (string= (getf env :path-info) \"/503\") (error 'test-error) (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 (#:app194) (funcall (find-middleware :backtrace) #:app194 :result-on-error (lambda (condition) (if (typep condition (quote test-error)) (quote (503 (:content-type \"text/plain\") (\"Service Temporary Unavailable\"))) (quote (500 (:content-type \"text/plain\") (\"Internal Server Error\"))))))))) :initial-value (to-app (lambda (env) (if (string= (getf env :path-info) \"/503\") (error (quote test-error)) (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(c-assert fm)\n\nPattern to recognize: Macro call that should be transformed by c-assert", "input": "(c-assert fm)", "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 (c-break \"failed assertion: ~a\" (quote fm))))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.885} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-hook-type number->number (function (number) number) \"Hook taking a number and returning a number.\")\n\nIssue: Macro call that should be transformed by define-hook-type", "input": "(define-hook-type number->number (function (number) number) \"Hook taking a number and returning a number.\")", "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-number->number (hook) ((handler-type :initform (quote (function (number) number)) :allocation :class)) (:metaclass sb-mop:funcallable-standard-class) (:documentation \"Hook taking a number and returning a number.\"))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(multiple-value-bind (form expanded) (macroexpand-1 form *env*) (cond (expanded (e form)) (t (typecase form (null nil) (list (let ((next (compiler-macroexpand-1 form))) (if (eq form next) (handle form) (e next)))) (t `',form)))))\n\nWrite a macro that addresses: Macro call that should be transformed by m", "input": "(multiple-value-bind (form expanded) (macroexpand-1 form *env*) (cond (expanded (e form)) (t (typecase form (null nil) (list (let ((next (compiler-macroexpand-1 form))) (if (eq form next) (handle form) (e next)))) (t `',form)))))", "output": "(defmacro m (form &environment *env*)\n (e form))", "macroexpand": "(multiple-value-call (function (lambda (&optional form expanded &rest #:ignore) (declare (ignore #:ignore)) (cond (expanded (e form)) (t (typecase form (null nil) (list (let ((next (compiler-macroexpand-1 form))) (if (eq form next) (handle form) (e next)))) (t (sb-int:quasiquote (quote #S(sb-impl::comma :expr form :kind 0))))))))) (macroexpand-1 form *env*))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(fmap f (funcall p1 next))\n\nWhat needs to change: Macro call that should be transformed by fmap", "input": "(fmap f (funcall p1 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) (funcall p1 next) (if (failure? res) (fail next) (values (funcall f res) next)))", "category": "anaphoric", "technique": "anaphor", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(make-instance* 'class (shortcuts) nil)\n\nIssue: Macro call that should be transformed by make-instance*", "input": "(make-instance* 'class (shortcuts) 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) :shortcuts shortcuts nil)", "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-op (:case conjunctive-op))\n\nProblem: Macro call that should be transformed by define-op", "input": "(define-op (:case 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 (case-op (:include conjunctive-op (name \"CASE\")) (:constructor make-case-op (&rest expressions))))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(define-error invalid-context-symbols () (symbols) \"Sorry but the following symbols are not valid as a context specifiers: ~{~s~^ ~}\" symbols)\n\nIssue: Macro call that should be transformed by define-error", "input": "(define-error invalid-context-symbols () (symbols) \"Sorry but the following symbols are not valid as a context specifiers: ~{~s~^ ~}\" symbols)", "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-symbols (:error-type varjo-error :prefix \"Varjo\") (symbols) \"Sorry but the following symbols are not valid as a context specifiers: ~{~s~^ ~}\" symbols)", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-test emergency-dependency :depends-on (:not bad-dependency) (true \"ALARM!!\"))\n\nWrite a macro that addresses: Macro call that should be transformed by define-test", "input": "(define-test emergency-dependency :depends-on (:not bad-dependency) (true \"ALARM!!\"))", "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 emergency-dependency) (find-package #A((9) base-char . \"PARACHUTE\"))) (ensure-test (quote test) :name (quote emergency-dependency) :home (find-package #A((9) base-char . \"PARACHUTE\")) :tests (list (lambda nil (true \"ALARM!!\"))) :parent (quote nil) (quote :depends-on) (quote (:not bad-dependency)))) (quote emergency-dependency))", "category": "dsl", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(define-op (:in infix-list-op))\n\nProblem: Macro call that should be transformed by define-op", "input": "(define-op (: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 (in-op (:include infix-list-op (name \"IN\")) (:constructor make-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(defclause (counting expr &optional into var result-type (type 'fixnum)) \"Increment a variable if expression is non-nil\" (return-reduction-code :identity 0 :operation '(subst (var expr) (1+ var)) :expression nil :test expr :variable var :type type :accum-kind :increment))\n\nWrite a macro that addresses: Macro call that should be transformed by defclause", "input": "(defclause (counting expr &optional into var result-type (type 'fixnum)) \"Increment a variable if expression is non-nil\" (return-reduction-code :identity 0 :operation '(subst (var expr) (1+ var)) :expression nil :test expr :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-counting-9 (&key ((:counting expr)) ((:into var)) ((:result-type type) (quote fixnum))) \"Increment a variable if expression is non-nil\" (return-reduction-code :identity 0 :operation (quote (subst (var expr) (1+ var))) :expression nil :test expr :variable var :type type :accum-kind :increment)) (install-clause-info (quote (counting)) (quote (counting &optional :into :result-type)) (quote clause-counting-9) \"Increment a variable if expression is non-nil\" nil) (quote (counting expr &optional into var result-type (type (quote fixnum)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8049999999999999} {"instruction": "Generate a defmacro form that transforms code like this:\n(integer-writer 4)\n\nPattern to recognize: Macro call that should be transformed by integer-writer", "input": "(integer-writer 4)", "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-int4 write-uint4)) (defun write-uint4 (socket value) (declare (type stream socket) (type (unsigned-byte 32) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 24) value) socket) (write-byte (ldb (byte 8 16) value) socket) (write-byte (ldb (byte 8 8) value) socket) (write-byte (ldb (byte 8 0) value) socket) (values)) (defun write-int4 (socket value) (declare (type stream socket) (type (signed-byte 32) value) (optimize (speed 3) (safety 0) (space 1) (debug 1) (compilation-speed 0))) (write-byte (ldb (byte 8 24) value) socket) (write-byte (ldb (byte 8 16) value) socket) (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": "Define a macro that eliminates this repetitive pattern:\n(c-assert (member old-kid (kids fm-parent)) () \"~&oldkid ~s not amongst kids of its fm-parent ~s\" old-kid fm-parent)\n\nIssue: Macro call that should be transformed by c-assert", "input": "(c-assert (member old-kid (kids fm-parent)) () \"~&oldkid ~s not amongst kids of its fm-parent ~s\" old-kid 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 (member old-kid (kids fm-parent)) (c-break \"~&oldkid ~s not amongst kids of its fm-parent ~s\" old-kid fm-parent)))", "category": "control-flow", "technique": "nested-backquote", "complexity": "advanced", "quality_score": 0.9375} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(c? (* 2 (width self)))\n\nIssue: Macro call that should be transformed by c?", "input": "(c? (* 2 (width 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 ((* 2 (width self)))) :value-state :unevaluated :rule (c-lambda (* 2 (width self))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"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": "Write a Common Lisp macro to handle this code pattern:\n(define-modf-rewrite cddadr (expr) `(cdr (cdadr ,(second expr))))\n\nProblem: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cddadr (expr) `(cdr (cdadr ,(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 cddadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (cdadr #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 cdadr (expr) `(cdr (cadr ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite cdadr (expr) `(cdr (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 cdadr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (cdr (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(class/std stub slot1 slot2 slot3 slot4 slot5)\n\nWrite a macro that addresses: Macro call that should be transformed by class/std", "input": "(class/std stub slot1 slot2 slot3 slot4 slot5)", "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 stub nil ((slot1 slot2 slot3 slot4 slot5)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defdata either (left t) (right t))\n\nIssue: Macro call that should be transformed by defdata", "input": "(defdata either (left t) (right t))", "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 (either (:constructor nil) (:copier nil) (:predicate nil) (:include algebraic-data-type))) (progn (defstruct (left (:include either) (:constructor left (%0)) (:conc-name left) (:copier nil) (:predicate nil) (:print-function (lambda (#:object-137 #:stream-138 #:depth-139) (declare (ignore #:depth-139) (ignorable #:object-137)) (when *print-adt-readably* (write-string \"#.\" #:stream-138)) (write-char #\\LEFT_PARENTHESIS #:stream-138) (prin1 (quote left) #:stream-138) (write-char #\\Space #:stream-138) (prin1 (left%0 #:object-137) #:stream-138) (write-char #\\RIGHT_PARENTHESIS #:stream-138)))) #A((49) base-char . \"A component of ADT CL-ALGEBRAIC-DATA-TYPE::EITHER\") (%0 (error \"Unspecified field.\") :type t :read-only t)) (declaim (sb-ext:freeze-type left)) (defmethod make-load-form ((#:object-137 left) &optional #:environment-140) (make-load-form-saving-slots #:object-137 :slot-names (quote (%0)) :environment #:environment-140))) (progn (defstruct (right (:include either) (:constructor right (%0)) (:conc-name right) (:copier nil) (:predicate nil) (:print-function (lambda (#:object-137 #:stream-138 #:depth-139) (declare (ignore #:depth-139) (ignorable #:object-137)) (when *print-adt-readably* (write-string \"#.\" #:stream-138)) (write-char #\\LEFT_PARENTHESIS #:stream-138) (prin1 (quote right) #:stream-138) (write-char #\\Space #:stream-138) (prin1 (right%0 #:object-137) #:stream-138) (write-char #\\RIGHT_PARENTHESIS #:stream-138)))) #A((49) base-char . \"A component of ADT CL-ALGEBRAIC-DATA-TYPE::EITHER\") (%0 (error \"Unspecified field.\") :type t :read-only t)) (declaim (sb-ext:freeze-type right)) (defmethod make-load-form ((#:object-137 right) &optional #:environment-140) (make-load-form-saving-slots #:object-137 :slot-names (quote (%0)) :environment #:environment-140))) (quote either))", "category": "anaphoric", "technique": "gensym,anaphor", "complexity": "advanced", "quality_score": 0.825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-cache (\"foo\" :expire 2 :store storage) 2)\n\nWhat needs to change: Macro call that should be transformed by with-cache", "input": "(with-cache (\"foo\" :expire 2 :store storage) 2)", "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 ((#:key257 \"foo\") (#:store258 storage) (#:expire259 2)) (multiple-value-bind (#:value260 #:exists-p261) (getcache #:key257 #:store258) (if #:exists-p261 #:value260 (let ((#:value260 (progn 2))) (setcache #:key257 #:value260 #:store258 :expire #:expire259) #:value260))))", "category": "anaphoric", "technique": "once-only,gensym,anaphor,recursive-expansion", "complexity": "advanced", "quality_score": 0.85} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(set-data pt (rect y x))\n\nWrite a macro that addresses: Macro call that should be transformed by set-data", "input": "(set-data pt (rect y x))", "output": "(defmacro set-data (obj (name &rest new-values))\n \"Mutate the fields of the ADT value OBJ whose constructor is NAME\nand whose updated values are NEW-VALUES based on order. If the symbol\n'_' is used as a value, that field is not updated. Trailing '_' may be\nomitted.\"\n (let ((once (gensym \"ONCE\")))\n `(let ((,once ,obj))\n (psetf\n ,@(loop :for i :from 0\n :for x :in new-values\n :when (not (wild? x))\n :append (list `(,(field name i) ,once)\n x))))))", "macroexpand": "(let ((#:once145 pt)) (psetf (rect%0 #:once145) y (rect%1 #:once145) x))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Generate a defmacro form that transforms code like this:\n(defcategory :info (or :info :notice))\n\nPattern to recognize: Macro call that should be transformed by defcategory", "input": "(defcategory :info (or :info :notice))", "output": "(defmacro defcategory (category &optional expands-as set)\n `(defcategory-fn ',category ',expands-as ,set))", "macroexpand": "(defcategory-fn (quote :info) (quote (or :info :notice)) 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(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-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 (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-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 #:g126 :in specialized-lambda-list :if (listp #:g126) :collect #:g126 :else :collect (list #:g126 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 (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": "Define a macro that eliminates this repetitive pattern:\n(some-<>> nil :key nil)\n\nIssue: Macro call that should be transformed by SOME-<>>", "input": "(some-<>> nil :key nil)", "output": "(defmacro SOME-<>> ...)", "macroexpand": "(let* ((#:g133 nil)\n (#:g133\n (if (null #:g133)\n nil\n (:key #:g133))))\n (if (null #:g133)\n nil\n (->> #:g133 nil)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(insert-char-class-tester (char-class (schar *string* start-pos)) (lambda (start-pos) (declare (fixnum start-pos)) (and (< start-pos *end-pos*) (char-class-test) (funcall next-fn (1+ start-pos)))))\n\nWrite a macro that addresses: Macro call that should be transformed by insert-char-class-tester", "input": "(insert-char-class-tester (char-class (schar *string* start-pos)) (lambda (start-pos) (declare (fixnum start-pos)) (and (< start-pos *end-pos*) (char-class-test) (funcall next-fn (1+ start-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-class155 char-class)) (let ((#:test-function156 (test-function #:char-class155))) (lambda (start-pos) (declare (fixnum start-pos)) (and (< start-pos *end-pos*) (funcall #:test-function156 (schar *string* start-pos)) (funcall next-fn (1+ start-pos))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(gatherer 'some-name)\n\nIssue: Macro call that should be transformed by GATHERER", "input": "(gatherer 'some-name)", "output": "(defmacro GATHERER ...)", "macroexpand": "(common-lisp:let ((#:lastcons-452 (list nil)) #:lst-453)\n (declare (type cons #:lastcons-452)\n (type list #:lst-453))\n (setq #:lst-453 #:lastcons-452)\n (common-lisp:let (#:out-455)\n #'(lambda (#:items-451 result-p)\n (cond\n ((null result-p)\n (tagbody\n (setq #:lastcons-452\n (setf (cdr #:lastcons-452) (cons #:items-451 nil)))))\n (t\n (progn\n (setq #:lst-453 (cdr #:lst-453))\n (setq #:out-455\n (common-lisp:funcall 'some-name\n (common-lisp:funcall #'scan\n #:lst-453))))\n #:out-455)))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(*let nil\n :key\n nil)\n\nWhat needs to change: Macro call that should be transformed by *LET", "input": "(*let nil\n :key\n nil)", "output": "(defmacro *LET ...)", "macroexpand": "(let* ()\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-store-entry (key store :quiet quiet) (when (item key store) (trc \"overwriting item\" key (item key store))) (setf (item key store) object))\n\nWhat needs to change: Macro call that should be transformed by with-store-entry", "input": "(with-store-entry (key store :quiet quiet) (when (item key store) (trc \"overwriting item\" key (item key store))) (setf (item key store) object))", "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 (when (item key store) (trc \"overwriting item\" key (item key store))) (setf (item key store) object)) (unless quiet (kick-c-link key store)))", "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-value (s (value ratio) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~v$\" *float-format-precision* value))\n\nWhat needs to change: Macro call that should be transformed by make-stream-method", "input": "(make-stream-method pp-xml-value (s (value ratio) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~v$\" *float-format-precision* value))", "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-value ((s stream) (value ratio) &optional colon-p at-p) (declare (ignore colon-p at-p)) (format s \"~v$\" *float-format-precision* value)))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(class/std example slot1 slot2 slot3)\n\nIssue: Macro call that should be transformed by class/std", "input": "(class/std example slot1 slot2 slot3)", "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 example nil ((slot1 slot2 slot3)))", "category": "control-flow", "technique": "recursive-expansion", "complexity": "advanced", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(builder (:backtrace :result-on-error `(500 (:content-type \"text/plain\") (\"Internal Server Error\"))) (lambda (env) (if (string= (getf env :path-info) \"/error\") (error \"Error occured\") '(200 () (\"ok\")))))\n\nPattern to recognize: Macro call that should be transformed by builder", "input": "(builder (:backtrace :result-on-error `(500 (:content-type \"text/plain\") (\"Internal Server Error\"))) (lambda (env) (if (string= (getf env :path-info) \"/error\") (error \"Error occured\") '(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 (lambda (#:app190) (funcall (find-middleware :backtrace) #:app190 :result-on-error (sb-int:quasiquote (500 (:content-type \"text/plain\") (\"Internal Server Error\"))))))) :initial-value (to-app (lambda (env) (if (string= (getf env :path-info) \"/error\") (error \"Error occured\") (quote (200 nil (\"ok\")))))) :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(dynenv-macrolet nil)\n\nWhat needs to change: Macro call that should be transformed by DYNENV-MACROLET", "input": "(dynenv-macrolet nil)", "output": "(defmacro DYNENV-MACROLET ...)", "macroexpand": "(macrolet nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(action (:after node-application) #'rewrite-direct-application)\n\nWhat needs to change: Macro call that should be transformed by action", "input": "(action (:after node-application) #'rewrite-direct-application)", "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 rewrite-direct-application))", "category": "control-flow", "technique": "", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(defun-advisable nil\n nil)\n\nIssue: Macro call that should be transformed by DEFUN-ADVISABLE", "input": "(defun-advisable nil\n nil)", "output": "(defmacro DEFUN-ADVISABLE ...)", "macroexpand": "(let ((#:oldfn134\n (handler-case (symbol-function 'nil) (undefined-function nil nil))))\n (defun nil ())\n (make-advisable 'nil :arguments 'nil)\n (when\n (and #:oldfn134\n (not (eql (advisable-function-arguments #:oldfn134) :not-provided))\n (equal (advisable-function-arguments #:oldfn134) 'nil))\n (copy-advice #:oldfn134 (symbol-function 'nil))))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(ematch0 (remove-if-not (curry #'eq symbol) slots :key #'c2mop:slot-definition-name) ((list) (when slots (simple-style-warning \"Found slots ~{~s~^, ~} but they are not EQ to ~s.\" (mapcar #'c2mop:slot-definition-name slots) symbol))) ((list slot) (return slot)))\n\nIssue: Macro call that should be transformed by ematch0", "input": "(ematch0 (remove-if-not (curry #'eq symbol) slots :key #'c2mop:slot-definition-name) ((list) (when slots (simple-style-warning \"Found slots ~{~s~^, ~} but they are not EQ to ~s.\" (mapcar #'c2mop:slot-definition-name slots) symbol))) ((list slot) (return slot)))", "output": "(defmacro ematch0 (what &body clauses)\n `(match0 ,what\n ,@clauses\n (_ (error \"level0 match error!\"))))", "macroexpand": "(match0 (remove-if-not (curry (function eq) symbol) slots :key (function sb-mop:slot-definition-name)) ((list) (when slots (simple-style-warning \"Found slots ~{~s~^, ~} but they are not EQ to ~s.\" (mapcar (function sb-mop:slot-definition-name) slots) symbol))) ((list slot) (return slot)) (_ (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(make-$instance nil)\n\nWhat needs to change: Macro call that should be transformed by MAKE-$INSTANCE", "input": "(make-$instance nil)", "output": "(defmacro MAKE-$INSTANCE ...)", "macroexpand": "(let ((class (symbol-value nil)))\n (funcall (mcs-slot-value class (index-of-basicnew-fn)) class))", "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 ((quot rem) (ftruncate x)) (check-wcs-math-result) (values rem quot))\n\nWrite a macro that addresses: Macro call that should be transformed by with-wcs-math-error-handling", "input": "(with-wcs-math-error-handling ((quot rem) (ftruncate x)) (check-wcs-math-result) (values rem quot))", "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* ((#:g233 x) (#:g234 nil) (#:g235 (list #:g233))) (declare (ignorable #:g234) (type list #:g235) (dynamic-extent #:g235)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (quot rem) (call-with-wcs-math-error-handler (quote ftruncate) #:g235) (flet ((check-wcs-math-result (&optional (ret quot) (arg-list #:g235)) (check-wcs-math-result ret arg-list))) (check-wcs-math-result) (values rem quot)))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(drelet* nil\n (progn))\n\nProblem: 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(deferror \"42710\" duplicate-object syntax-error-or-access-violation)\n\nPattern to recognize: Macro call that should be transformed by deferror", "input": "(deferror \"42710\" duplicate-object 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-object (syntax-error-or-access-violation) nil) (setf (gethash \"42710\" *error-table*) (quote duplicate-object)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.875} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(is 'foo 'foo \"Foo with multiline description!\")\n\nWrite a macro that addresses: Macro call that should be transformed by is", "input": "(is 'foo 'foo \"Foo with multiline description!\")", "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 ((#:expected194 (quote foo))) (let* ((#:new-args192 (list \"Foo with multiline description!\")) (#:desc193 (parse-description-and-test #:new-args192))) (with-catching-errors (:description #:desc193 :expected #:expected194) (with-duration ((#:duration190 #:result191) (quote foo)) (test #:result191 #:expected194 #:new-args192 :duration #:duration190)))))", "category": "capture-management", "technique": "once-only,gensym", "complexity": "intermediate", "quality_score": 0.875} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(-> :one :ignore-invariant t () (increment))\n\nProblem: 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": "Create a Common Lisp macro for the following transformation. Before code:\n(*> +comma+ +skip-space+)\n\nWhat needs to change: Macro call that should be transformed by *>", "input": "(*> +comma+ +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 (#:*>-offset233) (multiple-value-bind (#:*>-res234 #:*>-next235) (funcall +comma+ #:*>-offset233) (if (ok? #:*>-res234) (funcall +skip-space+ #:*>-next235) (fail #:*>-next235))))", "category": "control-flow", "technique": "gensym", "complexity": "advanced", "quality_score": 0.8724999999999999} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> :g (a) (+ a 4))\n\nIssue: Macro call that should be transformed by ->", "input": "(-> :g (a) (+ a 4))", "output": "(defmacro -> (invariant &body args)\n \"See flow:atomically\"\n `(atomically ,invariant ,@args))", "macroexpand": "(atomically :g (a) (+ a 4))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.8225} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(defstore example (&key (a 1) (b (the number (init-b a)))))\n\nWrite a macro that addresses: Macro call that should be transformed by defstore", "input": "(defstore example (&key (a 1) (b (the number (init-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 (a #:a?158) (declare (ignorable a #:a?158)) (the number (init-b a))) (ensure-store (quote example) (quote (&key (a 1 #:a?158) (b (the number (a-init-function152 a #:a?158)) #:b?159))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.9249999999999999} {"instruction": "You are a Common Lisp macro expert. Given this code pattern:\n(define-option-expander packages (module &rest names) (setf (module-packages module) names))\n\nWrite a macro that addresses: Macro call that should be transformed by define-option-expander", "input": "(define-option-expander packages (module &rest names) (setf (module-packages module) names))", "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 ((#:type142 (eql :packages)) module #:args141) (destructuring-bind (&rest names) #:args141 (setf (module-packages module) names)))", "category": "control-flow", "technique": "gensym", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Generate a defmacro form that transforms code like this:\n(defstore example (&optional (a (init-a)) (b a)))\n\nPattern to recognize: Macro call that should be transformed by defstore", "input": "(defstore example (&optional (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?153) (declare (ignorable a #:a?153)) a) (ensure-store (quote example) (quote (&optional (a (the t (a-init-function152)) #:a?153) (b (the t (b-init-function154 a #:a?153)) #:b?155))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Generate a defmacro form that transforms code like this:\n(def-launched-iter nil\n :key\n nil)\n\nPattern to recognize: Macro call that should be transformed by DEF-LAUNCHED-ITER", "input": "(def-launched-iter nil\n :key\n nil)", "output": "(defmacro DEF-LAUNCHED-ITER ...)", "macroexpand": "(defun nil :key\n (let ((it\n (make-instance 'iterator :coro\n (lambda-coro\n nil))))\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(with* 'some-name)\n\nProblem: Macro call that should be transformed by WITH*", "input": "(with* 'some-name)", "output": "(defmacro WITH* ...)", "macroexpand": "(multiple-value-bind (quote) nil (multiple-value-bind (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(collect-last nil (progn))\n\nWrite a macro that addresses: Macro call that should be transformed by COLLECT-LAST", "input": "(collect-last nil (progn))", "output": "(defmacro COLLECT-LAST ...)", "macroexpand": "(common-lisp:let* ((#:generator-525 (generator nil))\n #:items-519\n (#:item-521 (progn)))\n (declare (type generator #:generator-525)\n (type (null-or t) #:item-521))\n (tagbody\n #:ll-526\n (setq #:items-519 (next-in #:generator-525 (go end)))\n (setq #:item-521 #:items-519)\n (go #:ll-526)\n end)\n #:item-521)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(loop)\n\nWhat needs to change: Macro call that should be transformed by LOOP", "input": "(loop)", "output": "(defmacro LOOP ...)", "macroexpand": "(block nil (tagbody #:g190 (progn) (go #:g190)))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"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": "(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(and)\n\nWrite a macro that addresses: Macro call that should be transformed by AND", "input": "(and)", "output": "(defmacro AND ...)", "macroexpand": "t", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.6825} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(defsynonym nil nil)\n\nWhat needs to change: Macro call that should be transformed by DEFSYNONYM", "input": "(defsynonym nil nil)", "output": "(defmacro DEFSYNONYM ...)", "macroexpand": "(eval-when (:compile-toplevel :load-toplevel :execute)\n (setf (get 'nil 'iterate::synonym) 'nil))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Define a macro that eliminates this repetitive pattern:\n(-> 'some-name)\n\nIssue: 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(in-compile-time nil\n nil)\n\nPattern to recognize: Macro call that should be transformed by IN-COMPILE-TIME", "input": "(in-compile-time nil\n nil)", "output": "(defmacro IN-COMPILE-TIME ...)", "macroexpand": "(macrolet ((#:macro142 (&environment ())\n nil))\n (#:macro142))", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defgenerator chain (&rest generators) \"Chains a number of generators together head to tail. Eg: (chain (list->generator '(1 2 3) (list->generator '(6 7))) -> 1 2 3 6 7\" (dolist (g generators) (yield-all g)))\n\nPattern to recognize: Macro call that should be transformed by defgenerator", "input": "(defgenerator chain (&rest generators) \"Chains a number of generators together head to tail. Eg: (chain (list->generator '(1 2 3) (list->generator '(6 7))) -> 1 2 3 6 7\" (dolist (g generators) (yield-all 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 chain (&rest generators) \"Chains a number of generators together head to tail. Eg: (chain (list->generator '(1 2 3) (list->generator '(6 7))) -> 1 2 3 6 7\" (with-yield (dolist (g generators) (yield-all g))))", "category": "dsl", "technique": "", "complexity": "intermediate", "quality_score": 0.9125} {"instruction": "Write a Common Lisp macro to handle this code pattern:\n(iterate 'some-name)\n\nProblem: Macro call that should be transformed by ITERATE", "input": "(iterate 'some-name)", "output": "(defmacro ITERATE ...)", "macroexpand": "(common-lisp:let* ((#:generator-265 (generator nil))\n #:m-259\n (#:generator-263 (generator nil))\n #:m-260)\n (declare (type generator #:generator-265)\n (type generator #:generator-263))\n (tagbody\n #:ll-266\n (setq #:m-259 (next-in #:generator-265 (go end)))\n (setq #:m-260 (next-in #:generator-263 (go end)))\n ((lambda (quote some-name)) #:m-260 #:m-259)\n (go #:ll-266)\n end)\n nil)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(producing 'some-name)\n\nPattern to recognize: Macro call that should be transformed by PRODUCING", "input": "(producing 'some-name)", "output": "(defmacro PRODUCING ...)", "macroexpand": "(non-opt-producing 'some-name)", "category": "control-flow", "technique": "", "complexity": "basic", "quality_score": 0.7525} {"instruction": "Generate a defmacro form that transforms code like this:\n(defun/1 ceil (x) (ceiling x))\n\nPattern to recognize: Macro call that should be transformed by defun/1", "input": "(defun/1 ceil (x) (ceiling 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 ceil (x) (declare (optimize (speed 0) (debug 3) (sb-ext:inhibit-warnings 3))) (ceiling x)) (defparameter ceil (vacietis.c:mkptr& (symbol-function (quote ceil)))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.86} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(define-modf-rewrite ninth (expr) `(car (cddddr (cddddr ,(second expr)))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite ninth (expr) `(car (cddddr (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 ninth) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (cddddr (cddddr #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(defstore nhadamard-product (y x &key (a 1)))\n\nIssue: Macro call that should be transformed by defstore", "input": "(defstore nhadamard-product (y x &key (a 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 nhadamard-product) (quote (y x &key (a 1 #:a?151))))))", "category": "anaphoric", "technique": "anaphor", "complexity": "advanced", "quality_score": 0.8875} {"instruction": "Create a Common Lisp macro for the following transformation. Before code:\n(with-wcs-math-error-handling (ret (fceiling 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 (fceiling 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* ((#:g242 x) (#:g243 nil) (#:g244 (list #:g242))) (declare (ignorable #:g243) (type list #:g244) (dynamic-extent #:g244)) (catch (quote return-from-with-wcs-math-error-handling) (multiple-value-bind (ret) (call-with-wcs-math-error-handler (quote fceiling) #:g244) (flet ((check-wcs-math-result (&optional (ret ret) (arg-list #:g244)) (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(define-modf-rewrite caaddr (expr) `(car (caddr ,(second expr))))\n\nWhat needs to change: Macro call that should be transformed by define-modf-rewrite", "input": "(define-modf-rewrite caaddr (expr) `(car (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 caaddr) *modf-rewrites*) (lambda (expr) (sb-int:quasiquote (car (caddr #S(sb-impl::comma :expr (second expr) :kind 0)))))))", "category": "control-flow", "technique": "", "complexity": "intermediate", "quality_score": 0.9125}