File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,17 @@ def examples_data(input_dir, output_fn):
191191 'julia' : shutil .which ('julia' ),
192192}
193193
194+ def reset_code (lang ):
195+ '''
196+ some code to reset local identifyers, in order to speed up execution (to avoid restarts)
197+ while avoid side effects of previous examples (mostly, I guess)
198+ '''
199+ reset = {
200+ 'sage' : 'reset()' ,
201+ 'python' : '%reset -f'
202+ }
203+ return reset .get (lang .lower (), '' )
204+
194205def language_to_kernel (lang ):
195206 data = {
196207 "sage" : "sagemath" ,
@@ -223,6 +234,9 @@ def get_jupyter(language, restart=True):
223234
224235def exec_jupyter (language , code , restart = False ):
225236 client = get_jupyter (language , restart = restart )
237+ if not restart :
238+ # if we don't restart, prepend a reset instruction
239+ code = '\n ' .join ([reset_code (language ), code ])
226240 msg_id = client .execute (code )
227241 outputs = []
228242 errors = []
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ code: |
2424 print("k: %s" % k)
2525 s = (1 - sqrt(k))^2
2626 print("s: %s" % s)
27+ test : false
2728---
2829title : Symbolic Function
2930descr : |
@@ -38,6 +39,7 @@ code: |
3839 @interact
3940 def f_interact(x=(0, 100)):
4041 print 'f({}) = {}'.format(x, f(x))
42+ test : false
4143---
4244title : Multiple Sliders
4345descr : |
@@ -50,3 +52,4 @@ code: |
5052 print("k: %s" % k)
5153 print("j: %s" % j)
5254 print("l: [%s, %s]" % l)
55+ test : false
Original file line number Diff line number Diff line change @@ -107,13 +107,15 @@ descr: |
107107
108108 *Warning*: when defining a symbolic function like `f(x) = x^2`, the variable `x`
109109 will not be a symbolic variable. So the code
110+
110111 ```
111112 x = 7
112113 print x
113114 f(x) = x^2
114115 print x
115116 ```
116- will print `7` and then `x`.
117+
118+ will print `7` and then `x`.
117119code : |
118120 def f(x):
119121 return 2*x
You can’t perform that action at this time.
0 commit comments