Twigでlispを作ってるんだナ! (9レス)
上下前次1-新
2: 07/07(日)12:07 ID:Z9WWCnLov(1/8) AAS
{% macro evaluate(expression) %}{% set result = _self._evaluate(expression|trim) %}{{ result }}{% endmacro %}
{% macro _evaluate(expression) %}{% set num = 1 %}
{% set expr = expression|trim %}{% set expr = expr|split(')(') %}{% set expra = expr[0] %}
{% set expra = expra|trim('(')|trim(')')|trim %}{% set components = expra|split(' ') %}
{% set operator = components[0] %}{% set operands = components[1:] %}
{% if operator == '+' %}{{_self._keisan(operator,operands)}}
{% elseif operator == '-' %}{{_self._keisan(operator,operands)}}{% elseif operator == '*' %}{{_self._keisan(operator,operands)}}
{% elseif operator == '/' %}{{_self._keisan(operator,operands)}}{% elseif operator == 'if' %}{% set a = operands[0]|trim('(') %}
{% set b = operands[1] %}{% set c = operands[2]|trim(')') %}{% if a == 'eq?' %}{% if b == c %}{% set result = "true" %}
{% set expra = expr[1] %}{% set expra = expra|trim('(')|trim(')')|trim %}{% set components = expra|split(' ') %}
{% set operator = components[0] %}{% set operands = components[1:] %}
{{_self._keisan(operator,operands)}}{% else %}
{% set result = "false" %}{% endif %}{% elseif a == 'neq?' %}{% if b != c %}{% set result = "true" %}
{% set expra = expr[1] %}{% set expra = expra|trim('(')|trim(')')|trim %}{% set components = expra|split(' ') %}
{% set operator = components[0] %}{% set operands = components[1:] %}{{_self._keisan(operator,operands)}}
{% else %}{% set result = "false" %}{% endif %}{% endif %}{% else %}{% set result = "Unknown operation" %}
{% endif %}{{ result }}{% endmacro %}
上下前次1-新書関写板覧索設栞歴
あと 7 レスあります
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.264s*