curiouslearn
2021-1-14 13:26:22

@greg Thank you for the reply. I changed the line (regexp-match #rx"(\r\n\|^)\r\n" in) to (println (regexp-match #rx"(\r\n\|^)\r\n" in)) However, when I visit the url, this is what it prints in the REPL '(#"\r\n\r\n" #"\r\n") .


curiouslearn
2021-1-14 13:33:04

> If the client waits to finish writing the request, before trying to read the response, Thanks. That explains why the regexp line is required. However, shouldn’t the port->string command also read the whole request? Incidentally, even that does not output the request until after a timeout occurs (or I visit the page twice). I need to figure that out. But it does not print it out immediately.


samth
2021-1-14 17:43:51

Anyone who’s used racketscript: is there an easy way to just run the “fully expanded programs to JS” function, instead of using the whole pipeline? (maybe @stchang)


massung
2021-1-14 17:59:52

Okay, got an interesting thing I’d like to do, but not sure if it’s doable…

• I want to be able to tell if my program launched from a Racket REPL (I’m OK w/ it being specifically from DrRacket, but knowing it “was executed from REPL” would be ideal) • If the above is #t, I’d like to be able to “interrupt” my running program, drop back to the same REPL source (not necessarily the same REPL). And - upon either leaving the REPL or calling a (call/cc?) function, continue my previously running code from where it left off. I realize I can create a sandbox and just call something like (read-eval-print-loop) from within my code, but then it requires me to create my own terminal-like environment to run it in, which I really would like to avoid if possible. I’m running a graphical program, and unless it’s dirt simple to pop open a new terminal window with a REPL, I’d rather just drop back to DrRacket’s terminal (or Emacs) and get all the benefits of those environments.

I’d also prefer to not launch the program from the REPL in another thread, because what I intend to do from the REPL after interrupting the program would require retro-fitting a lot of thread-safety and such.

Example use: imagine I’ve launched an OpenGL program from the REPL, which is now stuck waiting for the function to exit. Now, I’d like to drop back to the REPL in order to play around with something like (set! camera-fov 45.0) and then continue and see how it changes things.


greg
2021-1-14 18:14:17

I’m not sure all the pieces (e.g. what “run from REPL” means and how to detect it), or how to arrange them. But a couple pieces might be:


greg
2021-1-14 18:14:50

massung
2021-1-14 18:17:04

Ah, that might be a pretty simple solution! I’ll check into it. Thanks :slightly_smiling_face:


greg
2021-1-14 18:17:10

Not sure about GUI programs’ handling of stdin/stdout, but: You could parameterize current-{input output}-port around (read-eval-print-loop), and set them to some other port. Like TCP. Or unix domain socket. That is connected to a terminal via waves hands idk how exactly.


greg
2021-1-14 18:18:10

Or maybe there’s a way to capture the original in/out ports, before GUI redirects them (if it even does that), and supply those ports around r-e-p-l.


greg
2021-1-14 18:19:14

Also see https://pkgs.racket-lang.org/package/debug. That’s for a predefined point. Not on-demand. But maybe helpful for you anyway, idk.


soegaard2
2021-1-14 19:32:49

@massung Is Tony’s reloadable any use in your use case? https://github.com/tonyg/racket-reloadable


capfredf
2021-1-14 20:26:38

@mflatt for a user-defined method, the Racket’s OO system initially inserts a self parameter as the first one, but after the program is fully expanded, the self parameter could be moved to the second or third position. (e.g, keyword methods). However, Typed Racket assumes the first parameter is self, which might cause problems. Is there any reliable way to tell which parameter is self? (checking if the prefix of the name of a parameter is “self” is not enough) cc @samth


mflatt
2021-1-14 20:43:19

I’m not sure I understand the question. For a function representing a method, “self” is always the first by-position position. The expansion of a method that has keyword arguments will involve a helper function that takes “self” after keyword arguments, but that helper function isn’t the method; it will be referenced in a make-keyword-function — really make-optional-keyword-method or something like that — to construct the method. So, it would be possible to infer that a non-first argument to a helper function corresponds to “self” by seeing it use in a make-optional-keyword-method that creates a method.


jbclements
2021-1-14 21:00:21

Is anyone else here using a recent build seeing way too much space around the names of tabs? I’ve verified that this does not occur in the release candidate, so it’s either a more recent change, a consequence of packages I have installed, or some other terrible foolishness on my part. To see what I mean, here’s a screenshot:


capfredf
2021-1-14 21:03:34

Thank you for the explanation. I didn’t make myself clear. The problem is about those helper functions. (e.g. https://gist.github.com/capfredf/b3f9e4411daa068c9ca2cd1c653a0bb0#file-exanded-rkt-L72) TR checks every lambda form in a fully expanded program. In this case, TR sees x11:51 as self


shu--hung
2021-1-14 21:09:37

I’m on gui-lib 8b523ad from Jan 2th and DrRacket 3a07fc0 from Jan 4th and I don’t see this.

I can update my gui-lib to HEAD later today and see if it’s cause by this flat-portable style https://github.com/racket/gui/commit/93fd2ebabafcc24cea943a6df8a7eaf1a47f4eb2


mflatt
2021-1-14 21:16:37

I don’t understand why TR would see that lambda as a method, since it doesn’t flow to the list of methods for a class. The result from line 92 does, though.


mflatt
2021-1-14 21:17:40

Mouse over one of those tabs, and you’ll see an “x” to close the tab appear.


shu--hung
2021-1-14 21:22:01

Ah, yes I also see this (with hidden "X"s) if I open more files.


dvanhorn
2021-1-14 21:59:05

Does anyone have a nice scribble hack for conditionally showing content based on the date the document is built? I’d like to set up a course web page where each assignments is it’s own include-section’d document and each assignment module provide a release-date; if the document is built before the release date, it shows a placeholder; otherwise it includes the document as usual?


dvanhorn
2021-1-14 22:40:11

include-section is pretty simple, so I was able to make my own variant that is pretty close to what I’m after #lang racket (provide include-section-if-released) (require racket/date) (define-syntax (include-section-if-released stx) (syntax-case stx () [(_ mod) (with-syntax ([doc-from-mod (datum->syntax #'mod 'doc)] [rel-from-mod (datum->syntax #'mod 'release-date)]) (unless (module-path? (syntax->datum #'mod)) (raise-syntax-error #f "not a module path" stx #'mod)) #'(begin (require (only-in mod [doc-from-mod doc] [rel-from-mod release-date])) (if (< (date->seconds release-date) (current-seconds)) doc "Not yet released")))]))


ben.knoble
2021-1-14 22:49:25

ben.knoble
2021-1-14 22:51:27

Just changed the text-area to a monospace as well, but this is a hack I put together today using racket/sandbox


jbclements
2021-1-15 00:24:59

Interesting… but it looks like the space for the “X” is being left blank on both sides of the tab?


samth
2021-1-15 01:15:40

I have some relevant code (by @ccshan) that I can post in a bit


dvanhorn
2021-1-15 01:19:45

thanks


shu--hung
2021-1-15 02:02:02

Yeah, seems weird that tab captions are centered with blank spaces on both sides.


notjack
2021-1-15 03:08:57

Would anyone happen to know where the implementation of the default DrRacket s-expression indenter is?


greg
2021-1-15 03:11:11

A couple months ago I could have told you offhand, because I was deep into a branch exploring having Racket Mode use lang-supplied lexers and indenters.


greg
2021-1-15 03:11:19

Let me see if I can find it again…


sorawee
2021-1-15 03:13:44

I recall there’s a method named like find-amount-to-indent or something like that


sorawee
2021-1-15 03:14:06

Oh, it’s compute-amount-to-indent



sorawee
2021-1-15 03:14:11

Close enough


notjack
2021-1-15 03:14:20

Would it be a bad idea to just… reimplement this without depending on all the gui framework nonsense


greg
2021-1-15 03:15:14

Well, from my POV as a non-GUI potential user of it, heck yes. :smile:


greg
2021-1-15 03:16:01

The color-lexer thing especially is kind of all wrapped up with the edit% or whatever thingie … my brain has swapped out all the names a couple months ago.


greg
2021-1-15 03:16:19

With some warm up, though, I could rant and propose at some length. :smile:


greg
2021-1-15 03:17:10

I mean, clean sheet of paper, it’s easy. 10 or 20 years ago, I 100% understand doing things however they were done, just to make something as ambitious as DrRacket a reality, at all.


sorawee
2021-1-15 03:17:15

Maintaining it would be cumbersome though, since any changes to the original implementation will need to be updated in the reimplementation.


sorawee
2021-1-15 03:17:25

But @greg probably did that already, in Emacs


sorawee
2021-1-15 03:18:11

So I guess that’s an improvement from that perspective?


notjack
2021-1-15 03:19:44

Maybe I’ll rip it out and make it part of the standard distribution somehow?


greg
2021-1-15 03:20:25

A couple notes I made:


greg
2021-1-15 03:20:40

Simple “syntax highlighting” only needs a lexer: A stream of tokens classifed as various “kinds”, so each kind can get its own appearance, customizable by the end user. An editor or indenter will want to access the resulting “token map” with something like a ~data/interval-map~ interface: Given a position, get the token and its bounds (its position span as a half-open interval, a.k.a. “from” and “upto”).


greg
2021-1-15 03:20:56

To do indentation and basic navigation editor commands, slightly more is needed. The tokens need to be consumed by a simple reader — not a full Lisp reader, but one which at least consumes “open” and “close” tokens to discover “expressions” or “blocks” that are nested arbitrarily deeply. (Unlike a full Lisp reader, token values remain strings like “123”, “’symbol”, "#:hash-keyword".) These open and close tokens could be single-character delimters like parens, brackets, and braces. Or they could be multi-character keywords like “begin” and “end”. In an offside rule lexer they could even be “indent” and “outdent” tokens. Then a token-map can provide some helpers to navigate these expressions — much like Emacs and text<%> functions like “forward-sexp”, “up-list”, and so on.

Also, because indentation is line-oriented — it matters if tokens are on the same line, or not — it helps if a whitespace token produced by a lexer like " \n " is transformed to four tokens: " " "\n" "\n" " ".


notjack
2021-1-15 03:22:28

hmm


notjack
2021-1-15 03:22:32

lots of thinking to do


shu--hung
2021-1-15 03:23:50

After all, it’s old code with 10 yrs of history. Plus you only know how to structure things more reasonable after it has been tried once.

The data structure maintenance code, GUI interaction code and Racket-specific parenthesis matching code are all coupled together in a single mixin so well..


greg
2021-1-15 03:23:52

Also I was reading so-called tree-sitter parsers that emit “concrete” syntax trees instead of abstract syntax trees. But that kind of gave me a headache and I convinced myself that a token-map could be updated efficiently given change notifications. But I could have been wrong. shrug


notjack
2021-1-15 03:26:15

In my case I don’t need something fast, since I’m using it for resyntax output


greg
2021-1-15 03:27:48

I think the TL;DR is that you definitely could split out the sexp indenter stuff from GUI stuff. I think you’ll find you want some basic “sexp nav command” type functions to do indenting. Like at least “forward sexp”, “backward sexp”, “up to parent sexp”. Maybe a couple more.


greg
2021-1-15 03:28:10

So it’s natural to just use the DrRacket or Emacs commands for those, when available. Ergo the status quo.


greg
2021-1-15 03:29:56

FWIW this is mostly the stuff on that branch that’s relevant, in this folder: https://github.com/greghendershott/racket-mode/tree/lang-lexer/racket/token-map


greg
2021-1-15 03:30:23

Well, it’s what I came up with, anyway. shrugs


greg
2021-1-15 03:36:42

Oh ha ha I forgot. I wrote a small rant in the form of a long comment, plus an attempt to bandaid the status quo: https://github.com/greghendershott/racket-mode/blob/lang-lexer/racket/token-map/private/core.rkt#L281-L348


shu--hung
2021-1-15 03:44:37

wow that profj comment.. I suppose at that time the #lang protocol didn’t even exist


greg
2021-1-15 03:52:45

Yes I assume that’s the timeline. Again, any “ranting” was re the situation not the history!


greg
2021-1-15 03:53:46

I started working on this branch thinking, well, maybe a non-sexp Rhombus is inevitable, so maybe I’d better try to prepare. And also, maybe more importantly, the #lang vision is people’s own non-sexp langs should work well in Racket Mode, too.


greg
2021-1-15 03:54:25

And honestly for Rhombus it ought to be an eat your own dogfood thing where it’s using the same #lang mechanisms and tooling specs, as everyone else. Regardless of the surface syntax.


greg
2021-1-15 03:54:56

That’s not the case for DrRacket and Racket, entirely. Which again is understandable. But probably going forward it’s a good goal.