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

"get" function

 [1/13] from: dukeofperl:ml1 at: 8-Nov-2010 19:54


From "REBOL/Core Users Guide - Chapter 4 - Expressions": [quote] print native? :if true Here the get returns the function for if. [/quote] Is this a typo? I don't see the "get" function being used. Is it implied in native? -- Duke

 [2/13] from: edoconnor::gmail at: 8-Nov-2010 22:44


You might find this a bit confusing at first... The colon notation (i.e., :if) refers to the value referenced to the word 'if. This notation with the colon in front of the word is called the "get" function. The example expression tells REBOL to print the result of applying native? to the value referenced by the word if. A complex value like a function has the form: <set-word:> <function body> By using the "get" form of the word (instead of the "set/assignment" form), you are ensuring that native? processes the value referenced by if-- a function body-- and not merely the word if. I hope this helps. On Mon, Nov 8, 2010 at 9:54 PM, Duke Normandin <dukeofperl-ml1.net> wrote:

 [3/13] from: pwawood:gma:il at: 9-Nov-2010 11:52


On 9 Nov 2010, at 10:54, Duke Normandin wrote:
> =46rom "REBOL/Core Users Guide - Chapter 4 - Expressions": > [quote]
<<quoted lines omitted: 4>>
> Is this a typo? I don't see the "get" function being used. Is it > implied in native?
No, it's not a typo. The "get" function (or an equivalent) was used. No, it's not implied in native? What you wrote was equivalent to:
>> print native? get 'if
true The : prefix denotes a get-word value, that is to say :if is a get-word. In REBOL a get-word evaluates to the "contents" of the word. (I quoted contents because depending on the type of value, the result of the evaluation may be the value referred to in the word - as is the case with functions). The section on Words in the REBOL/Core 2.3 docs is still valid - http://www.rebol.com/docs/core23/rebolcore-4.html#section-5 Regards Peter =20=

 [4/13] from: henrikmk::gmail at: 9-Nov-2010 15:03


On Tue, Nov 9, 2010 at 4:52 AM, Peter W A Wood <pwawood-gmail.com> wrote:
> On 9 Nov 2010, at 10:54, Duke Normandin wrote: >>
<<quoted lines omitted: 23>>
> Regards > Peter
It's also a nice shortcut for a security measure to avoid running functions, if you are processing untrusted input, where it would be possible to inject a function and you don't want to limit the possible datatypes in the function argument. my-func: func [data] [ case [ any-function? :data [:data] ; pass it through series? :data [parse :data my-rules] ; process it ] ] my-func some-dangerous-function == make function! [.... There are better examples, but that is the general idea. -- Regards, Henrik Mikael Kristensen

 [5/13] from: dukeofperl:ml1 at: 9-Nov-2010 8:54


MESSAGE RE-FORMATED TO BOTTOM-POSTING On Mon, 8 Nov 2010, Ed O'Connor wrote:
> On Mon, Nov 8, 2010 at 9:54 PM, Duke Normandin <dukeofperl-ml1.net> wrote: > >
<<quoted lines omitted: 20>>
> if-- a function body-- and not merely the word if. > I hope this helps.
So, in a nutshell, `:blah' is identical to `get blah'? -- Duke

 [6/13] from: tim-johnsons:web at: 9-Nov-2010 7:29


* Duke Normandin <dukeofperl-ml1.net> [101108 18:45]:
> From "REBOL/Core Users Guide - Chapter 4 - Expressions": > [quote]
<<quoted lines omitted: 4>>
> Is this a typo? I don't see the "get" function being used. Is it > implied in native?
print native? :if ;; is the equivalent of print native? get 'if ;; I think :) I.E. get 'if ;; is the equivalent of :if ;; I think ? ? ? .... but there may be subtle differences. Let's see what others say. I'm falling in love with rebol all over again. -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com

 [7/13] from: henrikmk::gmail at: 9-Nov-2010 17:43


On Tue, Nov 9, 2010 at 4:54 PM, Duke Normandin <dukeofperl-ml1.net> wrote:
> So, in a nutshell, `:blah' is identical to `get blah'?
it's: get 'blah not: get blah :-) it does the same, but GET allows you to for example retrieve any kind of value: get/any 'my-value == unset! even if it's unset.
>> :my-value
** Script Error: my-value has no value ** Near: :my-value GET is also used on objects:
>> get in system/view/screen-face 'size
== 1208x815 -- Regards, Henrik Mikael Kristensen

 [8/13] from: santilli:gabriele:gmai:l at: 9-Nov-2010 17:53


