Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Scheme hits the App Store (ventonegro.org)
52 points by prakash on Oct 23, 2009 | hide | past | favorite | 30 comments


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.



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


> The Scheme code deals with position evaluation, alpha-beta pruning, transposition tables, move legality, different strategies and so on.

For some reason, those sound like compiler optimizations instead of game calculations...


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


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.


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...


how is Gambit compared to Chicken?


In what respect?

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


Of course I jumped directly to the tabulated results but found...

A helluva a way to present statistics: green values representing the CPU time in milliseconds of the fastest software while all other values on a row are normalized multipliers of that value. No attention paid to significant digits whatsoever. Jeez! Wonder what Edward Tufte would say about this one? And once again I'm grateful to not be one of the 8% of men who are color blind.


FWIW, color blindness is probably not an issue with that chart, as green is the only saturated color, and it seems to be of a dark enough value that it would not be confused with the other colors in the chart.

You can preview an approximation of what a page looks like to the color blind here: http://www.vischeck.com/vischeck/vischeckURL.php


I am colorblind. The page seemed alright (colorwise).


Also color blind. I agree with eru.


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?


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.


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.


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...

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


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.


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...

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


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.


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


This is fixed in 4.5.3.

The crash was caused by printing the value of the procedure in the nested REPL. Using define in nested REPLs works, but you'll get a warning about it.


I've had these crashes, and I can tell you exactly what it is that is causing it...

You're not at the top level of the repl, for some reason, defining things at a lower nesting level of the repl sometimes produces crashes, it's annoying yes, but it's not a huge disaster :)

if you use ",t" to get back to the top level after an error, you shouldn't see those crashes.


thanks for the heads up JazzScheme. I am gonna give that IDE a try.


I have to prefix this with the fact that I've only barely touched Chicken. I've been using Gambit for a few months.

Performance: See benchmarks above.

FFI: Gambit's is very clean. I've used this extensively, and people that are doing iPhone/Objective-C stuff with it are using the FFI. I can't comment on Chicken's FFI.

Libraries: I'm guessing Chicken wins here. The egg system seems more developed and has more packages than Gambit's Black Hole.

Installation: I know Gambit is painless on Linux and Mac. I can't speak to Windows nor to which Linux distros package it.

Licensing: I have to correct you here. Gambit is dual licensed: LGPL 2.1 and Apache 2.

Support: Chicken's community and IRC room seem active. Gambit's are too; detailed answers are rapid on the mailing list.


Installation:

For the record, I looked into prebuilt binaries for Gambit. The support is quite extensive for Mac and Windows.

Mac: installers provided for G3, G4, G5, X86, X86-64, and universal binaries.

Windows: installers for Gambit compiled with MSVC and mingw.

The latest version (4.5.2) is available here: http://www.iro.umontreal.ca/~gambit/download/gambit/v4.5/pre...

Canonical download link: http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Distri...


Success stories: For gambit, there is a recent 3d game [1] and Termite [2]. Termite is a version of an Erlang like system written in scheme. There may be others I'm not aware of though.

[1] http://www.gamerizon.com/

[2] http://code.google.com/p/termite/


For the curious, the game is called Quantz. It's available on Windows and OS X.


FYI: you can edit your comments here (within two hours of the original post).


Most important software launch of the week.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: