xuuexu
2020-2-28 09:38:31

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


soegaard2
2020-2-28 09:44:44

@xuuexu What kind of operations do you need


xuuexu
2020-2-28 10:09:55

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


chris613
2020-2-28 13:38:15

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


chris613
2020-2-28 13:38:28

are there any techniques for reducing my search space ?


robby
2020-2-28 15:50:40

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


robby
2020-2-28 15:50:48

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


robby
2020-2-28 15:50:51

but this one doesn’t:


robby
2020-2-28 15:50:58

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


robby
2020-2-28 15:52:39

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.


robby
2020-2-28 15:52:58

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


robby
2020-2-28 15:55:18

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.


robby
2020-2-28 15:55:23

@mflatt may recall more


robby
2020-2-28 15:55:32

@greg ^


robby
2020-2-28 15:56:06

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


samdphillips
2020-2-28 19:02:14

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.


samdphillips
2020-2-28 19:03:15

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


samdphillips
2020-2-28 19:03:31

At least not through the public API


samdphillips
2020-2-28 19:09:31

Maybe possible by passing in a fake SSL tunnel.


leif
2020-2-28 19:30:06

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


leif
2020-2-28 19:30:10

(In pdf output)


leif
2020-2-28 19:30:35

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


leif
2020-2-28 19:31:08

leif
2020-2-28 19:35:27

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.


leif
2020-2-28 19:37:57

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


blerner
2020-2-28 19:38:12

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)


blerner
2020-2-28 19:38:56

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


leif
2020-2-28 19:40:30

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


leif
2020-2-28 19:41:05

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


leif
2020-2-28 19:41:17

But i’m going to check \strut first…


notjack
2020-2-28 19:41:25

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


notjack
2020-2-28 19:42:19

Weird, I don’t remember doing anything in Scribble


notjack
2020-2-28 19:42:32

which commits?


leif
2020-2-28 19:47:42

@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


leif
2020-2-28 19:48:43

So it looks like 3c62d4cd5


leif
2020-2-28 19:53:24

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


leif
2020-2-28 19:53:31

Just….ewww…


greg
2020-2-28 20:30:10

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.


greg
2020-2-28 20:35:13

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.


greg
2020-2-28 20:35:53

(< bad good perfect) :simple_smile:


greg
2020-2-28 20:49:59

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


robby
2020-2-28 20:55:07

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


robby
2020-2-28 20:55:20

But I haven’t found time to properly investigate


notjack
2020-2-28 20:55:49

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


notjack
2020-2-28 20:56:15

(but I fear backwards compatibility dragons)


spdegabrielle
2020-2-28 21:21:42

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


samth
2020-2-28 21:59:51

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


lukasalazarek
2020-2-28 22:02:32

Yes, please submit anything you think is interesting!


notjack
2020-2-28 22:23:01

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.


lukasalazarek
2020-2-28 22:47:01

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.


plragde
2020-2-29 01:14:56

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.


robby
2020-2-29 01:55:21

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


robby
2020-2-29 01:55:33

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


robby
2020-2-29 01:56:23

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


robby
2020-2-29 01:56:30

When printing int he REPL these should be the same thing


robby
2020-2-29 01:57:04

Because, by default current-print calls print


robby
2020-2-29 01:57:19

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


robby
2020-2-29 02:02:45

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


robby
2020-2-29 02:03:28

@greg ^


deactivateduser60718
2020-2-29 03:55:30

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


sorawee
2020-2-29 04:24:01

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.


sorawee
2020-2-29 04:25:02

deactivateduser60718
2020-2-29 04:27:08

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


deactivateduser60718
2020-2-29 04:27:55

Also, TIL about with-module-reading-parameterization


sorawee
2020-2-29 04:28:57

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


greg
2020-2-29 04:38:54

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.


greg
2020-2-29 04:41:36

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.


greg
2020-2-29 04:44:42

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


greg
2020-2-29 04:50:14

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.


greg
2020-2-29 04:51:21

Is it something like this-stx??



sorawee
2020-2-29 04:54:24

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


greg
2020-2-29 04:56:02

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.


sorawee
2020-2-29 04:57:22

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


greg
2020-2-29 04:58:24

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.


rokitna
2020-2-29 04:58:53

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


rokitna
2020-2-29 05:03:12

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


deactivateduser60718
2020-2-29 05:03:15

Ah, switching to current-namespace does it.


rokitna
2020-2-29 05:03:31

doing appropriate things to update the variables in between


sorawee
2020-2-29 05:03:50

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.


sorawee
2020-2-29 05:05:21

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


rokitna
2020-2-29 05:05:40

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


sorawee
2020-2-29 05:05:40

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


rokitna
2020-2-29 05:06:03

oh yeah, you were one step ahead of me XD


sorawee
2020-2-29 05:06:10

haha


sorawee
2020-2-29 05:06:35

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


sorawee
2020-2-29 05:07:03

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


sorawee
2020-2-29 05:07:43

Nice!


rokitna
2020-2-29 05:08:59

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


sorawee
2020-2-29 05:10:34

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


rokitna
2020-2-29 05:11:16

oh, nifty XD


sorawee
2020-2-29 05:12:34

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


sorawee
2020-2-29 05:12:43

sorawee
2020-2-29 05:16:20

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