Sunday, September 18, 2011

USL 3.6.8

Aside from completely upgrading my code, I have added many new features to USL.
I have added these mathematical functions: abs, floor, ceil, cos, cosh, acos, tan, tanh, atan, sin, sinh, asin, log, sqrt, exp.

*note: I am occasionally using the ';' code separator so I can write code in single lines.

Example:
@a = 256
@b = @a.tan
say @b
Produces: 25.1116

I have also added some string control: to_lower, to_upper, is_lower?, is_upper?.

Example:
# swap case
@a = "This is a string."
@b = " ";@b -= " "

loop @a.size
       @c = "${$}"

       if @c = is_upper?
              @d = @c.to_lower
              @b += @d
       orif @c = is_lower?
              @d = @c.to_upper
              @b += @d
       else
              @b += @c
       endif
endfor

say @b
# end of example
Produces:  tHIS IS A STRING.

A new and interesting feature is the ability to load stubs of definitions. USL has always had a "load" command to load definitions from a script. The new version of USL allows separation of library definitions similar to namespaces and packages in C++ and Java, respectively.

Example:
##
lib_example.us
-------------------------
stubs in library script
##
[stub_a]
method say_hello
        say "Hello, World!"
end
[/stub_a]

[stub_b]
method say_hello
        say "Hello, Internet!"
end
[/stub_b]
# end of lib_example.us

##
lib_load.us
##
load lib_example.us
load stub_a

say_hello
remove say_hello
load stub_b
say_hello
# end of lib_load.us
Produces:
        Hello, World!
        Hello, Internet!

No comments:

Post a Comment