From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: steve-humphreys@gmx.com Newsgroups: gmane.emacs.help Subject: Re: Understanding the "let" construct and the setting of variables Date: Thu, 17 Dec 2020 08:31:35 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16934"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Help Gnu Emacs To: Jean Louis Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 17 08:32:55 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kpnmQ-0004Hp-Ku for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 17 Dec 2020 08:32:54 +0100 Original-Received: from localhost ([::1]:38116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpnmP-0008IP-N3 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 17 Dec 2020 02:32:53 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpnlj-0008GS-2c for help-gnu-emacs@gnu.org; Thu, 17 Dec 2020 02:32:11 -0500 Original-Received: from mout.gmx.net ([212.227.17.20]:33597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpnlg-00053x-30 for help-gnu-emacs@gnu.org; Thu, 17 Dec 2020 02:32:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1608190295; bh=G+rT6L5Bg1+v9K8UIevp4YJGMUK0ZWEc2VMjtvCnWsc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=MdYgB0cQuBrMsaE6jeY98ZznW144F42vo9NS7LgU1kPLLKufwEthmjZnrK578KxoX dCOdE3H3ql+bdYdff1zQpzeWusjOWX8MvycYRYvSMzLItdg/efDzirOP4tSSZqzbvd sTgP3ynqC4JfHbESI4QZB5BKgcL5NWPBl7zQOPP4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [213.165.168.94] ([213.165.168.94]) by web-mail.gmx.net (3c-app-mailcom-bs11.server.lan [172.19.170.179]) (via HTTP); Thu, 17 Dec 2020 08:31:35 +0100 Importance: normal Sensitivity: Normal In-Reply-To: X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:oFnTAQ6qOJ7myVIfAryuT8yECZStWYSmKSIITmy31CDNGSkwwqabgEPvJ4nmUEapjMoSy cxJa+okD8gyDWsrq7SbNUWHN5Bb7/mDBeE7FpkNIBjvm6e6him6t64WV1RJ6/ecLYU/vvmZjJeMi WFLM517EQNTyxjFeK14AFQwV3ELaNMlXTpQatuOGMAjEHiVhpaZG12/XMVT0amCZ01dSbz2Gd3lT 5ueJHhS5vojALuDzn5PgXeZgtRONLzZ/ARPV69IAlDxLXt5S8FRiMcaQBFNVBjkqLsQDBw58dfqY 0Q= X-UI-Out-Filterresults: notjunk:1;V03:K0:TfYe+tLSsTs=:lURqE9WrVZ74QZCLUiaE2E t2lsQpdGehBVN3aQOcQ1m6U3fAW1q4Okc6rmVxGiRYQM5dP6afZnRVmtv7+397BCsqEI8U3lG JV7x3zJy7Fsy95K/lAtfwMpMJaJ5sLLW+DSxlkaPvTS43jU0kzkvJGIa7BOGf1cYXAN1ytjIs X9K5Erw2t7Ab/wl2CT2qzPqlaqgf2dRfsfQZBQYyf7OTO+XQQFYEFmtDqz2qdwKQ33ZneROjw mXfv4eNrFgTgAugXpJkpVmpDR1TjRkKBoYVKfLkVEdZpXD45gi4K6myuEjmH69FI42NlCCm9d sFnFvi1cCyROjWcTn0YilULG33YXDOXCNXs3m1kVQk7XEpeRikJmoEEy/fzAD1CYuOTQAxv4B 4yfNzln0Dj3MGy3Sx5kA7msGELUOC1nCT/ZjJmv1CQgtlcGc4L+DvscqCs5Xm071CHN6YSJIb ZeawJMjBnlZgORbUuUTE/+CY+jfJhxHRqHjoyQ4nkzWhQoaptN5hA6V+C0vmO2o3IHFjOw0cC mXG40fsSXDUeqiaZuOZDtrd8NefyEC/2VshimkAIGiFeWfgc25sO7b1N7UnfawUOwE7KhOrPJ RQt/Y60Y23cGM= Received-SPF: pass client-ip=212.227.17.20; envelope-from=steve-humphreys@gmx.com; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126451 Archived-At: Can you be so kind to help me output tim_out from the following function=2E I do not know in which construct to insert the output=2E If inside the "let" variable definition area, in the body of the=20 "let" construct , or if outside the "let"=2E =20 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" > To: steve-humphreys@gmx=2Ecom > Cc: "Help Gnu Emacs" > Subject: Re: Understanding the "let" construct and the setting of variab= les > > > -*- lexical-binding: t; -*- > * steve-humphreys@gmx=2Ecom [2020-12-17 03:2= 6]: > > Let's introspect two questions=2E > >=20 > > 1=2E In what simple circumstances would one use a "setq" in the body > > of a let? >=20 > Whenever I find myself in linear programming within a function and > need to change variable I will use setq=2E Some global variables are > rather set with setq: >=20 > (set-buffer buffer) > (setq header-line-format (concat buffer " =E2=9E=9C 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) >=20 > But I will often use it in construction of lists: >=20 > (defun rcd-cgi-parse-query-string (query-string) > "Parse QUERY-STRING that normally comes from the environment > variable `QUERY_STRING'=2E Return PLIST=2E" > (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 "=3D")) > (prop (car data)) > (val (cadr data))) > (setq plist (plist-put plist (intern prop) val)))))) >=20 >=20 > (defun iota (count &optional start step) > "Return a list containing COUNT numbers, starting from START > and adding STEP each time=2E 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))) >=20 > 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=2E >=20 > (defun my-fun () > (let ((my-var nil)) > (setq my-var 2))) >=20 > (my-fun) >=20 > my-var is not defined >=20 > (defun my-fun () > (let ((my-var nil))) > (setq my-var 2)) >=20 > (my-fun) >=20 > my-var is here defined as 2 and became global variable=2E >=20 > And each time that variable is already defined with `defvar' one > can then change it with setq=2E >=20 > Jean >