[racket] Splitting Racket source code by scope?

From: Rüdiger Asche (rac at ruediger-asche.de)
Date: Tue Feb 28 02:31:05 EST 2012

yes, but the docs for include also say that "If the source is not a complete 
path string, then path-spec is resolved relative to 
(current-load-relative-directory) if it is not #f, or relative to 
(current-directory) otherwise." Is that a documentation bug then?


----- Original Message ----- 
From: "Matthias Felleisen" <matthias at ccs.neu.edu>
To: "Rüdiger Asche" <rac at ruediger-asche.de>
Cc: "Danny Yoo" <dyoo at cs.wpi.edu>; <users at racket-lang.org>
Sent: Monday, February 27, 2012 11:44 PM
Subject: Re: [racket] Splitting Racket source code by scope?



On Feb 27, 2012, at 5:33 PM, Rüdiger Asche wrote:

> Thanks again - but there is something in path resolution policy I don't 
> understand - why does this one here:
>
> (parameterize ([current-directory "f:"])
> (load "suchandsuch.scs"))
>
> give the expected result (reads the file from f:), but this one here:
>
> (parameterize ([current-directory "f:"])
> (include "othersuch.scs"))


The docs say "(include ...) Inlines the syntax in the file designated by 
path-spec in place of the include expression." but parameterize sets the 
current directory at run-time (e.g., for read, load, and other actions).

Do you want this:

;; foo.rkt:
(define x (+ y 10))

;; bar.rkt:
#lang racket

(let ([y 3])
  (include-at/relative-to 'here "foo.rkt" "foo.rkt")
  x)






>
> doesn't (raises error stdin::196512: include: can't open include file 
> (open-input-file: cannot open input file: 
> "D:\install\racket\othersuch.scs" (Das System kann die angegebene Datei 
> nicht finden.; errno=2)) at: #<path:D:\install\racket\othersuch.scs> in: 
> (include "othersuch.scs")) ? I read the docs to use current-directory 
> consistently on load and include?
>
> ----- Original Message ----- From: "Danny Yoo" <dyoo at cs.wpi.edu>
> To: "Rüdiger Asche" <rac at ruediger-asche.de>
> Cc: <users at racket-lang.org>
> Sent: Monday, February 27, 2012 6:22 PM
> Subject: Re: [racket] Splitting Racket source code by scope?
>
>
> On Mon, Feb 27, 2012 at 11:38 AM, Rüdiger Asche <rac at ruediger-asche.de> 
> wrote:
>> I'd like to split the components of my Racket project into multiple files
>> according to this structure:
>>
>> contents of file1:
>>
>> (letrec ((id1 body1)
>> ...
>> <contents of file2, see below>
>> ...
>> )
>> (main execution body using id1, idx, idy...)
>> )
>
>
> As Matthias mentions, you can formally link together "units" together.
> Units are Racket's dependency-injection component framework.  You can
> read documentation about them here:
>
>   http://docs.racket-lang.org/guide/units.html
>
>
> Although there are other mechanisms for textually substituting the
> content of one file within another, such as the racket/include
> library:
>
>   http://docs.racket-lang.org/reference/include.html
>
> because you mentioned components in your question, the racket/unit
> framework might be more suitable for your purposes.
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users


Posted on the users mailing list.