Jeremy Collins <[EMAIL PROTECTED]> writes:

> I bet this is something that Rob would suggest we do in Scheme.

Yep.

> It sounds like Scheme would laugh at this kind of
> task.. hehe... BTW, I have been trying to learn scheme but it is not
> going to well yet... I'll get there.

Feel free to ask questions, even "dumb" ones.  Scheme can hide quite a
bit of sophistication behind seemingly ordinary things, and I've found
that sometimes that confuses people.  Unlike some other languages,
when the scheme standard says that "X does Y", it generally means that
in in the most general sense, no exceptions --- it'll work everywhere.
This can make ordinary constructs more powerful than they might at
first seem.  As a (very) trivial example:

  ((if should-be-increasing? + -) x y)

This calls + or - on x and y depending on the value of
should-be-increasing.  That's because the standard says that when
evaluating (a non-macro), you take the list, you evaluate all the
items in the list, then you call whatever the first item evaluates to
as a function with the rest of the items (whatever they evalutate to)
as the arguments.

Another trivial example: if you want to reduce a list of integers
using a function that takes the args in the opposite order of what you
expect, just whip up a trivial anonymous "swapper" function:

  (map (lambda (x y) (somefunc y x))
       list-of-x-values
       list-of-y-values)

Or to create some shared functions/variables that are only visible to
a subset of your code (i.e. "modules" (sort of)):

  (define public-func-a #f)  ;; Signature will be (public-func-a x y)
  (define public-func-b #f)  ;; ;; Signature (public-func-b x)

  (let ((shared-data '()))

    (define (func-a-implementation x y)
      ;; Use shared data somehow
      ...)

    (define (func-b-implementation z)
      ;; Use shared data somehow
      ...)

    (set! public-func-a func-a-implementation)
    (set! public-func-b func-b-implementation))

After this let, only the functions bound to public-func-a and
public-func-b are visible, but both of these functions can still
access and manipulate shared-data since they were created in the scope
of the relevant "let".  At this point you could use public-func-a and
public-func-b normally:

  (public-func-a val-1 val-2)
  (public-func-b val-3)

etc.

Anyway, I'd be happy to help if I can.

-- 
Rob Browning <[EMAIL PROTECTED]> PGP=E80E0D04F521A094 532B97F5D64E3930

--
Gnucash Developer's List 
To unsubscribe send empty email to: [EMAIL PROTECTED]

Reply via email to