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

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

Re: Executing part of the code instead of another


From: Nick Dokos
Subject: Re: Executing part of the code instead of another
Date: Wed, 07 Oct 2020 13:29:24 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Christopher Dimech <dimech@gmx.com> writes:

> I have tried executing the following condition (if (nb > na))
>
> (setq na 2)
> (setq nb 5)
> ( if (> nb na)
>     (message "nb > na [condition true]")
>     (message "condition false")
> )
>
> I highlighted the region then pressed C-x C-e
> It returned the first message as expected, but when I tried
> the next one, I still got the first message.
>
`C-x C-e` is bound to `eval-last-sexp` which evaluates the *last*
sexp: the if.  It does not evaluate the setq's (setting the region does
*NOT* matter for it - try `M-x eval-region' for that)


> (setq na 2)
> (setq nb 1)
> ( if (> nb na)
>     (message "nb > na [condition true]")
>     (message "condition false")
> )
>
>
>
>
>> Sent: Wednesday, October 07, 2020 at 9:20 AM
>> From: "Robert Pluim" <rpluim@gmail.com>
>> To: "Christopher Dimech" <dimech@gmx.com>
>> Cc: moasenwood@zoho.eu, help-gnu-emacs@gnu.org
>> Subject: Re: Executing part of the code instead of another
>>
>> >>>>> On Wed, 7 Oct 2020 09:01:00 +0200, Christopher Dimech <dimech@gmx.com> 
>> >>>>> said:
>>
>>     Christopher> What can one use if there is an else branch with multiple 
>> commands, as I would
>>     Christopher> like to use it.
>>
>> From 'C-h f if'
>>
>>     if is a special form in `C source code'.
>>
>>     (if COND THEN ELSE...)
>>
>>       Probably introduced at or before Emacs version 1.1.
>>
>>     If COND yields non-nil, do THEN, else do ELSE...
>>     Returns the value of THEN or the value of the last of the ELSE's.
>> =>  THEN must be one expression, but ELSE... can be zero or more expressions.
>>     If COND yields nil, and there are no ELSE's, the value is nil.
>>
>>
>> Robert
>> --
>>
>
>

-- 
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler




reply via email to

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