No colons syntax? (was Re: Syntaxes & Block Closures)
Paul Fernhout
pdfernhout at kurtz-fernhout.com
Thu Sep 14 14:43:38 UTC 2000
Jesse-
I haven't tried 2.9 yet, so thanks for the example.
Of course, the colon syntax (and unary, binary, keyword precedence) is
one of the things I like most about Smalltalk. Admitedly I don't like
typing any unneeded punctuation though.
atAll: indexArray
"Answer a new collection like the receiver which contains all
elements
of the receiver at the indices of indexArray."
|newCollection|
newCollection := self species new: indexArray size.
1
to: indexArray size
do: [:index | newCollection
at: index
put: (self
at: (indexArray at: index))].
^newCollection
versus for comparison:
atAll (indexArray)
"Answer a new collection like the receiver which contains all
elements
of the receiver at the indices of indexArray."
Use newCollection.
Set newCollection to self species new (indexArray size).
Repeat (1)
to (indexArray size)
do [With index. newCollection
at (index)
put ((self
at ((indexArray at (index)))))].
Answer newCollection
It is going in a good direction, but I think the parenetheses nesting
creates a set of other problems -- as well as more total punctuation
(ignoring the other reduction English words for assignment etc.).
Actually, my major reservation about the indnetaional Scheme syntax I
worked out is that I preferred Smalltlak keyword syntax and leading
receiver object order -- versuses "(send object message arg1 arg2 ...)".
For comparison, here is indentational Scheme syntax augmented with some
imaginary OO functions supporting something like Smalltalk objects
represented as method dispatch functions:
define (atAll indexArray)
;Answer a new collection like the receiver which contains all elements
; of the receiver at the indices of indexArray.
let
.
newCollection
(self species) new: (indexArray size)
1 to:each:do: (indexArray size) index
newCollection at:put: index
self at:
indexArray at: index
newCollection
Or alternatively with a heavier parse modification needed:
define (atAll indexArray)
;Answer a new collection like the receiver which contains all elements
; of the receiver at the indices of indexArray.
let
.
newCollection
(self species) new: indexArray size
1 to: indexArray size each: index do:
newCollection at: index put:
self at:
indexArray at: index
newCollection
Or for lazy typists (as "-" isn't shifted like ":" on most keyboards):
define (atAll indexArray)
;Answer a new collection like the receiver which contains all elements
; of the receiver at the indices of indexArray.
let
.
newCollection
(self species) new- indexArray size
1 to- indexArray size each- index do-
newCollection at- index put-
self at-
indexArray at- index
newCollection
I think there might be a few more iterations in this indentational
syntax trying to integrate in some of the english language notions
replacing standard Scheme constructs.
-Paul Fernhout
Kurtz-Fernhout Software
=========================================================
Developers of custom software and educational simulations
Creators of the Garden with Insight(TM) garden simulator
http://www.kurtz-fernhout.com
Jesse Welton wrote:
>
> Paul Fernhout wrote:
> >
> > I'm not sure what the "Dan Ingalls No Colon Syntax" is, but I am hoping
> > you use the "_" in place of the colon when making substitutions (unless
> > there is something better).
>
> Try turning on the printAlternateSyntax preference in 2.9alpha. (I
> thought this was supposed to work in 2.8, but the preference isn't
> used anywhere.) The basic idea is mostly Smalltalk-like, with the
> colons replaced by parentheses. There are several other changes, as
> well. SequenceableCollection>>atAll: provides a good overview:
>
> atAll (indexArray)
> "Answer a new collection like the receiver which contains all elements
> of the receiver at the indices of indexArray."
> Use newCollection.
> Set newCollection to self species new (indexArray size).
> Repeat (1)
> to (indexArray size)
> do [With index. newCollection
> at (index)
> put ((self
> at ((indexArray at (index)))))].
> Answer newCollection
>
> -Jesse
More information about the Squeak-dev
mailing list
|