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

Deja vu. For/fold is close though.

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

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

(into-max)
;)

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

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

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

yup, at least if there’s custom comparators involved


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

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

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

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

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

That is a pretty fabulous example.

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:

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


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

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

no, I thought I posted that in a thread

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.

IIRC that was for @dvanhorn


thanks!

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

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?

$ 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?

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

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

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

or is the way I debug a syntax class wrong?

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

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

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

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

ah, I sort of understand

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

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

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


I’ve never used it though

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.

yes

Thank you very much!

@curiouslearn How are you making the requests?

i.e. what is the client?

I am opening the page in my standard Brave Browser.

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 has joined the channel

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

Do you have the complete: error message after ssl-connect: connect failed (.....
` ?
plus, by ubuntu repo do you mean Ubuntu PPA by takikawa?

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

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.

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

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

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

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

What OS and bc or cs?

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

@tom640 has joined the channel

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!