Line | |
---|
1 | |
---|
2 | == live-define |
---|
3 | [[toc:]] |
---|
4 | Hack to simplify some cases of interactive development. |
---|
5 | |
---|
6 | |
---|
7 | === Requirements |
---|
8 | * matchable |
---|
9 | |
---|
10 | |
---|
11 | === Documentation |
---|
12 | <macro> (define name (lambda arguments body ...))</macro> |
---|
13 | <macro> (define (name arguments) body ...)</macro> |
---|
14 | |
---|
15 | A macro that replaces the standard Scheme {{define}} with one that, when it detects that a procedure is bound to {{name}}, mutates that procedure in place instead of binding the name to a new procedure. |
---|
16 | |
---|
17 | This is useful in situations where you pass the procedure {{name}} as an argument to another and want to change itâs behavior while the program is running. For example by using your text editorâs facility to send code to a running instance of csi. |
---|
18 | |
---|
19 | '''Please note that this is only intented to be used within the interpreter and will probably break in various ways if used in compiled code''' |
---|
20 | |
---|
21 | |
---|
22 | === Examples |
---|
23 | This is a pretty contrived example, but it shows the modified behavior quite well. |
---|
24 | |
---|
25 | Run it with {{csi -s example.scm}} |
---|
26 | |
---|
27 | <enscript highlight="scheme"> |
---|
28 | (import srfi-18) |
---|
29 | |
---|
30 | ;; try commenting this next line to see the standard behavior |
---|
31 | (import live-define) |
---|
32 | |
---|
33 | (define (thread-proc thunk) |
---|
34 | (lambda () |
---|
35 | (let lp () |
---|
36 | (thread-sleep! 1) |
---|
37 | (thunk) |
---|
38 | (lp)))) |
---|
39 | |
---|
40 | (define (the-thunk) |
---|
41 | (print "hi!")) |
---|
42 | |
---|
43 | (thread-start! (thread-proc the-thunk)) |
---|
44 | ;; -> prints "hi!" every second |
---|
45 | |
---|
46 | (thread-sleep! 5) |
---|
47 | |
---|
48 | (define (the-thunk) |
---|
49 | (print "coucou !")) |
---|
50 | ;; -> thread now prints "coucou !" every second |
---|
51 | |
---|
52 | (thread-sleep! 5) |
---|
53 | </enscript> |
---|
54 | |
---|
55 | |
---|
56 | === Version History |
---|
57 | |
---|
58 | ==== Version 1.1 |
---|
59 | 30 November 2018 |
---|
60 | |
---|
61 | * Fix a bug that prevented the redefinition of a symbol imported from a module |
---|
62 | |
---|
63 | |
---|
64 | ==== Version 1.0 |
---|
65 | 30 November 2018 |
---|
66 | |
---|
67 | * Original release |
---|
68 | |
---|
69 | |
---|
70 | === Source repository |
---|
71 | Source available in [[https://www.upyum.com/cgit.cgi/live-define/|a git repository]] |
---|
72 | |
---|
73 | Bug reports and patches welcome! Bugs can be reported to kooda@upyum.com |
---|
74 | |
---|
75 | |
---|
76 | === Authors |
---|
77 | Adrien (Kooda) Ramos |
---|
78 | |
---|
79 | |
---|
80 | === License |
---|
81 | BSD-2-Clause |
---|
82 | |
---|
Note: See
TracBrowser
for help on using the repository browser.