wanpeebaw
2020-5-21 08:21:33

How about (in-range [1 n]) and (in-range [1 n)), just like mathematical notation…:laughing:


soegaard2
2020-5-21 08:43:52

@wanpeebaw That’s doable, if we change to:  (in-range "[1,n]") and  (in-range "[1,n[") . The in-range transformer can handle expressions inside string literals without problems.

But the reason I wanted (range n m) to return a struct, was to allow operations such as range-union and range-intersection.


wanpeebaw
2020-5-21 08:47:00

Maybe extend range expression to express closed and open ended like (range n m '])  and (range n m '))


soegaard2
2020-5-21 08:50:08

Maybe I should lobby for domain to replace range?

> ; A domain interval represents an interval, a subset of the real number line > ; of one of the following forms: > ; i) a<x<b open-open > ; ii) a<=x<b closed-open > ; iii) a<x<=b open-closed > ; iv) a<=x<=b closed-closed > > ; A domain consists of a list of intervals. > ; The invariant is: > ; I) the intervals doesn’t overlap > ; II) the intervals are sorted in ascending order I used them in MetaPict to represent the domain of functions (of which I wanted to plot their graph).

https://github.com/soegaard/metapict/blob/master/metapict/domain.rkt


soegaard2
2020-5-21 08:53:03

