Here's a YS program to format a YS program and output as a Rosetta Code entry for https://rosettacode.org/wiki/Category:YAMLScript#mw-pages
#!/usr/bin/env ys-0
# Create a Rosetta Code entry for a YS program:
defn main(program *args):
say: |-
=={{header|YAMLScript}}==
<syntaxhighlight lang="yaml">
$chomp(program:read)
</syntaxhighlight>
when ENV.NOUT.!:
command =: "ys $program$fmt-args(args)"
output =: bash(command).out:chomp
say: |-
{{out}}
<pre>
$ $command
$output
</pre>
defn fmt-args(args):
args =: !:joins
reduce _ [] args:
fn(args arg):
conj args:
if arg =~ /^[-+,.:\w]+$/:
arg pr-str(arg)
when args.?: " $args"$ ./bin/rcd-ys-entry integer-overflow.ys
=={{header|YAMLScript}}==
<syntaxhighlight lang="yaml">
!YS-v0
tests =: |
-9223372036854775807.-- * -1
5000000000000000000 + 5000000000000000000
-9223372036854775807 - 9223372036854775807
3037000500 * 3037000500
each test tests:lines:
say: test
try:
eval: test
catch e:
say: "$e\n"
</syntaxhighlight>
{{out}}
<pre>
$ ys integer-overflow.ys
-9223372036854775807.-- * -1
java.lang.ArithmeticException: long overflow
5000000000000000000 + 5000000000000000000
java.lang.ArithmeticException: long overflow
-9223372036854775807 - 9223372036854775807
java.lang.ArithmeticException: long overflow
3037000500 * 3037000500
java.lang.ArithmeticException: long overflow
</pre>