在 Rebol 中使用直接值?
我是一名 Rebol 新手。我经常发现由于某种原因表达式需要有一个值作为变量而不是“直接使用”的情况。我怀疑我只是没有正确使用开关或取消引用运算符?
一个例子:
>> "hi"/1 ; doesn't work == /1 >> x: "hi" == "hi" >> x/1 ; works == #"h"
有什么方法可以让这个例子和其他例子一起“直接使用”?
谢谢。
I'm a Rebol newb. I'm often finding situations where for some reason an expression needs to have a value as a variable instead of "direct use." I suspect that I'm just not using a switch or dereference operator correctly?
An example:
>> "hi"/1 ; doesn't work == /1 >> x: "hi" == "hi" >> x/1 ; works == #"h"
Any way I can make this and other examples work with "direct use?"
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这些:
Try these:
我不是专家,但我的理解是带有
/
标记的表达式称为路径,并且必须以单词开头!
而不是任何类型的文字(您所说的“直接值”)。当您有一个
word!
充当多变的。您不能说"foo"/bar
因为"foo"
是一个字符串!
,而不是单词!
,但你可以说foo/bar
因为foo
是一个word!
。I'm not an expert, but my understanding is that expressions with
/
marks in them are called paths, and must begin with aword!
and not a literal — what you are calling a "direct value" — of any kind.You can think of
/
as syntactic sugar forpick
andselect
when you have aword!
that serves as a variable. You cannot say"foo"/bar
because"foo"
is astring!
, not aword!
, but you can sayfoo/bar
becausefoo
is aword!
.每个数据类型都有自己的词汇表示形式,允许您与其内部数据交互(或不交互)。
REBOL 中没有实际的路径语法或运算符。这主要是因为 Rebol 不是一种 OOP 语言,即使它确实有一个对象!数据类型。
您可能没有注意到代码
FOO/BAR
根本不是一个表达式,而是一个实际上是路径的单个数据元素! *datatype*
只有路径允许您“按字面意思”导航 Rebol 数据。仅当路径被_评估_时才会发生这种情况。在这种情况下,您将获得通过从该路径导航获得的值。
在 Rebol 中,通用数据类型“访问器”本质上不是词汇的而是编程的。正如 Sunanda 向您展示的,您可以使用各种系列函数直接操作文字数据。
这是非常强大的,因为它们可以“链接”,例如:
我将通过给您一个更高级的路径用法的预告来结束...路径表达式!
请注意,您实际上可以将任何代码放在括号中!如果它遵循可以导航的数据。
Each datatype has its own lexical representation which allows you to interact with its internal data (or not).
There is no actual path syntax or operator in REBOL. This is mainly due to fact that Rebol is not an OOP language, even if it does have an Object! datatype.
You might not have noticed that the code
FOO/BAR
is not an expression at all, but rather a single data element which is actually of apath! *datatype*
Only paths allow you to navigate Rebol data "literally". This only occurs when paths are _evaluated_ . In that case you will get the value which is obtained by navigating from that path.
In Rebol, the generic datatype "accessors" are not lexical but programmatic in nature. As Sunanda showed you, you use the various series functions to manipulate literal data directly.
this is very powerful since they can be "chained", for example:
I'll finish by giving you a teaser into more advanced path usage... path expressions!
Note that you can really put any code in the paren! if it follows data which can be navigated.