开发者

Why can't I bind things like EMAIL! in the global context on interpreter startup?

开发者 https://www.devze.com 2023-01-04 09:57 出处:网络
When I start up an R3 Alpha 99 session, and enter this as the first command, I get an error: >> is-email-addr: get bind to-word \"email?\" bind? \'system

When I start up an R3 Alpha 99 session, and enter this as the first command, I get an error:

>> is-email-addr: get bind to-word "email?" bind? 'system
** Script error: email? is not in the speci开发者_如何学Cfied context
** Where: bind
** Near: bind to-word "email?" bind? 'system

But if I quit, restart and instead execute a test to prove that the email? primitive lives in global context like the system object, the test itself makes my alias work:

>> equal? bind? 'system bind? 'email?
== true

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

What's going on, here?


Binding doesn't add words to the context, unless you tell it to - you have to use bind/new.

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

But your question shows a couple misconceptions about the R3 binding model. There is no single global context in R3, not like R2. The word 'system in your example is bound to the task-local shared script context, aka the user context. And getting the right value for words in the user context often means importing them from the system context, or the exports of the loaded modules, a process known as interning the words.

To do what you apparently want to do here, it would be best for you to use intern, like this:

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

The to-block is used because intern is generally used to operate on whole blocks of code. I'll fix it in the next version so it can work on words directly as well; then you will be able to do this:

>> get intern to-word "email?"

I hope this helps.

Why aren't you using the word directly? Using strings and converting to words later has so much overhead, which is usually unnecessary.


If you really insist on using "email?" string instead of an 'email? word, then the simplest way for you to obtain a word from it while not observing any strangenesses would be to use the LOAD function as follows:

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

精彩评论

暂无评论...
验证码 换一张
取 消