Q 7.10 for OpenZaurus = ==== === ========== This is a port of Q 7.10 (http://q-lang.sf.net) for Sharp Zaurus PDAs running OpenZaurus 3.5.4. As far as Linux-based PDAs go, the Zaurus is still my favourite, and Q makes for a nice programmable desktop calculator on this nifty little machine. OpenZaurus was chosen as the target OS rather than the official Sharp ROM since it has better and more recent development tools, making it easier to port Q to this platform, and also provides a nice set of end user applications for standard PIM usage (especially when used with the Opie GUI environment). Please see http://www.openzaurus.org for the necessary software and instructions on how to install OpenZaurus on your Zaurus. NOTE: OpenZaurus is currently being phased out in favour of the Angstrom distribution (http://www.angstrom-distribution.org) which supports a greater variety of hardware platforms. At this time Angstrom is not really ready for end users yet, so I decided to stick with OpenZaurus for now. Note that OpenZaurus 3.5.4 continues to be available from http://www.openzaurus.org. The packages provided here have been built on a Zaurus C1000 "Akita" running OpenZaurus 3.5.4.1 and should work with both Opie and GPE based OpenZaurus images on all newer Clamshell models. Currently *no* packages are provided for the older Zaurii ("Collie" etc.), so if you have one of those then please drop me a note or use the older Q 6.2 packages still available in the OpenZaurus.old feed. The following packages are provided: - q_7.10-r0_arm5vte.ipk: Contains the interpreter, standard library and some assorted modules. Specifically, the curl, gdbm, ncurses, octave, sqlite3 and xml modules are included, as well as Q Yacc and Lex and Rob Hubbard's rational and polynomial libraries. For a minimal installation this package is all that you need. - q-swig_1.3.22-20071021-r0_arm5vte.ipk: A SWIG version which has been patched up to provide support for the Q language. This is not needed for running the interpreter, but makes it easier to interface Q to C/C++ code. Note that the OZ feeds contain a different SWIG package which is *not* compatible with the version provided here. - texinfo_4.8-r0_arm5vte.ipk: GNU texinfo. You only need this if you want to be able to read the online manual with the interpreter's help command. (Alternatively, you can also install emacs and read the info file there, or download HTML and PDF versions of the manual from http://q-lang.sf.net.) Also note that, as far as memory sizes on PDAs go, these packages need quite a bit of storage space, so you'll probably have to install them on a memory card. To install the packages you can edit /etc/ipkg.conf to point ipkg to the OZ Q feed at http://q-lang.sf.net/feed/OpenZaurus and then run ipkg or the GUI package manager as usual. To these ends, add the following line to your ipkg.conf file and then run ipkg update: src qlang http://q-lang.sf.net/feed/OpenZaurus Or you can just download the packages, transfer them to your Z and install the local package files. E.g., a minimal setup would be (assuming SD card installation): # ipkg install q_7.10-r0_arm5vte.ipk -d sd # ipkg-link add q If you have enough space then you should also install the texinfo package to make Q's builtin documentation system work. OTOH the swig package is not needed for normal Q development; you'll only want to install this if you are planning to develop new extension modules or interface Q with existing C and C++ code. GETTING STARTED ======= ======= Once you installed the q_7.10 package (and possibly texinfo_4.8) you're ready to go. Fire up a console window and execute the "q" command. You should be greeted with a sign-on message, after which the interpreter leaves you at its prompt: ____ / __ \ Q interpreter version 7.10 (armv5tel-unknown-linux) / /_/ / Copyright (c) 1991-2008 by Albert Graef \___\_\ http://q-lang.sourceforge.net This software is distributed under the terms of the GNU General Public License version 2 or later; type `copying' for details. ==> You can enter any legal Q expression here: ==> prd [1..30] 265252859812191058636308480000000 The "edit" command lets you enter a script using vi or the editor named by the EDITOR environment variable. E.g., let's program the well-known Fibonacci function: ==> edit fib.q Enter the following little script: fib N = A where (A,B) = fibs N; fibs N = (B,A+B) where (A,B) = fibs (N-1) if N>0; = (0,1) otherwise; Save the script, exit from the editor and run the script with the interpreter: ==> run fib.q ==> map fib [1..20] [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765] That way Q makes for a fairly nice calculator program on your Z. But Q is much more powerful than this; it is a complete modern-style functional programming environment with a full-featured system interface which can also be used for scripting purposes. (Alas, none of Q's fancy graphics and multimedia extensions are supported under OZ right now.) More information can be found in the Q language manual. If you have installed the texinfo package then you can read this document online with the interpreter's "help" command. In particular, take a look at the "Getting Started" section in the manual. There is also a bunch of instructive programming examples in the /usr/share/q/examples directory. USING Q WITH EMACS ===== = ==== ===== If you have GNU Emacs installed (available in the OpenZaurus 3.5.4 contrib feed) then you can also use "Q mode" to edit and run scripts from within Emacs. This also gives you auto indentation and syntactic fontification in the editor, and for Emacs fans it is certainly the most convenient way to run Q on the Zaurus. To make this work, copy /usr/share/q/etc/q-mode.el to your Emacs site-lisp directory and add the following lines to your .emacs startup file: (require 'q-mode) (setq auto-mode-alist (cons '("\\.q$" . q-mode) auto-mode-alist)) (add-hook 'q-mode-hook 'turn-on-font-lock) (add-hook 'q-eval-mode-hook 'turn-on-font-lock) While you're at it, you might also wish to add the following convenient key assignments: (global-set-key "\C-h\C-q" 'q-help) (global-set-key "\C-c\C-q" 'run-q) (global-set-key [C-S-up] 'comint-previous-matching-input-from-input) (global-set-key [C-S-down] 'comint-next-matching-input-from-input) More customization options are described at the beginning of the q-mode.el file. Once you have set things up to your liking you can invoke Emacs with your script in a console window: # emacs fib.q To run the script now just type Ctrl-C Ctrl-C. This will open a *q-eval* window in Emacs in which you can execute Q interpreter commands as usual. This has the added benefit that you can get a transcript of your interpreter session simply by saving the contents of the *q-eval* buffer in a file. With the key assignments from above you can also run an empty script by typing Ctrl-c Ctrl-q, and read the online documentation inside Emacs with Ctrl-h Ctrl-q. (You might have to fiddle with the location of the qdoc.info* files so that Emacs finds them.) In particular, see Appendix E of the manual for more information on Emacs Q mode. Q AND VIM = === === If you have Vim ("Vi Improved") installed, you might want to use that for editing your Q scripts. The q.vim file, found in /usr/share/q/etc, provides Q syntax highlighting for Vim. It is to be installed in the ~/.vim/syntax directory. You also have to add the following lines to the ~/.vim/filetype.vim file (create the file if necessary) so that Vim recognizes the .q file type: augroup filetypedetect au BufNewFile,BufRead *.q setf q augroup END Q AND TINYKATE = === ======== If you're not friends with GNU Emacs or Vim then you might wish to use TinyKate to edit Q scripts instead. Q comes with a q.xml syntax file for Kate which works just fine with TinyKate. Copy /usr/share/q/etc/q.xml to /opt/QtPalmtop/share/tinykate/syntax and voila, next time you open a Q script in TinyKate it will be nicely colorized. Enjoy! :) Albert Graef 2007-12-18