wc example

80 views
Skip to first unread message

edbond

unread,
Nov 23, 2010, 5:03:51 AM11/23/10
to szl-users
Wc example from language description page doesn't works:
http://szl.googlecode.com/svn/doc/sawzall-language.html

wc.szl:
nlines: table sum of int; # Lines
emit nlines <- 1;

> szl wc.szl scrub.sh
emit nlines <- 1;
emit nlines <- 1;
emit nlines <- 1;
emit nlines <- 1;

What am I doing wrong?
I tried declare nlines as static - doesn't helps?

Where can I find usage example of szl command?
I assumed it works with stdin -> stdout but it doesn't.

Thanks,
Eduard

Tim Wintle

unread,
Nov 23, 2010, 6:25:43 AM11/23/10
to szl-...@googlegroups.com
On Tue, 2010-11-23 at 02:03 -0800, edbond wrote:
> Where can I find usage example of szl command?
> I assumed it works with stdin -> stdout but it doesn't.

I gather you need to explicitly emit to stdout in your program.

szl --help gives you some information (but not much)

Try

szl wc.szl inputfile

e.g.

$ cat wc.szl

nlines: table sum of int; # Lines
emit nlines <- 1;

$ cat input
hello
world
$ szl wc.szl input


emit nlines <- 1;
emit nlines <- 1;


Tim Wintle

Eduard Bondarenko

unread,
Nov 23, 2010, 6:36:56 AM11/23/10
to szl-...@googlegroups.com
Thanks Tim,

That's exactly what I wrote in my first email.

szl --help tells us:

szl
-bootstrapsum_fastpath (Enable fast path sampling.) type: bool
default: true
-bootstrapsum_seed (Seed used when SetRandomSeed is not called.)
type: string default: ""

no mention of program or input, I expected:
szl <program.szl> input1 [input2...]
or something

Regarding wc expected output for your input file ('hello', 'world') would be:
2

not copying my source to stdout :)
emit nlines <- 1;

Maybe I don't understand some core conception or using sawzall.

From documentation http://szl.googlecode.com/svn/doc/sawzall-language.html :
Sum
A sum variable accumulates the arithmetic sum of each of its
components, elementwise.

Best regards,
Eduard

Tim Wintle

unread,
Nov 23, 2010, 7:09:39 AM11/23/10
to szl-...@googlegroups.com
On Tue, 2010-11-23 at 13:36 +0200, Eduard Bondarenko wrote:
> Thanks Tim,
>
> That's exactly what I wrote in my first email.

Sorry for giving a completely useless explanation there ;)

szl isn't simply echoing your source, it's printing each emitted item as
it's mapped over.

To show the output of the reduced table instead, add the --table_output
flag

e.g.
$szl wc.szl --table_output=* input
nlines[] = 2

Tim

Eduard Bondarenko

unread,
Nov 23, 2010, 7:31:47 AM11/23/10
to szl-...@googlegroups.com
Thanks a lot, Tim.

This is exactly what I need.
It would be great to have Usage page on wiki.

Best regards,
Eduard

Xiaoyu Ma

unread,
Jul 16, 2013, 10:04:47 PM7/16/13
to szl-...@googlegroups.com, edb...@gmail.com
Can't agree more...;)
Had same problem running example. 
Reply all
Reply to author
Forward
0 new messages