notes-computer-programming-programmingLanguageDesign-prosAndCons-nockOld

Alternate Nock notation

We can rewrite Nock expressions into more familiar prefix notation if we swap the position of subject and verb and if we use names instead of opcodes. We may also want to put the subject in the last argument position instead of the first. Note that we'll end up with 'uncompleted' code in the subject that has not yet been assigned a subject. For example, the above infinite loop becomes:

nock(select(1, subject_placeholder), select(1, subject_placeholder), nock(select(1, subject_placeholder) select(1, subject_placeholder), subject_placeholder))

we can make this more concise by omitted the subject until it is assigned, and using the special notation '

subject=()' to give a subject when it assigned:

nock(select(1), select(1), subject=nock(select(1) select(1)))

and we can indent:

nock(select(1), select(1))

subject=(nock(select(1),
                select(1))))

and we can omit the 'eval's, and use the convention that applying a subject is only done at eval time.

Now the reduction looks like:

nock(select(1), select(1))

subject=(nock(select(1),
                select(1)))

select(1))

subject=(nock(select(1),
                           select(1)))
subject=(select(1)subject=(nock(select(1),
                                     select(1))))

nock(select(1), select(1))

subject=(select(1)subject=(nock(select(1),
                                     select(1))))

nock(select(1), select(1))

subject=(nock(select(1),
                 select(1)))

Compare to the notation used above, with added indentation:

eval([nock [select 1] [select 1]] nock [select 1] [select 1])

eval(eval([nock [select 1] [select 1]] [select 1]) eval([nock [select 1] [select 1]] [select 1]))

eval([nock [select 1] [select 1]] [nock [select 1] [select 1]])

(by right associativity of [])

eval([nock [select 1] [select 1]] nock [select 1] [select 1])

The prefix notation requires more characters but takes up less verbal space. It is unclear to me which, if either, is preferable; i think i prefer the bottom (non-prefix) notation. One could take less vertical space in the bottom by only giving a newline between subjects and the rest of their nodes:

eval([nock [select 1] [select 1]] nock [select 1] [select 1])

eval(eval([nock [select 1] [select 1]] [select 1]) eval([nock [select 1] [select 1]] [select 1]))

eval([nock [select 1] [select 1]] [nock [select 1] [select 1]])

(by right associativity of [])

eval([nock [select 1] [select 1]] nock [select 1] [select 1])

One could perhaps mix-and-match further, by moving the subject to the end position, and writing

in between the subject and the rest:

eval[nock [select 1] [select 1]

nock [select 1] [select 1]]

eval[eval[[select 1]

nock [select 1] [select 1]]
eval[[[select 1]
nock [select 1] [select 1]]]]

eval[nock [select 1] [select 1]

nock [select 1] [select 1]]

i think i like that last notation the best. One could make it shorter by replacing the primitive operations by short mnemonics:

eval[NOK [SEL 1] [SEL 1]

NOK [SEL 1] [SEL 1]]

eval[eval[[SEL 1]

NOK [SEL 1] [SEL 1]]
eval[[[SEL 1]
NOK [SEL 1] [SEL 1]]]]

eval[NOK [SEL 1] [SEL 1]

NOK [SEL 1] [SEL 1]]