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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:23:46+00:00 2026-05-26T17:23:46+00:00

Function manageFirstList should recursively copy one element at the time to global list x.

  • 0

Function manageFirstList should recursively copy one element at the time to global list x.

(define test1DataA '(("a" "a") ("b" "b") ("c" "c") ("d" "d") ("e" "ok")))
(define test1DataB '(("a" "aa") ("b" "bb") ("c" "cc") ("d" "dd") ("ok" "Ir OK!")))

(define x '())

(define manageFirstList
  (lambda (a b)  
    ((cond ((not (null? b))
            ((append x (car a))
             (manageFirstList (cdr a) b)))))))

(define ff (lambda (a b) (manageFirstList a b)))

(ff test1DataA test1DataB)

But it causes an error:

car: expects argument of type <pair>; given '()

Questions are:

  1. How do I update global value `x’?
  2. How do I concatenate lists the right way?
  3. Can I call more than 1 function (or is there a workaround) like this:

    ((append x (car a))
     (manageFirstList (cdr a) b))
    

EDIT: What I’m trying to do is to create a list with first value of each test1DataA list item and second value of each test1DataB list item, where test1DataA list element second value is the same as test1DataB first value of its list element.

  • 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-26T17:23:46+00:00Added an answer on May 26, 2026 at 5:23 pm

    About your questions:

    1. Although you can update a global variable from within a function using (set! x <value>), you really shouldn’t, that’s not the preferred way to program using Scheme; instead you should return a new list from your procedure and if necessary, assign the returned value to x afterwards
    2. What do you mean by “the right way”? the append procedure concatenates two lists, that’s the right way to do it, if you ask me 🙂 . You simply call it like this: (append a b), where both a and b must be lists
    3. The code is wrong, because you’re surrounding the call to append between an extra pair of parenthesis, Scheme will try to apply the value returned by (append ...) as if it were a procedure with arguments (manageFirstList (cdr a) b), and obviously it’s going to fail, since append returns a list, not a procedure. And maybe you should explain exactly what do you mean with “can I call more than 1 function” – of course you can, but what do you intend to do? combine the results from both calls? process the results independently?

    Anyway, the above procedure is going to fail for several reasons – you’re not considering the cases when the lists are null, you’re only recurring on one of the lists, etc.

    Finally, your should make clear what is the expected result from the procedure, after calling it with (ff test1DataA test1DataB), what is the value you want to see in x? write it as part of your question, since the text “recursively copy one element at the time to global list x” is not clear enough.

    Edit:

    Ok, here’s my shot at answering your question, I hope I understood you correctly. Notice that I’m using the assoc procedure for searching each second-value in the first list, in the second list, therefore interpreting the second list as an association list:

    (define (manageFirstList lst1 lst2)
      (cond ((null? lst1) '())
            (else (cons (list (caar lst1) (cadr (assoc (cadar lst1) lst2)))
                        (manageFirstList (cdr lst1) lst2)))))
    

    Now, if you absolutely need to change the value of the x global variable, simply do something like this:

    (define x '())
    (set! x (manageFirstList test1DataA test1DataB))
    

    Notice how I avoided completely the need to modify x inside the procedure, since in general that’s not the Scheme way to solve problems. In the end, the value in x is:

    (("a" "aa") ("b" "bb") ("c" "cc") ("d" "dd") ("e" "Ir OK!"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function holiday_hitlist($tablename, $hit_user){ global $host, $user, $pass, $dbname; $link = mysql_connect($host, $user, $pass, $dbname);
function a($function, $array) { global $test $test->$function(implode(',' $array)); } For example, I want to
(function($) { $.fn.myFoo= function (o){ this.element = $(this) options = jQuery.extend({ name: defaultName, size:
function ff_chk_username_unique(element, action) { alert(element.value); alert(action); var actiona=http://localhost/myproject/check/check_username.php; var form_data = { username: element.value,
function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
Function FillAdminAccount() As Boolean FillAdminAccount = True Try SQLconn.ConnectionString = connect timeout=9999999; & _
function Submit_click() { if (!bValidateFields()) return; } function bValidateFields() { /// <summary>Validation rules</summary> ///
function main() { Hello(); } function Hello() { // How do you find out
function AddTheatres() { Services.AdminWebServices.AddTheatresSVC(oTheatres, OnSuccessTheatres, OnError, OnTimeOut); } function OnSuccessTheatres(result1) { Services.AdminWebServices.AddTicketPricesSVC(oTicketPrices, OnSuccessTicketPrices, OnError,
function register_contact ($person = array()) { $nogood = false; foreach ($person as $val) {

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.