代码之家  ›  专栏  ›  技术社区  ›  HostileFork says dont trust SE

为什么我不能绑定邮件之类的东西!在解释器启动时的全局上下文中?

  •  1
  • HostileFork says dont trust SE  · 技术社区  · 14 年前

    当我启动一个R3 Alpha 99会话,并将此作为第一个命令输入时,我得到一个错误:

    >> is-email-addr: get bind to-word "email?" bind? 'system
    ** Script error: email? is not in the specified context
    ** Where: bind
    ** Near: bind to-word "email?" bind? 'system
    

    email? 原始人生活在全球环境中,就像 system 对象,测试本身使我的别名工作:

    >> equal? bind? 'system bind? 'email?
    == true
    
    >> is-email-addr: get bind to-word "email?" bind? 'system
    >> is-email-addr fork@example.com
    == true
    

    怎么了,这里?

    2 回复  |  直到 14 年前
        1
  •  5
  •   BrianH    14 年前

    绑定不会在上下文中添加单词,除非你告诉它-你必须使用 bind/new .

    >> get bind/new to-word "email?" bind? 'system
    

    'system 在您的示例中,是绑定到任务本地共享脚本上下文(也称为用户上下文)的。在用户上下文中为单词获取正确的值通常意味着从系统上下文中导入它们,或者导出加载的模块,这个过程称为 实习 这些话。

    做你想做的事,最好用 intern ,如下所示:

    >> get first intern to-block "email?"
    

    to-block 是因为 实习生 通常用于对整个代码块进行操作。我将在下一个版本中修复它,这样它也可以直接处理单词;然后你就能做到:

    >> get intern to-word "email?"
    

    我希望这有帮助。

    你为什么不直接用这个词?使用字符串并在以后转换为单词会有很大的开销,这通常是不必要的。

        2
  •  1
  •   Ladislav    14 年前

    如果你真的坚持使用“email?”字符串而不是“email”?word,那么从中获取单词的最简单方法是使用LOAD函数,如下所示:

    is-email-addr: get bind load "email?" bind? 'system