Created
May 13, 2014 19:28
-
-
Save jordonbiondo/3e9cebd37035da54d103 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; gel.el --- A collection of code golf macros and aliases for emacs lisp | |
| ;; | |
| ;; Filename: gel.el | |
| ;; Description: A collection of code golf macros and aliases for emacs lisp | |
| ;; Author: Jordon Biondo ([email protected]) | |
| ;; Created: Wed Mar 12 10:21:11 2014 (-0400) | |
| ;; Version: 0.0.1 | |
| ;; Package-Requires: () | |
| ;; Last-Updated: Wed Mar 12 10:22:12 2014 (-0400) | |
| ;; By: jordon | |
| ;; Update #: 3 | |
| ;; URL: | |
| ;; Doc URL: | |
| ;; Keywords: | |
| ;; Compatibility: | |
| ;; | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; | |
| ;;; Commentary: | |
| ;; | |
| ;; | |
| ;; | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; | |
| ;;; Change Log: | |
| ;; | |
| ;; | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; | |
| ;; This program is free software; you can redistribute it and/or | |
| ;; modify it under the terms of the GNU General Public License as | |
| ;; published by the Free Software Foundation; either version 3, or | |
| ;; (at your option) any later version. | |
| ;; | |
| ;; This program is distributed in the hope that it will be useful, | |
| ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| ;; General Public License for more details. | |
| ;; | |
| ;; You should have received a copy of the GNU General Public License | |
| ;; along with this program; see the file COPYING. If not, write to | |
| ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth | |
| ;; Floor, Boston, MA 02110-1301, USA. | |
| ;; | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; | |
| ;;; Code: | |
| (defun ~o (&rest args) | |
| "Make cyclic list" | |
| (setcdr (last args) args)args) | |
| (defmacro e (p v &rest body) | |
| "Like let but with one binding. (m a b x) == (let ((a b)) x)" | |
| `(let ((,p ,v)) ,@body)) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Formatting | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defmacro n (thing) | |
| `(string-to-number (format "%f" ,thing))) | |
| (defmacro nd (thing) | |
| `(string-to-int (format "%d" ,thing))) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Looping | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias '@ 'while) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; output | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias 'p 'print) | |
| (defalias 'm 'message) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Setters | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias 'sd 'setcdr) | |
| (defalias 'sa 'setcar) | |
| (defalias 'q 'setq) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Stack | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias '^ 'pop) | |
| (defalias 'v 'push) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Lists | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias '& 'list) | |
| (defalias 'c (lambda (car &optional cdr) (cons car cdr))) | |
| (defalias 'a 'car) | |
| (defalias 'aa 'caar) | |
| (defalias 'a3 'caaar) | |
| (defalias 'a4 'caaaar) | |
| (defalias 'd 'cdr) | |
| (defalias 'da 'cddr) | |
| (defalias 'd3 'cdddr) | |
| (defalias 'd4 'cddddr) | |
| (defalias 'ad 'cadr) | |
| (defalias 'da 'cdar) | |
| (defalias '~ 'last) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; map reduce | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias '~> 'mapcar) | |
| (defalias '~< 'reduce) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Lambdas | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias 'l 'lambda) | |
| (defalias 'l~ 'apply-partially) | |
| (defmacro || (&rest body) | |
| "lambda with one arg predefined _" | |
| `(lambda (_) ,@body)) | |
| (defmacro ||: (&rest body) | |
| "lambda with two args predefined _, -" | |
| `(lambda (_ -) ,@body)) | |
| (defmacro | (a &rest body) | |
| "lambda with one arg given A" | |
| `(lambda (,a) ,@body)) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; buffers, files | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias '~b 'with-temp-buffer) | |
| (defalias '~f 'with-temp-file) | |
| (defalias '!b 'with-current-buffer) | |
| (defalias 'i 'insert) | |
| (defalias '.bs 'buffer-string) | |
| (defalias '.bss 'buffer-substring) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Shell | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias '!! 'shell-command) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; current | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defalias '.w 'current-word) | |
| (defalias '.t 'current-time) | |
| (defalias '.b 'current-buffer) | |
| (defalias '.c 'current-column) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; misc | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defmacro ++ (p) `(incf ,p)) | |
| (defmacro -- (p) `(decf ,p)) | |
| (defalias '... (apply-partially 'sit-for 1) | |
| "Wait one second... good for continuous output funcs.") | |
| (defun r (n &optional m) | |
| "range function. (r 5) -> '(1 2 3 4 5) | |
| (r 5 10) -> '(5 6 7 8 9 10)" | |
| (if m (mapcar (apply-partially '+ (1- n)) (r (1+(- m n)))) | |
| (let ((x (cons n nil))) | |
| (while (> (decf n) 0) (setq x (cons n x))) x))) | |
| (defun r (n &optional m) | |
| (if m(~>(l~ '+(1- n))(r(1+(- m n))))(e x(c n)(@(>(-- n)0)(q x(c n x)))x))) | |
| (let((a'(?\^D?\^H?\^O?\^P?\^W?*)))(setcdr(last a)a)(while(print(pop a)))) | |
| (provide 'gel) | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;;; gel.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some nice stuff here, very cool.