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: Shell-style programming in Kawa


On Jan 29, 2014, at 10:54 AM, Per Bothner <per@bothner.com> wrote:

> On 01/27/2014 05:06 PM, Jamison Hope wrote:
>> In the scripts I've written so far, these two definitions have proven
>> quite handy:
>> 
>> (define-simple-constructor prop java.lang.System:getProperty)
>> (define-simple-constructor env  java.lang.System:getenv)
> 
> That does seem worth considering.
> 
> You may also want to try out the (so far undocumented)
> &`{FNAME} which is equivalue to &<{FNAME} which is
> equivalent to (path-data "FNAME") which is equivalent
> to &`{cat "FNAME"}.

Are you sure about that first one?  I get an IOException if I
try &`{FNAME}, because it tries to execute the file.  &<{FNAME}
and (path-data "FNAME") both work, though.

> There is also (path-bytes PATH) which returns the contents
> pf PATH as a bytevector.  path-bytes is also settable:
> (set! (path-bytes PATH) BYTEVECTOR)
> 
> Thee re undocumented because they're incomplete.

Ooh I like that.

#|kawa:19|# &`{ls /tmp/newfile.txt}
ls: /tmp/newfile.txt: No such file or directory
#|kawa:20|# (set! (path-bytes "/tmp/newfile.txt") (string->utf8 "this is a test\n"))
#|kawa:21|# &`{ls /tmp/newfile.txt}
/tmp/newfile.txt
#|kawa:22|# &<{/tmp/newfile.txt}
this is a test

We can go one further and do

(set! (setter path-data)
  (lambda ((p ::path) (s ::string))
    ((setter path-bytes) p (gnu.lists.U8Vector (->String s):bytes))))

and then
(set! &<{/tmp/newfile.txt} "test")

but it looks weird to have a '<' involved in redirecting *to*
a file. :-)

--
Jamison Hope
The PTR Group
www.theptrgroup.com




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