funcall http://funcall.posterous.com Most recent posts at funcall posterous.com Thu, 26 May 2011 21:30:00 -0700 ECL for iOS update for ECL-11.1.1, Xocde 4, and SDK 4.3 http://funcall.posterous.com/ecl-for-ios-update-for-ecl-1111-xocde-4-and-s http://funcall.posterous.com/ecl-for-ios-update-for-ecl-1111-xocde-4-and-s

I've committed a new branch of ECL for iOS, which now requires ECL-11.1.1 (latest stable), and produces functioning device binaries for armv6 and armv7 architectures using Xcode 4 and SDK 4.3. This release has been tested on iPhone and iPad devices running iOS 4.3.1.

Please refer to the updated README for further details.

https://github.com/kriyative/ecl-iphone-builder/tree/elf

Please note that the earlier release branch `dragon' has also been updated to work with Xcode 4, and SDK 4.3. However, it continues to be based on ECL-10.4.1.

https://github.com/kriyative/ecl-iphone-builder/tree/dragon

Many thanks to Terje Norderhaug for his help with this update.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/850425/rkris_profile.jpg http://posterous.com/users/15YhdQTJcJP Ram Krishnan kriyative Ram Krishnan
Mon, 20 Dec 2010 05:09:00 -0800 Lisp functions as UI callbacks in ECL/iOS http://funcall.posterous.com/building-user-interfaces-in-eclios http://funcall.posterous.com/building-user-interfaces-in-eclios

There's been a bit of recent interest in building "real" apps using ECL/iOS. While the `eclffi' sample code in the ecl-iphone-builder repo included examples of how to create/call Objective-C classes/methods from Lisp, it was missing the glue to go the other way, which was necessary to implement callbacks in Lisp. I've pushed an update to github which adds this functionality.

As an example I created a subclass of UIButton called UIButtonCB with one instance var called "clickHandler", which can be set to a Lisp function pointer. The UIButtonCB class wires the UIControlEventTouchUpInside event to the specified handler function.

@implementation UIButtonCB

- (id) initWithFrame: (CGRect) aFrame
{
    [super initWithFrame: aFrame];
    clickHandler = Cnil;
    [self addTarget: self action: @selector(clicked:) forControlEvents: UIControlEventTouchUpInside];
    return self;
}

- (void) setClickHandler: (cl_object) fun
{
    register_cb(clickHandler, fun);
}

- (void) clicked: (id) sender
{
    if (Cnil != clickHandler) {
        cl_funcall(2, clickHandler, ecl_foreign_data_ref_elt(&sender,ECL_FFI_POINTER_VOID));
    }
}

- (void) dealloc
{
    remove_cb(clickHandler);
    clickHandler = Cnil;
    [super dealloc];
}

The call to register_cb() ensures that the callback function is protected from GC, and remove_cb() makes the function GC'able again. UIButtonCB can now be wrapped in Lisp with the following FFI glue:

(defun set-click-handler (view fun)
  (when fun
    (c-fficall ((view :pointer-void)
                ((make-callback-function fun) :object))
        :void
      "[#0 setClickHandler: #1];")))

(defun make-button (&rest init-view-args &key title title-color icon
                    on-click (enabled t) &allow-other-keys)
  (let ((view (make-view-instance "UIButtonCB" init-view-args)))
    (set-click-handler view on-click)
    (when icon (set-image view icon))
    (when title (set-title view title))
    (when title-color (set-title-color view title-color))
    (set-enabled view enabled)
    view))

Here's an example of the Lisp code to create a button with an on-click callback, which updates a label:

