Wednesday, October 12, 2011

USL 3.7.5

I have changed the way variables are created so the binary size has been decreased but not too dramatically (~.04MB). I have also added various features to list objects to make them more usable. I also fixed the comments. Previously, comments on the same line would nullify the statement(s) before them. This version allows comments on the same line. The list now has indexes. These indexes can be used to set variable values and vice versa. Lists may also be populated in a new way. I will demonstrate below.

New list demonstration:

##
       animal_list.us

       to execute: usl animal_list.us

       or just type as you see it in the USL shell
##

@animal = "tiger"
list animals

animals = ("elephant",@animal,"chameleon") 
# animals contains: elephant, tiger, chameleon

@animal = animals[0]    # @animal contains: elephant

try
       animals[0] = "shark"
       animals[1] = "whale"
       animals[2] = "dolphin"
       animals[3] = "This will throw an index out of bounds exception."
catch
       say "The index value exceeded the list size."
caught

see animals     # animals contains: shark, whale, dolphin

# eof

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

To download 3.7.5, you can visit any of the following links:
sourceforge
freecode

Sunday, October 2, 2011

USL 3.7.4

I have received a few suggestions in my quest. So in reply, I have audited my code to produce the desired suggestions. ;]

The white-space convention of the previous versions was far too strict, so I have changed the convention dramatically.

Example:
object    o
       method         m
              say      "Hello, World!"
       end
end

o.m
say "There is white-space after the last quotation mark!"        

The above code would not be parsed correctly in the previous versions. The new release is more lenient with white-space.

The first suggestion I received was another for-loop. A for-loop that would return an iterable list or a range of numbers. So I developed both.

New for-loops:
# iterable list loops

@file = "example.txt"
list lines
for line in @file.read
       lines += "${line}"
endfor

@line_num = 1

for line in lines
       say "Line(\{@line_num}): ${line}"
       @line_num += 1
endfor

# range loops

for i in (1..25)
       say "Iteration: ${i}"
endfor

for i in (25..-25)
       if "${i}" < 0
              say "${i} is negative."
       orif "${i}" = 0
              say "${i} is zero."
       else
              say "${i} is positive."
       endif
endfor
The second suggestion I received was to add an "fwrite" command. The "fwrite" command would cut the use of creating a file with the "fpush" command and appending text with the "append" or "appendl" commands.

My "fwrite" creates a file if it does not already exist and then appends text to it.

The "fwrite" command returns: "1" if the file was created, "0" if the file already existed, or "-1" if an error occurred. The error is caused by using a numeric variable or value instead of a string variable or string literal as the file parameter of the "fwrite" command.

Catching the return value of "fwrite":
method fwrite(file,contents)
       fwrite $0 $1
end

@contents = "This text will be appended to a file with the fwrite command."

@ret_val = fwrite("file.txt",@contents)

switch @ret_val
       case 0
              say "Content has been appended."
       case 1
              say "File was created."
              say "Content has been appended."
       case -1
              error "An error occurred."
       default
              say "Another value was returned instead."
              say "This will happen if the fwrite operation is not at the end of the method."
end
The third suggestion I received was sort of a self-conceived suggestion to change the code-separator symbol from a pipe-symbol to the more traditional semi-colon. This at first caused problems with methods and objects, but I fixed it and now the language runs smooth with the "end" keyword to end method, object, template, and thread definitions.

Here is an example demonstrating most of what I have just mentioned:
object obj
       public
              method __m(s)
                     @__s = $0

                     switch @__s
                            case "hello"
                                   self.sayHello
                            case "bye"
                                   self.sayGoodbye
                            case "while"
                                   @commands = "say 'in a little while'"
                                   self.++while(@commands,0,10)
                                   remove @commands
                            default
                                   say "Invalid Case: \{@__s}"
                     end
              end

              method sayHello
                     say "Hello, World!"
              end

              method sayGoodbye
                     say "Goodbye, World!"
              end

              method ++while(commands,start,stop)
                     @cmd = $0;@start = $1;@stop = $2

                     while @start < @stop
                            ! @cmd
                            @start += 1
                     end

                     remove @cmd;remove @start;remove @stop
              end
end
The final suggestion I received was to replace the list populating function of variables with a "split" function.

Previously, a list could be populated as so:
list array
@s = "abcdefghijklmnopqrstuvwxyz0123456789"
array = @s.size
# array contains 36 items
This causes much confusion to some people, so I will replace "size" with "get_chars" in the future. I have added the "split" function for populating lists in place of the "size" function.

String split example:
@s = "This is a string with multiple instances of the letter \'i\'."
list eye_split

eye_split = @s.split("i")

##
       eye_split now contains: 
              Th
              s
              s a str
              ng w
              th mult
              ple
              nstances of the letter '
              '.
##

eye_split = @s.split()

##
       eye_split now contains: 
              This
              is
              a
              string
              with
              multiple
              instances
              of
              the
              letter
              'i'.
##

eye_split.reverse

##
       eye_split now contains: 
              'i'.
              letter
              the
              of
              instances
              multiple
              with
              string
              a
              is
              This
##

# revert to previous content
eye_split.revert

eye_split.sort

##
       eye_split now contains: 
              'i'.
              This
              a
              instances
              is
              letter
              multiple
              of
              string
              the
              with
##

# empty all content
eye_split.clear
I've updated the MediaWiki and you can find it under the "Hosted Apps" tab at the sourceforge link below.

To download 3.7.4, you can visit any of the following links:
sourceforge
freecode

Saturday, October 1, 2011

USL 3.7.3

I realized that separate mathematical operations weren't very attractive, so I have added another way to assign numeric variables.  I also added a modulo assignment operator.  I can't believe I forgot that before.

Anyway...here are a few examples. :]

New ways to assign numeric values to the untyped variables of USL:
method getYear
       @year = this_year
       return @year
end

method julian_leap?
       @julian_leap? = (getYear%4)
       @ret_val = false

       if @julian_leap? = 0
              @ret_val = true
       endif

       remove @julian_leap?
       return @ret_val
end

@is_leap? = julian_leap?

say "Is this year a Julian leap year: \{@is_leap?}"

@pi = 3.14
@r = 256
@c_sphere = (2*@pi*@r)
@half_of_c = "(@c_sphere / 2)"

say "Circumference of a sphere with a radius of \{@r}: \{@c_sphere}\]Half of the circumference: \{@half_of_c}"

@r %= 4

if @r = 0
       say "The radius is divisible by four."
else
       say "This will never be seen."
endif

clear_all!

say "All objects have been removed from memory.\]Leaving in 5 seconds..."
delay 5
exit


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

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

sourceforge
freecode

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!