unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: prj@po.cwru.edu (Paul Jarc)
Cc: guile-user@gnu.org
Subject: Re: extending FEM enginering package with Guile
Date: Mon, 05 Jan 2004 15:26:09 -0500	[thread overview]
Message-ID: <m3k7465eh4.fsf@multivac.cwru.edu> (raw)
In-Reply-To: <200401051920.i05JKHsC023665@minerva.ceride.gov.ar>

Mario Storti <mstorti@intec.unl.edu.ar> wrote:
> the lack of `break' and `continue' in Scheme.

Guile has break and continue (undocumented in the 1.6.4 manual ), but
they are only defined inside the body of the while loop, not at the
top level.  (Well, there is a break procedure from srfi-1, but that
does something different.)

continue seems to be buggy in 1.6.4:
guile> (define x 1)
guile> (while (< x 5)
...      (format #t "x1=~A\n" x)
...      (if (= x 3)
...        (begin
...          (set! x 9)
...          (continue)
...          (format #t "x2=~A\n" x)))
...      (set! x (1+ x)))
x1=1
x1=2
x1=3
x2=9
#t
guile> (format #t "x=~A\n" x)
x=10

But it's fixed in 1.7 CVS.

> Question 2: I have learned that in Scheme it is considered bad
> practice to `set!' variables, or in general to use side-effects. In
> our applications we manipulate huge structures (mainly vectors, sparse
> matrices, graphs, with sizes in the order of several hundredths MBs,
> and running for weeks), and it seems much more efficient to code this way
> (using side-effects). Am I right?

Side effects are discouraged by functional programmers because lots of
bugs are the result of modifying (by side-effect) the wrong object by
mistake.  (Of course, these bugs are not totally eliminated by
avoiding side effects: essentially the same thing can happen by
shadowing an existing binding, with "define" at the top level, or in
let*.)  Well-written functional code may also be easier to read and
understand than procedural code, which also helps to eliminate bugs.

To see which way is more efficient, profile the code both ways.  If
performance matters, and if side-effect code is found to be faster,
and if you're willing to put as much effort into debugging your
side-effect-using Scheme code that you would have to put into
debugging your side-effect-using C code, then go ahead and use side
effects.


paul


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


  reply	other threads:[~2004-01-05 20:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-05 19:20 extending FEM enginering package with Guile Mario Storti
2004-01-05 20:26 ` Paul Jarc [this message]
2004-01-05 21:32 ` Ken Anderson
2004-01-05 22:04 ` rm
2004-01-08  4:58 ` Keith Wright
2004-01-08  6:04   ` Paul Jarc
2004-01-08 22:13     ` Keith Wright
2004-01-09 21:31     ` Keith Wright
  -- strict thread matches above, loose matches on Subject: below --
2004-01-06 19:35 Mario Storti
2004-01-06 22:31 ` Kevin Ryde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3k7465eh4.fsf@multivac.cwru.edu \
    --to=prj@po.cwru.edu \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).