-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcj-source-wraps.scm
77 lines (60 loc) · 1.98 KB
/
cj-source-wraps.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;; Copyright 2013-2018 by Christian Jaeger <ch@christianjaeger.ch>
;;; This file is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License (GPL) as published
;;; by the Free Software Foundation, either version 2 of the License, or
;;; (at your option) any later version.
(require cj-source
(improper-list-1 improper*-map))
(export source-wrap-1
source-wrap-1*
source-wrap-n
source-wrap-1+
source:symbol-append ;; aliased to source.symbol-append by oo-util
source.length
source.car
source.cdr
source.pair?
source.symbol?
source.string?
source.number?
;; move?
symbol->keyword
source.symbol->keyword
source.symbol->string
;;/move?
source.map
source.improper*-map)
(include "cj-standarddeclares.scm")
(define (source-wrap-1 fn)
(lambda (x)
(fn (source-code x))))
(define (source-wrap-1* fn)
(lambda (x)
(possibly-sourcify (fn (source-code x)) x)))
(define (source-wrap-n fn)
(lambda xs
(apply fn (map source-code xs))))
(define (source-wrap-1+ fn)
(lambda (x . rest)
(apply fn (source-code x) rest)))
(define (source-wrap-_1-n fn)
(lambda (a . rest)
(apply fn a (map source-code rest))))
(define source:symbol-append (source-wrap-n symbol-append))
;; XX keep source information? rarely used for symbols though.
(define source.length (source-wrap-1 length))
(define source.car (source-wrap-1 car))
(define source.cdr (source-wrap-1 cdr))
(define source.pair? (source-wrap-1 pair?))
(define source.symbol? (source-wrap-1 symbol?))
(define source.string? (source-wrap-1 string?))
(define source.number? (source-wrap-1 number?))
;; hm move to another lib?
(define (symbol->keyword v)
(string->keyword (symbol->string v)))
(define source.symbol->keyword (source-wrap-1 symbol->keyword))
(define source.symbol->string (source-wrap-1 symbol->keyword))
;; from cj-source-util-2.scm
(define source.map source-map)
;; from predicates.scm
(define source.improper*-map (source-wrap-_1-n improper*-map))