Friday, September 30, 2011

USL 3.7.2

I was writing some libraries for my language and realized I was missing out on certain features.  I have added the ability to compare method return values in if-expressions.  Very useful.  I also added the ability to define my own iterators.  Previously iterators have only been the '$' character.  Now iterator symbols may be defined explicitly.  I also fixed the way string literals are parsed.  So you can retrieve variable values inside of quotation marks during certain operations.  It's very useful.  Here are some examples.

Iterators example:
list array

for 1 < 10 (i)
        array += "Element(${i})"
endfor

loop array (item)
        say "Item: ${item}"
endfor

Comparing methods:
object o
        method m(a)
                return $0
        end
end

method m(a)
        return $0
end

if m("foobar") = o.m("foobar")
        say "These methods return the same values."
        say "You can compare return values to variable values as well."
else
        say "This will never be seen."
endif

New string literal parsing system:
method get_host_address(host)
        @host = $0
        @ping ? "ping -n 1 \{@host}"

        @ip = " ";@ip -= @ip
        @start = false

        loop @ping.size (char)
                if @start = true
                        @ip += "${char}"
                endif

                if "${char}" = "["
                        @start = true
                orif "${char}" = "]"
                        @start = false
                endif
        endfor

        @ip -= "]"

        remove @ping
        remove @start
        remove @host

        return @ip
end

@hostname = "chomp.enter host name: "
@address = get_host_address(@hostname)

say "address: \{@address}"

clear_all!

I've updated the MediaWiki and you can find it under the "Hosted Apps" tab at the sourceforge link below.

To download 3.7.2, you can visit any of the following links:

sourceforge
freecode

Sunday, September 25, 2011

USL 3.7.1

In this release I added while loops, constants, switch statements, and exponential operators. I also updated the comprehensive help function.

The while loops are the only loops that can contain nested for loops at the moment. I have to fix nesting for loops but I work around that with while loops now.  While loops expressions must begin with a numeric variable to toggle.  I haven't programmed strings for while loop expressions yet but that will come soon (probably tomorrow).

Here is an example:
@a = 1
@b = 10
while @a <= @b
        for 5 > 1
                out "${$} "
        endfor
        @a += 1
end

The switch statements require a variable to be switched against. The variable may be either string or number and the cases may be both string or number. If no cases match, a default block of code will be parsed.

Here is an example:
method example
        @c = "This is a string."

        switch @c
                case "This is a string"
                        say "Not quite..."
                        say "The next case will be evaluated."
                case 3.14159
                        say "That is pi..."
                case "This is a string."
                        say "A match was found!"
                default
                        say "No match was found..."
        end
end

example

Constant values are immutable, meaning you cannot alter them. Constant identifiers may only contain characters A through Z and underscores. Constant variables are only used to assign values to variables.

Here is an example:
MY_CONST = "This value is immutable."
@c = MY_CONST 
say @c

The exponential operator **= assigns a numeric variable to the power of a given operand.

Here is an example:
@d = 25.6
@d **= 2

say @d

I've updated the MediaWiki and you can find it under the "Hosted Apps" tab at the sourceforge link below.

To download 3.7.1, you can visit any of the following links:

sourceforge
freecode

Saturday, September 24, 2011

USL 3.7.0

I added exception-handling with the "try-catch-caught" keywords.  Believe it or not, it took me awhile to do this and I had ran into many complications until tonight when I found all I had to do was structure my code differently to utilize the benefits of try-catch-caught.  At first only an error in the try block would work correctly.  Now both erroneous and impeccable code works.  The original error message is contained in a keyword called "last_error" which may be assigned to a variable.  The variable is disposed after "caught" is called.  This is an extra garbage-handling feature I added.

The way my try statements work are as follows:

1. Try to parse code until "catch" keyword.
2. If an error occurs before "catch", stop parsing and skip to catch code.
3. If an error does not occur, skip catch code.
4. Parse until caught.

An example would be:
method test
        try
                @var = 123.456789
                @var = "This will cause a conversion error."
                say "This will never be seen as an error already occurred."
        catch
                @e = last_error
                say "An error occurred: ${@e}"
        caught

        say "try-catch-caught may be used as many times as necessary."
end

test
Produces: An error occurred: conversion_error:@a

If an error does not occur, the catch code will not be parsed.  If an error does occur, parsing stops and USL automatically starts parsing the catch code until all is caught.  The caught keyword closes the try statement.  You may use try-catch-caught as many times as is needed.  Other languages exit the method/function after try-catch statements.  So that is another unique feature of USL that distinguishes it among other languages.

I've updated the MediaWiki and you can find it under the "Hosted Apps" tab at the sourceforge link below.

To download 3.7.0, you can visit any of the following links:

sourceforge
freecode

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!