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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:14:50+00:00 2026-05-31T16:14:50+00:00

I have been stuck on this for a while. i have tried and I

  • 0

I have been stuck on this for a while. i have tried and I am not getting it. I thought I was getting it, but the fact that this isn’t working is confusing. I should due getting 1 but keep getting nil. The purpose is to simplify the expression using the rules(which I added below). My problem:

(defun simplify (main-list)
  (setq count 1)

  (if (and (eq t (atom (car (cdr main-list))))
           (eq t (atom (car (cdr (cdr main-list))))))
      (print "this says that the 2 ands are cons cells"))

  (if (and (eq nil (cdr main-list))
           (eq t (atom (car main-list))))
      (print "reached end of file, going back now"))

  (if (eq 'and (car main-list))
      (progn
        (if (and (eq t (atom (car (cdr main-list))))
                 (eq nil (atom (car (cdr (cdr main-list))))))
            (if (or (eq nil (car (cdr main-list)))
                    (simplify (car (cdr (cdr main-list)))))
                nil
                (if (eq 1 (car (cdr main-list)))
                    (simplify (car (cdr (cdr main-list))))
                    (if (eq 1 (simplify (car (cdr (cdr main-list)))))))))

        (if (and (eq t (atom (car (cdr main-list))))
                 (eq t (atom (car (cdr (cdr main-list))))))
            (if (or (eq nil (car (cdr main-list)))
                    (eq nil (car (cdr (cdr main-list)))))
                nil
                (if (eq 1 (car (cdr main-list)))
                    (car (cdr (cdr main-list)))
                    (if (eq 1 (car (cdr (cdr main-list))))
                        (car (cdr main-list)))))))))

The list I am using is:

(and 1 (and 1 1))

This is a simple version of what I am trying to accomplish, but I am tackling it a step at a time since I am completely new to the language. These are the rules for the AND I am suppose to follow for this Homework:

(and x nil) => nil; 
(and nil x) => nil;
(and x 1) => x; 
(and 1 x) => x;

I have tested it by doing

(simplify (car(cdr(cdr x))))

and I added counts to see if its even looping, but it is not. So my guess it has something to do with the recursive function calls that are within the if statements in the first block of code. Any explanations as to why would be 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-05-31T16:14:51+00:00Added an answer on May 31, 2026 at 4:14 pm
    (defun simplify (expression)
      (if (consp expression)
          (destructuring-bind (op arg1 arg2)
              expression
            (ecase op
              (and (cond ((or (null arg1) (null arg2))
                          nil)
                         ((eql 1 arg1)
                          (simplify arg2))
                         ((eql 1 arg2)
                          (simplify arg1))))))
        expression))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been stuck for a long time on this simple but obtuse message
i know this is basic but somehow i have been stuck here for some
I have been stuck on this for a while and nothing seems to work.
I've been stuck on this question for a while. I have a data file
This is kind of silly, but I've been stuck for a while in this
I have been stuck at this for a while. I have a smartgwt widget
I have been stuck on this for days, and was wondering if anyone had
I have been stuck on this and don't really know how to go about
I have been stuck on this silly if statement, whatever i do, I cannot
so i have been stuck with this issue for 3 weeks now and i

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.