| Type | Bug | Status | submitted | Date | 2-Jul-2010 11:16 |
|---|---|---|---|---|---|
| Version | alpha 99 | Category | Unspecified | Submitted by | Ladislav |
| Platform | All | Severity | minor | Priority | normal |
| Summary | SPEC-OF and BODY-OF are misleading |
|---|---|
| Description |
Porting the %include.r3 script to R3 I noticed, that I cannot use the THIRD function to obtain the SPEC block of the object as accepted by the MAKE function. Therefore, I used the SPEC-OF function, which yielded NONE for the object. (see example below) It was a surprise for me, and I needed some search to find out, that the BODY-OF function might eventually yield the required value. I see it as a bug, and a gotcha, since objects don't have bodies, but it should be possible to obtain the SPEC block acceptable by the MAKE function. Examining the subject further, it looks, that the SPEC-OF function actually yields a header of the value, not the expected SPEC of it. |
| Example code |
>> o: make object! [x: 1]
== make object! [
x: 1
]
; the [x: 1] block expected
>> spec-of o
== none
; NONE expected
>> body-of o
== [
x: 1
]
|
| Assigned to | n/a | Fixed in | - | Last Update | 31-Aug-2010 00:26 |
|---|
| Comments | |
|---|---|
|
(0002422)
BrianH 2-Jul-2010 11:49 |
What you think of the spec of an object is only part of the spec that it will have eventually. The SPEC-OF function is really not appropriately used for modules either, since what it returns is more of a header than the whole spec, which would include the module body. But since we don't have a 'header reflector, we use SPEC-OF to return the header instead, since that is how it works for functions.
The same goes for objects: SPEC-OF returns their header, if any. And you can make an object that has a header by using it as the context of a module. What you can't yet do is specify a header in MAKE object! syntax, because that syntax hasn't been updated to support headers yet. It's still on the todo list. An object "body" is created by combining the words and the values of the object, and we don't have another reflector that comes close to this meaning since the real body - the code block portion of the object spec - is thrown away after the object is created, so we have to make do with a recreation of it. But even the original body is only part of the object spec, in theory, the other part being the header we can't directly make yet. So in summary: - What you think is the spec of an object isn't the complete spec: It is the body, same as a function body. - BODY-OF can't return the real body of an object or module since that is thrown away after use, so it creates a fake body instead. - SPEC-OF returns a header, but we decided to call it SPEC-OF anyways (nobody ever revealed why). - Objects can have a header (surprise!), and when they do, SPEC-OF returns it. - Most objects don't have headers since there is no syntax support for them, so SPEC-OF returns none. |
|
(0002427)
BrianH 2-Jul-2010 12:56 |
It would be possible to create a specification for an object that would be similar, even if the original specification is thrown away after the initial object was created (answer to deleted comment). However, what BODY-OF creates is a body of object initialization code, in code format. Objects don't yet have full specifications in R3; like R2, the specification of the object is inferred from the initialization code by scanning for set-words. This scan is used to create the internal layout of the object. Then the body of the code is run, and tossed.
You can think of the body of a object as being like the body of a closure that is only run once then thrown away, with the words of the object (corresponding to the closure's arguments) being collected from the body ahead of time using COLLECT-WORDS/set instead of explicitly specified. Modules work the same way, except COLLECT-WORDS/set is called by BIND/only/set instead of MAKE. I agree that it is unfortunate that what SPEC-OF returns is not the same thing as the spec argument to MAKE, for many types. Perhaps it is the spec argument of MAKE that is misnamed, perhaps it is SPEC-OF. |
|
(0002465)
Ladislav 24-Aug-2010 13:23 |
This looks as a documentation problem too, http://www.rebol.com/r3/docs/datatypes/function.html describes:
make function! [[specs][body]] , while I prefer to say, that the SPEC (argument of MAKE) is [[header] [body]], i.e. the first part of the function SPEC is the HEADER, and the second part of the SPEC is the BODY. |
|
(0002466)
PeterWood 24-Aug-2010 16:00 |
IT really does seem that referring to the argument to MAKE as spec is quite misleading and it is certainly different from a "function spec". Take these un-real examples:
>> a: make object! 100000 == make object! [ ] What should SPEC-OF return in this case? Here is a slightly less un-real example: >> b: make map! 1000 == make map! [ ] >> reflect b 'spec ** Script error: invalid argument: spec ** Where: reflect ** Near: reflect b 'spec >> reflect b 'body == [] Here the "spec" to the original MAKE is not returned by any of the options of REFLECT which somewhat reinforces BrianH's point above. Also the terminology for MAKE FUNCTION! looks a bit recursive: make function! [spec] where spec = [[spec] [body]] I understand that neither of these examples may be relevant but they do demonstrate that the terminology could be clearer. Perhaps function specs should be referred to as some thing like signatures. |
|
(0002467)
PeterWood 24-Aug-2010 16:06 |
A small further point. The description in the help text of SPEC-OF states: "Returns a copy of the spec of a function or module" but the function accepts any value. Perhaps SPEC-OF should only accept functions and modules?
|
|
(0002474)
PeterWood 25-Aug-2010 03:39 |
On reflection, it would seem better to rename the "spec" to MAKE as "initial" to reflect they are the initial values of any mutable datatype. |
|
(0002481)
Gregg 31-Aug-2010 00:26 |
Assuming SPEC-OF returns the header for an object (the bit that specifies type restrictions, as in func specs) when that becomes available, I don't think it needs to change. 'Spec is overloaded. I wouldn't say it's misleading, but we could use a matrix showing what various reflection values are for different datatypes. 'Header and 'initial are more specific, but I don't know if they add value. |
| Date | User | Field | Action | Change |
|---|---|---|---|---|
| 31-Aug-2010 00:26 | Gregg | Comment : 0002481 | Added | - |
| 25-Aug-2010 03:39 | PeterWood | Comment : 0002474 | Added | - |
| 24-Aug-2010 16:06 | PeterWood | Comment : 0002467 | Added | - |
| 24-Aug-2010 16:00 | PeterWood | Comment : 0002466 | Added | - |
| 24-Aug-2010 13:23 | Ladislav | Comment : 0002465 | Added | - |
| 3-Jul-2010 08:28 | Ladislav | Description | Modified | - |
| 3-Jul-2010 08:27 | Ladislav | Comment : 0002426 | Removed | - |
| 3-Jul-2010 08:27 | Ladislav | Description | Modified | - |
| 3-Jul-2010 08:26 | Ladislav | Description | Modified | - |
| 3-Jul-2010 08:21 | Ladislav | Comment : 0002426 | Modified | - |
| 2-Jul-2010 13:08 | BrianH | Comment : 0002427 | Modified | - |
| 2-Jul-2010 13:07 | BrianH | Comment : 0002427 | Modified | - |
| 2-Jul-2010 13:00 | BrianH | Comment : 0002427 | Modified | - |
| 2-Jul-2010 12:56 | BrianH | Comment : 0002427 | Added | - |
| 2-Jul-2010 12:51 | Ladislav | Comment : 0002425 | Removed | - |
| 2-Jul-2010 12:51 | Ladislav | Description | Modified | - |
| 2-Jul-2010 12:48 | Ladislav | Comment : 0002423 | Removed | - |
| 2-Jul-2010 12:48 | Ladislav | Code | Modified | - |
| 2-Jul-2010 12:48 | Ladislav | Summary | Modified | Objects don't have bodies => SPEC-OF and BODY-OF are misleading |
| 2-Jul-2010 12:48 | Ladislav | Description | Modified | - |
| 2-Jul-2010 12:47 | Ladislav | Comment : 0002426 | Modified | - |
| 2-Jul-2010 12:42 | Ladislav | Comment : 0002425 | Modified | - |
| 2-Jul-2010 12:42 | Ladislav | Comment : 0002424 | Removed | - |
| 2-Jul-2010 12:12 | Ladislav | Comment : 0002426 | Modified | - |
| 2-Jul-2010 12:11 | Ladislav | Comment : 0002426 | Added | - |
| 2-Jul-2010 12:08 | Ladislav | Comment : 0002425 | Added | - |
| 2-Jul-2010 12:07 | Ladislav | Comment : 0002424 | Added | - |
| 2-Jul-2010 12:04 | Ladislav | Comment : 0002423 | Added | - |
| 2-Jul-2010 11:51 | BrianH | Comment : 0002422 | Modified | - |
| 2-Jul-2010 11:49 | BrianH | Comment : 0002422 | Added | - |
| 2-Jul-2010 11:16 | Ladislav | Ticket | Added | - |