3

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)
tofutim
  • 22,664
  • 20
  • 87
  • 148
Graham Chiu
  • 4,856
  • 1
  • 23
  • 41
  • 1
    wow, i never heard of 8th, how do you like it? – tofutim May 21 '16 at 05:54
  • It's a full featured closed source forth with GUI and multiplatform support including OSX, Windows, and Android. Liking it so far! – Graham Chiu May 21 '16 at 05:56
  • are you using a paid version? it says the free is 'limited' but does not really explain why – tofutim May 21 '16 at 06:15
  • The binaries you compile with the free version only work for 2 days I think. There is no timeout on the binaries built by paid versions. But I'm working in the REPL. – Graham Chiu May 21 '16 at 06:21
  • well, I registered and downloaded the zip but sadly neither mac64 and the mac32 launch in OSX - bad omen ;P – tofutim May 21 '16 at 06:25
  • I don't know anything about OSX. But I see this "For your convenience, you should unzip the 'bin/osx.app.zip' and copy the %s executable to 8th.app/Contents/MacOS/8th\n" whatever that means. – Graham Chiu May 21 '16 at 06:32
  • ok, i got it to work - just does not launch when you click it, but i can run the REPL if i go into a shell – tofutim May 21 '16 at 06:43
  • I figured out how solve my problem. Store the execution address in the array instead. – Graham Chiu May 21 '16 at 06:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112561/discussion-between-tofutim-and-graham-chiu). – tofutim May 21 '16 at 07:24

2 Answers2

5

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).

8th_dev
  • 106
  • 6
  • so, the first backtick needs a space before and after it, but the second does not need the preceding space. – Graham Chiu May 21 '16 at 20:06
  • Yes, if you use the backtick in the REPL; but inside JSON it is interpreted immediately (so it doesn't require spaces around it). However, it is better practice to get in the habit of surrounding the leading backtick with spaces. – 8th_dev May 22 '16 at 06:16
2

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 ) ]
Graham Chiu
  • 4,856
  • 1
  • 23
  • 41