Posts Tagged ‘development’


Single Xcode project for iOS and Mac OS X

Thursday, September 16th, 2010

In Xcode 3.2.4, it’s trivial to create same project for iOS and Mac OS X. Just add a new target into your existing project; if your project is for OS X, then create a new Cocoa Touch Application target. If your project is for iPhone, obviously, craete a new Cocoa Application target. Then do a Get Info on your new target, and choose the appropriate Base SDK. For simplicity, let’s presume you’re adding an OS X target to an iPhone project.

However, after doing this, you’ll quite probably find that despite the choice of Base SDK in your target (you used Get Info on it, didn’t you?), Xcode has locked the target SDK onto whatever your project originally used. That is, now you’ll find it locked onto iPhone, despite switching to the OS X target using the Overview dropdown (in the top left of your Xcode project).

So how do you actually switched the now-locked SDK? Quite simple. Hold the option key while clicking in the Overview box. Instead of only two-entries device list (if you have an iPhone target selected), and then Active Configuration, Active Target, Active Executable and Active Architecture, by holding the option key while clicking on Overview you’ll also find the Active SDKs list. By switching it to the appropriate OS, you’ll be able to compile the application.

Of course, now comes the hard part: actually porting the code to the new platform.
E49PEQSG669E

iPhone development: Bits/c++config.h: No such file or directory

Tuesday, April 27th, 2010

Developing for iPhone with some C++ code? Suddenly getting this error after installing a beta SDK?

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk/usr/include/c++/4.2.1/bits/stl_algobase.h:65:0 Bits/c++config.h: No such file or directory in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk/usr/include/c++/4.2.1/bits/stl_algobase.h

Note the bolded folder. Change into it and make a symlink from arm-apple-darwin9 to arm-apple-darwin10. Please note that Apple has fixed this already at one upgrade of beta SDK (I had this error before too, but I still didn’t get 4.0 beta 2 so I didn’t check) so it’s reasonable to assume they will do this again.

cd Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk/usr/include/c++/4.2.1/
ln -s arm-apple-darwin9 arm-apple-darwin10

PS I don’t think posting this violates any NDA. Especially since origin for this solution is also public.

Sorting folder in Xcode

Wednesday, March 3rd, 2010

To sort a folder by name or to sort a folder by type when working in Xcode, select the folder in Groups & Files, click on Edit menu, choose Sort and finally choose either By Name or By Type.

About writing a Logo interpreter, part 3

Saturday, September 12th, 2009

Let’s resume from yesterday!
So we have arguments for procedures separated by whitespace, procedure calls separated by whitespace. We also have function arguments and function calls separated by whitespace. So what you can get is this (we’ll also simultaneously demonstrate a list):
PR “JOHN FD 10 RT 2*FIRST FIRST [[45 1 1] 1] FD 10 RT 90
See that RT? It has only one argument. So does the first call to FIRST, and the second call to FIRST. How fortunate you cannot actually invert multiplication arguments and write:
RT FIRST FIRST [[45 1 1] 1]*2
In this case list will be used as the left argument of multiplication, which will fail, and if it didn’t, then FIRST would fail because it cannot operate with a number.
What’s my pain here?
I basically designed the interpreter to analyze arguments as follows. It’s got a few more gotchas (operator precedence) but this is basic modus operandi.
  1. Ok, token is of type “procedure name”, that’s cool.
  2. Once we’ve established that, let’s examine not what’s immediately afterwards, but the second one afterwards. C++ equivalent: *(it + 2) if iterator it is pointing to the procedure name itself.
  3. It’s a token of type “operator”? Cool! Let’s kick into special “eliminate-the-operator” mode.
  4. Grab the left side, grab the right side, calculate calculate calculate!
  5. Eliminate operator token and right side token. Replace left side token with the result of the operation.
