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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:05:09+00:00 2026-06-07T13:05:09+00:00

I am not experienced in LISP and list processing, but I have a set

  • 0

I am not experienced in LISP and list processing, but I have a set of C++ STL vectors (or strings) on which I need to perform the following operations:

IdenticalHead (v1, v2): Return the biggest sequence that both v1 and v2 start with it.

IdenticalTail (v1, v2): Return the biggest sequence that both v1 and v2 end with it.

IdenticalTailHead (v1, v2): Return the biggest sequence that v1 ends with it and v2 starts with it.

For example:

if v1 = (a,b,c,e,f), v2 = (a,b,d,e,f), then:

IdenticalHead (v1, v2) = (a,b)
IdenticalTail (v1, v2) = (e,f)

if v1 = (a,b,c), v2 = (b,c,g), then:

IdenticalTailHead (v1, v2) = (b,c)

My question is that are these standard operations in LISP or any other language? Do they have standard names like CDR and CAR?

  • 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-07T13:05:12+00:00Added an answer on June 7, 2026 at 1:05 pm

    No, there are no standard operators for these. But identical-head is not hard to write:

    (defun identical-head (l1 l2)
      (and l1 l2 (equal (car l1) (car l2))
           (cons (car l1) (identical-head (cdr l1) (cdr l2)))))
    

    I don’t know of an easier way to write identical-tail except reversing the input lists, calling identical-head, and then reversing the result, since lists only allow forward traversal, not backward.

    (defun identical-tail (l1 l2)
      (reverse (identical-head (reverse l1) (reverse l2))))
    

    Here’s how I’d write identical-tail-head:

    (defun identical-tail-head (l1 l2)
      (labels ((starts-with-p (list prefix)
                 (cond ((null prefix) t)
                       ((null list) nil)
                       ((equal (car list) (car prefix))
                        (starts-with-p (cdr list) (cdr prefix))))))
        (cond ((null l1) nil)
              ((starts-with-p l2 l1) l1)
              (t (identical-tail-head (cdr l1) l2)))))
    

    It’s not a very efficient way to do it, since it’s O(n²), but (again) given that lists are forward-traversal-only, I haven’t come up with a better way.

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

Sidebar

Related Questions

I'm not super experienced in writing grammars, but let's say I have a record
Hei there, I'm not experienced at all in C++ as I need to start
I am not an experienced iPhone user, so I have a question regarding to
I'm not very experienced in C#, done some small stuff with it, but it's
I'm not very experienced with JavaScript, but this code was similar to what I
I'm a long time developer but not very experienced with DNS. Here's my problem:
I need help on regex or preg_match because I am not that experienced yet
I'm not experienced with sitemaps - only just started looking into them. I have
I'm not experienced with java applications but I found out that finding static pointers
First, I'm not experienced with PHP whatsoever. I have 2 arrays - minimumpressure and

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.