Re: [racket-users] Please provide a simple example of typed racket with hyper-literate

2020-08-08 Thread greadey
It is not wrong, if you type the annotation and definition and run it in a 
typed/racket repl it works. I can also annotate it as;
(: foo : Integer -> Integer)
and that works as well in typed/racket

On Friday, 7 August 2020 at 18:57:03 UTC+1 Linus Björnstam wrote:

> Your type annotation is wrong. 
>
> (: foo (-> Integer Integer)) is (iirc, I haven't done typed racket other 
> than for fun) more like it.
>
> -- 
> Linus Björnstam
>
> On Fri, 7 Aug 2020, at 14:16, greadey wrote:
> > 
> > Hi All,
> > 
> > I've been trying to write typed racket code with hyper-literate. The 
> > docs seem to suggest I can just add typed racket to the #lang 
> > hyper-literate;
> > 
> > So my trial code is;
> > 
> > #lang hyper-literate typed/racket
> > 
> > @chunk[
> > 
> > (: foo : (Integer -> Integer))
> > (define (foo n)
> > (* 2 n))]
> > 
> > The repl "runs" this code without any complaint, however when I try;
> > 
> > (foo 2)
> > 
> > I get the following error;
> > 
> > Type Checker: missing type for identifier;
> > consider adding a type annotation with `:'
> > identifier: foo in: foo.
> > 
> > So would someone mind telling me where I am going wrong.
> > 
> > thanks in advance,
> > 
> > greadey
> > 
> > 
> > 
> > -- 
> > 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...@googlegroups.com.
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/racket-users/b38730fb-f01d-4c46-8db6-d42394d2860an%40googlegroups.com
>  
> <
> https://groups.google.com/d/msgid/racket-users/b38730fb-f01d-4c46-8db6-d42394d2860an%40googlegroups.com?utm_medium=email_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/eea3b0a3-48f7-4196-9b58-a0dfcc6161c3n%40googlegroups.com.


[racket-users] Please provide a simple example of typed racket with hyper-literate

2020-08-07 Thread greadey

Hi All,

I've been trying to write typed racket code with hyper-literate.  The docs 
seem to suggest I can just add typed racket to the #lang hyper-literate;

So my trial code is;

#lang hyper-literate typed/racket

@chunk[

   (: foo : (Integer -> Integer))
   (define (foo n)
 (* 2 n))]

The repl "runs" this code without any complaint, however when I try;

(foo 2)

I get the following error;

Type Checker: missing type for identifier;
 consider adding a type annotation with `:'
  identifier: foo in: foo.

So would someone mind telling me where I am going wrong.

thanks in advance,

greadey


-- 
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/b38730fb-f01d-4c46-8db6-d42394d2860an%40googlegroups.com.


[racket-users] Re: plotting multiple data sets on one set of axes

2020-04-12 Thread greadey
Thanks, Alex.   I managed to get that working a treat.

