1

[%a/b]我想改成[%a/c]。基本上,与更改路径或细化相同,但file!改为:

我想将a/b块内部更改为a/c

test: [a/b]

在这种情况下,要么 要么change next test/1 'c工作test/1/2: 'c。但不是什么时候test是 a file!

>> test: [%a/b]
== [%a/b]
>> test/1
== %a/b
>> test/1/2         ; can't access 2nd value
== %a/b/2
>> next first test  ; not quite what you expect
== %/b

尝试change它不会得到你所期望的东西:

>> change next test/1 'c
== %b
>> test
== [%acb]
4

4 回答 4

4

你是混淆path!file!系列,他们可以看起来相似,但他们的性质是非常不同的。

A是由斜线符号分隔path!的值(通常是值)的集合,a是值的集合。系列中的斜线字符只是字符,因此不了解任何子结构。它(主要)具有系列的语义,而具有系列的语义。word!file!char!file!file!string!path!block!

现在这已被清除,关于test/1/2结果,系列上的路径符号与 onfile!具有不同的行为string!,它将执行智能连接而不是充当访问器。它之所以被称为智能,是因为它可以很好地处理出现在左右部分的额外斜杠字符。例如:

>> file: %/index.html
== %/index.html

>> path: %www/
== %www/

>> path/file
== %www/file

>> path/:file
== %www/index.html

相同的路径符号规则也适用于url!系列:

>> url: http://red-lang.org
== http://red-lang.org

>> url/index.html
== http://red-lang.org/index.html

>> file: %/index.html
== %/index.html

>> url/:file
== http://red-lang.org/index.html

因此,要更改 , as 的嵌套内容test: [%a/b], as 的file!行为基本上与string!, 您可以使用任何可用的字符串方法来修改它。例如:

>> test: [%a/b]
== [%a/b]

>> change skip test/1 2 %c
== %""

>> test
== [%a/c]

>> change next find test/1 slash "d"
== %""

>> test
== [%a/d]

>> parse test/1 [thru slash change skip "e"]
== true

>> test
== [%a/e]
于 2017-05-18T16:25:50.043 回答
3

文件是字符串类型,可以像修改字符串一样进行操作。例如:

test: [%a/b]
replace test/1 %/b %/c
于 2017-05-18T16:05:22.840 回答
3

这是因为文件!是任意字符串!,不是任意数组!

>> any-string? %a/c
== true
>> any-array? 'a/c
== true

所以文件中的目录分隔符'/'!对动作 CHANGE 没有任何特别的意义。所以 %a/b 中的 'a'、'/' 和 'b' 以相同的方式处理,解释器不会尝试将其解析为两段文件路径 [ab]。

而对于路径!,因为它是一个数组,所以每个组件都是一个 rebol 值,解释器知道这一点。例如,a/bcd 中的 'bcd' 将被视为一个整体(一个单词!),而不是三个字符 'b'、'c' 和 'd'。

我同意这个文件!是一个任意字符串!不方便。

于 2017-05-18T16:12:05.127 回答
1

这是一个可能很麻烦的解决方案,但适用于将它们视为文件的目录

test/1:  to-file head change skip split-path test/1 1 %c
于 2017-06-02T06:36:14.317 回答