Upsilon

From Esolang
Jump to: navigation, search
This language is still undergoing design. It may, and will, probably change in the future.

Upsilon is an upvar-based esoteric programming language by User:Rdococ which is designed around the use of upvars. Its basic syntax was inspired by Lambda, but it has managed to come up with its own gimmick.

Overview

Upsilon has constructs named upvars, which are parameters that pass values out of a subroutine, rather than into it.

assign x, 3. [x is the upvar]
print x. [3]

Here, a subroutine named assign utilizes an upvar, and assigns it the value 3. Then, the upvar is printed. You also see comments in the square brackets, and that periods end instructions.

The syntax for creating your own subroutines is straightforward:

square upvar number a, number b: [subroutine parameters have types]
	multiply c, b, b. [c := b * b]
	assign a, c. [a := c]
back.

Here, you also see that back, as opposed to return, is used to return to the caller. More importantly, you see the nature of Upsilon's mathematical operators - that they are subroutines just like your own, and use upvars to return a result. Also note how the b in the assignment replaces the b in the subroutine, and how subroutine parameters can be declared as upvars, and declared as specific types.

One more note is that even if you call the subroutine like this:

square b, 5.

then it will work as usual - there is an important difference in scope between b in the subroutine, and b outside of it, and they can't influence eachother directly, just through having the same name.

Here is another example:

factorial upvar number result, number a:
	equal isZero, a, 0.
	subtract x, a, 1.
	if isZero:
		assign result, 1.
	else:
		factorial result, x.
	end.
back.

This one demonstrates the special conditional form if: [else:] end. - where the else: section is optional.

Fundamental Types

This is a list of the basic types Upsilon has.

string
number [Can be floating, or an integer.]
boolean [Can be true or false.]

Fundamental Subroutines

Here is the most basic Upsilon standard set, their pseudo-code equivalents and any extra details.

add z, x, y. [z := x + y]
subtract z, x, y. [z := x - y]
multiply z, x, y. [z := x * y]
divide z, x, y. [z := x / y]

fewer z, x, y. [z := x < y]
greater z, x, y. [z := x > y]
equal z, x, y. [z := x == y]

concat z, x, y. [z := concat(x, y)]
substring z, str, i, j. [z := substring(str, i, j)] [Use negative indexes for offsets from the end of the string]

not y, x. [y := !x]
and z, x, y. [z := x && y]
or z, x, y. [z := x || y]

Add these if you need them.

modulus z, x, y. [z := x % y] [always positive, doesn't reverse when negative]
negation y, x. [y := -x]

These ones allow you to find the properties of numbers more easily.

absolute y, x. [y := abs(x)] [absolute value]
sign y, x. [y := sign(x)] [1, 0 or -1]

floor y, x. [y := floor(x)]
ceiling y, x. [y := ceil(x)]
round y, x. [y := round(x)]

These ones are only required for trigonometric calculations. Note that they should be in radians.

sine y, theta. [y := sin(theta)]
cosine y, theta. [y := cos(theta)]
tangent y, theta. [y := tan(theta)]

arcsine theta, x. [theta := asin(x)]
arcosine theta, x. [theta := acos(x)]
arctangent theta, x. [theta := atan(x)]

arctangent2 theta, x, y. [theta := atan2(x, y)]