[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 08:31:35 +0100 |
Can you be so kind to help me output tim_out from the following
function. I do not know in which construct to insert the output.
If inside the "let" variable definition area, in the body of the
"let" construct , or if outside the "let".
Regards
(defun timfutur (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) ))
> Sent: Thursday, December 17, 2020 at 5:34 AM
> From: "Jean Louis" <bugs@gnu.support>
> To: steve-humphreys@gmx.com
> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Understanding the "let" construct and the setting of variables
>
> > -*- lexical-binding: t; -*-
> * steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2020-12-17 03:26]:
> > Let's introspect two questions.
> >
> > 1. In what simple circumstances would one use a "setq" in the body
> > of a let?
>
> Whenever I find myself in linear programming within a function and
> need to change variable I will use setq. Some global variables are
> rather set with setq:
>
> (set-buffer buffer)
> (setq header-line-format (concat buffer " ➜ Finish with `q' or `h'"))
> (cf-org-view-mode)
> (insert blob)
> (setq org-hierarchical-todo-statistics nil)
> (org-update-parent-todo-statistics)
> (goto-char 1)
>
> But I will often use it in construction of lists:
>
> (defun rcd-cgi-parse-query-string (query-string)
> "Parse QUERY-STRING that normally comes from the environment
> variable `QUERY_STRING'. Return PLIST."
> (let* ((query-string (url-unhex-string query-string))
> (parts (split-string query-string "&"))
> (length (length parts))
> (plist '()))
> (dolist (part parts plist)
> (let* ((data (split-string part "="))
> (prop (car data))
> (val (cadr data)))
> (setq plist (plist-put plist (intern prop) val))))))
>
>
> (defun iota (count &optional start step)
> "Return a list containing COUNT numbers, starting from START
> and adding STEP each time. The default START is 0, the default
> STEP is 1"
> (let* ((start (if start start 0))
> (step (if step step 1))
> (last (+ start count))
> (counter 0)
> (list '())
> (elt start))
> (while (< counter count)
> (push elt list)
> (setq elt (+ elt step))
> (setq counter (1+ counter)))
> (reverse list)))
>
> How I understand it is that `setq' I can freely use on variables
> already defined with and within my `let' as then the variable
> will not become global.
>
> (defun my-fun ()
> (let ((my-var nil))
> (setq my-var 2)))
>
> (my-fun)
>
> my-var is not defined
>
> (defun my-fun ()
> (let ((my-var nil)))
> (setq my-var 2))
>
> (my-fun)
>
> my-var is here defined as 2 and became global variable.
>
> And each time that variable is already defined with `defvar' one
> can then change it with setq.
>
> Jean
>
- 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 <=
- 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
Re: Understanding the "let" construct and the setting of variables, Joost Kremers, 2020/12/16