Wednesday, December 15, 2010

Curl memoization and a PEG parsing pkg

A text search of the Curl 7.0 docs using the Curl Documentation Viewer finds two mentions of Memoizer-of but only one is an implementation note:
make-SocketInetAddress-from-address
Memoizer-of is documented as
{Memoizer-of domain:Type, range:Type} (class)
This memoization class or its near equivalent would be crucial to getting PEG parsing into Curl as a package for a regexp alternative.
The other mention in the docs is suggestive and occurs as one of the notes to the docs on BucketHashTable-of of the package CURL.LANGUAGE.CONTAINERS

public final serializable BucketHashTable-of {inherits {Association-of tk, te}}

With regard to regexp, the Curl GUI packages already come with a RegexpValidator class for controls relying on use of CURL.LANGUAGE.REGEXP

Btw, great demos of the power of the Curl Documentation Viewer are the Regular Expressions doc pages with their 'live-code' examples for learning PCRE.

Tuesday, December 14, 2010

Curl ValueControl

Here's a challenge for class hierarchies without Traits.

The Curl class ValueControl is noted as follows in the docs:

ValueControl (class)
public abstract ValueControl {inherits Control}
Import from: CURL.GUI.STANDARD. Defined in package CURL.GUI.CONTROL-BASE.
Direct Known Subclasses: ValueControl-of
A superclass for any Control that has a value.
Description
All the Controls with values inherit from this class. It provides abstract accessors for the value, as an any, and an accessor for the expected Type of the value.
Overriding
Don't subclass this class. Subclass ValueControl-of instead.
I added emphasis to the advice. My question is, how might such an intent be enforced in a class hierarchy?  What would you call such a modifier or a macro used to create such a class?

The class in question has the 2 abstract methods value-type and value-as-any but it also implements 2 methods: form-value and has-value?.  In addition, it has a class procedure form-string.  The default constructor for the class is noted as
... : Rest arguments are passed up to Control, which passes them to Visual.
The method form-value is documented as intended for use with controls embedded in HttpForm instances.
It is documented as a getter but not as being abstract yet as intended to be overridden by subclasses.

Here is a snippet from those docs;
The value returned by this getter must be one of the following:
 • String
 • array of String
 • null
Notes
Each control overrides this method to return the value that needs to be sent when the HttpForm that contains this control is submitted.

So why is the method not abstract? Well, because it returns a value of type any - but its subclass is parameterized for types of values.  And here is one more thing that makes Curl fascinating: the leaf classes of these hierarchy branches are not themselves declared as parameterized for a type - and in the case of DateField, the value keyword parameter to the default constructor may be of a possibly-null type - a #DateTime type.

What this may show is that multi-inheritance with partially-abstract classes as mixins or otherwise can be very flexible:
public abstract MultiUIValueControlFrame-of {inherits 
   MultiUIControlFrame, 
   {ValueControl-of tValue}}

value classes in Curl

The Curl language for the last two versions has allowed explicit declaration of value classes used to create objects which can be moved on the stack rather than referenced on the heap.

There is an important tip in the Curl docs that one should keep such an object smaller than 64 bits so that it can be referenced as a simple any variable with no further memory allocated, i.e., why keep an object off the heap and then have allocate for it just to use it ...

A usual class declaration in Curl begins as the macro
{define-class
and these non-reference classes begin as
{define-value-class
which is in keeping with an accepted pattern as easy to recall.  But there are some caveats and they are laid out clearly in the docs.
The docs list Keycode, Pixel, and Vector2d-of as long having been implemented as value classes.

The Curl Documentation Viewer allows you to choose an installed version when opening another viewer, so I hopped down from 7.0 to 5.0 to look at Pixel - it was reported as (class) and not (value class) but perhaps that kept things from getting murky.  More often Curl docs state that a given feature is for internal use only.

rlwrap for the Curl shell

It is really essential to get a wrapper around some REPL's - the Curl shell is an example.

I run
rlwrap /opt/curl/surge/8/bin/curl --shell
which gives sane keystrokes and a command history.  If you are a client web developer coming over to the server-side, it is as essential a tool as egrep.

Pharo Smalltalk linux config

This would seem to be essential to working with Pharo Smalltalk on a daily basis on linux: pharo.st

Property ECMAScript5

If you are looking to port JavaScript3 up to strict ECMAScript5 in whole, part, stages but you have some choice for mission-critical applications, here is a glimpse from the package CURL.LANGUAGE.REFLECTION
Property (class)
public abstract sealed Property {inherits ClassMember}
Package: CURL.LANGUAGE.REFLECTION
Direct Known Subclasses: Getter, Option, Field, Setter
The representation of a property: Field, Getter, Setter, or Option.
The Property class provides a singular point of contrast for a mature web language against a maturing web language.

What is facilitated are such primitives of the Curl language as private-set
field public-get private-set key-field:int
There is as yet no tool for PITL with CommonJS packages comparable to the ability of the Curl Documentation Viewer to display selectively only public, non-inherited properties of a class as part of a package.  And what is PITL without such tools for communicating what is in a API?  Now look for comparable 'live-code' example facilities for training developers new to a language (they may yet appear in JavaScript as part of Avocado with Lively-Kernel.)

When I hear advocates of reusing an existing JavaScript codebase for PITL on industrial-quality server-side applications I wonder whatever they can be thinking?  Would this have been an aerospace argument to stick with aluminum?  After all, there are more aero-mech's out there accustomed to repairing aluminum aircraft components ... and far more aluminum in the air - and it was aluminum that made the air travel age possible ...

Monday, December 13, 2010

Curl BaseFrame

The Curl class BaseFrame is declared as
public BaseFrame {inherits BasicBox}
and is not abstract. Frame inherits from it as
public Frame {inherits BaseFrame}
and is certainly not abstract. But a RootFrame to root a graphic hierarchy is declared as
public abstract sealed RootFrame {inherits Frame}
and is abstract -yet its immediate subclass View is declared as
public View {inherits GuiRangeSelectionContext, RootFrame}
and is a very common class for concrete instances.  GuiSelectionRange is also abstract and is declared as
public abstract GuiRangeSelectionContext {inherits TextSelectionContext, BaseGuiRangeSelectionContext, ContainerDragScroller, OptionListInterface}
RootFrame and GuiRangeSelectionContext are performing a special role that Traits or Mixins might perform in another language.

View has a need to have its visibility specified as a property, which can be a stumbling block in first experiments with Curl. Here is an example:

{curl 7.0 applet}
{import WindowVisibility from CURL.GRAPHICS.WINDOW}
{View visibility=WindowVisibility.normal,
   {text Some text that will appear in a freestanding window}
}

View has an interesting subclass which is rather like the first window one used to create for MS Windows back in the days of C using only a frame: OutlineOnlyView.

BaseFrame is a usable class, which is not what the name would suggest in some other languages: it is usable in the sense that a subclass can make immediate use of its constructor in a class declaration as shown in the Curl docs:
{constructor {default}
     {construct-super.BaseFrame
which the docs say can be used as a special frame destined to have only one child graphic or visual object.