0

I'm having trouble finding where the problem here is exactly. The result I'd like returned is a string that looks like

1. (n,adj-no) occupation
2. business

My function is here and it looks like something is supposed to be a list but isn't.

(defun japanese-get-definition (dictentry)
  "Get a definition from a dictionary entry."
  (let* (index 1)
    (save-match-data
      (and (string-match "/\\(.*?\\)$" dictentry)
           (setq definitions (split-string (match-string 1 dictentry) "/" t))
           (dolist (definition definitions)
             (setq definition (concat (int-to-string index) ". " definition))
             (setq index (+ index 1)))
           (mapconcat 'identity
                      definitions
                      "\n"))
      )
    )
  )
(japanese-get-definition "職業 [しょくぎょう] /(n,adj-no) occupation/business/")

1 Answer 1

3

You have the wrong syntax for let*.

Use (let* ((index 1))...) to bind variable index to the value 1.

Use C-h f let* RET to see a description of let*. Use C-h S let* RET to read more about it in the manual.

And always read (and report) the exact error message that you get. It's meant to help you. If you get a debugger backtrace, report that.

You can customize option debug-on-error to t to enter the debugger automatically when an error occurs. Use C-h S debug-on-error to read about this in the manual.

In this case, the error message told you that Emacs was expecting a list (tested by predicate listp), and instead it received the number 1. That is a hint that you are using the wrong syntax.

After let* comes a list of bindings or implicit bindings (to nil). You have a list, whose first element is the symbol index. This is interpreted as an implicit binding of variable index to the value nil. The second element of your list is the number 1, which is neither a symbol (an implicit binding to nil of the symbol as a variable) nor a list (an explicit binding of a symbol to an explicit value).

3
  • That's now working, I also included (definitions) into the let* and the function no longer throws an error but now it seems that the return value is nil. instead of what I hoped which was the result of mapconcat
    – irregular
    May 21, 2016 at 14:05
  • If you have another question then please ask it separately. You don't show your fixed version so it is anyway difficult to guess why you are getting nil (or even whether you are really getting nil). save-match-data returns the result of its last sexp, and mapconcat returns the result of concatenating its sequence elements.
    – Drew
    May 21, 2016 at 15:36
  • new question please advise :) emacs.stackexchange.com/questions/22408/… I saw your answer here stackoverflow.com/questions/36202330/… but I'm not sure why mine isn't working as intended
    – irregular
    May 21, 2016 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.