* Possible to access previous arg in `interactice' call?
@ 2014-08-02 12:15 Thorsten Jolitz
2014-08-02 16:29 ` Drew Adams
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Jolitz @ 2014-08-02 12:15 UTC (permalink / raw
To: help-gnu-emacs
Hi List,
in this example, is there a way to access num1 while reading num2?
#+begin_src emacs-lisp
(defun foo (num1 num2)
(interactive
(list
(read-number "Num1: ")
(+ (read-number "Num2: ") num1)))
(message "num1: %s\nnum2: %s" num1 num2))
#+end_src
#+results:
: foo
#+begin_src emacs-lisp
(call-interactively 'foo)
#+end_src
-> list: Symbol's value as variable is void: num1
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Possible to access previous arg in `interactice' call?
2014-08-02 12:15 Possible to access previous arg in `interactice' call? Thorsten Jolitz
@ 2014-08-02 16:29 ` Drew Adams
2014-08-02 17:36 ` Thorsten Jolitz
[not found] ` <mailman.6474.1407001032.1147.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 4+ messages in thread
From: Drew Adams @ 2014-08-02 16:29 UTC (permalink / raw
To: Thorsten Jolitz, help-gnu-emacs
> (interactive (list (read-number "Num1: ")
> (+ (read-number "Num2: ") num1)))
>
> -> list: Symbol's value as variable is void: num1
Bind the value returned by the first `read-number' to a local
variable, and use that.
(interactive
(let ((n1 (read-number "Num1: ")))
(list n1 (+ (read-number "Num2: ") n1))))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Possible to access previous arg in `interactice' call?
2014-08-02 16:29 ` Drew Adams
@ 2014-08-02 17:36 ` Thorsten Jolitz
[not found] ` <mailman.6474.1407001032.1147.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 4+ messages in thread
From: Thorsten Jolitz @ 2014-08-02 17:36 UTC (permalink / raw
To: help-gnu-emacs
Drew Adams <drew.adams@oracle.com> writes:
>> (interactive (list (read-number "Num1: ")
>> (+ (read-number "Num2: ") num1)))
>>
>> -> list: Symbol's value as variable is void: num1
>
> Bind the value returned by the first `read-number' to a local
> variable, and use that.
>
> (interactive
> (let ((n1 (read-number "Num1: ")))
> (list n1 (+ (read-number "Num2: ") n1))))
That works, thanks!
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Possible to access previous arg in `interactice' call?
[not found] ` <mailman.6474.1407001032.1147.help-gnu-emacs@gnu.org>
@ 2014-08-02 20:57 ` Pascal J. Bourguignon
0 siblings, 0 replies; 4+ messages in thread
From: Pascal J. Bourguignon @ 2014-08-02 20:57 UTC (permalink / raw
To: help-gnu-emacs
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Drew Adams <drew.adams@oracle.com> writes:
>
>>> (interactive (list (read-number "Num1: ")
>>> (+ (read-number "Num2: ") num1)))
>>>
>>> -> list: Symbol's value as variable is void: num1
>>
>> Bind the value returned by the first `read-number' to a local
>> variable, and use that.
>>
>> (interactive
>> (let ((n1 (read-number "Num1: ")))
>> (list n1 (+ (read-number "Num2: ") n1))))
>
> That works, thanks!
Indeed. Remember that the point of the interactive _declaration_, is to
be able to get the argument _before_ the function is called. Therefore
the parameters are not bound yet!
Declaration means that it's not _executed_ in the body of the command
It declares some behavior that is used before the command is called.
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-08-02 20:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-02 12:15 Possible to access previous arg in `interactice' call? Thorsten Jolitz
2014-08-02 16:29 ` Drew Adams
2014-08-02 17:36 ` Thorsten Jolitz
[not found] ` <mailman.6474.1407001032.1147.help-gnu-emacs@gnu.org>
2014-08-02 20:57 ` Pascal J. Bourguignon
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.