I chose (open a b) , (closed a b), (open-closed a b) and (closed-open a b) to construct the intervals ]a;b[, [a;b], ]a;b] and [a;b[ respectively.


massung
2020-5-21 13:32:04

@soegaard2 When talking about math, functions like range always bug me, because range is meant to be continuous, while domain is a set. The Racket method (range 5) technically returns a domain (0 1 2 3 4). The value 2.5 is not in that domain, but is in the range. If you’re really wanting math predicates, I’d probably do something along the lines of:

(define (in-range x start end #:start-open [so #t] #:end-open [eo #f]) ...) And then in-domain could be implemented as just member or something similar.

My 2c.


capfredf
2020-5-21 13:47:50

How can I debug an “instantiate-linket” error: FAILURE name: check-not-exn location: typed-racket-test/main.rkt:88:31 expression: (check-not-exn thnk) params: '(#&lt;procedure:...acket-test/main.rkt:80:10&gt;) message: "Exception raised" exception-message: "instantiate-linklet: mismatch;\n reference to a variable that is not exported;\n possibly, bytecode file needs re-compile because dependencies changed\n name: Poly*178.1\n exporting instance: \"/home/runner/work/typed-racket/typed-racket/typed-racket-lib/typed-racket/rep/type-rep.rkt\"\n importing instance: (submod \"/usr/share/racket-7.7.0.6/pkgs/math-lib/math/private/array/array-parallel.rkt\" #%type-decl)" exception: #(struct:exn:fail:contract "instantiate-linklet: mismatch;\n reference to a variable that is not exported;\n possibly, bytecode file needs re-compile because dependencies changed\n name: Poly*178.1\n exporting instance: \"/home/runner/work/typed-racket/typed-racket/typed-racket-lib/typed-racket/rep/type-rep.rkt\"\n importing instance: (submod \"/usr/share/racket-7.7.0.6/pkgs/math-lib/math/private/array/array-parallel.rkt\" #%type-decl)" #&lt;continuation-mark-set&gt;)


capfredf
2020-5-21 13:48:37

Usually, I would run raco setup and this type of errors would go away.


capfredf
2020-5-21 13:54:46

@mflatt Is there a more effective and efficient racket-ish way to fix this than something like git bisect?


capfredf
2020-5-21 14:09:06

Ah, nvm, I see what I got wrong


mflatt
2020-5-21 15:14:58

In case someone else runs into similar trouble, what was it? (I didn’t have any good guesses.)


alexknauth
2020-5-21 15:47:32

I’m working on a version of dict/c with chaperones, but I’m running into a surprising problem that only comes up because of the failure-result optional-argument to dict-ref.

When the failure-result is used, I don’t want the “value” contract to apply to that result. But when the failure-result isn’t used, but the “value” result happens to be exactly equal to the failure-result, I do want the “value” contract to apply to it. How do I distinguish those though?

I tried to take inspiration from Carl Eastlund’s dict/c implemented in mischief/contract, but it doesn’t use chaperones so it is free to both add an escape continuation, and change the failure-result input to always be a new synthesized procedure. That way the new synthesized failure-result procedure can call the escape continuation. If I’m constrained to chaperones, I don’t know how to do either of those things.

How can I detect whether the failure-result is used-or-not by the dict’s implementation of dict-ref, while keeping the failure-result a chaperone of the original failure-result?


samth
2020-5-21 15:58:57

it was out-of-date zo files caused by (the TR CI tests) running raco setup on only a limited set of collections


alexknauth
2020-5-21 16:52:29

samth
2020-5-21 19:15:33

Maybe, send 64-byte chunks with a header byte that’s all–0 to signal “end of object”


samth
2020-5-21 19:24:21

use all–1 to signal “there’s more” after this and all–0 to signal “this is the end”


gfb
2020-5-21 19:29:29

that shifts the problem into the 64-byte window though, doesn’t it?


gfb
2020-5-21 19:35:44

Why not just take any incremental (non-empty) data you have, length-prefix that part, repeat, at the end emit a “length” of 0.


jaz
2020-5-21 19:36:45

Or use something like http 1.1’s chunked encoding.


jaz
2020-5-21 19:37:04

Which is exactly what @gfb’s suggestion amounts to… :slightly_smiling_face:


gfb
2020-5-21 19:51:32

And @mbutterick, your hex idea is essentially available in racket via base64 encoding ( https://docs.racket-lang.org/net/base64.html ), which avoids many characters (for a different reason, but that doesn’t matter). That library also breaks the data into chunks (again, not for the reasons we would), but you can just set the separator to the empty byte string.


abmclin
2020-5-21 20:05:38

and profile to see if the base64 encoding/decoding is expensive or not, that’ll help you decide if base64 is good enough


abmclin
2020-5-21 20:06:39

if 64 byte chunks seem like the better approach, then could reserve the first byte of the chunks to indicate if it’s the last chunk or more still coming


gfb
2020-5-21 20:12:54

You still need a length indicator on the last chunk, not just that it’s the final one.


abmclin
2020-5-21 20:20:36

if every chunk is of a known same size, won’t a length indicator not be necessary?


abmclin
2020-5-21 20:20:55

oh I see what you mean


abmclin
2020-5-21 20:21:13

the last bit of the binary file might not occupy the entire chunk


gfb
2020-5-21 20:28:27

change of topic : what’s the noticeable difference between defining a function in a class, versus defining a private method, and is there a standard heuristic for choosing which to do.


samth
2020-5-21 20:30:52

One will produce a closure over this, one will indirect through the vtable


gfb
2020-5-21 20:51:19

so the closure is a bit of allocation per object, but a standard closure for higher-order uses


mflatt
2020-5-21 20:58:03

Right. For space and time performance, you should practically always define a private method, except when doing would lead to a syntax error (because the method name is used as an expression). A private method avoids closure allocation and is potentially inlined.


jaz
2020-5-21 21:03:40

@mbutterick Here’s an example of what I was talking about: https://gist.github.com/97jaz/20a53bb49d2f6684b91011f2aa1911ff

It transmits data as a series of variable-length chunks, where the end of the stream is indicated by a chunk of length 0. This is a bit different from how it’s done in HTTP, since I use a fixed two-byte chunk size.


gfb
2020-5-21 21:18:35

thanks!


sorawee
2020-5-21 21:24:35

Is this documented anywhere? I was confused by this for a very long time. If not, would it be a good idea to put it in tutorial/doc?


alexknauth
2020-5-22 01:25:40

Is it wrong in a procedure chaperone, to call the function I’m supposed to be chaperoning during the chaperone’s wrapper-proc? It feels kinda evil to me, but I’m not sure why


samth
2020-5-22 02:26:24

that definitely seems wrong


samth
2020-5-22 02:26:34

it would call the procedure twice


alexknauth
2020-5-22 03:05:27

Okay.


alexknauth
2020-5-22 03:09:40

So I guess it would be worth avoiding chaperones then, for a contract that would need to be an impersonator contract, that only calls the procedure once, rather than a chaperone contract that calls the procedure twice


jcoo092
2020-5-22 04:00:17

Hi Racket folks. I am attempting to perform some basic comparative benchmarking of a handful of implementations of parallel Concurrent ML, with Racket being one of them (since its channels and events correspond pretty closely to Concurrent ML). To that end, I have been working on implementing some small test programs in Racket - thank you very much to the people who have helped me out with that so far :slightly_smiling_face:

I have now ‘completed’ these programs using places, channels and events. You can see the current results here: https://github.com/jcoo092/CML_benchmarks/tree/master/Racket

I strongly suspect, however, that since I’m pretty much still a total Racket newbie, I have done one or more things in a sub-optimal (or at least non-idiomatic) way. Plus, there could well be a bug or two in there that I haven’t spotted. Thus, I would very much appreciate it if anyone who is interested would take a look at the programs, and let me know if they spot any glaring errors or inefficiencies. Or anything else that jumps out at you as a problem.

I’m interested in any and all critiques you can come up with that might make the programs better, but, please note that I might not take them into account. This is mostly likely to happen if the suggested change would be a significant rewrite of a whole program beyond what I have now. The reason for that is I’m also (implicitly) somewhat testing the languages I am working with to see which ones enable new-to-the-language programmers to get good performance without too much effort.

Thanks again everyone for your help! :slightly_smiling_face:

EDIT: You don’t need to suggest Typed Racket, since I already plan to try that out in the near future :wink:


hedgehogshiatus
2020-5-22 05:18:54

@hedgehogshiatus has joined the channel


joe
2020-5-22 06:38:23

@joe has joined the channel


joe
2020-5-22 06:44:03

Hi. Is Racket suitable to make a chat server with a web client?