# Path: joy/parser.py
# def text_to_expression(text):
#   '''
#   Convert a text to a Joy expression.
#   '''
#   return _parse(_tokenize(text))
# 
# class Symbol(str):
#   __repr__ = str.__str__
# 
# Path: joy/utils/stack.py
# def list_to_stack(el, stack=()):
#   '''Convert a list (or other sequence) to a stack.
# 
#   [1, 2, 3] -> (1, (2, (3, ())))
# 
#   '''
#   for item in reversed(el):
#     stack = item, stack
#   return stack
# 
# def iter_stack(stack):
#   '''Iterate through the items on the stack.'''
#   while stack:
#     item, stack = stack
#     yield item
# 
# def pick(s, n):
#   '''
#   Find the nth item on the stack. (Pick with zero is the same as "dup".)
#   '''
#   if n < 0:
#     raise ValueError
#   while True:
#     try:
#       item, s = s
#     except ValueError:
#       raise IndexError
#     n -= 1
#     if n < 0:
#       break
#   return item
# 
# def pushback(quote, expression):
#   '''Concatinate quote onto expression.
# 
#   In joy [1 2] [3 4] would become [1 2 3 4].
#   '''
#   return list_to_stack(list(iter_stack(quote)), expression)


from inspect import getdoc
from .parser import text_to_expression, Symbol
from .utils.stack import list_to_stack, iter_stack, pick, pushback
import operator, math
  (quote, (x, stack)) = stack
  expression = (x, expression)
  return stack, pushback(quote, expression), dictionary


def dipd(S, expression, dictionary):
  '''
  Like dip but expects two items.

     ... y x [Q] dip
  ---------------------
       ... Q y x

  '''
  (quote, (x, (y, stack))) = S
  expression = (y, (x, expression))
  return stack, pushback(quote, expression), dictionary


def dipdd(S, expression, dictionary):
  '''
  Like dip but expects three items.

     ... z y x [Q] dip
  -----------------------
       ... Q z y x

  '''
  (quote, (x, (y, (z, stack)))) = S
  expression = (z, (y, (x, expression)))

# Path: joy/parser.py
# def text_to_expression(text):
#   '''
#   Convert a text to a Joy expression.
#   '''
#   return _parse(_tokenize(text))
# 
# class Symbol(str):
#   __repr__ = str.__str__
# 
# Path: joy/utils/stack.py
# def list_to_stack(el, stack=()):
#   '''Convert a list (or other sequence) to a stack.
# 
#   [1, 2, 3] -> (1, (2, (3, ())))
# 
#   '''
#   for item in reversed(el):
#     stack = item, stack
#   return stack
# 
# def iter_stack(stack):
#   '''Iterate through the items on the stack.'''
#   while stack:
#     item, stack = stack
#     yield item
# 
# def pick(s, n):
#   '''
#   Find the nth item on the stack. (Pick with zero is the same as "dup".)
#   '''
#   if n < 0:
#     raise ValueError
#   while True:
#     try:
#       item, s = s
#     except ValueError:
#       raise IndexError
#     n -= 1
#     if n < 0:
#       break
#   return item
# 
# def pushback(quote, expression):
#   '''Concatinate quote onto expression.
# 
#   In joy [1 2] [3 4] would become [1 2 3 4].
#   '''
#   return list_to_stack(list(iter_stack(quote)), expression)


# Path: joy/library.py
from inspect import getdoc
from .parser import text_to_expression, Symbol
from .utils.stack import list_to_stack, iter_stack, pick, pushback
import operator, math

  (quote, (x, stack)) = stack
  expression = (x, expression)
  return stack, pushback(quote, expression), dictionary


def dipd(S, expression, dictionary):
  '''
  Like dip but expects two items.

     ... y x [Q] dip
  ---------------------
       ... Q y x

  '''
  (quote, (x, (y, stack))) = S
  expression = (y, (x, expression))
  return stack, pushback(quote, expression), dictionary


def dipdd(S, expression, dictionary):
  '''
  Like dip but expects three items.

     ... z y x [Q] dip
  -----------------------
       ... Q z y x

  '''
  (quote, (x, (y, (z, stack)))) = S
  expression = (z, (y, (x, expression)))

  return stack, pushback(quote, expression), dictionary