I've been dabbling with scheme off and on for a while but I am just getting started with Gambit-C.
I am trying to read the output of a program printing information in the form of s-expressions. The problem is that it puts single quotes around strings.
eg.
(domain (domid 1) (on_crash restart) (image (linux (kernel /boot/vmlinuz-2.6.18-5-xen-amd64) (ramdisk /boot/initrd.img-2.6.18-5-xen-amd64) (args 'root=/dev/sda1 ro ') ... and so on
I have an mzscheme script that reads it by messing with the readtable; the code looks like:
; (mzscheme code) ; Read after redefining so that single quotes are handled like pipe quotes (define (read-data inport) (parameterize ((current-readtable (make-readtable #f #' #| #f))) (let ((domain (read inport))) (if (eof-object? domain) '() (cons domain (read-data inport))))))
The readtable stuff in gambit is different, obviously, so how would I go about tackling this problem? I've done some reading and trying different things but my scheme chops are weak and at this point I'm stumped.
Thanks for your help.
- Jamie
=============================== CONFIDENTIAL & PRIVILEGED COMMUNICATION
The information contained in this message is privileged, confidential, and protected from disclosure. This message is intended for the individual or entity addressed herein. If you are not the intended recipient,please do not read, copy, use or disclose this communication to others. Also please notify the sender by replying to this message, and then delete it from your system. The sender totally disclaims, and will not accept, any responsibility or liability for the unauthorized use, or the consequences of any unauthorized use, of this communication or message.
Afficher les réponses par date
On Thu, 2009-04-30 at 14:54 -0600, Briggs, Jamie wrote:
=============================== CONFIDENTIAL & PRIVILEGED COMMUNICATION
The information contained in this message is privileged, confidential, and protected from disclosure. This message is intended for the individual or entity addressed herein. If you are not the intended recipient,please do not read, copy, use or disclose this communication to others. Also please notify the sender by replying to this message, and then delete it from your system. The sender totally disclaims, and will not accept, any responsibility or liability for the unauthorized use, or the consequences of any unauthorized use, of this communication or message.
You know this is going to an archived, public mailing list, right? This makes no sense.
Brad
On 30-Apr-09, at 4:54 PM, Briggs, Jamie wrote:
The readtable stuff in gambit is different, obviously, so how would I go about tackling this problem? I've done some reading and trying different things but my scheme chops are weak and at this point I'm stumped.
You'll have to use some of the hidden readtable features. Attached is what you want.
Marc
(define (setup-special-readtable input-port) (let* ((original-rt (input-port-readtable input-port)) (rt (##readtable-copy original-rt))) (##readtable-char-class-set! rt #' #t ##read-escaped-string) (input-port-readtable-set! input-port rt)))
(define (process input-port) (setup-special-readtable input-port) (read input-port))
(define input " (domain (domid 1) (on_crash restart) (image (linux (kernel /boot/vmlinuz-2.6.18-5-xen-amd64) (ramdisk /boot/initrd.img-2.6.18-5-xen-amd64) (args 'root=/dev/sda1 ro ')))) ")
(pp (call-with-input-string input process))
;; When this program is run the output is:
#; (domain (domid 1) (on_crash restart) (image (linux (kernel /boot/vmlinuz-2.6.18-5-xen-amd64) (ramdisk /boot/initrd.img-2.6.18-5-xen-amd64) (args "root=/dev/sda1 ro "))))
You can also rely on your OS in some cases and make the easy choices :)
./s-expr-printer-program | sed -e "s/'/"/g" | ./scheme-reader
P!
2009/5/1 Marc Feeley feeley@iro.umontreal.ca:
On 30-Apr-09, at 4:54 PM, Briggs, Jamie wrote:
The readtable stuff in gambit is different, obviously, so how would I go about tackling this problem? I've done some reading and trying different things but my scheme chops are weak and at this point I'm stumped.
You'll have to use some of the hidden readtable features. Attached is what you want.
Marc