unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* another day of cutting edge Elisp (read from a file to a string)
@ 2024-09-12  6:07 Emanuel Berg
  2024-09-12  7:09 ` is OO a model that makes models? (was: Re: another day of cutting edge Elisp (read from a file to a string)) Emanuel Berg
  2024-09-15  2:33 ` another day of cutting edge Elisp (read from a file to a string) Richard Stallman
  0 siblings, 2 replies; 3+ messages in thread
From: Emanuel Berg @ 2024-09-12  6:07 UTC (permalink / raw)
  To: emacs-devel

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-15  2:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-12  6:07 another day of cutting edge Elisp (read from a file to a string) Emanuel Berg
2024-09-12  7:09 ` is OO a model that makes models? (was: Re: another day of cutting edge Elisp (read from a file to a string)) Emanuel Berg
2024-09-15  2:33 ` another day of cutting edge Elisp (read from a file to a string) Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).