<div>Hi, I am a newbie of Gambit Scheme coming from Clojure.</div><div>Currently I am trying to build an iOS app in Gambit.</div><div>I have successfully done the following:</div><div>1. Built 4.6.6-devel git version (snapshot of two weeks ago) of Gambit using llvm-gcc </div>
<div>2. Built Gambit REPL using iOS SDK 6.1 by using both clang and llvm-gcc from Xcode.</div><div>3. Minimized the remote REPL part of Gambit REPL and created a simple app </div><div>3.1. Created a scheme file, init.scm, to register and change the text of the UILabel.</div>
<div><br></div><div>;; The whole init.scm</div><div>(declare (standard-bindings) </div><div>         (extended-bindings) </div><div>         (block) </div><div>         (fixnum) </div><div>         ;(not safe)</div><div>         )</div>
<div><br></div><div>(c-define-type UILabel* (pointer "UILabel"))</div><div><br></div><div>(c-declare "#import <UIKit/UIKit.h>")</div><div>(define current-label #f)</div><div><br></div><div>(c-define (register-label label) (UILabel*) void "register_label" ""</div>
<div>          (set! current-label label))</div><div><br></div><div>(define change-label-text</div><div>  (c-lambda ((pointer "UILabel")) void #<<c-code</div><div>            ___arg1.text = @"Text changed.";</div>
<div>c-code</div><div>))</div><div><br></div><div>3.2. In Xcode, I defined a viewDidLoad method as below, which prints "Hello Wolrd" and then passes the label to the scheme function register_label().</div><div><br>
</div><div>// Part of VIewController.m</div><div>- (void)viewDidLoad</div><div>{</div><div>    [super viewDidLoad];</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>// Do any additional setup after loading the view, typically from a nib.</div>
<div>    </div><div>    _label = [[UILabel alloc] init];</div><div>    _label.text = @"Hello World";</div><div>    [_label setLineBreakMode:UILineBreakModeWordWrap];</div><div>    [_label setNumberOfLines:0];</div>
<div>    _label.frame = CGRectMake(0, 225, 320, 30);</div><div>    _label.textAlignment = UITextAlignmentCenter;</div><div>    [self.view addSubview:_label];</div><div>    </div><div>    _timer = nil;</div><div>    _queuedActions = [[NSMutableArray alloc] init];</div>
<div>    </div><div>    gambit_setup();</div><div>    register_label(_label);</div><div>    repl_server_start();</div><div>    [self heartbeat_tick];</div><div>}</div><div><br></div><div>So far, I have successfully built this simple app. I can connect to the remote REPL of iOS Simulator from the Emacs Inferior Lisp, and even able to change the text of the label dynamically by doing like (change-label-text current-label).</div>
<div><br></div><div>Now it seems that I can develop iOS apps, but I want to go further with the interactive development using the REPL.</div><div>What I want to do is like:</div><div>1. Redefine the change-label-text function by changing the text like "New text!"</div>
<div><br></div><div>2. Create a loadable library</div><div>gsc -cc-options "-arch i386 -x objective-c -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300" -ld-options "-framework CoreFoundation -framework Foundation -framework UIKit" lib/init.scm</div>
<div><br></div><div>3. Do below in REPL</div><div>(define old-label current-label)</div><div><br></div><div>4. Load the loadable library init.o1 from the REPL</div><div><br></div><div>5. Do below in REPL</div><div>(change-label-text old-label)</div>
<div><br></div><div>6. Then an error in Xcode and the app terminates.</div><div>2013-02-27 17:38:31.305 gambit-test[61410:11303] *** NSForwarding: warning: selector (0x87a6f44) for message 'setText:' does not match selector known to Objective C runtime (0xabb96d)-- abort</div>
<div>2013-02-27 17:38:31.306 gambit-test[61410:11303] -[UILabel setText:]: unrecognized selector sent to instance 0x8284a50</div><div>2013-02-27 17:38:31.306 gambit-test[61410:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel setText:]: unrecognized selector sent to instance 0x8284a50'</div>
<div>*** First throw call stack:</div><div>(0x21a4012 0x15e1e7e 0x222f4bd 0x2193bbc 0x219394e 0x87a6e07 0x44b0c0)</div><div>libc++abi.dylib: terminate called throwing an exception</div><div><br></div><div><br></div><div>I can  create and load a loadable library with no errors. It seems that something is missing.</div>
<div>Does anyone know how to solve this kind of problem?</div><div><br></div><div>Thanks,</div><div>Tatsuya Tsuda</div>