(let ((n 0)
      (label (make-label "" :frame '(10.0 50.0 300.0 35.0))))
  (add-subview (key-window) label)
  (add-subview (key-window)
               (make-button :frame '(140 230 40 20)
                            :title "click"
                            :background-color (color-argb 1 0.5 0.5 0.5)
                            :on-click (lambda (button)
                                        (declare (ignore button))
                                        (set-text label
                                                  (format nil
                                                          "~d click~:p"
                                                          (incf n)))))))

Obviously, this isn't a very sophisticated approach, but it's a start. It requires subclassing each UIControl or UIView to add the vars to store the Lisp callbacks. I'm sure there's ample room for abstracting or automating some of this boilerplate Objective C code.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/850425/rkris_profile.jpg http://posterous.com/users/15YhdQTJcJP Ram Krishnan kriyative Ram Krishnan
Tue, 14 Dec 2010 16:25:00 -0800 ECL for iOS updated to work with SDK 4.2 http://funcall.posterous.com/ecl-for-ios-updated-to-work-with-sdk-42 http://funcall.posterous.com/ecl-for-ios-updated-to-work-with-sdk-42

I've pushed a new branch (centaur) of the ECL for iOS project to github, which contains a number of fixes to get ECL compiled under the latest 4.2 SDK from Apple. This release has been tested on iPhone and iPad devices running iOS 4.2 as well as the older 3.1.3. Please refer to the updated README for further details.

http://github.com/kriyative/ecl-iphone-builder/tree/centaur

Many thanks to Terje Norderhaug and Anthony Fairchild for their bug reports and feedback.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/850425/rkris_profile.jpg http://posterous.com/users/15YhdQTJcJP Ram Krishnan kriyative Ram Krishnan
Tue, 23 Mar 2010 23:25:00 -0700 Displaying a daily Org-mode agenda reminder in Emacs http://funcall.posterous.com/displaying-a-daily-org-mode-agenda-reminder-i http://funcall.posterous.com/displaying-a-daily-org-mode-agenda-reminder-i

Here's a simple hack to get an Org-mode agenda view to popup in an Emacs buffer, daily at a specified time.

1
2
3
4
5
6
7
8
9
10
11
(defvar daily-agenda-timer (parse-relative-time "9:00 am"))
;; (decode-time daily-agenda-timer)

(defun show-daily-agenda ()
  (unless (time-less-p (current-time) daily-agenda-timer)
    (setq daily-agenda-timer (time-add daily-agenda-timer
(seconds-to-time 86400)))
    (org-agenda-list)))

(add-hook 'display-time-hook 'show-daily-agenda)
(display-time)

The PARSE-RELATIVE-TIME function helps in initializing the DAILY-AGENDA-TIMER using a human readable string.

1
2
3
4
5
6
7
8
9
10
11
12
(defun parse-relative-time (time-str)
  (destructuring-bind (sec min hour day month year dow dst zone)
      (parse-time-string time-str)
    (destructuring-bind (sec1 min1 hour1 day1 month1 year1 dow1 dst1 zone1)
(decode-time)
      (encode-time (or sec sec1)
(or min min1)
(or hour hour1)
(or day day1)
(or month month1)
(or year year1)
(or zone zone1)))))

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/850425/rkris_profile.jpg http://posterous.com/users/15YhdQTJcJP Ram Krishnan kriyative Ram Krishnan
Wed, 10 Feb 2010 07:36:00 -0800 Snapshot of ECL for iPhone http://funcall.posterous.com/snapshot-of-ecl-for-iphone http://funcall.posterous.com/snapshot-of-ecl-for-iphone

I've uploaded a snapshot of fully patched ECL-9.12.3, and Boehm GC sources to help anyone trying to build this environment from scratch. I realize a lot of the external dependencies tend to be in flux, so hopefully this snapshot will provide a fully functional starting point.

The snapshot is available at: http://github.com/kriyative/ecl-iphone-snapshot

The snapshot includes:

  • README
  • build.sh
  • bdwgc/
  • ecl/
  • eclshell/
  • iphone/

The bdwgc/ and ecl/ directories contain the patched sources for Boehm GC, and ECL 9.12.3. The eclshell/ folder has the sources for the sample iPhone app, including a snapshot of slime (CVS head as of 2010-01-29).

The iphone/ folder contains the built product -- a set of header and static library files built for the iPhone architecture. The iphone/universal/ folder contains `fat' versions of the libraries which maybe used with either simulator or device builds.

As always, feedback and patches are welcome.

UPDATE: I moved to a github repo for the snapshot as well. It's easier this way to track any patches that may arise.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/850425/rkris_profile.jpg http://posterous.com/users/15YhdQTJcJP Ram Krishnan kriyative Ram Krishnan
Fri, 29 Jan 2010 16:48:00 -0800 ECL on iPhone update http://funcall.posterous.com/ecl-on-iphone-update http://funcall.posterous.com/ecl-on-iphone-update

I've just checked in a significant set of changes to the ecl-iphone-builder repository, incuding the following updates:

  • builds with ECL 9.12.3
  • requires the CVS head version of the Boehm Weiss collector
  • smoother build process (should "just work")
  • better SLIME integration (with :spawn communication style as the default)
  • expanded `eclshell' example (more goodies to follow)

As always feedback and bug reports are appreciated.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/850425/rkris_profile.jpg http://posterous.com/users/15YhdQTJcJP Ram Krishnan kriyative Ram Krishnan
Tue, 29 Dec 2009 13:10:00 -0800 A lightweight `bind' macro http://funcall.posterous.com/a-lightweight-bind-macro http://funcall.posterous.com/a-lightweight-bind-macro

In my recent work I found myself writing a lot of code that looked like the following:

1
2
3
4
5
6
7
(destructuring-bind (x y)
    point
  (destructuring-bind (x1 y1 w h)
      frame
    (let ((x2 (+ x1 w))
          (y2 (+ y1 h)))
      (and (>= x x1) (<= x x2) (>= y y1) (<= y y2)))))

The above example is a bit contrived, for effect, but hopefully conveys the general idea.

What I wanted was a Clojure style `let' which could destructure inline. There was one Common Lisp implementation (http://common-lisp.net/project/metabang-bind/), which had some nice features, but it was bit much for my needs. So I came up with my own lightweight `bind' macro (see below), which lets me rewrite the above example as:

1
2
3
4
5
(bind (((x y) point)
       ((x1 y1 w h) frame)
       (x2 (+ x1 w))
       (y2 (+ y1 h)))
  (and (>= x x1) (<= x x2) (>= y y1) (<= y y2)))

Way better, IMHO.

Oh, here's the `bind' macro in its entirety:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(defmacro bind (clauses &body body)
  "This macro combines the behaviour of the forms `let*', `destructuring-bind',
and `multiple-value-bind', permitting the following style of binding form:

(bind (((:values m n) (values 10 20))
((a b &key (c 10)) '(1 2))
(x 5))
(+ x a b c m n))
=> 48

This is a more limited and lightweight implementation of some ideas from
metabang-bind (http://common-lisp.net/project/metabang-bind/)."
  (cond
    ((null clauses) `(progn ,@body))
    ((and (listp (caar clauses)) (eq (caaar clauses) :values))
     `(multiple-value-bind ,(cdaar clauses)
          ,@(cdar clauses)
        (bind ,(cdr clauses) ,@body)))
    ((listp (caar clauses))
     `(destructuring-bind ,(caar clauses)
          ,@(cdar clauses)
        (bind ,(cdr clauses) ,@body)))
    (t
     `(let (,(car clauses))
        (bind ,(cdr clauses) ,@body)))))

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/850425/rkris_profile.jpg http://posterous.com/users/15YhdQTJcJP Ram Krishnan kriyative Ram Krishnan
Sat, 12 Dec 2009 09:42:00 -0800 ECL on iPhone (redux) http://funcall.posterous.com/ecl-on-iphone-redux http://funcall.posterous.com/ecl-on-iphone-redux

A while ago Red Daly posted about some great initial work he had done in porting ECL to the iPhone. I contacted him, and worked to clean up some of the external dependencies, and got ECL to run on the simulator and device (with SLIME). I put together an updated Git repo with all my changes, and finally got around to posting about it.

http://github.com/kriyative/ecl-iphone-builder

Hopefully, this will be of use to others.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/850425/rkris_profile.jpg http://posterous.com/users/15YhdQTJcJP Ram Krishnan kriyative Ram Krishnan