function quasiquote($ast) { if (!is_pair($ast)) { return _list(_symbol("quote"), $ast); } elseif (_symbol_Q($ast[0]) && $ast[0]->value === 'unquote') { return $ast[1]; } elseif (is_pair($ast[0]) && _symbol_Q($ast[0][0]) && $ast[0][0]->value === 'splice-unquote') { return _list(_symbol("concat"), $ast[0][1], quasiquote($ast->slice(1))); } else { return _list(_symbol("cons"), quasiquote($ast[0]), quasiquote($ast->slice(1))); } }
function is_macro_call($ast, $env) { return is_pair($ast) && _symbol_Q($ast[0]) && $env->find($ast[0]) && $env->get($ast[0])->ismacro; }
function hand_type($hand) { $ranks = []; $suits = []; for ($rank = 0; $rank < RANK_COUNT; $rank++) { $ranks[$rank] = 0; } for ($suit = 0; $suit < SUIT_COUNT; $suit++) { $suits[$suit] = 0; } foreach ($hand as $card) { $ranks[$card[RANK_FIELD]]++; $suits[$card[SUIT_FIELD]]++; } // echo '<pre>'; // print_r($ranks); // print_r($suits); // echo '</pre>'; $flush = is_flush($suits); $straight = is_straight($ranks); $royal = is_royal($ranks); if ($flush && $royal) { return ROYAL_FLUSH; } elseif ($flush && $straight) { return STRAIGHT_FLUSH; } elseif (is_quads($ranks)) { return QUADS; } elseif (is_boat($ranks)) { return BOAT; } elseif ($flush) { return FLUSH; } elseif ($straight) { return STRAIGHT; } elseif (is_trips($ranks)) { return TRIPS; } elseif (is_two_pair($ranks)) { return TWO_PAIR; } elseif (is_pair_jacks($ranks)) { return PAIR_JACKS; } elseif (is_pair($ranks)) { return LOW_PAIR; } else { return NOTHING; } }