jjsimpso
2020-12-20 18:45:14

How does one specify the source files for a package? I have a #lang collection that I build with ‘raco setup’ but I realized that it is including my test code in the language. This is causing a program that I’m writing outside of the package to fail. I assume there’s something I can put in an info.rkt that will do this, but it isn’t clear.


jjsimpso
2020-12-20 18:48:13

My tests are in a subdirectory of the #lang’s source files. Is that the problem?


jjsimpso
2020-12-20 19:13:10

I found my problem. It may not have been the test code after all, but I was able to add a ‘compile-omit-paths’ field to an info.rkt file to remove the test code just in case. I think there is a raco test option that I should be using for that instead of building it with my package. Any relatively simple examples out there to look at for the right way to package a #lang ?


laurent.orseau
2020-12-20 19:20:07

test-omit-paths may be what you are looking for


jjsimpso
2020-12-20 19:24:28

Ok, thanks. I’ll experiment. IPreviously I’ve had the tests run whenever I ran ‘raco setup <my-pkg>’ but I’m guessing it would be better to split out the tests.


phanthero
2020-12-20 22:43:55

Okay, so it seems like a more reasonable time in North America than when I asked the question yesterday, but I am still not sure what a “structure” in Racket is, and what a “variable” in Racket is.

When a thing is passed to a function, how do we determine whether we should pass its reference or not? In C, it is pretty clear an “array” is just an address in memory, but in Racket it is not so clear. I am only superficially familiar with Java, but is this similar to the “primitive” vs. “object” distinction there?


soegaard2
2020-12-20 23:38:02

Racket always use call-by-value. A structure or struct is similar to a record (in Pascal) or a struct (in C) or as an ‘object with no methods’ (in Java). Wrt ‘variable’ see https://docs.racket-lang.org/reference/eval-model.html#%28part._vars-and-locs%29\|https://docs.racket-lang.org/reference/eval-model.html#%28part._vars-and-locs%29 When a struct is passed to a function as an argument - no copy is made.


rokitna
2020-12-21 01:37:09

I’m not terribly familiar with languages which have a distinction between passing by reference and passing by value, but I think what Racket is doing sits in the middle, so that the answer is a little different depending on what you have in mind.

I think as far as a C programmer is concerned, Racket programs are basically full of variables of type (racket_value *), where racket_value is some tagged union type that represents all possible Racket values. (I’m speaking metaphorically here and making up the name "racket_value," but when writing extensions for Racket BC, I believe Scheme_Object is the name of this type.)

Since each of the variables has type (racket_value *), the variable is a reference to a pointer which is a reference to a value. So the “by reference or by value?” question has three answers:

  • pass the variable’s address (racket_value **)

  • pass the variable’s value, which is itself a reference (racket_value *)

  • pass the data at the variable’s value’s target (racket_value)

The second option describes what Racket does. Compared to the first option, Racket passes everything by value, but compared to the third option, Racket passes everything by reference.


rokitna
2020-12-21 01:57:39

It sounds like the distinction you have in mind in your question is “how does Racket know when to copy some data structure or just pass a pointer to it?” which boils down to a decision between the third and second options. Racket always uses the second option. If you want to make a new copy of some data structure, you can copy it explicitly rather than using a calling convention.

But I think C++, C#, and PHP (and maybe modern C?) have the ability to declare some function parameters as being by-reference in the sense of the first option. (C# calls it an out or inout variable.) So that’s how the first option can get tangled into this question. If you ever want to do that kind of thing in Racket, you can pass in a mutable box to serve as a receptacle for the output, or you write a macro that expands to set!.


phanthero
2020-12-21 02:23:57

Ah! Thank you all for the fantastic explanations! So a copy is made, just of the racket_value* since we need to put it into the functions stack somehow (unless Racket shares stacks between functions.. well excluding tail recursion, I think it is ok to presume Racket’s functions do not share call stacks… right?).

So the pointer to the racket_value is copied to the function’s local stack, but the underlying value itself is not copied, nor is the first sense of racket_value** that @rokitna mentioned used.

Thank you so much! Let me know if I misunderstood something here!


phanthero
2020-12-21 02:41:34

I think I understand better now why the terminology “location” is being used in the Racket docs. This is a pointer to the variable, not the value of the variable (at least in BC). Makes a lot of sense


phanthero
2020-12-21 07:04:15

Is there any advantage to using streams over lists?


me1890
2020-12-21 07:09:44

I think the advantage of using streams to iterate is that they can operate in constant space instead of generating all the results then iterating. The advantages are clear when iterating over something large, but simple to generate, like numbers.