Question

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 specified 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?

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top