boofaq

Where to get the boofaq?. 11

How to contribute to the Boofaq?. 11

What will happen if you mail your boo programming problems to the authors?. 11

Boofaq1: General Questions about boo. 11

What is boo?. 11

Who supports boo? Who develops it? Why is it free?. 12

Which version of boo should I use?. 12

What are boo 1, boo 2, or boo 3?. 12

How stable is boo?. 12

Is boo difficult to learn?. 12

How does boo compare with other languages like Java, Python, C, C++, REXX, Scheme or Tcl?. 12

Can I do [task] in boo?. 13

When shouldn’t I program in boo?. 13

What’s the difference between boo and c-sharp?. 13

Is it a boo program or a boo script?. 13

What is a JAPH? JACH? JACSH?. 13

How can I convince others to use boo?. 13

Boofaq2: Obtaining and Learning about boo. 13

What machines support boo? Where do I get it?. 13

How can I get a binary version of boo?. 14

I don’t have a C compiler. How can I build my own boo compiler?. 14

I copied the boo compiler binary from one machine to another, but it doesn’t work. 14

I grabbed the sources and tried to compile but gdbm/dynamic loading/malloc/linking/… failed. How do I make it work?. 14

What modules and extensions are available for boo?. 14

Is there an ISO or ANSI certified version of boo?. 14

Where can I get information on boo?. 14

What are the boo newsgroups on Usenet? Where do I post questions?. 14

Where should I post source code?. 15

boo Books. 15

Which magazines have boo content?. 15

What mailing lists are there for boo?. 15

Where are the archives for mono and mono-devel?. 15

Where can I buy a commercial version of boo?. 15

Where do I send bug reports?. 15

What is csharp.com, csharp-station.com, csharphelp.com, codeproject.com, etc?. 15

Boofaq3: Programming Tools. 15

How do I do (anything)?. 16

How can I use boo interactively?. 16

Is there a boo shell?. 16

How do I find which modules/libraries are installed on my system?. 16

How do I debug my boo programs?. 16

How do I profile my boo programs?. 16

How do I cross-reference my boo programs?. 16

Is there a pretty-printer (formatter) for boo?. 17

Is there a ctags for boo?. 17

Is there an IDE or Windows boo editor?. 17

Where can I get boo macros for vi?. 17

Where can I get csharp-mode for emacs?. 17

How can I use curses with boo?. 17

How can I use X or Tk with boo?. 17

How can I make my boo program run faster?. 17

How can I make my boo program take less memory?. 17

Is it safe to return a reference to a local or lexical data?. 17

How can I free an array or hash so my program shrinks?. 18

How can I make my CGI script more efficient?. 18

How can I hide the source for my boo program?. 18

How can I compile my boo program into byte code or C?. 18

How can I get #!/usr/bin/csharp to work on [MS-DOS, NT, … ] ?. 18

Can I write useful boo programs on the command line?. 18

Why don’t boo one-liners work on my DOS/Mac/VMS system?. 18

Where can I learn about CGI or Web programming in boo?. 18

Where can I learn about object-oriented boo programming?. 19

Where can I learn about linking C with boo?. 19

I’ve read XYZ but I can’t embed boo in my C program; what am I doing wrong?. 19

When I tried to run my script, I got this message. What does it mean?. 19

What’s MakeMaker? [x:What is MSBUILD or Nant?] 19

Boofaq4: Data Manipulation. 19

Data: Numbers. 19

Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?. 19

Why is int() broken?. 19

Why isn’t my octal data interpreted correctly?. 20

Does boo have a round() function? What about ciel() and floor()? Trig functions?. 20

How do I convert between numeric representations/bases/radixes?. 20

Why doesn’t & work the way I want it to?. 21

How do I multiply matrices?. 21

How do I perform an operation on a series of integers?. 21

How can I output Roman numerals?. 22

Why aren’t my random numbers random?. 22

How do I get a random number between X and Y?. 22

Data: Dates. 22

How do I find the day or week of the year?. 22

How do I find the current century or millennium?. 22

How can I compare two dates and find the difference?. 22

How can I take a string and turn it into epoch seconds?. 23

How can I find the Julian Day?. 23

How do I find yesterday’s date?. 23

Does boo have a Year 2000 problem? Is boo Y2K compliant?. 23

Data: Strings. 23

How do I validate input?. 23

How do I unescape a string?. 23

How do I remove consecutive pairs of characters?. 24

How do I expand function calls in a string?. 24

How do I find matching/nesting anything?. 24

How do I reverse a string?. 24

How do I expand tabs in a string?. 24

How do I reformat a paragraph?. 24

How can I access or change N characters of a string?. 24

How do I change the Nth occurrence of something?. 25

How can I count the number of occurrences of a substring within a string?. 25

How do I capitalize all the words on one line?. 25

How can I split a [character] delimited string except when inside [character]?. 25

How do I strip blank space from the beginning/end of a string?. 27

How do I pad a string with blanks or pad a number with zeroes?. 27

How do I extract selected columns from a string?. 27

How do I find the soundex value of a string?. 27

How can I expand variables in text strings?. 27

What's wrong with always quoting "$vars"?. 27

Why don't my <<HERE documents work?. 27

Data: Arrays. 28

What is the difference between a list and an array?. 28

What is the difference between $array[1] and @array[1]?. 28

How can I remove duplicate elements from a list or array?. 28

How can I tell whether a certain element is contained in a list or array?. 28

How do I compute the difference of two arrays? How do I compute the intersection of two arrays?. 29

How do I test whether two arrays or hashes are equal?. 29

How do I find the first array element for which a condition is true?. 30

How do I handle linked lists?. 31

How do I handle circular lists?. 31

How do I shuffle an array randomly?. 31

How do I process/modify each element of an array?. 32

How do I select a random element from an array?. 32

How do I permute N elements of a list?. 32

How do I sort an array by (anything)?. 32

How do I manipulate arrays of bits?. 32

Why does defined() return true on empty arrays and hashes?. 33

Data: Hashes (Associative Arrays) [x:Dictionaries] 33

