Why Does Quoting Change the TYPE OF a Value?

My inclination with reflection is that types return the same no matter the quotedness:

>> type of first [1]
== \~{integer!}~\  ; antiform (datatype!)

proposed>> type of first ['1]
== \~{integer!}~\  ; antiform (datatype!)

And that the quotedness should be determined separately:

proposed>> quotes of first [1]
== \~null~\  ; antiform (logic!)  ; or whatever the flow-breaking mechanism is

>> quotes of first ['1]
== 1

>> quotes of first [''1]
== 2 ; etc.

In Parse, you would need to match the exact number of quotes:

parse [1 '1 ''1 '''1] [
    '1
    quoted '1
    quoted quoted '1
    quoted quoted quoted '1
]

The return of quoted datatypes seems problematic.

Unrelated: is that a quoted number I see on the last example here?

I'd strongly advise against such a design.

My technical concern is that if you conflate a quoted type with its underlying type, then by default you'd wind up with dialects that inadvertently treat quoted things and non-quoted things identically. This seems chaotic to me, and also it will create problems down the road when one decides to start using quotes creatively in dialects.

Imagine that people using your dialect realize you haven't checked both the type and the quotedness. So as a user, they don't bother stripping off the quotes when they are generating code (since an INTEGER! will accept a quoted INTEGER! anyway, why should they?) Things would wind up looking a mess.

Plus then later, imagine you do decide you would like to distinguish the meaning of quoting to have it mean something distinct... but people are relying on your laxness.

Yep.

And what you may have some conceptual worry over is having TYPE OF any quoted thing equaling the TYPE OF any other quoted thing.

But... consider that the TYPE OF any BLOCK! equals the TYPE OF any other BLOCK!.

If you think of quoting as a "container", then it becomes coherent to say that 'foo and ''''[a b c] and ''7 all have the "same type".

Consider two prominent examples where the most important thing about being quoted--in terms of behavior--is that it's a QUOTED!:

  • In the evaluator, 'foo and ''''[a b c] and ''7 all do the "same thing", they drop one quote and give you what's left over.

  • In PARSE, 'foo and ''''[a b c] and ''7 all do the "same thing", they drop one quote and try to match the thing that's left over.


Sidenote: I'll point out that treating unquoted types the same as their quoted types would create incompatibility with history:

rebol2>> type? first [x]
== word!

rebol2>> type? first ['x]
== lit-word!

rebol2>> (type? 'x) = (type? first ['x])
== false

And that's even with a pretty lax equality operator:

rebol2>> equal? first [x] first ['x]
== true

Of course incompatibility is not something I worry about too much (unless there's no way to implement a compatible behavior!)

I updated my answer here (to say that I consider this matter decided, vs. the original 2019 "maybe I'd change it if there were a good reason...")

While editing I updated the code samples, and noticed that you had proposed (assumed?) this would not be zero.

But it is zero, and I realized reviewing this that I hadn't really thought about it being not zero.

I think it should probably stay zero, and we need some kind of "turn zeros into nulls" operator.

Also, a QUOTED combinator, doesn't seem like a bad idea.

(Compare match ['word!] with quoted word!, for example.)