// macro-s.txt  macro expansion
//   public release som v3.1    19 Aug 2007 (Draft vote day)
//   public release som v4.0    2 July 2008

// return pointer to n-th ele of e
to pick e n =
    if e == NIL
        NIL
    else if n < 1
        NIL
    else if n == 1
        car e
    else
        pick (cdr e) (n-1)

// map atom with n-arg in e, e is the actual arg list
// sustitute get.local with n-th ele of e
to mapAtom a e =
    if (car a) != LNAME
        a
    else
        pick e cdr a	// n-arg of caller

// e1 is the body of macro def, e2 is the actual arg list
to subst e1 e2 =
    if e1 == NIL
        NIL
    else if isatom e1
        mapAtom e1 e2
    else if isatom car e1
        cons (mapAtom car e1 e2) (subst cdr e1 e2)
    else
        cons (subst car e1 e2) (subst cdr e1 e2)

//  I decide to discard a full macro from the language
//  26 Aug 2007

// End


