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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:39:42+00:00 2026-06-15T20:39:42+00:00

I’ve been wracking my brain on a scheme problem for the last couple days

  • 0

I’ve been wracking my brain on a scheme problem for the last couple days that involves creating a procedure with message passing that keeps track of a list of friends, and can then manipulate that list to change the value of a specific friend to online or offline. If the person that is put in is a friend, it returns true. If they haven’t been added yet, it returns false. It can also show the list of friends that are online, and another list of the ones that you have. Basically, the idea is to make something of a changeable Facebook tracker. It responds to 4 inputs: ‘add, ‘toggle-status, ‘get-online-friends, and ‘get-friends.

This is what I’ve managed to get so far:

(define (sort-strings lst)
    (sort lst string<?))

(define (make-facebook-list)
(let ((T '()))
(define (dispatch x)
  (define (add-person name)
(set! T (cons (cons name #f) T)) 
'done)
  (define (online? friend)
(eq? friend #t))
  (define (toggle-status! name)
(begin ;(if () (set! T (cons (cons name #t) T)))
  (if (member name T)
      (set-cdr! T (cons (cons name (not (cdr name)) T))))
  (if (member name T) #t #f)))
  (define (get-online-friends!)
(sort-strings (filter online? T)))
  (define (get-friends!)
(sort-strings T))
  (cond ((eq? x 'add) add-person)
    ((eq? x 'toggle-status) toggle-status!)
    ((eq? x 'get-online-friends) (get-online-friends!))
    ((eq? x 'get-friends) (get-friends!))
    (else (error "Unknown Request" x))))
dispatch))

And these are the test cases that I’m using:

(define my-lst (make-facebook-list))
(display ((my-lst 'add) "Francis"))(newline) ; should return 'done
(display ((my-lst 'add) "Adrian"))(newline) ; should return 'done
(display ((my-lst 'add) "Zule"))(newline) ;  should return 'done
(display ((my-lst 'add) "Geralt"))(newline) ; should return 'done
(display ((my-lst 'add) "Dexter"))(newline) ; should return 'done
(display ((my-lst 'add) "Leonidas"))(newline) ; should return 'done
(display ((my-lst 'toggle-status) "Leonidas"))(newline) ; should return #t
(display ((my-lst 'toggle-status) "Francis"))(newline) ; should return #t
(display ((my-lst 'toggle-status) "Zule"))(newline) ; should return #t
(display ((my-lst 'toggle-status) "Xavier"))(newline) ; should return #f
(display (my-lst 'get-online-friends))(newline) ; should return ("Francis" "Leonidas" "Zule")
(display (my-lst 'get-friends)) ; should return ("Adrian" "Dexter" "Francis" "Geralt" "Leonidas" "Zule")

I know that they won’t all work right now, which is why I commented out some of the procedures. The one I’m trying to get to run correctly is the the procedure that toggles the status to online or offline. I’ve been led to believe that “member” is used to check if a certain value is a part of a list.A m I going about this the wrong way?

NOTE: the sort-strings procedure is meant to be used with the procedures that return a list of friends, so as to keep them in alphabetical order.

  • 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-06-15T20:39:43+00:00Added an answer on June 15, 2026 at 8:39 pm

    Your friend is begin, which forces the following expressions to be evaluated sequentially:

    (define (make-facebook-list)
      (define T '())
      (define (dispatch x)
        (lambda (fl)
          (cond ((eq? x 'add) 
                 (begin
                   (set! T (append T (list fl)))
                   'done))
                (else 'invalid))))
      dispatch)
    
    scheme@(guile-user)> (define my-lst (make-facebook-list))
    scheme@(guile-user)> ((my-lst 'add) "Francis")
    $1 = done
    

    Edit

    (define (make-facebook-account)
      (let ((*facebook-friends* '()))
        (define (sort-alphabetically sequence)
          (sort-list sequence string<?))
        (define (friend name)
          (assoc name *facebook-friends*))
        (define (friends-name friend)
          (car friend))
        (define (friends-status friend)
          (cdr friend))
        (define (online? friend)
          (eq? (friends-status friend) #t))
        (define (friend-on-facebook? name)
          (if (member (friend name)
                      *facebook-friends*)
              #t #f))
        (define (add-person! name)
          (begin
            (set! *facebook-friends*
                  (cons (cons name #f)
                        *facebook-friends*))
            'done))
        (define (toggle-status! name)
          (if (friend-on-facebook? name)
              (begin
               (set-cdr! (friend name)
                          (if (online? (friend name))
                              #f #t))
               'done)
              (error
               "Person no friend on facebook -- TOGGLE-STATUS!" name)))
        (define (get-friends table)
          (sort-alphabetically
           (map friends-name table)))
        (define (get-online-friends table)
          (get-friends
           (filter online? table)))
        (define (dispatch m)
          (cond ((eq? m 'add!) add-person!)
                ((eq? m 'toggle-status!) toggle-status!)
                ((eq? m 'get-friends)
                 (get-friends *facebook-friends*))
                ((eq? m 'get-online-friends)
                 (get-online-friends *facebook-friends*))
                ((eq? m 'friend-on-facebook?) friend-on-facebook?)
                (else
                 (error "Unknown request -- DISPATCH" m))))
        dispatch))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I've tracked down a weird MySQL problem to the two different ways I was

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.