[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Understanding the "let" construct and the setting of variables
From: |
steve-humphreys |
Subject: |
Re: Understanding the "let" construct and the setting of variables |
Date: |
Thu, 17 Dec 2020 02:20:53 +0100 |
> Sent: Thursday, December 17, 2020 at 2:05 AM
> From: "Joost Kremers" <joostkremers@fastmail.fm>
> To: steve-humphreys@gmx.com
> Cc: help-gnu-emacs@gnu.org
> Subject: Re: Understanding the "let" construct and the setting of variables
>
>
> On Thu, Dec 17 2020, steve-humphreys@gmx.com wrote:
> > For example, the following fails. Why? Haw can one fix the function?
> >
> > (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))
> >
> > (message "%d %d" tim_out) )
> >
> > (message "%s" "lett") ))
> >
> > (lett 845 80)
>
> The error is a bit cryptic, but it's telling you that you need to move the
> first
> `message` into the body of the `let*`. Right now, it's in the list of
> variables
> to bind, but it's not a valid binding form:
>
> ```
> (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)))
>
> (message "%d %d" tim_out)
>
> (message "%s" "lett") ))
> ```
>
> Note that this will still produce an error, because the first `message` has a
> format string that requires two arguments but only one is given.
This means that I can use the variables in the body of the "let". Great
explanation,
I fixed to. Now I need to have the function output "tim_out".
> --
> Joost Kremers
> Life has its moments
>
- Understanding the "let" construct and the setting of variables, steve-humphreys, 2020/12/16
- Re: Understanding the "let" construct and the setting of variables, Jean Louis, 2020/12/16
- Re: Understanding the "let" construct and the setting of variables, steve-humphreys, 2020/12/17
- Re: Understanding the "let" construct and the setting of variables, Emanuel Berg, 2020/12/19
- Re: Understanding the "let" construct and the setting of variables, Jean Louis, 2020/12/19
- Re: Understanding the "let" construct and the setting of variables, Emanuel Berg, 2020/12/20
Re: Understanding the "let" construct and the setting of variables, Emanuel Berg, 2020/12/18