AndrewBurton
AndrewBurton

Reputation: 407

Getting strings from words in Rebol

I really feel like I'm missing something simple, so I apologize in advance for even having to ask. In Rebol how do you get a string value from a word/variable in a block? I have this code:

REBOL []
aLink: "http://google.com"
anAtt: "href"
aList: [anAtt aLink]
print "Test 1"
foreach el aList [ print type? el ]
print "Test 2"
foreach el2 aList [ print el2]
print "Test 3"
foreach el2 aList [ print string! el2]

That returns this:

Test 1
word
word
Test 2
anAtt
aLink
Test 3
string
string

What I'd like up in Test 2 is for it to return the values of aLink and anAtt, but in every combination it returns the word name. What am I doing wrong? I'm doing this in REBOL/Core 2.7.8.4.2 on 32-bit Ubuntu using the 2.3 libc binary.

I've used foreach and blocks in other Rebol programs before and never had this trouble. Help!

Upvotes: 2

Views: 101

Answers (1)

In Rebol how do you get a string value from a word/variable in a block?

If you have a WORD! in a value, and it is bound (the ones you have here happen to be) then you're looking for get.

a-link: http://google.com
an-att: "href"
a-list: [an-att a-link]
foreach el a-list [ print get el ]

Output should be:

href
http://google.com

Note modifications. CamelCase-type stuff is not common in Rebol, being case-insensitive for lookup. Also, if you don't strike the quotes from URL! and use the URL! datatype you're missing out on one of the niceties. :-)

Also note that PRINT will implicitly REDUCE a block you give it. So print a-list gives you:

href http://google.com

Upvotes: 1

Related Questions