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: another day of cutting edge Elisp (read from a file to a string) Date: Thu, 12 Sep 2024 08:07:14 +0200 Message-ID: <87wmjhpfql.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32707"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:BgWTfeK+2DuXXCk493snbFdoK6g= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Sep 12 08:39:42 2024 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 1sodUR-0008Fh-Lb for ged-emacs-devel@m.gmane-mx.org; Thu, 12 Sep 2024 08:39:39 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sodTb-0005tG-1f; Thu, 12 Sep 2024 02:38:47 -0400 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 1soczI-00018o-GK for emacs-devel@gnu.org; Thu, 12 Sep 2024 02:07:28 -0400 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 1soczG-0006ka-JM for emacs-devel@gnu.org; Thu, 12 Sep 2024 02:07:28 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1soczD-0006Yk-E3 for emacs-devel@gnu.org; Thu, 12 Sep 2024 08:07:23 +0200 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: 9 X-Spam_score: 0.9 X-Spam_bar: / X-Spam_report: (0.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TO_NO_BRKTS_PCNT=2.499 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 12 Sep 2024 02:38:44 -0400 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:323554 Archived-At: Here - don't mind eieio-specific syntax - or my own `read-data' - what this does is actually to read the text in a text file and pass it on as a string list (a list of strings). Trust me, I looked, but I never find anything. And not this time either ;[ - but tell me, if and where it exists. If it doesn't - hm, files, strings, the world's most powerful editor - nobody thought about adding it since 1984? 39y 5m 23d We also see in the below code, that while Lisp can indeed and is often very cool and elegant, this doesn't come automatically. `buffer-substring-no-properties' must be the most ugly in all of Elisp. Despite buffer being in the function name, one has to specify (point-min) and (point-max), alltho that sounds like a pretty reasonable default for no args. Also, "no-properties", are we saying what we _don't_ want, now? That said (about certain aspects), as for what I mentioned initially, eieio (from 1995!) - that implements CLs CLOS - that has been an absolute bliss, nothing short of amazing and I used to spent 4 or 5 times the time on a single `defun' as I now do on a whole class with 3-5 `cl-defmethod' - this including initialization validation, defaults and so on - all of which had to be manually in plain Elisp. But it isn't just time - it is also complexity, with plain Elisp it would have taken months and years to setup some kind of framework to manage and reduce complexity, here it is already available and, being the best or worst I don't know but if you have it, you do use it and it does work. Wring what I've been working on would have been impossible for me in functional, and, to be honest, I think impossible or nearly so for most people, including those with skills and experience. eieio also solves many of the other problems I complained about: - modularity (no notion of a package, be it a convention or real, but you don't need to care about that since OO is modular by default - that's the whole idea - to couple data with the functions that use them), and because of the extra association with the name _there is no need for those super-pesky and error prone local--fun-prefixes! that didn't even denote anything real, it was just a convention - that cost me I would say between 25% and 33% of all my errors). - anti-MVC, "do everything in the buffer" - this very bad tendency, that comes from two - let's call them "failed states" - namely dynamic/special scope and the lack of ability with pure functional style to store state and actually _do_ stuff. Absolutely not a problem with eieio as you on the contrary do everything in objects. - I don't remember what more negative I said, but eieio has solved that as well, the only thing it doesn't solve, and maybe cannot solve, are the errors at the user level with typos, "edit" errors (much around with parens here, cause an error somewhere else; remove a sublist here, actually it was the outer and not the inner; etc) also boredom and typos because of Lisp's appreciation of overly long-names-that-could-be-much-shorter, often typos happen when you are unmotivated, it isn't interesting to type what you are typing) - all in all, I'd say I have 5-7 times as many typo/edit mistakes in Lisp, as I would have in e.g. Python. Just my approximation about myself, and while I may be more or less something than everyone else, I don't think I'm so unique in this aspect, actually. Lisp programmers are either hacker-angels with ridiculous skills, or they aren't, in which case I think they have normalized the amount of errors. Do like this, work for 2h on random Elisp project that is advanced, so not just a bunch of `alias' or anything like that. Count how many errors you have in 2h! In other languages, it is common that people who have spent decades doing them have 1, 2 or 3 errors and hour writing code. But in 2h, I almost always have 10 errors, sometimes I have 20 errors and it happens quite often I have 30 errors or more. Do we have a module to give us stats on our own errors? Like I said, I have typos, edit errors (those are an unknown factor in most languages), and in particular I had insane amounts of errors with the double--prefix convention - and both ways! Either mine was wrong, backwards, or someone else's were and I did it. Anyway, here is the source: (cl-defmethod read-file ((a ascii) &optional f dir) (with-slots (name) a (or dir (setq dir (file-name-concat bad-dir "data"))) (setq f (file-name-concat dir (or f (concat name ".txt"))))) (with-temp-buffer (insert-file-contents f) (let* ((lines (split-string (buffer-substring-no-properties (point-min) (point-max)) "\n")) (len (apply #'max (mapcar #'length lines)))) (read-data a (mapcar (lambda (l) (string-pad l len)) lines))))) -- underground experts united https://dataswamp.org/~incal