RunOnUiThread Macro
My first Scheme macro! (define-syntax run-ui (syntax-rules () ((run-ui activity body …) (android.app.Activity:runOnUiThread activity (runnable (lambda () body … )))))) To test the macro (from Kawa) (require 'syntax-utils) (display (expand '(run-ui *activity* (android.util.Log:v "kawa-hello" "test log") ((Toast:makeText *activity* "Good Morning Australia" Toast:LENGTH_LONG):show)))) To run it: java -jar kawa-1.11.jar -f test.scm Note: don’t do this, java [...]
Kawa scheme and event handlers
Kawa makes writing eventhandlers rather easy by providing a short hand for creating anonymous classes from lambdas. Reference An anonymous class is commonly used in the Java platform where a function language would use a lambda expression. Examples are call-back handlers, events handlers, and run methods. In these cases Kawa lets you use a lambda [...]
Listing Network Interfaces on Android with Kawa
The following works for me: (define (Enumeration->list (enum :: java.util.Enumeration)) :: list (let loop ((ls '())) (if (enum:hasMoreElements) (loop (cons (enum:nextElement) ls)) (reverse ls)))) (require 'srfi-1) (define (enumerate-network-interfaces) (map (lambda (x :: java.net.InetAddress) x:host-address) (filter (lambda (x :: java.net.InetAddress) (not (x:is-loopback-address))) (concatenate (map (lambda (x :: java.net.NetworkInterface) (Enumeration->list x:inet-addresses)) (Enumeration->list java.net.NetworkInterface:network-interfaces)))))) … which is the [...]
Scheme REPL on Android Experiments
My first attempt of running Scheme on Android weren’t very good, and Helmut Eller provided a nicer implementation of REPL which I reproduce here: (define-syntax try-with-resources (syntax-rules () ((try-with-resources () body …) (begin body …)) ((try-with-resources ((var val) (vars vals) …) body …) (let ((var val)) (try-finally (try-with-resources ((vars vals) …) body …) (invoke var [...]