   if (LastPrint != '\n') pfun('\n');
 }
 
+void plist (object *form, pfun_t pfun) {
+  pfun('(');
+  printobject(car(form), pfun);
+  form = cdr(form);
+  while (form != NULL && listp(form)) {
+    pfun(' ');
+    printobject(car(form), pfun);
+    form = cdr(form);
+  }
+  if (form != NULL) {
+    pfstring(PSTR(" . "), pfun);
+    printobject(form, pfun);
+  }
+  pfun(')');
+}
+
+void pstream (object *form, pfun_t pfun) {
+  pfun('<');
+  pfstring(streamname[(form->integer)>>8], pfun);
+  pfstring(PSTR("-stream "), pfun);
+  pint(form->integer & 0xFF, pfun);
+  pfun('>');
+}
+
 void printobject (object *form, pfun_t pfun) {
   if (form == NULL) pfstring(PSTR("nil"), pfun);
   else if (listp(form) && issymbol(car(form), CLOSURE)) pfstring(PSTR("<closure>"), pfun);
-  else if (listp(form)) {
-    pfun('(');
-    printobject(car(form), pfun);
-    form = cdr(form);
-    while (form != NULL && listp(form)) {
-      pfun(' ');
-      printobject(car(form), pfun);
-      form = cdr(form);
-    }
-    if (form != NULL) {
-      pfstring(PSTR(" . "), pfun);
-      printobject(form, pfun);
-    }
-    pfun(')');
-  } else if (integerp(form)) pint(form->integer, pfun);
+  else if (listp(form)) plist(form, pfun);
+  else if (integerp(form)) pint(form->integer, pfun);
   else if (symbolp(form)) { if (form->name != NOTHING) pstring(symbolname(form->name), pfun); }
   else if (characterp(form)) pcharacter(form->chars, pfun);
   else if (stringp(form)) printstring(form, pfun);
-  else if (streamp(form)) {
-    pfun('<');
-    if ((form->integer)>>8 == SPISTREAM) pfstring(PSTR("spi"), pfun);
-    else if ((form->integer)>>8 == I2CSTREAM) pfstring(PSTR("i2c"), pfun);
-    else if ((form->integer)>>8 == SDSTREAM) pfstring(PSTR("sd"), pfun);
-    else pfstring(PSTR("serial"), pfun);
-    pfstring(PSTR("-stream "), pfun);
-    pint(form->integer & 0xFF, pfun);
-    pfun('>');
-  } else
-    error2(0, PSTR("Error in print"));
+  else if (streamp(form)) pstream(form, pfun);
+  else error2(0, PSTR("Error in print"));
 }
 
 void prin1object (object *form, pfun_t pfun) {

  int len = stringlength(formatstr);
  uint8_t n = 0, width = 0, w, bra = 0;
  char pad = ' ';
  bool tilde = false, comma, quote;
  while (n < len) {
    char ch = nthchar(formatstr, n);
    char ch2 = ch & ~0x20; // force to upper case
    if (tilde) {
      if (comma && quote) { pad = ch; comma = false, quote = false; }
      else if (ch == '\'') {
        if (comma) quote = true; 
        else formaterr(formatstr, PSTR("quote not valid"), n);
      }
      else if (ch == '~') { pfun('~'); tilde = false; }
      else if (ch >= '0' && ch <= '9') width = width*10 + ch - '0';
      else if (ch == ',') comma = true;
      else if (ch == '%') { pln(pfun); tilde = false; }
      else if (ch == '&') { pfl(pfun); tilde = false; }
      else if (ch == '{') {
        if (save != NULL) formaterr(formatstr, PSTR("can't nest ~{"), n);
        if (args == NULL) formaterr(formatstr, noargument, n);
        if (!listp(first(args))) formaterr(formatstr, notalist, n);
        save = args; args = first(args); bra = n; tilde = false;
      }
      else if (ch == '}') {
        if (save == NULL) formaterr(formatstr, PSTR("no matching ~{"), n);
        if (args == NULL) { args = cdr(save); save = NULL; } else n = bra; 
        tilde = false;
      }
      else if (ch2 == 'A' || ch2 == 'S' || ch2 == 'D' || ch2 == 'G' || ch2 == 'X') {
        if (args == NULL) formaterr(formatstr, noargument, n);
        object *arg = first(args); args = cdr(args);
        uint8_t aw = atomwidth(arg);
        if (width < aw) w = 0; else w = width-aw;
        tilde = false;
        if (ch2 == 'A') { prin1object(arg, pfun); indent(w, pad, pfun); }
        else if (ch2 == 'S') { printobject(arg, pfun); indent(w, pad, pfun); }
        else if (ch2 == 'D' || ch2 == 'G') { indent(w, pad, pfun); prin1object(arg, pfun); }
        else if (ch2 == 'X' && integerp(arg)) {
          uint8_t hw = hexwidth(arg); if (width < hw) w = 0; else w = width-hw;
          indent(w, pad, pfun); pinthex(arg->integer, pfun);
        } else if (ch2 == 'X') { indent(w, pad, pfun); prin1object(arg, pfun); }
        tilde = false;
      } else formaterr(formatstr, PSTR("invalid directive"), n);
    } else {
      if (ch == '~') { tilde = true; pad = ' '; width = 0; comma = false; quote = false; }
      else pfun(ch);
    }
    n++;
  }


void checkanalogwrite (int pin) {
#if defined(__AVR_ATmega328P__)
  if (!((pin>=2 && pin<=13) || pin==4 || pin==7 || pin==8)) error(ANALOGWRITE, invalidpin, number(pin));
#elif defined(__AVR_ATmega2560__)
  if (!((pin>=2 && pin<=13) || (pin>=44 && pin<=46))) error(ANALOGWRITE, invalidpin, number(pin));
#elif defined(__AVR_ATmega1284P__)
  if (!(pin==3 || pin==4 || pin==6 || pin==7 || (pin>=12 && pin<=15))) error(ANALOGWRITE, invalidpin, number(pin));
#elif defined(ARDUINO_AVR_NANO_EVERY)
