Casting vs. SPELL

With my bolstered confidence that FILE! best serves as a non-string, I feel like it gives a certain amount of irresistable power.

>> size of %foo.dat
== 143983  ; size of the foo.dat file on disk

(Note: My thinking on SIZE with strings is that it gives you a count in bytes, whereas LENGTH gives you a count in codepoints. This distinction of "length is logical units" and "size is a byte count" has precedent in other systems...but I'd like to go through and make sure that it's being used consistently everywhere. A BINARY! can use either since its logical size is 1, but I'd prefer to speak in terms of the size where possible...e.g. when the binary is not being discussed in the context of a generic length that would apply to any series)

Somewhat extremely, this would suggest I'd be saying that length of %foo.dat would be something that would delegate to whatever the port type was for that file...and give back the logical length of the contents.

; contents of %foo.myformat
[record 1 "foo" #bar]
[record 2 "baz" #mumble]

>> length of %foo.myformat
== 2

We're imagining here that you're living in a world where a "myformat" port would act something like:

>> p: open %foo.myformat

>> read/part p 1
== make object! [
    x: "foo"
    y: #bar
]

>> read/part p 1
== make object! [
    x: "baz"
    y: #mumble
]

>> read/part p 1
; null

Of course I am making this all up. But what I'm trying to get at is that when you want to talk about the attributes of something that is a representation of some grand thing, the number of characters in its name is potentially much less interesting than all the logical things you can ask about it.

That said...it should be easy to ask how long the name is. And this is a little bit ugly:

>> length of as text! %foo.dat
== 7

In the API I've used the word "spell" to talk about string extraction. Might that look nicer?

>> spell %foo.dat
== "foo.dat"

>> length of spell %foo.dat
== 7

I guess it could also be FORM. Though FORM never quite sat right with me, I don't think of it so much as a verb in computer programming as a noun for "form you fill out".

Anyway, this is just to throw out there the idea of SPELL as a way to ask for the underlying string of something that may look a bit better than AS TEXT!.

2 Likes

This is heading in an interesting direction!

When I think "length of " I usually expect to be a noun. So something like:

>> length of chars %foo.dat
== 7

Although to verbify it we'd be looking at something more like:

>> length of as-chars %foo.dat
== 7

or

>> length of as chars %foo.dat
== 7

Which probably doesn't sit well either. It pushes us closer to Hypertext / Applescript syntax.

>> length of form %foo.dat
== 7

Might be imperfect, but it's plain and simple.

Some other pseudocode:

>> query.name %foo.dat
== "foo.dat"

>> length of query.name %foo.dat
== 7

>> file: query %foo.dat
== make object! [
    name: "foo.dat"
    suffix: %.dat
    size: 1869
    date: 10-Aug-2021/10:48:33.724-4:00
    type: 'file
]

>> length of file.name
== 7