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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:45:50+00:00 2026-05-30T01:45:50+00:00

I have a very simple data structure that I have defined in Lisp: ;;Data

  • 0

I have a very simple data structure that I have defined in Lisp:

;;Data structure for a person

(defstruct person
  (name nil)
  (age 0)
  (siblings nil :type list))   ;; Siblings is a list of person objects

I then procede to instantiate a few person objects:

(setf person-a (make-person :name 'Tim :age 23))
(setf person-b (make-person :name 'Sally :age 21))
(setf person-c (make-person :name 'Louis :age 24))

I then relate the siblings (assume they are all siblings of each other):

(setf (person-siblings person-a) (list person-b person-c))
(setf (person-siblings person-b) (list person-a person-c))
(setf (person-siblings person-c) (list person-b person-a))

How can I then print information about the objects that i’ve instantiated and modified? I have looked into the options of a defstruct with regard to print-object and print-function but I cannot figure out how to properly print my objects. Using something like:

(print person-a)

sends my ACL interpreter into an infinite loop.

  • 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-30T01:45:51+00:00Added an answer on May 30, 2026 at 1:45 am

    Common lisp has a variable that controls the printing of recursive structures: *print-circle*. In your Lisp it may be false (nil) by default (as it is in SBCL and clisp – I’m not familiar with ACL), which is probably causing the infinite loop. If you set it to t, your structures should print:

    (setf *print-circle* t)
    

    I tested this with the following file:

    (defstruct person
      (name nil)
      (age 0)
      (siblings nil :type list))
    
    (setf person-a (make-person :name 'Tim :age 23))
    (setf person-b (make-person :name 'Sally :age 21))
    (setf person-c (make-person :name 'Louis :age 24))
    
    (setf (person-siblings person-a) (list person-b person-c))
    (setf (person-siblings person-b) (list person-a person-c))
    (setf (person-siblings person-c) (list person-a person-b))
    
    (setf *print-circle* t)
    (format t "~a~&" person-a)
    (format t "~a~&" person-b)
    (format t "~a~&" person-c)
    
    (print person-a)
    (print person-b)
    (print person-c)
    

    Here is a transcript from running that code:

    > sbcl
    This is SBCL 1.0.55, an implementation of ANSI Common Lisp.
    More information about SBCL is available at <http://www.sbcl.org/>.
    
    SBCL is free software, provided as is, with absolutely no warranty.
    It is mostly in the public domain; some portions are provided under
    BSD-style licenses.  See the CREDITS and COPYING files in the
    distribution for more information.
    * (load "defstruct.lisp")
    
    #1=#S(PERSON
            :NAME TIM
            :AGE 23
            :SIBLINGS (#2=#S(PERSON
                             :NAME SALLY
                             :AGE 21
                             :SIBLINGS (#1#
                                        #3=#S(PERSON
                                              :NAME LOUIS
                                              :AGE 24
                                              :SIBLINGS (#1# #2#))))
                       #3#))
    #1=#S(PERSON
          :NAME SALLY
          :AGE 21
          :SIBLINGS (#2=#S(PERSON
                           :NAME TIM
                           :AGE 23
                           :SIBLINGS (#1#
                                      #3=#S(PERSON
                                            :NAME LOUIS
                                            :AGE 24
                                            :SIBLINGS (#2# #1#))))
                     #3#))
    #1=#S(PERSON
          :NAME LOUIS
          :AGE 24
          :SIBLINGS (#2=#S(PERSON
                           :NAME TIM
                           :AGE 23
                           :SIBLINGS (#3=#S(PERSON
                                            :NAME SALLY
                                            :AGE 21
                                            :SIBLINGS (#2# #1#))
                                      #1#))
                     #3#))
    
    #1=#S(PERSON
          :NAME TIM
          :AGE 23
          :SIBLINGS (#2=#S(PERSON
                           :NAME SALLY
                           :AGE 21
                           :SIBLINGS (#1#
                                      #3=#S(PERSON
                                            :NAME LOUIS
                                            :AGE 24
                                            :SIBLINGS (#1# #2#))))
                     #3#)) 
    #1=#S(PERSON
          :NAME SALLY
          :AGE 21
          :SIBLINGS (#2=#S(PERSON
                           :NAME TIM
                           :AGE 23
                           :SIBLINGS (#1#
                                      #3=#S(PERSON
                                            :NAME LOUIS
                                            :AGE 24
                                            :SIBLINGS (#2# #1#))))
                     #3#)) 
    #1=#S(PERSON
          :NAME LOUIS
          :AGE 24
          :SIBLINGS (#2=#S(PERSON
                           :NAME TIM
                           :AGE 23
                           :SIBLINGS (#3=#S(PERSON
                                            :NAME SALLY
                                            :AGE 21
                                            :SIBLINGS (#2# #1#))
                                      #1#))
                     #3#)) 
    T
    * (sb-ext:quit)
    

    If I leave *print-circle* nil, then I get a stack overflow error (SB-KERNEL::CONTROL-STACK-EXHAUSTED in sbcl).

    HTH,

    Kyle

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

Sidebar

Related Questions

Say you have a very simple data structure: (personId, name) ...and you want to
I have an abstract data type that points to a concrete data type structure.
I am using Delphi 2009. I have a very simple data structure, with 2
I have a very simple WPF application in which I am using data binding
i have very simple problem. I need to create model, that represent element of
I have a very simple bit of script that changes the status of an
I have a very simple Java RMI Server that looks like the following: import
I have a very simple ASP.Net page that acts as a front end for
I have a large data structure that is using striping to reduce lock contention.
Below is a very simple bit of code that mimics a class structure in

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.