
@y84qiu173 has joined the channel

Hey guys

Hey @y84qiu173

:smile:

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

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

That doesn’t install Racket for command line right

It only gives us the DrRacket application?

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

Ahh okay

Thanks!

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/

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?


That part makes sense, awesome!

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

Yes- just trash the folder

Alrighty

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

Because all the relevant things stay there

It does make folders in /Library

That is where packages get stored

Oh

Whaaaa

I haven’t been able to find any

What are the folders it makes?

Give me a minute to look it up

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

My bad.

Oh

Doesn’t exist, apparently

Hmm

Anywhere else it could be?

I’d assume not

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

Ohhhh

(I think)

I’ll go install some to check then

Thanks, you two!

No problem

Good morning @soegaard2

:grin:

You too.

Closer to noon here :wink:

where are you?

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

Denmark.

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

Well - I already taught my first class today…

(Over the internet of course)

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

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

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

It works reasonably well.

Oh, I have the preferences there

And installing some stuff made a Racket folder in library

Working as intended :thumbsup:

@y84qiu173 screenshot

There is support for video conference and chat rooms etc.

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

yeah team isnt bad. I also use it at work

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

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

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

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

@mojotrek.lgt has joined the channel

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"

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)))))

@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.

#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])))

This is for LDAP Filter type. https://tools.ietf.org/html/rfc4511#appendix-B

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

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
.

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: …”.

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

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

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

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)]))

Seems to be working. Thanks Ryan!

thanks guys

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

oh wait

it warns if in exhaustive match is executed

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:

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})
}

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

@badkins what’s the Haskell version?

@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

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:

@badkins: does this help? https://docs.racket-lang.org/fancy-app/index.html

It would let you avoid spelling out curry
.

Interesting - very Arc-like

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.

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

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

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

note that the ones sortOn
are similar to #:key

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

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.

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))))

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))))

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

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

I actually like it better by far :slightly_smiling_face:

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

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

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