How do you specify the 8th namespaces in an array?

156 Views Asked by At

8th uses namespaces instead of vocabularies. Each namespace has its own integer representation.

ok> ns:a . cr ns:n . cr
4
2

So, 2 is for the number namespace, and 4 is for arrays.

I want to construct an array holding the namespaces which I can then place at the TOS (top of stack).

However, if I just write this

ok> [ ns:a , ns:n ]
Exception: invalid JSON array: at line 1 char 3 in ....: cr (G:;;; +000004c2)
Exception: can't find: :a: at line 1 char 6 in (null): cr (G:??? +00000029)
Exception: can't find: ,: at line 1 char 8 in (null): cr (G:??? +00000029)
Exception: can't find: ]: at line 1 char 15 in (null): n (G:??? +00000029)
2

There are 2 best solutions below

2
8th_dev On BEST ANSWER

I'm the developer of 8th. The solution with ' ns:a is not really what you want, since that puts the word in the array instead of the value that word would return.

You can accomplish what you're looking for by using the backtick: [ ` ns:a ` ]

The backtick feeds the text up to the next backtick to eval and puts the value (whatever it is) in the JSON you're creating (it's not limited to JSON, it's a general construct).

0
Graham Chiu On

You can store the function address instead in the array

[ ' ns:n , ' ns:a ]

and access the values by grabbing an array value and exec it

0 a:@ w:exec . cr
2
ok>

You can also use anonymous functions

[ ( ns:a ) , ( ns:m ) ]