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

  • Home
  • SEARCH
  • 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 142227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:54:10+00:00 2026-05-11T07:54:10+00:00

Could any CL’er please explain ‘slots’ in CLOS? I am finding it difficult to

  • 0

Could any CL’er please explain ‘slots’ in CLOS? I am finding it difficult to understand the part after the slot name. That is in :

(defclass foo () (data1 :initarg foo))

What do the ‘initarg’ and other such similar things mean? I am re-reading manuals. So, I would really appreciate if any of you here could explain it to a layman like me.

Thanks!

  • 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. 2026-05-11T07:54:11+00:00Added an answer on May 11, 2026 at 7:54 am

    Your example is slightly wrong. It has to be:

    (defclass foo ()    ((data1 :initarg foo))) 

    Notice the added parentheses to indicate a list of slot descriptions.

    DEFCLASS takes a list of slots. So with two slots we have:

    (defclass foo ()    ((data1 :initarg :data1arg            :initform (random 1.0)             :type number            :documentation 'doc here'            :accessor foo-data1-acc)     (data2 :initarg :data2arg))) 

    DATA1 is the name of the slot. Behind that you find pairs of :keyword value.

    :INITARG tells you what the parameter for MAKE-INSTANCE is. (make-instance ‘foo :data1arg 10) ; creates the object and sets the slot data1 to 10. Usually you should use a keyword symbol (like :data1arg here).

    :INITFORM sets the slot by default, when the object is created. Like in: (make-instance ‘foo) ; creates the object. The slot is set to the value of the initform.

    :TYPE specifies the type of the slot’s object.

    :DOCUMENTATION is just a string for, well, documentation.

    :ACCESSOR specifies a function to read and write the slot.

    (foo-data1-acc some-foo-object-here)             ; read (setf (foo-data1-acc some-foo-object-here) 7)    ; write 

    Note that you can write the pairs in any order and that you can also specify multiple accessor functions. There are also :READER and :WRITER functions.

    With CLOS you can specify all that within the DEFCLASS macro. These things are not automatically generated like in defstruct, which has a shorter notation.

    The description of DEFCLASS is here: DEFCLASS. Short CLOS Intro.

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

Sidebar

Related Questions

Could any one give an explanation on how a DHT works? Nothing too heavy,
Could someone recommend any good resources for creating Graphics User Interfaces, preferably in C/C++?
I could not find any pointers on how to create a menubar icon on
I'm doing something bad in my ASP.NET app. It could be the any number
What would be the best way to resize images, which could be of any
Is there any way that I could get the source of a website (as
Are there any good professional associations for IT Managers that I could join and
Does anybody know of any sample databases I could download, preferably in CSV or
I could only find the function confirm() that gives OK/Cancel buttons. Is there any
Any recommendations for a javascript form validation library. I could try and roll my

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.