This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: how to read a file in a string
- From: Per Bothner <per at bothner dot com>
- To: Damien MATTEI <damien dot mattei at unice dot fr>, kawa at sourceware dot org
- Date: Mon, 14 Dec 2015 17:59:18 -0800
- Subject: Re: how to read a file in a string
- Authentication-results: sourceware.org; auth=none
- References: <566AA076 dot 7080008 at unice dot fr> <566AA29E dot 7030905 at itdesign dot de> <566F68FA dot 1010303 at unice dot fr>
On 12/14/2015 05:12 PM, Damien MATTEI wrote:
thanks
i finally wrote one code version doing it:
(define (read-counter-value fn)
(define cf &<{&[fn]})
(define toStringCF (gnu.lists.Blob:toString (->string cf)))
That is redundant, as you're probably guessing. Looks like you've
been experimenting - but now your code can be cleaned up. :-)
The reason ->string is a no-op on cf is because the Blob is
already a string, because Kawa considers any java.lang.CharSequence
to be a string. Thus java.lang.String, gnu.lists.FString, and
gnu.lists.Blob are all strings (in the Scheme sense) but only
gnu.lists.FString is a mutable (modifiable) string.
For example you can call string-ref and string-length (but not
string-set!) on a Blob.
If you want a java.lang.String, you can just do:
(gnu.lists.Blob:toString cf)
or just:
(cf:toString)
(define toFStringCF (gnu.lists.FString toStringCF))
So you only need to convert toStringCF (or for that matter cf)
you actually want an FString - i.e. you want to modify it, which
you usually don't.
--
--Per Bothner
per@bothner.com http://per.bothner.com/