On Tue, Nov 9, 2010 at 5:43 PM, Henrik Mikael Kristensen <henrikmk-gmail.com> wrote:
> GET is also used on objects: > >>> get in system/view/screen-face 'size > == 1208x815
LOL, not in this case, where you're passing a word. I assume, you wanted to refer to this:
>> obj: context [a: 1 b: 2] >> get obj
== [1 2]
>> set obj [3 4]
== [3 4]
>> print obj
a: 3 b: 4

 [9/13] from: edoconnor:gma:il at: 9-Nov-2010 11:54


> So, in a nutshell, `:blah' is identical to `get blah'? > -- > Duke > --
As far as I know, yes, although the get notation is probably quicker. if is the standard or natural form; it refers to the action of returning any referenced value if: is the "set form"; it refers to the action of assigning if to a value 'if is the literal form; it refers to the word/symbol, isolated from any value it references :if is the "get form"; it refers to the referenced value, isolated from any word handles on the value If you evaluate native? if, you'll run into a problem because you used the natural form of if, which means it will trigger the dereferencing process (which requires arguments to be supplied to the function). You can inspect the function value referenced by if just like a series. To do this, use the get-form (or the get function) and use a series function:
>> first :if
== [condition then-block /else else-block]
>> second :if
== none
>> third :if
== [ "If condition is TRUE, evaluates the block." condition then-block [block!] /else "If not true, evaluate this block" else-block [block!] ] if is a native in R2, so there isn't much to access here. A function like probe might be better, since it's a mezzanine. Here are some of the guts of the simple probe function.
>> second :probe
== [ print mold :value :value ]
>> first second :probe
== print
>> second second :probe
== mold

 [10/13] from: henrikmk:gma:il at: 9-Nov-2010 18:23


On Tue, Nov 9, 2010 at 5:53 PM, Gabriele Santilli <santilli.gabriele-gmail.com> wrote:
> On Tue, Nov 9, 2010 at 5:43 PM, Henrik Mikael Kristensen > <henrikmk-gmail.com> wrote:
<<quoted lines omitted: 3>>
>> == 1208x815 > LOL, not in this case, where you're passing a word.
Well, more correctly, it's IN that's passing a word to GET, but the get in <object> <value> combination is a common code pattern, thus valuable to learn. -- Regards, Henrik Mikael Kristensen

 [11/13] from: santilli:gabriele:g:mail at: 9-Nov-2010 23:14


On Tue, Nov 9, 2010 at 6:23 PM, Henrik Mikael Kristensen <henrikmk-gmail.com> wrote:
> Well, more correctly, it's IN that's passing a word to GET, but the
If you want to be "more correct", then no, IN is simply returning a word, not passing it to something else. But, this is just terminology and it does not matter that much. The key issue is that GET is still getting a word, and there is no difference actually with the other examples. "GET on an object" is a different thing.

 [12/13] from: dukeofperl:ml1 at: 9-Nov-2010 21:42


On Tue, 9 Nov 2010, Henrik Mikael Kristensen wrote:
> On Tue, Nov 9, 2010 at 4:54 PM, Duke Normandin <dukeofperl-ml1.net> wrote: > > So, in a nutshell, `:blah' is identical to `get blah'?
<<quoted lines omitted: 13>>
> >> get in system/view/screen-face 'size > == 1208x815
OK! Got it... Thanks! -- Duke

 [13/13] from: dukeofperl:ml1 at: 9-Nov-2010 21:47


On Tue, 9 Nov 2010, Ed O'Connor wrote:
> > So, in a nutshell, `:blah' is identical to `get blah'? > > --
<<quoted lines omitted: 39>>
> >> do first second :probe "hi Duke welcome to REBOL" > hi Duke welcome to REBOL
Thanks Ed! I'm going to have to study and digest your reply a little more. No time for it today. Much obliged. -- Duke

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