2007-04-28

DSL vs. Rich Native Syntax

It's interesting - there is so many different projects which authors declare as an advantage that a project does not use (strange) Domain Specific Language, but where everything is implemented in the same host language.

Sometimes it comes out more beautiful, sometimes it is not.

Tried ZestyParser.

Here is the banal parsing of a phrase "create or replace"
from ZestyParser import *

sp = Omit((RE('\s+')) + Skip((RE('#[^\n]*\n') | RE('\s+'))))
create_package = RawToken('create') + sp
+ ((RawToken('or') + sp + RawToken('replace')) | EmptyToken)
ZestyParser('create or replace').scan(create_package)

I have to dig it further, so far it comes out ugly enough.

2007-04-20

There is only one right include strategy

There is only one right way of the implementation of searching of included files. In case if include contains a relative path it should be relative to the folder where the inclusive file is placed. Actually, it is so in C/C++.

Either I do not understand something, or Nant has surprised me
Let's take the following folders structure:

./
a/
a.build
all.build
common.build

I'd like to build project «a» if I'm located at folder «a» and if I'm in the root I'd like to build all projects.
The situation has become complicated because of the common file common.build which contains required useful settings.

At a first sight nant includes files relative to a current working directory (basedir project attribute)

The contents of a.build file

<project name="all" basedir="..">
<include buildfile="common.build"/>
<echo message="building a type - ${type}"/>
<echo message="base-dir ${project::get-base-directory()}"/>
</project>


The contents of all.build file

<project name="all" basedir=".">
<include buildfile="common.build"/>
<include buildfile="a/a.build"/>
<echo message="building all type - ${type}"/>
</project>


Run a.build being in folder a - everything is cool.

Being in the folder with the file all.build - run:

NAnt 0.85 (Build 0.85.2478.0; release; 14.10.2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///D:/Temp/2007-04-19/all.build
Target framework: Microsoft .NET Framework 2.0


BUILD FAILED

D:\Temp\2007-04-19\a\a.build(3,7):
Build file 'D:\Temp\2007-04-19\a\common.build' does not exist.

Total time: 0 seconds.


I have the impression that files included in the main file are searched relative to the working directory, but the files included into included files are searches relative to the inclusive file.

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?