This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Shell-style programming in Kawa
- From: Jamison Hope <jrh at theptrgroup dot com>
- To: "kawa at sourceware dot org list" <kawa at sourceware dot org>
- Date: Wed, 29 Jan 2014 14:11:35 -0500
- Subject: Re: Shell-style programming in Kawa
- Authentication-results: sourceware.org; auth=none
- References: <52C4B518 dot 5080000 at bothner dot com> <A72FB562-9459-4C69-B346-A6C94DBD22C4 at theptrgroup dot com> <52E3772D dot 50804 at bothner dot com> <4A37A2F8-76B0-421D-AFCB-62AA1EE78468 at theptrgroup dot com> <9CF037C1-15CA-48B9-80E5-83EDF306017F at theptrgroup dot com> <52E92422 dot 60300 at bothner dot com>
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