Hi, Could someone please tell me whats the gambit way to "slurp" a file? Regards, Kashyap
Afficher les réponses par date
On Mon, Mar 19, 2018 at 10:21 PM, Bradley Lucier lucier@math.purdue.edu wrote:
On 03/19/2018 10:17 PM, C K Kashyap wrote:
Hi, Could someone please tell me whats the gambit way to "slurp" a file? Regards, Kashyap
It depends on the file. Try read-all with an appropriate third argument. It's in the documentation.
Gerbil's std/misc/ports also defines read-all-as-string read-file-string read-all-as-lines read-file-lines. You can use Gerbil (yay!) or you can trivially port that code to plain Gambit.
—♯ƒ • François-René ÐVB Rideau •Reflection&Cybernethics• http://fare.tunes.org The least deviation from truth will be multiplied later. — Aristotle
For a text file you can do:
(call-with-input-file "file" (lambda (port) (read-line port #f))
Marc
On Mar 19, 2018, at 10:17 PM, C K Kashyap ckkashyap@gmail.com wrote:
Hi, Could someone please tell me whats the gambit way to "slurp" a file? Regards, Kashyap _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
And to read a file as a list of lines:
(call-with-input-file "read.scm" (lambda (port) (read-all port read-line)))
Marc
On Mar 20, 2018, at 8:38 AM, Marc Feeley feeley@iro.umontreal.ca wrote:
For a text file you can do:
(call-with-input-file "file" (lambda (port) (read-line port #f))
Marc
On Mar 19, 2018, at 10:17 PM, C K Kashyap ckkashyap@gmail.com wrote:
Hi, Could someone please tell me whats the gambit way to "slurp" a file? Regards, Kashyap _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Just what I was looking for.
Also I think I'll need (read-line p #f) occasionally!
Thanks, Kashyap
On Tue, Mar 20, 2018 at 5:41 AM, Marc Feeley feeley@iro.umontreal.ca wrote:
And to read a file as a list of lines:
(call-with-input-file "read.scm" (lambda (port) (read-all port read-line)))
Marc
On Mar 20, 2018, at 8:38 AM, Marc Feeley feeley@iro.umontreal.ca
wrote:
For a text file you can do:
(call-with-input-file "file" (lambda (port) (read-line port #f))
Marc
On Mar 19, 2018, at 10:17 PM, C K Kashyap ckkashyap@gmail.com wrote:
Hi, Could someone please tell me whats the gambit way to "slurp" a file? Regards, Kashyap _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list