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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:52:28+00:00 2026-05-17T02:52:28+00:00

(defun returnFirstCharacter(p) (if (symbolp p) (char (symbol-name p) 0) nil) ) (defun returnRestCharacters (p)

  • 0
(defun returnFirstCharacter(p)

(if (symbolp p) (char (symbol-name p) 0) nil)
)

 (defun returnRestCharacters (p)
(let ()
    (intern (subseq(string p) 1))
)         
)

 (defun val (x a)
  (cond ((null a) nil)
        ((equal (car(cdr a)) x) (cdr (cdar a)))
        (t (val x (cdr a)))
    )
 )



 (defun match (pattern data)
(cond 
    ((equal pattern data) t)
    ((match2 pattern data nil))
    (t nil)
)
 )

  (defun match2 (p d a)
(cond

    ( (null p)(cond 
                    ((null a) t)
                    (t a)
                )
    )

    ((numberp p) (cond 
                        ((equal p d) t) 
                        (t nil)
                    )
    ) 

    (  (symbolp p) (cond
                        ((alpha-char-p (returnFirstCharacter p))
                                    (let ()(if (equal p d) (match2 nil nil a) nil)))
                        ((equal (returnFirstCharacter p) #\=)
                                    (let ()
                                            (if (and  (returnRestCharacters p) (null (val (returnRestCharacters p) a)))
                                                (match2 nil nil (cons (
                                                                                list  = (returnRestCharacters p)  d)  a)
                                                )
                                                (let ()
                                                    (if (and  (returnRestCharacters p) (equal (val (returnRestCharacters p) a) (car d))) 
                                                        (match2 (cdr p) (cdr d) a) nil)
                                                )
                                            )
                                    )
                        )
                    )
    )
    (   (listp p) 
                    (cond 
                        ((equal (list-length p) (list-length d))
                            (let ()
                            (   if (equal p d) 
                                    (match2 nil nil a)  
                                    (let ()
                                        (append (match2 (car p) (car d) a)(match2 (cdr p) (cdr d) a) )
                                    )


                            )
                            )
                        )
                    )
    )

)
)

I have match2 being called twice by itself.I want the recursive calls to happen. the moment a call of match2 returns either true or nil
the program is terminated
i want control to be passed back to the previous match2 which called it.

As you can see I have called match2 twice. (listp p) this condiiton in match2 I need to do recursion.How to do this

  • 1 1 Answer
  • 2 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-17T02:52:29+00:00Added an answer on May 17, 2026 at 2:52 am

    This looks like part of a COND block. With that assumption in mind, I’ve added the COND back in and re-formatted the code to make it a bit more obvious.

    (cond ((alpha-char-p (returnFirstCharacter p))
           (let () (if (equal p d) (match2 nil nil a) nil)))
          ((equal (returnFirstCharacter p) #\=)
           (let ()
             (if (and (returnRestCharacters p)
                      (null (val (returnRestCharacters p) a)))
                 (match2 nil nil (cons (list '= (returnRestCharacters p) d) a))
                 (let ()
                   (if (and (returnRestCharacters p) 
                            (equal (val (returnRestCharacters p) a)
                                   (car d))) 
                       (match2 (cdr p) (cdr d) a) nil))))))
    

    First off, you’re calling MATCH2 from the tail position, so it is not obvious what you mean by “passing control back to the previous match2”. Once a call to MATCH2 happens, as written the return value will simply be propagated up the call chain, since you’re not doing anything with the return value.

    Second, you’re using empty LET blocks for no obvious reason (the first IF calls MATCH2 if the condition is true, otherwise slips to the next IF). In neither case do you have multiple expressions that need evaluating, so you could’ve just skipped the LET blocks. Furthermore, using PROGN is a bit more conventional than using an empty LET block (doesn’t matter to the compiler, but it does matter to the human reader).

    It would probably help if you replace the code segment above with the whole function definition of MATCH2 and added a “plain english” description of what you think it should do.

    Edit: With the whole code published (and with atrocious formatting), there’s only one case within MATCH2 that there is a concept of “return and do something” and that’s the two calls that are arguments to APPEND, right at the end. There’s at least one piece of code that is probably going to cause run-time errors (and definitely compile-time warnings), with = used as a variable (unless there’s a dynamic inding elsewhere, that’s probably supposed to be '=).

    You still have not explained what the code is supposed to do. If you sit down and write what you expect the code to do, in a step-by-step fashion, it’s possible that you’ll figure out where you’re going wrong.

    • 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
(defun find-attr (node attr) (let ((children (pt-children node))) (if (null children) nil (let ((subchildren
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
I have the following code in Lisp: (defun Is_List_Even (lista) (cond ((null lista) t)
This is my function: (defun MyFunction(input) (let ((NEWNUM (find input num))) (if (find input
Let's say I need to check if hello.el file is read or not. (defun
The test function is as below: (defun fab (n) (let ((res '(1 1))) (loop
The following code generates prime from 1 to n: (defun prime-list(n) (let ((a)(b)(x (floor
sorry to overflow with so many questions. I have the following: (defun recursive-function (string)

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.