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

No comments:

Post a Comment