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

  • Home
  • SEARCH
  • 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 7176869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:35:44+00:00 2026-05-28T16:35:44+00:00

I have a problem with common lisp. I want to pass a string to

  • 0

I have a problem with common lisp.

I want to pass a string to a function
and want that this strings become a structure.
I can’t use external library.

For example with this input:

(testfu "ftp/http.ok:3345")

This is the struct:

(defstruct test-struct
    scheme 
    part
    ans     
port)

I want this result:

scheme: “ftp” part: “http” ans “ok” port “3345”

How can I do the testfu ?

here my bad try 🙁

(defun testfu (x) 
(setq ur1 (make-test-struct :scheme frist x :host second x)))
  • 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-28T16:35:44+00:00Added an answer on May 28, 2026 at 4:35 pm

    You will have to parse the data out of the string in order that you might use it for your strut. Lisp won’t do that magically.

    Split Sequence is a good library for doing that

    If you don’t want a library, then some code to get you on the correct track. This will tokenize string based on a predicate function fn ( which returns true when a character is a delimiter and false otherwise )

    (defun split-by-fn (fn string)
      (let* ((STARTING 0)
             (TOKEN 1)
             (DELIM 2)
             (state STARTING)
             (a-token "")
             (the-list '())
             (str-length (length string)))
        (dotimes (i str-length)
          (if (funcall fn (char string i))
              (progn
                (if (eq state TOKEN)
                    (progn
                      (setq the-list (cons a-token the-list))
                      (setq a-token "")))
                (setq state DELIM))
            (progn
              (setq a-token
                    (concatenate 'string a-token (string (char string i))))
              (setq state TOKEN))))
        (if (eq state TOKEN)
            (setq the-list (cons a-token the-list)))
        (setq the-list (reverse the-list))))
    

    I don’t usually write code for people but here is an example parser, it’s not the most lisp-y, there are better ways of doing this, but it works.

    (defun parser ( string )
      (labels ((set-field (state struct token)
                (let ((SCHEME 0)
                      (PART   1)
                      (ANS    2)
                      (PORT   3))
                (cond ((= state SCHEME) 
                        (setf (example-struct-SCHEME struct) token))
                      ((= state PART)  
                        (setf (example-struct-PART struct) token))
                      ((= state ANS)  
                        (setf (example-struct-ANS struct) token))
                      ((= state PORT)  
                        (setf (example-struct-PORT struct) token))))))
        (let ((state  0)
              (token "")
              (check 0)
              (a-list '())
              (struct (make-example-struct)))
          (loop for char across string do
            (progn
              (setq check (position char "/.:"))
              (if check
                (progn
                  (set-field state struct token)
                  (setq token "")
                  (setq state (+ check 1)))
                (setq token (concatenate 'string token (string char))))))
          (progn
            (if (/= 0 (length token))
              (set-field state struct token))
              struct))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have run into a common, yet difficult problem. I do not use Photoshop
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a problem that is common, but I am not quite sure exactly
I have the presumably common problem of having elements that I wish to place
So I have a problem that I think is quite common but I have
I have a common problem that I'm looking for a solution to. I have
I have this classic problem that seems impossible to solve for me. I just
A common problem that I have with web pages is floating div tags creeping
I think this is a common problem... yet i have not been able to
In common lisp I can do this: src-> (defmacro macro-hello () `hello) (eval '(macro-hello))

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.