Category Archives: Tips’n Tricks

Building your own power tools: an Example

Using ZnLogEvents and GT Tools to look at HTTP traffic behind Monticello.

I love it when a plan comes together. Many small usability changes were added to GT Tools since they were included in Pharo 4. And a lot of small custom inspector presentations were added.

  http://youtu.be/rIBbeMdFCys  (be sure to select the 720p version)

This short screencast shows how to use ZnLogEvents and GT Tools in Pharo 4 to look at the HTTP traffic behing Monticello (more specifically, an MCSmalltalkhubRepository). This demonstrates how simple custom inspectors are combined to form a powerful tool - and how easy it is to learn about what is going on inside Pharo or inside your complex business app

Sven
Advertisements

Blog translator

Udo Schneider wrote a nice blog article on how to use block as translators.

All,
I just finished a blog entry. It shows how to use Smalltalk blocks as parsers/translators. E.g. translating a Block
[:customer | (customer joinDate year is: Date today year)]
into an SQL-like String
(YEAR(customers.joinDate) = 2014)
The SQL stuff is just an example – you can create nearly any output.
Check out http://readthesourceluke.blogspot.de/2014/09/block-translators-parsing-magic.html
Maybe that’s old stuff for some of you – but I hope it’s interesting for some at least 🙂
Comments and feedback appreciated.

CU,

Udo

Bit fiddling in Pharo

Here is an interesting mails about BitSet. It is a bit (hahaha) covered in the chapter on little number of http://deepintopharo.org

Hi Pablo,

can you be more specific why you need a BitSet class other than convinience? What do you
want to do?

Note that for bit handling in Smalltalk you can easily just send messages to integers
or large integers:

Access bits:    12 bitAt: 1              -> 0
Modify bits:    12 bitAt: 1 put: 1       -> 13
Print binary:   12 printStringBase: 2    -> ‘1100’
Print hex:      12 printStringBase: 16    -> ‘C’
Large number:   67677557657 printStringBase: 2  ->  ‘111111000001111001011001001110011001’

There are also #bitAnd:, #bitOr:, #bitXor: messages:

12 bitOr: 1  -> 13
12 bitAnd: 8 -> 8

and you can use the abbreviations known from C world:

12 | 1    -> 13
12 & 1    -> 0

If you want to see the bit representation just print as a string with base 2:

12 | 2 printStringBase: 2  ->  ‘1110’

So for octal use:

12 | 2 printStringBase: 8  -> ’16’

If you disklike to stay in decimal system you should be aware that in
Smalltalk you can easily write a number in different bases directly
using the “BASE, followed by r followed by number” representation.

So you can for example write:

12
as  2r1100
as 16rC
as 10r12 (decimal again)
as 8r14 (octal)
or any other base that you like directly

With this you can also easily manipulate bits while writing in bit representation:

2r0001 bitOr: 2r0101  -> 5
same as:  2r0001 | 2r0101       -> 5

when you need the result again as bits:

(2r0001 | 2r0101) printStringBase: 2  ->  ‘101’

Many other convinience methods are there like:
12 hex                      -> ’16rC’
12 printStringHex           -> ‘C’
$A hex                      -> ’16r41′
$A printStringHex           -> ’41’

Feel free to mix all that

(16rFF00 | 2r00001) hex  ->  ’16rFF01′

Try to get used to these methods and you will have fun with bits
in Pharo Smalltalk easily.

If you need something more tell us, a BitSet class implementation
could be easily written using the above as a base.

Bye
T.

Tagged