As already mentioned, this works in case you don’t take operator precedence into consideration. It also works if you don’t consider function calls. But what’s such a big deal, really?
See, once that pesky thing called precedence kicks in, things get nasty. You have to go through that entire argument, find the multiplications, and parse them first. Find multiplication or division, get its left and right side, eliminate the left and right side, rinse and repeat. Then repeat the procedure for remaining tokens (plus and minus operations) until the argument is one-and-only.
So that’s what ONLogo does.
What’s bad about this approach, it’s utterly useless when functions show up in the game. How the hell am I supposed to know how long the argument is, with regard to token count … without actually evaluating the damn thing? I could figure out how long a function call is… if its arguments were simple data types or bracket-delimited expressions (remember, tokenizer turns the expression into a single token).
But what happens when its arguments are also non-bracket-delimited expressions (including plus and minus, multiplication and division, and even extra function calls)? The whole idea very quickly falls down. It’s rather hard to satisfy both infix mathematical operators and the prefix function calls, and nearly impossible with the architecture outlined!
It may be possible by analyzing it all recursively, somehow. But my parser is sequential, not recursive.
Now, I feel that I suck here. But probably not. There are numerous “Logo” interpreters out there, but not so many real Logo interpreters. Best ones are UCB Logo (basically for UNIX), Terrapin Logo (commercial) and PC Logo (commercial, by Harvard Associates, no link since it’s from 1992). There are UCB Logo variants with Windows GUI, such as MSW Logo and its post-mortem fork FMS Logo. Here we have two basic dialects that I’m familiar with: UCBLogo (UCBLogo, MSWLogo and FMSLogo share the same core) and Terrapin/PCLogo.
Not so good one is, for example, KTurtle for KDE, which apparently values only turtle graphics, and values translating built in procedures over providing remaining Logo environment. Web site says KTurtle is being rewritten for KDE4, but I have not yet seen the rewrite; the KDE3 version was just not Logo despite several places claiming it’s a Logo. There is also several projects calling themselves Logo, despite just implementing turtle graphics in another language (for example, I saw Logo for Java which just … isn’t Logo).
So what I’m saying is, perhaps it’s really not so easy to write a fully functional Logo interpreter. It might be that it’s not just me that’s stupid.
Hopefully, the class I’m having this semester, PPJ, will provide some useful insight on how to properly do this.
In continuation, I’ll try to explain in greater detail how the tokenizer itself in ONLogo works, and perhaps how the interpretation of the tokens itself works.
Image source: Baby Sea Turtles by minds-eye

This concludes the first series that I’ve began writing in late evening on September 9th, and finished in 0:49 on September 10th. Information provided so you don’t get surprised if the series doesn’t continue — remember, this is autopublished :-)

About writing a Logo interpreter, part 2

Friday, September 11th, 2009

