popa.bogdanp
2021-3-20 08:15:54

I like DI for “auto-wiring” the dependency graph so that things are started/stopped and passed to each other in the right order w/o me doing it manually. I can just declare what the dependencies between things are and the system handles all of this for me. That is what component-lib does: it builds a component graph, sorts it topologically and then passes dependencies around using closures. It’s also nice to be able to take that specification as a concrete value and then replace various components in the system for CLIs, testing, etc. Parameters are more convenient in some circumstances, but are a bit clunky when you have two instances of the same component (eg. a read-only and a read-write DB).

I’ve never been a fan of the Guice-style runtime DI via annotations, though. Too much magic and hard to debug.


popa.bogdanp
2021-3-20 08:24:03

Here’s matchacha’s component spec: https://gist.github.com/Bogdanp/58391f9723c49874c3ce9cf0bbc56220 . Another advantage of having a declarative spec of these things is you can build tools to visualize the graph. If I run raco koyo graph in matchacha’s root, I get:


chansey97
2021-3-20 08:25:33

Does the component-lib support circular dependencies? AFAIK, many OOP DI container support two kinds of injection: 1. constructor injection (1st pass) 2. setter injection (2nd pass that deal with circular dependencies)


popa.bogdanp
2021-3-20 08:25:54

It doesn’t.


chansey97
2021-3-20 08:29:18

Thanks. FP seems to discourage circular dependencies. It’s logical.


rokitna
2021-3-20 08:34:41

At my last job, DI started to click for me when I realized it was something like module system for stateful services. You sort of “import” loggers, database adapters, task queues, etc., and the state of the overall application at run time can then be understood to be in the same shape as the codebase (and can be decomposed along those lines for testing). I think it’s not that other abstraction techniques can’t be used for any given thing DI does, but that when people’s preferences bring them toward module-system-like abstractions for complex codebase development and stateful abstractions for complex application architecture, DI techniques play right to that niche.


hectometrocuadrado
2021-3-20 10:07:58

When running scribbling --html file.scrbl I get this: Warning: some cross references may be broken due to undefined tags. How can I fix this?


sorawee
2021-3-20 10:22:21

If you now have installed your code as a package, you can run raco setup --pkgs <your-package-name>. It will automatically render your Scribble file (assuming you point to your Scribble file in info.rkt) with correct cross reference information.


raoul.schorer
2021-3-20 10:42:56

I’d like to essentially make a contract on something void. I did (unconstrained-domain-> any/c) but that still checks for a) a procedure and b) that the procedure returns a single value. Is there some way to do even less? I tried #f in lieu of the contract expression, but it fails.


laurent.orseau
2021-3-20 10:58:21

Use any instead of any/c


laurent.orseau
2021-3-20 10:58:36

It won’t check the return arity


sorawee
2021-3-20 10:59:53

Why not just any/c?


laurent.orseau
2021-3-20 11:00:14

If you use any/c instead of the whole contract, it will just check that the thing is just a single value


sorawee
2021-3-20 11:00:40

Right. Isn’t that what @raoul.schorer wants?


laurent.orseau
2021-3-20 11:00:45

But then using a contract at seems not very useful :)


laurent.orseau
2021-3-20 11:02:13

Myself I would probably just use procedure?


laurent.orseau
2021-3-20 11:02:49

That way it’s checked only when the procedure is passed, not each time it is called


laurent.orseau
2021-3-20 11:03:30

maybe also procedure-arity-includes/c iirc


raoul.schorer
2021-3-20 11:04:21

Ah, yes indeed those are all pretty valid solutions. It’s good that I posted in #beginners :smiling_face_with_tear:


raoul.schorer
2021-3-20 11:05:19

The reason for the void contract is that I have a contracted unit interface, with just 2 unsafe procedures in the middle of 15 others


raoul.schorer
2021-3-20 11:05:40

so I just wanted to remove all checks on those 2


hectometrocuadrado
2021-3-20 13:04:28

Oh, I underatnd it now. Thanks!


anything
2021-3-20 13:46:38

Why is raco pkg install apparently reading a test2.rkt file I have in the directory of the language? Or is it not? test2.rkt is indeed a program that fails with that error message. I don’t know where the problem is, but I’m surprised installing the package would run this program at all. %raco pkg install [...] raco setup: --- parallel build using 4 jobs --- [10:41:33] raco setup: 3 making: <pkgs>/jsonic4 string::1: read: expected a `)` to close `(` compilation context...: C:\sys\tolcom\current\little-languages\jsonic4\test2.rkt [...] raco pkg install: packages installed, although setup reported errors


soegaard2
2021-3-20 13:48:02

I too have been confused my this previously. I think the installation process simply compiles all files in the folder. You can use the info.rkt file to exclude some files.


anything
2021-3-20 13:48:32

Oh, thank you so much!