
Hi, is there any curl
api binding in Racket or equivaliant, I want to use it for unix socket :blush:

@xuuexu What kind of operations do you need

curl --unix-socket unix:///var/run/docker.sock http:/v1.24/images/json

ok …. so a question about the csp module … or maybe just CSP in general…. the search space is something akin to “product of all the lengths of the variable lists” so with 5 variables of 20 posibilities the search space is 3200000

are there any techniques for reducing my search space ?

I think that maybe I was confused. I see that this program produces a blue circle in drr:

#lang racket
(require pict)
(print (colorize (disk 40) "blue"))

but this one doesn’t:

#lang racket
(require pict)
(write (colorize (disk 40) "blue"))

Looking at the source code of DrRacket, I see that DrRacket is setting the global-port-print-handler
(in language.rkt) and I believe that that’s what achieves this printing.

That is, it looks like DrRacket does not set current-print

I have lost track of a nice example as to why this is the right way to go, but I vaguely recall it has something to do with the idea that the programming language is going to set current-print
so the changes the IDE makes to it might be clobbered.

@mflatt may recall more

@greg ^

(And I’m sure the test suites in DrRacket would fail if it wasn’t set up the way it is. But this isn’t exactly a first-principles argument :wink:)

I’ve thought about trying it, but haven’t yet using https://docs.racket-lang.org/unix-socket/index.html to just connect to the docker socket.

Ideally you could pass a port pair to net/http-client
, but from the docs that doesn’t look possible.

At least not through the public API

Maybe possible by passing in a fake SSL tunnel.

Has anyone here tried to use code:hilite
in scribble?

(In pdf output)

The code for @racketblock[(code:hilite (+ 1 2))]
looks like:


