From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Elisp - Function returning a sequence of times Date: Wed, 16 Dec 2020 10:20:03 +0100 Message-ID: <87ft46yubf.fsf@fastmail.fm> References: <878s9y8fy5.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20190"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.7; emacs 27.1.50 Cc: help-gnu-emacs@gnu.org To: steve-humphreys@gmx.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 16 10:28:25 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 1kpT6f-00059V-GU for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 10:28:25 +0100 Original-Received: from localhost ([::1]:46204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpT6e-000189-IL for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 04:28:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpT5y-000155-9L for help-gnu-emacs@gnu.org; Wed, 16 Dec 2020 04:27:42 -0500 Original-Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:39015) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpT5t-0004Jq-SO for help-gnu-emacs@gnu.org; Wed, 16 Dec 2020 04:27:42 -0500 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id E1DDBC89; Wed, 16 Dec 2020 04:27:35 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 16 Dec 2020 04:27:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= references:from:to:cc:subject:date:in-reply-to:message-id :mime-version:content-type; s=fm1; bh=7MyAaBCfLxvfaCeAGxSix2coAy D5veMs8EoY10dmYvA=; b=q0QFW3gpmIhC3HG+U0EsOC0tRTIsVENqEGEueFalpG n6FSYSklBnUxQwsCH0L48H1itFIj2NOzHUMhIQ2jJ4m0nfrXAcDEdVKk+A6pPnRm aoAhgtyAr/fOvw9Pn9/MxoulRaQaz2xvbp3orcmWyggbwtSuFjDDohLwYfHPeNJH eZliEpm2SGq2u1yBDgNoxo2Hr2Yar26sAivbZ+OzgvfkWopmvKtub7cq6girAo9t +950b7P6oWf+GCwGt9IlpHitmtgk2xuDe5VkWxqECJ8t8M33pGdb5PSkNyUOYBKT 9DDIMg6p3nxEBRFQT1yK6E4ObvsjVoJJH2WiCTDkz9Fg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=7MyAaB CfLxvfaCeAGxSix2coAyD5veMs8EoY10dmYvA=; b=VBH3f5Zya8Jv0tBwwy7+1n SxdWGzWtQ5ZSWf3Fp5mBfjwmTUDz9z0F1rDlzX3EXkkXRraw+3Zu9XMn+6uGlwHN zI8TI1IsVujtnijbZETHwpNyzg7wtQd52rqoaYSHHN73r8Tpp2ycT3alKKA7b6kD InZTqw5fvIPu0GnDXoMTZg4mzARetZ/osCevHh22qR/qOMd73A+i8IcHQhhLo5Ib hw33Vk/cPEr+b+6FfrCGVTazKD4SIhW8ZF7XteUrQF+HyX+W1Gs1fpE2pEZcvj6M sdGImRWOld0KGvE8LyOl/eDKjukIdNvZovpZ0wwHEB88Pwu+SKgICAaC52eXyZmg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudelvddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpehffgfhvffuffgjkfggtgesthdtre dttdertdenucfhrhhomheplfhoohhsthcumfhrvghmvghrshcuoehjohhoshhtkhhrvghm vghrshesfhgrshhtmhgrihhlrdhfmheqnecuggftrfgrthhtvghrnhepvdeihfetueevke duteehudeihedvlefgieejhedvteefgeelleehhfejudeijeevnecukfhppeelhedrledt rddvvdegrddvgeeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhoohhsthhkrhgvmhgvrhhssehfrghsthhmrghilhdrfhhm X-ME-Proxy: Original-Received: from Swift.fastmail.com (ip5f5ae0f6.dynamic.kabel-deutschland.de [95.90.224.246]) by mail.messagingengine.com (Postfix) with ESMTPA id 7CFAB240064; Wed, 16 Dec 2020 04:27:34 -0500 (EST) In-reply-to: Received-SPF: pass client-ip=64.147.123.20; envelope-from=joostkremers@fastmail.fm; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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:126415 Archived-At: On Wed, Dec 16 2020, steve-humphreys@gmx.com wrote: > I have done something like this, but need help to finalise the actual function. > Do you agree on this solution? > > > (defun timfutur () > (interactive) > (setq tm 845) > (setq tsk 30) > (setq thr (/ tm 100)) > (setq tmn (- tm (* thr 100))) > (setq tmn-futur (% (+ tmn tsk) 60)) > (setq thr-futur (% (+ (/ (+ tmn tsk) 60) thr) 24)) > (message "%d %d %d%d" thr tmn thr-futur tmn-futur)) My humble opinion: try to avoid `setq` at all cost. It has some legitimate uses, but they're far and few between. ``` (defun timfutur () (interactive) (let* ((tm 845) (tsk 30) (thr (/ tm 100)) (tmn (- tm (* thr 100))) (tmn-futur (% (+ tmn tsk) 60)) (thr-futur (% (+ (/ (+ tmn tsk) 60) thr) 24))) (message "%d %d %d%d" thr tmn thr-futur tmn-futur))) ``` -- Joost Kremers Life has its moments