Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Confused about "word" forms

From: semseddinm:bircom at: 2-Dec-2010 10:57

> Hello List.... > > First of all, the term "form" is confusing to me. Would someone give > me an appropriate synonym.
I'm sure, gurus will answer much better, but here is 50 cent. form is a native which converts all values to human readable strings.
> I understand that a Rebol "word" is not a variable bound to a datatype > as in other programming languages. It is merely the "name" of a > container which can hold any Rebol datatype; which itself has the > "word!" datatype.
Words are just symbols which can be a variable or not. They can hold a value (which can be any value, native, function, string, email etc.). Or they don't hold a value then they are just symbols.
> Assuming the Rebol word "age", if I want to have the name of the > container returned to me, I would use the syntax (form) 'age. Correct? > Where does the "lit-word" datatype come in? I don't get the > terminology! > > If I want to have assign something to the "age" container, I would > use: > > age: 35 > > is the ":" the "set-word!" datatype.
Yes it is a set-word which means you are assigning a value to a word. where does lit-word come in, if you need to talk about a word itself not by its value. If you type age and if it has a value you will get that value, if you type 'age it means you are talking about the age word. Try these examples: type? first [a:] ;== set-word! type? first [:a] ;== get-word! type? first ['a] ;== lit-word! type? first [a] ;== word! And also try to examine the source codes of probe and source functions: ?? probe ?? source You will see the usage of lit-word and get-word.
> If I want the "contents" of age, I would use: > > :age and have 35 returned to me. is the prefixed ":" the "get-word!" > datatype?
:age is a get-word. age and :age both return same value which is 35. But it is important if age is a function! age: func [] [7 * 5] age ;will return 35, the value by evaluated by age function. :age ;returns the function itself. Now look at that: probe age ;==35 probe :age ;==func [][7 * 5] without get-word age will be evaluated. So you can pass a function as a argument also: f: func [x] [probe :x] f :age ;==func [][7 * 5]
> I'm getting all balled up with the terminology - how is an "action" - > like "get the contents of the word called "age", a datatype? > > Also, what's the difference between using: > > age: 45 > > SET age 45 >
they are similar, but there is a bit difference. Currently you can skip that part :) Look at below for one of example using set: f: does [print "no return value"] a: f no return value ** Script Error: a needs a value ** Near: a: f set/any 'a f no return value ;no error occurred, a is unset! Try reading the core.pdf it has lots of explanations about words. Those set-, get-, lit- words are mostly useful when you are parsing an input: parse [a: 5 'b :f] [set-word! integer! lit-word! get-word!] ;== true Of course it is a meaningless example but you get the idea, you can parse a config file, a user input, any blocks come from network etc.. But Parse is another deep topic. Hope I could help.