Sign in to follow this  
  • entries
    73
  • comments
    131
  • views
    54686

Touch and accelerometer functionality available fo

Sign in to follow this  

293 views

Posted from http://jlongster.com/blog/:

--------------------------------------------

Touch and accelerometer functionality available for Scheme on the iPhone

July 20, 2009



I have finished the Gambit Scheme libraries for touch and accelerometer support. The green smudge was produced by my fingers, and the orange smudge was produced by tilting the phone.

I've introduced a basic events system. To capture a an event, you define an event handler using DEFINE-EVENT-HANDLER. Currently, the only events implemented are "touches-began", "touches-moved", "touches-ended", "touched-cancelled", and "did-accelerate". The arguments of the event are the same as they would be in Objective-C.

Here's an example, taken from the application shown above:

(define-event-handler (touches-began touches event)
(for-each (lambda (touch)
(let ((loc (UITouch-location touch)))
(add-point (car loc) (cdr loc))))
touches))

(define-event-handler (touches-moved touches event)
(for-each (lambda (touch)
(let ((loc (UITouch-location touch)))
(add-point (car loc) (cdr loc))))
touches))

(define-event-handler (did-accelerate device accel)
(define (shift n weight)
(+ n (* weight 70)))

(add-point (shift 150 (UIAcceleration-x accel))
(shift 100 (- (UIAcceleration-y accel)))))

** Download **

I'm still polishing up a few things in these FFIs, but they are ready to use. Soon, I will create a separate github project for Gambit Scheme FFIs. For now, they are included in my gambit scheme on the iphone example project.

Specifically:

lib/ffi/osx.scm
lib/ffi/osx#.scm
lib/ffi/iphone.scm
lib/ffi/iphone#.scm
lib/events.scm

Don't forget to setup a few hooks in your Objective-C app, as seen here (accelerometer) and here (touch).

You can view this iphone application included in my github project as well for example usage.
Sign in to follow this  


4 Comments


Recommended Comments

I'd not seen the original post, but I'd just like to be one of the first to say that Scheme + iPhone is both cool and disgusting.

Share this comment


Link to comment
Thanks, besides the disgusting part! If you are implying Scheme is disgusting, I would heartily beg to differ. It's the only language that keeps me sane.

Share this comment


Link to comment
Quote:
Original post by okonomiyaki
Thanks, besides the disgusting part! If you are implying Scheme is disgusting, I would heartily beg to differ. It's the only language that keeps me sane.


I would assume so, since you're using scheme and all. But yes, I do find pretty much anything in the Lisp branch of the evolutionary tree to be rather distasteful (albeit conceptually elegant).

Share this comment


Link to comment
Quote:
Original post by Telastyn
Quote:
Original post by okonomiyaki
Thanks, besides the disgusting part! If you are implying Scheme is disgusting, I would heartily beg to differ. It's the only language that keeps me sane.


I would assume so, since you're using scheme and all. But yes, I do find pretty much anything in the Lisp branch of the evolutionary tree to be rather distasteful (albeit conceptually elegant).


I respect that. I think you have a fair point. There are two main things which remove it's ugliness:

* After using it for a while, you really do stop seeing the parenthesis. And, to stimulate that even more, your code editor should be able to use a gray-ish font on the parenthesis, so they literally are barely noticeable.

* Gambit Scheme has an infix syntactic extension (see documentation), so you can avoid prefix notation when it truly is ugly, usually in mathematical formulas:


(define (calculate x y)
\5+3-(sin(x)*cos(y)-6)/3.14;


Prefix notation has many benefits otherwise.

Also, paredit.el for Emacs makes editing Lisp code a dream. It's so hard for me to go back to editing code with ambiguous syntax.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now