[plt-scheme] signed unit syntax
I made two changes:
(define output-sqrt-sum-squares
(lambda (x y)
(invoke-unit/sig
(compound-unit/sig
(import)
(link
(COMP : c^ (sqrt-sum-squares@))
(OUT : o^ (simple-output@))
;; auxiliary unit
(DOIT : () [(unit/sig () (import c^ o^) (output (computation x
y))) COMP OUT]))
(export (open COMP) (open OUT))))))
1. When you invoke a unit, you run the linked network of unit bodies.
The result of the last expression is the result of this run; there are
no exports. So, I created an auxiliary unit that imports the exports of
the two units that you want to run and I placed your expression into
the body of this unit.
2. I changed "distance" to "computation" in this expression, because it
looks like this is what you want. I couldn't find a def for distance
anywhere.
-- Matthias
On Oct 27, 2004, at 3:12 PM, David J. Neu wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Hi all,
>
> I'm trying to get a handle around some of the syntax for signed units
> and have attached a simple toy example to show where I'm stuck.
>
> In the example, there are two units one that performs some simple
> computation and one that displays formatted output. I have a function
> called _output-sqrt-sum-squares_ which consumes the values to submit
> to the computation and tries to run the compuation and output the
> result.
>
> The error I'm getting is
>> reference to undefined identifier: output
> Clearly a lack of understanding on my part.
>
> Thanks in advance for any help!
>
> Cheers,
> David
>
>
> (require (lib "unitsig.ss"))
>
> (define-signature c^ (computation))
>
> (define-signature o^ (output))
>
> (define sqrt-sum-squares@
> (unit/sig c^
>
> (import)
>
> (define square
> (lambda (x) (* x x)))
>
> (define computation
> (lambda (x y)
> (+ (square x) (square y))))))
>
> (define simple-output@
> (unit/sig o^
>
> (import)
>
> (define output
> (lambda (v)
> (printf "value = ~a~n" v)))))
>
> (define output-sqrt-sum-squares
> (lambda (x y)
> (invoke-unit/sig
> (compound-unit/sig
> (import)
> (link
> (COMP : c^ (sqrt-sum-squares@))
> (OUT : o^ (simple-output@)))
> (export (open COMP) (open OUT))))
> (output (distance x y)))) ; *** I don't know how to make this
> procedure call ***
>
> (output-sqrt-sum-squares 2 4)