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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:30:07+00:00 2026-05-28T14:30:07+00:00

I have a list of objects in scheme as described below. How is it

  • 0

I have a list of objects in scheme as described below. How is it possible to call objects functions when for example taking the first element out of the list?

(define persons false)
(define length 10)

(let loop ((n 0))
    (if (< n length)
        (begin
            (define newp (make-person))
            (send newp setage (- 50 n))

            (cond
                 ((= n 0)
                        (set! persons (list newp)))
                 (else
                        (set! persons (cons persons newp)))
            )

            (loop (+ n 1))
        )
     )
 )

 (define (firstpersonage)
     (send (car persons) getage)
 )

When calling the firstpersonage I am getting error message that there is no such method. Is there way to “cast” the first object to be “person” type?

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. Editorial Team
    Editorial Team
    2026-05-28T14:30:08+00:00Added an answer on May 28, 2026 at 2:30 pm

    First, please do learn to indent Lisp correctly.

    Second, your problem is that you’ve decided to use a pile of side effects to construct a list of people in Scheme (and as a consequence, you tripped over one of the finer points of
    list construction).

    What I would do in this situation is write

    (define persons
      (map (lambda (n)
             (let ((newp (make-person)))
               (send newp setage (- 50 n))
               newp))
           (iota 10)))
    
    (define (firstpersonage)
      (send (car persons) getage))
    

    That is, define person to be the list of ten people of descending ages from 50 to 41. Doing it this way avoids the possibility for many bugs, including the one you just got bitten by.

    If you absolutely, positively can’t bear to part with your set!s, the error seems to be in the line

    (set! persons (cons persons newp))
    

    cons doesn’t append two lists, it adds a new element to the head of a list. For example

    (cons 3 (list 2 1)) => (3 2 1)
    

    If you do it in the reverse way, you won’t quite get what you’re looking for

    (cons (list 1 2) 3) => ((1 2) . 3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have List where myObj has it own list of objects called example mySubObj.
I have a list of elements around 1000. Each element (objects that i read
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have 2 List objects: List<int> lst1 = new List<int>(); List<int> lst2 = new
I have a list of objects and I want to remove all the ones
I have a list of objects: [Object_1, Object_2, Object_3] Each object has an attribute:
I have a list of objects (mainly int, string, double) And I would like
I have a list of objects which uses paging in my home > index.cshtml.
I have a list of custom objects List and I would like to update
I have a list of objects that have two int properties. The list is

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.