<commit_before>function rpn(input) {
  var ar = input.split(/\s+/), st = [], token, result;
  while(token = ar.shift()) { 
    if (token == +token) { // numeric
      st.push(token);
    } else {
      switch(token) {
        case '+':
        case '-':
        case '*':
        case '/': {
          let n2 = st.pop(), n1 = st.pop();
          result = eval(n1 + token + ' ' + n2);
          break;
        }
        case '^': {
          let n2 = st.pop(), n1 = st.pop();
          result = Math.pow(n1, n2);
          break;
        }
        case 'log': {
          let n1 = st.pop();
          result = Math.log(n1);
          break;
        }
      }

      st.push(result);
    }
  }
  return st.pop();
}

module.exports = {
  help: {
    name: 'rpn',
    desc: 'Evaluates an equation written in rpn format',
    usage: '<equation>',
    aliases: []
  },

  exec: (client, msg, params) => {
    let equation = params.join(' ').replace('e', Math.E).replace('pi', Math.PI);
    msg.edit(`String: ${params.join(' ')}
\`\`\`xl\n${equation} = ${rpn(equation)}\`\`\``);
  }
};<commit_msg>Added variables to rpn command<commit_after>function rpn(input) {
  var ar = input.split(/\s+/), st = [], token, result;
  while(token = ar.shift()) { 
    if (token == +token) { // numeric
      st.push(token);
    } else {
      switch(token) {
        case '+':
        case '-':
        case '*':
        case '/': {
          let n2 = st.pop(), n1 = st.pop();
          result = eval(n1 + token + ' ' + n2);
          break;
        }
        case '^': {
          let n2 = st.pop(), n1 = st.pop();
          result = Math.pow(n1, n2);
          break;
        }
        case 'ln': {
          let n1 = st.pop();
          result = Math.log(n1);
          break;
        }
        case 'log': {
          let n2 = st.pop(), n1 = st.pop();
          result = Math.log(n2) / Math.log(n1);
          break;
        }
      }

      st.push(result);
    }
  }
  return st.pop();
}

module.exports = {
  help: {
    name: 'rpn',
    desc: 'Evaluates an equation written in rpn format',
    usage: '<equation>',
    aliases: []
  },

  exec: (client, msg, params) => {
    let vars = {
      'e': Math.E,
      'pi': Math.PI
    };
    let lines = params.join(' ').split('\n');
    let equation = lines[lines.length-1];

    lines.slice(0, lines.length - 1).forEach(line => {
      let variable = line.replace(/ /g, '').split('=')[0];
      let value = parseInt(line.replace(' ', '').split('=')[1]);
      vars[variable] = value;
    });

    Object.keys(vars).forEach(variable => {
      equation = equation.replace(variable, vars[variable]);
    });

    console.log(equation);

    msg.editCode('xl', `${lines.join('\n')} = ${rpn(equation)}`);
  }
};
{'fraction_non_alphanumeric': 0.20277169948942378, 'fraction_numerical': 0.010576221735959153, 'mean_word_length': 1.7131552917903066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2077352', 'n_tokens_mistral': 965, 'n_tokens_neox': 950, 'n_words': 202}