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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:16:48+00:00 2026-06-14T15:16:48+00:00

(defun simplify (x) (if (and (not (null x)) (listp x)) (if (and (equal ‘(car

  • 0
(defun simplify (x) 

 (if (and (not (null x)) (listp x))
   (if (and (equal '(car x) '(cadr x)) (equal '(car x) 'not))
      (simplify (cddr x))
      (cons (car x) (simplify (cdr x)))
     )
    'nil
  )
)

This lisp function is meant to take an expression as an argument then remove superfluous ‘not’s from it and return it. It checks if the argument is a non-empty list and returns nil if it isn’t (base case). If it is non-empty, I want to check if the car(x) = car(cdr(x)) = ‘not’. If they aren’t detected to be a pair of ‘not’s then it should recurse and build on a list to return. If they are detected to be both ‘not’ then it should still recurse but also skipping both car(x) and car(cdr(x)). Right now all this code does is return an expression identical to the argument so I assume the problem is that my condition in the nested if statement isn’t being set off properly, how can I check if car(x) and cadr(x) are both ‘not’?

  • 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-14T15:16:49+00:00Added an answer on June 14, 2026 at 3:16 pm

    “when you assume…”

    Actually, the test is semi-ok (but you’ll end up taking (car nil) if x is (not) ). The problem is the recursion. Try it on paper:

    (simplify '(and (not (not y)) (or x (not (not z))))`
    
    1. (car x) is not not.

    2. so: (cons (car x) (simplify (cdr x))

    3. Now x is ‘((not (not y)) (or x (not (not z))))So(car x)is(not (not y)), which is not equal tonot`. Recurse again

    4. Now x is ((or x (not (not z)))and(car x)is(or x (not (not z)))`. But you probably get the picture.

    Hint: (map simplify x) and fix your termination condition to return x if x is an atom.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this quicksort function: (defun quicksort (lst) (if (null lst) nil (let ((div
Why does this code not print out the content of the array - (defun
When I define a function in Common Lisp like this: (defun foo (n) (declare
I have the following Common Lisp function: (defun get-positions (marker) (let ((result nil)) (dotimes
I have: (defun getTotalValue(pack) (cond ((null pack) 0) (t (+ (car (car pack)))) (getTotalValue
In Common Lisp you can do this: (defun foo (bar &key baz quux) (list
I have the following code in Lisp: (defun Is_List_Even (lista) (cond ((null lista) t)
(defun find-attr (node attr) (let ((children (pt-children node))) (if (null children) nil (let ((subchildren
This is my function: (defun MyFunction(input) (let ((NEWNUM (find input num))) (if (find input
I have the following LISP code (defun l (x y) (list x y)) when

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.