This commit is contained in:
Jeff 2023-11-03 18:04:45 -04:00
parent d1b116cc35
commit 8ca97300d3
8 changed files with 39 additions and 31 deletions

View File

@ -3,20 +3,26 @@ suspects = ['White' 'Green']
weapons = ['Rope' 'Lead_Pipe'] weapons = ['Rope' 'Lead_Pipe']
cards = [rooms suspects weapons] cards = [rooms suspects weapons]
take_turn = function current_room opponent_card take_turn = |current_room opponent_card| => {
remove_card opponent_card (remove_card opponent_card)
make_guess current_room (make_guess current_room)
}
remove_card = function opponent_card remove_card = |opponent_card| => {
for card_list in cards for card_list in cards {
removed = remove card from card_list removed = remove card from card_list
card == opponent_card card == opponent_card
}
if type removed == 'empty' if (type removed) == 'empty'
output 'Card not found.' output 'Card not found.'
}
make_guess = function current_room make_guess = |current_room| => {
if length suspects == 1 && length rooms == 1 && length weapons == 1 if ((length suspects) == 1)
&& ((length rooms) == 1)
&& ((length weapons) == 1)
{
(output 'It was ' (output 'It was '
+ suspects:0 + suspects:0
+ ' in the ' + ' in the '
@ -24,7 +30,7 @@ make_guess = function current_room
+ ' with the ' + ' with the '
+ weapons:0 + weapons:0
+ '!') + '!')
else } else {
(output 'I accuse ' (output 'I accuse '
+ (random suspects) + (random suspects)
+ ' in the ' + ' in the '
@ -32,5 +38,7 @@ make_guess = function current_room
+ ' with the ' + ' with the '
+ (random weapons) + (random weapons)
+ '!') + '!')
}
}
(make_guess 'Library') (make_guess 'Library')

View File

@ -1,4 +1,4 @@
fib = function <i> { fib = |i| => {
if i <= 1 { if i <= 1 {
1 1
} else { } else {

View File

@ -1,31 +1,31 @@
my_table = table <text number bool> [ my_table = table |text number bool| [
["a", 1, true] ["a", 1, true]
["b", 2, true] ["b", 2, true]
["a", 3, true] ["a", 3, true]
] ]
test_table = table <text bool> [ test_table = table |text bool| [
["a", true] ["a", true]
["b", true] ["b", true]
["a", 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) (assert_equal test_select, test_table)
test_table = table <text number bool> [ test_table = table |text number bool| [
[1, true] [1, true]
[3, true] [3, true]
] ]
test_select_where = select <number, bool> from my_table { test_select_where = select |number, bool| from my_table {
text == "a" text == "a"
} }
(assert_equal test_select_where, test_table) (assert_equal test_select_where, test_table)
test_table = table <text number bool> [ test_table = table |text number bool| [
["a", 1, true] ["a", 1, true]
["b", 2, true] ["b", 2, true]
["a", 3, true] ["a", 3, true]

View File

@ -94,13 +94,13 @@ impl AbstractTree for BuiltInFunction {
BuiltInFunction::AssertEqual(expressions) BuiltInFunction::AssertEqual(expressions)
} }
"download" => { "download" => {
let expression_node = node.child(2).unwrap(); let expression_node = node.child(1).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::Download(expression) BuiltInFunction::Download(expression)
} }
"help" => { "help" => {
let child_node = node.child(2).unwrap(); let child_node = node.child(1).unwrap();
let expression = if child_node.is_named() { let expression = if child_node.is_named() {
Some(Expression::from_syntax_node(source, child_node)?) Some(Expression::from_syntax_node(source, child_node)?)
} else { } else {
@ -110,7 +110,7 @@ impl AbstractTree for BuiltInFunction {
BuiltInFunction::Help(expression) BuiltInFunction::Help(expression)
} }
"length" => { "length" => {
let expression_node = node.child(2).unwrap(); let expression_node = node.child(1).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::Length(expression) BuiltInFunction::Length(expression)
@ -126,7 +126,7 @@ impl AbstractTree for BuiltInFunction {
BuiltInFunction::OutputError(expressions) BuiltInFunction::OutputError(expressions)
} }
"type" => { "type" => {
let expression_node = node.child(2).unwrap(); let expression_node = node.child(1).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::Type(expression) BuiltInFunction::Type(expression)
@ -140,7 +140,7 @@ impl AbstractTree for BuiltInFunction {
BuiltInFunction::Append(expressions) BuiltInFunction::Append(expressions)
} }
"metadata" => { "metadata" => {
let expression_node = node.child(2).unwrap(); let expression_node = node.child(1).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::Metadata(expression) BuiltInFunction::Metadata(expression)
@ -153,13 +153,13 @@ impl AbstractTree for BuiltInFunction {
BuiltInFunction::Move(expressions) BuiltInFunction::Move(expressions)
} }
"read" => { "read" => {
let expression_node = node.child(2).unwrap(); let expression_node = node.child(1).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::Read(expression) BuiltInFunction::Read(expression)
} }
"remove" => { "remove" => {
let expression_node = node.child(2).unwrap(); let expression_node = node.child(1).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::Remove(expression) BuiltInFunction::Remove(expression)
@ -172,25 +172,25 @@ impl AbstractTree for BuiltInFunction {
BuiltInFunction::Write(expressions) BuiltInFunction::Write(expressions)
} }
"from_json" => { "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)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::FromJson(expression) BuiltInFunction::FromJson(expression)
} }
"to_json" => { "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)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::ToJson(expression) BuiltInFunction::ToJson(expression)
} }
"to_string" => { "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)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::ToString(expression) BuiltInFunction::ToString(expression)
} }
"to_float" => { "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)?; let expression = Expression::from_syntax_node(source, expression_node)?;
BuiltInFunction::ToFloat(expression) BuiltInFunction::ToFloat(expression)

View File

@ -18,7 +18,7 @@ impl AbstractTree for Find {
let expression_node = node.child(3).unwrap(); let expression_node = node.child(3).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; 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)?; let item = Block::from_syntax_node(source, item_node)?;
Ok(Find { Ok(Find {

View File

@ -33,7 +33,7 @@ impl AbstractTree for For {
let expression_node = node.child(3).unwrap(); let expression_node = node.child(3).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; 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)?; let item = Block::from_syntax_node(source, item_node)?;
Ok(For { Ok(For {

View File

@ -18,7 +18,7 @@ impl AbstractTree for Remove {
let expression_node = node.child(3).unwrap(); let expression_node = node.child(3).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; 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)?; let item = Block::from_syntax_node(source, item_node)?;
Ok(Remove { Ok(Remove {

View File

@ -19,7 +19,7 @@ impl AbstractTree for Transform {
let expression_node = node.child(3).unwrap(); let expression_node = node.child(3).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?; 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)?; let item = Block::from_syntax_node(source, item_node)?;
Ok(Transform { Ok(Transform {