17
2
Inspired by, and in memory of, our beloved genius,
R.I.P.
He invented and implemented dfns — his magnum opus and the subject of the challenge.
For the interested: latest full dfns documentation and videos with John.
Task
Given an ASCII source code, answer in which of the following four categories it belongs:
Dyadic dop
Monadic dop
Dfn
Other
You may return any four consistent values, but please state your mapping if it isn't obvious.
Details
You may assume that the source code always begins with an opening curly brace {
and ends with a closing curly brace }
.
Recursively nested braces can occur (e.g. {{{}}}
), but categories 1–3 can never have brace nesting depth go below 1 (so {}{}
is "Other") and all braces must be balanced (so {{}
is "Other").
Characters in the following contexts on a line are ignored:
To the right of
#
(a comment):significant#ignored
Enclosed in single quotes
'
…'
(i.e. in a string):significant'ignored'significant
(This applies to#
too:'#'significant
)To the right of an unpaired quote
'
(pairing quotes from the left):significant'ignored
In curly brace level one (i.e. excluding nested braces):
Dyadic dops contain the uninterrupted phrase
ww
Monadic dops do not contain
ww
, but do containaa
Dfns contain neither
ww
noraa
Test cases
Dyadic dops
{ww}
{
www
}
{
''ww'
}
{aa
ww}
{'#''#'ww?aa}
Monadic dops
{aa}
{aaaa}
{aa{ww}'ww'}
{w#w'
aa'
}
{aaw*w}
{w'\'aa\''}
Dfns
{}
{a a}
{aA}
{
{aa}
}
{w
w''w#
w}
{{
}}
{w\'aa\'}
Other
{}{}
{{}
{}}
{ww}}
{}
{}
{ww}{}
{#}
{'
'}
@LuisfelipeDejesusMunoz Dfn. If you see a reason to think otherwise, please let me know. – Adám – 2019-02-19T13:38:59.567
1Can string quotes be escaped, and if so do we need to handle them? (eg:
{'#\'ww?aa'}
-> other?) – Οurous – 2019-02-19T21:27:58.8031@Οurous No, the spec is as stated: Anything in quotes is insignificant. (Indeed, APL strings have no escape mechanism.) I'll add a case. – Adám – 2019-02-20T05:14:24.687
Hm, may we assume that strings will not contain
''
(apostrophe in string, can also be parsed as two adjacent strings for this challenge)? – Erik the Outgolfer – 2019-02-20T16:23:35.330@EriktheOutgolfer It may occur. I'll add a case, but as you say, it doesn't matter whether
'abc''def'
is parsed as one or two strings for this challenge. – Adám – 2019-02-20T16:57:12.420