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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:00:54+00:00 2026-05-28T18:00:54+00:00

The following code does what I want: 1 (defclass some-class () 2 ((some-slot 3

  • 0

The following code does what I want:

 1 (defclass some-class ()
 2   ((some-slot
 3       :initarg :somearg
 4       :initform (error ":somearg not specified"))))
 5 (defparameter *alpha* (make-instance 'some-class :somearg 3))
 6 (defparameter *beta*  (make-instance 'some-class :somearg 5))
 7 (defparameter *gamma* (make-instance 'some-class :somearg 3))
 8 (princ (slot-value *beta* 'some-slot)) (terpri)
 9 (defparameter *delta* (list *alpha* *beta* *gamma*))
10 (princ *delta*) (terpri)
11 (princ (remove-duplicates *delta*
12          :test #'equal
13          :key (lambda (x) (slot-value x 'some-slot))))
14 (terpri)
5
(#<SOME-CLASS #x21C1D71E> #<SOME-CLASS #x21C1DAFE> #<SOME-CLASS #x21C1DC3E>)
(#<SOME-CLASS #x21C1DAFE> #<SOME-CLASS #x21C1DC3E>)

But is there a way to do this without having to write the function on line 13? Is there a shorthand way to specify as the key a slot value in the class instance?

The following blows up with a syntax error, of course, but it gives the general idea of what I’m seeking.

 1 (princ (remove-duplicates *delta*
 2          :test #'equal
 3          :key '(slot-value 'some-slot)))
 4 (terpri)
*** - FUNCALL: (SLOT-VALUE 'SOME-SLOT) is not a function name; try using a
      symbol instead
  • 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-28T18:00:55+00:00Added an answer on May 28, 2026 at 6:00 pm

    You could try a :reader or :accessor.

    Doing

    (defclass some-class ()
      ((some-slot
        :initarg :somearg :reader some-slot
        :initform (error ":somearg not specified"))))
    

    should let you re-write lines 11 through 13 as

    (princ (remove-duplicates *delta* :test #'equal :key #'some-slot))
    

    That is, (some-slot x) is equivalent to (slot-value x 'some-slot) if the slot in question has a reader/accessor.


    After-Sleep Edit:

    You also don’t need to bother setting :initform to error; a slot will do that by default if you don’t specify a default value and someone tries to read it. If you don’t want the error, you do something like :initform nil. Check out this excellent CLOS tutorial as well as chapters 16 and 17 of Practical Common Lisp for more information about objects in Common Lisp.

    Also, in the future if you have working code that you’d like style advice on, do check out codereview.stackexchange. There’s a small, but active population of Lisp reviewers.

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

Sidebar

Related Questions

The following code does not want to compile. See the included error message. Code:
The following code does not compile: public class GenericsTest { public static void main(String[]
The following code does not compile, saying error C2248: 'A::getMe' : cannot access private
The following code does not compile: #include <iostream> class Foo { std::string s; public:
The following code does not output hello world I do not want to use
The following Code does not compile Dim BasicGroups As String() = New String() {Node1,
The following code does not run as rootNode is null when retrieved by name
The following code does not set the comment: string userName = yrtre.etre.423369a9-3e57-42da-934d-dae91f87a1e4; MembershipUser user
The following code does not give a warning with g++ 4.1.1 and -Wall .
The following code does not submit the input values: $('.button').live('click', function() { var date

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.