by PuercoPop · 11y ago · 0 comments
[0]: http://ergoemacs.org/emacs/elisp_grep_string_inside_tag.html
(let (var1 (var2 0))
(when condition
(setq var1 (var1-initializer-form))
...)))
is just silly. Only the inner scope of the when uses var1, or any of the vars; it could just be: (when condition
(let ((var1 (var1-initializer-form))
(var2 0))
...))
Never do two-step initialization of a variable without an excellent reason; it's just sloppy otherwise.[0]: https://www.reddit.com/r/lisp/comments/29ufoc/it_is_not_hard...
About Scheme's regexp SRFI, have you seen rx.el? Not quite but I like it myself.
lispm point is nice (and no one can argue about evaluation order and count), but beside the battle-tested aspect, `loop` scares the crap out of me. That's even more a reason to prefer things that avoids it in my mind, mentally small building blocks and patterns versus huge macro-based sublanguages. Yes general and probably super-efficiently implemented, but .. nah.
(defvar xah-left-brackets '("(" "{" "[" "<" "〔" "【" "〖" "〈" "《" "「" "『" "“" "‘" "‹" "«" )
"List of left bracket chars.")
(progn
;; make xah-left-brackets based on xah-brackets
(setq xah-left-brackets '())
(dotimes (x (- (length xah-brackets) 1))
(when (= (% x 2) 0)
(push (char-to-string (elt xah-brackets x))
xah-left-brackets)))
(setq xah-left-brackets (reverse xah-left-brackets)))
(defvar xah-right-brackets '(")" "]" "}" ">" "〕" "】" "〗" "〉" "》" "」" "』" "”" "’" "›" "»")
"list of right bracket chars.")
(progn
(setq xah-right-brackets '())
(dotimes (x (- (length xah-brackets) 1))
(when (= (% x 2) 1)
(push (char-to-string (elt xah-brackets x))
xah-right-brackets)))
(setq xah-right-brackets (reverse xah-right-brackets)))
In CL this is just: (defun every-nth (seq start n &aux (len (length seq)))
(loop for i = start then (+ i n)
while (< i len)
collect (elt seq i)))
(defvar xah-left-brackets (every-nth xah-brackets 0 2))
(defvar xah-right-brackets (every-nth xah-brackets 1 2))
Write useful building blocks. Don't duplicate code. Get rid of low level imperative code.Bonus points for a more efficient version for lists.
Now you might think that this is also unidiomatic:
(setq totalCnt (1+ totalCnt))
Turns out, though, that Elisp doesn't have modify macros, except in the CL compatibility package.What Xah is doing is the same as the accepted SO answer for incrementing a local variable:
http://stackoverflow.com/questions/6858894/how-to-increment-...
On the setq, I what I meant was iterating through setqs and while (and I seem to recall even catch/throw) as agumonkey mentioned.
Then again, 'in my mind', idiomatic elisp uses cl-lib :D. so (cl-incf total-count) would be better. snakeCase is unidiomatic as well.