Re: [racket-users] function dispatch in typed racket

2019-10-14 Thread Sam Tobin-Hochstadt
Typed Racket won't generate type-dispatching code for you
automatically. However, if you write such code the same way you'd
write it in regular Racket, Typed Racket will be ok with that. For
example,

#lang typed/racket

(: id : (case-> (One One -> Number)
((Immutable-Vectorof One) (Immutable-Vectorof One) ->
(Vectorof Number

(define id (lambda (x y)
 (if (number? x)
 (+ x y)
 (for/vector : (Vectorof Number) ([i x] [j y]) (+ i j)

(id 1 1)
(id #(1 1) #(1 1))

On Mon, Oct 14, 2019 at 9:13 AM Raoul Schorer  wrote:
>
> Hi,
>
> I am trying to write an APL compiler (a typed J implementation) with a typed 
> racket backend. APLs have first-class functions that apply to both scalars 
> and arrays, so there are 2 cases for functions of 2 arguments:
>
> the array -- array case
> the scalar -- scalar case
>
> Scalar -- array and array -- scalar cases get their scalar argument lifted to 
> arrays, and are therefore equivalent to the array -- array case.
> Now, with an interpreter if I assign a function to an identifier, it can use 
> just textual replacement to evaluate the function glyph in the runtime 
> context (that's the way J does it). For example:
>
> id =: +  ;;assign the 'add' function to 'id'
>
> 1 id 1   ;;evaluate to '2' using the scalar context on replacement with 
> '+'
>
> 1 1 id 1 1;;evaluates to '2 2' using the array context on replacement 
> with '+'
>
>
> But at compile-time I can't use that trick, can I? So I end up with something 
> like:
> #lang typed/racket
>
> (define id (case-lambda
>  [([x : One] [y : One]) (+ y)]
>  [([x : (Immutable-Vectorof One)] [y : (Immutable-Vectorof One)]) 
> (for/vector ([i x] [j y]) (+ i j))]))
>
> (id 1 1)
> (id #(1 1) #(1 1))
>
> Which fails although the case-lambda is actually legal typed racket, because 
> the second clause is considered dead code and one cannot dispatch on type.
> In my (hobbyist) understanding, the solution seems to require multiple 
> dispatch? Or is there another way to do that in typed racket?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/63e5ec59-23f1-4fc7-8045-beb32409bbca%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2BYYYSUfnE2VVw-bhE45FZXpjNpJFTeXrJvfFOUMAumRNQ%40mail.gmail.com.


Re: [racket-users] I Need Help Bringing Vulkan to Racket

2019-10-14 Thread Sage Gerard
Thanks for the advice, Jay.

I installed dynamic-ffi and could not get the initial example to work, 
presumably due to my own error: 
https://github.com/dbenoit17/dynamic-ffi/issues/25

~slg

‐‐‐ Original Message ‐‐‐
On Wednesday, October 9, 2019 6:36 PM, Jay McCarthy  
wrote:

> Hi Sage,
>
> You should model your implementation of Stephan's RacketGL --- 
> https://github.com/stephanh42/RacketGL --- which parses the spec.
>
> If you also want to or need to capture parts of the headers, I recommend 
> David Benoit's dynamic-ffi --- https://github.com/dbenoit17/dynamic-ffi --- 
> for parsing them with Clang's library, rather than going with something home 
> grown.
>
> I am very interested in making mode-lambda work on Vulkan. I have a Windows 
> computer that I could test on.
>
> Jay
>
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
>
> On Thu, Oct 10, 2019 at 5:56 AM Sage Gerard  wrote:
>
>> I'm resuming work on a very early-stage project that generates FFI bindings 
>> for Vulkan in Racket [1]. VkTk is the closest relative project I have found 
>> for reference [2].
>>
>> Last time I was on the project I was focused on generating bindings from the 
>> API registry. That has not changed. I considered use of Dave Herman's C 
>> library [3] on vulkan.h directly, but the XML spec has supplemental data, 
>> and vulkan.h has preprocessor directives that I would like to capture for 
>> completeness.
>>
>> Once I am finished with the bindings. would anyone be available to 
>> contribute/run tests in the hopes that we can make this viable faster? I 
>> intend to run any applications on Windows 10 and a 1080Ti, but that's about 
>> all of the configurations that I can verify. I'll definitely need guinea 
>> pigs and feedback.
>>
>> [1]: https://github.com/zyrolasting/racket-vulkan
>> [2]: https://github.com/awolven/VkTk
>> [3]: https://docs.racket-lang.org/c-utils/index.html
>>
>> ~slg
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> [https://groups.google.com/d/msgid/racket-users/RsANZblSLyJViX1EDgDg-umCCJKCS6uYV84htPiRjjgAuW7G_3nx-fAOrLD7VMDqtEDkSKbm16jPyTWsAk1QyXCF8cz2CUi-mP04jrpmgn8%3D%40sagegerard.com](https://groups.google.com/d/msgid/racket-users/RsANZblSLyJViX1EDgDg-umCCJKCS6uYV84htPiRjjgAuW7G_3nx-fAOrLD7VMDqtEDkSKbm16jPyTWsAk1QyXCF8cz2CUi-mP04jrpmgn8%3D%40sagegerard.com?utm_medium=email&utm_source=footer).
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> [https://groups.google.com/d/msgid/racket-users/CAJYbDa%3DotA_tNaD1troPWF9XDoj_hg0dMKKpiR1xQV%2BKMip%2BHQ%40mail.gmail.com](https://groups.google.com/d/msgid/racket-users/CAJYbDa%3DotA_tNaD1troPWF9XDoj_hg0dMKKpiR1xQV%2BKMip%2BHQ%40mail.gmail.com?utm_medium=email&utm_source=footer).

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/eO91JW6_IYvYy30i5nyeKkHGg0Kgha4MVl96Kyek5fBsxydUdR9IBxXJUCV6i7So1Y2ELZ26qkYNSkRMz2qR-l341y-nOOQYxPq9Epuk_OQ%3D%40sagegerard.com.


[racket-users] function dispatch in typed racket

2019-10-14 Thread Raoul Schorer
Hi,

I am trying to write an APL compiler (a typed J implementation) with a 
typed racket backend. APLs have first-class functions that apply to both 
scalars and arrays, so there are 2 cases for functions of 2 arguments:

   - the *array -- array* case
   - the *scalar -- scalar* case

*Scalar -- array* and *array -- scalar* cases get their scalar argument 
lifted to arrays, and are therefore equivalent to the *array -- array* case.
Now, with an interpreter if I assign a function to an identifier, it can 
use just textual replacement to evaluate the function glyph in the runtime 
context (that's the way J does it). For example:

id =: +  ;;assign the 'add' function to 'id'

1 id 1   ;;evaluate to '2' using the scalar context on replacement with 
'+'

1 1 id 1 1;;evaluates to '2 2' using the array context on replacement 
with '+'


But at compile-time I can't use that trick, can I? So I end up with 
something like:
#lang typed/racket

(define id (case-lambda
 [([x : One] [y : One]) (+ y)]
 [([x : (Immutable-Vectorof One)] [y : (Immutable-Vectorof One
)]) (for/vector ([i x] [j y]) (+ i j))]))

(id 1 1)
(id #(1 1) #(1 1))

Which fails although the case-lambda is actually legal typed racket 
, because the second 
clause is considered dead code and one cannot dispatch on type.
In my (hobbyist) understanding, the solution seems to require multiple 
dispatch? Or is there another way to do that in typed racket?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/63e5ec59-23f1-4fc7-8045-beb32409bbca%40googlegroups.com.