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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:45:20+00:00 2026-06-18T05:45:20+00:00

I am learning how to use higher-order functions in scheme. I get the idea

  • 0

I am learning how to use higher-order functions in scheme. I get the idea of using higher-order functions, however I am having trouble using them. For this learning exercise, I would prefer to only use some combination of filter, fold, and/or map.

For example, I want to construct the set difference between two lists call them A and B. I am defining set difference as x such that x is an element of A but x is not an element of B. I only want to use the functions map, filter and fold. For example:

Let A = (1 8 6 2)

Let B = (5 7 9 1 6)

The set difference of A and B would be (8 2)

The idea is to construct a new list by iterating over the elements of A and seeing if an element of A equals an element of B, if so don’t add a to the new list; otherwise add a to the new list.

My algorithm idea goes something like this:

Let neq be “not equal to”

  1. For each a in A and b in B evaluate the expression: (neq? a b)

    For a = 1 we have:

    (and (neq? 1 5) (neq? 1 7) (neq? 1 9) (neq? 1 1) (neq ? 1 6))

  2. If this expression is true then a goes in the new list; otherwise don’t add a to the new list. In our example (neq? 1 1) evaluates to false and so we do not add 1 to the new list.

Pretty much my entire procedure relies on 1, and this is where I have a trouble.

  1. How do I do step 1?
  2. I see that in step 1 I need some combination of the map and fold functions, but how do I get the and a neq b distributed?

EDIT This is the closest sample I have:

(fold-right (trace-lambda buggy (a b c) (and (neq? a b))) #t A B)
|(buggy 3 5 #t)
|#t
|(buggy 2 4 #t)
|#t
|(buggy 1 1 #t)
|#f
#f

The above shows a trace of my anonymous function attempting to perform the (and (neq? a b)) chain. However, it only performs this on elements in A and B at the same position/index.

All help is greatly appreciated!

  • 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-18T05:45:22+00:00Added an answer on June 18, 2026 at 5:45 am

    A simplified version of member is easy to implement using fold, of course:

    (define (member x lst)
      (fold (lambda (e r)
              (or r (equal? e x)))
            #f lst))
    

    Now, with that, the rest is trivial:

    (define (difference a b)
      (filter (lambda (x)
                (not (member x b)))
              a))
    

    If you want to amalgamate all that into one function (using your neq?), you can do:

    (define (difference a b)
      (filter (lambda (x)
                (fold (lambda (e r)
                        (and r (neq? e x)))
                      #t b))
              a))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning to use the PHP interactive shell, but I'm having trouble with multi-line
I'm learning to use F# to build WPF applications. I using this as reference.
I'm learning to use ImageMagick, but I'm having trouble when I try to generate
I am learning to use xmlhttprequest/AJAX. In this sample code from w3schools, I do
I am learning to use Rcpp via Hadley's tutorial here . However, when I
I am currently learning to use Audio Queue Services in iOS. For this, I
I am having trouble finding a good place to start learning assembly. I have
I am learning to use the allegro library right now and when using the
I learning to use Pointers. I have a few questions about an exercise code
I'm learning to use xlib and I'm unable to get XChangeProperty() to work for

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.