[squeak-dev] Squeak File Glitch

Paul DeBruicker pdebruic at gmail.com
Fri Jul 21 06:44:31 UTC 2017


Hi - 


You've misplaced the ending ]  of the block that you send #whileTrue: to.


Try:


[(line := inFIle nextLine) notNil]
whileTrue:[
words := line substrings.
self halt.
words size >0 ifTrue:[
outFile nextPutAll: line, '<br>'; cr; lf].
].
inFIle close.
outFile close.

Also you probably want to wrap those file close  method sends in an #ensure:
block so it all looks like this:

 [
   [(line := inFIle nextLine) notNil]
    whileTrue:[
    words := line substrings.
    self halt.
    words size >0 
        ifTrue:[outFile nextPutAll: line, '<br>'; cr; lf].
    ]  ensure: 
 [
    inFIle close.
    outFile close.]

So that when there is an error (or a halt) in the file processing code the
files are closed properly.  (And of course assuming nobody pulls the power
cord).

 

Also here is the terse guide to Squeak

http://squeak.org/documentation/terse_guide/

On that page the Iteration section shows how to use the #whileTrue: idiom
and in the File section has an example like you attempted to make.



And there are some free Smalltalk books available here:


http://stephane.ducasse.free.fr/FreeBooks.html


Often when I'm writing code  (often bugs :/ ) it helps me to find the
senders and implementors of methods and read how the methods I'm trying to
use are used canonically.


Are you trying to interact with Python from your image?  I think you'd have
to use FFI if so.  I'm not sure.  Hopefully someone else can chime in.  


Hope this helps


Paul



ReliableRobots.com wrote
> I ran this program and nothing happened so I added self halts and learned
> it can't even read the input file!  Yet the File List tool reads it.  Such
> dichotomy in behavior might be covered by a preference?  I know MS
> Notepad,
> the simplest editor now allows one to store a file in ones's choice of
> formats.  Does Squeak have a simple choice for input treatments that works
> in Win10?
> 
> do
> "Read a Bible file, reformat for beter readability and html standards."
> | inPath ootPath inFIle outFile line words |
> inPath := 'C:\Users\Owner\Desktop\Website\Jesus Words\Matthew.html'.
> ootPath := 'C:\Users\Owner\Desktop\Website\Jesus Words\Matthew2.html'.
> inFIle := FileStream oldFileNamed: inPath.
> outFile := FileStream newFileNamed: ootPath.
> self halt.
> [(line := inFIle nextLine) notNil
> whileTrue:[
> words := line substrings.
> self halt.
> words size >0 ifTrue:[
> outFile nextPutAll: line, '
> <br>
> '; cr; lf].
> ]].
> inFIle close.
> outFile close.
> 
> 
> It is my observation that Squeak is the last gasp uttered by a mouse when
> it fears death.  It is not a normal sound they make unless they are being
> eaten by a Python!   I hope the Python people don't release code that
> simply doesn't work.





--
View this message in context: http://forum.world.st/Squeak-File-Glitch-tp4955993p4956002.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.


More information about the Squeak-dev mailing list