Monday, January 05, 2009

Timestamping F# assembly versions

Following up to the previous post, with this script Timestamp.fsx (unchanged by the Feb 2010 CTP, but enhanced to show the current year when it is no longer 2009):

suitably adjusted to taste in your main project folder, and a pre-build step of

cd ..\..
"C:\Program Files\FSharp-1.9.6.2\bin\fsi.exe" --exec Timestamp.fsx

or in the Feb 2010 CTP

cd ..\..
"C:\Program Files\FSharp-1.9.9.9\bin\fsi.exe" --exec Timestamp.fsx

you can get an automatically timestamped assembly, as per a C# 1.0.* version.

Note that using [< assembly: AssemblyVersion(\"1.0.*\") >] gives an assembly version of 0.0.0.0 in the DLL manifest, and no file version whatsoever.

You will have to bootstrap the process by creating a dummy AssemblyInfo.fs, and adding it to the project -- but of course not checking it in to source control or anything like that, since it is recreated every build.

Later: If the 4th facet exceeds 32k, it ends up set to zero, so change the factor to 3 in let revision= ((int fraction.TotalSeconds) / 3) for those end-of-UTC-day builds...

Links for 5-Jan

Just a small selection from the last week or so, and not even trying to keep up with PoSh v2CTP3 goodness -- I will be so pleased when that gets to go-live state!

AssemblyInfo.fs usage for F# DLLS and console executables. Note that the ability to default build and revision numbers as in [<assembly: AssemblyVersion("1.0.*")>] is not provided for you -- time-stamping has to be done externally e.g. by a pre-build step.

Generics in XAML.

Avoiding deadlocks when redirecting stdin/out/err for spawned processes in .Net code.

Speech recognition with .Net 3 and speech synthesis too!

Thursday, January 01, 2009

The first day of the rest of my life

After a good week last week, Karen's MS has really bitten her these last few days, both physically and mentally. On the bright side, it is the first real attack, rather than just slow progression, for a long while. Still, it looks like I'm going to have to pretty much everything about the house and more body-servant work while getting some formal assistance involved.

All this and work too, tomorrow.

2008 in media -- retrospect

Film : apart from the handful at the Film Festival, cinema seemed to be either the standard extruded product from the bowels of Hollywood, or English-miserablist. The only one I saw was when taking Karen to see Georgiana, and that I didn't rate.

Books : almost everything I read was software related -- for SF, see above about extruded product. My recommendation on the software front would be F# for Scientists, which did the basic teaching necessary to make the other books (Foundations of..., Expert...) somewhat more comprehensible. Foundations in particular is a poor introductory text as it hides the descriptions of syntax (as opposed to accidents of the examples) in solid paragraphs of text -- you need to have grasped the language before you can really get to grips with the book.

Anime : the year when Aniplex hired an outfit to send out DMCA notifications, where fansubs were slow, but some titles were for the first time officially simulsubbed or nearly so (of which only Strike Witches took my fancy). A fair number of OK-to-good series from the middle of the year, but nothing as outstanding as '07.

No real highlight, unless Mouryou no Hako delivers as it has begun, and only one that was so bad that I regretted having watched the one episode (Mnemosyne); though quite a lot that failed out of boredom (Spice & Wolf, Shigofumi Telepathy Girl Ran).

Other titles get separate mentions earlier, or get covered in spring and summer round-ups.

F# CTP and Silverlight 2 redux

Following up from here.

Units of measure are indeed useful, especially once one has twigged that the syntax needed to generalize over the units involved is like

and that you need to go the F# built-in math functions to have ones that are themselves so generalised.

So, here is the mostly essentially finished example applet (still needs to compute and draw the moon phases) with source bundled into the .xap file

Tuesday, December 30, 2008

Anime — Allison & Lillia

On a world that is not our Earth, two nations that share a continent have long been at odds, glaring across the separating river, and often breaking out into war. In a period akin to the inter-war years of Europe, these two nations have fallen into an uneasy armistice. Two young people, Wil and Allison, learn from an old man of a secret treasure that could end this seemingly eternal war.

That is a set-up that could last a whole series -- but that's just the first 4 episodes; and in the peace that follows there is skullduggery afoot seeking to reignite the flames of conflict. That provides for a series of escapades, including the involvement of our heroes with the royal family of the tiny statelet of Ixtova; then at the half-way mark, the torch passes to the next generation, Lillia, daughter of the original pair, and Trieze, incognito prince of Ixtova.

It's rather Tintin-esque in flavour; with firearms proving a threat but (except in one case of an old chap needing to exit the stage for plot reasons) never doing any harm. And there are magnificent old style train and aeroplanes.

There is a continual motif of the couples never realising each others' feelings, which one has come to expect from anime, but that never really gets in the way of a good Boys' Own style of adventure. The real weak point is the ending, which is, if you pardon the pun, a bit of a trainwreck -- the last episode is very poorly paced, and uneven in style.

Still, not bad in all -- the journey was fun, if a bit delayed.

Nice idea while it lasted…

To summarize -- if your Scala.Net project only uses .Net 1 features, then you can tweak the IL to use the .Net 2 libraries if you wish; but you can't build something that invokes full .Net 2 functionality as yet.

That means trying to build a Scala project against Silverlight assemblies is a non-starter (or at least not a trivial one) with the current build process. Using the out-of-the-box assemblies:

scalac-net.bat astroclock.scala -Xassem-path 
System.Core.dll;system.dll;System.Windows.Browser.dll;System.Windows.dll
12@(06 15 12 80 ad 02 12 80 b1 12 88 c8)
error: error while loading Control, type 'System.Windows.Controls.Control' is broken
(15@2 in (06 15 12 80 ad 02 12 80 b1 12 88 c8))
9@(06 15 12 80 b9 01 12 86 80)
error: error while loading FrameworkElement, type 'System.Windows.FrameworkElement' is broken
(15@2 in (06 15 12 80 b9 01 12 86 80))
11@(20 01 15 12 25 01 12 78 11 85 b4)
error: error while loading UIElement, type 'System.Windows.UIElement' is broken
(15@3 in (20 01 15 12 25 01 12 78 11 85 b4))
11@(06 15 12 80 ad 02 12 86 38 11 5c)
error: error while loading DependencyObject, type 'System.Windows.DependencyObject' is broken
(15@2 in (06 15 12 80 ad 02 12 86 38 11 5c))
9@(06 15 12 80 b9 01 12 86 10)
error: error while loading Application, type 'System.Windows.Application' is bro
ken
(15@2 in (06 15 12 80 b9 01 12 86 10))
astroclock.scala:90: error: System.Windows.Application does not have a constructor
class MyApp extends Application  {
                    ^
…

while rebuilding the assemblies against either .Net 2.0 or silverlight mscorlib and trying again gave the even more fundamental, but well known

scalac-net.bat astroclock.scala -Xassem-path 
System.Core.dll;system.dll;System.Windows.Browser.dll;System.Windows.dll
error: error while loading String, type 'System.String' is broken
(PEModule.getTypeDefOrRef(): TypeSpec)
one error found

So, to do this would mean upgrading the scala-net compiler to understand .Net 2.0 constructs.


Later:--

In constructs like (15@2 in (06 15 12 80 ad 02 12 80 b1 12 88 c8)), the 0x15 (at position 2) is the code ELEMENT_TYPE_GENERICINST, which is then followed by <an mdTypeDef metadata token> <argument Count> <arg1> ... <argN>. The type metadata turns out to be a type-spec; but the rest of it I've not yet unpicked. And then there'd be reverse-engineering the Scala MSIL decompiler...

The first culprit is DependencyObject (#22 in the typedef table), for a private field; but there are dependency properties on UIElement which suffer the same.

Monday, December 29, 2008

Scala-light?

I ordered a copy of Programming in Scala last Sunday -- and to my surprise, it arrived on my doorstep this morning. This, of course, deflected me from my F# and Silverlight activity today.

I think I shall have to try the experiment of putting Scala.Net into Silverlight, just as part of my usual "can I wedge this into that" play.

I would start with the recipe as before, in the library form; but to retro-fit a link against the Silverlight mscorlib which has the signature

rather than the mainline .Net 2.0 assembly.

What fun toys these are!

Sunday, December 28, 2008

F# CTP and Silverlight 2 and XAML

Following up from yesterday, the rudiments of the clock, to show XAML integration in the F# plus Silverlight combination. This should be enough of a template for starting with and mutating to taste.

The code is unchanged in the Feb 2010 (v 1.9.9.9) CTP.

astroclock.xaml:

which we note has a UserControl as root, and astroclock.fs:

with the obvious AppManifest.xaml:

LATER: Data binding sort of works sometimes; I can get it to work when set at run-time to bind a string to a TextBlock via myTextBlock.DataContext <- this.StringProperty (but not yet through XAML), and Sliders are being totally recalcitrant...

I think there is some autogeneration magic just not happening for F# -- the best I can get seems to be to approximate a one-time binding -- so it's back to wiring up events by hand.

Saturday, December 27, 2008

F# CTP and Silverlight 2

Feb 2010: This post is probably obsolete as we're coming up on Silverlight 4.0, so I've not retested. You might get away with changing the 1.9.6.2 version in the file path to 1.9.9.9 now.

Tinkering with my silverlight/IronPython planetarium clock, I find that the bulk of the errors I'm making are in units of measure -- is this angle in degrees, radians, hours or days? This is just the thing that F# CTP has built in features to cope with. So, proving the concept of Silverlight with F#...

Google turns up a bunch of references, some assuming a full Visual Studio while I'm developing on a laptop with just IronPython Studio and F# part of the time; others slightly out of date (still referring to System.Windows.Controls.dll from the beta).

The latter, John Liao's post, looked promising, though, so I duplicated it thus--

  • New F# library; paste the code in to the autogenerated Module1.fs
  • Remove all references supplied by default
  • Add a reference to System.Core and to System.Windows by navigating directly to the Silverlight SDK binaries in C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies -- at this point you can also add any others you're going to want
  • Use the suggested AppManifest.xaml without the System.Windows.Controls.dll line
    <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" 
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                RuntimeVersion="2.0.31005.0" 
                EntryPointAssembly="SilverLightFSharp" 
                EntryPointType="SilverLightFSharp.MyApp">
      <Deployment.Parts>
        <AssemblyPart x:Name="SilverLightFSharp" Source="SilverLightFSharp.dll" />
        <AssemblyPart x:Name="FSharp.Core" Source="FSharp.Core.dll" />
      </Deployment.Parts>
    </Deployment>
  • create a folder in $(ProjectDir) called simplebutton and copy C:\Program Files\FSharp-1.9.6.2\bin\FSharp.Core.dll into it, along with the AppManifest.xaml above
  • create an empty file null.py in the folder to keep chiron quiet
  • Add the following post-build steps
    cd $(ProjectDir)
    copy /y $(OutDir)$(TargetFileName) simplebutton
    "C:\Program Files\IronPython 2.0\Silverlight\bin\chiron.exe" /d:simplebutton /z:simplebutton.xap
  • Use the suggested TestPage.html, putting it in $(ProjectDir)
  • Build project
  • Load page in browser and enjoy

Note that the FSharp.Core.dll assembly is crucial in the manifest, even though it's not needed as an explicit reference in the project at build time -- everything links happily with it as an implicit component for building -- but without it there in the manifest and the XAP, the Silverlight content fails to load, silently, without putting up anything into the error reporting <div> as a cry for help!

For our Gauleiter of Culture

A propos of this.

OnePlusYou Quizzes and Widgets

"This rating (G) was determined based on the presence of the following words: stab (1x)"

But also

blog readability test

which probably rules out any pols.

Also, at the typealyzer

ISTP - The Mechanics

The independent and problem-solving type. They are especially attuned to the demands of the moment are masters of responding to challenges that arise spontaneously. They generally prefer to think things out for themselves and often avoid inter-personal conflicts.

The Mechanics enjoy working together with other independent and highly skilled people and often like seek fun and action both in their work and personal life. They enjoy adventure and risk such as in driving race cars or working as policemen and firefighters.

A week of contrasts

Saturday last, getting up early-ish to get hair cut, and attend to vanities before going out in the evening, so driving into town rather than taking advantage of the mild weather. Town was quiet, the only real activity a long queue in Borders; though Morrison's had been very busy Friday late morning.

Sunday, very mild, cycling to the garden centre with just an open denim jacket over my T-shirt, for sake of sleeves, and sandals on feet.

Two days at work, winding down, some self development, some tidying up of bugs, getting home with 29000 on the odometer as I parked. Wednesday, cooler, and dull, OK for cycling -- but had brightened to T-shirtable when I nipped out for lunch. Usual dinner with friends in the evening, even if being designated driver takes the edge off.

Thursday -- don't get up at all; drift downstairs for breakfast to eat in bed just before dark.

Friday -- drive to the in-laws, with the A12 being quite busy, and slow to the Blackwall Tunnel. Coming back being surprised on the M11 to often be cruising past traffic in the slow lane when only doing 60 myself.

Today -- hard, white frost again overnight. Drive in to town late morning for a few odds and ends to find the place seething. In all respects, the opposite of last week.

Friday, December 26, 2008

Silverlight 2 and Opera

To make the previous example also work on Opera I would have to

  • Set the data on the object to be "data:application/x-silverlight-2," to get it to work at all
  • to restore the effect of transparency remove the <param name="windowless" value="true" />
  • set an opaque value rather than <param name="background" value="#00000000" /> matching the page background colour
  • manually tile a matching background image and set background image brush with Stretch="None" to match any page background image

In particular, there seems to be no obvious way to get at the parameter set of the object from JavaScript via a DOM look-up on the <object> tag, otherwise I would have done some jQuery magic via browser sniffing instead.

Bug in my jQuery usage. BRB

You can do something like

but once you've tiled with an opaque image, there's no effect (even if this substitution were in fact in time to be useful).

Sample here.

I guess such customization would be possible via the silverlight.js file; however that needs tome work of its own to fix up to provise silverlight 2 data types.

Tuesday, December 23, 2008

PoSh v2 CTP3 linkfest

The release notes give a view from 50,000 feet; the help file stubbornly refuses to play for me (the document window gives a 404 error); but there's already some stuff about the new material out on the 'net:

CTP2->3 migration guide.

Module Manifests

Advanced functions (previously script cmdlets).

Eventing.

Parameter sets for advanced functions.

Updated remoting.

Hmm. This looks like it might resolve those 404 issues...

PoSh v2 CTP3 is out

Download here : http://go.microsoft.com/fwlink/?LinkID=131969

Although it states:

  • Windows PowerShell V2 CTP3 release is compatible with and replaces previous versions of Windows PowerShell. To install the Windows PowerShell V2 CTP3 release you must uninstall any previous version of Windows PowerShell.
  • Windows PowerShell V2 CTP3 uses the execution policy setting from the previous installation, if present. The Windows PowerShell installer does not remove or change the execution policy when you uninstall Windows PowerShell.

On XP, I got bumped from a previous Unrestricted to AllSigned, as I found when starting up the new shell for the first time and getting my start-up script denied.  Going Set-ExecutionPolicy unrestricted then resulted in

Set-ExecutionPolicy : Windows PowerShell updated your
execution policy successfully, but the setting is overridden by a
policy defined at a more specific scope.  Due to the override, your
shell will retain its current effective execution policy of
"AllSigned". For more information, please see "Get-Help
Set-ExecutionPolicy."
At line:1 char:20
+ Set-ExecutionPolicy <<<<  unrestricted
    + CategoryInfo          : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
    + FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Com
   mands.SetExecutionPolicyCommand

Running the C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe executable directly (not via shortcut) as the local Administrator (right-click, Run as...) lets that user change settings without spitting out a message stating that this is futile; but that is not propagated globally.

Other users (like my usual login) trying to run scripts still got the same

File ...\???.ps1 cannot be loaded. The file ...\???.ps1 
is not digitally signed. The script will not execute on the system. 
Please see "get-help about_signing" for more details..
At line:1 char:2
+ . <<<<  '...\???.ps1'
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

as before, and going Set-ExecutionPolicy unrestricted still results in the same message as above, too!

I've not yet found an official work around to this override through PoSh itself -- but you can directly frob the setting by going to the registry (OK, you can do this in PoSh as well, but it's still "cheating") and setting the value of HKEY_CURRENT_USER\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ExecutionPolicy from AllSigned to Unrestricted.  Although running as Administrator has changed the key at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ExecutionPolicy to Unrestricted, any per-user setting that has already been struck from this pattern seems to remain to override this.

LATER : setting the HKCU value to RemoteSigned then leaves me at Unrestricted, until I similarly edit the HKLM key as well. LOL WUT?

Set-ExecutionPolicy still remains ineffective as a normal (local administrator) user.