Paste number 23866: The real example

Index of paste annotations: 1 | 2 | 3 | 4

Paste number 23866: The real example
Pasted by: ignas
2 years, 4 months ago
#lisp
Paste contents:
Raw Source | XML | Display As
(test (make-field)
  (is (equal (macroexpand-1
              '(make-field (s s _ _)
                           (_ s s _)
                           (_ _ _ _)
                           (_ _ b b)
                           (_ _ b b)
                           (_ _ _ _)
)
)

             '(make-field-stub `((,s ,s ,_ ,_)
                                 (,_ ,s ,s ,_)
                                 (,_ ,_ ,_ ,_)
                                 (,_ ,_ ,b ,b)
                                 (,_ ,_ ,b ,b)
                                 (,_ ,_ ,_ ,_)
)
)
)
)
)

Annotations for this paste:

Annotation number 1: the code that does the job
Pasted by: ignas
2 years, 4 months ago
Paste contents:
Raw Source | Display As
(defmacro make-field (&rest contents)
  `(make-field-stub (list
                     ,@(loop for row in contents
                          collect `(list ,@(loop for cell in row
                                              collect cell
)
)
)
)
)
)


(test (make-field)
  (is (equal (macroexpand-1
              '(make-field (s s _ _)
                           (_ s s _)
                           (_ _ _ _)
                           (_ _ b b)
                           (_ _ b b)
                           (_ _ _ _)
)
)

             '(make-field-stub (list (list s s _ _)
                                     (list _ s s _)
                                     (list _ _ _ _)
                                     (list _ _ b b)
                                     (list _ _ b b)
                                     (list _ _ _ _)
)
)
)
)
)

Annotation number 2: ignas, this should do the same
Pasted by: attila
2 years, 4 months ago
Paste contents:
Raw Source | Display As
;;; should do the same, although the list variant is more
;;; readable in this situation, imho
(test (make-field)
  (is (equal (macroexpand-1
              '(make-field (s s _ _)
                           (_ s s _)
                           (_ _ _ _)
                           (_ _ b b)
                           (_ _ b b)
                           (_ _ _ _)
)
)

             '`(make-field-stub ((,s ,s ,_ ,_)
                                 (,_ ,s ,s ,_)
                                 (,_ ,_ ,_ ,_)
                                 (,_ ,_ ,b ,b)
                                 (,_ ,_ ,b ,b)
                                 (,_ ,_ ,_ ,_)
)
)
)
)
)

Annotation number 3: the real thing this time
Pasted by: attila
2 years, 4 months ago
Paste contents:
Raw Source | Display As
(defmacro make-field (&rest contents)
  `(make-field-stub `(,@,(loop for row in contents
                          collect `(,@(loop for cell in row
                                              collect cell
)
)
)
)
)
)

Annotation number 4: ignas, a bit simplified
Pasted by: attila
2 years, 4 months ago
Paste contents:
Raw Source | Display As
;;; the inner backquoting was unnecessary

(defmacro make-field (&rest contents)
  `(make-field-stub `(,@,(loop for row in contents
                          collect (loop for cell in row
                                              collect cell
)
)
)
)
)

Colorize as:
Show Line Numbers
Index of paste annotations: 1 | 2 | 3 | 4

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.