pocmatos
2018-7-17 12:09:16

I would like to parse racket code in order to find code matching some templates. What’s the best way to go about this? The point here is to check that my code is consistent and remind me of things that I might have forgotten. For example, for for/vector I would like to add a note that I should be using the #:length keyword, if possible. This in turn means that I cannot have a purely regexp parser. I need to ensure that the for/vector I am looking at comes from racket/base lang. Any suggestions on how to deal with this?


soegaard2
2018-7-17 12:11:03

Use read-syntax in a loop? And use syntax-parse to analyze each expression?


soegaard2
2018-7-17 12:12:11

Or … just thinking aloud … redefine for/vector to log any notes.


soegaard2
2018-7-17 12:12:40

But how does one redefine it - without actually changing the defintion … hmm.


soegaard2
2018-7-17 12:13:21

Maybe one can use the module name resolver ?


pocmatos
2018-7-17 12:15:50

using read-syntax makes sense. From the syntax output I should be able to inspect where it comes from. Will give it a go and see.


soegaard2
2018-7-17 12:17:09

@pocmatos You’ll need to expand the expression first, to get the binding information.


soegaard2
2018-7-17 12:20:07

Wait - this would be similar to the optimization coach. Maybe you there is something you can reuse?


pocmatos
2018-7-17 12:23:03

hummm, good idea.




greg
2018-7-17 13:13:53

Also at RacketCon N years ago @notjack demoed something like this.


greg
2018-7-17 13:15:24


soegaard2
2018-7-17 13:20:43

@notjack Can this be used in the for/vector example pocmatos mentioned?


spdegabrielle
2018-7-17 16:06:42

Hi, I noticed this the other day

It provides a nice file viewer panel for DrRacket. It’s still new but I like it. (Does what is says on the tin)

I don’t know the author, but they promptly accepted my PR to add a very basic scribble file —- http://docs.racket-lang.org/files-viewer/index.html https://pkgs.racket-lang.org/package/files-viewer https://github.com/MatrixForChange/files-viewer File Manager for DrRacket

From the readme: The project is under LGPL LICENSE (same as Racket).

Issues and pull requests are welcomed.


greg
2018-7-17 16:18:52

Neat.


greg
2018-7-17 16:19:06

greg
2018-7-17 16:19:32

also uses projectile and sets a keybinding to toggle neotree for the current project: https://github.com/greghendershott/.emacs.d/blob/master/init.el#L510-L533


leif
2018-7-17 16:46:59

@mflatt Is there any way to resolve the ‘self’ module path index?


leif
2018-7-17 16:47:18

