From 535555a228532013b19eb216a4a6dcc928499c17 Mon Sep 17 00:00:00 2001 From: Andreas Roehler Date: Tue, 27 Oct 2009 11:14:46 +0100 Subject: [PATCH] initial --- elbb.org | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 elbb.org diff --git a/elbb.org b/elbb.org new file mode 100644 index 0000000..0ba191c --- /dev/null +++ b/elbb.org @@ -0,0 +1,268 @@ +#+TITLE: ELBB - itself +#+STARTUP: odd hidestars unfold +#+AUTHOR: Emacs Community +#+EMAIL: bzg AT gnu DOT org +#+LANGUAGE: en +#+OPTIONS: skip:nil toc:nil +* How to check regexp for syntax-errors? +#+BEGIN_SRC emacs-lisp +;; From: Kevin Rodgers +;; Date: Tue, 20 Oct 2009 01:54:56 -0600 +;; Subject: Re: How to check regexp for syntax-errors? (There HAS to be SOME + +;; David Combs wrote: +;; > Isn't there some .el that that will try to parse a regexp, and tell +;; > me where it got confused, and what to look for for errors? + +(defun valid-regexp-p (regexp) + (interactive "sRegexp: ") + (with-temp-buffer + (condition-case error-data + (progn + (re-search-forward regexp nil t) + t) + (invalid-regexp + (when (interactive-p) (message "Invalid regexp: %s" (cdr error-data))) + nil)))) + +;; -- +;; Kevin Rodgers +;; Denver, Colorado, USA +#+END_SRC +* prefer cond over case? +#+BEGIN_SRC emacs-lisp +;; From: David Kastrup +;; Date: Mon, 12 Oct 2009 10:03:39 +0200 +;; To: help-gnu-emacs@gnu.org +;; Subject: Re: Perferr cond over case? + +;; pjb@informatimago.com (Pascal J. Bourguignon) writes: + +;; > Nordlöw writes: +;; > +;; >> Does the use of the cl macro case() incurr some loss of performance +;; >> compare to using cond() instead? +;; > +;; > (macroexpand '(case (* 2 2 2 2 3) +;; > (10 'one) +;; > ((24 42) 'two) +;; > ((3 33) 'three) +;; > (otherwise 'unknown))) +;; > --> +;; > (let ((--cl-var-- (* 2 2 2 2 3))) +;; > (cond ((eql --cl-var-- (quote 10)) (quote one)) +;; > ((member* --cl-var-- (quote (24 42))) (quote two)) +;; > ((member* --cl-var-- (quote (3 33))) (quote three)) +;; > (t (quote unknown)))) +;; > +;; > What do you think? + +;; Before or after byte compilation? + +;; -- +;; David Kastrup + + +#+END_SRC +* batch-mode +#+BEGIN_SRC emacs-lisp +;; From: Decebal +;; Newsgroups: gnu.emacs.help +;; Date: Sat, 10 Oct 2009 11:33:17 -0700 (PDT) +;; To: help-gnu-emacs@gnu.org +;; Envelope-To: andreas.roehler@easy-emacs.de + +;; In a Bash script I changed: + local i + local length=${#1} + + for i in $(seq ${1}) ; do + printf " Regel %${length}d voor de test\n" ${i} + done >${2} + ;; to: + emacs -batch -nw --eval=' + (let ( + (i) + (nr-of-lines '${1}') + (nr-of-lines-length) + (output-file "'"${2}"'")) + (setq nr-of-lines-length (length (number-to-string nr-of-lines))) + (dotimes (i nr-of-lines t) + (insert (format (format " Regel %%%dd voor de test\n" nr-of-lines-length) (1+ i)))) + (write-file output-file)) + ' 2>/dev/null + +;; The Bash version took 293 seconds and the Emacs Lisp version 59 +;; seconds. So it is about 5 times as fast. +;; The Emacs batch gives output like: + ;; Saving file /home/cecil/temp/inputEmacs... + ;; Wrote /home/cecil/temp/inputEmacs +;; That is why I use the 2>/dev/null. +;; Is there a way to circumvent the generation of the above output? +;; Because when there is an error it is also thrown away and that is not +;; nice. + +;; From: Vassil Nikolov +;; Newsgroups: gnu.emacs.help +;; Date: Sat, 10 Oct 2009 16:55:31 -0400 +;; To: help-gnu-emacs@gnu.org +;; Envelope-To: andreas.roehler@easy-emacs.de + + +;; On Sat, 10 Oct 2009 11:33:17 -0700 (PDT), Decebal said: +;; > ... +;; > local i +;; > local length=${#1} +;; > for i in $(seq ${1}) ; do +;; > printf " Regel %${length}d voor de test\n" ${i} +;; > done >${2} + + ;; translates to + + ;; emacs -Q -batch -eval ' + (dotimes (i '"${1}"') + (princ (format " Regel %'"${#1}"'d voor de test\n" (1+ i)))) + ;; ' > "${2}" + + ;; ---Vassil. + + +;; From: Decebal +;; Newsgroups: gnu.emacs.help +;; Date: Sat, 10 Oct 2009 13:57:07 -0700 (PDT) +;; To: help-gnu-emacs@gnu.org +;; Envelope-To: andreas.roehler@easy-emacs.de + +;; On Oct 10, 10:06pm, Andreas R=F6hler +;; wrote: +;; > > The Emacs batch gives output like: +;; > > Saving file /home/cecil/temp/inputEmacs... +;; > +;; > it's in files.el, save-buffer, AFAIS +;; > +;; > (if (and modp (buffer-file-name)) +;; > (message "Saving file %s..." (buffer-file-name))) +;; > +;; > commenting out these lines should cancel the message + +;; The problem with that is that it only works for me. But I found a way. +;; I replaced: + (write-file output-file)) +;; with: + (set-visited-file-name output-file) + (basic-save-buffer)) + +;; But maybe there should be more consideration for the possibility that +;; Emacs is used as a batch program. + + +;; > > Wrote /home/cecil/temp/inputEmacs + +;; I still have to find something for this. + +;; That is not possible I am afraid. In the C-source there is a call to +;; message_with_string. + +#+END_SRC +* vectors and lists +#+BEGIN_SRC emacs-lisp +;; From: pjb@informatimago.com (Pascal J. Bourguignon) +;; Newsgroups: gnu.emacs.help +;; Date: Fri, 09 Oct 2009 19:19:49 +0200 +;; To: help-gnu-emacs@gnu.org +;; Envelope-To: andreas.roehler@easy-emacs.de + +;; Nordlöw writes: + +;; > If I have an association list say, +;; > +;; > '( +;; > ("key" sym1 val1 num1) +;; > ("key2" sym2 val2 num2) +;; > ) +;; > +;; > , where each entry is a fixed sequence of various objects. + +;; If this is an a-list, then you could write it as: + + (("key1" . (sym1 val1 num1)) + ("key2" . (sym2 val2 numb2))) + +;; to show that it is a list of cons cells. + +;; (a . (b c d)) <=> (a b c d), but the first notation shows that you +;; consider it as a list of cons, and notably that you don't expect nil +;; ie. () to be in the toplevel of the a-list. + +;; Also, if we write the a-list properly like this, we can better answer +;; the following question: + +;; > I might +;; > aswell use a vector to represent an entry in this alist, right? + +;; You cannot use a vector instead of the cons cells of the a-list, but +;; you can use a vector as a value of an a-list entry. Values can be of +;; any type. In the case of emacs lisp, you could also easily use +;; vectors (or any other type) as keys in an a-list, since it uses equal +;; to compare keys. + + (("key1" . [sym1 val1 num1]) + ("key2" . [sym2 val2 num2]) + ([?k ?e ?y ?3] . [sym3 val3 num3])) + +;; > In this case, what do I gain by using a vector instead of list? + +;; In general, vectors take half the space of lists, and access to the +;; nth element is done in O(1) instead of O(n) with lists. However, +;; adding or removing an element in a vector is O(n) while in the case of +;; lists, it may be O(1) (prepending an element or removing the first +;; element or one of the few firsts elements) or O(n) (inserting, +;; appending an element or removing the nth element). + +;; > What about performance?: aref() faster than nth() only for large +;; > vectors? + +;; aref has to compute a multiplication and a sum, before doing one +;; memory load to get the element. In the case of emacs lisp, the +;; multiplication is always by the same fixed factor AFAIK. + +;; nth has to do n memory loads to get the element. + +;; So indeed, aref will probably be faster than nth, even for indices as +;; small as 1 or 0. + +;; > Is there vector-variant of assoc()? + +;; No. Unless you count hash-tables as a vector variant. + +;; > If not, why? + +;; Because there's no point. The advantage of using a list for a-list, +;; apart from the historical simplicity, is that you can easily prepend +;; the a-list with new associations, and therefore use the a-list in a +;; purely functional way. + + (defun f (bindings) + (let ((val (cdr (assoc 'x bindings)))) + (if (zerop val) + (list val) + (cons val (f (cons (cons 'x (1- val)) bindings)))))) + + (let ((bindings '((y . 0) (x . 1)))) + (list (f (cons (cons 'x 2) bindings)) + (cdr (assoc 'x bindings)))) + ;; --> ((2 1 0) 1) + +;; Note: you could use (require 'cl) (acons key value a-list) + ;; instead of (cons (cons key value) a-list). + +;; > Has any one already written such a function? + +;; Not AFAIK, but you can write it. However, the semantics of assoc +;; require a sequential search of the keys in the list, so there would be +;; no gain. On the contrary, we would now have O(n) complexity to +;; prepend a new entry to the a-vector. + +;; -- +;; __Pascal Bourguignon__ +#+END_SRC -- 2.11.4.GIT