cd and *home-directory* in shen-scheme with Chez

84 views
Skip to first unread message

Tatsuya Tsuda

unread,
Nov 26, 2017, 3:53:41 AM11/26/17
to Shen
I am playing with the Chez port and totally amazed by the insane performance!

One thing I noticed is that *home-directory* is set to an absolute path when calling cd with a relative path, which is different from other ports I have used so far that set to a relative path and also can call cd multiple times with the same argument without resetting by (cd "").


(0-) (cd "shen")
"/SomePath/shen"

(1-) (cd "shen")
cannot set current directory to ~s: "shen/"


Looking at the source of cd in shen-scheme, there is this comment of "\\ TODO: handle relative dirs?" and this raises the question: what is the expected behavior of cd and *home-directory* when passing a relative path to cd in Shen?

Tatsuya

Mark Tarver

unread,
Nov 27, 2017, 8:53:28 AM11/27/17
to Shen
 Yes;  this is a great result.   Well done Bruno (and the makers of Chez).  

I note that the download page is still pointing to Chibi.  I'll put in an extra entry for Chez.  Where is it on github btw?

Re cd; the code that I left simply sets the home directory to the directory path given a non-empty string.  

(define cd 
  Path -> (set *home-directory* (if (= Path "") "" (make-string "~A/" Path))))

That's the expected behaviour.  If you want to make cd relative to the home directory, you need a small simple code change.  As you say, if you do this you have to reset by (cd "") when calling different directories.  

Mark

Tatsuya Tsuda

unread,
Nov 27, 2017, 11:09:35 AM11/27/17
to Shen
Thanks.
There is a chez branch https://github.com/tizoc/shen-scheme/tree/chez that I used.
But I'm not sure Bruno wants this url to be the official download url. Perhaps he may answer.

Tatsuya

2017年11月27日月曜日 22時53分28秒 UTC+9 Mark Tarver:

Mark Tarver

unread,
Nov 27, 2017, 11:18:14 AM11/27/17
to qil...@googlegroups.com
I'm quite happy to have both the chibi and the chez links.  Generally I never drop links; people's work is appreciated.

Mark

--
You received this message because you are subscribed to the Google Groups "Shen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qilang+unsubscribe@googlegroups.com.
To post to this group, send email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.

Bruno Deferrari

unread,
Jan 3, 2018, 10:46:09 PM1/3/18
to qil...@googlegroups.com
shen-scheme overrides `cd` so that the directory change also gets reflected in the Scheme runtime. Relative directories do work, ignore that comment I probably forgot to remove it. The error you are seeing is caused by the second directory you are "cd"-ing to not existing, and is thrown by Scheme's directory changing function which behaves that way.

Another thing that behaves differently in shen-scheme is that (cd "") does not change the directory instead of reseting it like other ports, something I never noticed until you mentioned it, but I can fix that.

Mark, when trying to "cd" into a non-existing directory, is it ok to throw an error or does that violate the spec?

Example run:

Shen, copyright (C) 2010-2015 Mark Tarver
running under Scheme, implementation: chez-scheme
port 0.16 ported by Bruno Deferrari


(0-) (cd "..")
"/Users/bruno/projects/shen"

(1-) (cd "..")
"/Users/bruno/projects"

(2-) (cd "shen")
"/Users/bruno/projects/shen"

(3-) (cd "shen") \* this directory doesn't exist *\
cannot set current directory to "shen/"

(4-) (cd "shen-chibi")
"/Users/bruno/projects/shen/shen-chibi"

(5-) (cd "") \* as you noted, this doesn't reset to the initial location *\
"/Users/bruno/projects/shen/shen-chibi"

 
Tatsuya

--
You received this message because you are subscribed to the Google Groups "Shen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qilang+unsubscribe@googlegroups.com.
To post to this group, send email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Bruno Deferrari

unread,
Jan 3, 2018, 10:51:35 PM1/3/18
to qil...@googlegroups.com
On Thu, Jan 4, 2018 at 12:46 AM, Bruno Deferrari <uti...@gmail.com> wrote:
On Sun, Nov 26, 2017 at 5:53 AM, Tatsuya Tsuda <ota...@gmail.com> wrote:
I am playing with the Chez port and totally amazed by the insane performance!

One thing I noticed is that *home-directory* is set to an absolute path when calling cd with a relative path, which is different from other ports I have used so far that set to a relative path and also can call cd multiple times with the same argument without resetting by (cd "").


(0-) (cd "shen")
"/SomePath/shen"

(1-) (cd "shen")
cannot set current directory to ~s: "shen/"


Looking at the source of cd in shen-scheme, there is this comment of "\\ TODO: handle relative dirs?" and this raises the question: what is the expected behavior of cd and *home-directory* when passing a relative path to cd in Shen?


shen-scheme overrides `cd` so that the directory change also gets reflected in the Scheme runtime.

Btw, the reason having the directory change reflected in the Scheme runtime is useful is that calling Scheme's `scm.load` function to load Scheme code will work as expected by running inside the new directory, same with any function that interacts with the filesystem or any external command that gets invoked:

(0-) (cd "shen-test-programs")
"/Users/bruno/projects/shen/shen-chibi/shen-test-programs"

(1-) (scm.system "ls") \* invokes a shell command to list directory contents *\
Chap13        cartprod.shen     fruit machine.shen    parse.prl     qmachine.shen     structures-typed.shen
README.shen     change.shen     interpreter.shen    parser.shen     red-black.shen      structures-untyped.shen
TinyLispFunctions.txt   classes-defaults.shen   metaprog.shen     powerset.shen     search.shen     tests.shen
TinyTypes.shen      classes-inheritance.shen  minim.shen      prime.shen      semantic net.shen   types.shen
binary.shen     classes-typed.shen    mutual.shen     prolog.shen     spreadsheet.shen    whist.shen
bubble version 1.shen   classes-untyped.shen    n queens.shen     proof assistant.shen    stack.shen      yacc.shen
bubble version 2.shen   depth'.shen     newton version 1.shen   proplog version 1.shen    streams.shen
calculator.shen     einstein.shen     newton version 2.shen   proplog version 2.shen    strings.shen
0

(2-)



--
BD

Bruno Deferrari

unread,
Jan 4, 2018, 10:11:29 AM1/4/18
to qil...@googlegroups.com
`(cd "")` resets *home-directory* to the initial directory now, but trying to `cd` into a non-existing directory (or an invalid path) will still fail.

If failing breaks the spec I can fix it easily but I would rather not because having it work at the Scheme runtime level has many desirable advantages, and I can't think of anything useful that can be done by being able to `cd` into non-existing directories (or even paths that are just not valid).
--
BD
Reply all
Reply to author
Forward
0 new messages