Obviously (resolve-module-path-index (module-path-index-join #f #f)) results in an error…


samth
2018-7-17 16:47:53

@leif I think that’s a question where you need to back up at least one step


leif
2018-7-17 16:58:03

@samth Okay, how about this: “I want to serialize a reference to ‘this’ module, and later (as in within a different VM), expand to the referenced identifier.


leif
2018-7-17 16:58:19

(Obviously relative to the current module at the time of expansion.)


leif
2018-7-17 16:58:50

So by being a ‘this’ reference, it will expand to the identifier in the expanding module.


leif
2018-7-17 17:00:08

"


samth
2018-7-17 17:32:36

@leif depending on what you mean, there are parts of TR that do things like that


samth
2018-7-17 17:32:54

see, for example, the #%contract-defs-reference module that TR generates


leif
2018-7-17 17:35:15

@samth Sure, that seems to use define-runtime-module-path-index, which, iirc, can only be used at the top/module level, yes?


samth
2018-7-17 17:36:08

yes, although I don’t really see how it would work otherwise — you can’t expand to a lexical identifier from another module


leif
2018-7-17 17:37:31

Fair point.


leif
2018-7-17 17:38:05

I’m okay with limiting the definitions to top/module level (in fact, they already are), but the uses need to be lexical.


samth
2018-7-17 17:40:54

the uses of that are lexical


leif
2018-7-17 17:48:19

OH! It looks like module path indexes actually change when provided and then required into a different module…odd..


leif
2018-7-17 17:49:03

(or at least how they are printed….odd…)


leif
2018-7-17 17:53:47

@michael.ballantyne Seems to think this is because of syntax-module-path-index-shift, but we can’t seem to find much else about it.


samth
2018-7-17 17:54:16

I don’t think the indexes change


samth
2018-7-17 17:54:37

the evaluation of #%variable-reference produces different things, I think


leif
2018-7-17 18:01:05

That would make sense.


leif
2018-7-17 19:18:49

@samth Hmm….this still doesn’t seem to properly serialize. For example:


leif
2018-7-17 19:19:11
#lang racket

(require racket/runtime-path
         racket/serialize)

(define-runtime-module-path-index x ".")
(serialize x)

leif
2018-7-17 19:19:36

’((3) 0 () 0 () () (mpi “.” mpi (p+ #“/Users/leif/test/foo.rkt” . unix) . #f)


leif
2018-7-17 19:20:00

And when I deserialize it, (and resolve it), I still get the absolute path.


leif
2018-7-17 19:20:33

Meaning that it would be hard to store it in a file. :disappointed:


samth
2018-7-17 19:20:37

that sounds like a different issue than where we started


samth
2018-7-17 19:21:50

but I don’t understand why that’s hard to store in a file


leif
2018-7-17 19:22:08

Its hard because the file could have moved.


leif
2018-7-17 19:22:41

So, the original (stepped back) question was: “I want to serialize a reference to ‘this’ module, and later (as in within a different VM), expand to the referenced identifier.“, as such, what I’m imagining is something like:


mflatt
2018-7-17 19:22:57

Did you mean to pass #:relative-directory to serialize?


samth
2018-7-17 19:23:01

that doesn’t seem fixable — you can’t expand to a reference to a file that isn’t there any more


leif
2018-7-17 19:24:48

@mflatt AH!!! That’s why you wanted to split out #:relative-directory and #:deserialize-relative-directory! That makes so much more sense now.


leif
2018-7-17 19:25:50

(And yes, that does seem to work. Thanks. :slightly_smiling_face: )


leif
2018-7-17 19:26:29

@samth Nah, I don’t want a reference to the same instance of that file, I want a reference to the relative location of that file.


leif
2018-7-17 19:26:56

But what @mflatt pointed out works. So thanks to both of you. :smile:


samth
2018-7-17 19:27:16

right, but “relative location” isn’t necessarily going to work in the future either


leif
2018-7-17 19:28:53

Yup, you are correct.


leif
2018-7-17 19:29:12

But it does mirror Racket’s existing binding system, which is what I was going for. :slightly_smiling_face:


contact
2018-7-17 19:35:24

Hello! I’m experimenting with message passing between processes written in /= languages. Like a “ping-pong” app written in 2 different languages. Is there anything that compares to zeromq for such a task? Thx.


krismicinski
2018-7-17 19:35:48

Hi all, anyone have a handy guide on the preferred way to use bibtex with scribble?


krismicinski
2018-7-17 19:36:09

soegaard2
2018-7-17 19:36:55

soegaard2
2018-7-17 19:38:25

@krismicinski Also if you have an existing bibtex file: http://matt.might.net/articles/parsing-bibtex/


contact
2018-7-17 19:39:01

@soegaard2 Thx ! But is there something else that compares to that in the Racket world? w/o ZeroMQ, how would a racket program send and receive messages with other processes? In other words, is ZeroMQ a necessary dependency or not?


samth
2018-7-17 19:39:43

@contact if you want something super simple, I’d just use a pipe and read/write


samth
2018-7-17 19:40:04

obviously 0MQ is both more heavyweight and more featureful than that


krismicinski
2018-7-17 19:41:04

hmm… this lets me know how to parse, but doesn’t really let me just use bibtex as a database without a racket-based representation of it, I think?


pocmatos
2018-7-17 19:41:29

How can I get read-syntax to read a normal racket file without chocking on #lang racket ?


pocmatos
2018-7-17 19:41:55

Is there an automated way to transform it into a module, without the #lang line?


contact
2018-7-17 19:42:22

@samth OK, thx!


soegaard2
2018-7-17 19:42:24

@pocmatos read-language can handle the first line


pocmatos
2018-7-17 19:45:33

@soegaard2 interesting, it does. The description for it looks menacing. :slightly_smiling_face:


samth
2018-7-17 19:45:59

@pocmatos you should just call read-syntax


samth
2018-7-17 19:46:11

that’s how you transform it into a module


pocmatos
2018-7-17 19:46:28

read syntax is chocking on it. read: #lang not enabled in the current context



samth
2018-7-17 19:47:31

you have to enable it because it potentially executes arbitrary code


pocmatos
2018-7-17 19:49:28

ah, yes, I needed read-accept-lang and read-accept-reader. Thanks


pocmatos
2018-7-17 19:57:39

I am reading source with read-syntax and then using expand-syntax on the result parameterzied wtih make-base-namespace. However, I get module: unbound identifier; also, no #%app syntax transformer is bound in: module


pocmatos
2018-7-17 19:58:02

Basically I have (define source-syntax (with-input-from-file file (lambda () (read-syntax file)) #:mode 'text)) (define expanded-syntax (parameterize ([current-namespace (make-base-namespace)]) (expand-syntax source-syntax)))


mflatt
2018-7-17 20:00:55

@pocmatos You could use a namespace that has module bound, but I recommend adjusting the result of read-syntax with check-module-form, instead.


pocmatos
2018-7-17 20:06:14

Thanks. (expand (check-module-form ... works.


leif
2018-7-17 20:26:12

@mflatt Oh wait, never mind, that won’t properly solve it. While it will handle relative module movements, it won’t handle ‘self’ if ‘self’ is a renamed file. For example:


leif
2018-7-17 20:26:40
#lang racket ;; /Users/leif/test/renamed.rkt

(require racket/serialize
         racket/runtime-path)

(define-runtime-module-path-index here ".")
(serialize here
           #:relative-directory (current-directory))

leif
2018-7-17 20:26:53

Will evaluate to: '((4) 0 () 0 () () (mpi "." mpi (p* #"renamed.rkt") . #f))


leif
2018-7-17 20:27:34

But if I store that into the current file, rename the file, and then try to deserialize it, I’ll still get the old module-path-index.


leif
2018-7-17 20:28:08

(Which would be what you expect for a different relative file, but not for a ‘self’ reference.)


leif
2018-7-17 20:29:05

I guess it boils down to, ’is there any way to distinguish a relative module path from a ‘self’ module path.)


leif
2018-7-17 20:31:00

Oh wait, I guess #:relative-directory doesn’t actually need to be a directory at all, just any path:

(define-runtime-module-path-index here ".")
(serialize here
           #:relative-directory (build-path (current-directory) "renamed.rkt"))

leif
2018-7-17 20:31:27

@mflatt This seems like a pretty good indicator we should actually make the keywords be #:relative-path and #:deserialize-relative-path, thoughts?


mflatt
2018-7-17 20:33:56

I don’t think that will work in general. "<dir>/x.rkt" is not "../x.rkt" relative to "<dir>/y.rkt".


leif
2018-7-17 20:34:29

Mmm…good point. :disappointed:


mflatt
2018-7-17 20:35:14

It seems possible that you want a hook to replace module reference in serialize to complement the hook to replace module references in deserialize.


leif
2018-7-17 20:37:11

Possibly Are you referring to the dir argument in make-serialize-info?


leif
2018-7-17 20:37:22

(Or possible the deserialize-id argument?)


notjack
2018-7-17 20:43:21

@pocmatos @soegaard2 to get syntax warnings about for/vector you could write your own for/vector macro that just adds warnings if needed while expanding to the regular for/vector. You’d have to make sure you use your wrapper macro everywhere instead of the regular one though.


pocmatos
2018-7-17 20:44:21

@notjack I want an external tool that can be extended and used across software that you might not have control of.


leif
2018-7-17 20:52:17

@mflatt Thinking about it a bit more, should #:relative-directory also refer to directories that are .. from the one you gave?


leif
2018-7-17 20:52:25

(And not only subdirectories.)


mflatt
2018-7-17 20:55:41

@leif No when a single dir is given. The pair form of relative directories lets you pick an enclosing directory whose contents will be recorded as relative.


mflatt
2018-7-17 20:56:07

For deserialize, I mean deserialize-module-guard.


soegaard2
2018-7-17 21:05:04

@notjack thanks for the explanation


leif
2018-7-17 21:13:15

Oh, you just mean a parameter like serialize-module-guard, which gets applied to any dynamic-require type of path that gets written into the serialize data? If so that would probably work.


leif
2018-7-17 21:15:06

So, then something like this should maybe work in general?:

(define-runtime-module-path-index here ".")

(serialize here
           #:relative-directory (cons (variable-reference-&gt;module-source (#%variable-reference))
                                      (build-path "/")))

notjack
2018-7-17 21:18:07

(cc @soegaard2) in my experience (mostly via Google’s tooling around large-scale refactorings and code cleanups across their monorepo) tools that find problems in code are far less useful when they’re external to the code


soegaard2
2018-7-17 21:30:25

Good point.


mflatt
2018-7-17 22:39:48

Well, you really can’t use a file path (like the result of variable-reference-&gt;module-source) where a directory path is expected for determining relative paths. Few of our existing tools support file-relative instead of directory-relative references, although I guess you could extend serialize and deserialize further.

Also, beware that "/" isn’t an absolute path on Windows. The idea of making all paths relative can’t work on Windows, since there can be any number of roots.


leif
2018-7-17 23:20:13

Acknowledged.


leif
2018-7-17 23:20:45

Also, when you say / can’t be an absolute path on windows, do you mean it can’t be a complete path, or it can’t be a complete path as well as an absolute path?


leif
2018-7-17 23:21:11

(I thought that Racket’s definition of an absolute path did not contain the drive name for windows, and the complete path was for that. But maybe I’m mistaken?)


notjack
2018-7-17 23:26:57

@mflatt @leif so I’ve been following the serialization module paths discussion and wondering something: would it make sense for module paths to be URIs? that’s a hypothetical I’ve been curious about (I don’t mean to distract from the actual problems you’re both trying to solve right now, and “that’s nonsense” is an acceptable response)