
 Scheme hits the App Store - prakash
http://www.ventonegro.org/2009/10/scheme-hits-the-app-store/
======
stuntmouse2
MIRROR (site appears to be down):

I believe I have got the first Scheme application past Apple review into the
iTunes App Store. It is yet another Reversi clone, called Reverso. It is a
combination of 90% Scheme and 10% Objective-C, written with Gambit-C Scheme.
James Long has already shown how to compile Gambit-C for the iPhone, and I
started from there. My Scheme code is compiled to C by Gambit and later by GCC
to produce native ARM code, bundled in a static library, which is ok with the
iPhone SDK license agreement. The Objective-C then calls the library as a pure
C library. The Scheme code deals with position evaluation, alpha-beta pruning,
transposition tables, move legality, different strategies and so on. The
Objective-C code deals with sound, animations, GUI, user preferences,
basically everything that calls the iPhone OS API. Reversi was chosen because
I like strategy games and it is much more algorithmic than artistic, and I am
no artist.

The performance of the code is excellent. I used some Gambit-specific
declarations, only fixnum arithmetic, pre-allocated a large heap, and called
the garbage-collector every time the user needed to think. The search is not
memory intensive, but the transposition tables are. I did not write a specific
hash function but relied on Gambit-C’s table type. The boards used during
search were retrieved from a pool (the newest Gambit-C has made subu8vector-
move! a public API), so they did not put pressure on the garbage-collector. In
the end it was a very successful experiment. Developing with Scheme is orders
of magnitude more productive than with most other languages. Gambit-C is also
one of the best Scheme compilers out there, and made my job a lot easier.

~~~
stuntmouse2
LINKS:

Reverso:
[http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftwa...](http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=334979538&mt=8)

Gambit Scheme:
[http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_P...](http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page)

James Longster - Scheme on the iPhone:
[http://jlongster.com/blog/2009/06/17/write-apps-iphone-
schem...](http://jlongster.com/blog/2009/06/17/write-apps-iphone-scheme/)

~~~
stuntmouse
Correction: That should read 'James Long' instead of 'James Longster'.

------
pistoriusp
I have no idea why everyone wants to get around objective-c, it's really not
complicated to learn.

~~~
elai
Because dictionaries, object-arrays, strings and other fundamentals are way
more verbose than they should be:

someDictionary["bla"][3] vs. [[someDictionary objectForKey:@"bla"]
objectAtIndex:3];

someDictionary["bla"] = 5 vs.[someDictionary setObject:[NSNumber
numberWithInt:5] forKey:@"bla"];

"%@ - %@" % (date, name) vs. [NSString stringWithFormatString:@"%@ -
%@",date,name];

Smalltalk is a lot better than objective-c even, because you can define binary
& unary operators with singular symbols to make a far more concise syntax. You
think you have done alot of work sometimes in objective-c when you find out
that you were just extracting some values out of variables and putting it into
this or that dictionary or array.

------
futuremint
Good news to hear. Objective-C is alright as a language, but I'm excited to
hear about some of my favorite languages running on the platform, like this
Scheme and Smalltalk (<http://isqueak.org/>). I suppose I have no excuse to
NOT make an app in my spare time anymore...

------
morphir
how is Gambit compared to Chicken?

~~~
stuntmouse
In what respect?

Benchmarks by Marc Feeley of Gambit:
<http://www.iro.umontreal.ca/~gambit/bench.html>

~~~
morphir
In general. Who has the best performance? Who has the best ffi support? The
most and best library support? Does anyone have a success story (case study)?
Does anyone offer a painfree setup? Chicken is BSD, while Gambit i GPL - so
chicken maybe preferred for its less restrictive lisence?

~~~
NikkiA
Personally, I think chicken is the least interesting of the 3 (bigloo, gambit
and chicken) scheme->c compilers.

Bigloo has the best FFI, hands down, it's simple, it offers mapping, and
doesn't require you write chunks of C for each definition. It's also slightly
easier to call from, and embed in, C, in my experiments.

Bigloo has better potential performance, due to the strict typing abilities.

Gambit has the best performance, this is probably debatable though, at least
according to the benchmarks I've seen.

Gambit also has the best portability, bigloo and chicken only 'mostly' work on
win32 - bigloo's socket support has some annoying bugs on win32, for example,
and I've had problems with chicken even compiling properly on win32, often
failing to find compilers, etc.

Whether Chicken or Bigloo has the best built-in module system is debatable,
personally I'd prefer bigloo's over the two. Gambit's lack of a built-in
module system is offset by 'black hole' which is progressing nicely, and is
possibly better than both bigloo's and chicken's, in the long term.

License wise, Gambit is dual (LGPL and Apache), Chicken is BSD and Bigloo is
LGPL. All are pretty much equal, really, from an end-user's point of view and
none of them should impart any restrictions on any programs you create with
them, as far as I can tell.

Edit: I knew I forgot something, I didn't mention the '4th' option -
JazzScheme. Which is really just a version of Gambit with an integrated IDE, a
module system similar to bigloo's, and a bunch of pre-built library mappings
(Gtk, OpenGL, and a bunch more, iirc). It has potential, but for me, I don't
like to have to use a provided IDE, I prefer emacs, and the 'command line'
version of jazz isn't really finished yet.

~~~
morphir
when I play around with Gambit (gsi) I often end up with bus errors. This
implies the word: 'half-assed' to me. So that is directly annoying and will
guaranteed put new users off. Crashing is never good.

~~~
stuntmouse
That's extremely surprising. I'm sure the maintainers would be eager to hear
about your experiences. Care to provide example code which triggers a crash
with a little detail about version and platform?

The best place to post would be the mailing list [1] or the bug tracker [2].

[1] [https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-
lis...](https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list)

[2] <http://www.iro.umontreal.ca/~gambit/bugzilla/>

~~~
morphir
3> (define x (lambda (y) (* 2 y))) __* WARNING -- defining global variable: x
3 > x Bus error

Gambit v4.5.2 OSX 10.5

Of course, I do know that x should not be evaluated. For that have to type (x
3). But its still annoying, and very unnecessary. In DrScheme/PLT I get a: > x
#<procedure:x> Explicitly telling me its a procedure.

~~~
stuntmouse
I've reproduced your crash. The issue is that you're using define within a
nested REPL, which isn't supported [1].

However, a segfault is really not acceptable. I'll file a report for this.

[1]
[http://www.iro.umontreal.ca/~gambit/doc/gambit-c.html#Debugg...](http://www.iro.umontreal.ca/~gambit/doc/gambit-c.html#Debugging)

Relevant section: "Note that some special forms (define in particular) can
only be evaluated in the global interaction environment."

~~~
NikkiA
I'm fairly sure that the nested repl 'define' being allowed at all is a fairly
recent change, I seem to recall just getting an error when trying to define in
a nested repl in 4.4.x.

~~~
stuntmouse
Right, it looks like a regression in 4.5.*. 4.4.4 is fine.

------
stuntmouse
Most important software launch of the week.

