This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: why undefined return values?


> > I'm not aware of the precise reasoning, but it seems to me that the
> > idea of the language construct (set! VAR VAL) is to alter the value of
> > VAR.  It doesn't seem to be a good idea to add further functionality
> > to this construct since that mixes concepts.

This is what I had expected to find a flamefest about somewhere.
I have lots of

      (let (eof match str)
       (if
	(and 
           (not (setq eof (eof))
           (setq match (find-match regexp))
           (setq str (car match)) 
          )
         ...
        )

type constructs in my programs and it seems quite unnatural to unmix the
two concepts, just as it would be to unmix the 3 functions of `let':
(1) bind variables, (2) evaluate a body and (3) return a value.

> quite.  but if you still *want* to have setq, that's very easy:

 
> (defmacro setq (var val)
>   (let ((tname (gensym)))
>     `(let ((,tname ,val))
>        (set! ,var ,tname)
>        ,tname)))

Both Guile and Scsh return an error message upon evalling this one.
 
> (use-syntax (ice-9 syncase))
> 
> (define-syntax setq
>   (syntax-rules ()
>     ((setq var val)
>      (let ((tmp val))
>        (set! var tmp)
>        tmp))))

This one works in Guile, but not in Scsh, because it seems to depend on a
special package.

Wouldn't it have been easier to define

	(define set! (lambda (var val) (set var val) #f))

This btw also shows that not only setq is more basic than set!, but
set is the most basic of all.

Sorry to have brought up this debate.

Attached you find a scsh script I wrote today, which led me to these
thoughts. It discovers the coding-system of a file, if this is specified
according to the Emacs file variables convention.

Would it be meaningful to attempt this kind of thing in Guile?

--
phm
#!/usr/local/bin/scsh -s
!#
; find out the coding of a textfile that observes the Emacs File Variables convention
; (see the chapter on 'file variables' in the Emacs Info manual)

(define displine (lambda (str) (display (string-append str (string #\newline)))))
(define fatal (lambda (err str) (displine str) (exit err)))

(and (null? command-line-arguments) (fatal 5 "need 1 argument"))

(define file (car command-line-arguments))

(or (file-readable? file) (fatal 4 "no such file"))

(define textfile? (lambda (f) (regexp-search (rx "text") (run/string (file ,f)))))

(or (textfile? file) (fatal 3 "not even a text file"))

(define size (file-size file))

(define codingre (rx (: bow "coding: " (submatch (** 0 10 (| alphanum "-"))) eow)))

(define port (open-input-file file))
(define match #f)

(define headgetcoding 
  (lambda () (let ((line (read-line port)))
    (set! match (regexp-search (rx (: "-*- " (submatch (+ any)) " -*-")) line))
    (and match   
	 (set! match (regexp-search codingre line) (match:substring match 1)))
    match)))

(define eofsearch 
  (lambda (re) 
    (let loop ((line (read-line port)))
      (cond
       ((not (string? line)) #f)
       ((begin (set! match (regexp-search re line)) match) #t)
       (else (loop (read-line port)))
       ) ) ) )

(define tailgetcoding 
  (lambda ()
    (seek port (max 0 (- size 800)))
    (and (eofsearch (rx "Local Variables:")) (eofsearch codingre))
    ) )

(if (or (headgetcoding) (tailgetcoding)) 
  (displine (match:substring match 1))
  (displine "no coding found") 
)

(close port)

(exit (if match 0 1))

; Local Variables:
; coding: utf-8
; mode: scheme
; End:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]