On Saturday, 11 April 2020 08:38:05 UTC+1, Alex Harsanyi wrote:
>
>
> The renderers  that you pass on to the `plot` function can be manipulated 
> outside the call to plot, so you can read the datasets you need, construct 
> a renderer for each one, group them in a list and pass them on to plot.  I 
> am not familiar with Matlab, but based on your description, you can 
> implement hold-on and hold-off as follows:
>
> #lang racket
> (require plot)
>
> (define the-renderers '())
>
> (define (hold-on renderer)
>   (set! the-renderers (cons renderer the-renderers)))
>
> (define (hold-off)
>   (begin0
> (plot (reverse the-renderers))
> (set! the-renderers '(
>
> ;; add a renderer for SIN
> (hold-on (function sin 0 10))
>
> ;; add a renderer for COS
> (hold-on (function cos 0 10))
>
> ;; Show the plot
> (hold-off)
>
> Alternatively, if you want a separate plot for each function, you can 
> implement hold-off as follows:
>
> (define (hold-off-2)
>   (begin0
> (for/list ([renderer (reverse the-renderers)])
>   (plot renderer))
> (set! the-renderers '(
>
> Alex.
>
> On Thursday, April 9, 2020 at 2:35:04 PM UTC+8, greadey wrote:
>>
>> Hi All,
>>
>> Can anyone give me some pointers on plotting multiple data sets on one 
>> set of axes.  Plotting two or more data sets on one set of axes is easy if 
>> you know in advance what the data is called;
>>
>> (plot (list
>>   (lines set1)
>>   (points set2))
>>  #:x-label "x" #:y-label "y")
>>
>> however I have a list of data sets generated from reading a bunch of 
>> files in a directory and I wish to loop through the list and add each 
>> data-set to an existing set of axes.
>>
>> Iterating through the data and plotting each set results in multiple plot 
>> windows.
>>
>> In summary I am looking for something similar to Matlab's "hold on" e.g.
>>
>> ;Pseudo Matlab code
>>
>> figure()
>> for idx = 1 : numel(list-of (list-of vector-pairs))
>> plot(list-of (list-of vector-pairs))(idx)
>> hold on
>> end
>> hold off
>>
>> I have got (plot-new-window? #t), however as far as I know this is just 
>> causing a plot to appear in a new window rather than directly in the repl.
>>
>> Many thanks,
>>
>> greadey.
>>
>

-- 
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/3c0dad34-68a0-4c2a-abf3-b81f53655b3a%40googlegroups.com.


[racket-users] plotting multiple data sets on one set of axes

2020-04-09 Thread greadey
Hi All,

Can anyone give me some pointers on plotting multiple data sets on one set 
of axes.  Plotting two or more data sets on one set of axes is easy if you 
know in advance what the data is called;

(plot (list
  (lines set1)
  (points set2))
 #:x-label "x" #:y-label "y")

however I have a list of data sets generated from reading a bunch of files 
in a directory and I wish to loop through the list and add each data-set to 
an existing set of axes.

Iterating through the data and plotting each set results in multiple plot 
windows.

In summary I am looking for something similar to Matlab's "hold on" e.g.

;Pseudo Matlab code

figure()
for idx = 1 : numel(list-of (list-of vector-pairs))
plot(list-of (list-of vector-pairs))(idx)
hold on
end
hold off

I have got (plot-new-window? #t), however as far as I know this is just 
causing a plot to appear in a new window rather than directly in the repl.

Many thanks,

greadey.

-- 
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/a16546e5-4bc9-4a96-a9b3-1ee28c65b06a%40googlegroups.com.


Re: [racket-users] Help with vector-sort

2020-02-16 Thread greadey


On Saturday, 15 February 2020 13:03:44 UTC, Jens Axel Søgaard wrote:
>
> Den lør. 15. feb. 2020 kl. 13.44 skrev greadey  >:
>
>> I have written a programme to compute a bootstrapped mean etc.  I 
>> successfully wrote it using lists both untyped and in typed/racket.
>> I am interested in optimising the code and having seen that typed racket 
>> performs faster (for lists) I am interested in seeing if I get a 
>> performance increase using vectors in both typed and untyped code.
>> In order to compute the median value as well as certain percentiles it is 
>> necessary to sort the samples.  My specific problem is using vector-sort.  
>> I have got round it by using vector->list and list->vector functions and 
>> using the list sort function.
>> If I use vector-sort typed racket keeps telling me to use 
>> "require/typed".  I got a function definition to compile  (:sort-myvector : 
>> (Vectorof Flonum) (Flonum Flonum -> Boolean) -> (Vectorof Flonum))
>> I'm not sure if that is exactly right but it was something similar, 
>> however it did not work.  I did add a "require/typed racket/vector" to the 
>> expression.
>> So, how can I use vector-sort in typed racket code, and can anyone tell 
>> me if translating vectors to lists and back again actually introduces a 
>> performance hit? 
>>
>
> Here is an example of how to use `vector-sort` from a typed/racket program:
>
> #lang typed/racket
> (require/typed racket/vector
>   [vector-sort (-> (Vectorof Any) (-> Any Any Boolean) (Vectorof Any))])
>
> (define (compare x y)
>   (if (and (real? x) (real? y))
>   (< x y)
>   (error 'compare "expected two real numbers, got: ~a ~a" x y)))
>
> (vector-sort (vector 3 1 5 2) compare)
>  
> /Jens Axel
>
> Thanks Jens - Nice one!  I had to define vector-sort to accept and yield 
Real values in order to get it to work!  My understanding of typed 
programming is that if you (as you did) define a function to be 
polymorphic, it should be polymorphic.  However, copying your code exactly 
and running vector sort  on a vector of reals gives  the error;
Type Checker: type mismatch
  expected: (Vectorof Any)
  given: (Vectorof Real) in: orig

Maybe one day I'll understand this one :-)

-- 
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/da0772b1-02bc-4c12-9b8b-0a37e7c3107f%40googlegroups.com.


[racket-users] Help with vector-sort

2020-02-15 Thread greadey
rr-mean (stddev my-means))
(define std-err-median (stddev my-medians))
;The next two compute the percentiles - 2.5 and 97.5
(define 95-means (95-limits my-means))
(define 95-medians (95-limits my-medians))
;Need to get the mean and the median of the original data
(define the-mean (mean orig))
(define the-median (my-median orig))
;Output the results
(list "Mean is: " the-mean "std error is: " std-err-mean "limits: " "97.5: "
  (last 95-means) "2.5 " (first 95-means)
  "The median is: "
  the-median
  " std error: "
  std-err-median
  "Limits: "
  "97.5 "
  (last 95-medians)
  "2.5 "
  (first 95-medians)
))

I'd be grateful to receive constructive criticism about my code :-)

Regards
greadey

-- 
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/0d7d6ad4-4e62-424c-9ea4-91b5118e7b18%40googlegroups.com.


Re: [racket-users] Strange error in racket 7.5

2020-01-26 Thread greadey
Hi Gustavo,
Thanks for getting back to me.  It is definitely a GhostBSD / TrueOS 
thing.  My masochistic tendencies persuaded me to reinstall a FreeBSD 
desktop and lo and behold everything is OK.  I was running it in DrRacket.
cheers,
greadey

On Saturday, 25 January 2020 18:30:31 UTC, gustavo wrote:
>
> It is an internal function of the math package 
> https://github.com/racket/math/blob/cdc64390f1e7b75de9575a91f0ec3a31f7878530/math-lib/math/private/bigfloat/mpfr.rkt#L587that
>  
> is used to show bigfloats. 
>
> I can't reproduce the error in Windows, but it doesn't look like an error 
> that is platform dependent. Are you running this in DrRacket or in the 
> command line? Any unusual configuration?
>
> Is the code available? Can you send a minimized example? Try to remove as 
> much as you can (including all the secret sauce if it is an internal 
> project). Any example that shows the error would be very helpful, but if 
> you can reduce the example to a hundred of lines it would be nice. And 
> shorter examples are better, even if the code makes no sense.
>
> Gustavo
>
>
> On Sat, Jan 25, 2020 at 9:34 AM greadey > 
> wrote:
>
>> Hi there,
>>
>> I am running racket 7.5 on GhostBSD 20.01, I am getting a strange error 
>> running a file which previously ran OK on FreeBSD 12.
>>
>> ../../../../local/share/racket/collects/racket/pretty.rkt:478:8: 
>> bigfloat-custom-write: undefined;
>>  cannot reference an identifier before its definition.
>>
>> What I cannot understand is that big-float-custom-write is not listed in 
>> the documentation.  Does anyone have any ideas what might be causing this?
>>
>> Cheers,
>>
>> greadey
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/37641b85-9d6b-4d29-9f35-bb35e99c5c99%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/racket-users/37641b85-9d6b-4d29-9f35-bb35e99c5c99%40googlegroups.com?utm_medium=email_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/a28b1053-64bf-4ca7-9254-a5425a1f198f%40googlegroups.com.


[racket-users] Strange error in racket 7.5

2020-01-25 Thread greadey
Hi there,

I am running racket 7.5 on GhostBSD 20.01, I am getting a strange error 
running a file which previously ran OK on FreeBSD 12.

../../../../local/share/racket/collects/racket/pretty.rkt:478:8: 
bigfloat-custom-write: undefined;
 cannot reference an identifier before its definition.

What I cannot understand is that big-float-custom-write is not listed in 
the documentation.  Does anyone have any ideas what might be causing this?

Cheers,

greadey

-- 
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/37641b85-9d6b-4d29-9f35-bb35e99c5c99%40googlegroups.com.


[racket-users] Trying to get my head around typed racket and higher order functions

2019-06-30 Thread greadey
Hi all,

I have a function - create-points- which takes two lists of Flonum and 
yields a list of vector pairs suitable for passing to Racket's plot 
function.

In un-typed code I can just do;

(define (create-points xs ys)
  (map vector xs ys))

and voila!  It works.  However the only way I have managed to get it to 
type check is by wrapping the vector function in a lambda;

(: create-points : (Listof Flonum) (Listof Flonum) -> (Listof (Vectorof 
Flonum))

(define (create-points xs ys)
  (map  (lambda ([x : Flonum] [y : Flonum]) (vector x y)) xs ys)).

I have tried using an inst form, but I cannot seem to get that to work. 
Question is thought, is wrapping the vector function in a lambda the only 
way to do this?

Cheers,

greadey

-- 
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/b6192278-03b1-4720-a3c2-72a915e6c959%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.