maxim_jaffe
2018-7-27 10:06:02

Good Morning Racketnam!


maxim_jaffe
2018-7-27 10:07:29

Let’s Racket


maxim_jaffe
2018-7-27 10:37:04

So in TR to ensure that a function takes to arrays with the same size/shape do I use a contract or is there a way to do it without


soegaard2
2018-7-27 10:37:41

array as in math/array ?


maxim_jaffe
2018-7-27 10:37:45

yes :thumbsup:


soegaard2
2018-7-27 10:40:21

Just checked the matrix implementation. Didn’t learn anything :slightly_smiling_face:


soegaard2
2018-7-27 10:40:25

(define-type (Matrix A) (Array A))


maxim_jaffe
2018-7-27 10:42:35

from what I understood a matrix is just a 2d array right? and since I do have to deal with some arrays bigger then 2d I thought I better stick to math/array


maxim_jaffe
2018-7-27 10:43:10

although in this particular case it would be a 2d array / matrix


maxim_jaffe
2018-7-27 10:43:35

but I need them to be the same size


soegaard2
2018-7-27 10:43:39

Yes. I just wanted to check whether the Matrix type contained information on the shape. It didn’t.


soegaard2
2018-7-27 10:43:57

So a contract sounds a nice approach.


maxim_jaffe
2018-7-27 10:44:23

ok :slightly_smiling_face: I’ll give that a try


maxim_jaffe
2018-7-27 10:44:29

thanks!


maxim_jaffe
2018-7-27 10:45:31

by the way if I want an argument to be a 1/0 Array is (Array (U Zero One)) the best approach? Or is there a number type that’s more adequate?


soegaard2
2018-7-27 10:46:03

Don’t know.


maxim_jaffe
2018-7-27 10:47:15

by the way in terms of testing TR is it good practice to have test cases for the output types or is that too redundant?


maxim_jaffe
2018-7-27 11:41:10

hey once again


maxim_jaffe
2018-7-27 11:41:28

can someone help me figure out how to use unfold from srfi/1


maxim_jaffe
2018-7-27 11:42:05

I want to unfold a function x times (not sure if I am describing this right)


soegaard2
2018-7-27 11:43:09

So you want to generate the list (list (f 0) (f 1) ... (f (- x 1))) ?


soegaard2
2018-7-27 11:46:29

#lang racket (require (only-in srfi/1 unfold)) (define (f x) (* x x)) (unfold (λ (x) (= x 10)) ; last seed value? f ; seed to value add1 ; next seed value 0) ; first seed value


maxim_jaffe
2018-7-27 11:47:19

hum not quite I think


maxim_jaffe
2018-7-27 11:48:04

more like (list (f 0) (f (f 0)) (f (f (f 0)))) etc


maxim_jaffe
2018-7-27 11:49:19

till f has been nested f times


maxim_jaffe
2018-7-27 11:50:07

ah yes that looks right


maxim_jaffe
2018-7-27 11:50:12

now that I ran it


maxim_jaffe
2018-7-27 11:50:38

thanks :slightly_smiling_face:


maxim_jaffe
2018-7-27 11:50:51

or hang on


maxim_jaffe
2018-7-27 11:51:05

no still think not quite what I wanted


maxim_jaffe
2018-7-27 11:52:12

some pointed to unfold in another chat


maxim_jaffe
2018-7-27 11:52:16

for what I described


maxim_jaffe
2018-7-27 11:52:22

but never used it


maxim_jaffe
2018-7-27 11:52:58

ok a concrete example


soegaard2
2018-7-27 11:53:22

If 0 is the seed, and f is the next seed function then unfold computes that list.


soegaard2
2018-7-27 11:53:51

The only tricky thing is for unfold to know when to stop.


maxim_jaffe
2018-7-27 11:54:50

I want someting like (f 3 sqr 2) which gives would give (list (sqr 2) (sqr (sqr 2)) (sqr (sqr (sqr 2)))) where 3 is the depth (?) sqr the function to apply and 2 the initial value


maxim_jaffe
2018-7-27 11:55:54

if you get my thought process


maxim_jaffe
2018-7-27 11:56:01

