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 8771699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:51:19+00:00 2026-06-13T17:51:19+00:00

I’m attempting to write my first anaphoric macro and am running into a problem.

  • 0

I’m attempting to write my first anaphoric macro and am running into a problem. I am using sblc and slime.

When the anaphoric macro is expanded in another package its symbols are prefixed with the package it was defined in (i.e. they become tjb-utilities::value instead of just value. What is going on?

PE> (macroexpand-1 '(act-if-key :pcram (get-node) (print value)))
(IF (HAS-KEY? :PCRAM (GET-NODE))
    (LET ((TJB-UTILITIES::KEY :PCRAM)
          (TJB-UTILITIES::VALUE (GETHASH :PCRAM (GET-NODE))))
      (PRINT VALUE)))

This is the macro definition:

(defmacro act-if-key (key hashtable &body body)
  `(if (has-key? ,key ,hashtable) 
       (let ((key ,key) (value (gethash ,key ,hashtable)))
     ,@body)))

It does work correclty if I prefix the value:

(act-if-key :pcram (get-node) (print tjb-utilities::value))
; in: ACT-IF-KEY :PCRAM
;     (LET ((TJB-UTILITIES::KEY :PCRAM)
;           (TJB-UTILITIES::VALUE
;            (GETHASH :PCRAM (PHILOSOPHY-EXPERIENCE::GET-NODE))))
;       (PRINT TJB-UTILITIES::VALUE))
; 
; caught STYLE-WARNING:
;   The variable TJB-UTILITIES::KEY is defined but never used.
; 
; compilation unit finished
;   caught 1 STYLE-WARNING condition

"hello" 
"hello"

The packages are defined as follows:

(defpackage #:tjb-utilities
  (:nicknames :tjb)
  (:use #:cl)
  (:export "HAS-KEY?" "KEY-VALUE-PAIRS" "ACT-IF-KEY" "TJB-MAKE-HASH-TABLE"))

(defpackage #:my-package
  (:nicknames :pe)
  (:use #:cl #:clsql #:tjb-utilities))

Update: Changing the key in the lambda list to key_in has no effect

(defmacro act-if-key (key_in hashtable &body body)
  `(if (has-key? ,key_in ,hashtable) 
       (let ((key ,key_in) (value (gethash ,key_in,hashtable)))
     ,@body)))
  • 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-06-13T17:51:21+00:00Added an answer on June 13, 2026 at 5:51 pm
    CL-USER> (in-package #:tjb)
    #<PACKAGE "TJB-UTILITIES">
    TJB> (defmacro act-if-key (key hashtable &body body)
           (let ((value (intern "VALUE")))
             `(if (has-key? ,key ,hashtable) 
                  (let ((key ,key) (,value (gethash ,key ,hashtable)))
                    ,@body))))
    ACT-IF-KEY
    TJB> (macroexpand-1 '(tjb:act-if-key :pcram (get-node) (print value)))
    (IF (HAS-KEY? :PCRAM (GET-NODE))
        (LET ((KEY :PCRAM) (VALUE (GETHASH :PCRAM (GET-NODE))))
          (PRINT VALUE)))
    T
    TJB> (in-package #:cl-user)
    #<PACKAGE "COMMON-LISP-USER">
    CL-USER> (macroexpand-1 '(tjb:act-if-key :pcram (get-node) (print value)))
    (IF (TJB-UTILITIES::HAS-KEY? :PCRAM (GET-NODE))
        (LET ((TJB-UTILITIES::KEY :PCRAM) (VALUE (GETHASH :PCRAM (GET-NODE))))
          (PRINT VALUE)))
    T
    CL-USER> 
    

    Not sure if I copied all that you needed, and I’m a tad blur on how did you intend to use the “key”, so I did it only for the value in the way it will be created in the package, where the macro is used. You’d figure it for yourself whether you need the same for the key or not.

    The above bind the symbol value in the current package to whatever gethash will return. In your original version you have key supplied by the user of the macro, so I decided you didn’t want a symbol key inside the macro, just it’s value.

    But wait a bit, perhaps there will be a better answer, maybe you can just make-symbol it instead of interning and then bind it somehow. I’m not sure.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.