Arc Forumnew | comments | leaders | submitlogin
prn drops quotes on string?
3 points by kens 6277 days ago | 5 comments
I'm printing out a list with prn, but quotes around strings get dropped. This is a problem because I want to sread the list back in.

  arc> (prn (list 'a 2 "c"))
  (a 2 c)   ; This is the printed output from prn
  (a 2 "c") ; This is the REPL's view of the list
Is this a bug in prn (disp)? I guess you want (prn "Hello") to drop the quotes. But is there a way to print out the list the same way the REPL does, with quotes preserved?


3 points by parenthesis 6277 days ago | link

Here's a quick hack for what you want:

Put this in ac.scm:

  (xdef 'print (lambda args
                 (if (pair? args)
                     (print (ac-denil (car args)) 
                              (if (pair? (cdr args)) 
                                  (cadr args)
                                  (current-output-port))))
                 (flush-output)
                 'nil))
And these in arc.arc:

  (def rpr args
    (map1 print args)
    (car args))

  (def rprn args
    (do1 (apply rpr args)
         (writec #\newline
                 (if (isa (car args) 'output) (car args) (stdout)))))
Then:

  > (rprn (list 'a 2 "c"))
  (a 2 "c") ; prints this
  (a 2 "c") ; returns this
Edit: The above are just very slightly modified versions of the code used to implement pr and prn, the difference is that Scheme's print is used instead of display, to give READable output.

-----

3 points by pg 6277 days ago | link

As offby1 pointed out (http://arclanguage.org/item?id=1997) there is already a fn for this: write.

-----

6 points by offby1 6277 days ago | link

why not just use "write"?

-----

1 point by kens 6276 days ago | link

Thanks; I didn't see "write".

A couple more problems:

  arc> (= x (thread (fn () nil)))
  #<thread>
  arc> (prn x)
  #<thread>Error: "Type: unknown type #<thread>"
  arc> (prn (exact 1))
  #tError: "Type: unknown type #t"
  
It looks like the Scheme types are leaking through, breaking things that use them, not just prn.

-----

1 point by kens 6276 days ago | link

One more output question:

  arc> (= x '`(a ,b ,@c))
  (quasiquote (a (unquote b) (unquote-splicing c)))
How can I print x in its original short form, rather than expanded out (as prn does)? Is there an easy function I'm missing, or do I need to write my own?

-----