[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

RE: gEDA-user: spice-sdb connection order confusion[Scanned]



> -----Original Message-----
> From: owner-geda-user@xxxxxxxx 
> [mailto:owner-geda-user@xxxxxxxx] On Behalf Of Stuart Brorson
> Sent: 27 December 2005 15:54
> To: geda-user@xxxxxxxx
> Subject: Re: gEDA-user: spice-sdb connection order confusion[Scanned]
>
> [1]  Does Scheme even have an "assert" function?  Does guile? 
>  Anyway, a functional language like Scheme doesn't easily 
> support a step-by-step method of solving a problem.  
> Therefore, doing something like this:
> 
> 1.  Make sanity check 1.
> 2.  Make sanity check 2.
> 3.  Make sanity check 3.
> 4.  Do work.

Although Scheme is a functional language don't try to write all code
using functions for absolutely everything, it's confusing for many
purposes.  Use it when you need it.

You can do the above it like you would in most languages:

(define (foo arg1 arg2 arg3 arg4) ;; Untested code, I program lisp
normally, not scheme
       (begin
         (and (eq? arg1 0) (error "arg1 cannot be zero in foo" arg1))
         (and (eqv? arg2 arg3) (error "arg2 cannot equal arg3 in foo"
arg2 arg3))
	   (and (not (string? arg4) (error "arg4 must be a string in
foo" arg4)))
	   (rest-of-the-code)))

"error" is like perror, it's a pseudo-standard scheme function from
SRFI-23.  It's available in most schemes, but maybe not in Guile.  If
not, SRFI-23 gives a way to write it in normal R5RS scheme in about 10
lines you could use. See  http://srfi.schemers.org/srfi-23/srfi-23.html

> which is trivial in a procedural language like C is a real 
> PITA in Scheme.  And counting all those parens would be a nightmare!

Don't count parens in Scheme, you will go mad very quickly.  Treat them
mostly like {} in C and use indentation as the guide.  If for example
you have a function like this (which is the one I mentioned for "error"
above):

(define (error reason . args)
      (display "Error: ")
      (display reason)
      (for-each (lambda (arg)
                  (display " ")
                  (write arg))
                args)
      (newline)
      (scheme-report-environment -1))

Don't count the parens to find out where you are in the function, just
look at where the you are in the indentation.  Counting the parens is
only really useful to see where you are within a particular line.
If the indentation is wrong, then mark the area and get your editor to
reindent it.