ARMbob!
Willard Goosey (5119) 257 posts |
finally playing with Gavin Wraith’s ARMbob and I’m having fun! (decided not to spam up Announcements with this) Done some “hello world” and “what is your name” type stuff in it. Now I’m re-writing silly little BASIC games in it. :-) Bob is so much like C that it’s like coming home, but without the annoying parts. :-) |
||||||
GavinWraith (26) 1563 posts |
High praise indeed. Thank David Betz for that. A salient ingredient of C and Armbob, that is absent from BASIC, is that assignments are expressions, not statements. So you can write and in compound expressions you can capture subexpressions by bunging in an assignment of it to a variable. That makes it easier to follow the golden rule of programming never evaluate the same subexpression twice , in a snappy way. Just assign it to a variable and use the variable later on instead of the subexpression. Of course you can do this in BASIC too, but it is clumsier. Some people accuse C of being unreadably terse, for example, which you might recognize as the key part of the wimp-polling loop.
Lua is like BASIC in that it cannot do this. Assignments are not expressions in Lua, but Lua makes up for this by allowing multi-assignments and functions can return multiple arguments. I used the word salient above because I think these are aspects of syntax that give the language its particular feel. |
||||||
Clive Semmens (2335) 3276 posts |
That sounds like the empty set to me… 8~P |
||||||
GavinWraith (26) 1563 posts |
I have just updated Armbob after finding an error in the library bob:string.string which was causing anything trying to compile it to crash. That is bad and calls for an improvement in error-handling. I have have replaced the binary, bob, by one recompiled with -arch 7 rather than -arch 3. If you are using RPCEmu and need -arch 3 let me know. |
||||||
Willard Goosey (5119) 257 posts |
Updated! Glad I hadn’t started messing with strings yet, mostly FP stuff so far. :-) |
||||||
Willard Goosey (5119) 257 posts |
umm, I think you broke input()!!!! |
||||||
GavinWraith (26) 1563 posts |
Thanks for the heads-up. I think I know why. I am intending to alter the print function so that its first argument can have format specifiers, like fprintf in C. I have also reinstated the original error-handling which now reacts better to syntax errors. I will announce here when the corrected version goes up. OK. I think input () is corrected now. At the suggestion of the latest version of the Acorn C-compiler I changed the LDM/STM commands to LDR/STR but forgot the writeback in the STR commands, so the stack was going crazy. When I have worked out how to do it I will implement some better string-formatting. |
||||||
Willard Goosey (5119) 257 posts |
Yay newest version works! thank you! |
||||||
GavinWraith (26) 1563 posts |
I shall be updating the Help file in !ArmBob over the next few days. So keep downloading! If you have any suggestions for more material, let me know. |
||||||
Steve Pampling (1551) 8170 posts |
I think you should do both arch3 and arch7 on the available downloads – we have a mix of users with and without modern hardware. |
||||||
GavinWraith (26) 1563 posts |
OK; done. I have split out the sources into a separate zip file. |
||||||
Willard Goosey (5119) 257 posts |
Let me look through the docs again, there were a couple of points that weren’t clear to me… |
||||||
GavinWraith (26) 1563 posts |
I have just tried a small comparative test: to fill an array of 1000 elements with the squares of the indices. It comes out, in centiseconds, as
Of course it is only a rough indication. It is quite hard to ensure that code in three different languages is comparable. The programs were:
|
||||||
GavinWraith (26) 1563 posts |
The ArmBob libraries have been cleaned up, and augmented. You can now iterate over objects in a directory (io.dir), read filetypes, size, permissions, date-stamp, etc (io.stat). Debugging ArmBob programs is not straightforward. When Bob compiles it puts no source-code location information into the bytecode, unlike Lua. It was designed originally to be as simple as possible, after all. Debugging compile-time errors is fine, but for run-time errors there is nothing for it but to examine the trace and debug outputs. |
||||||
Colin McMurchie (8817) 21 posts |
I am still playing with !armbob. As a noobie to riscos, I am learning a lot about riscos and the wimp and of course armbob. I have noticed a possible error in the help files. I think the glossary entry for ‘&’ talks of bitwise EOR ( ie ‘^’) rather than bitwise and. |
||||||
GavinWraith (26) 1563 posts |
It does and its a typo. Thanks for pointing it out. Please edit and replace the EOR by AND in the Glossary HTMLfile. I had been thinking of writing more in the way of tutorials about ArmBob but found myself very rusty and making silly syntax errors. I have added a couple of io libraries, namely io.dir for iterating over objects in a directory and io.stat for getting the size, attributes, filetype and datestamp of a file. |
||||||
GavinWraith (26) 1563 posts |
Actually it was supposed to be an example of ArmBob looking like C, or C++, or … :). I have mixed feelings about ArmBob. It was devised by David Betz to illustrate the OOP notion of classes and their instances . I never really took to them as I could not see what was going on. Until, that is, I saw how Lua could implement them as tables, for which my imagination is more confident. The key is the Lua colon-notation for methods . ArmBob could be developed a lot further with libraries – classes are a good way of hiding SWIs, for example – but is it worth the effort? Where Lua really shines is in pattern matching and I had thought of doing a pattern-matching library for ArmBob based on Lua’s. But to do it properly I kept finding myself needing other aspects of Lua (having functions as first class values) which ArmBob lacks. The truth is that you cannot just add extra features to a language like sauces to a burger in McDonalds. In a good language the features all mesh tightly – they are not just options.
I see ArmBob as a toy for those who like C++-like syntax. |
||||||
Rick Murray (539) 13840 posts |
Probably better to have a real example than all that rubbish about programming the Amiga, such as something that explains more clearly how to fake OO in standard C. The benefit of proper classes (like in C++) is the concept of destructors. These tidy up when something finishes. Otherwise, it’s on you to track allocations and free things that go out of scope. Which will quickly turn into a bit of a nightmare when you have dozens of gadgets and objects. Either that or the program can leak like a sieve. |
||||||
Rick Murray (539) 13840 posts |
I think you mean Burger King, the one where you can fiddle with the insides of the burger. ;-) |
||||||
GavinWraith (26) 1563 posts |
I hope I won’t be banished to Aldershot if I say that I have never in my life been to a Burger King. I think the children were once taken to a McDonalds when they were small, but I never ate anything there myself. Lua 5.4.3 lets you define to-be-closed local variables. When they go out of scope their closure-method is called. For file handles this is just the usual closing, but tables can be given a __close metamethod. The terminology of constructors and destructors links computer science and category theory in an interesting way that was not really understood until the 90s. Category theory looks at things in terms of abstract mappings, usually denoted by arrows. Thus A → B depicts a function that maps things of type A to things of type B. So-called universal constructions come in two flavours: limits defined in terms of arrows out of them ( destructors ) and colimits defined in terms of arrows into them ( constructors ). For example, the product X of A and B comes equipped with two destructors: p: X → A and q: X → B, and satisfies the universal property that for any pair of arrows f: Z → A, g: Z → B there is a unique arrow <f,g> : Z → X such that composing <f,g> with p (resp. q) yields f (resp. g). This captures the idea that X consists of pairs (a,b) with a in A and b in B, and that p(a,b) is a, and q(a,b) is b, but does it in a way that mentions only arrows and not elements. Turn all the arrows to point in the opposite direction and you get the notion of coproduct or ( sum ). I launch into all this spiel just to point out that what you can do with types in programming languages is not arbitrary but based on quite fundamental abstract principles, that may well not be immediately obvious to the working programmer. PS. I do cook my own burgers sometimes, but only with veal mince, coated in egg and breadcrumbs. Carbonader they are called in Danish. But never eaten in a bun, of course. In my experience burger buns are too sweet – not appropriate for meat. As for cheese, mayonnaise, ketchup and so on – Nej Tak . |
||||||
Steve Drain (222) 1620 posts |
Based purely on the Toolbox, I programmed OO in assembler for Basalt. Not to be recommended, though. ;-) And, of course, you can do OO in just BASIC, but you will get no help from the language. |