2007-04-06

Generic Visitor Combinators

It's simple and practical - Visitor Combination and Traversal Control.

The main idea is to separate specific code that executes concrete actions from the code that effects visits check.








IdentyDo nothing
Sequence(v1,v2)Sequentially perform visitor v2 after v1.
FailRaise exception.
Choice(v1,v2)Try visitor v1. If v1 fails, try v2 (left-biased choice).
All(v)Apply visitor v sequentially to every immediate subtree.
One(v)Apply visitor v sequentially to the immediate subtrees until it succeeds.


So, it's rather flexible to implement different actions by combine it and inherit from it.


TopDown(v) = def Sequence(v,All(TopDown(v)))
BottomUp(v) = def Sequence(All(BottomUp(v)),v)
IfZeroAddOne = def TopDown(Try(Sequence(IsZero,AddOne)))

2007-03-30

Usability: jalousie

I have difficulties...Every time to understand which string should be pulled in order to open or close jalousie I have to examine what's going on above and where the limiters are placed. Or to detect the required string by the hit-and-miss method.

The problem of visual indication is easy to solve — I just have to paint the string into gradient color ring. Now jalousie are closing if blue color is closer to you.

The opened question is tactile indication. How the beads shape should be changed so that the fixing mechanism could work and in the same time it would be convenient to pull both bottom-up and up-bottom?
Cool idea — thanks to mikhail_maximov: As a variant — stick a nail into a wall so that the string will catch on it and you'll be happy: left up — to open, right up — to close, if you'll pull the string the other way the action will be inversed ;-)

But we still need the visual indication, it can be implemented just by grey gradient — if you wish to close jalousie, you should pull down the darker part of string.



2007-03-27

Web: shamanism

Good heavens!
To make a fixed block be still when you scroll a page in Microsoft Explorer, you have to fix a page background(!)
body
{
background: url('/n.gif') no-repeat;
background-attachment: fixed;
}

2007-03-12

PowerShell - The first one object(!) shell


...Microsoft Exchange Server 2007 where everything is done via command line interfaces and the administrative GUI is layered on top of those commands.
Wikipedia


Came across it by accident.
get-process | where { $_.WS -gt 1000MB } | stop-process

It's beautiful... now through pipes goes not only just text but full-fledged .NET objects, anytime and everywhere one can easily get access to a required object field. Farewell, sed and awk.

Killer feature - the possibility of creation and trying COM-object just in interpreter.
$a = New-Object -comobject Excel.Application
$a.Visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "A value in cell A1."
$b.SaveAs("C:\Scripts\Test.xls")
$a.Quit()

It makes me glad that methods autocompletion works.

According to one's choise any .net build can be loaded.
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$d = [Windows.Forms.MessageBox]::Show("msg")

Аnd one can send e-mail
$Attach     = new-object System.Net.Mail.Attachment("C:\Test.txt")  
$SMTPClient = new-object System.Net.Mail.SMTPClient
$Msg = new-object System.Net.Mail.MailMessage

$Msg.Attachments.add($Attach)
$Msg.To.Add("BillGates@Microsoft.Com")
$Msg.from="Vasya.Pupkin@Mail.Ru"
$Msg.Subject="Subject"
$Msg.Body="This is body of E-Mail"

$SMTPClient.Host="SMTP.Mail.Ru"

$SMTPClient.Send($Msg)

There is a simple auto-completion of paths. There is even Far plug-in

In short, it's a practical thing for those on Windows.

I'm curious, if there were some tries of objects extension of shells under *nix?

2007-02-26

What is taught in schools...

I discussed with my little sister her university programming tasks again. Even if to abstract from the maxim «Pascal is the best language for teaching» ™ IMHO still there are two important problems:

1 Something is told prematurely — the necessity of such solutions can be understood only conforted by the problem by oneself
2 Not the process of how somebody came to the idea of a solution it is told but the result only.

The separation to a file system and an on-line storage is not necessary, binary number notation was chosen because it is easy to implement; if you so need to bind a program into one big execution file beforehand then you will need the separate compilation for really large projects only.

The modules support in the language is not better than the simple agreement: «do not call functions with names start with xxx».

The knowledge of the result only forms one-sided view of things — it can be done in this way only... misunderstanding of why the result is exactly like this leads to non-using it where it is really needed.

Next time I'll summon my strength and try to explain what the procedures and functions are, what is the black box abstraction and so on.
For my sister has no doubts any more that to write the whole program inside one switch is not good.


Update One more interesting point have come to the surface — students visit lectures, study algebra, math logic, analytic and differential geometry. Teachers say: would you like a bonus? Write a program... find how many non-isomorphic graphs there are for the given number of edges and vertices or factorize a symmetric polynom to prime factors.

Oh... in Pascal? I'm curious how many lines of code a student will write until he stops to understand what sort of FL1, FL2 means, where RuntimeError 210 occurs and what is required to get at all?

2007-02-16

What a wonderful world ....

It's hard to believe but it's true: If in the decimal representation of a fraction 1/p, where p is prime number and the length of a period is even then after adding the first half of the period with the last one we'll get only nines(!)

For example:

1/7 = 0.(142875) 142 + 875 = 999
1/13 = 0.(076923) 076 + 923 = 999

2007-02-12

You can't take a step without SQL

Cool problem at Project Euler - Find the sum of the only ordered set of six cyclic 4-digit numbers for which each polygonal type: triangle, square, pentagonal, hexagonal, heptagonal, and octagonal, is represented by a different number in the set.

I just felt that it is ideal for sql ... I used my brains and as a result I've got a small table and a small, absolutely dumb query.

I'd like to have a-la «implementation schedule» support in languages not relating to db.