Overview
Comment: | Reworked howto. Added s:shared-hash, added s:if to sugar.scm |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | selfcontained |
Files: | files | file ages | folders |
SHA1: |
9cde8a89e86d4ba210d63cb5c2fc5087 |
User & Date: | matt on 2013-09-22 17:35:20 |
Other Links: | branch diff | manifest | tags |
Context
2013-10-26
| ||
04:26 | Added some sugar; a default to s:shared-get and s:label check-in: 53f9eeed61 user: matt tags: selfcontained | |
2013-09-22
| ||
17:35 | Reworked howto. Added s:shared-hash, added s:if to sugar.scm check-in: 9cde8a89e8 user: matt tags: selfcontained | |
05:25 | Added some document snippets. Improved page handling/loading logic to provide message if page not found and option to not compile pages check-in: 886293086d user: matt tags: selfcontained | |
Changes
Modified doc/howto.txt from [cc3668b264] to [9ad6dc4f19].
1 2 3 | 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | - + + - + - - + + - - + + + + - - + + + - - + + + - - + + + - - + + + - - + + + - - + + + + + + + + + + + + + + + + - - + + + - - - | Gotchas! ======= |
Modified setup.scm from [370e79d111] to [b6762fc909].
︙ | |||
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | + + + + + + + + + + + + | (session:del! s:session "*sessionvars*" key)) ;; utility to get all vars as hash table (define (s:session-get-sessionvars) (sdat-get-sessionvars s:session)) ;; inputs ;; (define (s:get-input key) (session:get-input s:session key)) (define (s:load-model model) (session:load-model s:session model)) (define (s:model-path model) (session:model-path s:session model)) ;; share data between pages calls ;; (define (s:shared-hash) (sdat-get-shared-hash s:session)) (define (s:shared-set! key val) (hash-table-set! (sdat-get-shared-hash s:session) key val)) (define (s:shared-get key) (hash-table-ref (sdat-get-shared-hash s:session) key)) ;; http://foo.bar.com/pagename/p1/p2 => '("p1" "p2") ;; (define (s:get-page-params) (sdat-get-page-params s:session)) (define (s:db) (sdat-get-conn s:session)) |
︙ |
Modified sugar.scm from [08f3dbeadf] to [8c9838f5ec].
︙ | |||
20 21 22 23 24 25 26 27 | 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + | ;; [(_ s x y) (if (s:get s) x y)])) ;; ;; ;; (define-syntax s:if-test ;; (syntax-rules () ;; [(_ s x) (if (string=? "yep" s) x (list "s:if not"))] ;; [(_ s x y) (if (string=? "yep" s) x y)])) ;; Some of these routines use: ;; ;; http://www.cs.toronto.edu/~gfb/scheme/simple-macros.html ;; ;; Syntax for defining macros in a simple style similar to function definiton, ;; when there is a single pattern for the argument list and there are no keywords. ;; ;; (define-simple-syntax (name arg ...) body ...) ;; (define-syntax define-simple-syntax (syntax-rules () ((_ (name arg ...) body ...) (define-syntax name (syntax-rules () ((name arg ...) (begin body ...))))))) ;;====================================================================== ;; syntatic sugar items ;;====================================================================== ;; We often seem to want to include stuff if a conditional is met ;; otherwise not include it. This routine makes that slightly cleaner ;; since using a pure if results in #<undefined> objects. (admittedly they ;; should be ignored but this is slightly cleaner I think). ;; ;; NOTE: This has to be a macro or the true clause will be evaluated ;; whether "a" is true or false ;; If a is true return b, else return '() (define-simple-syntax (s:if a b) (if a b '())) ;; Using the Simple-Syntax System ;; ;; The syntax for defining macros in this system is similar to that for defining functions. In fact if the macro has a fixed number of arguments the syntax is identical. For example: ;; ;; ; Define a simple macro to add a value to a variable. ;; ; ;; (define-simple-syntax (+= variable value) ;; (set! variable (+ variable value))) ;; ;; ; Use it. ;; ; ;; (define v 2) ;; (+= v 7) ;; v ; => 9 ;; ;; For a fixed number of arguments followed by an unknown number of arguments we use ... after a single argument to represent the unknown number (possibly zero) of arguments. For example, let's revise our definition of += to allow zero or more values to be added: ;; ;; ; Define a simple macro to add a zero or more values to a variable ;; ; ;; (define-simple-syntax (+= variable value ...) ;; (set! variable (+ variable value ...))) ;; ;; ; Use it ;; ; ;; (define v 2) ;; (+= v 7) ;; v ; => 9 ;; (+= v 3 4) ;; v ; => 16 ;; (+= v) ;; v ; => 16 ;; |