-
-
Save threeifbywhiskey/9d47b4b16ee220334660 to your computer and use it in GitHub Desktop.
CJam operations encoded as pseudo-Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! | |
Number a -> a != 0 # boolean NOT | |
List/String a -> a.empty? # not empty | |
Char a -> a != '\0' # not NUL | |
# | |
Number a, Number b -> a ** b # exponentiation | |
List/String a, Block b -> a.index(b) or -1 # index by | |
Block a, List/String b -> b.index(a) or -1 # index by | |
$ | |
Number a -> Stack[-(a + 1)] # stack plucking | |
List a -> a.sort # sort | |
List a, Block b -> a.sort_by(b) # sort by (need to stabilize) | |
% | |
Number a, Number b -> a % b # modulus | |
Block a, List b -> b.map(a) # map | |
List a, Block b -> a.map(b) # map | |
List a, List b -> a.split_at(b) # split at | |
List a, Number b -> a.take_every(b) # take every (starting at the first) | |
Number a, List b -> b.take_every(a) # take every (starting at the first) | |
& | |
Number a, Number b -> a & b # bitwise AND | |
List a, List b -> a & b # set intersection | |
( | |
Number/Char a -> a - 1 # decrement | |
List a -> Stack << a.shift # uncons left | |
) | |
Number/Char a -> a + 1 # increment | |
List a -> Stack << a.pop # uncons right | |
* # Might have missed a signature here? | |
Number a, Number b -> a * b # multiplication | |
Char a, Number b -> a * b # replication | |
Number a, Char b -> b * a # replication | |
List a, Number b -> a * b # replication | |
Number a, List b -> b * a # replication | |
List a, Char b -> a.join(b) # join | |
Char a, List b -> a.join(b) # join | |
List a, Block b -> a.reduce(b) # left fold | |
Block a, List b -> b.reduce(a) # left fold | |
+ | |
Number a, Number b -> a + b # addition | |
Char a, Char b -> a + b # string buildup | |
Char a, Number b -> (a.ord + b).chr # character addition | |
Number a, Char b -> (b.ord + a).chr # character addition | |
List a, Any b -> a + b # concatenation | |
Any a, List b -> b + a # concatenation | |
- | |
Number a, Number b -> a - b # subtraction | |
Char a, Number b -> # character subtraction | |
Char a, Char b -> a.ord - b.ord # character difference | |
List a, List b -> a - b # set exclusion | |
?/ | |
Number a, Number b -> a / b | |
List a, Number b -> a.chunk(b) # list division into chunks | |
Number a, List b -> b.chunk(a) # list division into chunks | |
List/String a, List/Char b -> a.split(b) # split | |
List a, Block b -> a.each { b(a) } # each | |
Block a, List b -> b.each { a(b) } # each | |
: (infix) | |
Any a, Var b -> var[b] = a # set var (keep on stack) | |
List a, Unary b -> a.map(b) # quick map | |
List a, Binary b -> a.fold(b) # quick fold | |
, | |
Number a -> (0...a) # range | |
Char a -> ('\0'...a) # character range | |
List/String a -> a.length # list length | |
List a, Block b -> a.filter(b) # filter | |
; | |
Any a -> Stack.pop # pop | |
< | |
Any a, Any b -> (a <=> b) < 0 # number/list/string/char comparison | |
List a, Number b -> a.take(b) # first b elements | |
Number a, List b -> b.take(a) # first a elements | |
= | |
Any a, Any b (= a) -> (a <=> b) == 0 # number/list/string/char comparison | |
List a, Number b -> a[b] # index into | |
Number a, List b -> b[a] # index into | |
List a, Block b -> a.find_by(b) # find_by | |
> | |
Any a, Any b -> (a <=> b) > 0 # number/list/string/char comparison | |
List a, Number b -> a.drop(b) # all but first b elements | |
Number a, List b -> b.drop(a) # all but first a elements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment