Skip to content

Instantly share code, notes, and snippets.

@hsjunnesson
Created September 5, 2013 21:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hsjunnesson/6456440 to your computer and use it in GitHub Desktop.
Save hsjunnesson/6456440 to your computer and use it in GitHub Desktop.
Update: I've made a more thorough example of embedding Clojure logic in an iPhone app. Toes, a tic-tac-toe game in clojure on the iPhone. https://github.com/hsjunnesson/toes
2013-09-05 23:24:37.777 Prime[4204:c07] 1
2013-09-05 23:24:37.779 Prime[4204:c07] 0.732028842267092
2013-09-05 23:24:37.780 Prime[4204:c07] 0.2530017011838238
2013-09-05 23:24:37.781 Prime[4204:c07] 0.22892546997679017
2013-09-05 23:24:37.781 Prime[4204:c07] 0.5423003204364027
2013-09-05 23:24:37.782 Prime[4204:c07] 0.6065306597126334
2013-09-05 23:24:37.783 Prime[4204:c07] 0.44399788140114904
2013-09-05 23:24:37.783 Prime[4204:c07] 0.15345314921321815
2013-09-05 23:24:37.784 Prime[4204:c07] 0.13885046809469812
2013-09-05 23:24:37.784 Prime[4204:c07] 0.32892187595578626
2013-09-05 23:24:37.785 Prime[4204:c07] 0.3678793973166949
2013-09-05 23:24:37.785 Prime[4204:c07] 0.2692981492646763
2013-09-05 23:24:37.786 Prime[4204:c07] 0.09307381417486162
2013-09-05 23:24:37.786 Prime[4204:c07] 0.0842172501146435
2013-09-05 23:24:37.786 Prime[4204:c07] 0.19950128720145147
2013-09-05 23:24:37.787 Prime[4204:c07] 0.2231301069498101
2013-09-05 23:24:37.787 Prime[4204:c07] 0.16333747577456365
2013-09-05 23:24:37.788 Prime[4204:c07] 0.056451985048343076
2013-09-05 23:24:37.788 Prime[4204:c07] 0.05108045593331044
2013-09-05 23:24:37.788 Prime[4204:c07] 0.12100369876387275
2013-09-05 23:24:37.789 Prime[4204:c07] 0.13533525097001878
2013-09-05 23:24:37.789 Prime[4204:c07] 0.09906925265999281
2013-09-05 23:24:37.789 Prime[4204:c07] 0.0342400257592264
2013-09-05 23:24:37.790 Prime[4204:c07] 0.030981659456104205
2013-09-05 23:24:37.790 Prime[4204:c07] 0.07339232847755396
2013-09-05 23:24:37.791 Prime[4204:c07] 0.08208501819439779
2013-09-05 23:24:37.791 Prime[4204:c07] 0.06008869862406271
2013-09-05 23:24:37.791 Prime[4204:c07] 0.02076782681175789
2013-09-05 23:24:37.792 Prime[4204:c07] 0.01879116203578023
2013-09-05 23:24:37.792 Prime[4204:c07] 0.044514621737261346
2013-09-05 23:24:37.793 Prime[4204:c07] 0.04978710397786021
(ns thrust-clj.plot)
(defn bounce
[x]
(/ (.abs js/Math (.cos js/Math (* x 2 (.-PI js/Math))))
(.pow js/Math (.-E js/Math) x)))
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"js"];
if (filePath) {
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSString *source = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (source) {
JSContext *context = [[JSContext alloc] init];
[context evaluateScript:source];
JSValue *plotFun = [context evaluateScript:@"thrust_clj.plot.bounce"];
for (float t = 0; t < 3.0; t += 0.1f) {
JSValue *v = [plotFun callWithArguments:@[@(t)]];
NSLog(@"%@", [v toString]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment