jerome.martin.dev
2018-6-21 08:50:22

@greg @notjack So, quick question about that. When you write a new racket collection, do you link it immediately, or do you use relative paths first, then switch for production? I’m usually stuck with relative paths for a long time before I consider making my module work as a (pushable) racket package.


jerome.martin.dev
2018-6-21 08:51:41

(maybe because raco link is nowhere advertised, I just learned about it from your conversation)


notjack
2018-6-21 09:02:17

@jerome.martin.dev I link immediately. As a rule, I put all racket code I write in packages + collections (usually single-collection packages) and link all packages whose code I intend to edit. So the only time I require things with relative paths is when I’m making small examples that need to span files, like for bug reports and that kind of thing. Those are too tiny to justify the effort of packaging them.


notjack
2018-6-21 09:04:37

I also keep as much code as possible in some subcollection with private in its name like foo/private, then I use#lang reprovide to define the publicly exposed entrypoint modules of the collection(s)


jerome.martin.dev
2018-6-21 09:08:18

so when you work on some subcollection that requires another one next to it, let’s say, package fruits with sub-collections banana and apple

banana requires fruits/apple/private

Would that work?


notjack
2018-6-21 09:09:02

actually what I would do is just put everything in fruits/private so they’re all adjacent files


notjack
2018-6-21 09:09:16

fruits/private/apple, fruits/private/banana, etc.


jerome.martin.dev
2018-6-21 09:09:33

yeah ok, keeping the public file to a minimum


notjack
2018-6-21 09:10:39

it’s less that, it’s more that now I can rearrange the public module hierarchy by just moving a bunch of tiny reprovide files around - the actual implementation files are all in a flat directory in fruits/private so changing the exposed hierarchy doesn’t require moving implementation files and folders


notjack
2018-6-21 09:11:42

effectively, I’ve set up redirects / symlinks at the module level


notjack
2018-6-21 09:13:24

for instance, in addition to fruits/private/apple and fruits/private/banana I would have these files:

;; fruits/main.rkt
#lang reprovide
fruits/apple
fruits/banana

;; fruits/apple.rkt
#lang reprovide
fruits/private/apple

;; fruits/banana.rkt
#lang reprovide
fruits/private/banana

jerome.martin.dev
2018-6-21 09:15:47

I see. The only issue I have with reprovide is that there’s no whitelisting mechanism. You can except-out, but you cannot only-out


notjack
2018-6-21 09:16:47

I think you can use only-in for that


notjack
2018-6-21 09:17:14

also, I tend to move that kind of stuff into the implementation modules by giving them submodules that provide the whitelisted exports


notjack
2018-6-21 09:18:16

like, fruits/private/apple.rkt might have this:

(provide apple? make-apple apple-chew)

(module+ for-trusted-clients
  (provide unsafe-apple-chew))

... implementation ...

jerome.martin.dev
2018-6-21 09:19:01

better be careful with apple chewing


notjack
2018-6-21 09:19:11

it’s a dangerous habit


notjack
2018-6-21 09:19:56

anyway, then I could have fruits/apple reprovide only the root module and add fruits/apple/unsafe which reprovides the for-trusted-clients submodule


jerome.martin.dev
2018-6-21 09:20:22

ooh, I see


notjack
2018-6-21 09:20:41

or I could move them around some other way by putting the reprovide files somewhere else - that’s really the main advantage here, to let me change my mind about what modules go where in the exposed hierarchy without a bunch of headaches


githree
2018-6-21 09:21:58

@notjack how would the fruits/apple/unsafe.rkt look like - how do you reprovide submodule?


notjack
2018-6-21 09:22:13

I can also have two exposed entrypoints that reprovide the same module, which is really useful when you want to change the name of a module without breaking things - you can document that the old name is deprecated but keep it around


notjack
2018-6-21 09:22:40

@githree like this, I think:

#lang reprovide
(submod fruits/private/apple for-trusted-clients)

notjack
2018-6-21 09:22:53

(beware: I have only written the above, not compiled it)


githree
2018-6-21 09:24:12

thanks - gives an idea though


githree
2018-6-21 09:26:55

@notjack what real package would you recommend as a reference for this kind of linking?


notjack
2018-6-21 09:29:45

@githree alas I have no references, the only project I’ve actually done this on is my private general utils repository


notjack
2018-6-21 09:30:52

doing things this radically is a recent experiment of mine so it hasn’t made its way into any of my open source projects yet


jerome.martin.dev
2018-6-21 09:30:54

I guess racket/web-server is a good example https://github.com/racket/web-server


notjack
2018-6-21 09:32:04

@jerome.martin.dev that’s actually a separate thing where the code is split among multiple packages for dependency reasons


notjack
2018-6-21 09:32:43

within the web-server-lib/web-server folder it looks more like a regular collection with code mixed around in various places, some of which are in a private/ subcollection but not all


jerome.martin.dev
2018-6-21 09:33:36

Yeah, I was saying that because it sometimes uses private collections and no relative paths


notjack
2018-6-21 09:34:41

oh! yeah, now I see what you mean


notjack
2018-6-21 09:35:54

poking around some of the private/ files it looks like it follows the pattern where any modules that are not intended to ever be required by modules outside of the private directory are required via relative paths, but everything else is through collection paths


jerome.martin.dev
2018-6-21 09:36:06

yes


notjack
2018-6-21 09:36:34

I think that’s about what I used to do, but with more reprovides


jerome.martin.dev
2018-6-21 09:38:16

Last question: I get the usefulness of doing that public/private separation for libraries. But does it make sense to use the same pattern for programs/executables? Are they even racket packages?


notjack
2018-6-21 09:40:09

I think so, but I’m not really sure since I don’t make programs / apps / binaries / etc. nearly as often and have less of a feel for it


notjack
2018-6-21 09:41:06

I’d probably approach that by making my app be a library that exports a main function / macro / lang / whatever that launches the app given some config values


jerome.martin.dev
2018-6-21 09:41:13

Right now I’m making a program that runs in the CLI, and I’m considering making it a racket package, so that people can install it and use it directly from the racket package repository. But does that even work?


notjack
2018-6-21 09:42:02

it does, there’s a way to make racket packages expose arbitrary command line tools where using the tool runs some main module specified in package metadata


notjack
2018-6-21 09:42:04

there’s also raco commands


jerome.martin.dev
2018-6-21 09:42:33

yeah, I knew about the raco command, but I was wondering if you could expose something that installs itself in the PATH


notjack
2018-6-21 09:42:46

yup - I think racket-launcher-names is the relevant info.rkt key



jerome.martin.dev
2018-6-21 09:43:48

nice !


notjack
2018-6-21 09:44:16

it puts things into the same directory where the raco, racket, drracket, etc. programs are (I think) so if that’s in your path you don’t need to add any other dirs to your path


jerome.martin.dev
2018-6-21 09:44:37

I guess it works like that for scribble


notjack
2018-6-21 09:44:55

yup!


githree
2018-6-21 09:46:34

@notjack piggybacking on your conversation above I need a clarification - if fruits/private/banana.rkt uses apple than with collection link, in fruits/private/apple.rkt it is enough to use (require fruits/private/banana)?


notjack
2018-6-21 09:48:47

@githree that would work, but I try to avoid requiring /private things as much as possible so even within fruits/private/apple.rkt I would rather use (require fruits/banana) than (require fruits/private/banana) - the exception being when I really do need to require something that’s not exposed via a public api, like an internal helper module or a common implementation utility or something


githree
2018-6-21 09:49:20

ok, gotcha!


notjack
2018-6-21 09:51:11

let me know how it works for ya if you try this, I’m curious


githree
2018-6-21 09:56:41

this conversation comes right in time as I am currently struggling working on a package that has so many relative paths I am lost - before that I only did smaller projects in racket


jerome.martin.dev
2018-6-21 09:59:26

same for me x)


notjack
2018-6-21 09:59:35

I’m glad I could help out :)


jerome.martin.dev
2018-6-21 09:59:54

