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

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

Re: Understanding the "let" construct and the setting of variables


From: Joost Kremers
Subject: Re: Understanding the "let" construct and the setting of variables
Date: Thu, 17 Dec 2020 09:01:36 +0100
User-agent: mu4e 1.5.7; emacs 27.1.50

On Thu, Dec 17 2020, steve-humphreys@gmx.com wrote:
> I want the function "lett" to return "tim_out".  I understand that the last 
> command 
> is the output of the function.  But should this be done in the binding part 
> or in the
> body part of the "let".  Or outside the "let".  

If `message` is in the last form in the body of the `let`, the return value of
`message` is also the return value of `let`. If `let` is the last form in the
body of the function, its return value is the return value of the function.

`message` can also be outside the body of `let`, but in that case it cannot
refer to any of the variables bound in `let`, because they are then out of scope
and no longer exist.

> (defun lett (tim tsk)
>
>    (let* ( (thr (/ tim 100))
>            (tmn (- tim (* thr 100)))
>
>            (tinc_mn (+ tmn tsk))
>            (tinc_hr (/ (+ tmn tsk) 60))
>            (tinc_mn (- tinc_mn (* tinc_hr 60)))
>
>            (thr_futur (* (+ thr tinc_hr) 100))
>            (tmn_futur tinc_mn)
>            (tim_out (+ thr_futur tmn_futur)) )
>       ;; --- body of let ----
>       (message "tim_out: %d" tim_out) ))


-- 
Joost Kremers
Life has its moments



reply via email to

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