This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to read a file in a string




Le 15/12/2015 02:59, Per Bothner a Ãcrit :


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. :-)

yes i do it, i no more need FString as it was for a previous version needing mutable string

Damien

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]