Created
January 22, 2018 16:24
-
-
Save BilalQadri/ea7ceecdf922349540c94473be443343 to your computer and use it in GitHub Desktop.
biwascheme utility functions and macros
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
(define (rassoc key alist) ;; remove alist entry with key | |
(define (eq- pair) | |
(not (string=? key (car pair)))) | |
(filter eq- alist)) | |
(define (capitalize str) | |
(let* ((f (substring str 0 1)) | |
(s (substring str 1 (string-length str)))) | |
(string-append (string-upcase f) s))) | |
(define (get-val symbol alist) ;; get alist value | |
(let ((val (assoc symbol alist))) | |
(if val | |
(cdr val) | |
nil))) | |
(define (set-val symbol value alist) ;; set alist value | |
(let ((old-val (assoc symbol alist))) | |
(if old-val | |
(set-cdr! old-val value) | |
nil))) | |
(define (sub1 value) | |
(- value 1)) | |
(define (now) | |
(js-eval "Date.now()")) | |
(define-macro (to-assoc! lst) ;; plist to alist (list "src" "image.png") -> (list ("src" . "image.png")) | |
`(let () | |
(define (loopi lst) | |
(if (null? lst) | |
nil | |
(cons (cons (car lst) (cadr lst)) (loopi (cddr lst))))) | |
(loopi ,lst))) | |
(define (reload) ;; reload page | |
(js-invoke location "reload" #t)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment