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 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 help me understand the below code. Please help me how it
Could any one please tell me the meaning of ++ with array in the
Could any one explain me how to create a text file using php where
Could any explain the following meaning of TextBlock.Text and Binding Path? <TextBlock> <TextBlock.Text> <Binding
could any one please help us to retrieve data from incoming message in blackberry
Could any body explain, when to use TempData ViewBag ViewData I have a requirement,
What is difference between setFlags and addFlags for intent. Could any one explain it
Could any one explain me how to get to know the calling convention of
could any explain me how to load the virtual keyboard for banking applications?
I'm developing a windows form application. Could any one please advise what are the

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.