 patternCompile = (ctx, pattern, matched, polymorphic) ->
   # caching can occur while compiling the pattern
   # precs are {cond}s and {cache}s, sorted in order they need to be executed
+  console.log (print pattern)
   {precs, assigns} = expressionCompile ctx, pattern
 
   definedNames = ctx.definedNames()

scopedName = (name, scopeIndex) ->
  "#{name}_#{scopeIndex}"

constPattern = (ctx, symbol) ->
  exp = ctx.assignTo()
  precs: [(cond_ switch symbol
      when 'True' then exp
      when 'False' then (jsUnary "!", exp)
      else
        (jsBinary "instanceof", exp, (validIdentifier symbol)))]

nameTranslate = (ctx, atom, symbol, type) ->
  id = ctx.declarationId symbol

    translation: malformed ctx, atom, 'Macros cannot be referenced'
  else
    validSymbol = validIdentifier symbol
    # TODO: we probably need to defer anyway, because the top level might not be
    #       typed yet when we expand a macro referencing it
    #    more generally we should probably just combine this with nameCompile
    type = mapOrigin (freshInstance ctx, (ctx.typeInTopScope symbol)), atom
    fromCurrentModule = atom.builtInDefinition or
      (modulePathsEqual atom.modulePath, ctx.typedModulePath.names)
    if fromCurrentModule
      if ctx.assignTo()
        if isConst atom
          type: type
          pattern: constPattern ctx, symbol, (jsAccess '_', validSymbol)
        else
          malformed atom, 'Cannot use a quoted reference as a new name'
          pattern: []
      else
        type: type
        translation: (jsAccess '_', validSymbol)
    else
      # TODO: access from other module
      throw "NOT SUPPORTED YET"

isQuotedReference = (atom) ->
  atom.builtin or atom.builtInDefinition or atom.modulePath
