Exemple #1
0
 def define(self, symbol, value):
   if types.is_symbol(symbol):
     symbol = symbol.value
   self.lock.acquire()
   self[symbol] = value
   self.lock.release()
   return value
Exemple #2
0
def test_integration(rt, form):
  try:
    if types.is_list(form) and types.is_symbol(form.car) and form.car.value == "is":
      result = rt.execute(rt.ns, form)
      assert types.true == result, "\nIn file %s:\nIn form:\n  %s\n\n%s" % (rt.__test_filename__, repr(form), pprint_assert(rt, form))
    else:
      rt.execute(rt.ns, form)
  except LispException as e:
    pytest.fail("\nIn file %s:\nIn form:\n  %s\n\nException: %s" % (rt.__test_filename__, repr(form), e))
Exemple #3
0
  def macro(self, scope, args):
    sig = list(args[0])
    body = types.mklist(args[1])

    for arg in sig:
      if not types.is_symbol(arg):
        raise LispException("argument 1 of lambda must be a list of symbols, found %s" % types.type_name(arg))

    return types.mkmacro(sig, body, scope)
Exemple #4
0
 def eval(self, scope, exp):
   """
   If exp is a list, execute it as a function call.
   If exp is a symbol, resolve it.
   Else, return it as is.
   """
   if types.is_list(exp) and not types.is_nil(exp):
     return self.execute(scope, exp)
   elif types.is_symbol(exp):
     return self.lookup(scope, exp)
   else:
     return exp
Exemple #5
0
  def _unquote(self, scope, sexp):
    if types.is_list(sexp) and not types.is_nil(sexp):
      if types.is_symbol(sexp.car) and sexp.car.value == "unquote":
        return self.rt.eval(scope, sexp.cdr.car)

      out = types.nil
      for el in sexp:
        if is_splice(el):
          for splice in self.rt.eval(scope, el.cdr.car):
            out = types.conj(out, splice)
        else:
          out = types.conj(out, self._unquote(scope, el))
      return out
    else:
      return sexp
Exemple #6
0
def is_splice(sexp):
  return (not types.is_nil(sexp)) and types.is_list(sexp) and types.is_symbol(sexp.car) and sexp.car.value == "unquote-splice"