In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to learn elisp in JavaScript, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
It may seem difficult for us JS users to learn Emacs Lisp, but it's all yesterday. Because although elisp is old, library keeps pace with the times. When we start with elisp's meritorious dash.el, we can write elisp in a second.
Keep the gossip short and get to the point.
Dash.el is a tool for dealing with arrays for elisp users. Its one-to-one correspondence with JS's array is summarized as follows:
It is divided into 1) array conversion (iterative) 2) array conversion (non-iterative) 3) logical judgment 4) operational data structure 5) sorting five aspects.
1. Iterative method array variant Transform (pure function without side effecs)
The most important point of functional programming is that you do not need to pay attention to iteration's dirty-details. Here, the functional iterative method is classified, and the array method of JS is mapped to elisp's bash.el library one by one:
Reuduce (- reduce-from (lambda (acc val) (+ acc val)) 0'(4 7 8 10));; = > 29; 2.map (- map (lambda (val) (* val 2))'(4 7 8 10));; = > (8 14 16 20); 3.flat (- flatten-n 2'((1 2) ((3 4) (5 6)) = > (1 234 (56)); 4.flatMap with no couterpart;; 5.repeat as fill ELISP > (- repeat 100) (0 000 000 000); 6.each with side effects (- each'("x"y"z") (lambda (val) (princ val);; > "xyz" 2. Non-iterative method array variant non-side-effects
The above six kinds of iterative pure functions are transform for the array. Here, the pure functions of non-iterative methods are singled out and classified:
; 1.concat (- concat'("x"y"z")'(356)); = > ("x"y"z" 3 56); 2.format for join (format "% s" ("x" y "" z "));; = >" (x y z) "; 3.slice (- slice'(" x "" y "" z "w") 1 3) = > ("y"z") 3. Logical judgment of the array logic-predicates (non-side-effect)
After the six methods of the function normal form, we continue to examine the higher-order functions used for logical judgment:
;; 1.-filter as js filter (- filter (lambda (v) (and (> v 30))
< v 100))) '(23 76 98 10)) ;; =>(76 98); 2. Find or first as js find (- find (lambda (v) (and (> v 30))
< v 100))) '(23 76 98 10)) ;; =>76;; 3.-find-index as js findIndex (- find-index (lambda (v) (and (> v 30))
< v 100))) '(23 76 98 10)) ;; =>1;; 4.contains-p as js includes (- contains-p'(23 76 98 10) 76); t; 5.-elem-index as indexOf (- elem-index 76'(23 76 98 10));; = > 1;; 6.some (- some (lambda (v) (and (> v 30))
< v 100))) '(23 76 98 10)) ;; =>T;; 7.every (- every (lambda (v) (and (> v 30))
< v 100))) '(23 76 98 10)) ;; =>False IV. Data structure operation
Array can be used as the carrier of two kinds of abstract structural data: stack and queue respectively.
1) push 2) pop 3) shift 4) unshift 5) splice (splice is a special method because the original array was changed and placed here)
;; 1.append element to the end of array (array.push) (append'(23 76 101 89) 67);; > (23 76 101 89. 67);; 2.nbutlast to remove last element (array.pop) (nbutlast'(23 76 101 89));; = > (23 76 101);; 3.remove first element (array.shift) ELISP > (let ((23 76 89)) (pop l) l) (76 89) 4. Add element to the front (array.unshift) ELISP > (let (23 76 89)) (push 12 l) l) (12 23 76 89); 5.insert to list at position n (array.splice) (- insert-at 1'x'(a b c));; = > (a x b c); let arr = [a, b, c]; arr.splice (1, 0, x); arr 6.replace at potion (array.splice) (- replace-at 09'(012345)); = > (9 12345); let arr = [1,2,3,4,5]; arr.splice (0,1,9); arr five, array sort
It ends with a ubiquitous sort, and both sort and reverse are modified directly on the original array, that is, the inplace operation.
(- sort'
< '(3 1 2)) ;; =>(1 2 3) (- sort'> 'class3' > (3 12)); = > (3 21);
From the above summary, we found that even without looking at the documentation, we can start writing elisp immediately.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.