Namespaces Quiz

?

Hi all, would anybody be able to help me here. I want to create ( .animal.dog) and ( .animal.cat) using sv however I end up just joining cat and dog to animal to get this. 

 

I have created the namespace when n and v are single symbols however I’m running into errors when they are lists of symbols. 

 

Any help is greatly appreciated.

Lots of ways to do this, my first thought was to append  the cat dogs to the `animal making two lists and then separately performing the sv

q).animal ,/: catdog .animal cat .animal dog q) sv ’ .animal ,/: catdog .animal.cat`.animal.dog

If you don’t have the . before animal you could write like this

q)sv’[`]``animal,/:`cat`dog `.animal.cat`.animal.dog

There might be a more elegant implementation here, but should help…

Thank you very much for your help!

Just on that note, I realise this was not your question but as it pertains to namespaces wanted to provide some flavour around namespace definition alternate methods

// Definining namespace q).test:((::),a,b)!((::),1,2) q).test ::| :: a| 1 b| 2 // However we can create the namespace as an empty // dictionary and assign keys after creation q).test:{x!x}enlist(::) q).test[a]:1 q).test[b]:2 q).test ::| :: a| 1 b| 2 // also acceptable method q).test:{x!x}enlist(::) q).test[ab]:1 2 q).test ::| :: a| 1 b| 2

 

Slight correction on Paul’s second answer. Creating a template namespace should have backtick ` as key not (::)

q).test.a:1
q).Q.s1 .test
"``a!(::;1)"

So you create a template like:

q).test:enlist[`]!enlist(::)
q).Q.s1 .test
"(,`)!,::"
q).test[`a]:1
q).Q.s1 .test
"``a!(::;1)"

 

q)ns:`animal
q)n:`dog`cat
q)v:`rover`whiskers
q)sv[`;`,ns] set enlist[`]!enlist (::) //Create the empty namespace
`.animal
q).Q.s1 .animal
"(,`)!,::"
q)@[` sv `,ns;n;:;v] //Add the values
`.animal
q).animal
| ::
dog| `rover
cat| `whiskers