Reputation: 119
I'm using Rebol/Core 278-3.1 on Win-7 64-bit, launched from standard windows command shell. And I'm wondering how to explain to my young friend (a web designer by background) that the interpreter's CD
command does not require the %
.
It reminds me of DOS not needing a space after cd
. The REPL is not a shell, so why make this shortcut as if it were a shell? Why is a string name of a directory treated as a word when no such word has been set? Does it not make code needlessly ambiguous at a first glance?
(Think as if this is your FIRST programming language experience ... not as an old user of ls cd mv in unix shells.)
Even if a word is set, that word is ignored by cd unless a get-word is used ... example would be:
dir %tests
and
dir tests:
"complete" where cd tests
acts as if there is no word with get-word :tests
Note: Saphirion R3 has the following behavior : if I set a word to a dir name but in upper-case, the get-word moves me to that dir and shows it in that incorrect upper-case. But there is no dir with that name. I believe that the cd should have given an error. Surely as a matter of unicode and compliance with the linux-like world .. or is this only working on Windows ? Off I go to my Virtual Box with ubuntu and Syllable ...
Upvotes: 2
Views: 125
Reputation: 987
You can have a look at the source of the cd
function by writing
source cd
There you can find that for convenience, other datatypes are converted to file.
"Why is a string name of a dir treated as a word when no such word has been set?"
Rebol recognizes words by syntax allowing symbolic programming. It does not matter at all whether a word has been set or not to be recognized as a word.
"[If] I set a word to a dir name but in upper-case, the get-word moves me to that dir and shows it in that incorrect upper-case"
Some operating systems (such as Windows) try to be case-insensitive, assuming that this is more convenient for humans.
Rebol string handling is also case-insensitive by default for the same reason.
"Did anyone ever suggest that chdir could have all convenience and quirks and that cd expect a file correctly named ?"
That is essentially what happened but in a different manner. There is a change-dir
function which insists on proper (file!) datatype, while the cd
function is a "convenience shortcut".
Upvotes: 3
Reputation: 33607
You say "the REPL is not a shell". I totally agree. On a related note, I'm adamantly opposed to:
append [x y z] q
...appearing to crash the interpreter by invoking the shortcut for quit
. It's an easy mistake to make. And I feel it's penny-wise and pound-foolish to do similar shortcuts that you have noticed in the core interpreter. Rebol is a literate, English-like language that reads clearly... and things like LS and CD do not belong in the core. They should be part of a shell dialect, if anything.
Should a dialect author should be able to treat words as strings even if the domain of the legal words doesn't map to the range of the legal strings? I think it should be allowed, but I agree it sets a poor precedent in the shipping executable.
Upvotes: -1