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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:47:29+00:00 2026-05-23T02:47:29+00:00

I fully understand the use of list in lisp but I ‘ve got problem

  • 0

I fully understand the use of list in lisp but I ‘ve got problem using string.
I try to write my own code of functions like string> or string< from common lisp to understand how lisp deals with string.
For example, abcde is bigger than abbb and returns 1.

I think that I will use the char function or do you think that I must use subseq ? or function that deals with ASCII code ?

Here are cases that I found :
-character 0 of each string are equal, we continue, with the next character.
-charactere 0 are different, one is smaller that other, we stop.

I need help about “go to the next character”.

Thanks a lot !!

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

    This is an implementation of a function that given two strings will return either -1, 0 or +1 depending on if the first is less than, equal or greater than the second.
    In case one string is the initial part of the other then shorter string is considered to be “less than” the longer.

    The algorithm is very simple… loops for every char until either the index gets past one of the strings or if a character is found to be different.

    (defun strcmp (a b)
      (do ((i 0 (1+ i))
           (na (length a))
           (nb (length b)))
          ((or (= i na) (= i nb) (char/= (elt a i) (elt b i)))
             (cond
               ((= i na nb) 0)                  ;; Strings are identical
               ((= i na) -1)                    ;; a finished first
               ((= i nb) 1)                     ;; b finished first
               ((char< (elt a i) (elt b i)) -1) ;; Different char a < b
               (t 1)))))                        ;; Only remaining case
    
    (defun test (a b)
      (format t "(strcmp ~s ~s) -> ~s~%"
              a b (strcmp a b)))
    
    (test "abc" "abc")
    (test "ab"  "abc")
    (test "abc" "ab")
    (test "abd" "abc")
    (test "abc" "abd")
    

    The output is

    (strcmp "abc" "abc") -> 0
    (strcmp "ab" "abc") -> -1
    (strcmp "abc" "ab") -> 1
    (strcmp "abd" "abc") -> 1
    (strcmp "abc" "abd") -> -1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't fully understand when to use a workspace. Here is what I have
Please understand firstly that I fully understand that Java will return a String when
i do not fully understand how to communicate between adobe air (using flex3) and
I am trying to fully understand the process pro writing code in some language
Please not that I fully understand this is a dumb ass idea, but its
Not sure I fully understand what phpmyadmin does. I created a database in phpmyadmin,
I do not fully understand classes. I have read the python documentation and several
I was never able to fully understand what is going on in the background
I am relatively new to MEF so I don't fully understand the capabilities. I'm
I am getting a warning I do not fully understand every time I run

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.