Welcome back!
So let’s begin with those examples.
FD 50
This is a valid program that can be inputted on the command line. (So-called Editor in Logo is just used to store commands for batch execution.) FD is a shorthand for already mentioned FORWARD; depending on where the turtle is facing, it moves it forward, leaving a line behind. Number 50 denotes number of steps (pixel sized unit) the turtle will cross.
Despite this being a “primitive” (Logo’s term for a built-in) “procedure” (function that returns nothing) we can write a declaration:
TO FD :STEPS
Obviously, this receives a single parameter which will be stored in a variable called :STEPS. (:STEPS usually denotes “give me current value of variable :STEPS“, but it’s easier to call all variables that way, to show what they really are.)
This would mean everything is simple, right? Guess again! Let’s examine the command PRINT, or PR — we’ll pass it a word (denoted by quote symbol):
PR “CHOCOLATE
One would guess this is an example of procedure with one argument as well:
TO PR :ARG
However, PR canonically receives one argument, but nothing prevents it from receiving multiple arguments! So, Logo actually permits you to do this:
(PR “CHOCOLATE “WITH “ICE “CREAM)
That is, we’ve just passed an arbitrary-length list of arguments once we’ve added brackets. Sounds like Perl. I’m luckily not aware of any syntax that allows you to declare a user procedure which accepts an arbitrary number of arguments, though. But there are numerous primitives that can do this; not only procedures, but even many primitive functions can do it.
It is trivial, however, to resolve this. Brackets in Logo are always meaning brackets, unless prefixed by a backslash; ONLogo thus stores it all as a single token of type “expression” (like all other bracketed expressions). It just counts the opening and closing brackets, avoiding of course the escaped ones (backslashed), and when the counter comes to zero, that’s an expression. Trivial.
Now, you may notice that logo is separating arguments with whitespaces. That’s ok, right? We can handle that. But, things get interesting when you get to know that Logo also separates commands by whitespace.
PR “ARGUMENT FD 50 LT 90
Now here things get tricky, don’t they? Here’s an invalid program:
PR “ARGUMENT1 “ARGUMENT2 FD 50 LT 90 ; word “ARGUMENT2 in place of the expected procedure-name token
Easily catchable with primitives. But not catchable when user writes a procedure, uses a custom procedure, and the custom procedure itself is not yet defined. (It is defined at run-time, however.) An example is here (also demonstrating writing procedures):
TO SOMETHING :A
PR :A OTHERTHING PR :A ; note, not defined yet
END
TO OTHERTHING ; argumentless procedure
; some code here
END
Awesome, isn’t it? Remember, any source code stored in a file (or in RAM, depending on implementation of editor) is just a batch script; when you load the code from file or from RAM, it gets executed line by line.
This demonstrates that Logo simply cannot verify validity of code prior to execution.
It also introduces another problem. It’s somewhat hard to see where one argument begins, and where it ends. Combined with ability to write multiple commands in single line, Logo is unreadable.
This space-separate-only however also created a problem for my interpreter. See, there’s this awesome thing in Logo called functions. Yes, plain old functions; those are procedures that return something. I just recursively defined function, but that doesn’t matter, that’s in spirit of Logo.
We’ll continue this tomorrow.

Image source: The Turtle Farm at the Cayman Islands by Ev Nucci. CC-PUBLICDOMAIN. Source code manually colorized.

About writing a Logo interpreter, part 1

Thursday, September 10th, 2009

This semester I’m having a class at FER called Computer Language Compiling (Prevođenje programskih jezika, literally c. l. translation). From its Croatian name it is not necessarily dealing with just compilers, but also with interpreters. Anyways, I’ve decided to write this as a multipart series about my experiences with writing a Logo interpreter called ONLogo.

You may or may not know about programming language Logo. It’s an interpreted language compared by some to Lisp whose best known feature is so-called turtle graphics. Turtle graphics mean there’s a small icon of a turtle (or alternatively just a triangle) which moves around the screen with commands such as FORWARD 10, and rotates around the screen with commands such as RIGHT 90. The other thing it’s really good with are lists of data, and recursion.

This language is great for teaching children about programming, about basics of graphics, about geometric shapes and about recursive thinking. It’s also sweet for introducing kids to basic operations on sets of data (lists). I’ll immediately say that I’m not convinced anymore it’s the best language to start with: while ease of use of turtle graphics in Logo are unprecedented, I’m also convinced Python is far more general purpose language and including some sort of turtle graphics module would turn it in a much better learning tool than Logo.
It may seem I’m digressing, but I am not. What’s not good about Logo is its horrible syntax. It’s so unorthodox it puts to shame even Python with its blocks-are-indented paradigm and Perl with its there-are-no-arguments—at-least-not-really paradigm, and probably some other languages. (I still think this COBOL example I saw on Coding Horror is worse, though.)
I’ll say a few words why it seems to me that parsing Logo is horrible and unintuitive. I’ll explain my ideas in building ONLogo and say what went wrong and why. Probably I made bad choices when designing it; this is precisely why I’ve decided to post this when I only had one class of PPJ.
I’ll write and publish this series over the course of next few days. I’ll put the series on auto-publish so the series should slowly automatically roll out daily. (Unless I forget to write an installment.) It may however be interrupted by my usual rants :-)
So tomorrow we’ll examine some basic examples of programs.
Image source: Turtle at Antilla Wreck Aruba by Serge Melki. CC-BY license.