unstable.rkt (5639B)
1 #lang typed/racket 2 3 (require phc-toolkit) 4 (require "eval-get-values.rkt") 5 6 (provide (all-from-out phc-toolkit) 7 (all-from-out "eval-get-values.rkt")) 8 9 ;; Types 10 (provide AnyImmutable) 11 ;; Functions 12 (provide (rename-out [∘ compose])) 13 ;; Macros 14 ;(provide mapp) 15 (provide comment) 16 17 (require (for-syntax syntax/parse 18 racket/syntax)) 19 20 (define-syntax (comment stx) 21 #'(values)) 22 23 (define-type AnyImmutable (U Number 24 Boolean 25 True 26 False 27 String 28 Keyword 29 Symbol 30 Char 31 Void 32 ;Input-Port ;; Not quite mutable, nor immutable. 33 ;Output-Port ;; Not quite mutable, nor immutable. 34 ;Port ;; Not quite mutable, nor immutable. 35 36 ;; I haven't checked the mutability of the ones 37 ;; inside in the #||# comments below 38 #| 39 Path 40 Path-For-Some-System 41 Regexp 42 PRegexp 43 Byte-Regexp 44 Byte-PRegexp 45 Bytes 46 Namespace 47 Namespace-Anchor 48 Variable-Reference 49 |# 50 Null 51 #| 52 EOF 53 Continuation-Mark-Set 54 |# 55 ;; We definitely don't Undefined, it's not mutable 56 ;; but it's an error if present anywhere 99.9% of 57 ;; the time. Typed/racket is moving towards making 58 ;; occurrences of this type an error, anyway. 59 ; Undefined 60 #| 61 Module-Path 62 Module-Path-Index 63 Resolved-Module-Path 64 Compiled-Module-Expression 65 Compiled-Expression 66 Internal-Definition-Context 67 Pretty-Print-Style-Table 68 Special-Comment 69 Struct-Type-Property 70 Impersonator-Property 71 Read-Table 72 Bytes-Converter 73 Parameterization 74 Custodian 75 Inspector 76 Security-Guard 77 UDP-Socket ;; Probably not 78 TCP-Listener ;; Probably not 79 Logger ;; Probably not 80 Log-Receiver ;; Probably not 81 Log-Level 82 Thread 83 Thread-Group 84 Subprocess 85 Place 86 Place-Channel 87 Semaphore ;; Probably not 88 FSemaphore ;; Probably not 89 Will-Executor 90 Pseudo-Random-Generator 91 Path-String 92 |# 93 (Pairof AnyImmutable AnyImmutable) 94 (Listof AnyImmutable) 95 ; Plus many others, not added yet. 96 ;; Don't include closures, because they can contain 97 ;; mutable variables, and we can't eq? them. 98 ; -> 99 ; maybe Prefab? Or are they mutable? 100 )) 101 102 #| 103 (define-syntax (mapp stx) 104 (syntax-parse stx 105 [(_ var:id lst:expr body ...) 106 #'(let ((l lst)) 107 (if (null? l) 108 '() 109 (let ((result (list (let ((var (car l))) 110 body ...)))) 111 (set! l (cdr l)) 112 (do ([stop : Boolean #f]) 113 (stop (reverse result)) 114 (if (null? l) 115 (set! stop #t) 116 (begin 117 (set! result 118 (cons (let ((var (car l))) 119 body ...) 120 result)) 121 (set! l (cdr l))))))))])) 122 |# 123 124 125 ;; TODO: this does not work, because Null is (Listof Any) 126 ; (mapp x (cdr '(1)) (* x x)) 127 128 ;; TODO: foldll 129 (define-syntax (foldll stx) 130 (syntax-parse stx 131 [(_ var:id acc:id lst:expr init:expr body ...) 132 #'(let ((l lst)) 133 (if (null? l) 134 '() 135 (let ((result (list (let ((var (car l))) 136 body ...)))) 137 (set! l (cdr l)) 138 (do ([stop : Boolean #f]) 139 (stop (reverse result)) 140 (if (null? l) 141 (set! stop #t) 142 (begin 143 (set! result 144 (cons (let ((var (car l))) 145 body ...) 146 result)) 147 (set! l (cdr l))))))))])) 148