it’s basically to run a simulation


soegaard2
2018-7-27 11:56:04

So you have to keep track of two values: the number of times f has been applied to it self and the list of previous values.


maxim_jaffe
2018-7-27 11:57:02

hum ok, it should be possible to do that with fold right?


maxim_jaffe
2018-7-27 11:57:09

unfold


soegaard2
2018-7-27 11:57:10

(require (only-in srfi/1 unfold)) (define (f x) (list 'f x)) (struct seed (i x)) (unfold (match-lambda [(seed i x) (= i 10)]) ; stop? seed-x ; seed to value (match-lambda [(seed i x) (seed (+ i 1) (f x))]) ; next (seed 0 0)) ; initial seed


maxim_jaffe
2018-7-27 11:59:52

hum ok!


soegaard2
2018-7-27 12:00:58

Your example becomes:


soegaard2
2018-7-27 12:01:02
(require (only-in srfi/1 unfold))
(define (f x) (sqr x))
(struct seed (i x))
(unfold (match-lambda [(seed i x) (= i 5)])              ; stop?
        seed-x                                           ; seed to value
        (match-lambda [(seed i x) (seed (+ i 1) (f x))]) ; next
        (seed 0 2))                                      ; initial seed

maxim_jaffe
2018-7-27 12:01:35

guess the last part can be wrapped into a function right?


maxim_jaffe
2018-7-27 12:01:38

right?


soegaard2
2018-7-27 12:01:43

sure


maxim_jaffe
2018-7-27 12:02:09

This looks great thanks :slightly_smiling_face:


maxim_jaffe
2018-7-27 12:03:59

the seed struct is just syntatic sugar?


soegaard2
2018-7-27 12:04:00

Compare a loop:


soegaard2
2018-7-27 12:04:05

(let loop ([i 0] [x 2] [xs '()]) (if (= i 5) (reverse xs) (loop (+ i 1) (f x) (cons x xs))))


maxim_jaffe
2018-7-27 12:04:30

ah ok


maxim_jaffe
2018-7-27 12:04:34

looks a bit simpler hehe


maxim_jaffe
2018-7-27 12:04:43

and it’s still in functional style no?


jerome.martin.dev
2018-7-27 12:04:45

I was about to post that :stuck_out_tongue:


soegaard2
2018-7-27 12:04:57

yes, still functional


maxim_jaffe
2018-7-27 12:06:24

any suggestions for a name hehe, simulate sounds to specific


maxim_jaffe
2018-7-27 12:06:33

to wrap it up in a function


maxim_jaffe
2018-7-27 12:06:51

loop-n-times ?


maxim_jaffe
2018-7-27 12:07:06

or not quite


soegaard2
2018-7-27 12:07:52

maxim_jaffe
2018-7-27 12:10:55

cool


maxim_jaffe
2018-7-27 12:11:06

would that be useful to add in one of the racket libraries?


soegaard2
2018-7-27 12:11:28

I wouldn’t be surprised if it’s already there :slightly_smiling_face:


maxim_jaffe
2018-7-27 12:11:41

yeah I was wondering that


maxim_jaffe
2018-7-27 12:12:31

I looked up nest-list, that syntax doesn’t show up, but maybe by another name ?


maxim_jaffe
2018-7-27 12:12:40

I did feel it most be a standard kind function


soegaard2
2018-7-27 12:12:50

But it’s useful alright.


maxim_jaffe
2018-7-27 12:13:26

I mean it feels a bit like a map, filter, reduce kind of function no?


soegaard2
2018-7-27 12:14:13

Yes. Always fun to find new list functions.



maxim_jaffe
2018-7-27 12:15:55

hehe whenever I hear of Wolfram Language the languages as weapons cartoon always comes to mind



maxim_jaffe
2018-7-27 12:17:39

maxim_jaffe
2018-7-27 12:18:37
  1. Mathematica is a low earth orbit projectile cannon, it could probably do amazing things if only anyone could actually afford one.

maxim_jaffe
2018-7-27 12:25:18

Looks alright yes?


maxim_jaffe
2018-7-27 12:25:52

should be easy to add types no..?


maxim_jaffe
2018-7-27 12:25:59

for TR


soegaard2
2018-7-27 12:26:38

Yes. Only one nit: rename expr to something like seed. Mathematica is not call by value, so it makes sense for them to use expr.


maxim_jaffe
2018-7-27 12:26:55

hum ok!


maxim_jaffe
2018-7-27 12:27:14

but keeping a similar order of args makes sense no?


soegaard2
2018-7-27 12:27:29

yes


maxim_jaffe
2018-7-27 12:28:17

onething about TR


maxim_jaffe
2018-7-27 12:28:55

is the standard to have the separate (: etc) or to have the types in the function itself?


maxim_jaffe
2018-7-27 12:29:28

(define (f [i : Integer] (body))


soegaard2
2018-7-27 12:29:42

I don’t know what’s standard. I like to use (: ... ) before the function.


maxim_jaffe
2018-7-27 12:31:18

I mean since I tried a little Julia and Haskell my first instinct was to place it in the function itself, but I did notice sometimes it’s waymore compact to place it in (: ...)


maxim_jaffe
2018-7-27 12:38:45

anyways for the help @soegaard2 :slightly_smiling_face:


maxim_jaffe
2018-7-27 12:38:50

off to lunch


maxim_jaffe
2018-7-27 13:42:15

Ok so I think I’ve got the general jist of the typing for the nest-list function, but I have this problem . Type Checker: cannot apply a function with unknown arity; functionf’ has type Procedure which cannot be applied in: (f x)` which I kind of understand, but not sure what to do about it


maxim_jaffe
2018-7-27 13:42:32

plus I think the Any is probably not great idea


maxim_jaffe
2018-7-27 13:42:47

do I have to do some kind of polymorphic function..?


maxim_jaffe
2018-7-27 13:42:52

instead


maxim_jaffe
2018-7-27 13:43:18

or not really


soegaard2
2018-7-27 13:44:04

Replace Procedure with the type of an Any to Any function.


maxim_jaffe
2018-7-27 13:44:23

so (-> Any Any) ..?


maxim_jaffe
2018-7-27 13:44:24

or..?


maxim_jaffe
2018-7-27 13:44:38

I’ll admit I am a bit out of my depth :stuck_out_tongue:


maxim_jaffe
2018-7-27 13:44:49

(but giving it a try anyways)


maxim_jaffe
2018-7-27 13:46:21

guess not hehe


maxim_jaffe
2018-7-27 13:46:38

> (nest-list sqr 2 3) . Type Checker: type mismatch expected: (-> Any Any) given: (case-> (-> Zero Zero) (-> One One) (-> Positive-Byte Positive-Index) (-> Byte Index) (-> Positive-Integer Positive-Integer) (-> Integer Nonnegative-Integer) (-> Positive-Exact-Rational Positive-Exact-Rational) (-> Exact-Rational Nonnegative-Exact-Rational) (-> Flonum Nonnegative-Flonum) (-> Single-Flonum Nonnegative-Single-Flonum) (-> Inexact-Real Nonnegative-Inexact-Real) (-> Real Nonnegative-Real) (-> Float-Complex Float-Complex) (-> Single-Flonum-Complex Single-Flonum-Complex) (-> Inexact-Complex Inexact-Complex) (-> Exact-Number Exact-Number) (-> Number Number)) in: sqr


maxim_jaffe
2018-7-27 13:47:02

maxim_jaffe
2018-7-27 13:49:38

ah ok it’s because sqr is polymorphic?


maxim_jaffe
2018-7-27 13:50:12

hum how do I specify the type for accepting a polymorphic function ..?


soegaard2
2018-7-27 13:51:04

Well, we know that the input and output of f needs to be the same type as seed.


maxim_jaffe
2018-7-27 13:51:36

oh hum but actually what I am thinking of might not have the same type


maxim_jaffe
2018-7-27 13:51:47

in fact I was wondering why 2 was in the list


maxim_jaffe
2018-7-27 13:52:22

ah no yeah your right


maxim_jaffe
2018-7-27 13:52:45

but I’m wondering if that does what I was wanting


maxim_jaffe
2018-7-27 13:53:00

probably


maxim_jaffe
2018-7-27 13:54:23

Think I got it


maxim_jaffe
2018-7-27 13:54:31

does that make sense?


soegaard2
2018-7-27 13:55:41

It does. I am wondering how we can get the output type to be (Listof A)?


soegaard2
2018-7-27 13:56:16

Note: You don’t need to give types to i and x. They can be inferred.


maxim_jaffe
2018-7-27 13:56:29

ok yeah I felt it was overkill


soegaard2
2018-7-27 13:56:52

[xs : (Listof A) '()] works


maxim_jaffe
2018-7-27 13:57:26

Like this yeah? (was giving it a try)


soegaard2
2018-7-27 13:57:36

yes


maxim_jaffe
2018-7-27 13:57:57

> (nest-list sqr 2 5) - : (Listof Positive-Integer) '(2 4 16 256 65536)


maxim_jaffe
2018-7-27 13:57:59

cool


soegaard2
2018-7-27 13:58:13

Also you can remove : (Listof A) from (let loop : (Listof A)


maxim_jaffe
2018-7-27 13:58:39

nice :slightly_smiling_face:


maxim_jaffe
2018-7-27 13:58:54

by the way I came across let: is that of any use in this case?


maxim_jaffe
2018-7-27 13:59:13

didn’t quite understand it fully, but I had the impression I could use it


maxim_jaffe
2018-7-27 13:59:41

but it’s probably not need here yeah?


soegaard2
2018-7-27 14:00:34

I think let: is from the first version of typed racket.


soegaard2
2018-7-27 14:00:43

No reason not to use let.


maxim_jaffe
2018-7-27 14:01:09

hum ok!


maxim_jaffe
2018-7-27 14:01:15

Thanks for the help again :slightly_smiling_face:


maxim_jaffe
2018-7-27 14:10:49

Seems to work alright


maxim_jaffe
2018-7-27 14:23:14

I still haven’t quite understood how to use rackunit with typed racket


maxim_jaffe
2018-7-27 14:23:35

I mean I understand I have to annotate rackunit from the messages


maxim_jaffe
2018-7-27 14:23:54

with require/typed


maxim_jaffe
2018-7-27 14:24:31

ah… I just need to change rackunit to typed/rackunit ?? Hehe ok?


kyle.nweeia
2018-7-27 14:54:45

@kyle.nweeia has joined the channel


maxim_jaffe
2018-7-27 16:17:13

Based on what I learnt today changed some of the stuff I was working on yesterday, does this make sense..? It seems to work fine.


maxim_jaffe
2018-7-27 16:25:39

Maybe this is better?


samth
2018-7-27 16:29:35

@maxim_jaffe in general I recommend in-range instead of range (probably the docs should suggest this)


maxim_jaffe
2018-7-27 16:29:53

hum ok! sorry python habit


maxim_jaffe
2018-7-27 16:31:38

is that because range outputs and actual list while in-range outputs comething that can be iterated over?


samth
2018-7-27 16:32:57

yes — you can iterate over a list too, but there’s no reason to create the intermediate list


samth
2018-7-27 16:33:03

you can even just write n


maxim_jaffe
2018-7-27 16:33:54

n?


maxim_jaffe
2018-7-27 16:34:06

ah!


maxim_jaffe
2018-7-27 16:34:20

(for/list [i n] ...) yes?


maxim_jaffe
2018-7-27 16:38:51

hum can’t seem to do it without a (in-range n)


samth
2018-7-27 16:40:01

it works for me … (define (prior-samples n priors) (for/list ([i n]) (prior-sample priors)))


maxim_jaffe
2018-7-27 16:41:05

ah!


maxim_jaffe
2018-7-27 16:41:09

I was missing the []


maxim_jaffe
2018-7-27 16:43:37

thanks samth :slightly_smiling_face:


hunter.t.joz
2018-7-27 16:50:59

Going to start reading the reference manual tonight. That should get me into racket, as it looks interesting enough.


maxim_jaffe
2018-7-27 17:10:35

by the way is there a way to get DrRacket to eat less memory


maxim_jaffe
2018-7-27 17:11:44

sometimes it comes all the way up to 1.5 GB without doing run. I understood it continuoslty check your code and reports errors, is that the reason for the memory use?


maxim_jaffe
2018-7-27 17:12:46

it’s nice to have the error feedback, but I would be okay just rerunning and get some more memory in exchange


maxim_jaffe
2018-7-27 17:13:19

I already have one memory junky called firefox hehe


maxim_jaffe
2018-7-27 17:23:10

Cool I didn’t know FrTime was part of the Racket ecosystem


maxim_jaffe
2018-7-27 17:23:43

I had read about it in the programming paradigms for dummies chapter of Van Roy


maxim_jaffe
2018-7-27 17:24:23

is it possibility to combine something written in FrTime to some TR and regular Racket?


maxim_jaffe
2018-7-27 17:24:50

(I saw it was there in the tools options)


lexi.lambda
2018-7-27 17:24:57

@mflatt Given that the cache files produced by expander/run appear to be the results of calling compile, what distinguishes them from “real” bytecode files?


soegaard2
2018-7-27 17:25:39

@maxim_jaffe You need to check the docs of FrTime.


maxim_jaffe
2018-7-27 17:26:34

hehe ok, yeah sorry I should do that :stuck_out_tongue:!


maxim_jaffe
2018-7-27 17:28:35

the only thing is they are just a list of functions


soegaard2
2018-7-27 17:29:02

there is also a paper somewhere


soegaard2
2018-7-27 17:29:20

and some demo programs


maxim_jaffe
2018-7-27 17:29:42

yes think I’ll try the demos! I saw there is a thesis?



maxim_jaffe
2018-7-27 17:30:00

this one right?


maxim_jaffe
2018-7-27 17:32:28

looks interesting


maxim_jaffe
2018-7-27 17:32:42

and he gets into some code straight away (wasn’t expecting that)


maxim_jaffe
2018-7-27 17:32:53

not sure I got the time to read it for now :stuck_out_tongue:


maxim_jaffe
2018-7-27 17:32:58

but really cool


maxim_jaffe
2018-7-27 17:33:47

soegaard2
2018-7-27 17:34:50

soegaard2
2018-7-27 17:35:16

(it’s in postscript, so hope you aren’t on Windows)


maxim_jaffe
2018-7-27 17:47:01

Nono, I am in good all Linux (Manjaro Linux)


maxim_jaffe
2018-7-27 17:47:19

sorry Firefox, DrRacket and Zotero decided I was having too much fun


maxim_jaffe
2018-7-27 17:47:26

and ground my computer to a halt hehe


maxim_jaffe
2018-7-27 17:47:57

I still don’t get how much RAM these things consume


maxim_jaffe
2018-7-27 17:48:38

I mean I think 128 mb was a party back when I was a kid (1990s) and I remember having browser word and some other things open


maxim_jaffe
2018-7-27 17:49:10

on Mac OS 7 or what was it


maxim_jaffe
2018-7-27 17:49:55

I got 4gb RAM what the hell :stuck_out_tongue:?


maxim_jaffe
2018-7-27 17:50:04

sure it’s not humongous but still


maxim_jaffe
2018-7-27 18:02:22

there is actually the pdf version too



maxim_jaffe
2018-7-27 18:09:42

@soegaard2 thanks for the report :slightly_smiling_face: that’s really helpful


maxim_jaffe
2018-7-27 18:21:40

maybe a link to this particular report could be added in the docs of FrTime?


maxim_jaffe
2018-7-27 18:21:52

and to the thesis also


leo
2018-7-27 18:42:25

@leo has joined the channel


maxim_jaffe
2018-7-27 18:49:45

any idea what I am getting wrong (just manually copied it over from the report)? . match: syntax error in pattern in: ($ date sec min hr day mon yr _ _ _ _)


maxim_jaffe
2018-7-27 18:50:03

from the frtime report above


soegaard2
2018-7-27 18:50:23

Try (date sec …) instead.


maxim_jaffe
2018-7-27 18:50:49

without the $ ? still gives me the same error..!


soegaard2
2018-7-27 18:50:50

I think frtime is to old, that the report uses the old match implementation, which had a slightly different syntax.


maxim_jaffe
2018-7-27 18:51:06

hum ok! I’ll look it up


soegaard2
2018-7-27 18:51:21

Alternatively add (require mzlib/match)


maxim_jaffe
2018-7-27 19:02:44

hum just copied the list embedded in the (seconds->date seconds)


maxim_jaffe
2018-7-27 19:03:05

but still get a syntax error in pattern


maxim_jaffe
2018-7-27 19:03:40

the length matches so not sure what’s going own


maxim_jaffe
2018-7-27 19:04:11

think I’ll just look at the demos :stuck_out_tongue:


maxim_jaffe
2018-7-27 19:04:18

they should be working no?


maxim_jaffe
2018-7-27 19:09:16

hum ok just needed to replace the $ with list


maxim_jaffe
2018-7-27 19:09:25

and I forgot the extra info


soegaard2
2018-7-27 19:09:38

(seconds->date seconds)


maxim_jaffe
2018-7-27 19:09:38

maxim_jaffe
2018-7-27 19:09:50

going to try with the original example


soegaard2
2018-7-27 19:09:53

returns a (signal (date* …) …)


maxim_jaffe
2018-7-27 19:10:40

so probably have to convert it into something else


soegaard2
2018-7-27 19:10:43

So something is not quite right.


maxim_jaffe
2018-7-27 19:11:08

I mean there is this in the middle (date* 19 9 20 27 7 2018 5 207 #t 3600 0 "WEST")


maxim_jaffe
2018-7-27 19:11:31

which is what is supposed to ge t matched in the original script


soegaard2
2018-7-27 19:12:08

(value-now (seconds->date seconds))


soegaard2
2018-7-27 19:12:12

gives the date


maxim_jaffe
2018-7-27 19:12:52

cool


soegaard2
2018-7-27 19:12:59

but that doesn’t work


soegaard2
2018-7-27 19:13:24

the idea is that clock is the current date


soegaard2
2018-7-27 19:13:46

if we use value-now, the value of clock doesn’t update automatically


soegaard2
2018-7-27 19:14:04

I think you need to try frtime in an older version of racket.


maxim_jaffe
2018-7-27 19:14:16

hum ok!


soegaard2
2018-7-27 19:14:33

I am almost sure something has changed.


maxim_jaffe
2018-7-27 19:14:34

I saw something about streams in the docs somewhere


maxim_jaffe
2018-7-27 19:14:41

oh well!


maxim_jaffe
2018-7-27 19:14:46

interesting idea


maxim_jaffe
2018-7-27 19:14:54

maybe can look at it some other time


maxim_jaffe
2018-7-27 19:15:39

but looks like it’s not what I am thinking


samth
2018-7-27 20:14:13

@mflatt is the fact that make-base-namespace doesn’t work if you use it from a module that doesn’t load racket/base a bug, or just something that can’t work?


mflatt
2018-7-27 20:15:12

It can’t work


lexi.lambda
2018-7-27 20:22:37

@mflatt can I ask you to take a look at this PR at some point? https://github.com/racket/draw/pull/12


asumu
2018-7-27 22:35:38

hunter.t.joz
2018-7-28 00:40:51

Does Racket have something similar to Clojure’s (source) capability?


samth
2018-7-28 01:05:47

@hunter.t.joz what does that do?


hunter.t.joz
2018-7-28 01:06:34

Shows you the code for a particular function and/or macro; for example, (source dotimes) would show you the code for dotimes.


samth
2018-7-28 01:09:10

No, racket doesn’t keep the source code for things around


lexi.lambda
2018-7-28 04:08:49

@hunter.t.joz fwiw, while @samth’s answer is correct, both DrRacket and racket-mode have functionality to jump to the definition of a particular function


lexi.lambda
2018-7-28 04:09:17

which is probably enough if you just want to find out how something is implemented


lexi.lambda
2018-7-28 04:11:17

also, ,describe some-id in XREPL (which I believe is loaded by default in modern versions of Racket) will tell you the module some-id is defined in