tags:

views:

49

answers:

2

This works:

>> Oblock: [FirstName: ""
[    LastName: ""
[    BirthDate: ""]
== [FirstName: ""
    LastName: ""
    BirthDate: ""
]
>> Person: Make Object! OBlock
>> Person
>> probe Person
make object! [
    FirstName: ""
    LastName: ""
    BirthDate: ""
]
>> Person/FirstName
== ""
>> Person/FirstName: "John"
== "John"

But this doesn't work

>> List: ["Id" "FirstName" "LastName"]
== ["Id" "FirstName" "LastName"]
>> Person: []
== []
>> foreach attribute List [
[      Append Person to-word rejoin [attribute {: ""}]
[    ]
== [Id: "" FirstName: "" LastName: ""]
>> Person/FirstName
** Script Error: Invalid path value: FirstName
** Where: halt-view
** Near: Person/FirstName
>>

Why ?

A: 

Finally I have found it: use construct load http://reboltutorial.com/blog/application-configuration/

+1  A: 

There are so many ways to do this, but here's one way that adheres closely to the way you seem to envision it:

list: [ "Id" "FirstName" "LastName" ]
person: []
forall list [
    repend person [to-set-word first list ""]
]
person: make object! person
print person/FirstName
; == ""

In a traditional programming language, you do something like this to set the value of a variable:

x = 3;

In REBOL, you do this:

x: 3

In a traditional programming language, = is an operator, but : is not an operator in REBOL. It is a part of the word itself. This is a very important distinction, and it's why what you tried to do above did not work. x: is a set-word!, and to make one from a string you have to use to-set-word.

to-set-word "x"
; == x:

Also, you seem to be confusing objects and blocks. This is an object:

person: make object! [ first-name: "Jasmine" last-name: "Byrne" ]

This is a block:

person: [ first-name "Jasmine" last-name "Byrne" ]

They are not the same.

Gregory Higley