How do I process an entire hash?. 33

What happens if I add or remove keys from a hash while iterating over it?. 33

How do I look up a hash element by value?. 33

How can I know how many entries are in a hash?. 33

How do I sort a hash (optionally by value instead of key)?. 33

How can I always keep my hash sorted?. 33

What's the difference between "delete" and "undef" with hashes?. 33

Why don't my tied hashes make the defined/exists distinction?. 33

How do I reset an each() operation part-way through?. 33

How can I get the unique keys from two hashes?. 33

How can I store a multidimensional array in a DBM file?. 33

How can I make my hash remember the order I put elements into it?. 33

Why does passing a subroutine an undefined element in a hash create it?. 33

How can I make the boo equivalent of a C structure/C++ class/hash or array of hashes or arrays?. 33

How can I use a reference as a hash key?. 33

Data: Misc. 33

How do I handle binary data correctly?. 33

How do I determine whether a scalar is a number/whole/integer/float?. 33

How do I keep persistent data across program calls?. 34

How do I print out or copy a recursive data structure?. 34

How do I define methods for every class/object?. 34

How do I verify a credit card checksum?. 34

How do I pack arrays of doubles or floats for XS code?. 34

Boofaq5: Files and Formats. 35

How do I flush/unbuffer an output filehandle? Why must I do this?. 35

How do I change, delete, or insert a line in a file, or append to the beginning of a file?. 35

How do I count the number of lines in a file?. 37

How can I use Perl's -i option from within a boo program?. 37

How can I copy a file?. 38

How do I make a temporary file name?. 38

How can I manipulate fixed-record-length files?. 38

How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?. 38

How can I use a filehandle indirectly?. 39

How can I set up a footer format to be used with write()?. 39

How can I write() into a string?. 39

How can I output my numbers with commas added?. 39

How can I translate tildes (~) in a filename?. 39

How come when I open a file read-write it wipes it out?. 39

Why do I sometimes get an "Argument list too long" when I use <*>?. 39

Is there a leak/bug in glob()?. 39

How can I open a file with a leading ">" or trailing blanks?. 39

How can I reliably rename a file?. 39

How can I lock a file?. 39

Why can't I just open(FH, ">file.lock")?. 40

I still don't get locking. I just want to increment the number in the file. How can I do this?. 40

All I want to do is append a small amount of text to the end of a file. Do I still have to use locking?. 40

How do I randomly update a binary file?. 40

How do I get a file's timestamp in boo?. 40

How do I set a file's timestamp in boo?. 40

How do I print to more than one file at once?. 40

How can I read in an entire file all at once?. 40

How can I read in a file by paragraphs?. 40

How can I read a single character from a file? From the keyboard?. 40

How can I tell whether there's a character waiting on a filehandle?. 40

How do I do a tail -f in boo?. 40

How do I dup() a filehandle in boo?. 41

How do I close a file descriptor by number?. 41

Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work?. 41

Why doesn't glob("*.*") get all the files?. 41

Why does boo let me delete read-only files? Why does -i clobber protected files? Isn't this a bug in boo?. 41

How do I select a random line from a file?. 41

Why do I get weird spaces when I print an array of lines?. 42

Boofaq6: Regular Expressions. 42

How can I hope to use regular expressions without creating illegible and unmaintainable code?. 42

I'm having trouble matching over more than one line. What's wrong?. 42

How can I pull out lines between two patterns that are themselves on different lines?. 42

I put a regular expression into $/ but it didn't work. What's wrong?. 42

How do I substitute case insensitively on the LHS while preserving case on the RHS?. 43

How can I make \w match national character sets?. 43

How can I match a locale-smart version of /[a-zA-Z]/?. 43

How can I quote a variable to use in a regex?. 43

What is /o really for?. 43

How do I use a regular expression to strip C style comments from a file?. 43

Can I use regular expressions to match balanced text?. 43

What does it mean that regexes are greedy? How can I get around it?. 45

How do I process each word on each line?. 45

How can I print out a word-frequency or line-frequency summary?. 45

How can I do approximate matching?. 45

How do I efficiently match many regular expressions at once?. 45

Why don't word-boundary searches with \b work for me?. 45

