y84qiu173
2020-3-31 08:39:22

@y84qiu173 has joined the channel


y84qiu173
2020-3-31 08:39:56

Hey guys


spdegabrielle
2020-3-31 08:40:45

Hey @y84qiu173


y84qiu173
2020-3-31 08:40:50

:smile:


y84qiu173
2020-3-31 08:40:51

Quick question about DrRacket: is it self-contained for OSX?


y84qiu173
2020-3-31 08:41:09

We get a Racket v7.6 folder out of the download and move it to applications


y84qiu173
2020-3-31 08:41:15

That doesn’t install Racket for command line right


y84qiu173
2020-3-31 08:41:21

It only gives us the DrRacket application?


soegaard2
2020-3-31 08:42:36

It’s self-contained. But you need to add the folder with the command line racket to your path.


y84qiu173
2020-3-31 08:42:59

Ahh okay


y84qiu173
2020-3-31 08:43:32

Thanks!


spdegabrielle
2020-3-31 08:43:47

On macOS:

sudo sh -c ‘echo "/Applications/Racket v7.6/bin" >> /etc/paths.d/racket’ (If you have installed a previous version you may want to edit /etc/paths.d/racket to remove the old paths. I used vi but you may prefer to delete the file with sudo rm /etc/paths.d/racket , and recreate it with the above command)

To use command line tools (raco) you will also need to run the command sudo xattr -r -d com.apple.quarantine /Applications/Racket v7.6/


y84qiu173
2020-3-31 08:43:57

And, just to be sure: in the event that I did want to uninstall Racket, all I would need to do is to trash the “Racket v7.6” folder?



y84qiu173
2020-3-31 08:44:11

That part makes sense, awesome!


y84qiu173
2020-3-31 08:44:32

I’m just wondering whether the DrRacket app makes additional directories in the library or bin or something


spdegabrielle
2020-3-31 08:44:47

Yes- just trash the folder


y84qiu173
2020-3-31 08:44:58

Alrighty


y84qiu173
2020-3-31 08:45:03

That’s why there’s no uninstall script I assume?


y84qiu173
2020-3-31 08:45:10

Because all the relevant things stay there


spdegabrielle
2020-3-31 08:45:34

It does make folders in /Library


spdegabrielle
2020-3-31 08:45:53

That is where packages get stored


y84qiu173
2020-3-31 08:45:59

Oh


y84qiu173
2020-3-31 08:46:00

Whaaaa


y84qiu173
2020-3-31 08:46:16

I haven’t been able to find any


y84qiu173
2020-3-31 08:46:30

What are the folders it makes?


spdegabrielle
2020-3-31 08:47:06

Give me a minute to look it up


soegaard2
2020-3-31 08:47:07

Not in /Library ? It’s in ~/Library/Racket


spdegabrielle
2020-3-31 08:47:18

My bad.


y84qiu173
2020-3-31 08:47:32

Oh


y84qiu173
2020-3-31 08:47:43

Doesn’t exist, apparently


y84qiu173
2020-3-31 08:47:44

Hmm


y84qiu173
2020-3-31 08:47:55

Anywhere else it could be?


y84qiu173
2020-3-31 08:47:57

I’d assume not


soegaard2
2020-3-31 08:48:31

It will be created when you download packages that aren’t in the distribution.


y84qiu173
2020-3-31 08:48:37

Ohhhh


soegaard2
2020-3-31 08:48:39

(I think)


y84qiu173
2020-3-31 08:49:15

I’ll go install some to check then


y84qiu173
2020-3-31 08:49:19

Thanks, you two!


spdegabrielle
2020-3-31 08:52:26

No problem


spdegabrielle
2020-3-31 08:52:35

Good morning @soegaard2


spdegabrielle
2020-3-31 08:52:39

:grin:


soegaard2
2020-3-31 08:52:53

You too.


soegaard2
2020-3-31 08:53:10

Closer to noon here :wink:


spdegabrielle
2020-3-31 08:57:28

where are you?


spdegabrielle
2020-3-31 08:58:14

@y84qiu173 /Users/spdegabrielle/Library/Racket/ is the packages. still looking for drracket config


soegaard2
2020-3-31 08:58:21

Denmark.


spdegabrielle
2020-3-31 08:59:15

You are an hour ahead but I’d still call 11 morning. :grin:


soegaard2
2020-3-31 08:59:43

Well - I already taught my first class today…


soegaard2
2020-3-31 09:00:24

(Over the internet of course)


spdegabrielle
2020-3-31 09:03:08

