Changeset 4052


Ignore:
Timestamp:
09/25/03 16:33:18 (20 years ago)
Author:
piso
Message:

%WRITE-STRING, %WRITE-NEWLINE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/Primitives.java

    r4050 r4052  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: Primitives.java,v 1.437 2003-09-25 15:36:14 piso Exp $
     5 * $Id: Primitives.java,v 1.438 2003-09-25 16:33:18 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    34403440    };
    34413441
    3442     // ### write-string
    3443     // write-string string &optional output-stream &key start end => string
    3444     private static final Primitive WRITE_STRING =
    3445         new Primitive("write-string") {
     3442    // ### %write-string
     3443    // write-string string output-stream start end => string
     3444    private static final Primitive _WRITE_STRING =
     3445        new Primitive("%write-string", PACKAGE_SYS, false)
     3446    {
    34463447        public LispObject execute(LispObject[] args) throws ConditionThrowable
    34473448        {
    3448             if (args.length == 0)
    3449                 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this));
    3450             LispString string = checkString(args[0]);
     3449            if (args.length != 4)
     3450                throw new ConditionThrowable(new WrongNumberOfArgumentsException(this));
     3451            String s = LispString.getValue(args[0]);
    34513452            CharacterOutputStream out = null;
    34523453            if (args.length == 1)
     
    34543455            else {
    34553456                LispObject streamArg = args[1];
     3457                if (streamArg == T)
     3458                    streamArg = _TERMINAL_IO_.symbolValue();
     3459                else if (streamArg == NIL)
     3460                    streamArg = _STANDARD_OUTPUT_.symbolValue();
    34563461                if (streamArg instanceof CharacterOutputStream)
    34573462                    out = (CharacterOutputStream) streamArg;
    3458                 else if (streamArg == T || streamArg == NIL)
    3459                     out = getStandardOutput();
     3463                else if (streamArg instanceof TwoWayStream)
     3464                    out = ((TwoWayStream)streamArg).getOutputStream();
    34603465                else
    3461                     throw new ConditionThrowable(new TypeError(args[1],
    3462                                                                "character output stream"));
    3463             }
    3464             out.writeString(string);
    3465             return string;
     3466                    throw new ConditionThrowable(new TypeError(args[1], "character output stream"));
     3467            }
     3468            int start = Fixnum.getValue(args[2]);
     3469            int end = Fixnum.getValue(args[3]);
     3470            out.writeString(s.substring(start, end));
     3471            return args[0];
     3472        }
     3473    };
     3474
     3475    // ### %write-newline
     3476    // write-string string output-stream start end => string
     3477    private static final Primitive1 _WRITE_NEWLINE =
     3478        new Primitive1("%write-newline", PACKAGE_SYS, false)
     3479    {
     3480        public LispObject execute(LispObject arg) throws ConditionThrowable
     3481        {
     3482            LispObject streamArg = arg;
     3483            if (streamArg == T)
     3484                streamArg = _TERMINAL_IO_.symbolValue();
     3485            else if (streamArg == NIL)
     3486                streamArg = _STANDARD_OUTPUT_.symbolValue();
     3487            final CharacterOutputStream out;
     3488            if (streamArg instanceof CharacterOutputStream)
     3489                out = (CharacterOutputStream) streamArg;
     3490            else if (streamArg instanceof TwoWayStream)
     3491                out = ((TwoWayStream)streamArg).getOutputStream();
     3492            else
     3493                throw new ConditionThrowable(new TypeError(streamArg, "character output stream"));
     3494            out.writeString(System.getProperty("line.separator"));
     3495            return NIL;
    34663496        }
    34673497    };
     
    35063536                out = ((TwoWayStream)streamArg).getOutputStream();
    35073537            else
    3508                 throw new ConditionThrowable(new TypeError(args[1], "character output stream"));
     3538                throw new ConditionThrowable(new TypeError(args[0], "character output stream"));
    35093539        }
    35103540        out.flushOutput();
Note: See TracChangeset for help on using the changeset viewer.