From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.devel Subject: Re: Instead of pcase Date: Fri, 17 Nov 2023 00:41:43 +0100 Message-ID: <875y21cll4.fsf@dataswamp.org> References: <87fs169mjj.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1890"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:MBilXl7cX6/H/Te3E9oaY0bVXrk= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 17 07:35:41 2023 Return-path: Envelope-to: ged-emacs-devel@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 1r3sS4-0000Ef-Ut for ged-emacs-devel@m.gmane-mx.org; Fri, 17 Nov 2023 07:35:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3sRi-0001nd-0w; Fri, 17 Nov 2023 01:35:18 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3lzg-0005Xs-36 for emacs-devel@gnu.org; Thu, 16 Nov 2023 18:41:56 -0500 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3lze-00031X-8d for emacs-devel@gnu.org; Thu, 16 Nov 2023 18:41:55 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1r3lzc-000AOC-4t for emacs-devel@gnu.org; Fri, 17 Nov 2023 00:41:52 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 17 Nov 2023 01:35:13 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:312849 Archived-At: T.V Raman wrote: > RMS' message makes some very valuable points re specialized > languages like pcase -- pcase has its strengths, but in > general, it's definitely not easy to understand complex code > that leverages it -- as an example: > > I recently tried to understand some of the completion code; > -- specifically, completion-at-point, and immediately hit > the pcase wall and gave up --- my lack of understanding of > pcase made that code in Emacs Core read like line-noise. I grepped my own Elisp for pcase and found this. Interestingly, it uses cl-lib as well. So here we have cl-lib and pcase in combination, so should be downright incomprehensible, right? You will see that the use of pcase is very clear. I'm sure you can understand it. From there, more complex use should be very possible for you to understand as well, I'm positive. But really: code that is difficult to understand can be written using non-cl-lib Elisp and non-pcase Elisp as well. Good use of cl-lib and good use of pcase reduces complexity. Complex use of cl-lib and pcase will be complex, sure, but there are no guarantees solving that complexity in any other way will be any less complex. If everyone did that instead of using libraries we would end up with much more code, and code that essentially - but not quite, and that would be a big problem - did the same thing over and over. ;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/time-cmp.el (require 'cl-lib) (require 'pcase) (defun days (y1 m1 d1 y2 m2 d2) (let*((then (float-time (encode-time 0 0 0 d1 m1 y1))) (now (float-time (encode-time 0 0 0 d2 m2 y2))) (diff (- now then)) ) (string-to-number (format-seconds "%d" diff)) )) ;; (days 1958 04 13 1958 08 30) ; 139 days between Tahiti Nui 2 & 3 (defun days-date (date1 date2) (pcase-let*( (sep "-") (`(,y1 ,m1 ,d1) (cl-map 'list #'string-to-number (split-string date1 sep))) (`(,y2 ,m2 ,d2) (cl-map 'list #'string-to-number (split-string date2 sep))) ) (days y1 m1 d1 y2 m2 d2) )) ;; (days-date "2021-03-19" "2021-04-20") ; 31 ;; (days-date "1964-07-26" "2021-03-22") ; 20 693 -- underground experts united https://dataswamp.org/~incal