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
class SteeringWheel { | |
public: | |
boolean fuzzy; | |
SomeExternalResource * resource; | |
// copy constructor | |
SteeringWheel(const SteeringWheel & other) { | |
fuzzy = other.fuzzy; |
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
template<typename T> | |
class LinkedList { | |
struct Node { | |
Node * previous; | |
Node * next; | |
T value; | |
}; |
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
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 { "." } | |
}) |
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
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; |
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
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) |
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
{"__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}, |
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
// 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; |
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
"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) |
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
struct Spaceship { | |
subsystem: Subsystem | |
} | |
enum Subsystem { | |
Engine { fuel: i64 }, | |
Navigation { antenna: Box<Antenna> }, | |
} | |
struct Antenna { | |
frequency: i64 | |
} |
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
# Does Python have data races? | |
# | |
# As we've seen, Java can have data races, according to | |
# https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html | |
# It says an example of a data race is when: | |
# - there is a write in one thread, | |
# - a read of the same variable by another thread, | |
# - and the write and read are not ordered by synchronization. | |
# | |
# This program attempts to cause a data race in Python. |
OlderNewer