Clean up
This commit is contained in:
parent
d1b116cc35
commit
8ca97300d3
@ -3,20 +3,26 @@ suspects = ['White' 'Green']
|
||||
weapons = ['Rope' 'Lead_Pipe']
|
||||
cards = [rooms suspects weapons]
|
||||
|
||||
take_turn = function current_room opponent_card
|
||||
remove_card opponent_card
|
||||
make_guess current_room
|
||||
take_turn = |current_room opponent_card| => {
|
||||
(remove_card opponent_card)
|
||||
(make_guess current_room)
|
||||
}
|
||||
|
||||
remove_card = function opponent_card
|
||||
for card_list in cards
|
||||
remove_card = |opponent_card| => {
|
||||
for card_list in cards {
|
||||
removed = remove card from card_list
|
||||
card == opponent_card
|
||||
}
|
||||
|
||||
if type removed == 'empty'
|
||||
if (type removed) == 'empty'
|
||||
output 'Card not found.'
|
||||
}
|
||||
|
||||
make_guess = function current_room
|
||||
if length suspects == 1 && length rooms == 1 && length weapons == 1
|
||||
make_guess = |current_room| => {
|
||||
if ((length suspects) == 1)
|
||||
&& ((length rooms) == 1)
|
||||
&& ((length weapons) == 1)
|
||||
{
|
||||
(output 'It was '
|
||||
+ suspects:0
|
||||
+ ' in the '
|
||||
@ -24,7 +30,7 @@ make_guess = function current_room
|
||||
+ ' with the '
|
||||
+ weapons:0
|
||||
+ '!')
|
||||
else
|
||||
} else {
|
||||
(output 'I accuse '
|
||||
+ (random suspects)
|
||||
+ ' in the '
|
||||
@ -32,5 +38,7 @@ make_guess = function current_room
|
||||
+ ' with the '
|
||||
+ (random weapons)
|
||||
+ '!')
|
||||
}
|
||||
}
|
||||
|
||||
(make_guess 'Library')
|
||||
|
@ -1,4 +1,4 @@
|
||||
fib = function <i> {
|
||||
fib = |i| => {
|
||||
if i <= 1 {
|
||||
1
|
||||
} else {
|
||||
|
@ -1,31 +1,31 @@
|
||||
my_table = table <text number bool> [
|
||||
my_table = table |text number bool| [
|
||||
["a", 1, true]
|
||||
["b", 2, true]
|
||||
["a", 3, true]
|
||||
]
|
||||
|
||||
test_table = table <text bool> [
|
||||
test_table = table |text bool| [
|
||||
["a", true]
|
||||
["b", true]
|
||||
["a", true]
|
||||
]
|
||||
|
||||
test_select = select <text bool> from my_table
|
||||
test_select = select |text bool| from my_table
|
||||
|
||||
(assert_equal test_select, test_table)
|
||||
|
||||
test_table = table <text number bool> [
|
||||
test_table = table |text number bool| [
|
||||
[1, true]
|
||||
[3, true]
|
||||
]
|
||||
|
||||
test_select_where = select <number, bool> from my_table {
|
||||
test_select_where = select |number, bool| from my_table {
|
||||
text == "a"
|
||||
}
|
||||
|
||||
(assert_equal test_select_where, test_table)
|
||||
|
||||
test_table = table <text number bool> [
|
||||
test_table = table |text number bool| [
|
||||
["a", 1, true]
|
||||
["b", 2, true]
|
||||
["a", 3, true]
|
||||
|
@ -94,13 +94,13 @@ impl AbstractTree for BuiltInFunction {
|
||||
BuiltInFunction::AssertEqual(expressions)
|
||||
}
|
||||
"download" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::Download(expression)
|
||||
}
|
||||
"help" => {
|
||||
let child_node = node.child(2).unwrap();
|
||||
let child_node = node.child(1).unwrap();
|
||||
let expression = if child_node.is_named() {
|
||||
Some(Expression::from_syntax_node(source, child_node)?)
|
||||
} else {
|
||||
@ -110,7 +110,7 @@ impl AbstractTree for BuiltInFunction {
|
||||
BuiltInFunction::Help(expression)
|
||||
}
|
||||
"length" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::Length(expression)
|
||||
@ -126,7 +126,7 @@ impl AbstractTree for BuiltInFunction {
|
||||
BuiltInFunction::OutputError(expressions)
|
||||
}
|
||||
"type" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::Type(expression)
|
||||
@ -140,7 +140,7 @@ impl AbstractTree for BuiltInFunction {
|
||||
BuiltInFunction::Append(expressions)
|
||||
}
|
||||
"metadata" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::Metadata(expression)
|
||||
@ -153,13 +153,13 @@ impl AbstractTree for BuiltInFunction {
|
||||
BuiltInFunction::Move(expressions)
|
||||
}
|
||||
"read" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::Read(expression)
|
||||
}
|
||||
"remove" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::Remove(expression)
|
||||
@ -172,25 +172,25 @@ impl AbstractTree for BuiltInFunction {
|
||||
BuiltInFunction::Write(expressions)
|
||||
}
|
||||
"from_json" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::FromJson(expression)
|
||||
}
|
||||
"to_json" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::ToJson(expression)
|
||||
}
|
||||
"to_string" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::ToString(expression)
|
||||
}
|
||||
"to_float" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression_node = node.child(1).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
BuiltInFunction::ToFloat(expression)
|
||||
|
@ -18,7 +18,7 @@ impl AbstractTree for Find {
|
||||
let expression_node = node.child(3).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
let item_node = node.child(5).unwrap();
|
||||
let item_node = node.child(4).unwrap();
|
||||
let item = Block::from_syntax_node(source, item_node)?;
|
||||
|
||||
Ok(Find {
|
||||
|
@ -33,7 +33,7 @@ impl AbstractTree for For {
|
||||
let expression_node = node.child(3).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
let item_node = node.child(5).unwrap();
|
||||
let item_node = node.child(4).unwrap();
|
||||
let item = Block::from_syntax_node(source, item_node)?;
|
||||
|
||||
Ok(For {
|
||||
|
@ -18,7 +18,7 @@ impl AbstractTree for Remove {
|
||||
let expression_node = node.child(3).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
let item_node = node.child(5).unwrap();
|
||||
let item_node = node.child(4).unwrap();
|
||||
let item = Block::from_syntax_node(source, item_node)?;
|
||||
|
||||
Ok(Remove {
|
||||
|
@ -19,7 +19,7 @@ impl AbstractTree for Transform {
|
||||
let expression_node = node.child(3).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
let item_node = node.child(5).unwrap();
|
||||
let item_node = node.child(4).unwrap();
|
||||
let item = Block::from_syntax_node(source, item_node)?;
|
||||
|
||||
Ok(Transform {
|
||||
|
Loading…
Reference in New Issue
Block a user