Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A simple lisp program

Tags:

emacs

lisp

elisp

I want to write this program to find a keyword in a list. If found then print the list. But errors occur, i can't solve it. Please give me some suggestions. I am a newbie for lisp.

The main program is two dolist(two for in C) and find keyword in a list of list(two dimension array).

(defun kanna_find (key)
  (let (
        (result 0)
        (kanna-table (list 
                (list "あ" "ア" "a")
                (list "い" "イ" "i")
               )
        )                               ;; End of kanna table
    )                                   ;; End of let var define
    (dolist (result kanna-table) 
      (dolist (item result)
      (if (string= item key)
          (print result))
        )                               ;; End of the second dolist
      )                                 ;; End of the first dolist
    )                                   ;; End of let
)

(kanna_find "あ")

Below is the debug info

Debugger entered--Lisp error: (void-variable  )
  (list "い"   "イ"   "i")
  (list (list "あ" "ア" "a") (list "い"   "イ"   "i"))
  (let ((result 0) (kanna-table ...)) (dolist (result kanna-table) (dolist ... ...)))
  kanna_find("あ")
  eval((kanna_find "あ"))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)
  recursive-edit()
like image 592
louxiu Avatar asked May 16 '26 05:05

louxiu


1 Answers

(list "あ" "ア" "a")
(list "い" "イ" "i")

Do you notice how the spaces in the second line are longer than the ones on the first line? That's because they're not ASCII spaces, so emacs doesn't recognize them as spaces. Rather emacs thinks they're variable names, so it complains to you that there's no variable called " " (thus the space in the void-variable error).

like image 191
sepp2k Avatar answered May 19 '26 02:05

sepp2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!