Nice. What do you use to teach over internet? Adobe connect?


spdegabrielle
2020-3-31 09:04:17

@y84qiu173 soem config files also at `~/Library/Preferences/ e.g. ~/Library/Preferences/org.racket-lang.prefs.rktd


soegaard2
2020-3-31 09:04:45

We are using Microsoft Teams (as parts as Office 365, which is pretty cheap for educational institutions).


soegaard2
2020-3-31 09:04:55

It works reasonably well.


y84qiu173
2020-3-31 09:05:00

Oh, I have the preferences there


y84qiu173
2020-3-31 09:05:08

And installing some stuff made a Racket folder in library


y84qiu173
2020-3-31 09:05:19

Working as intended :thumbsup:


spdegabrielle
2020-3-31 09:05:59

@y84qiu173 screenshot


soegaard2
2020-3-31 09:07:13

There is support for video conference and chat rooms etc.


spdegabrielle
2020-3-31 09:09:40

@soegaard2 I’m looking to do a virtual racket meetup - thinking about Jitsi meet - but not tried it yet.


spdegabrielle
2020-3-31 09:10:34

yeah team isnt bad. I also use it at work


spdegabrielle
2020-3-31 09:10:57

I don’t think I can use it for a racket meetup


soegaard2
2020-3-31 09:11:25

Agree. Maybe Google Meet (or is it Google Hangout?)


jestarray
2020-3-31 16:19:29

anyone know if there’s a built in way to print twos complement binary negative numbers?


jestarray
2020-3-31 16:20:07

(format "~b" –7) prints out –111 , it just puts a negative sign infront of the binary 7


mojotrek.lgt
2020-3-31 17:14:55

@mojotrek.lgt has joined the channel


samdphillips
2020-3-31 17:17:21

I don’t think there is a built-in way but you could put the number into a bytes and convert each byte: > (define (bits n) (define b (integer->integer-bytes n 4 #t #f)) (for/fold ([s* null] #:result (string-append* s*)) ([v (in-bytes b)]) (cons (number->string v 2) s*))) > (bits -7) "11111111111111111111111111111001"


samth
2020-3-31 17:44:55

This implementation is a bit shorter: (define (bits n) (define b (integer->integer-bytes n 4 #t #f)) (string-append* (reverse (for/list ([v b]) (number->string v 2)))))


samdphillips
2020-3-31 19:10:21

@ryanc I have a recursive type in asn1 that I’m trying to encode and it looks like it is failing because it gets forced too early? Skimming the code I think it may fail for other reasons as well.


samdphillips
2020-3-31 19:10:41

#lang racket/base (require asn1) (define Filter (let ([REC (DELAY Filter)]) (CHOICE [val #:implicit 0 INTEGER] [and #:implicit 1 (SET-OF REC)] [not #:implicit 2 REC])))


samdphillips
2020-3-31 19:12:04

samdphillips
2020-3-31 19:12:45

Simplified example. It works if the not line is absent.


ryanc
2020-3-31 19:55:01

The underlying problem is that an implicit tag cannot be added to a CHOICE type (or a type name that refers to a CHOICE type). The IMPLICIT TAGS declaration in the module you’re porting means “use implicit tags except for Choice types” (reference: http://www.oss.com/asn1/resources/books-whitepapers-pubs/larmouth-asn1-book.pdf, section 3.2.2, page 68). I think the fix is just to change the last #:implicit (in the not variant) to #:explicit.


ryanc
2020-3-31 19:59:41

I’m not sure it’s possible to give a better error in this particular case. The asn1 library is already trying to check and report this kind of error; that’s actually what causes it to force the promise before the type is defined (as you pointed out). If you try a non-recursive example, like (SEQUENCE [foo #:implicit 1 (CHOICE [a INTEGER] [b BOOLEAN])]), you’ll get the error “SEQUENCE: cannot implicitly tag type: …”.


samdphillips
2020-3-31 20:32:52

Thanks for taking a look. I’ll try that.


samdphillips
2020-3-31 20:34:14

I was starting to think I was going to have to write something to encode directly to BER-frame s


samdphillips
2020-3-31 20:34:52

Also I clearly only know enough ASN.1 to be dangerous


ryanc
2020-3-31 20:47:07

For arbitrarily large or small integers: (define (bits n) (cond [(zero? n) "0"] [(positive? n) (string-append "0" (number->string n 2))] [(negative? n) (number->string (+ n (expt 2 (add1 (integer-length n)))) 2)]))


samdphillips
2020-3-31 21:15:12

Seems to be working. Thanks Ryan!


jestarray
2020-3-31 21:28:16

thanks guys


jestarray
2020-3-31 21:28:33

looking at pattern matching, is there a way to make it exhaustive?


jestarray
2020-3-31 21:29:54

oh wait


jestarray
2020-3-31 21:30:40

it warns if in exhaustive match is executed


badkins
2020-3-31 21:44:48

I’ll always be grateful to Paul Graham for leading me to Racket via Arc :slightly_smiling_face: He recently asked folks on Twitter (https://twitter.com/paulg/status/1244921240227282944) what it would look like in their language to sort a list of strings in descending order of the length of the string: ;; The solution I would use (define (pg lst) (sort lst > #:key string-length)) ;; If I didn't have #:key and had to do the work in the comparator (define (pg lst) (sort lst (λ (a b) (> (string-length a) (string-length b))))) ;; A more concise version of the previous (define (pg lst) (sort lst (λ x (apply > (map string-length x))))) ;; A point-free version (define (pg lst) (sort lst (compose (curry apply >) (curry map string-length) list))) (pg '("a" "bcd" "ef" "ghij")) ;; => '("ghij" "bcd" "ef" "a") I’m not pleased with the point-free (comparator) version. How would you make that version nicer? If Rhombus can make that version more similar to Haskell, I might become interested :slightly_smiling_face:


massung
2020-3-31 22:33:36

Just for fun in some other esoterics… \ 8th (a derivative of Forth) : pg ( s:len nip swap s:len nip n:- ) a:sort ; # rakudo/perl6 sub pg(@xs) { @xs.sort({$^b.chars - $^a.chars}) }


massung
2020-3-31 22:51:09

Obviously the racket code is far more legible. :slightly_smiling_face:


samth
2020-3-31 22:56:16

@badkins what’s the Haskell version?


badkins
2020-3-31 23:46:02

@samth I was mainly referring to the implicit partial application that Haskell offers plus the compose operator - Haskell seems to be a local optimum for point free stuff


badkins
2020-3-31 23:47:13

It’s not that important to me; I’ve had a blast coding Racket full time for the last 1.5 years or so :slightly_smiling_face:


sorawee
2020-3-31 23:47:22

sorawee
2020-3-31 23:47:58

It would let you avoid spelling out curry.


badkins
2020-3-31 23:48:25

Interesting - very Arc-like


badkins
2020-3-31 23:49:32

re: the point free version above, I was mainly curious if I was missing something obvious. If sort didn’t have the #:key keyword arg, I’d probably code the second version for clarity.


badkins
2020-3-31 23:50:17

spelling out curry doesn’t bother me that much, as it’s clear, but having to use apply did bother me a bit


badkins
2020-3-31 23:56:26

Some of the Haskell responses were: reverse . sortOn length sortBy (flip (comparing length)) sortOn (Down . length)


badkins
2020-3-31 23:56:38

It’s been a few years since I coded much Haskell.


samth
2020-4-1 00:02:25

note that the ones sortOn are similar to #:key


badkins
2020-4-1 00:09:54

Yes. I like the use of #:key in sort - seems elegant to me.


badkins
2020-4-1 00:11:42

I also think my frustration was due to a lack of FP knowledge on my part. Since the comparator consumes 2 input args, I think there’s no way around doing something similar to what I did i.e. converting the args to a list, etc.


badkins
2020-4-1 00:47:13

Ok, I think I’ll stick with this for my hypothetical point free version. Requires the addition of apply2 which may be handy: (define (apply2 fun a b) (values (fun a) (fun b))) (define (pg lst) (sort lst (compose > (curry apply2 string-length))))


samth
2020-4-1 01:55:45

I think a nice point free version would use a combinator like this: (define ((comparison f) a b) (< (f a) (f b))) (define ((flip f) a b) (f b a)) (define (pg lst) (sort lst (flip (comparison string-length))))


badkins
2020-4-1 02:32:39

Very nice @samth I totally forgot about that define syntax!


samth
2020-4-1 02:35:23

that’s basically the Haskell solution you posted: sortBy (flip (comparing length))


badkins
2020-4-1 02:35:48

I actually like it better by far :slightly_smiling_face:


samth
2020-4-1 02:36:11

with fancy-app it’s (define pg (sort _ (flip (comparison string-length))))


badkins
2020-4-1 02:39:10

Well… I guess Haskell does offer a little more invocation flexibility i.e. you don’t have to commit to partial application.


badkins
2020-4-1 02:39:42

Still, there are a few places in my application where I’m using curry where the define syntax above would be better.