Saturday, October 29, 2011

USh

I have created a shell with USL as the native scripting language. I call it "Unorthodox Shell" or "USh" for short. You would pronounce that: uh-SH; oo-SH

:P

I also fixed the ~ error for Linux operating systems. Previously, the interpreter didn't parse the ~ character correctly. I actually found that bug accidentally. So there's a fix for the Linux users. The Windows users have no issue with the the ~ character.

I'm still working on anonymous functions.

For the people wanting generic methods, I have uploaded a picture for you.


Saturday, October 22, 2011

USL 3.7.9

This release touches up on interpolation. You may now retrieve values from list indices, list ranges, variable indices, variable ranges, and methods to be used in quoted strings. Which means you can print values easier and be more specific with what values are assigned. This release also fixes the chomp and shomp keywords which would originally not format the escape sequences of output strings when retrieving input. It also changes the escape characters from "\]" and "\[" to "\n" and "\t", respectively. Now you may retrieve input in a more formatted manner. This release also allows variables to be used as parameters to the "random" method.

Here are some examples:
@string = "abcdef"

object obj
       method foo(bar)
              return $0
       end

       method bar
              return "Hello, World!"
       end
end

method foo(bar)
       return $0
end

method bar
       return "Hello, World!"
end

list array

array = ("abc","def","ghi")

for i in (0..2)
       say "\{array[${i}]}"
endfor

for i in (2..0)
       say "\{array[${i}]}"
endfor

say "\{@string[5..0]}"
say "\{@string[0..5]}"
say "\{obj.foo(@string)}"
say "\{obj.bar}"
say "\{foo(@string)}"
say "\{bar}"
say "\{array[0..2]}"
say "\{array[2..0]}"

method get_randoms(a,b,c,d)
       @a = $0;@b = $1
       @c = $2;@d = $3

       list rands

       for i in (@a..@b)
              @r = random(@c..@d)

              rands += @r
       endfor

       return rands
end

list randoms

randoms = get_randoms(1,10,a,z)

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

Friday, October 21, 2011

USL 3.7.8

I have added a lot of different features in 3.7.8 thanks to suggestions. I have added list slicing from Python, variable indices, variable ranges, list indices, list ranges, sub-strings, and so forth.
I have also changed the way methods execute their code. Methods may now return a list object instead of just variables, strings, and numeric values. Any variables or lists created within the method are implicitly removed after leaving the method.

Here is an example of list slicing:
list list_a
list list_b

list_a = ("abc","bcd","cde","def")

list_b = list_a[0..3]       # list_b contains all elements of list_a
list_b = list_a[3..0]       # list_b contains all elements of list_a, reversed
Here is an example of iterating a sub-string:
@string "Hello, World!"

# loop a substring
for c in @string[0..12]
       say ${c}
endfor

# reversed
for c in @string[12..0]
       say ${c}
endfor
Here is an example of retrieving a sub-string:
@string = "Hello, World!"

@sub_str = @string[0..12]
@reversed = @string[12..0]
Here is an example of the new methods:
method get_even_numbers
       list even_numbers

       for x in (0..15)
              if (${x}%2) == 0
                     even_numbers += ${x}
              endif
       endfor

       return even_numbers
end

list numbers
numbers = get_even_numbers

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

Tuesday, October 18, 2011

USL 3.7.7

This release changes the old random function, fixes the return bug, and adds empty_string & empty_number as USL-specific environment variables. The old random function was very awkward but the new random function conforms to the recently introduced ranges of USL. I have also written a usl-doc for all of those people saying things like: "Is there ANY documentation on this AT ALL?!?!"

I'm 21 years old and am writing my own computer language. I took the time of day to write you some documentation.

P.S. THANK YOU to the people from 43 different countries that have downloaded my language. It is so much better than a paycheck or a salary. I wish I could personally thank each of you for considering the language. I hope to make it as useful as possible with what time I have and hope you enjoy using it. Whether you are writing attack scripts or simple every day task scripts. Just enjoy the language. I made it for you.

If you have any questions/comments/suggestions, send me an e-mail at scstauf@gmail.com. I don't mind if you write in your own language. I will use Google Translate.

Back to the programming.