yeah, thanks @notjack :slightly_smiling_face:


jerome.martin.dev
2018-6-21 12:47:58

Ok there’s something I don’t get with collections/packages. We’re supposed to put an info.rkt file in each collection, right? But the deps and implies options require a package name. How are we supposed to tell a collection that it depends on other collections inside the same package? Maybe update-implies?


jerome.martin.dev
2018-6-21 12:54:20

Maybe I’m just overthinking the stuff and I just don’t need to specify any deps


samth
2018-6-21 13:38:34

@jerome.martin.dev you don’t need to say that you depend on yourself


samth
2018-6-21 13:39:02

also, raco setup --fix-pkg-deps will fix up your deps


jerome.martin.dev
2018-6-21 13:45:06

I just spent multiple hours creating sub folders, “info.rkt” and “main.rkt” files everywhere. I’m gonna try running raco pkg install and CROSS FINGERS


greg
2018-6-21 14:03:16

https://racket.slack.com/archives/C06V96CKX/p1529571022000143 It sounds like @notjack is more deliberate about this, than I am. Often I go through stages: 1. Just exploring with one or more .rkt files in dir. 2. Hmm let’s git init and save some history before trying something. 3. OK this code might be handy to someone, I’ll push it to GitHub as a public repo. 4. OK I’m willing to commit to supporting it. I’ll make a package and add to package catalog. — Often I don’t ever make it to 4. I suppose I could make the Racket package earlier — and just not add to package catalog.


jerome.martin.dev
2018-6-21 14:38:36

Well… Crossing fingers was not enough. Everything falls appart pretty badly… :disappointed:


jerome.martin.dev
2018-6-21 14:39:16

my interdependent collections fail to build because they cannot find the others, which are not yet installed because.. well, they’re being built.


samth
2018-6-21 14:39:33

everything gets installed first, and then built


samth
2018-6-21 14:39:44

unless you have two packages and you’ve only installed one?


jerome.martin.dev
2018-6-21 14:40:28

I trying to install a multi-collection package, and I get a lot of “standard-module-name-resolver: collection not found”


samth
2018-6-21 14:41:08

what does the top-level info.rkt say? what’s the directory structure?