Why does using $&, $`, or $' slow my program down?. 45

What good is \G in a regular expression?. 45

Are regexes DFAs or NFAs? Are they POSIX compliant?. 45

What's wrong with using grep in a void context?. 45

How can I match strings with multibyte characters?. 45

How do I match a regular expression that's in a variable?. 45

Boofaq7: General boo Language Issues. 45

Can I get a BNF/yacc/RE for the boo language?. 46

What are all these $@%&* punctuation signs, and how do I know when to use them?. 46

Do I always/never have to quote my strings or use semicolons and commas?. 46

How do I skip some return values?. 46

How do I temporarily block warnings?. 46

What's an extension?. 46

Why do boo operators have different precedence than C operators?. 46

How do I declare/create a structure?. 46

How do I create a module?. 46

How do I create a class?. 46

How can I tell if a variable is tainted?. 46

What's a closure?. 46

What is variable suicide and how can I prevent it?. 46

How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?. 46

How do I create a static variable?. 46

What's the difference between dynamic and lexical (static) scoping? Between local() and my()?. 46

How can I access a dynamic variable while a similarly named lexical is in scope?. 46

What's the difference between deep and shallow binding?. 46

Why doesn't "my($foo) = <FILE>;" work right?. 46

How do I redefine a builtin function, operator, or method?. 46

What's the difference between calling a function as &foo and foo()?. 46

How do I create a switch or case statement?. 46

How can I catch accesses to undefined variables, functions, or methods?. 47

Why can't a method included in this same file be found?. 47

How can I find out my current package?. 47

How can I comment out a large block of boo code?. 47

How do I clear a package?. 47

How can I use a variable as a variable name?. 47

What does "bad interpreter" mean?. 47

Boofaq8: System Interaction. 47

How do I find out which operating system I'm running under?. 48

How come exec() doesn't return?. 48

How do I do fancy stuff with the keyboard/screen/mouse?. 48

How do I print something out in color?. 48

How do I read just one key without waiting for a return key?. 48

How do I check whether input is ready on the keyboard?. 48

How do I clear the screen?. 48

How do I get the screen size?. 48

How do I ask the user for a password?. 48

How do I read and write the serial port?. 48

How do I decode encrypted password files?. 48

How do I start a process in the background?. 48

How do I trap control characters/signals?. 48

How do I modify the shadow password file on a Unix system?. 48

How do I set the time and date?. 48

How can I sleep() or alarm() for under a second?. 48

How can I measure time under a second?. 48

How can I do an atexit() or setjmp()/longjmp()? (Exception handling) 48

Why doesn't my sockets program work under System V (Solaris)? What does the error message "Protocol not supported" mean?. 48

How can I call my system's unique C functions from boo?. 48

Where do I get the include files to do ioctl() or syscall()?. 48

Why do setuid boo scripts complain about kernel problems?. 48

How can I open a pipe both to and from a command?. 48

Why can't I get the output of a command with system()?. 49

How can I capture STDERR from an external command?. 49

Why doesn't open() return an error when a pipe open fails?. 49

What's wrong with using backticks in a void context?. 49

How can I call backticks without shell processing?. 49

Why can't my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS-DOS)?. 49

How can I convert my shell script to boo?. 49

Can I use booto run a telnet or ftp session?. 49

How can I write expect in boo?. 49

Is there a way to hide boo's command line from programs such as "ps"?. 49

I {changed directory, modified my environment} in a boo script. How come the change disappeared when I exited the script? How do I get my changes to be visible?. 49

How do I close a process's filehandle without waiting for it to complete?. 49

How do I fork a daemon process?. 49

How do I find out if I'm running interactively or not?. 49

How do I timeout a slow event?. 49

How do I set CPU limits?. 49

How do I avoid zombies on a Unix system?. 49

How do I use an SQL database?. 49

How do I make a system() exit on control-C?. 49

How do I open a file without blocking?. 49

How do I tell the difference between errors from the shell and boo?. 49

How do I install a module from CPAN?. 49

What's the difference between require and use?. 50

How do I keep my own module/library directory?. 50

How do I add the directory my program lives in to the module/library search path?. 50

How do I add a directory to my include path (@INC) at runtime?. 50

What is socket.ph and where do I get it?. 50

Boofaq9: Networking. 50

What is the correct form of response from a CGI script?. 51

My CGI script runs from the command line but not the browser. (500 Server Error) 51

How can I get better error messages from a CGI program?. 51

How do I remove HTML from a string?. 51

How do I extract URLs?. 51

How do I download a file from the user's machine? How do I open a file on another machine?. 51

How do I make an HTML pop-up menu with boo?. 51

How do I fetch an HTML file?. 51

How do I automate an HTML form submission?. 51

How do I decode or create those %-encodings on the web?. 51

How do I redirect to another page?. 51

How do I put a password on my web pages?. 51

How do I edit my .htpasswd and .htgroup files with boo?. 51

How do I make sure users can't enter values into a form that cause my CGI script to do bad things?. 51

How do I parse a mail header?. 51

How do I decode a CGI form?. 51

How do I check a valid mail address?. 51

How do I decode a MIME/BASE64 string?. 51

How do I return the user's mail address?. 51

How do I send mail?. 51

How do I use MIME to make an attachment to a mail message?. 51

How do I read mail?. 51

How do I find out my hostname, domainname, or IP address?. 52

How do I fetch a news article or the active newsgroups?. 52

How do I fetch/put an FTP file?. 52

How can I do RPC in boo?. 52

Works Cited. 52

 

The Boofaq is a copy of perlfaq with questions answered in boo terms instead of perl terms. Perl has its roots in Unix and so many questions take a Mono instead of Microsoft answer approach only because Mono is the leading boo runtime on Unix. The authors wish to thank the authors of perlfaq for providing perlfaq as a perl resource. As former (and sometimes current) perl programmers we recognize that perlfaq has helped us be great perl programmers. When transitioning from perl to boo it was often easy to think in terms of perl and move that to boo. Sometimes this was a good thing, other times it was not. But rather than wade through API documentation in MSDN or Monodoc we wanted something like perlfaq.

When teaching an mentoring new perl programmers, my answer to their questions was often “That is in the perlfaq.” Or “Did look in perlfaq4?” When I started programming boo and trying to influence some of these same programmers, I noticed that they often had the same questions as they did before and that they didn’t know where to start looking for the answer. Some of the intent of Boofaq is to bridge this gap of information literacy. Another intent is to act as a reference for common questions. Many answers can be found in MSDN, but often diving through MSDN can be slow and difficult. Google yields many good answers to questions, but sometimes finding the right search phrase is difficult especially when namespaces are common to other languages or you are dealing with regular expressions.

Where to get the Boofaq?

http://workwith.net/faq/boo/

How to contribute to the Boofaq?

You can mail corrections, additions, and suggestions to <boofaq-workers@lists.xmtp.net>.

What will happen if you mail your boo programming problems to the authors?

We will make fun of you. j/k.  Probably nothing. We might try to help. We might try to reply. We might not. We aren’t a free programming help service. More than likely we will point you to the question in the faq that most closely resembles your problem, or we will point you to MSDN or boo documentation.

Boofaq1: General Questions about boo

Very general, high-level questions about boo.

What is boo?

boo is an object oriented statically typed programming language for the Common Language Infrastructure with a python inspired syntax and a special focus on compiler and language extensibility. Rodrigo B. de Oliveira created boo by due to his frustration with existing systems and his love for the CLI. He wanted to use python but use the .net framework.

Who supports boo? Who develops it? Why is it free?

The development community at large supports boo. Volunteers develop it as open source software. It is free for most of the same reasons that other languages and development environments are free.

Which version of boo should I usehName?

You should use the latest possible boo version that is possible in your environment.

The release of boo 0.7.8 was the last release to support .net 1.1.

What are boo 1, boo 2, or boo 3?

I don’t know.

How stable is boo?

boo is very stable. Between releases there is very little chance of breaking source level compatibility. There is even less chance at the byte code level (aka MSIL or CIL, not boo, but important to know). The development of boo is very open which adds to its stability. New releases do add new features often.

Is boo difficult to learn?

“No, [boo] is easy to start learning and easy to keep learning. It looks like most programming languages with which you are likely to have experience.“ (Christiansen & D'foy, 2007)

boo seems to have very few  “ah-ha” moments when learning it. While boo does have its share of “devil in the details” things to know about, these seem to be edge cases. These edge cases seem to be small. The average programmer can be up and running and writing boo code in short time. As with most languages, mastering the edge cases can take quite a bit longer.

How does boo compare with other languages like Java, Python, C, C++, REXX, Scheme or Tcl?

“Favorable in some areas, unfavorably in others.” (Christiansen & D'foy, 2007)

boo is most like python in that it compiles to a bytecode that is then run by a jitter to execute native code on a given platform. boo is also similar to python in that it is “object oriented”.

Generics in boo are more like templates in C++ or since they are CLR generics, they are most like C# generics. However where templates in C++ are expanded by the pre-compiler, in boo generics are known about at runtime (thus generics are a .NET runtime feature with boo language support). There is a tradeoff here. There are things that C++ templates can do that simply cannot be done with boo generics, however boo generics have this benefit of runtime awareness so it too can do things that C++ generics cannot. One biggie is that while C++ templates would create a new type for every template type, boo shares it generic type implementation for all reference types. This leads to much less code bloat.

boo is less like Perl, or REXX because these are dynamic typed languages. This line is definitely blurring as things like IronPython and IronRuby are released. The DLR aides in running dynamic languages on .NET. Modern Python and Ruby aren’t really interpreted anyway. These languages follow a similar compile to bytecode and then run in a managed runtime as boo does. The difference is that compilation takes place on invocation rather than before. Support for compile first is also available in boo. Boo is rare and maybe even unique in the regard that it can be both compiled and interpreted. The Dynamic Language Runtime is bridging the gap between these languages through use of the .NET runtime. While boo will probably never use or run on the DLR, you might consider using Python on DLR to interoperate with your boo.

Can I do [task] in boo?

Yes.

When shouldn’t I program in boo?

“When your manager forbids it – but consider replacing them J.” (Christiansen & D'foy, 2007)

Another answer might be: When you cannot afford the costs of a managed environment. These cases are few and you might reconsider if you think you cannot afford these costs. They are often surprisingly low. Currently even light 3d graphics is done in boo using XNA. However the latest photo-realistic 3d environment game engine is probably not well suited to be written in boo.

What’s the difference between boo and Boo?

I am not sure. Probably copyright. They are pronounced the same.

Is it a boo program or a boo script?

Either or both! boo can be interpreted like Perl or it can be compiled like C# or Java. This makes some of the questions in this faq not make some sense. We will refer those questions to here.

I sometimes call boo programs “scripts” if they do very simple things and I’ve written them in a script style, for example, one big main method. Or complete lack of OO design. For most “scripts” OO design would be overkill” – JRW

What is a JAPH? JABH?

“JAPH stands for ‘Just another Perl hacker’” (Christiansen & D'foy, 2007) So I guess we could coin JABH which I pronounce as “jab” for just another boo hacker. I’ve never heard JAB used so consider this term coined here.

How can I convince others to use boo?

“Appeal to their self interest!” (Christiansen & D'foy, 2007)

Boofaq2: Obtaining and Learning about boo

Where to find source and documentation for boo, support and related matters.

What machines support boo? Where do I get it?

Any machine which can run .NET code can run boo. The Microsoft .NET implementation can run on x86, x86_64 and, I think, also Itanium.

The Mono .NET implementation can run on many more platforms. A complete list is available here: http://www.mono-project.com/Supported_Platforms

You can get boo from http://boo.codehaus.org/ You will need a .NET runtime, and preferably the latest .NET runtime. You probably already have some version of .NET if you are running a Microsoft operating system. You can get Mono by downloading it and installing it. If you are running Linux it may be easier to use your distributions package management system to install Mono. You can download Mono here: http://www.mono-project.com/Downloads

Ubuntu Linux ships with both mono and boo. You can install boo by simply running “apt-get install boo”.

How can I get a binary version of boo?

The source and CLI binary are available from the boo website. See “Where do I get it?”

I don’t have a C compiler. How can I build my own boo compiler?

“Since you don't have a C compiler, you're doomed and your vendor should be sacrificed to the Sun gods. But that doesn't help you.” (Christiansen & D'foy, 2007)

You only need a C# compiler. See the csharpfaq and the Mono project.

I copied the boo compiler binary from one machine to another, but it doesn’t work.

“That's probably because you forgot libraries, or library paths differ. You really should build the whole distribution on the machine it will eventually live on…” (Christiansen & D'foy, 2007)

I grabbed the sources and tried to compile but gdbm/dynamic loading/malloc/linking/… failed. How do I make it work?

I’ll assume you are referring to Mono in which case you should read their INSTALL file and their documentation.

What modules and extensions are available for boo?

The extensible compiler architecture used by boo is documented in the advanced features section of the boo language guide: http://boo.codehaus.org/Boo+Compiler

This is a bad copy from the perlfaq that doesn’t match well with boo. boo has numerous free and commercial libraries available for it. There is no CPAN equivalent for boo. boo libraries are not specific to boo but will work with any .NET language. These are often called .NET libraries. Many .NET libraries will work with both Microsoft and Mono, but some are specific to one or the other. Google is your best friend in finding libraries for boo. Also see Codeplex, Sourceforge and Mono itself.

Is there an ISO or ANSI certified version of boo?

Nope.

Where can I get information on boo?

http://boo.codehaus.org/ is the one stop shop. Hopefully more documentation will find its way to the internet. See also: Brail and Binsor. Both are boo based DSL created by Oren (Ayende) Eini. http://www.ayende.com/

What are the boo newsgroups on Usenet? Where do I post questions?

There aren’t any on Usenet. (Unfortunately) It is now a google world. There is a boolang google group at http://groups-beta.google.com/group/boolang. There are 4 email lists for boo developers (this means you are developing boo itself, not just programming using boo), announcements, source control logs, and an old archive list. These mailing lists are also available via gmane which means they are readable via NNTP. It isn’t Usenet, but its NNTP J.  See http://boo.codehaus.org/Mailing+Lists for details.

Where should I post source code?

“You should post source code to whichever group is most appropriate…” (Christiansen & D'foy, 2007)

Getting involved in any online community is a great place to learn and to have others see your code. There are many online communities around boo there is not best one. The right one for you may not be the right one for someone else.

boo Books

I don’t know of any boo books. Maybe someone should write one?

Which magazines have boo content?

Unfortunately none.

What mailing lists are there for boo?

See http://boo.codehaus.org/Mailing+Lists and the “What are the boo newsgroups on Usenet? Where do I post questions?” section

Where are the archives for boo and boo-dev?

See Google and Gmane respectively.

Where can I buy a commercial version of boo?

You cannot.

Where do I send bug reports?

To the codehaus jira system: http://jira.codehaus.org/browse/BOO?report=com.atlassian.jira.plugin.system.project:openissues-panel

What is boo.com, boo.org, boo.net, etc?

None of these are related to the boo programming language.

Boofaq3: Programming Tools

Programmer tools and programming support.

How do I do (anything)?

“Have you looked at CPAN (see perlfaq2)? The chances are that someone has already written a module that can solve your problem. Have you read the appropriate manpages?” (Christiansen & D'foy, 2007)

We don’t have CPAN or equivalent in the .NET (and thus boo) world. However there are still many of excellent libraries that can solve your problem. Please search before you reinvent the wheel.

How can I use boo interactively?

Run booish the boo interactive shell. You can also use SharpDevelop, which comes with a boo plug-in. Just select Boo Interpreter from the View menu.

Is there a boo shell?

The booish, boo interactive shell is an interactive programming environment, but it is not a system shell. It is not a replacement for bash or even cmd.exe. However, it might be easy to make something to suit your needs.

How do I find which modules/libraries are installed on my system?

Look for DLLs that are .NET assemblies. They could be anywhere on your system. The runtime has something called the Global Assembly Cache(GAC) which you may want to look at. The assemblies installed in the GAC could be considered the “installed modules” on your system. The GAC is installed in %WINDIR%\Assembly on Microsoft platforms and could be installed anywhere on a Mono platform. See your Mono distribution for more information.

How do I debug my boo programs?

Sharpdevelop provides an excellent debugger.

How do I profile my boo programs?

Microsoft offers a profiler as a separate download. http://www.microsoft.com/downloads/details.aspx?FamilyId=A362781C-3870-43BE-8926-862B40AA0CD0&displaylang=en

Mono has a few profiling tools. http://www.mono-project.com/Profile

Google for CLR profiler or .Net profiler to find many other profiling tools.

How do I cross-reference my boo programs?

Perl has B::Xref. The Linux kernel uses LXR against its source. I know of no similar tools for boo. However, boo does have a standard for inline comment documentation.

Is there a pretty-printer (formatter) for boo?

SharpDevelop does a pretty nice job of pretty printing boo. pygments can pretty-print boo. (http://pygments.org/) boo is similar enough to python that a python pretty-printer might work too.

Is there a ctags for boo?

Yes, Exuberant ctags (http://ctags.sourceforge.net) has support for boo thanks to Steve Donovan’s sciboo project. (http://mysite.mweb.co.za/residents/sdonovan/sciboo.html)

Is there an IDE or Windows boo editor?

SharpDevelop is the most popular IDE for boo. There is boo support in countless other editors. Gvim has good support. Notepad2 has good support. MonoDevelop is an open source IDE for .NET that runs on Linux.

Where can I get boo macros for vi?

Various boo.vim files are available for various boo branches. They are all in boo svn. See http://fisheye.codehaus.org/browse/boo/boo/branches/stable/extras/boo.vim?r=root: for the stable release.

Where can I get csharp-mode for emacs?

You will have to write one.

How can I use curses with boo?

http://www.mono-project.com/MonoCurses

How can I use X or Tk with boo?

http://www.mono-project.com/Gtk

I know of no wait to use the antiquated “tk” with boo or Mono.

How can I make my boo program run faster?

http://www.mono-project.com/Performance_Tips

While this is mono documentation, nearly all of the concepts hold true for the MS runtime.

How can I make my boo program take less memory?

http://www.mono-project.com/Performance_Tips

While this is mono documentation, nearly all of the concepts hold true for the MS runtime.

Is it safe to return a reference to a local or lexical data?

This question is a bit of loaded perl, but it does have come boo corresponding questions. In a CLR there are reference types and there are value types. You can return a reference to a local, because the runtime is a garbage collected environment.

“Yes. Perl's garbage collection system takes care of this so everything works out right.” (Christiansen & D'foy, 2007)

How can I free an array or hash so my program shrinks?

“You usually can't.” (Christiansen & D'foy, 2007)

999 times out of a thousand you don’t need to do this. There is much writing on how and why to NEVER call GC.Collect(). Please use google and read about GC.Collect(). If you need this level of memory management, any managed environment is probably not right for you.

How can I make my CGI script more efficient?

CGI in boo? Well, it isn’t impossible. CGI is a gateway to ANY program. But with ASP.NET, CGI is not really used with boo. So the answer is: use ASP.NET

How can I hide the source for my boo program?

“Delete it. :-) Seriously, there are a number of (mostly unsatisfactory) solutions with varying levels of "security".” (Christiansen & D'foy, 2007)

It is true in perl and it is true in boo or any .Net program. See Lutz Roder’s Reflector program or even Mono’s monodis program.

How can I compile my boo program into byte code or C?

“In general, you can't do this.” (Christiansen & D'foy, 2007)

Runtime executed code is already byte code compiled. Use the booc.exe boo compiler.

How can I get #!/usr/bin/csharp to work on [MS-DOS, NT, … ] ?

boo is not perl J This is a bad copy from the perlfaq that doesn’t match well with boo.

boo programs compile to .NET bytecode. Windows operating systems know how to execute these .NET assemblies. They are .EXE files. In Linux you can help along these binary types by using [TODO: document that Linux file helper]

But most Mono programs simply create shell script wrappers for the compiled .exe files. E.g. ~/bin/MyProgram.exe has a shell script wrapper called ~/bin/MyProgram with contents “mono MyProgram.exe”.

If you find yourself asking the question and writing shell scripts with #!/usr/bin/booi at the top, maybe you should be using the boo compiler instead!

Can I write useful boo programs on the command line?

Not really. Certainly not like you can write one liners in perl.

Why don’t boo one-liners work on my DOS/Mac/VMS system?

See the previous question.

Where can I learn about CGI or Web programming in boo?

www.asp.net is a portal page run by Microsoft which is a great starting point for boo web programming. CastleProject has MonoRail which is an alternative to the WebForms style of ASP.NET Web development. Mono has some ASP.NET documentation http://www.mono-project.com/ASP.NET

Where can I learn about object-oriented boo programming?

See books, magazines, mailing lists, tutorials and websites.

Where can I learn about linking C with boo?

P/Invoke is well documented by Microsoft and Mono.

There is also a very interesting Mono project called “linker”. http://www.mono-project.com/Linker

I’ve read XYZ but I can’t embed boo in my C program; what am I doing wrong?

I’ll assume this is in regard to Mono. I know of no way to do this with the Microsoft runtime.

http://www.mono-project.com/Embedding_Mono

When I tried to run my script, I got this message. What does it mean?

I’ll assume this is a compile time question. The compiler usually gives very good messages. If you can’t understand them, then you should probably read more.

What’s MakeMaker? [x:What is MSBUILD or Nant?]

boo programs are usually distributed with either a Makefile, or a MSBUILD csproj or sln file, or a nant build script.

Boofaq4: Data Manipulation

Manipulating numbers, dates, strings, arrays, hashes, and miscellaneous data issues.

Everything I learned about perl I learned from perlfaq4 – JRW

Data: Numbers

Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

“Internally, your computer represents floating-point numbers in binary. Digital (as in powers of two) computers cannot store all numbers exactly. Some real numbers lose precision in the process. This is a problem with how computers store numbers and affects all computer languages, not just Perl.” (Christiansen & D'foy, 2007)

Why is int() broken?

Your int() is most probably working just fine. It's the numbers that aren't quite what you think.

First, see the answer to "Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?".

 (Christiansen & D'foy, 2007)

Why isn’t my octal data interpreted correctly?

The boo language standard does not support octal characters constants by default.

Does boo have a round() function? What about ciel() and floor()? Trig functions?

The Math class in the System namespace has Round(), Ceiling() and Floor(). There are many overloads which allow setting precision.

The same Math class has common trig functions such as Sin(), Cos(), Tan(), Abs(), Asin(), Acos(), Atan(), Atan2(), Exp(), Log(), Pow(), Log10(), Sinh(), Cosh() and Tanh().

How do I convert between numeric representations/bases/radixes?

There are lots of ways. You could reference the Microsoft.VisualBasic assembly and use the Conversion class. You could use the Parse method available on many of the base types and use its NumberStyles overload. You may even be able to use System.Convert class to help you do it.

How do I convert hexadecimal into decimal?

The boo language standard does not support octal or hexadecimal characters constants by default. The class methods given here will work in any .Net language.

>>> num = “A”

‘A’

>>> val = int.Parse(num, NumberStyles.HexNumber)

10

 

MSDN Topic titled “Parsing Numeric Strings” is a good source of more information.

Boo supports hexadecimal literals.

>>> x=0xa

10

How do I convert from decimal to hexadecimal?

>>> num = 10

>>> num.ToString(“X”)

‘A’

 

MSDN topic titled “Standard Numeric Format Strings” is a good source of more information.

How do I convert from octal to decimal

 

How do I convert from decimal to octal

How do I convert from binary to decimal

How do I convert from decimal to binary

Why doesn’t & work the way I want it to?

This is the bitwise and operator. If you want a logical and, use &&. If you are looking to reference a memory location then you should have probably used a reference type. boo will automatically box and unbox value types. For more information on boxing see “Boxing and Unboxing” in the boo Programming Guide.

How do I multiply matrices?

System.Drawing.Drawing2D.Matrix in the System.Drawing assembly provides support for 3-by-3 matrices. (from GDI+)

System.Windows.Media in WindowsBase assembly (from WPF) also provides support for 3-by-3 matrices.

System.Windows.Media.Media3D.Matrix3D in the PresentationCore assembly (from WPF) provides support for 4x4 matrix used for transformations in 3-D space.

A commercial general matrix library is available from bluebit software: http://www.bluebit.gr/NET/

When creating a brand spanking new multidimensional array, use this syntax:

foo = matrix(int, 2, 3, 4)

//That creates an empty 3 dimensional array.

//1st dimension will have 2 items, 2nd has 3, 3rd has 4

 

How do I perform an operation on a series of integers?

To call a function on each element in an array and collect the results use for

>>> x = [1,2,3,4,5]

>>> for i in x:

...   print AddOne(i)

2

3

4

5

6

Or a slightly more complex example:

>>> def MyFunc(listOfInts):

...   for I in listOfInts:

...     yield I

>>> x = [1,2,3,4,5]

>>> List(MyFunc(x))

[2, 3, 4, 5, 6]

How can I output Roman numerals?

Why aren’t my random numbers random?

Computers are good at being predictable and bad at being random (despite appearances caused by bugs in your programs :-). (Christiansen & D'foy, 2007)

You can seed System.Random by passing a value to the constructor, or you can use RNGCryptoServiceProvider instead. The interface for RNGCryptoServiceProvider is not the same as System.Random so your code may need changing. Better yet, use adapter pattern to create a compatible interface that gets its random numbers from RNGCryptoServiceProvider.

How do I get a random number between X and Y?

System.Random.Next() has an overload that takes minValue and maxValue as a parameter. This returns an int.  System.Random.NextDouble() returns a double from 0 to 1. If you want a double between X and Y you will need to do the math yourself. For example for a double between 1.5 and 4.5

myNumber = 1.5 + (System.Random()).NextDouble() * (4.5-1.5)

Data: Dates

How do I find the day or week of the year?

DateTime has DayOfWeek and DayOfYear properties.

now = DateTime.Now

print “Today is ${now.DayOfWeek} and it is the ${now.DayOfYear} day of the year”

How do I find the current century or millennium?

Divide DateTime.Year by 100 or 1000 +1

now = DateTime.Now

print “Today we live in Century ${ now.Year/100 + 1} and Millenium ${ now.Year/1000 +1}”

How can I compare two dates and find the difference?

Use the subtract or overloaded minus operator. This will give a result of type TimeSpan. You can also subtract a TimeSpan from a DateTime to find another DateTime.

now = DateTime.Now

Christmas = DateTime( now.Year, 12, 25 )

threedays =  TimeSpan(3,0,0,0)

print “Three days ago was ${ now - threedays }”

print “There is ${ Christmas - now } until Christmas”

How can I take a string and turn it into epoch seconds?

DateTime has a Parse method (like most .NET primitives).

myDateTimeStr = “04/17/2007 14:30:00”

myDateTime = DateTime.Parse(myDateTimeStr)

epoch = DateTime(1970,1,1)

(myDateTime - epoch).TotalSeconds

 

How can I find the Julian Day?

http://www.codeproject.com/csharp/JalaliCalendar.asp

http://heybo.com/weblog/posts/254.aspx

Calculate the Julian Date

(DateTime.UtcNow - DateTime.MinValue).TotalDays + (DateTime(4713,1,1)-DateTime(1,1,1)).TotalDays +403

Or the modified Julian Date

(DateTime.UtcNow - DateTime(1858,11,17)).TotalDays

Or the day of the year (which is what some people think of as Julian day)

(System.Globalization.JulianCalendar()).GetDayOfYear(DateTime.Now)

How do I find yesterday’s date?

DateTime.Now.AddDays(-1)

Does boo have a Year 2000 problem? Is boo Y2K compliant?

.NET does not have a Year 2000 problem. It is Y2K compliant. boo compiles to bytecode on .NET and thus does not have a Yeark 2000 problem and is Y2K compliant.

Data: Strings

How do I validate input?

There are many ways. CastleProject has a Validation system which works well with MonoRail. EnterpriseLibrary from Microsoft had a Validation system.

How do I unescape a string?

It depends on what you mean. URL and Html escapes can be handled with HttpUtility class in System.Web namespace and assembly.

How do I remove consecutive pairs of characters?

You can use the substitution operator to find pairs of characters (or runs of characters) and replace them with a single instance. In this substitution, we find a character in (.). The memory parentheses store the matched character in the back-reference \1 and we use that to require that the same thing immediately follow it. We replace that part of the string with the character in $1. (Christiansen & D'foy, 2007)

/* s/(.)\1/$1/g; #is the perl regex */

stripped = /(.)\1/.Replace(“Haarlem”,”$1”)

Here is the same example as perlfaq converting Haarlem like in the Netherlands to Harlem like in New York.

How do I expand function calls in a string?

There have been a number of attempts at a “exec” method for boo that uses CodeDom. I have not seen any one that did a very great job. boo is compiled to bytecode and then executed by a JIT engine. The method or function call you wish to perform may not exist at runtime.

That said, take a look at any of the boo DSL which may help you do what you want. Specifically take a look at Binsor in rhino-commons.

How do I find matching/nesting anything?

This isn't something that can be done in one regular expression, no matter how complicated. (Christiansen & D'foy, 2007)

A regular expression is a representation of a Regular Language in the field of formal languages. They are equivalent to finite automaton. It can be proven that this is impossible. This is the task of a regular grammar.

How do I reverse a string?

Call reversed to make an enumerator and then call join.

>>> blah = “hello”

‘hello’

>>> join(List(reversed(blah)),"")

'olleh'

 

Array.Reverse will reverse an array in place.

>>> blah = "hello"

'hello'

>>> chars = blah.ToCharArray()

(h, e, l, l, o)

>>> Array.Reverse(chars)

>>> string(chars)

'olleh'

How do I expand tabs in a string?

>>> tabSpaces = " "*4

'    '

>>> mystring = " <-- tab"

'\t<-- tab'

>>> expanded = /\t/.Replace(mystring, tabSpaces)

'    <-- tab'

How do I reformat a paragraph?

[TODO: find a Text::Wrap and Text::Autoformat .NET Library or boo code]

How can I access or change N characters of a string?

Access can be done for a single character using the indexer in boo.

>>> blah

'hello'

>>> blah[2]

l

>>> blah[1]

e

Strings in .NET are immutable reference types so any change results in the creation of a new string. You can use string.Substring() or slice notation.

>>> jabh = "Just another boo hacker"

'Just another boo hacker'

>>> jabh.Substring(0,12) + " awesome " + jabh.Substring(13,10)

'Just another awesome boo hacker'

>>> jabh[:13] + "awesome" + jabh[12:]

'Just another awesome boo hacker'

 

How do I change the Nth occurrence of something?

You have to keep track of N yourself. (Christiansen & D'foy, 2007)

want = 3

sues = “One fish two fish red fish blue fish”

fisher = /(\w+)\s+fish\b/

count = 0

for match in fisher.Matches(sues):

      count++

      if count == 3:

           print “the third fish is a ${match.Groups[1]} one.”

How can I count the number of occurrences of a substring within a string?

>>> blah = "there was an x in my string x in my string!"

'there was an x in my string x in my string!'

>>> re = @/x in/

x in

>>> r = re.Matches(blah).Count

2

 

How do I capitalize all the words on one line?

.NET regular expressions don’t support the \L \U modifiers like perl does. However, .NET provides a MatchEvaluator delegate which lets you call code for every match in a regular expression.

>>> def upper(m as Match):

...   return m.Groups[1].Value.ToUpper()

...

>>> @/\b(\w)/.Replace("welcome to the boofaq", upper )

'Welcome To The Boofaq'

>>>

To make the whole string uppercase just use string.ToUpper

>>> “somestring”.ToUpper();

‘SOMESTRING’

You can (and probably should) enable locale awareness of those characters by using the CultureInfo overload

>>> import System.Globalization

>>> str1 = "this is some string man!"

'this is some string man!'

>>> str2 = str1.ToUpper(CultureInfo("en-US", false))

'THIS IS SOME STRING MAN!'

>>>

There is also System.Globalization.TextInfo.ToTitleCase()

>>> myTI = CultureInfo("en-US",false).TextInfo

TextInfo - 1033

>>> myTI.ToTitleCase("welcome to the boofaq")

'Welcome To The Boofaq'

>>> 

How can I split a [character] delimited string except when inside [character]?

Usually characters here are a comma and a quote. ODBC allows the use of an ODBC ADO.NET CSV DataProvider. There are multiple CSV parsers available at places like CodeProject.

Take the example case of trying to split a string that is comma-separated into its different fields. You can't use split(/,/) because you shouldn't split if the comma is inside quotes. For example, take a data line like this:

      SAR001,"","Cimetrix, Inc","Bob Smith","CAM",N,8,1,0,7,"Error, Core Dumped"

Due to the restriction of the quotes, this is a fairly complex problem. Thankfully, we have Jeffrey Friedl, author of Mastering Regular Expressions, to handle these for us. He suggests (assuming your string is contained in $text):

       @new = ();

       push(@new, $+) while $text =~ m{

            "([^\"\\]*(?:\\.[^\"\\]*)*)",?  # groups the phrase inside the quotes

           | ([^,]+),?

           | ,

           }gx;

       push(@new, undef) if substr($text,-1,1) eq ',';

If you want to represent quotation marks inside a quotation-mark-delimited field, escape them with backslashes (eg, "like \"this\"". (Christiansen & D'foy, 2007)

This is Boofaq so you may or may not know perl. The above is a rather nice regular expression. We can get similar behavior with boo using this code.

text = "\"This is a Quoted Value\",1,2,CSV,omg csv,\"Quotes, commas, and things\""

//+        re    {"([^"\]*(?:\.[^"\]*)*)",? | ([^,]+),? | ,}    System.Text.RegularExpressions.Regex

re = Regex("\"([^\\\"\\]*(?:\\.[^\\\"\\]*)*)\",?" + @"|([^,]+),?" + @"|,")

value = []

for m in re.Matches(text):

    values.Add(m.Groups[m.Groups.Count - 1].Value);

 

[TODO: this regex doesn’t work fix this!]

 

How do I strip blank space from the beginning/end of a string?

Use string.Trim(), string.TrimEnd(‘ ‘), string.TrimStart(‘ ‘);

How do I pad a string with blanks or pad a number with zeroes?

Use the String(Char, Int32) constructor.

things = string(‘ ‘, 20) + “my stuff”

Or you can use the * operator:

>>> " "*20+"my stuff"

'                    my stuff'

How do I extract selected columns from a string?

If you know where the columns that contain the data are, you can use string.Substring to extract a single column

column = line.Substring(startColumn, length)

or you can use slicing

column = line[startColumn:length+startColumn]

 

You can use split if the columns are separated by whitespace or some other delimiter as long as the delimiter cannot appear as part of the data.

>>> line = " fred barney  betty  "

' fred barney  betty  '

>>> line.Split(char(' '))

('', 'fred', 'barney', '', 'betty', '', '')

How do I find the soundex value of a string?

[TODO: what is soundex?]  Is this a good place for Levenshtein distance from http://www.merriampark.com/ldcsharp.htm

How can I expand variables in text strings?

boo just does it for you

foo = “Fred”

bar = “Barney”

“Say hello to ${foo} and ${bar}”

What's wrong with always quoting "$vars"?

With boo you can’t do that, so it doesn’t apply. However the string class is often misunderstood. People say not to use + and to prefer string.Format. It turns out that the compiler itself has some optimizations for using + concatenation. Don’t prematurely optimize strings. You should just be aware that they are immutable reference types with value semantics. If you run into issues, then you can consider optimizing.

http://www.ayende.com/Blog/archive/2007/07/06/The-truth-about-string-concatenation-performance.aspx

Why don't my <<HERE documents work?

With boo you can’t do that either!  :0

Data: Arrays

What is the difference between a list and an array?

This is VERY different than perl, so beware. In .NET arrays are more like C arrays. They are fixed length at time of creation. They represent a contiguous block of memory. Lists are anything that implements IList. Usually this is System.Collections.ArrayList or System.Collections.Generic.List<>

The generic List<> should almost always be preferred to use of ArrayList.

Array’s have a Length property. Lists have a Count property.

In boo there is also Boo.Lang.List which is what you get when you use [] notation. () notation give you a real array. Boo is smart enough to recognize if all the types of an array are the same and return an array of that type. Otherwise boo gives an System.Object[].

What is the difference between $array[1] and @array[1]?

boo doesn’t have these language issues.

How can I remove duplicate elements from a list or array?

Use a Dictionary (hash). When you think the words “unique” or “duplicated”, think Dictionary keys.

If you don’t care about the order of the elements, you could just create the Dictionary and then extract eh keys.

words = [ "one", "two", "three", "one", "four" ]

dict = { }

for s in words:

  dict[s] = true

How can I tell whether a certain element is contained in a list or array?

Hearing the word "in" is an indication that you probably should have used a hash, not a list or array, to store your data. Hashes are designed to answer this question quickly and efficiently. Arrays aren't. (Christiansen & D'foy, 2007)

***** I LEFT OFF HERE ****

Both Array and List have an Exists method. List also has a Contains method.

//TODO: boo generic types

// goodcolors = List<string>([ "Red", "White", "Blue" ])

okcolors = [ "Teal", "Pink" ];<