Does what follows reveal a bug or am I misusing the awk macro?
Starting from the first awk example in 8.2.1 of the 0.6.2 reference
manual...
======================================================================
#!/usr/local/bin/scsh \
-s
!#
;;; ~/scsh/awk1.scm
(define $ list-ref)
;;; print the name and home-directory of everyone in /etc/passwd
(let ((read-passwd (field-reader (infix-splitter ":" 7))))
(call-with-input-file "/etc/passwd"
(lambda (port)
(awk (read-passwd port) (record fields) ()
(#t (format #t "~a's home directory is ~a~%"
($ fields 0)
($ fields 5)))))))
======================================================================
sge:/home/sge/scsh:11$ ./awk1.scm
root's home directory is /root
daemon's home directory is /root
operator's home directory is /operator
bin's home directory is /
smmsp's home directory is /nonexistent
popa3d's home directory is /var/empty
sshd's home directory is /var/empty
uucp's home directory is /var/spool/uucppublic
www's home directory is /var/www
named's home directory is /var/named
proxy's home directory is /nonexistent
nobody's home directory is /nonexistent
sge's home directory is /home/sge
sge:/home/sge/scsh:12$
======================================================================
Now wrap it in -e ...
======================================================================
#!/usr/local/bin/scsh \
-e go -s
!#
;;; ~/scsh/awk2.scm
(define $ list-ref)
;;; print the name and home-directory of everyone in /etc/passwd
(define (go _)
(let ((read-passwd (field-reader (infix-splitter ":" 7))))
(call-with-input-file "/etc/passwd"
(lambda (port)
(awk (read-passwd port) (record fields) ()
(#t (format #t "~a's home directory is ~a~%"
($ fields 0)
($ fields 5))))))))
======================================================================
sge:/home/sge/scsh:12$ ./awk2.scm
./awk2.scm
root's home directory is /root
daemon's home directory is /root
operator's home directory is /operator
bin's home directory is /
smmsp's home directory is /nonexistent
popa3d's home directory is /var/empty
sshd's home directory is /var/empty
uucp's home d
Error: returning zero values when one is expected
(values)
irectory is /var/spool/uucppublic
www's home directory is /var/www
named's home directory is /var/named
proxy's home directory is /nonexistent
nobody's home directory is /nonexistent
sge's home directory is /home/sge
sge:/home/sge/scsh:13$
======================================================================
Other versions used force-output to make the error appear at the end.
Now put (zap '!) in <state-var-decls> ...
======================================================================
#!/usr/local/bin/scsh \
-e go -s
!#
;;; ~/scsh/awk3.scm
(define $ list-ref)
;;; print the name and home-directory of everyone in /etc/passwd
(define (go _)
(let ((read-passwd (field-reader (infix-splitter ":" 7))))
(call-with-input-file "/etc/passwd"
(lambda (port)
(awk (read-passwd port) (record fields) ((zap '!))
(#t (format #t "~a's home directory is ~a~%"
($ fields 0)
($ fields 5))))))))
======================================================================
sge:/home/sge/scsh:13$ ./awk3.scm
root's home directory is /root
daemon's home directory is /root
operator's home directory is /operator
bin's home directory is /
smmsp's home directory is /nonexistent
popa3d's home directory is /var/empty
sshd's home directory is /var/empty
uucp's home directory is /var/spool/uucppublic
www's home directory is /var/www
named's home directory is /var/named
proxy's home directory is /nonexistent
nobody's home directory is /nonexistent
sge's home directory is /home/sge
sge:/home/sge/scsh:14$
======================================================================
Why does wrapping the expression in -e cause the error and why does
adding (zap '!) to <state-var-decls> fix/conceal it?
Thanks,
Steve
|