* Elisp: Simple function to Add Two Numbers
@ 2006-08-27 21:25 Edward Dodge
2006-08-27 21:47 ` Hadron Quark
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Edward Dodge @ 2006-08-27 21:25 UTC (permalink / raw)
Please,
Why do I get "wrong number of arguments" every time I try to run this simple,
straight-forward code?
(defun ekd-average (jabba wabba)
"Adds two numbers and returns the sum."
(interactive "nFirstvar: \nn Secondvar: \nr")
( + jabba wabba))
--
Edward Dodge
__o
_`\(,_
(_)/ (_) --- ---
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elisp: Simple function to Add Two Numbers
2006-08-27 21:25 Elisp: Simple function to Add Two Numbers Edward Dodge
@ 2006-08-27 21:47 ` Hadron Quark
2006-08-27 21:55 ` Pascal Bourguignon
2006-08-27 21:55 ` Magnus Henoch
2006-08-27 22:12 ` David Kastrup
2 siblings, 1 reply; 8+ messages in thread
From: Hadron Quark @ 2006-08-27 21:47 UTC (permalink / raw)
Edward Dodge <user@foo.bar> writes:
> Please,
>
> Why do I get "wrong number of arguments" every time I try to run this simple,
> straight-forward code?
>
> (defun ekd-average (jabba wabba)
> "Adds two numbers and returns the sum."
> (interactive "nFirstvar: \nn Secondvar: \nr")
> ( + jabba wabba))
>
As a fellow beginner I would say its because you havent properly
specified your second argument string in the interactive
statement. Check whitespace.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elisp: Simple function to Add Two Numbers
2006-08-27 21:47 ` Hadron Quark
@ 2006-08-27 21:55 ` Pascal Bourguignon
2006-08-28 1:39 ` Edward Dodge
0 siblings, 1 reply; 8+ messages in thread
From: Pascal Bourguignon @ 2006-08-27 21:55 UTC (permalink / raw)
Hadron Quark <hadronquark@gmail.com> writes:
> Edward Dodge <user@foo.bar> writes:
>
>> Please,
>>
>> Why do I get "wrong number of arguments" every time I try to run this simple,
>> straight-forward code?
>>
>> (defun ekd-average (jabba wabba)
>> "Adds two numbers and returns the sum."
>> (interactive "nFirstvar: \nn Secondvar: \nr")
>> ( + jabba wabba))
>>
>
> As a fellow beginner I would say its because you havent properly
> specified your second argument string in the interactive
> statement. Check whitespace.
The whitespaces don't matter, as long as they're not just after a
newline. The problem is that there are two newlines with three
characters specifying a total of four interactive arguments: n, n and r.
(r gives two arguments, start and end of region).
--
__Pascal Bourguignon__ http://www.informatimago.com/
READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elisp: Simple function to Add Two Numbers
2006-08-27 21:55 ` Pascal Bourguignon
@ 2006-08-28 1:39 ` Edward Dodge
2006-08-28 1:50 ` Barry Margolin
0 siblings, 1 reply; 8+ messages in thread
From: Edward Dodge @ 2006-08-28 1:39 UTC (permalink / raw)
Pascal Bourguignon <pjb@informatimago.com> writes:
> The whitespaces don't matter, as long as they're not just after a
> newline. The problem is that there are two newlines with three
> characters specifying a total of four interactive arguments: n, n and r.
> (r gives two arguments, start and end of region).
Yes, this is correct. And I have managed to keep the function from causing
an error by rewriting it:
(defun ekd-average (jabba wabba)
"Adds two numbers and returns the difference between"
(interactive "nFirstvar: \nnSecondvar: ")
(eval ( + jabba wabba)))
Now the only problem is this: it returns no answer when I run it. I thought
lisp functions always returned a value. I even made it explicit by using the
"eval" statement, but still I get no answer in either the minibuffer or
*Messages*.
--
Edward Dodge
__o
_`\(,_
(_)/ (_) --- ---
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elisp: Simple function to Add Two Numbers
2006-08-28 1:39 ` Edward Dodge
@ 2006-08-28 1:50 ` Barry Margolin
2006-08-29 0:18 ` Edward Dodge
0 siblings, 1 reply; 8+ messages in thread
From: Barry Margolin @ 2006-08-28 1:50 UTC (permalink / raw)
In article <ihq64gdtz97.fsf@chlr7032.ch.intel.com>,
Edward Dodge <user@foo.bar> wrote:
> Pascal Bourguignon <pjb@informatimago.com> writes:
>
>
> > The whitespaces don't matter, as long as they're not just after a
> > newline. The problem is that there are two newlines with three
> > characters specifying a total of four interactive arguments: n, n and r.
> > (r gives two arguments, start and end of region).
>
> Yes, this is correct. And I have managed to keep the function from causing
> an error by rewriting it:
>
> (defun ekd-average (jabba wabba)
> "Adds two numbers and returns the difference between"
> (interactive "nFirstvar: \nnSecondvar: ")
> (eval ( + jabba wabba)))
You don't need eval.
>
> Now the only problem is this: it returns no answer when I run it. I thought
> lisp functions always returned a value. I even made it explicit by using the
> "eval" statement, but still I get no answer in either the minibuffer or
> *Messages*.
Yes, the function returns a value. But your command never displays the
value anywhere, and M-x doesn't automatically display the return value
of functions. Use (print (+ jabba wabba)) and it will be displayed in
the echo area.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elisp: Simple function to Add Two Numbers
2006-08-28 1:50 ` Barry Margolin
@ 2006-08-29 0:18 ` Edward Dodge
0 siblings, 0 replies; 8+ messages in thread
From: Edward Dodge @ 2006-08-29 0:18 UTC (permalink / raw)
Barry Margolin <barmar@alum.mit.edu> writes:
> Yes, the function returns a value. But your command never displays the
> value anywhere, and M-x doesn't automatically display the return value
> of functions. Use (print (+ jabba wabba)) and it will be displayed in
> the echo area.
That was it! Thank-you very much!
--
Edward Dodge
__o
_`\(,_
(_)/ (_) --- ---
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elisp: Simple function to Add Two Numbers
2006-08-27 21:25 Elisp: Simple function to Add Two Numbers Edward Dodge
2006-08-27 21:47 ` Hadron Quark
@ 2006-08-27 21:55 ` Magnus Henoch
2006-08-27 22:12 ` David Kastrup
2 siblings, 0 replies; 8+ messages in thread
From: Magnus Henoch @ 2006-08-27 21:55 UTC (permalink / raw)
Edward Dodge <user@foo.bar> writes:
> Why do I get "wrong number of arguments" every time I try to run this simple,
> straight-forward code?
>
> (defun ekd-average (jabba wabba)
> "Adds two numbers and returns the sum."
> (interactive "nFirstvar: \nn Secondvar: \nr")
> ( + jabba wabba))
The trailing "r" in the interactive string means to give the region as
argument to the function, in the form of two integers telling the
beginning and the end. Remove "\nr" in the end, and the function will
work.
Magnus
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Elisp: Simple function to Add Two Numbers
2006-08-27 21:25 Elisp: Simple function to Add Two Numbers Edward Dodge
2006-08-27 21:47 ` Hadron Quark
2006-08-27 21:55 ` Magnus Henoch
@ 2006-08-27 22:12 ` David Kastrup
2 siblings, 0 replies; 8+ messages in thread
From: David Kastrup @ 2006-08-27 22:12 UTC (permalink / raw)
Edward Dodge <user@foo.bar> writes:
> Please,
>
> Why do I get "wrong number of arguments" every time I try to run this simple,
> straight-forward code?
>
> (defun ekd-average (jabba wabba)
> "Adds two numbers and returns the sum."
> (interactive "nFirstvar: \nn Secondvar: \nr")
> ( + jabba wabba))
Because the arguments would need to be
(jabba wabba region-start region-end)
You are aware what the final "r" in your interactive spec means?
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-08-29 0:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-27 21:25 Elisp: Simple function to Add Two Numbers Edward Dodge
2006-08-27 21:47 ` Hadron Quark
2006-08-27 21:55 ` Pascal Bourguignon
2006-08-28 1:39 ` Edward Dodge
2006-08-28 1:50 ` Barry Margolin
2006-08-29 0:18 ` Edward Dodge
2006-08-27 21:55 ` Magnus Henoch
2006-08-27 22:12 ` David Kastrup
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.