Also, looking at the generated code, it looks like a new \highlighted{} block is inserted arround every lexeme. But if I remove all of the extra \highlighted{ blocks it actually shows up correctly.

@notjack and @mflatt git blame seems to point to you?

that output makes sense. another solution is to automatically insert a \strut
(assuming you’re in math mode) into each \highlighted
block; that’ll make the heights all have the same minimum height (which will match the height of the parens)

I’m pretty sure I gave up on pdf output for lecture notes at one point because of this; I didn’t feel like sinking time into a solution

Ya….sadly we need it for our ICFP paper.

Although I’m thinking if I use pict
to insert the word, than maybe it would also work.

But i’m going to check \strut
first…

FFI bindings to libcurl
would give Racketeers access to a high quality http2 implementation, which would be amazing

Weird, I don’t remember doing anything in Scribble

which commits?

@notjack 21:57:16 –0700 523) (eq? (syntax-e (car (syntax-e c))) ’code:hilite)) 3c62d4cd5 scribble-lib/scribble/racket.rkt (Jack Firth 2019–10–09

So it looks like 3c62d4cd5

@blerner You’ll hate this, but this seems to work: @racketblock[(+ #,(elem #:style highlighted-color (racket (+ 1 2))) 3)]

Just….ewww…

Trying to extract the position for an exn
is… interesting.
Sometimes exn:srclocs?
is true, but calling exn:srclocs-accessor
gives an empty list. So next you see if it’s exn:fail:syntax
or exn:fail:read
— but be careful you don’t match the subclass exn:fail:read:eof
! — and if so use the extra exprs
member, which is a list of syntax
. Sometimes that list is empty. Sometimes it has syntax… but for which syntax-position
returns #f
. Ugh.
So you try all those techniques that are documented in various places. As a final fallback, you can try to parse /path/to/file.rkt:1:0:
in the exn-message
. But also, be careful because some things use line.col
not line:col
. :cry: (Oh also: line:col is not position and span, so you get to convert.)
And you do all that, and feel like there are probably still more variations lurking…. So… yeah. :simple_smile: To be clear: This is just amused venting, not complaining. I understand there’s a lot of history, and sometimes improving things means not-improving old ways because compatibility.

That is, having structured errors is good, and making use of that is good, even when there are various structures and even when some old things still just report “stringly typed” errors.

(< bad good perfect)
:simple_smile:

@robby Thanks. That rationale/scenario — “the programming language is going to set current-print
so the changes the IDE makes to it might be clobbered” — makes sense to me.
I guess I’m not immediately sure how using global-port-print-handler
will avoid that, as it seems likely a language’s implementation of current-print
will use print
, and be affected anyway? But probably I’m just lost among the various things with “current” and “handler” and “print” in the name. Probably they all fit together in a way that avoids the problem.

Yeah, that’s where I got stuck just thinking about it.

But I haven’t found time to properly investigate

Would you happen to have a list of places that generate exceptions without good source locations? Maybe we can improve things.

(but I fear backwards compatibility dragons)

FYI
> PLT @ Northwestern is seeking out programs to help us understand the performance of Racket “in the wild”. > If you have any Racket applications that you use and care about how it performs, please let us know about them in the following survey:
https://forms.gle/b2eKMZdvXjpRHKL38\|https://forms.gle/b2eKMZdvXjpRHKL38

@lukasalazarek do you want parts of the racket distribution as submissions? Iow, should I submit Typed Racket or things like that?

Yes, please submit anything you think is interesting!

Will the list of programs be available to non-PLT folks? I want to use this to understand what sort of performance obstacles there would be if I was trying to use transducers in these projects.

We can ask the authors of the programs for approval and make available a list of all of those that approve. We hope to eventually build a large benchmark suite for the Racket community.

I don’t care enough about hierarchical numbering to suffer for it, and simple consecutive numbering presumably doesn’t care about phases. So let me see if the most primitive of state-based counters suffices.

Okay, I think I see what’s going on.

I was confused about the relationship between print
and current-print

racket mode is setting current-print
which affects the REPL. DrRacket sets the current-port-print-handler
.

When printing int he REPL these should be the same thing

Because, by default current-print
calls print

But if the program calls print
directly, then emacs mode and drracket should do different things

And yeah, that’s what I seem to see as different in racket-mode’s run of a program and DrRacket.

@greg ^

How do I instantiate the anonymous module produced below? This doesn’t work. (EDIT: got it working. Code edited to match answer)
#lang racket/base
(require syntax/modread)
(define racket-code "#lang racket/base\n(displayln \"hello\")")
(with-module-reading-parameterization
(λ ()
(define port (open-input-string racket-code))
(define user-module/stx (read-syntax (object-name port) port))
(define checked (check-module-form user-module/stx 'ignored "not a #lang module form"))
(eval-syntax checked (current-namespace))
(dynamic-require ''anonymous-module #f)))

Question: what’s the easiest way to obtain the smallest piece of surface syntax object that expands to the current invocation in a macro.
As an example:
(define-syntax-parser my-cond
[(_ [{~literal else} else-expr]) #'else-expr]
[(_ [test-expr then-expr] clause ...) #'(if test-expr then-expr (my-cond clause ...))]
[(_) (raise-syntax-error HERE)])
I want to be able to obtain the very original syntax object at HERE
. That is, to obtain (my-cond [(number? x) 1] [(string? x) 2])
that appears textually in the surface program, and not simply (my-cond)
.
Note that I understand that we can check the well-formedness of my-cond
at the very beginning, but my actual use-case is much more complex, and checking first wouldn’t suffice.


Some, yes. It led me to syntax/modread
. Didn’t yet see how to actually load the module once it’s read.

Also, TIL about with-module-reading-parameterization

Ah, I misunderstood what you are trying to do / what you got working already.

Racket Mode with two options on: Pretty print results in the REPL. Print images in the REPL. Note that user program’s use of print
is not affected — just what read-eval-print-loop
prints. Because Racket Mode is using current-print
.

Dr Racket with defaults. Note that it prints images, both ways. However, as for the list value: Note that the user’s print
is plain and one line (it wraps int the narrow window. The REPL’s printing of the list value has a line-break, i.e. it seems to be pretty-printed.

@robby See above. I don’t understand how/why Racket Mode’s behavior is wrong. It only affects what it’s own REPL prints, which is an end-user option. Use of print
in the user program is not affected, e.g. if they use print
to output data to a file or network connection. (I wouldn’t say that Dr Racket’s behavior is wrong, either.)

define-syntax-parser
sugars away the whole (define-syntax (my-cond stx) (syntax-parse stx ____))
business, in which I think you want stx
here? ISTR it defines something for stx
for just this situation, not sure of the name.

Is it something like this-stx
??


Unfortunately, this-syntax
would result in (my-cond)
in the above example

What if you not use define-syntax-parser
and instead write it out as the define-syntax (my-cond stx) (syntax-parse stx ___))
form? Maybe this-syntax
is bound to some inner piece where you use it, not the original whole thing which is what stx
is in the full form.

The main challenge, I think, is how to obtain the original surface syntax in the recursive expansion.

Oh OK I don’t think I understood that aspect. I’d still try to break it into simpler pieces that do less, would be my personal strategy.

Instead of generating another macro call to my-cond
, you could perform some recursion and call syntax-parse
again during the expansion of the original my-cond
call

like, as a rough sketch, imagine inserting a named let (let next ([remaining-stx stx]) ...)
between the define-syntax
and the syntax-parse
, and then use something like #
(if test-expr then-expr #,(next remaining-stx))`

Ah, switching to current-namespace
does it.

doing appropriate things to update the variables in between

I think that won’t do it either. Let me try to give you my actual problem that might be more illustrative:
I currently have this macro:
(define-syntax verify
(syntax-rules ()
[(_ #:assume pre #:guarantee post)
(∃-solve `(,@(asserts)
,@(eval/asserts (thunk pre))
,(apply \|\| (map ! (eval/asserts (thunk post))))))]
[(_ #:guarantee post) (verify #:assume #t #:guarantee post)]
[(_ post) (verify #:assume #t #:guarantee post)]))
That is, the full form that has all options has #:assume
and #:guarantee
. The shortcut forms don’t have all of these keywords, but they expand to the full form.
The question is, how can I access something that users actually write in the full form case.

I can certainly create a helper macro that accepts a “whole syntax” explicitly, like this

maybe it could work to do it the way match/derived
does it: it explicitly takes an subexpression that represents the “original” expression for error message purposes, so other macros can expand into match/derived
calls

(define-syntax verify-help
(syntax-rules ()
[(_ full-stx #:assume pre #:guarantee post)
(∃-solve `(,@(asserts)
,@(eval/asserts (thunk pre))
,(apply \|\| (map ! (eval/asserts (thunk post))))))]))

oh yeah, you were one step ahead of me XD

haha

So yeah, I know that trick. It’s just so cumbersome to actually do it

And even more annoying if you have a recursive macro, since you need to keep passing the original syntax around

Nice!

hmm, that sounds like a situation that could be made more concise using syntax-parameterize
somehow

You reminded me that I in fact has one project that use syntax-parameterize
to do exactly this

oh, nifty XD

@rokitna this is what I created, but there are fundamental design flaws, so I haven’t published yet


OK, I’m just really forgetful. This is a problem I solved already, and I should have just used my own library….