// Copyright (c) 1996-2002 Brian D. Carlstrom

package bdc.scheme.procedure;

import bdc.scheme.Stack;
import bdc.scheme.Scheme;
import bdc.scheme.SchemeException;
import bdc.scheme.exception.ArgumentTypeException;
import bdc.scheme.exception.BoundsException;
import bdc.scheme.expression.Procedure3;

/**
    (string-set&33; x y z)
*/
public class StringSet extends Procedure3
{
    public Object apply3 (Stack stack) throws SchemeException
    {
        Object o1 = stack.array[stack.inUse-1];
        Object o2 = stack.array[stack.inUse-2];
        Object o3 = stack.array[stack.inUse-3];
        if (!(o1 instanceof char[])) {
            throw new ArgumentTypeException(this, "char[]", o1);
        }
        char sb[] = (char[])o1;
        int size = sb.length;

        int k = Scheme.integer(o2, this);

        if ((k < 0) ||
            (k >= size))
            throw new BoundsException(o1, size, k);
        sb[k] = Scheme.character(o3, this);

        return Scheme.Unspecified;
    }
}
