4 ms·
As far as dash.el goes, I find lispm's critique of dash.el pretty convincing[0]. However a more profilic emacs coder fried of mine is undeterred and keeps using
by PuercoPop 11y ago
As far as dash.el goes, I find lispm's critique of dash.el pretty convincing[0]. However a more profilic emacs coder fried of mine is undeterred and keeps using modern emacs lisp. I think much of the community does as well.
[0]: https://www.reddit.com/r/lisp/comments/29ufoc/it_is_not_hard_to_read_lisp_code/cioznk5 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.
- agumonkey 11y agoIIUC rx.el is a sexp dsl/interface to build vanilla regex down the line right ? from what I remember about scheme SRFI is not the 'syntax' but the return values, you get streams of match, then you can leverage, folds and maps. 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.
- lispm 11y agoSee this Xah Lee Elisp code: (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.
- agumonkey 11y agoOh I wasn't arguing that CL loop was a far better solution than while loops (unless you process too long lists). I just became very very+ fond of academic recursive style. Here's a singly-linear variant for fixed steps. (defun ab (l) "I'm too lazy to reverse the result back." (defun _ (l a b f) (if (null l) (if f (list a b) (list b a)) (_ (cdr l) b (cons (car l) a) (not f)))) (_ l nil nil t)) (ab '()) (ab '(1)) (ab '(1 2)) (ab '(1 2 3 4 5 6 7 8 9 10)) ;; ((9 7 5 3 1) (10 8 6 4 2)) (ab '(1 2 3 4 5 6 7 8 9 10 11)) ;; ((11 9 7 5 3 1) (10 8 6 4 2)) I don't know how cute or ugly a solution for variable step could be though. `ab` is a nice partitioning building block, less general than every-nth surely. ps: Straight from the land of wishful lisping (defun abn (l n) (defun ono (n) "builds a cons oo cycle of size n" 'unicorn) (defun noo (c) "rotates a cons cycle by one" 'unicorn) (defun cooons (c v) "cons v to the head of c" 'unicorn) (defun _ (l c) (if (null l) c (_ (cdr l) (noo (cooons c (car l)))))) (_ l (ono n)))
- lispm 11y agoNested DEFUNs? Not in Lisp. In Common Lisp use LABELS for recursive local functions. I'd avoid recursive code like that as much as possible. I'd write: (defun ab (l) (loop while l collect (pop l) into a while l collect (pop l) into b finally (return (list a b))))
- agumonkey 11y agoOops, I forgot defun affected the global namespace. Your last example is nice. I had to read the CLHS loop to have a clue about linearity of multiple termination clauses though :) ps: funny, while googling I even found some lisp checker with a rule about nested defuns (## define-lisp-pattern nested-defuns) http://www.cs.northwestern.edu/academics/courses/325/programs/cs325/lisp-rules.lisp http://www.cs.northwestern.edu/academics/courses/325/program...
- klibertp 11y agoSome Schemes - most notably Racket, which I use the most - allow for nested defines. Your code actually is a valid Racket code after polishing the differences in naming and syntax a bit: #lang racket (define-syntax-rule (defun name (arg ...) . body) (define (name arg ...) . body)) (define nil null) (define t #t) (defun ab (l) ;; "I'm too lazy to reverse the result back." (defun _ (l a b f) (if (null? l) (if f (list a b) (list b a)) (_ (cdr l) b (cons (car l) a) (not f)))) (_ l nil nil t)) (ab '()) (ab '(1)) (ab '(1 2)) (ab '(1 2 3 4 5 6 7 8 9 10)) ;; ((9 7 5 3 1) (10 8 6 4 2)) (ab '(1 2 3 4 5 6 7 8 9 10 11)) ;; ((11 9 7 5 3 1) (10 8 6 4 2)) ...and you don't need to worry about recursion limits thanks to mandatory TCO.