Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

form-fiddle

1.1.0

A collection of utilities to destructure lambda forms.

About Form-Fiddle

Often times I need to destructure a form definition in a macro. This is a set of simple utilities to help with that.

How To

There's individual functions to extract each part of a lambda-definition-form: function, name, qualifiers, lambda-list, body, declarations, docstring and the forms. You can get all in one with split-lambda-form, or directly as a binding macro with with-destructured-lambda-form.

(split-lambda-form '(defun lambda-body (lambda-form)
                      (cddr lambda-form)))

(with-destructured-lambda-form (:forms forms)
    '(defmacro foo (bar)
       (declare (ignore bar))
       "Testing macro!"
       (print "test!"))
  forms)

See Also

Package Index

  • FORM-FIDDLE (ORG.SHIRAKUMO.FORM-FIDDLE)

    • function (

      LAMBDA-BODY

      LAMBDA-FORM)
      Returns all BODY forms of the lambda-form.
      
                                               |¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯v¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
       (function [name] qualifier* lambda-list [[docstring? | declaration*]] form*)
    • function (

      LAMBDA-DECLARATIONS

      LAMBDA-FORM)
      Returns the DECLARATIONS of the lambda-form, if any.
      
                                                                   v
       (function [name] qualifier* lambda-list [[docstring? | declaration*]] form*)
    • function (

      LAMBDA-DOCSTRING

      LAMBDA-FORM)
      Returns the DOCSTRING of the lambda-form, if any.
      
                                                     v
       (function [name] qualifier* lambda-list [[docstring? | declaration*]] form*)
    • function (

      LAMBDA-FORMS

      LAMBDA-FORM)
      Returns the actual body forms of the lambda-form, if any.
      
                                                                               v
       (function [name] qualifier* lambda-list [[docstring? | declaration*]] form*)
    • function (

      LAMBDA-FUNCTION

      LAMBDA-FORM)
      Returns the defining FUNCTION of the lambda-form.
           v
       (function [name] qualifier* lambda-list [[docstring? | declaration*]] form*)
    • function (

      LAMBDA-LAMBDA-LIST

      LAMBDA-FORM)
      Returns the LAMBDA-LIST of the lambda-form.
      
                                        v
       (function [name] qualifier* lambda-list [[docstring? | declaration*]] form*)
    • function (

      LAMBDA-NAME

      LAMBDA-FORM)
      Returns the NAME of the lambda-form, if any.
      
                   v
       (function [name] qualifier* lambda-list [[docstring? | declaration*]] form*)
    • function (

      LAMBDA-QUALIFIERS

      LAMBDA-FORM)
      Returns the QUALIFIERS of the lambda-form.
      
                            v
       (function [name] qualifier* lambda-list [[docstring? | declaration*]] form*)
    • function (

      SPLIT-BODY-OPTIONS

      BODY)
      Parses the body into two separate lists of forms and options.
      This is found in some expressions like in the clause body of RESTART-CASE.
      
      BODY   ::= OPTION* FORM*
      OPTION ::= KEYWORD EXPRESSION
    • function (

      SPLIT-LAMBDA-FORM

      LAMBDA-FORM)
      Returns all parts of a lambda-form as a list in the following order:
       FUNCTION NAME QUALIFIERS LAMBDA-LIST DOCSTRING DECLARATIONS FORMS
    • macro (

      WITH-BODY-OPTIONS

      (BODY OTHER-OPTIONS &REST OPTIONS) FORM &BODY BODY-FORMS)
      Destructures the body according to split-body-kargs.
      
      OTHER-OPTIONS will be bound to contain all the options that occur in the body but
      were not explicitly requested in OPTIONS. BODY will be bound to the remaining
      body forms. Each option in OPTIONS can be either a symbol or a list of symbol and
      default. The symbol is automatically converted to a keyword to match against the
      body options.
    • macro (

      WITH-DESTRUCTURED-LAMBDA-FORM

      (&KEY FUNCTION NAME QUALIFIERS LAMBDA-LIST DOCSTRING DECLARATIONS FORMS) EXPRESSION &BODY BODY)
      Destructures the given EXPRESSION into its lambda-form parts.