Here is an example of the new random function:
method gen_rand
       @random = env.empty_string

       for i in (1..256)
              @c = random(a..z)

              @random += @c
       endfor

       remove @c
       return @random
end

@rand_str = gen_rand

say "Random String: \{@rand_str}"
Here is an object-oriented guessing game:
##
guessing_game.us

run with: usl -n guessing_game.us
##

object AI
       public
              method init
                     @&__AI_num = env.empty_number
              end

              method set(num)
                     self.init
                     @&__AI_num = $0
              end

              method genRand
                     @random = random(1..5)

                     return @random
              end

              method makeChoice
                     self.set(self.genRand)
              end

              method getChoice
                     return @&__AI_num
              end
end

method getChoice
       @c = "chomp.Your choice: "

       return @c
end

method reset
       delay 2

       ? @clearScreen
end

method setup
       @choice = env.empty_number
       @os = env.os

       if @os = "UNIXMacorLinux"
              @clearScreen = "clear"
       else
              @clearScreen = "cls"
       endif

       ai = AI

       game
end

method game
       for infinity
              say "Pick a number between 1 and 5...0 to exit\]"
              say "The computer is making its choice...\]"
              ai.makeChoice

              try
                     @choice = getChoice
              catch
                     say "\]Leaving!"
                     leave!
              caught

              switch @choice
                     case 0
                            say "\]Leaving!"
                            leave!
                     default
                            @aiChoice = ai.getChoice

                            if @choice = @aiChoice
                                   say "\]You guessed correctly!"

                                   reset
                            else
                                   say "\]You guessed incorrectly!"
                                   say "\]Your choice:\[\{@choice}"
                                   say "AI choice:\[\{@aiChoice}\]"

                                   reset
                            endif
              end
       endfor
end

say "A Simple Guessing Game\]"
              
setup

# 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.7, you can visit any of the following links:
sourceforge
freecode

Friday, October 14, 2011

USL 3.7.6

Several adjustments and additions in 3.7.6. Previously I added the ability to assign numeric values with encapsulated expressions. The limitation to numeric values was unattractive and so I allow assignment with string variables as well. The expressions may be used in conditional statements as well. Numeric assignments can contain these operators: +, -, *, /, ^, and %. String assignments can contain these operators: +, -, and *. I also added the "unless" statement to compliment the conditionals of USL. The unless-statement is exactly the same as an if-statement except for the fact that it only executes code if a statement is false. Drawing more inspiration from Ruby. I also moved all of the old time functions into the usl-specific environment variables list. You can still access the old time methods, but as environment variables. Remember, you can pull values from any environment variable as long as it exists. I also revamped a few older commands like "return" and "remove." The old remove command could only remove single objects from memory. With the aid of parentheses this command can remove multiple objects. The old return command could only return specific values (numeric, string, variable values, other method return values). With the aid of parentheses, the return command can return a more modified value instead of setting up the return value before returning. :P

New remove example:

##
       file: email.us
       usl: 3.7.6

       Some people split their e-mail address in order to avoid 
       web crawlers from finding them.

       This script shows how to assemble email addresses
       from these split words with unorthodox scripting language.
##

method getEmail(s)
        @s = $0

        list words
        words = @s.split()

        for w in words
                @w = "${w}"

                 switch @w
                       case "dot"
                               @email += "."
                       case "dash"
                               @email += "-"
                       case "at"
                               @email += "@"
                       default
                               @email += @w
                end
        endfor

        remove (@s,@w,words)

        return @email
end

# @original = "chomp.enter split email: "

@original = "unorthodox dash scripting dash language at iconoclazt dot com"
@built = getEmail(@original)

say "\]Original:\[\{@original}\]E-mail address: \{@built}"

Random examples:
method foo
        @perishing = "This variable will be removed from memory."
        @perishing = "Hello, World!"

        return (@perishing*5)
end

@string = (@string+@string)
# is the same as
@string += @string

@num = 10

if @num < (@num+@num)
        say "Ten is less than twenty."
endif

unless (@num^2) < 20
        say "Unless the expression is true, say this message."
endif

I will update this blog post when I get around to it. Pardon the simplicity of these examples. I need SLEEP. I've updated the MediaWiki and you can find it under the "Hosted Apps" tab at the sourceforge link below.

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

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