Ursa
About
Ursa is a simple programming language that I've been working on for awhile now. Its syntax is (at times) similar to Lisp, but instead of being list-based, it is "stream-based." Most in-built statements operate on types of data called streams. Streams are are variable-length arrays of data of a certain type.
The basic premise of ursa is to function as a very high-level abstraction layer between streams and "I/O devices." I/O devices are objects that represent locations that can be read and written using data streams; namely, the console, files, and network ports. Ursa greatly simplifies the implementation of programs that transfer data between these devices.
Ursa uses reverse polish notation for math and functions are simply seperated from their arguments by space characters. This makes implentation of Standard Ursa interpreters since this syntax is easier to write a parser for.
Example Code
Raw File Transfer
This Ursa code opens a port on a remote server, then outputs the specified file to the port.
if (< (size args) 4)
out "usage: " args<0> " [server] [port] [file]" endl console
stop
end if
decl file f
decl port p
f.open args<3>
p.connect args<1> (int args<2>)
out (f.readall) p
f.close
p.close
Single-User Echo Server
# declare a serverport and a port to attach new connections to
declare serverport sp
declare port p
# declare a string to contain lines of input
declare string input
# attach the serverport to port 20000
sp.attach 20000
# loop indefinitely, getting connections then echoing the data they send
while true
set p (sp.getconn)
out "%msg: connection from " (p.addr) endl console
out "echo server " _version endl endl p
while true
set input (in string p)
out input endl p
if (and (= input "") (not (p.isopen 1000)))
break
end if
end while
p.close
out "%msg: connection closed" endl console
end while
See Also
Tasks
- 100 doors
- A+B
- Append a record to the end of a text file
- Arbitrary-precision integers (included)
- Arithmetic/Integer
- Array concatenation
- Array length
- Averages/Arithmetic mean
- Boolean values
- CSV data manipulation
- Caesar cipher
- Call an object method
- Case-sensitivity of identifiers
- Character codes
- Check that file exists
- Command-line arguments
- Comments
- Copy a string
- Create a file
- Create a two-dimensional array at runtime
- Create an HTML table
- Date format
- Delete a file
- Detect division by zero
- Determine if a string is numeric
- Empty program
- Empty string
- Environment variables
- Even or odd
- Exceptions
- Execute HQ9+
- Execute a system command
- Exponentiation operator
- Factorial
- Factors of an integer
- Fibonacci sequence
- Find limit of recursion
- FizzBuzz
- Function definition
- General FizzBuzz
- Generate lower case ASCII alphabet
- Get system command output
- Greatest common divisor
- Greatest element of a list
- Guess the number
- Guess the number/With feedback
- Hello world!
- Hello world/Newline omission
- Hello world/Standard error
- Hello world/Text
- Higher-order functions
- Hostname
- Include a file
- Increment a numerical string
- Infinity
- Input loop
- Input/Output for Lines of Text
- Input/Output for Pairs of Numbers
- Integer comparison
- Integer sequence
- Interactive programming
- Leap year
- Least common multiple
- Linux CPU utilization
- Literals/Floating point
- Literals/Integer
- Loop over multiple arrays simultaneously
- Loops/Break
- Loops/Continue
- Loops/Downward for
- Loops/For
- Loops/For with a specified step
- Loops/Infinite
- Loops/N plus one half
- Loops/While
- Menu
- Morse code
- Musical scale
- Null object
- Old lady swallowed a fly
- Pick random element
- Program termination
- Random number generator (included)
- Read a file line by line
- Read a specific line from a file
- Repeat
- Return multiple values
- Runtime evaluation
- Sleep
- Sockets
- Sort an integer array
- Special variables
- String append
- String case
- String concatenation
- String prepend
- Sum and product of an array
- Sum digits of an integer
- System time
- Temperature conversion
- Tokenize a string
- Unix/ls
- Variables
- Zero to the zero power