Hello every body ,
I am very beginner in lisp , I need your help
I am trying to do some thing like dictionary .
I want an example of how I can take sentence like this "this is an example"
then take each word "this" "is" "an" "example"
thank you very much
Help me on Tokinzer
Re: Help me on Tokinzer
Code: Select all
(defun split (string delimiters &optional (empty-strings nil))
(loop for start = 0 then (1+ finish)
for finish = (position-if #'(lambda (elem) (member elem delimiters)) string :start start)
for token = (subseq string start finish)
when (or empty-strings (/= 0 (length token))) collecting token
until (null finish)))
Code: Select all
(split "Hello world, people!" '(#\Space #\, #\!))
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
Re: Help me on Tokinzer
As far as I know, there is no ready-to-use splitting function in the cl standard.
However you can use the cl-split-sequence library, available through quicklisp.
Assuming quicklisp is installed,
The code for split-sequence can be read online at the following url:
http://common-lisp.net/project/clbuild/ ... uence.lisp
However you can use the cl-split-sequence library, available through quicklisp.
Assuming quicklisp is installed,
Code: Select all
CL-USER> (ql:quickload :split-sequence)
To load "split-sequence":
Load 1 ASDF system:
split-sequence
; Loading "split-sequence"
(:SPLIT-SEQUENCE)
CL-USER> (use-package :split-sequence)
T
CL-USER> (split-sequence #\space "This is an example.")
("This" "is" "an" "example.")
19
CL-USER>
http://common-lisp.net/project/clbuild/ ... uence.lisp