notjack
2021-1-15 11:59:29

Huh, I’m kind of surprised we don’t have for/max and for/min


soegaard2
2021-1-15 12:01:19

Deja vu. For/fold is close though.


sorawee
2021-1-15 12:19:14

It’s the example of for/fold/derived :disappointed:


sorawee
2021-1-15 12:20:29

for/max would be a lot more useful if we can provide custom comparator, or have generic comparison


notjack
2021-1-15 12:20:42

(into-max) ;)


notjack
2021-1-15 12:21:16

I guess if you’re brave you can get it with for/reducer


notjack
2021-1-15 12:22:06

(for/reducer (into-max string<=>) ([book (in-list books)]) (book-title book))


soegaard2
2021-1-15 12:22:12

The value for max over an empty set of elements needs to be an option.


notjack
2021-1-15 12:22:31

yup, at least if there’s custom comparators involved



yfangzhe
2021-1-15 12:27:25

it is because it’s hard to choose which value as (for/max ([i '()]) i)?


notjack
2021-1-15 12:28:08

:sob: (let (and (let (let (cond (let (let* (let (let* (let (if (if (let (lambda (let-values (let (let ...)))))))))))))))))


notjack
2021-1-15 12:28:37

@yfangzhe if there’s no custom comparators, it can probably just use #false for that case


laurent.orseau
2021-1-15 12:53:53

A pretty good exercize for resyntax and also possibly a good showcase!


laurent.orseau
2021-1-15 13:03:18

which can then be easily combined with or and a default value


greg
2021-1-15 13:12:53

That is a pretty fabulous example.


greg
2021-1-15 13:13:04

If this were another package ecosystem where it’s obligatory to come up with clever/creative names? Then you should probably rename resyntax to something like empty-nester. :stuck_out_tongue:


samth
2021-1-15 14:32:44

https://gist.github.com/02d2b4c3d64ed0464104113eab69bc0e (see the assignment function and the #:draft? argument)


samth
2021-1-15 14:32:45

ccshan
2021-1-15 14:33:12

Note that the draft feature is susceptible to url-guessing attack


laurent.orseau
2021-1-15 14:44:11

@samth Just checking: Did you intend to post this here?


samth
2021-1-15 14:44:56

no, I thought I posted that in a thread


mflatt
2021-1-15 15:04:47

This choice is made by the MMTabBarView library. FWIW, it seems consistent with what Safari does. You can try setting the PLT_FLAT_PORTABLE_TAB_PANEL environment variable (to any value) before starting DrRacket, and then you’ll get Robby’s custom implementation. If that’s widely preferred for DrRacket, it could be the default.


greg
2021-1-15 15:17:23

IIRC that was for @dvanhorn



dvanhorn
2021-1-15 16:23:47

thanks!


curiouslearn
2021-1-15 19:14:05

@greg Did I make a basic mistake here when following your instructions? Can you please comment on why it does not work? Thanks.


soegaard2
2021-1-15 19:21:11

I am slightly confused. I couldn’t get trace to work. Turns out racket/trace was what I wanted to use. Should trace contain a pointer to racket/trace and vice versa?


shu--hung
2021-1-15 19:33:19

$ racket -l trace -t fib.rkt (#<syntax:fib.rkt:5:9 fib> 5) (#<syntax:fib.rkt:5:9 fib> 4) (#<syntax:fib.rkt:5:9 fib> 3) ... like this?


shu--hung
2021-1-15 19:34:38

I can’t get (require trace) to work; not sure why.


shu--hung
2021-1-15 19:35:16

I guess it’s much like how you can’t (require errortrace) to enable errortrace.


capfredf
2021-1-15 19:41:16

@ryanc @mflatt #lang racket (require syntax/parse) (define-syntax-class (core-method register/method register/self) #:literal-sets (kernel-literals) #:attributes (form) (pattern (let-values ([(meth-name:id) meth:expr]) meth-name-2:id) #:when (number? (syntax-e #'meth) ) #:with form (begin (eprintf "in the 1st pattern; current syntax ~a ~n" this-syntax) #'10)) (pattern ((~and head let-values) ([(meth-name:id) meth] ...) meth-name-2:id) #:declare meth (core-method (begin (eprintf "~nin the second pattern; current syntax ~a ~n" this-syntax) register/method) register/self) #:do (register/method #'meth-name-2) #:with (plam-meth ...) (begin (eprintf "method is ~a ~a ~n" #'(meth-name ...) #'meth-name-2) (for/list ([meth (in-list (syntax->list #'(meth.form ...)))]) meth)) #:with form #'(head ([(meth-name) plam-meth] ...) meth-name-2))) (define test #'(let-values ([(hi) (let-values ([(world) 10]) world)]) (hi 20))) (syntax-parse test [(~var meth (core-method (lambda (x) x) (lambda (x) x))) #'42]) According to the debug message, It looks like the inner let-values matched both the first and second pattern, but I don’t think that’s true. I believe there must be some backtracking that happened, but I have some trouble figuring out the details.


capfredf
2021-1-15 19:46:04

or is the way I debug a syntax class wrong?


sorawee
2021-1-15 20:01:40

This seems to work as expected to me. What’s weird about it?


capfredf
2021-1-15 20:05:39

in the 1st pattern; current syntax #<syntax:/Users/capfredf/code/test.rkt:25:29 (let-values (((world) 10)) world)> in the second pattern; current syntax #<syntax:/Users/capfredf/code/test.rkt:25:29 (let-values (((world) 10)) world)>


capfredf
2021-1-15 20:06:56

The error message seems to say the first pattern was matched, but somehow the second pattern was also used for the same syntax object.


sorawee
2021-1-15 20:07:19

So, consider:

#lang racket (require syntax/parse) (define-syntax-class my-class (pattern (x:my-class2 3))) (define-syntax-class my-class2 (pattern _ #:do [(println (list 'a this-syntax))]) (pattern _ #:do [(println (list 'b this-syntax))])) (define test #'(1 2)) (syntax-parse test [x:my-class #'42])


capfredf
2021-1-15 20:08:40

ah, I sort of understand


capfredf
2021-1-15 20:09:52

Are you saying patterns in syntax class don’t work like clauses in syntax-parse or cond?


sorawee
2021-1-15 20:12:08

cond definitely can’t backtrack. I don’t think I know enough about syntax-parse clauses evaluation.


capfredf
2021-1-15 20:14:15

I kind of wanted to how backtracking work in detail in this case.



sorawee
2021-1-15 20:15:25

I’ve never used it though


capfredf
2021-1-15 20:19:55

So, the first time, the first pattern in my-class-2 matched. When 3 didn’t match 2, we were back to x:my-class2, but this time, the second pattern in my-class-2 were used.


sorawee
2021-1-15 20:20:24

yes


capfredf
2021-1-15 20:21:36

Thank you very much!


greg
2021-1-15 20:22:25

@curiouslearn How are you making the requests?


greg
2021-1-15 20:23:06

i.e. what is the client?


curiouslearn
2021-1-15 21:37:26

I am opening the page in my standard Brave Browser.


curiouslearn
2021-1-15 21:42:01

Thank you @greg. Here is the full code in case it is helpful. Also, I am running the application itself by opening a racket repl and then using (enter! "serve.rkt") (define stop (serve 3500))

The full code:

#lang racket (define (serve port-no) (define main-cust (make-custodian)) (parameterize ([current-custodian main-cust]) (define listener (tcp-listen port-no 5 #t)) (define (loop) (accept-and-handle listener) (loop)) (thread loop)) (lambda () (custodian-shutdown-all main-cust))) (define (accept-and-handle listener) (define cust (make-custodian)) (parameterize ([current-custodian cust]) (define-values (in out) (tcp-accept listener)) (thread (lambda () (handle in out) (close-input-port in) (close-output-port out)))) ;; time-out watcher (thread (lambda () (sleep 10) (custodian-shutdown-all cust)))) (define (handle in out) (println (regexp-match #rx"(\r\n\|^)\r\n" in)) (display "HTTP/1.0 200 Okay\r\n" out) (display "Server: k\r\nContent-Type: text/html\r\n\r\n" out) (display "<html><body>Hello, world!</body></html>" out))


rdu.hari
2021-1-15 23:39:19

@rdu.hari has joined the channel


rdu.hari
2021-1-15 23:41:05

would someone know how to fix an “ssl connect failed” error when I try to install a package using raco on ubuntu? I am using verion 7.9 from the ubuntu repo


shu--hung
2021-1-15 23:52:39

Do you have the complete: error message after ssl-connect: connect failed (.....` ?

plus, by ubuntu repo do you mean Ubuntu PPA by takikawa?


greg
2021-1-16 01:13:44

@curiouslearn That code works for me, using Firefox on Linux as the client. I see the “Hello world” response in the browser. I don’t know why it wouldn’t be working, for you.


greg
2021-1-16 01:15:01

As for your other question, try changing the regexp to #rx"(.*\r\n\|^)\r\n". The new .* portion will match the request before the \r\n so you’ll see it printed out. (The original regexp skips past it until the \r\n.) But that’s more about regexps than about TCP or HTTP.


greg
2021-1-16 01:21:18

@soegaard2 a link between those would be handy, I remember being confused by that before


greg
2021-1-16 01:22:11

As it happens I’ve been working on a racket/trace alternative, and decided to call it “vestige” because naming something else with “trace” would be unhelpful. :slightly_smiling_face: https://github.com/greghendershott/vestige/blob/master/vestige-doc/vestige/vestige.scrbl#L43-L47


curiouslearn
2021-1-16 02:14:35

@greg Sorry about not being clear. I had no trouble seeing the output in the browser with the original regex. The problem was that it was not printing the request in the repl. It was printing the output (#"\r\n\r\n" #"\r\n") instead of printing the request.

With the change in regex to #rx"(.*\r\n\|^)\r\n" the strange behavior with using (port->string) returns. (1) Hello world output is not shown in the browser; (2) The request is shown only after the second time I send the request.

Thank you very much for your help. Please don’t worry about replying. I don’t want to take more of your time with this. I was hoping to understand this for learning purposes. I won’t be using these basic tcp code to code the web pages anyway. Thanks again!


jestarray
2021-1-16 06:11:09

I’m using a snapshot from today version 8.0.0.1--2021-01-15(28105b7/a) and i cant even close out the tabs… the X isn’t even working. Are you guys running into this issue? Not sure if my 4k monitor has something to do with it


shu--hung
2021-1-16 06:12:04

What OS and bc or cs?


notjack
2021-1-16 06:15:28

resyntax can now properly indent its refactored output code :tada:


tom640
2021-1-16 07:47:59

@tom640 has joined the channel


tom640
2021-1-16 07:56:39

Would just like to thank everyone involved for their work on Racket; it’s my first foray into Lisps and it’s such an elegant and helpful language (I’m doing the UBC HTDP video course on edX). I really appreciate all the work you’ve done!