emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: list of elisp primitives ?


From: Stephen Berman
Subject: Re: list of elisp primitives ?
Date: Sun, 22 Dec 2019 16:01:49 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On Sun, 22 Dec 2019 13:14:41 +0900 Jean-Christophe Helary <address@hidden> 
wrote:

> What I'm trying to do is this:
>
>>  I was thinking that because of the sheer amount of functions in the elisp
>> reference, it might be much easier to start programming with the primitives
>> to understand how elisp works at its core, and then climb the ladder when
>> need arises...
>
> i.e. trying to find a limited subset of functions that one can use to program
> in elisp and do non-trivial things but that do not involve searching the
> reference at all times.
>
> I'm thinking like in standard learners dictionaries, there are clear
> indications, like asterisks, that tell the learner whether the word is basic
> (generally about 2000 words) or intermediate (about 4000 words).
>
> People who know the basic words can get by and express most of what they need
> to express in daily life.
>
> For ex, it is estimated that there are about 140k words in French, but daily
> use only requires 1k. Let's lower the number of passively known words to 40k,
> that's 50 functions in Elisp...

One way to come up with a list of "basic Elisp" functions is to compare
the usage frequencies in individual Elisp libraries; the most frequently
used functions in a reasonable number of libraries are likely to be the
most basic.  Here's a little hack to get a quick rough estimate for a
single file or buffer of Lisp code (to get a really accurate count would
take quite a bit more effort, which has probably already been done, but
I'm not aware of it):

(defun srb-count-lisp-funs (&optional buffer)
  "Display a frequency table of Lisp functions in BUFFER.
Called interactively with a prefix argument, use the current
buffer, otherwise, prompt for a file, visit it and use its
buffer."
  (interactive "P")
  (let ((fnh (make-hash-table :test 'equal))
        ;; FIXME: false positives with let, funargs, alists, ...
        (flh (lambda (h)
               (save-excursion
                 (save-restriction
                   (goto-char (point-min))
                   (while (search-forward "(" nil t)
                     (let ((sym (symbol-at-point)))
                       (when sym (puthash sym (1+ (gethash sym h 0)) h))))))))
        (bname (buffer-name))
        fnl)
    (if buffer
        (funcall flh fnh)
      (with-temp-buffer
        (let ((file (read-file-name "File: ")))
          (insert-file-contents file)
          (funcall flh fnh)
          (setq bname (file-name-nondirectory file)))))
    (maphash (lambda (key val) (setq fnl (append fnl (list (cons key val)))))
             fnh)
    (setq fnl (sort fnl (lambda (a b) (> (cdr a) (cdr b)))))
    (with-current-buffer (generate-new-buffer (concat "fn freqs (" bname ")"))
      (dolist (e fnl)
        (insert (symbol-name (car e)) ": " (number-to-string (cdr e)) "\n"))
      (view-buffer (current-buffer)))))

Steve Berman



reply via email to

[Prev in Thread] Current Thread [Next in Thread]