help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Return value not as expected in Emacs Lisp function


From: Pascal J. Bourguignon
Subject: Re: Return value not as expected in Emacs Lisp function
Date: Fri, 09 Aug 2013 00:31:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Thorsten Jolitz <tjolitz@gmail.com> writes:

> ,-----------------------------------------------------------------
> | "(prog (click NIL 1) (press NIL 1) (click NIL 4) (click NIL 1))"
> `-----------------------------------------------------------------
>
> is actually PicoLisp, a lisp-1 with NIL and T syntax (uppercase!). I
> thought the 'prog in the beginning (PicoLisp's 'progn)  would make it
> clear its not Elisp. At least C-h f doesn' show me a 'prog function in
> Elisp. 
>
> But thanks for your answer, I did not know `prin1-to-string', and finally
> looked up the difference between lisp-1 and lisp-2. 

Ok, that explains the 'lst.

Now, emacs has one good characteristic that helps in manipilating sexps
from other lisps:  it has no module or package system and it has case
sensitive symbols, with no lisp reader to upcase them automatically by
default.

Therefore, you can perfectly manipulate picolisp sexps as emacs lisp
sexps.  Unless you have to deal with reader macros or other strange
syntaxes, my advice would be to stick to sexps, this has big advantages
over strings.


As for the misplaced parenthesis problem, be sure to let emacs
auto-indent lisp (any) code for you, selectnig a region and typing C-M-\
(indent-region), or using paredit (strongly advised, to edit any kind of
sexps), typing M-q (paredit-reindent-defun) from time to time inside
sexps.

Then you will be shocked by any misplaced parenthesis, since it will
imply very strange indentation, like this:


(defun hostname ()
  (interactive "Hello"
               (cond ((boundp  'system-name) system-name)
                     ((fboundp 'system-name) (system-name)))
               (t (shell-command-to-string
                   "echo -n $( (hostname -f 2>/dev/null) || (hostname 
2>/dev/null) )"))))

where it is obvious that there's a missing closing parenthesis for
interactive, and that the cond is closed too early (before the (t …)
branch.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.  
You know you've been lisping too long when you see a recent picture of George 
Lucas and think "Wait, I thought John McCarthy was dead!" -- Dalek_Baldwin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]