Generic Lisp: delete function, how is it used?

I have a request-uri request in the form of "/ node / 143" (just an example format).

I want to remove the first slash line from a string, I searched for the delete function and tried. I just can't get it to work (I use SBCL for Linux).

I set request-uri with this code.

(setq request-uri "/node/143")

When I check a variable, I return it.

request-uri
"/node/143"

Now I'm trying to remove the first slash (at this point, it's just all to see how the function is being used correctly).

(remove "/" request-uri)
"/node/143"

(remove '/ request-uri)
"/node/143"

I even tried to provide a list

(remove '("/") request-uri)
"/node/143"

(remove '('/) request-uri)
"/node/143"

Despite the fact that strings are character vectors , I thought that somehow it could be, the whole string can be placed in one cell, and I tried to delete the whole thing, still no luck.

(remove "/node/143" request-uri)
"/node/143"

(remove '/node143 request-uri)
"/node/143"

, , , , , , , .

- , ?

.

: , .

,

(remove #\/ request-uri)

`(remove #\node request-uri`)

, .

(remove "node" request-uri)
(remove 'node request-uri)
(remove ?\node request-uri)
(remove #\node request-uri)
(remove '("node") request-uri)

, .

+5
4

Common Lisp HyperSpec.

, Arrays ( ) , , . , .

. CLHS :

remove item sequence &key from-end test test-not start end count key
    => result-sequence

- . , :

(remove #\/ "/foo/")

()

(remove #\/ "/foo/" :start 2)

: #\a - . #\ node . . "/foo/".

REMOVE . . ? TEST EQL EQL item. IDENTITY .

, ? , :

 (remove "/" "/abc/" :key #'string :test #'equal)

. "/" , EQUAL. . , "/abc/", .

:

 (remove "/" "/abc/" :test (lambda (a b) (eql (aref a 0) b)))

"/" "/abc/". , , ( ).

, , :

(remove (aref "/" 0) "/abc/")

"/" , REMOVE EJ- - , EQL, #/.

? \foo ? Common Lisp |? FOO |.

( "foo" "afoob" ) , ( "foo" ) . , - . , "/" - , . , "/" #/ . - , - .

SUBSEQ . , :

(subseq "0123456" 1 5)
     where 1 is the start and 5 is the end index.

CONCATENATE . , .

(concatenate 'string "abc" "123")
  returns a new string with the strings "abc" and "123" appended.

, . STRING-TRIM, STRING-LEFT-TRIM STRING-RIGHT-TRIM.

, , , , .

.

+4

, , :

(defun remove-string (rem-string full-string &key from-end (test #'eql)
                      test-not (start1 0) end1 (start2 0) end2 key)
  "returns full-string with rem-string removed"
  (let ((subst-point (search rem-string full-string 
                             :from-end from-end
                             :test test :test-not test-not
                             :start1 start1 :end1 end1
                             :start2 start2 :end2 end2 :key key)))
    (if subst-point
        (concatenate 'string
                     (subseq full-string 0 subst-point)
                     (subseq full-string (+ subst-point (length rem-string))))
        full-string)))

. , , . , :

(remove-string "node" "this is a node or not")

regex cl-ppcre.

+2

:

(remove "node" request-uri)
(remove 'node request-uri)
(remove ?\node request-uri)
(remove #\node request-uri)
(remove '("node") request-uri)

(): , (), () , , . REMOVE -, .

, SUBSEQ :

(let ((uri "/node/143"))
  (when (string= (subseq uri 0 6) "/node/")
    (format t "user wants node ~D" (parse-integer (subseq uri 6)))))

, , cl-ppcre / split-sequence. ( Hunchentoot, .)

+2

, "/" - , .

(remove "/" request-uri)
"/node/143"

, #/i.e .

(remove #\/ request-uri)
"node143"

, , . doc, , remove param : count, , . .

(remove #\/ request-uri :count 1)
"node/143"

, .

:: EDIT::

? /, # ​​/. !

0

All Articles