schemechez-scheme

Load file with relative path


With chezscheme to load files within the current directory all-codes

(load "ch4-mceval.scm")

However, if change directory to the parent-dir and try:

(load "all-codes/ch4-mceval.scm")

Exception in load: failed for all-codes/ch4-mceval.scm: no such file or directory:

My directory displays like

$ tree -L 2                                                                   
.                                                                             
├── 00.elisp-SICP.org                                                         
├── 00.preface.org                                                                                            
├── 01.building-abstrations-with-procedures.org                               
├── 02.building-abstrations-with-data.org
├── 03.modularity-objects-and-states.org
├── 04.metalinguistic-abstration.org
├── 05.computing-with-register-machines.org
├── all-codes
│   ├── ch1.scm
│   ├── ch2.scm
│   ├── ch2support.scm
│   ├── ch2tests.scm
│   ├── ch3.scm

How could I load the scm codes from 'all-codes' with the current level?


Solution

  • It seems you should either use an absolute path for the file or use source-directories to redefine the set of directories searched for source or object files when a file is loaded via load.

    More here:

    procedure: (load path) ... The parameter source-directories (Section 12.5) determines the set of directories searched for source files not identified by absolute path names.

    (source http://cisco.github.io/ChezScheme/csug9.5/system.html#./system:h4)

    and here

    global parameter: source-directories

    ... determines the set of directories searched for source or object files when a file is loaded via load, load-library, load-program, include, visit, or revisit, when a syntax error occurs, or when a source file is opened in the interactive inspector.

    The default value is the list (".")...

    (source http://cisco.github.io/ChezScheme/csug9.5/system.html#g114)