Skip to content

Instantly share code, notes, and snippets.

View Verdagon's full-sized avatar

Evan Ovadia Verdagon

View GitHub Profile
class SteeringWheel {
public:
boolean fuzzy;
SomeExternalResource * resource;
// copy constructor
SteeringWheel(const SteeringWheel & other) {
fuzzy = other.fuzzy;
template<typename T>
class LinkedList {
struct Node {
Node * previous;
Node * next;
T value;
};
fn main() {
let board =
Array(10, {(row)
Array(10, {(col)
= if (row == 0 or col == 0 or row == 9 or col == 9) { "#" }
else { "." }
})
});
let mut playerRow = 4;
@Verdagon
Verdagon / gist:f950c7e9917b2b866801e732d2a34eeb
Last active August 29, 2018 04:03
First working roguelike!
fn main() {
let board =
__MutArray(10, {(row)
__MutArray(10, {(col)
= if {row == 0} { "#" }
else if {col == 0} { "#" }
else if {row == 9} { "#" }
else if {col == 9} { "#" }
else { "." }
})
def evaluateFunction(globalCache0: GlobalCache, func: PFunction) = {
val localsCache0 = LocalsCache(Map())
val (localsCache1, params) =
evaluateParameters(localsCache0, func.params)
val (globalCache1, localsCache2, expressions) =
evaluateExpressions(globalCache0, localsCache1, func.body)
val (globalCache2, localsCache3, destructors) =
evaluateDestructors(globalCache1, localsCache2)
val (localsCache4, ret) =
evaluateReturn(localsCache3)
{"__type": "Function",
"range": {"__type": "Range", "begin": 188, "end": 253},
"header": {"__type": "FunctionHeader",
"range": {"__type": "Range", "begin": 188, "end": 229},
"name": {"__type": "Some",
"value": {"__type": "Name", "range": {"__type": "Range", "begin": 191, "end": 194}, "name": "has"}},
"attributes": [],
"maybeUserSpecifiedIdentifyingRunes": {"__type": "Some",
"value": {"__type": "IdentifyingRunes",
"range": {"__type": "Range", "begin": 194, "end": 197},
// Idiom #20 - Return two values
// Implement a function search which looks for item x in a 2D matrix m.
// Return indices i, j of the matching cell.
// Think of the most idiomatic way in the language to return
// the two values at the same time.
fn main() export {
m = [][ [][1, 2, 3], [][4, 5, 6], [][7, 8, 9] ];
to_search = 4;
"If a language only allowed owning references, memory management would betrivial, but ownership rules would severely limit the programmer."
Now that I think of it, this would just be a lot of copies. In fact, someone has tried something like this: https://degaz.io/blog/632020/post.html
"1.2.2 Borrow References". The term "borrow references" is fine, but might want to make it clear up front that they don't work like Rust's borrow references. Or sometimes, I call them non-owning references, to avoid confusion.
"while C++ uses the unique_ptr and shared_ptr classes mentioned in 1.1.1 to accomplish the same goal." -> "while C++ uses unique_ptr and raw pointers respectively mentioned in 1.1.1 to accomplish the same goal.
(shared_ptr is for RC in c++, and shared_ptr and unique_ptr dont mix)
struct Spaceship {
subsystem: Subsystem
}
enum Subsystem {
Engine { fuel: i64 },
Navigation { antenna: Box<Antenna> },
}
struct Antenna {
frequency: i64
}
struct Account {
name: String,
money: i64,
labelView: i32
}
struct Button {
onclick: Box<dyn FnMut()>
}