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

Confused about "word" forms

 [1/16] from: dukeofperl:ml1 at: 27-Nov-2010 21:52


Hello List.... First of all, the term "form" is confusing to me. Would someone give me an appropriate synonym. 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. 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. If I want the "contents" of age, I would use: :age and have 35 returned to me. is the prefixed ":" the "get-word!" datatype? 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

 [2/16] from: henrikmk:gm:ail at: 2-Dec-2010 9:35


On Sun, Nov 28, 2010 at 5:52 AM, Duke Normandin <dukeofperl-ml1.net> wrote:
> Hello List.... > > First of all, the term "form" is confusing to me. Would someone give > me an appropriate synonym.
I think of how REBOL separates words and strings. FORM is simply a way to convert a word, a value to a string, so it can be printed or transported in a non-REBOL environment. If you want to go the other way, go from string to code, there are several ways: DO, LOAD, TO-BLOCK, depending on your needs. If you want to serialize values properly for storage or transport in a non-REBOL environment, use MOLD/ALL instead of FORM.
> 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 =A0datatype; which itself has the > "word!" datatype.
Yes, that's almost it. Words are symbols, a single identifier that can be used for anything. Furthermore, words can be bound to contexts, so they can hold different values, depending on which context they are bound to. But very importantly, words may not have any values at all, as the words themselves are data: words: [luke skywalker] The words 'luke and 'skywalker don't necessarily refer to anything. It is the block that makes meaning of the words, and they can be parsed by parsers. This is what is going on when you create a GUI with the Visual Interface Dialect, if you are using REBOL2.
> 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?
Somewhat correct. REBOL does not backtrack values to words, so you can't deduce that a block a value of a specific word.
> Where does the "lit-word" datatype come in? I don't get the > terminology!
lit-word!s are ways of expressing words that are not to be reduced to values, but to words. If you type:
>> a
** Script Error: a has no value ** Near: a But if you type:
>> 'a
== a You get the word back. If you set:
>> a: 5 >> reduce [a 'a]
== [5 a]
>> reduce reduce [a 'a]
== [5 5] This is useful when building content for dialects. If you try to access the lit-word!, it becomes a word!, as you will notice in the code example to your next question.
> If I want to have assign something to the "age" container, I would > use:
<<quoted lines omitted: 3>>
> :age and have 35 returned to me. is the prefixed ":" the "get-word!" > datatype?
No, the whole word becomes the set-word! and get-word! type. If you build a block and study it: foreach val [a 1 :a b: c 'd "boo" %test [] #stuff 2.4] [probe type? val] You will see the types for each element in the block and types are largely identifiable by REBOL by what characters are appended or prepended to the word or value. A %-sign indicates a file!, a # is an issue!, square brackets become blocks, etc.
> I'm getting all balled up with the terminology - how is an "action" - > like "get the contents of the word called "age", a datatype?
I'm not sure I understand the question.
> Also, what's the difference between using: > > age: 45 > > SET age 45
When using a set-word!, it's the simplest way to set a value. SET is useful in ways where the 'age word is not directly available, but is accessible from another word, i.e. at times where a set-word! would be cumbersome to use. But there is more to both get-word! and set-word!: get-word! is useful, if you want to obtain a value and you want to be certain that no evaluation takes place, in case the word contains a function. set-word! is useful, if you want to determine the binding of a word to a context:
>> a: make object! [set 'b 1 c: 2] >> a/b
** Script Error: Invalid path value: b ** Near: a/b
>> a/c
== 2 ; meaning that 'c is bound to the 'a context
>> b
== 1 ; meaning that 'b is not bound to the 'a context. That's it for me. There are other people who can lead you much deeper into the rabbit hole. :-) -- Regards, Henrik Mikael Kristensen

 [3/16] 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?
<<quoted lines omitted: 4>>
> 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.

 [4/16] from: lmecir:volny:cz at: 2-Dec-2010 16:55


#[[Duke Hello List.... Duke]] - hi, your questions deserve good answers, and I hope you find my notes below at least a bit helpful. #[[Duke First of all, the term "form" is confusing to me. Would someone give me an appropriate synonym. Duke]] - if I understood you well, you did not want a "synonym" for form , rather you wanted to have a proper notion to refer to different word types. In my opinion, the proper notion is either "datatype", or word type . #[[Duke 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. Duke]] - this is not something you should worry much about. Words are REBOL values of their own right, but they *can* be used as variables, to refer to other REBOL values, also. #[[Duke 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! Duke]] - hmm, this may be quite hard to explain, so, let me introduce the QUOTE function to you. This function takes any argument (in R3) without allowing the DO function (or some of other common evaluators) to evaluate it. Thus, from the QUOTE function we get exactly what we give. Example:
>> type? quote age
== word!
>> quote age
== age So, to obtain the word age you mentioned above, we can use the word and pass it to the QUOTE function. That is not the only way, how to obtain the word age, though, there is yet another way:
>> type? 'age
== word!
>> 'age
== age This is what you may encounter more frequently, but, in fact, the processing is more complicated, than when using the QUOTE function, since, when we examine:
>> type? quote 'age
== lit-word!
>> quote 'age
== 'age we see, that 'age is actually not a word, it is a lit-word! Why, then, the expression 'age yields a word, not a lit-word? The reson is, that every REBOL value is processed (evaluated) somehow by the DO function, unless such an evaluation is prohibited by using e.g. the QUOTE function. And, the evaluation of a lit-word is done so, that the said lit-word is processed, yielding its corresponding word. #[[Duke If I want to have assign something to the "age" container, I would use: age: 35 is the ":" the "set-word!" datatype. Duke]] - no, not at all, the age: value is a set-word, as can be seen when trying:
>> type? quote age:
== set-word!
>> quote age:
== age: And, this set-word, when processed by the DO function, causes the age variable to refer to the integer value 35, which also becomes the result of the expression. #[[Duke If I want the "contents" of age, I would use: :age and have 35 returned to me. is the prefixed ":" the "get-word!" datatype? Duke]] - I refer you to the above explanation, this is just an analogical situation. #[[Duke I'm getting all balled up with the terminology - how is an "action" - like "get the contents of the word called "age", a datatype? ]] - the :age REBOL value has a datatype. The "action" you mention takes effect only when the DO function (or some other similar function) processes the value. #[[Duke Also, what's the difference between using: age: 45 SET age 45 Duke]] - this time, for the expressions to have a similar effect, you need to write: age: 45 ; i.e. you have this right set 'age 45 ; since 'age is processed becoming age before being passed to SET ; or, alternatively: set quote age 45 -Ladislav

 [5/16] from: semseddinm:bircom at: 2-Dec-2010 18:17


-Ladislav: Why quote function acts different in R2? age: 35 ;== 35 quote age ;== 35 ,in R3 == age If quote function would be as below, does it act as expected? (in R2) quote: func ['v] [:v] quote age ;==age Thu, 02 Dec 2010 17:55:18 +0200 tarihinde Ladislav Mecir <lmecir-volny.cz> =FE=F6yle yazm=FD=FE:

 [6/16] from: lmecir:volny:cz at: 2-Dec-2010 17:23


Dne 2.12.2010 17:17, Semseddin Moldibi napsal(a):
> -Ladislav: Why quote function acts different in R2?
You have it right, eddo. Unfortunately, we don't have a proper QUOTE function in R2, neither I am able to define it so, that it works as in R3. The fact, that QUOTE works well in R3 is caused by the improvements Carl built into R3, but these are missing in R2. -Ladislav

 [7/16] from: semseddinm:bircom at: 2-Dec-2010 18:40


Trace results are interesting for quote function in R2 x: 5 quote x Trace: quote (word) Trace: return (word) Trace: get/any (path) Trace: 'value (lit-word) Result: 5 (integer) Result: (error) ;??? Result: 5 (integer) == 5 quote :x Trace: quote (word) Trace: return (word) Trace: get/any (path) Trace: 'value (lit-word) Result: :x (get-word) Result: (error) Result: :x (get-word) == :x ;y is undefined quote :y Trace: quote (word) Trace: return (word) Trace: get/any (path) Trace: 'value (lit-word) Result: :y (get-word) Result: (error) Result: :y (get-word) == :y quote y Trace: quote (word) Trace: return (word) Trace: get/any (path) Trace: 'value (lit-word) Result: (unset) Result: (error) Result: (unset) ;returns unset! probe quote y == unset! Thu, 02 Dec 2010 18:23:00 +0200 tarihinde Ladislav Mecir <lmecir-volny.cz> =FE=F6yle yazm=FD=FE:

 [8/16] from: dukeofperl:ml1 at: 2-Dec-2010 12:24


-Henrik Mikael Kristensen -Semseddin Moldibi -Ladislav Mecir Instead of replying to each message, I'll thank you all right here and now for your detailed responses. Much appreciated! Here then is what I learned from you guys so far, about REBOL words: a plain, old word like "age", or "name" or whatever is - if not recognized by REBOL as part of it's built-in vocabulary - just that, a word with a data-type of "word!" This symbol, or identifier, or plain, old "word" can be used in different was, giving the word a new meaning each time. Appended with a colon - like age: - morphs "age" from a simple word! data-type, to a set-word! data-type. This is how values get assigned to "words". prepending with a colon - like :age - morphs "age" into a get-word! data-type, which returns the value assigned to "age" prepending with an apostrophe - like 'age - morphs "age" into a lit-word! data-type, which when executed returns its own name - "age" Using "age" by itself at the core prompt, also returns the value assigned to age. How did I do? So what's the diff between using "age" by itself, and ":age" to scoop the value? -- Duke

 [9/16] from: compkarori:g:mail at: 2-Dec-2010 21:45


On Fri, Dec 3, 2010 at 8:24 AM, Duke Normandin <dukeofperl-ml1.net> wrote:
> So what's the diff between using "age" by itself, and ":age" to scoop > the value? > > -- > Duke
Try that with a function. -- Graham Chiu http://www.compkarori.co.nz:8090/ Synapse - the use from anywhere EMR.

 [10/16] from: dukeofperl:ml1 at: 2-Dec-2010 13:03


On Fri, 3 Dec 2010, Graham Chiu wrote:
> On Fri, Dec 3, 2010 at 8:24 AM, Duke Normandin <dukeofperl-ml1.net> wrote: > >
<<quoted lines omitted: 4>>
> > Duke > Try that with a function.
OK! I guess only :age will work in a function :) age and :age will both work at the core prompt. -- Duke

 [11/16] from: izkata:gmai:l at: 2-Dec-2010 14:37


On Thu, Dec 2, 2010 at 2:03 PM, Duke Normandin <dukeofperl-ml1.net> wrote:
> On Fri, 3 Dec 2010, Graham Chiu wrote: > >
<<quoted lines omitted: 10>>
> OK! I guess only :age will work in a function :) > age and :age will both work at the core prompt.
Not in a function, on a function - for example:
>> age: func [][print "I am 22" return 0]
Using just age will evaluate the function:
>> age
I am 22 == 0 Using the get-word :age appears to do nothing, but that's because it retrieved the function instead of evaluated it:
>> :age >> probe age
I am 22 0 == 0
>> probe :age
func [][print "I am 22" return 0] It appears to do nothing different when using word!s as variables for integers, strings, etc, because in those cases, evaluating it just retrieves it. -- <*>

 [12/16] from: dhsunanda::gmail at: 2-Dec-2010 20:39


> OK! I guess only :age will work in a function :) > > age and :age will both work at the core prompt.
I think Graham may mean something slightly different. age1: 45 age2: func [] [return ask "how old are you"] All these return the value associated with age1: age1 == 45 :age1 == 45 get 'age1 == 45 But watch the difference with 'age2 age2 how old are you(escape) ;; ie executes the function :age2 ;; appears to do nothing get 'age2 ;; ditto So try: type? :age2 == function! ;;ah ha! it returns the function, rather than executes it probe get 'age2 ;; ditto func [][return ask "how old are you"] See the difference? Sunanda.

 [13/16] from: dukeofperl:ml1 at: 2-Dec-2010 13:57


-Izkata -Sunanda Got it! Thanks! -- Duke

 [14/16] from: compkarori::gmail at: 2-Dec-2010 21:46


Sorry for being obtuse On Fri, Dec 3, 2010 at 9:57 AM, Duke Normandin <dukeofperl-ml1.net> wrote:
> -Izkata > -Sunanda
<<quoted lines omitted: 4>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu http://www.compkarori.co.nz:8090/ Synapse - the use from anywhere EMR.

 [15/16] from: compkarori::gmail at: 2-Dec-2010 21:46


Generally I use this form ie. :func to pass functions as parameters to other functions. This is usually used for callbacks. On Fri, Dec 3, 2010 at 12:07 PM, Graham Chiu <compkarori-gmail.com> wrote:
> Sorry for being obtuse > On Fri, Dec 3, 2010 at 9:57 AM, Duke Normandin <dukeofperl-ml1.net> wrote:
<<quoted lines omitted: 11>>
>> >>
-- Graham Chiu http://www.compkarori.co.nz:8090/ Synapse - the use from anywhere EMR.

 [16/16] from: dukeofperl:ml1 at: 2-Dec-2010 17:02


On Fri, 3 Dec 2010, Graham Chiu wrote:
> Sorry for being obtuse > On Fri, Dec 3, 2010 at 9:57 AM, Duke Normandin <dukeofperl-ml1.net> wrote:
<<quoted lines omitted: 3>>
> > > > Got it! Thanks!
Not at all! I'm missing something here, because I don't think that I received your ML message. Maybe the server or my uplinks had a hiccup. -- Duke

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted