2018-03-08 19:44 GMT+01:00 Eliot Miranda <eliot.miranda@gmail.com>:
Hi Sven,
On Mar 8, 2018, at 9:55 AM, Sven Van Caekenberghe <sven@stfx.eu> wrote:
On 8 Mar 2018, at 17:58, Eliot Miranda <eliot.miranda@gmail.com> wrote:
Hi Stef,
following on from Sean, (+1000 for using ordinary quotes)
âstringâ collection of characters => âstringâ sequence of characters
$a, Character space Two ways to create characters => $a, Character space two ways to denote characters (or two ways to write characters; all other explanations in this list are not capitalized; this shouldn't be either)
exp1. exp2 expression separator => expr1. expr2 statement separator
; message cascade => expr doThis ; doThat semicolon - message cascade (c.f. exp1. exp2 expression separator)
^ expr caret - returns a result from a method => ^ expr caret - return a result from a method (or, ParcPlace preference, answer a result from a method, since we're sending messages here)
...
A unary message is one with no arguments. => A unary message has no arguments. (c.f. A binary message takes only one argument ...)
...
Set new add: 4; add: 4 ; yourself ~> aSet => Set new add: 4; add: 4 ; yourself ~> aSet(4)
Dictionary new at: #a put: 'Alpha' ; yourself a Dictionary => Dictionary new at: #a put: 'Alpha' ; yourself a Dictionary(#a->'Alpha' )
and then in the Files and Stream section I would give two more examples of exactly the same sequence that use the convenience APIs. This is the existing text:
work := FileSystem disk workingDirectory.
stream := (work / âfoo.txtâ) writeStream.
stream nextPutAll: âHello Worldâ.
stream close.
stream := (work / âfoo.txtâ) readStream.
stream contents. ~> 'Hello World'
stream close.
I would make it read
work := FileSystem disk workingDirectory.
stream := (work / âfoo.txtâ) writeStream.
stream nextPutAll: âHello Worldâ.
stream close.
stream := (work / âfoo.txtâ) readStream.
stream contents. ~> 'Hello World'
stream close.
or, more simply
work := FileSystem disk workingDirectory.
(work / âfoo.txtâ) writeStreamDo: [ :fileStream | fileStream nextPutAll: âHello Worldâ ].
(work / âfoo.txtâ) readStreamDo: [ :fileStream | fileStream contents] ~> 'Hello World'
or, more simply still
work := FileSystem disk workingDirectory.
(work / âfoo.txtâ) writeStreamDo: [ :fileStream | fileStream nextPutAll: âHello Worldâ ].
(work / âfoo.txtâ) contents ~> 'Hello World'
file := FileSystem disk workingDirectory / 'foo' , 'txt'. file ensureDelete. file writeStreamDo: [ :fileStream | fileStream nextPutAll: 'Hello World' ]. file contents. file delete.
(to make it re-entrant and a bit more concise)
that suggests
file := FileSystem disk workingDirectory / 'foo' , 'txt'. file newWriteStreamDo: [ :fileStream | fileStream nextPutAll: 'Hello World' ]. file contents. file delete.
where newWriteStreamDo: includes the file ensureDelete, or better still a truncation, which saves the effort of deletion but (I *think*) has the same effect.
Hi Eliot, not exactly the same effect wrt file access rights.
+1e10 for plain single quotes, VERY important.
or if you can't make it fit, just give the last version
Finally, this seems to have fallen off the end:
A simple, uniform and powerful model
Pharo has a simple dynamically-typed object model:
Perhaps shrink the picture of the browser. You can save three lines by writing
OrderedCollection new
add: 1;
add: 2;
add: 3.
as OrderedCollection new add: 1; add: 2; add: 3.
And another by writing 2=2 ifTrue: [ Error signal: âHelpâ ]. on one line.
HTH
On Fri, Apr 8, 2016 at 12:56 PM, stepharo <stepharo@free.fr> wrote:
new cheatsheet for Pharo syntax.
Any feedback is welcome
Stef
--
_,,,^..^,,,_
best, Eliot