help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] [RFC] New Smalltalk syntax v2


From: Paul D. Fernhout
Subject: Re: [Help-smalltalk] [RFC] New Smalltalk syntax v2
Date: Fri, 16 Mar 2007 08:03:38 -0400
User-agent: Icedove 1.5.0.9 (X11/20061220)

Paolo Bonzini wrote:
> Anything I missed?  Anything I got wrong?

I did not see any discussion of the alternative I proposed, see the
details here:
http://www.nabble.com/Re%3A--RFC--Smalltalk-scripting-syntax-p9406679.html

Essentially, another alternative is, for convenience, the introduction
of Python-like triple double quotes (or even more Smalltalk-ish triple
single quotes :-) to the regular Smalltalk parser, then using these in
invoking methods on Class which do compiling of embedded language
strings. For example, using triple single quotes to delimit embedded
Smalltalk language statements:

====

Class defineWithName: #NullChessPiece extends: Object;
    category: 'Examples-Classic'.

"Note that now we can assume NullChessPiece is defined.
Also note how we can embed comments"

NullChessPiece addMethodFromSource: '''
    do: aBlock
        "Evaluate aBlock passing all the remaining solutions"
        | result |
        [ result := self next. result notNil ] whileTrue: [
            aBlock value: result
        ]
'''; category: 'enumerating'.

====

Note also that this approach opens up the system for alternative
syntaxes. Such as:

NullChessPiece addMethodFromCSource: '''
  OBJECT unsafeFastAdd(OBJECT self, OBJECT x, OBJECT y)
    {
    printf("unsafeFastAdd called\n");
    // the following code may crash the VM
    // if the arguments are not small integers
    // no testing is done for performance reasons
    // which is probably really not very wise in the long term.
    // But if you can't crash it, you're not doing the driving. :-)
    return int_to_st(st_to_int(x) + st_to_int(y));
    }
'''; safetyLevel: #mayCrashVM; category: 'optimized calculating'.

=========

This approach bypasses all (or almost all) of these other new syntax
issues. It is legible to anyone who understands Smalltalk without
needing to learn extra operators (beyond the triple quote). There is no
need to learn operators and conventions which break Smalltalk standards,
like "extend [". This approach also supports other embedded languages.
Any smart IDE tool should in theory be able to recognize this structure
and then do another level of language parsing withing the triple quoted
strings, to flag and report embedded syntax errors. This approach is
endlessly expandable in terms of adding new tags or pragmas using
regular Smalltalk methods and without further modifying the compiler,
which is in line with Smalltalk elegance. On the negative side, it may
be slightly more verbose (as in a few characters) than alternatives like
you have been discussing; however in return it is consistent and
requires less new things to learn and remember.

You could probably make a change to add triple quotes to the Smalltalk
compiler and a few other methods to Class or Method in a short time (an
hour or two? maybe longer to get the embedded error reporting right in a
WorkSpace?) and try it out, whereas all these other deeper syntax
changes proposed might take much longer (days?) to implement. As a plus,
the triple quote would then be available to all new methods for the
system, and it can be quite useful when making a regular method in the
browser, like a method that defines a paragraph of text to report to the
user.

In any case, feel free to ignore this suggestion, but I am just curious
what any substantial objections are to this meta approach.

--Paul Fernhout




reply via email to

[Prev in Thread] Current Thread [Next in Thread]