1

I'm writing an Objective C application on Mac OS X 10.7, and I need to solve a problem with arithmetic constraints. For example, I have two equations for a rectangle, a and b are the lengths of the sides:

P=2(a+b) (perimeter)
A=ab     (area)

I identified this problem as a constraint satisfaction problem. The user should be able to specify a and A, and have the solver compute b and P. I have found an implementation of this in http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html#%_idx_3516 , but I'm not sure if there is a clean way to call LISP programs from Objective C. I'm looking for something that could provide me an Objective C interface to the solver, or maybe compile the LISP program into an Objective C library. Otherwise, a minimalist open source constraint solver would fit my needs.

alecail
  • 3,993
  • 4
  • 33
  • 52

4 Answers4

1

There actually are people building lisp systems for iOS. (Disclaimer - I've never used lisp in my life)

This SO question common-lisp-on-iphone-ios points to the funcall blog, whose author has the ecl-iphone-builder on github

This SO question: has-anyone-got-any-code-examples-of-ecl-lisp-for-iphone-development ends up at the same destination.

Hopefully that is a good start for you.

EDIT

I totally missed that this was not an iOS question.

But there are people running lisp on OSX. This SO question has some solutions: what-is-the-best-scheme-or-lisp-implementation-for-os-x

This blog: common-lisp-on-mac-os-x is more nuts and bolts (and was the top of google for me)

Community
  • 1
  • 1
Peter M
  • 7,309
  • 3
  • 50
  • 91
  • I'm interested in a solution that works on MacOS X 10.7, not iOS. I'll have a closer look and see if it is specific to iOS. – alecail Apr 30 '12 at 12:30
  • Ooops .. my mistake .. I actually discounted the purely OSX info I saw! But there are lisp solutions for OSX – Peter M Apr 30 '12 at 12:37
1

That book's examples are written in Scheme, a dialect of Lisp (there are many). The book is somewhat old, but most implementations of Scheme today would be able to execute the code examples in that book. There are several implementations of Scheme that run on OSX, but examples from the book would be easily ported to Common Lisp too - there's only minor difference, really. More than that, I don't believe it would take that much time to write them in C/Obj-C. The examples in the book are meant to be general-purpose programming, nothing extremely peculiar to the Lisp dialect they use.

(The article in Wiki also has links to implementations, I don't want to advertise any particular one to not to sound biased - besides, I don't have much experience using it outside academia).

Probably, if you were looking for a general-purpose tool for proving mathematical theorems, then you could look into Coq - this is the language that specializes exactly on the task. It also runs on any Unix or Unix-like OS.

0

If this is the only problem you need to solve, it's easier than that. You can solve b in terms of A and a:

b = A / a

Then you can find P using the first equation you posted.

joerick
  • 16,078
  • 4
  • 53
  • 57
0

The nu programming language is a Lisp dialect that can integrate with Objective-C, including being embedded in an Objective-C application. http://programming.nu/index

I've heard very good things about it, but have never used it.

You might also just try translating that constraint solver app into Objective-C.

Chris Perkins
  • 799
  • 4
  • 8