Last active
March 13, 2020 15:10
-
-
Save gregspurrier/5014399 to your computer and use it in GitHub Desktop.
ShenRuby's K Lambda Spec (work in progress)
This file contains hidden or 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
Atoms: | |
a string | |
is self-evaluating | |
a symbol | |
is self-evaluating | |
may include any of the legal characters for symbol | |
may begin with any legal character other than a digit | |
may not begin with a digit | |
numbers | |
parses integers as integers | |
parses floating point numbers as reals | |
with leading sign characters | |
recognizes negative numbers | |
treats any odd number of minuses as negative | |
treats any even number of minuses as positive | |
ignores leading plusses | |
true | |
evaluates to boolean true rather than a symbol | |
false | |
evaluates to boolean false rather than a symbol | |
Primitives for Arithmetic | |
+ | |
adds its arguments | |
returns an integer when both arguments are integers | |
returns a real when either argument is a real | |
raises an error if its first argument is not an integer or a real | |
raises an error if its second argument is not an integer or a real | |
evaluates its arguments from left to right | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
- | |
subtracts its second argument from its first | |
returns an integer when both arguments are integers | |
returns a real when either argument is a real | |
raises an error if its first argument is not an integer or a real | |
raises an error if its second argument is not an integer or a real | |
evaluates its arguments from left to right | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
* | |
multiplies its arguments | |
returns an integer when both arguments are integers | |
returns a real when either argument is a real | |
raises an error if its first argument is not an integer or a real | |
raises an error if its second argument is not an integer or a real | |
evaluates its arguments from left to right | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
/ | |
divides its first argument by its second argument | |
returns an integer when an integer evenly divides another integer | |
returns a real when an integer does not evenly divide another integer | |
returns a real when either argument is a real | |
raises an error if its first argument is not an integer or a real | |
raises an error if its second argument is not an integer or a real | |
evaluates its arguments from left to right | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
> | |
returns false if its first argument is less than its second argument | |
returns false if its first argument is equal to its second argument | |
returns true if its first argument is greater than its second argument | |
raises an error if its first argument is not an integer or a real | |
raises an error if its second argument is not an integer or a real | |
evaluates its arguments from left to right | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
< | |
returns true if its first argument is less than its second argument | |
returns false if its first argument is equal to its second argument | |
returns false if its first argument is greater than its second argument | |
raises an error if its first argument is not an integer or a real | |
raises an error if its second argument is not an integer or a real | |
evaluates its arguments from left to right | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
>= | |
returns false if its first argument is less than its second argument | |
returns true if its first argument is equal to its second argument | |
returns true if its first argument is greater than its second argument | |
raises an error if its first argument is not an integer or a real | |
raises an error if its second argument is not an integer or a real | |
evaluates its arguments from left to right | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
<= | |
returns true if its first argument is less than its second argument | |
returns true if its first argument is equal to its second argument | |
returns false if its first argument is greater than its second argument | |
raises an error if its first argument is not an integer or a real | |
raises an error if its second argument is not an integer or a real | |
evaluates its arguments from left to right | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
number? | |
returns true when its argument is an integer | |
returns true when its argument is a real | |
returns false when its argument is of any other type | |
Primitives for assignment | |
(set Name Value) | |
associates Value with Name | |
returns Value | |
overwrites the previous value when called again with same Name | |
raises an error if its first argument is not a symbol | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
evaluates its arguments from left to right | |
(value Name) | |
returns the value associated with Name | |
raises an error if Name has not previously been set | |
raises an error if its first argument is not a symbol | |
supports partial application of 0 arguments | |
Primitives for Boolean Operations | |
if special form | |
raises an error when given 0 arguments | |
raises an error when given 1 argument | |
raises an error when given 2 arguments | |
evaluates its first argument | |
when its first argument evaluates to true | |
returns the normal form of its second argument | |
does not evaluate its third argument | |
when its first argument evaluates to false | |
returns the normal form of its third argument | |
does not evaluate its second argument | |
and special form | |
evaluates its first argument | |
may be passed as an argument to a higher-order function | |
when its first argument evaluates to true | |
returns true if its second argument evaluates to true | |
returns false if its second argument evaluates to false | |
when its first argument evaluates to false | |
returns false | |
does not evaluate it second argument | |
partial application | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
results in it no longer short-circuiting argument evaluation | |
or special form | |
evaluates its first argument | |
may be passed as an argument to a higher-order function | |
when its first argument evaluates to false | |
returns true if its second argument evaluates to true | |
returns false if its second argument evaluates to false | |
when its first argument evaluates to true | |
returns true | |
does not evaluate it second argument | |
partial application | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
results in it no longer short-circuiting argument evaluation | |
Primitives for Generic Functions | |
(defun Name ArgList Expr) | |
does not evaulate Expr | |
returns Name | |
binds Name to a function having ArgList as its formals and Expr as its body | |
allows ArgList to be the empty list | |
allows previously defined non-primitive functions to be redefined | |
raises an error when attempting to redefine a primitive | |
raises an error if its first argument is not a symbol | |
raises an error if ArgList is not a list | |
raises an error if ArgList contains non-symbols | |
raises an error when given 0 arguments | |
raises an error when given 1 argument | |
raises an error when given 2 arguments | |
(lambda X Expr) | |
does not evaulate Expr | |
returns a function | |
raises an error if its first argument is not a symbol | |
raises an error when given 0 arguments | |
raises an error when given 1 argument | |
the returned function, when applied | |
evaluates Expr with X bound to its argument | |
(freeze Expr) | |
does not evaluate Expr | |
returns a continuation | |
the returned continuation, upon thawing | |
evaluates and returns the value of Expr | |
re-evaluates Expr with each thawing | |
partial application | |
supports partial application of 0 arguments | |
results in it no longer delaying execution of Expr | |
Primitives for lists | |
(cons Hd Tl) | |
creates a list with Hd as the head and Tl as the tail | |
allows Tl to be a non-list | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
evaluates its arguments from left to right | |
(hd L) | |
returns the head of L | |
raises an error if its first argument is not a list or a dotted pair | |
supports partial application of 0 arguments | |
(tl L) | |
returns the tail of L | |
raises an error if its first argument is not a list or a dotted pair | |
supports partial application of 0 arguments | |
cons? | |
returns true when its argument is a list | |
returns true when its argument is a dotted pair | |
returns false when its argument is of any other type | |
Primitives for strings | |
(pos S N) | |
returns the character at zero-based index N of S as a unit string | |
raises an error if N is negative | |
raises an error if N is >= the length of S | |
raises an error if its first argument is not a string | |
raises an error if its second argument is not an integer | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
evaluates its arguments from left to right | |
(tlstr S) | |
returns a string containing all but the first character of S | |
raises an error when S is the empty string | |
raises an error if its first argument is not a string | |
supports partial application of 0 arguments | |
string? | |
returns true when its argument is a string | |
returns false when its argument is of any other type | |
(n->string N) | |
returns a unit string containing the character with ASCII code N | |
raises an error if its first argument is not an integer | |
supports partial application of 0 arguments | |
(string->n S) | |
returns the ASCII code of the unit string S | |
returns the ASCII code of the first character of non-unit string S | |
raises an error when S is the empty string | |
raises an error if its first argument is not a string | |
supports partial application of 0 arguments | |
Primitives for symbols | |
intern | |
converts a string to its corresponding symbol | |
supports characters not allowed in symbol literals | |
converts the string "true" to boolean true | |
converts the string "false" to boolean false | |
raises an error if its first argument is not a string | |
supports partial application of 0 arguments | |
Primitive functions for vectors | |
(absvector N) | |
returns a new absolute vector of size N | |
raises an error if its first argument is not an integer | |
supports partial application of 0 arguments | |
(address-> V N Value) | |
returns the vector V updated with Value at index N | |
raises an error if N is negative | |
raises an error if N is >= the size of the vector | |
raises an error if its first argument is not a vector | |
raises an error if its second argument is not an integer | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
supports partial application of 2 arguments | |
evaluates its arguments from left to right | |
(<-address V N) | |
returns the value previously stored at index N in V | |
returns an unspecified value if index N has not been stored to | |
raises an error if N is negative | |
raises an error if N is >= the size of the vector | |
raises an error if its first argument is not a vector | |
raises an error if its second argument is not an integer | |
supports partial application of 0 arguments | |
supports partial application of 1 argument | |
supports partial application of 2 arguments | |
evaluates its arguments from left to right | |
absvector? | |
returns true when its argument is a vector | |
returns false when its argument is of any other type | |
Tail recursion | |
does not consume stack space for self tail calls | |
does not consume stack space for mutually recursive tail calls | |
Finished in 0.63245 seconds | |
210 examples, 0 failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment