Really cool Curl

I was pointing out JSForth to a developer on-line (Forth interpreter in JavaScript) which I thought was cool but then I see this in Curl: a folding coding window in a web page.

Here is the Curl 5.0 code for the applet:


{curl 5.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
{applet manifest = "manifest.mcurl"}

{include "./utils/guide-header.scurl"}
{include "./utils/support.scurl"}

   {x-example-ref
        title = "Folding Tree example",
        {url "./examples/RIA_with_Curl.curl"}
    }

What this does is create a labeled hotspot on my page: with one click an entire Curl client-side scripting environment opens. The running example is there; the code that is running is there; buttons to execute, save applet; revert changes; close popup – and the panel allows editing the script.

Clicking on ‘Execute’ causes a popup version of the script to run with your changes.

I had seen this cool way of working with code as part of the example macro

{example

}

What was new was the ‘expandable’ and ‘collapsible’.

I cannot imagine this being more concise in JavaFX or in Groovy. Here is the Curl procedure from the include file:


|| Copyright (C) 1998-2006, Sumisho Computer Systems Corp.
|| All Rights Reserved.
{define-proc {x-example-ref
                 title:String = {message Example},
                 href:Url, ...}:Visual
    let display:Graphic = {example-ref title = title, href, ...}
    {for-each-graphic
        {proc {g:Graphic}:void
            {type-switch g
             case g:TextEditPanel do
                || consume right click, so TreeControl ignores it
                {g.add-event-handler
                    {on e:PointerPress do
                        {if e.button == right-button then
                            {e.consume}}}}}},
        display}
    {return
        {text-width-display
            {expandable
                border-width = 2px,
                {bold {value title}},
                display}}}
}
|| *** calls the following ***
{define-proc public {example-ref
                        loc:Url,
                        title:#String = null,
                        base-url:Url = {get-base-url},
                        manifest:ComponentManifest =
                           {get-default-manifest},
                        package:OpenPackage =
                            {OpenPackage
                                CURL.IMPLICIT.APPLET,
                                CURL.IDE.DOCUMENTATION,
                                manifest = manifest},
                        ...
                    }:Graphic
    let result:any =
        {try
            {evaluate
                base-url = loc,
                package = package,
                {format "\{example title = %w,\n %s\}",
                    title,
                    {read-from loc}}}
         catch e:Exception do
            {paragraph
                Error in {bold {value loc}}:{br}
                {text color = "red", {value e}}}}
    {return {Frame result, ...}}
}

It is perfectly readable. When you see ‘…’ inside { } what you are seeing are rest arguments, or unnamed arguments for variable parameter procedure calls. And then again in the

{ return {Frame result, …} }

– these are not code elisions! The critical {example } macro is in the evaluate block. Dynamic language fans will note that the result is their preferred type: any.

And to learn to use this expand/collapse ‘live’ code environment/widget all I had to do was right-click on a folding code-editor page in the Curl Documentation Viewer which is itself Curl. I copied in the files to include for my applet and set a few imports in my ‘manifest.mcurl’ file. No CLASSPATH to look at, no question of which JARs are where. No JavaScript library required. As cool as Smalltalk, Strongtalk or the XOTcl IDE.

To see one in action, you will need the XML Document Model for Curl 5.0 from curl.com
Just install the RTE, then the IDE and then the XDM. Open your Documentation Viewer and search for ‘WSDK XML Document Model’ or just ‘build-xml

The proc identifies an anonymous procedure and we pass in what Groovy calls a ‘closure’ at on e:PointerPress do or what would likely be an inner class Listener in Java.

If you know something as cool using FLASH with ActionScript, post a snippet or a link to same.
Of course you could do this using AJAX with Prototype and Scriptaculous. But I got this page out in a matter of minutes. Oh yes, Sun says JavaFX is not about ‘throwing up pages’ …

Imagine that you are working on a problematic page. You drop in a gem like this and now you are displaying and experimenting with your code. Only Seaside for Smalltalk can rival this as far as I am aware but that requires some understanding of Smalltalk. I love Seaside, but I know of nothing that can beat this. Of course Rebol 3.0 is on the way …

As for snide remarks from Sun in their JavaFX promo, there are quick ways to throw up a web page… I like blocknote and there is the Meta/HyperCard Revolution product or even MS Word or FrontPage in a pinch…

Leave a Reply

You must be logged in to post a comment.