unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: Looping local binding
@ 2007-10-30 17:03 Marco Maggi
  2007-11-03 10:46 ` Dmitry Dzhus
  0 siblings, 1 reply; 7+ messages in thread
From: Marco Maggi @ 2007-10-30 17:03 UTC (permalink / raw)
  To: guile-user

(define-module (doit)
  #:use-module (ice-9 format)
  #:use-module (ice-9 getopt-long)
  #:use-module (ice-9 syncase))

(define-syntax let-numeric-options
  (syntax-rules ()
    ((_ ?options-list (?option ...) ?body ...)
     (let ((?option (string->number
		     (option-ref ?options-list
				 (quote ?option)
				 (number->string ?option))))
	   ...)
       ?body ...))))

(define-syntax print-option
  (syntax-rules ()
    ((_ ?option)
     (format #t "~A~/= ~A~%" (quote ?option) ?option))))

(define *grammar*
  '((method		(value #t))
    (right-bound	(value #t))
    (wave-number	(value #t))
    (subintervals	(value #t))
    (test-epsilon	(value #t))))

(define (test args)
  (let* ((options	(getopt-long args *grammar*))
	 (method	(option-ref options 'method "fundmatrix"))
	 (right-bound	1)
	 (wave-number	2)
	 (subintervals	3)
	 (test-epsilon	4)
	 (separator	(lambda ()
			  (display (make-string 30 #\-))
			  (newline))))
    (let-numeric-options options
      (right-bound wave-number subintervals test-epsilon)
      (separator)
      (print-option method)
      (print-option right-bound)
      (print-option wave-number)
      (print-option subintervals)
      (print-option test-epsilon)
      (separator))))

(test '("the-command"))
(test '("the-command" "--right-bound=123" "--subintervals=456"))
(test '("the-command" "--subintervals=456"
"--test-epsilon=123"))
(test '("the-command"
"--method=minkowsky-space-time-chess-opening"
	"--subintervals=456" "--test-epsilon=123"))

;; end of file

--
Marco Maggi

"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Looping local binding
@ 2007-10-29 16:28 Dmitry Dzhus
  2007-10-29 22:12 ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Dzhus @ 2007-10-29 16:28 UTC (permalink / raw)
  To: guile-user

Greetings! I've got the following lines in my code:

 (let* ((method (option-ref options 'method "fundmatrix"))
             ;; Command line options override ones in statement file
             (right-bound
              (string->number
               (option-ref options 'right-bound (number->string right-bound))))
             (wave-number
              (string->number
               (option-ref options 'wave-number (number->string wave-number))))
             (subintervals
              (string->number
               (option-ref options 'subintervals (number->string subintervals))))
             (test-epsilon
              (string->number
               (option-ref options 'test-epsilon  (number->string test-epsilon)))))
             <body follows .. >)

Looks like total mess, doesn't it?

Is there any way to rewrite this somehow, say using a loop over a list

      '(right-bound wave-number subintervals test-epsilon)

?

Desperately I tried to perform local binding using `(let (map ..`, but
obviously that couldn't work.
-- 
Happy Hacking.

Dmitry "Sphinx" Dzhus
http://sphinx.net.ru



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-11-03 18:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-30 17:03 Looping local binding Marco Maggi
2007-11-03 10:46 ` Dmitry Dzhus
2007-11-03 11:12   ` Neil Jerram
2007-11-03 18:33   ` Keith Wright
  -- strict thread matches above, loose matches on Subject: below --
2007-10-29 16:28 Dmitry Dzhus
2007-10-29 22:12 ` Neil Jerram
2007-11-03 10:46   ` Dmitry Dzhus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).