вторник, 29 октября 2019 г., 2:52:48 UTC+3 пользователь NewLogoUser написал:
I'm working my way through Computer Science Logo Style using UCB Logo 6.0 on Win10
One of the examples is the extract procedure, on this page: https://people.eecs.berkeley.edu/~bh/v2ch1/files.html
My problem is that it will only read one line from the file. I made the sample file using Notepad.exe with 2 entries separated by a hard return (the ENTER) key.
Here's the procedure and the sample case:
to extract :word :file
openread :file
setread :file
extract1 :word
setread []
close :file
end
to extract1 :word
local "line
if eofp [stop]
make "line readlist
if memberp :word :line [print :line]
extract1 :word
end
? extract "brian "phonelist
Brian Harvey 555-2368
Brian Silverman 555-5274
My sample file had the 2 Brian lines but only the first one is retrieved. Any ideas what's going on? - Thanks
Hi NewLogoUser
I've tested the code with 3 differently created files under Windows:
* a file created using Notepad.exe, as you did. The file name is phonelist_notepad
* a file created using built-in UCBLogo editor. The file name is phonelist_ledit
You can create one with EDITFILE command.
e.g. editfile "c://ucblogo//phonelist_ledit
* a file created using Emacs for Windows. The file name is phonelist_emacs
Here is my UCBLogo session with the code and the files:
Welcome to Berkeley Logo version 6.0(206)
? edit
? setprefix "c://local//ucblogo//
? extract "brian "phonelist_ledit
Brian Harvey 555-2368
Brian Silverman 555-5274
? extract "brian "phonelist_notepad
Brian Havrey 555-2368
? extract "brian "phonelist_emacs
Brian Harvey 555-2368
Brian Silverman 555-5274
As you can see I've got proper extract both from phonelist_ledit and phonelist_emacs files.
But extract from phonelist_notepad consists the only one line, the same as in your listing.
A possible reason for the problem is the way how Notepad.exe handles CR and EOF flags.
So to avoid such type of problems, I recommend using UCBLogo built-in editor or Emacs for Windows instead of Notepad.exe.
Hope this will help.
And best of luck with CSLS. It is definitely worth the effort!
Regards
Alexey
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)