jerome.martin.dev
2018-6-21 14:44:32
;; info.rkt
(define collection 'multi)

jerome.martin.dev
2018-6-21 14:46:38

the tree looks something like this:


jerome.martin.dev
2018-6-21 14:46:47
virtual-mpu
├── asm-lang
│   ├── assemble.rkt
│   ├── info.rkt
│   ├── main.rkt
│   ├── private
│   │   ├── ...
│   ├── s-record.rkt
│   └── tests
├── cli
│   └── main.rkt
├── emulator
│   ├── main.rkt
│   ├── private
│   │   ├── gui
│   │   │   ├── ...
│   │   └── main.rkt
│   └── terminal.rkt
├── info.rkt
├── LICENSE
├── mpu-lang
│   ├── docs
│   ├── info.rkt
│   ├── main.rkt
│   ├── op-table.rkt
│   ├── private
│   │   ├── ...
│   ├── test.rkt
│   └── tests
├── README.md
└── utils.rkt

samth
2018-6-21 14:47:19

and what error messages are you getting?


jerome.martin.dev
2018-6-21 14:48:15

mostly raco setup: error: during making for <pkgs>/virtual-mpu/asm-lang/private raco setup: asm-lang/private/s-record.rkt:8:2: collection not found raco setup: for module path: virtual-mpu/utils raco setup: collection: "virtual-mpu"


jerome.martin.dev
2018-6-21 14:49:08

a lot of’em


jerome.martin.dev
2018-6-21 14:50:31

which means one of my (require virtual-mpu/utils) is failing


samth
2018-6-21 14:51:36

right, there’s no virtual-mpu collection


samth
2018-6-21 14:51:56

virtual-mpu is just a package name, not a collection name — the collections are the subdirectories


jerome.martin.dev
2018-6-21 14:52:02

oh, so you mean the main package cannot be its own collection?


samth
2018-6-21 14:52:20

you can either have a package represent a single collection


samth
2018-6-21 14:52:32

or you can have a package where the subdirectories are each collections


samth
2018-6-21 14:52:53

it can’t be both, because then virtual-mpu/cli/main and cli/main would be the same thing


jerome.martin.dev
2018-6-21 14:53:41

so collections are not namespaced?


samth
2018-6-21 14:55:58

I’m not sure what you mean


jerome.martin.dev
2018-6-21 14:57:32

well if I want my collections to be distinguishable from other packages, I’ll need to put them inside another dummy collection, otherwise they’ll be accessible as cli, mpu, utils instead of virtual-mpu/cli…etc


jerome.martin.dev
2018-6-21 14:58:33

I find this a bit overwhelming to make so much subfolders


jerome.martin.dev
2018-6-21 15:02:33

But I guess it’s the way it is. I just need to remember that a package cannot be a collection and have sub-collections at the same time


samth
2018-6-21 15:04:41

it sounds like you don’t want a multi-collection package


jerome.martin.dev
2018-6-21 15:05:09

yeah, that’s what I just realized writing that…


samth
2018-6-21 15:05:12

you can just change to (define collection "virtual-mpu")


samth
2018-6-21 15:05:18

and keep that directory structure


jerome.martin.dev
2018-6-21 15:13:15

alright, I still get some errors, especially concerning places where I require emulator/private (meaning “emulator/private/main.rkt”) that is understood as “emulator/private.rkt”


jerome.martin.dev
2018-6-21 15:13:32

is this normal behavior?


jerome.martin.dev
2018-6-21 15:14:17

(private is a folder but racket tries to use it as a file)


jerome.martin.dev
2018-6-21 15:16:14

and I get errors everywhere I require mpu instead of mpu-lang (because I declared (define collections "mpu") I supposed it would understand the renaming)


jerome.martin.dev
2018-6-21 15:21:38
First, if the unquoted path contains no /, then require automatically adds a "/main" to the reference. For example, (require slideshow) is equivalent to (require slideshow/main).

jerome.martin.dev
2018-6-21 15:21:43

ooooookkk


jerome.martin.dev
2018-6-21 15:22:03

main.rkt does not work for sub-collections :disappointed:


jerome.martin.dev
2018-6-21 15:51:56

I got it compiling :smile:


jerome.martin.dev
2018-6-21 15:52:40

now I just need to understand how to reprovide an expander with a default s-exp reader


jerome.martin.dev
2018-6-21 15:54:38

In other words, how to provide a custom lang so that modules can use it as #lang my-collection/my-language


jerome.martin.dev
2018-6-21 15:55:15

for a custom reader it’s easy, but how do I provide an expander if I want the reader to be s-exp?


jerome.martin.dev
2018-6-21 15:56:07

I tried stuff like ;; my-collection/my-language.rkt #lang s-exp syntax/module-reader "mpu-lang/lang.rkt"


samth
2018-6-21 16:54:56

@jerome.martin.dev to make something work as #lang mylang, you need to either have (submod mylang reader) or mylang/language/reader


shu--hung
2018-6-21 20:45:43

I have a class inheriting string-snip%. Is it possible to change the overall style (like adding borders and changing text colors)? Or do I have to reimplement draw or use image-snip%, pict-snip% etc?


shu--hung
2018-6-21 20:50:58

I tried to use set-style directly but nothing changed


mflatt
2018-6-21 20:55:47

@shu—hung If you want to ignore or modify the style that the editor gives the snip, then you’d need to override on-draw. You can chain to the string-snip% implementation after adjusting drawing state, because string-snip% assumes that the editor-imposed style has been installed (if I remember correctly), but be sure to restore any drawing state that you change.


sersha42
2018-6-21 20:57:27

@sersha42 has joined the channel


shu--hung
2018-6-21 20:57:47

@mflatt so that is, I can override on-draw, change relevant settings installed on dc and call string-snip%’s on-draw?


mflatt
2018-6-21 20:58:00

Yes


shu--hung
2018-6-21 20:58:18

okay thanks :smile: