Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6188519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:14:44+00:00 2026-05-24T02:14:44+00:00

I want to do a macro in common lisp which is supposed to take

  • 0

I want to do a macro in common lisp which is supposed to take in one of its arguments a list made of slots and strings. Here is the prototype :

(defclass time-info ()
  ((name :initarg name)
   (calls :initarg calls)
   (second :initarg second)
   (consing :initarg consing)
   (gc-run-time :initarg gc-run-time)))

(defun print-table (output arg-list time-info-list) ())

The idea is to print a table based on the arg-list which defines its structure. Here is an example of a call to the function:

(print-table *trace-output*
             '("|" name "||" calls "|" second "\")
             my-time-info-list)

This print a table in ascII on the trace output. The problem, is that I don’t know how to explicitely get the elements of the list to use them in the different parts of my macro.

I have no idea how to do this yet, but I’m sure it can be done. Maybe you can help me 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:14:45+00:00Added an answer on May 24, 2026 at 2:14 am

    I would base this on format. The idea is to build a format string
    from your arg-list.

    I define a helper function for that:

    (defun make-format-string-and-args (arg-list)
      (let ((symbols ()))
        (values (apply #'concatenate 'string
                       (mapcar (lambda (arg)
                                 (ctypecase arg
                                   (string 
                                    (cl-ppcre:regex-replace-all "~" arg "~~"))
                                   (symbol
                                    (push arg symbols)
                                    "~a")))
                               arg-list))
                (nreverse symbols))))
    

    Note that ~ must be doubled in format strings in order to escape them.

    The printing macro itself then just produces a mapcar of format:

    (defmacro print-table (stream arg-list time-info-list)
      (let ((time-info (gensym)))
        (multiple-value-bind (format-string arguments)
            (make-format-string-and-args arg-list)
          `(mapcar (lambda (,time-info)
                     (format ,stream ,format-string
                             ,@(mapcar (lambda (arg)
                                         (list arg time-info))
                                       arguments)))
                   ,time-info-list)))
    

    You can then call it like this:

    (print-table *trace-output*
                 ("|" name "||" calls "|" second "\\")
                 my-time-info-list)
    

    Please note the following errors in your code:

    • You need to escape \ in strings.

    • Second is already a function name exported from the common-lisp
      package. You should not clobber that with a generic function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a subroutine into my Word 2007 macro that will take
Why would anyone prefer Scheme macros over Common Lisp macros (and I genuinely want
i want a macro to consolidate the data form multiple sheets to one sheet..
In Common-Lisp CLOS Is it possible to dynamically add one more super class in
I want to create a macro whose argument is optional. If not specified, the
I want a debug function-macro that works like this: int myVar = 5; PRINTVAR(myVar);
I want to create a C macro that creates a function with a name
I want to connect to DB2 from excel macro...This is my code, but it
I have CSV file and Macro in VBA. I want to open CSV file
I've created latex macro to typeset guitar chords diagrams(using picture environment). Now I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.