   ].join '\n'
 
 compileWhereImpl = (wheres) ->
-  "#{wheres.map(compileDef).reverse().join '\n'}"
-
-getToken = (word) -> word.token
-
-compileFn = (ast) ->
-  typedMacro 'function', ast, (node) ->
-    {params, body, wheres} = fnDefinition node
-    """$curry(function (#{params.map(getToken).map(validIdentifier).join ', '}) {
-         #{compileFnImpl body, wheres, yes}
-       })"""
+  "#{wheres.map(compileDef).join '\n'}"
+
+compileDef = ([name, def]) ->
+  pm = patternMatch(name, compileImpl def)
+  pm.precs.filter(({cache}) -> cache).map(({cache}) -> cache)
+  .concat(pm.assigns).map(compileAssign).join '\n'
+
+newVar = ->
+  "i#{variableCounter++}"
 
 repeat = (x, n) ->
   new Array(n + 1).join x

trueMacros =
  'match': (onwhat, cases...) ->
    varNames = []
    exp = compileImpl onwhat
    compiledCases = (for [pattern, result], i in pairs cases
      control = if i is 0 then 'if' else ' else if'

syntaxedExp = (source) ->
  collapse inside toHtml typify astize tokenize source

tokenizedDefinitions = (source) ->
  toTokens [inside typifyDefinitions astize tokenize "(#{source})"]

variableCounter = 1

# exp followed by list of definitions
