Ugg
current mood: sick
Ok, make that really sick. I just hope that at 2:45 tomorrow I have enough wakefulness and energy to get to the doctor.
Ok, make that really sick. I just hope that at 2:45 tomorrow I have enough wakefulness and energy to get to the doctor.
And then I was able to collapse everything down to a single point:
Everything is a parentheses wrapped list of expressions that looks to its left and right.
That is basically it... There are some fine details, there are a good number of such expressions that hold special values, or do special stuff with their context. For example "private" will hide a symbol from inner and outer scopes, "protected" will hide a symbol from outer scopes. "dot" (.) will give you access to the symbols of an inner scope through it. "is" lets us bind a parentheses wrapped list of expressions to a symbol (and of course an unbound symbol is not a parentheses wrapped list of expressions).
I can't really explain how it all fits together so beautifully, but I think I may be able to build it. It's such a simple language that should fit perfectly into a neat little tree. I feel as if I could code its core in five lines of code.
Although, with me sick and all, and my brain not working right. This could just be an illusion. How far can you really go with duck typing for instance?
Even if it's an illusion though, if it's something that can't exist, or something whose existing form would ugly and useless, at this moment, it's still beautiful.
I'm still quite sick actually.
package datastructures;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
public class AdjacencyListGraph<vertex_t, weight_t> {
private class GraphConnection {
public vertex_t connected_vertex;
public weight_t connection_weight;
}
private HashMap<vertex_t, ArrayList<GraphConnection>> vertex_map;
void addBidirectionalAdjacency(vertex_t from, Collection<vertex_t> to) {
}
void addUndirectedAdjacency(vertex_t from, Collection<vertex_t> to) {
}
boolean isConnected(vertex_t first_vertex, vertex_t second_vertex) {
return false;
}
weight_t connectionWeight(vertex_t first_vertex, vertex_t second_vertex) {
return null;
}
}
Why am I doing this? Why isn't this sort of thing already in Java's standard library?
I've revamped this language to remove the problems it previously had, I'm quite liking it now.while is operator [
void,
void,
type [lambda, lambda],
(
if [right . 0, (
evaluate right . 1
while right
)
)
]
( some language specs for my future reference )
( wall of code )
Reasons this doesn't work:
1. Hard to read.
2. Not terse enough.
3. No way to enforce constness or volatility.
4. No access protection.
5. Garbage collection eww.
http://pastie.org/728770
Input:{type "type",
name "list"}
{type "virtual binary operator",
name "add",
left "list",
returns "void"}
{type "virtual binary operator",
name "get",
left "list",
right "integer"}
{type "virtual unary operator",
name "get",
argument "list"}
{type "unary operator",
name "concatenate",
argument "[list, list]",
returns "list",
does (
{type "integer", name "n", value '0'};
while [(n < size argument[1]), (argument[0] add (argument[1] get n))];
return argument[0];
)}
{type "binary operator",
name "+=",
left "list,
right "list",
returns "list",
does (concatenate [left, right])}
{type "type",
name "linked list",
parent "list",
adjectives ["of"],
types {
type "type",
name "node",
members [["node", "next"], ["node", "previous"]
}
members [["node", "head"] ["node", "tail"]]}
{type "linked list", of "integer", name "samplelist"}
samplelist add '23'
print samplelist
Output:
Compiler error, operator "list add *" is virtual.
If you were to define a "linked list add *" operator you would be able to concatenate two linked lists of the same type.
() can be used to denote scoping.
Input:
print quote ('2' + '2');
Output:
'2' + '2'
Input:
{type "integer", name n};
n = '10';
while [(return n > 0;), (print [n, " "]; -- n)];
Output:
10 9 8 7 6 5 4 3 2 1
Now if you were to say:
while [n > 0, (print [n, " "]; -- n)];
It wouldn't compile because the while operator takes a tuple<scope, scope> and there's no way to convert a boolean to such a type.
Now we can relax this, make scopes implicitly add a return to the front of their last expression. That would make (true) compile, due to the implicit return making that a valid expression. (false; true) wouldn't compile though, it would be a syntax error as that's complete nonsense.
Now that I'm almost done with my "principles of programming languages" class, I thought I'd revisit my programing language design musings.
So far I have three things:
1. Primitives
a. Number primitive example, '2.3'
b. String primitive example, "hi"
d. Tuple primitive example, ['1', "a"]
2. Operators
a. Operator like operator example, '2' + '2'
b. Keyword like operator example, println "hello world"
c. Function like operator example find ["c", ["a", "c", "b"]]
3. Constructors
a. A new integer variable {type "integer", name "n"}
b. Construct new operators, new primitives, new types etc.
Now the find function looks like this in conventional OO style pseudocode:
find<T> (T search_term, List<T> search_list) {
Now at compile time, the compiler will do implicit conversions to make this work, a Tuple<str, str, str> can be converted into a List<str>.
Now if I were to try: find["c" ["a", '3.3', "c"] that would also be valid. It would try to implicitly convert each element of the tuple into a string. This is possible with pretty much any type.
Now this is not yet a complete programming language, but it's fun to think about.
The left half of my head has cleared up. For now at least. I managed to force one big, and two small solid chunks of gunk out of there.
If I try and imagine a cube, I get a view that rotates, but I can't imagine a cube in the center of it. This is progress.
I haven't tried the nasal spray I have a prescription for yet.