Q-SET

From Esolang
(Redirected from Q set)
Jump to navigation Jump to search

Q-SET is an abandoned programming language designed by User:Peter in 2022. All data consists of sets of numbers, which may or may not be structured in ordered pairs. It's named after the set of rational numbers, which contains every value that can be used in Q-SET.

Language Overview

There are three different data types in Q-SET: Sets, ordered pairs and functions. Sets can contain up to (countably) infinite values, and any operator that changes a set changes each value independently. Numerical literals are treated as sets with only one element. Ordered pairs can include two sets, a set and an ordered pair or two ordered pairs. Functions can take in any amount of sets and/or pairs as parameters, and will return another set or pair without side effects.

Commands

Instruction Parameters Description Example usage
a = b Identifier, set/pair Sets a, which is a set or a pair, equal to b, which must have the same data type as a. a = 5
[a, b] Literal, literal Any number between and including a and b is in this set. Replace a with <- to include all numbers lower than b, or b with -> to include all numbers greater than a. [3, ->]
{a, b} Literal, literal Any number between but not including a and b is in this set. You can use <- and -> for the same purposes as with the [a, b], and you can use curly brackets and square brackets for the same set. {5, 9]
Number Literal A number outside of curly or square brackets counts as a set containing only one element. a = 5
a,b Set/pair, set/pair An ordered pair containing the values a and b, which can be sets or pairs. a = (5, [2, 6}), 3
<a Pair The left side of pair a. a = <b
a> Pair The right side of pair a. a> = b
a: b Identifier, data type Declares a as a variable of type b (Set/Pair). May be used in the same line as a =. a: Set = {<-, 8]
a :: b = c Identifier, data type, identifier (constant) / literal Declares a as a constant variable of type b (Set/Pair) with value c. a :: Pair = 5, 7
a & b Set, set Returns the intersection of a and b. a = b & [3, 9]
b Set, set Returns the union of a and b. {12, 100]
a ^ b Set, set Returns all values in either a or b but not both. a = a ^ b
!a Set Returns the complement of a. a = !1
a+b Set Returns every combination of any value in a added to any value in b. a = {1, 5] + [-3, -2}
a*b Set Returns every combination of any value in a multiplied by any value in b. a = b * 0.5
Natural None A built-in set of all natural numbers, not including 0. a = Natural & {<-, 10]
Integer None A built-in set of all integers. a = !Integer
Rational None A built-in set of all rational numbers. a = Rational
[] or {} None An empty set. Equal :: a: Set, b: Set -> Set = a^b ? {}, a
a?b Set, pair Returns the right side of b if a is empty, and returns the left side otherwise. a & [0, ->} ? 1, -1
a :: b -> c = d Identifier, identifier declarations, data type, function A pure function taking in argument(s) b and returning d, which has type c. Sum :: a: Set, b: Set -> Set = a + b
a(b) Function, argument(s) Calls function a, using argument(s) b, separated by commas. Sum(a, 1)
-- None The rest of the line is a comment. a = b -- make a equal b
import a File name Import a (without an extension or quotation marks) so functions from the file can be used in this one. import simple maths
public a Identifier declaration Gives other files access to a if they have imported this one. public Sum :: a: Pair -> Set = <a + a>

Example programs

Here are some simple Q-SET examples.

FizzBuzz

Q-SET doesn't have IO or strings, so FizzBuzz is simply implemented as a function returning -1, -2, -3 or a natural number depending on the value used.

Fizz :: n: Set -> Set
    = n & (Integer * 3) ? -1, {} -- Integer * 3 = 3, 6, 9, 12, 15 ...

Buzz :: n: Set -> Set
    = n & (Integer * 5) ? -2, {}

public FizzBuzz :: n: Set -> Set
    = (Fizz(n) + Buzz(n)) ? (Fizz(n) + Buzz(n)), n

Even or odd?

IsEven :: n: Set -> Set
    = n & (Integer * 2) ? n : {}

Fibonacci

Fibonacci :: n: Set -> Set
    = n & 1 ? 1 n & [<-, 1} ? 0