[plt-scheme] signed unit syntax
Ahem!
Actually the code below doesn't work - still had my previously evaluated
working version invoked with define-value/invoke-unit/sig available in
the REPL that was being called:
; (define compound@
; (compound-unit/sig
; (import)
; (link
; (COMP : c^ (sqrt-sum-squares@))
; (OUT : o^ (simple-output@)))
; (export (open COMP) (open OUT))))
;
;
; (define-signature compound^ ((open c^) (open o^)))
;
;
; (define-values/invoke-unit/sig compound^ compound@)
Give me another few minutes to get it right, or hopefully a units expert
will answer...
Apologies PLT-ers.
Stephen
Stephen Tetley wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Hello David
>
> I believe you just need the expression inside the old friend the begin
> form then the compound-unit gets invoked before its called:
>
> (define output-sqrt-sum-squares
> (lambda (x y)
> (begin
> (invoke-unit/sig
> (compound-unit/sig
> (import)
> (link
> (COMP : c^ (sqrt-sum-squares@))
> (OUT : o^ (simple-output@)))
> (export (open COMP) (open OUT))))
> (output (computation x y)))))
>
> Presume you mean to call computation rather than distance as well :-)
> Then at the prompt you can call the function:
>
> > (output-sqrt-sum-squares 3 4)
> value = 25
> >
>
>
> Best wishes
>
> Stephen Tetley
>
> 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)
>>
>>
>>
>>
>>
>
>
>