Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Camlp4 and Cocoa
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-06-09 (12:42)
From: Joel Reymont <joelr1@g...>
Subject: Camlp4 and Cocoa
I'm trying to figure out how to define Cocoa classes in OCaml. The  
definition needs to be parsed somehow, to make invoke code that  
registers the classes with the Objective C runtime.

I think camlp4 can be somehow used to parse a regular OCaml class  
definition and figure out the ObjC based on the types used. Trouble  
is, I'm not even sure what this would look like.

Please let me know if you have any suggestions!

I'm including the original ObjC as well as the equivalent Scheme code  
using the excellent Chicken Scheme Cocoa bridge.

     Thanks, Joel

--- Original Objective-C ---

@interface ConverterController : NSObject {
   IBOutlet id dollarField;
   IBOutlet id rateField;
   IBOutlet id totalField;

- (IBAction)convert:(id)sender;

--- Chicken Scheme ---

(define-objc-class ConverterController NSObject ((outlet: amountField)
                                                   (outlet: dollarField)
                                                   (outlet: rateField)
                                                   (outlet: converter))
    (- VOID ((convert: ID sender))
       (let* ((currency (@ @dollarField float-value))
              (rate     (@ @rateField   float-value))
              (amount   (@ @converter   convert-currency: currency
                                        at-rate: rate)))
         (@ @amountField set-float-value: amount)
         (@ @rateField select-text: self))))

--      - EasyLanguage to C# translator  - Blog