Created
April 29, 2012 14:41
-
-
Save heiko-henrich/2550875 to your computer and use it in GitHub Desktop.
parens saving macros for Nu
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
# wraplist.nu - parens saving convenience macros and function for Nu | |
# Heiko Henrich - 2012 - heiko.henrich@gmail.com | |
;; Nu Boolean is false for '() and 0 !!! | |
;; if you test for lisp truth, that means everything but nil == '() | |
;; use this | |
(function nn? (x) | |
(not (eq (send x class) NSNull))) | |
;; divlist divides a list until del and puts the first part in the car of the result | |
;; the delimiter del is removed | |
(function divlist (lst del) | |
(if (and | |
(nn? (car lst)) | |
(nn? (cdr lst)) | |
(not (eq (car lst) del))) | |
(then | |
(set div (divlist (cdr lst) del)) | |
(cons | |
(cons | |
(car lst) | |
(car div)) | |
(cdr div))) | |
(else | |
(cons | |
'() | |
(cdr lst))))) | |
;; wraplist wraps up a list with del | |
;; that means it puts the part before del in the car of the result | |
;; and does the same thing with that car recursively | |
;; example: (wraplist '(1 . 3 4 . 345 3 . 3 5 1 5) '.) | |
;; result: ((((1) 3 4) 345 3) 3 5 1 5) | |
(function wraplist (lst del) | |
(set div (divlist lst del)) | |
(if (nn? (cdr div)) | |
(then | |
(wraplist div del)) | |
(else | |
lst))) | |
# macro for objective c messages: | |
;; (.. SymbolInfoCenter sharedSymbolInfoCenter | |
;; <- symbolArray | |
;; <- map: (x| x description) | |
;; <- select: (x| string-start-equal x partial) | |
;; <- sortedArrayUsingBlock: (| a b | a caseInsensitiveCompare: b) | |
;; ) | |
;; expands to: | |
;; (((((SymbolInfoCenter sharedSymbolInfoCenter) symbolArray) map: (x| x description)) | |
;; select: (x| string-start-equal x partial)) sortedArrayUsingBlock: (| a b | a caseInsensitiveCompare: b)) | |
;; which is kind of awkward and just for lisp junkies who are highly addicted on parentheses | |
(macro .. (*expr) | |
(wraplist *expr '<-)) | |
# block/lambda convenience macros | |
;; usage (| a b | + a b) => (do (a b) (+ a b)) | |
;; | |
(macro | (*block) | |
(set div (divlist *block '|)) | |
`(do ( ,@(car div) ) ,(cdr div) ) ) | |
;; usage (x| * x x) => (do (x) (* x x)) | |
;; | |
(macro x| (*block) | |
`(do ( x ) ,*block) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment