Script Library: 1238 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

Archive version of: rebol-dom.r ... version: 75 ... inetw3dm 21-Oct-2021

Amendment note: Fixed: *get() will be selections of [any [attempt]] or combo of some[] and return. || Publicly available? Yes

    	File: %rebol-dom.r
    	Date: 05-01-2021
    	Title: "Dialect Object Model"
        author: daniel murrill
        version: 1.0     
    	Purpose: {
             Use a exstensible Rebol Markup function to parse DSL's that will return an
             easy to follow tagged key value Dialect Object Model  that allow different DSL's,
             programming languages to work with or together through a Central Processing
             interpreter. Yes Rebol/Core. A demo example of a HTML DSL is parsed by
             the Dialect Object Model to return valid HTML then processed by the %Mdlparser
             wich in return creates UI VID code. All scripting takes place in the DOM and then
             passed as VID code to Rebol/View. So instead of writing parse rules for DSL's, you
             work with your DSL as a DOM and immediatley began to write code for it as if it's a 
             programming language.}

library: [
        author: daniel murrill
    	level: 'intermediate
        platform: 'all
        type: [Dialects Markup]
        domain: [html vid css json js array]
        tested-under: 'windows
        support: none
        license: none
        see-also: %Mdlparser.r
        version: 1.0

my-dialect: [
rebol-DOM: [{DSL-type="html/block" type="text/html"}]

lua-tbl = {[first] = "fred", [last] = "cougar"} 
#this-issue [{color: "purple" bgcolor: "orange"}]

var anObj = {`100: 'a', `2: 'b', `7: 'c', };

body: [{background-color="blue" text "white"} ]

p: [
    {"color":"#0000ff", "bgcolor":"yellow", "width" : "399", "height" : "100" "font-styles": "big" } 
 This is an example of an Dialect Oject Model
b: [
    {id="my-p1" color = "Chocolate" bgcolor = "yellow"} 
 that can be written to look like json' html' javascript arrays' css'  
i: [
    {color = "green"} 
 VID' or plain old rebol ] 
 if you like.

hr: [{color="red" bgcolor="yellow"}]

div: [
    {width="399" bgcolor="orange"}  
b: [
    {color: "purple" bgcolor: "orange"} 
 Maybe it would be easier to write  
i: [
    {id="my-p1" color: "green"}
 MakeDoc.r code but the purpose of this rebol DOM is']  

p: [
    {width "399" height= 200 
    style="color: red;  bgcolor: brown; border: 2x2;" 
b: [     
 to read or load as many well known dialects of coding styles as possible
 and write all of it as a single or seperate legible rebol series that's
 quickly manipulated' transcoded as html' and viewed as a VID. ]


document.: func [request-as][
        DOM: head DOM use*=*to-set-values 
        any [ 
        all [not empty? data-node equal? block! type? data-node] insert data-node: [] 
        any [attempt [strip-obj-chars-from request-as] request-as]]
        any [equal? tag! type? node-element: data-node/1
        attempt [node-element: build-tag to-block data-node/1]]
        var .style: = node-element style: *![.style]
                return node-element
.return-tag-node: does [=: :equal? 
        node: either any [attempt [empty? node-name] equal? word! type? node-name]
        [either any [attempt [empty? node-element] none = node-element]
        any [
        equal? tag! type? node-element: node
        attempt [node-element: data-node: build-tag 
        to-block strip-obj-chars-from replace/all to-string node "," " "]
        set 'node-element node]  return node-element
.style: []
equal?: :=
DOM: DSL: html: window: end-tag: ""
data-node: parent-node: node: none

.body: .hr: .p: .b: .i: .tr: .ul: .li: .area: .table: .td: .button: .input: .div: .font: .span: 0
node-obj: node-element: node-name: *name: use-methods: attr-name: attr-value: none

check: func [select-this][return first parse trim strip-chars-from form select-this none " "]

strip-chars-from: func [node-name elemt-chars][
	foreach char elemt-chars: any [elemt-chars 
        ["<" ">" "{" "}" "(" ")" {"} "/" "." "[" "]" "," ":" ";" "," "="] 
        replace/all node-name char " "

strip-obj-chars-from: func [node-name][
        trim node-name if equal? #"^"" node-name/1 [remove node-name]
        foreach [-char +char] obj-chars: [#"^/" " " "  " " " {" , "} {" } {", "} {" } 
        "," " " {" "} {" } {" : "} {: "} {":"} {: "} {":} {:} { " } "" {"[["} {"[[" "}
        "{" "[" "}" "]" {""} {"} {  "} "" ":" " " { =} {=} {=} " " "'" ""
        replace/all node-name -char +char

getnodename: func [node-name][data-node: []
        DOM: head DOM =: :equal?
        either block! = type? node-name [.return-tag-node][
        node-name: to block! strip-chars-from form node-name none
        count: any [attempt [count: pick find node-name integer! 1]1]
        nodename: to-word join  "." array-obj!: node-name/1 
        any [attempt [repeat ? count [data-node: first DOM: next node: find DOM nodename]]
        print reduce ["node-name:" mold form node-name/1 "not found"]
        slf*: join node-name/1 count
        if " " = data-node [data-node: form first DOM: next DOM]
        return either tag! = type? data-node/1 [node-element: data-node/1][node-element: data-node] 

setnodename: func [old-name new-name][
        any [equal? this-name: check old-name check node-element getnodename old-name]
        any [equal? none not find node-element new-name try [
        replace node-element to string! this-name new-name 
        replace data-node to-tag join "/" this-name  to-tag join "/" new-name] 
getattribute: func [attr-name][
            attr-value: none
            do compose/deep [attr-value: array-obj![(attr-name)]]
            print any [[attr-name attr-value] ["node-attribute:" mold form attr-name "not found"]

setattribute: func [attr-name new-attr][
            *key: *value: none var  node-element *![.style]
            do compose/deep [.style[(attr-name )]]
            any [
            if *value [replace node-element attr-name new-attr]
            array-obj![repend [" " new-attr {="undefined"}]""]
            print ["Must get a parent-node with this attribute: " attr-name]]
            ;get-attributes node-element attempt [set-attributes]

setattributevalue: func [attr-name attr-value][
            var  node-element *![.style]
            any [
            if find node-element key: form attr-name [
            do compose/deep [.style[(key)] `= (attr-value)]]    
            array-obj![repend [" " attr-name {="}attr-value {"}]""]
            print ["Must get a parent-node with this attribute: " attr-name]
            ] ;get-attributes node-element attempt [set-attributes]

getElementByTagName: func [Tag-Name selection [block!]][
            dom: head dom 
            repeat this first selection [
            node-element: first data-node: first dom: next find dom to-word join "." Tag-Name]
            if all [equal? true use-methods not find node-element " ."][use-attr-as-methods yes]
            use-methods: off        

look-deep-for: func [this in-node][
            foreach in-child-node in-node [
            if all [tag! = type? child: in-child-node find/any child this][print node-element: child] 
            if block! = type? in-child-node [look-deep-for this in-child-node]
getElementById: func [my-id][in-child-node: none 
            id: copy join "id*" form my-id =: :equal?
            foreach in-parent-node dom [
            if block! = type? in-parent-node [look-deep-for id in-parent-node

querySelecter: func [css-Selecter][in-child-node: none 
            id: rejoin [css-Selecter "*"] =: :equal?
            foreach in-parent-node dom [
            if block! = type? in-parent-node [look-deep-for id in-parent-node

.innerHTML: func [element][
            children: copy/part next data-node find/last data-node tag!
            either equal? tag! type? node-element [
            any [empty? element replace data-node children element]
            ][print "The node-element has no innerHTML"]
use*=*to-set-values: does [=: func [value][any [value]]]

use-attr-as-methods: func [maybe [logic!]][
            if false != maybe [foreach [-char +char][{" } {" .} ".." "."][replace/all node-element -char +char]
            replace node-element " " " ."
            use-methods: no

node-list: []

*!: func [var][=: :equal? set to-set-word node-name set to-set-word form var :array-obj!]

proto-type: func [var-data new-var][ 
	    var replace node-element: copy var-data 
	    form variable form new-var

var: func [var-data][node-element:  variable: "" 
            any [
            attempt [variable: first parse node-element: var-data "=:, "]
            attempt [if equal? block! type? var-data [variable: first node-element: var-data]] 
            attempt [variable: var-data node-element: ""]
            use*=*to-set-values node-name: variable: to-string variable
            either empty? node-element [any [find node-list variable append node-list reduce 
            [variable node-element: any [attempt [do :variable] " "]]]] 
            [append node-list reduce [form variable node-element]] 
            set to-word variable array-obj!: func [key] node: compose/deep copy get-array-obj!
            attempt [if not find variable "." [do load to-string reduce ["set " #"'" variable ". :array-obj!"]]]
            use-methods: off ()

return.: func [value][
              any [
              attempt [*value: to-block value  
              foreach a *value [if not equal? word! type? a [do *value: a ]]]
              attempt [*value: do form reduce load value]

.: func [value][either equal? block! type? *value [
                any [
		if equal? integer! type? *key: first to-block value [
		any [equal? 1 *key *key: *key + *key - 1]		
		attempt [do [value: select *value *key: pick *value *key *value: to-block value]]]
		attempt [*value: first next *value: find *value value]
		*value: load value]  
                ][ do compose/deep reduce [*value [(load value)]]]

some: func [next-key][
	        foreach try-this next-key [
		| try-this  
		either all [find node-element *key: form try-this function! != type? *key]
		[ print ["*key: " *key " *value: " *value: *value ]]
		[*get try-this] key: any [*key try-this] ()

get-array-obj!: [
            if not equal? tag! type? node-element [node-element: select node-list  
            (form variable) ]
            |: :array-obj! 
	    all [inline: find/any node-element { style*=*"} 
            replace node-element inline
            replace/all replace replace inline {"} "{" {"} "}" "  " ": "]
            any [1 <> length? parse form node-element ":= ," insert node-element [#1:]] 
            any [
            if empty? form key [ 
            return any [
            if equal? tag! type? node-element [node-element]
            node-element: head node-element]*key: key: *value: value: none
            if all [*key: first to-block key not find node-element rejoin [" " *key " "] 
            equal? integer! type? *key][
            values: any [attempt [parse head node-element "<=;,`#: []>"] 
	    parse mold head node-element "<=;,`#: []>"] keys: length? replace/all values [""][]
            if odd? length? values [remove values]
	    any [equal? 1 *key *key: *key + *key - 1]		
	    *value: any [*value: select values *key: pick values *key *value ]
            node-name: keys: value: none  *key: *value: none
            if equal? path! type? key[]
            if equal? refinement! type? key[attempt [do replace/all form key "." "/."]]
            if find ["url!" "email!" "tag!" "refinement!"] mold type? key [ 
            attempt [key: to-string parse/all replace/all to-string  key "." "/." "/"] 
            foreach [-char +char][":" ":." "@" ":" ".." "."][replace/all key -char +char]
            replace/all from-method: parse key ".:" ":" [] 
            attempt [*value: load first next find parse mold node-element "<{}=`;,#. []>" from-method/1]
            foreach value next from-method [any [array-obj! value . to-block value]]
            any [
            attempt [*value: load select/case parse strip-obj-chars-from load mold node-element "<{} =`,#>" 
            *key: trim head trim tail form key]
            attempt [*value: select/case load strip-obj-chars-from mold to-block node-element key]]
            any [
            attempt [do head append insert next copy key [node-element join] ""] 
            attempt [if equal? string! type? key [do head replace copy key " " { node-element }]]]
            attempt [do load key] 
            if not find node-element key [*key: *value: none]] ;[print [*key "called"]]

`=: func[attr-value][
            any [
            attempt [replace node-element *value *value: do load form attr-value]
            replace node-element form *value form *value: attr-value
            replace node-element mold form *value mold *value: attr-value
            attempt [*value: select node-element *key: load key] 
            ] node-element: head node-element

node-element: *node-name: *name: array-obj!: key: *key: *value: ""

markup-DOM: func [DSL][
use-methods: string-is-data: no =: :equal?
        either block! = this-type?: type? DSL [
            DOM: copy/deep DSL: load replace/all replace/all mold DSL "__" " " {=""} {="undefined"}
            any [
            find DSL [rebol-DOM: [{DSL-type="html/block" type="text/html"}]]
            insert DSL [rebol-DOM: [{DSL-type="html/block" type="text/html"}]]]
get-data: func [data][  
        find-end-tag: find data get-word!
            either find-end-tag [
            replace data first find-end-tag  to-tag mold to-refinement first find-end-tag
            insert tail data to-tag join "/" any [*name *node-name]
repeat in-data data [
        if set-word! = type? in-data [*node-name: copy form in-data
            replace data in-data node-name: to-word join "." *node-name
        if string! = type? in-data [
            strip-obj-chars-from in-data 
            insert in-data next reform [node-name " "]
            child: build-tag to-block in-data 
            foreach [a b][{=" } "={" {" "} "*}" "*" {"}][replace/all child a b]
            replace data in-data child
        if block! = type? in-data [
            get-next in-data

get-next: func [in-data][
    repeat data in-data [
        if set-word! = type? data [*name: copy form data
            replace in-data data node-name: to-word join "." *name
        if string! = type? data [
            strip-obj-chars-from data  
            insert data next reform [node-name " "]
            child: build-tag to-block data 
            foreach [a b][{=" } "={" {" "} "*}" "*" {"}][replace/all child a b]
            replace in-data data child
        if block! = type? data [get-data data
            set to-word *node-name data]
        ] find-end-tag: find in-data get-word!
            either find-end-tag[
            replace in-data first find-end-tag  to-tag mold to-refinement first find-end-tag
            insert tail in-data to-tag join "/" any [*node-name *name]
            clear *node-name]

repeat with-this-data DSL [
        if issue! = type? with-this-data [
            node-name: to-word join "." *name: copy form with-this-data
        if set-word! = type? with-this-data [
            replace DSL with-this-data node-name: to-word join "." *name: copy form with-this-data
        if word! = type? with-this-data [
            either '= = with-this-data [string-is-data: yes replace DSL with-this-data ""
            *name: copy form with-this-data
            replace DSL with-this-data node-name: to-word join "." with-this-data] 
            replace DSL reduce [node-name node-name] node-name
        if string! = type? with-this-data [
            either string-is-data [
            replace DSL with-this-data rejoin [node-name " " with-this-data]
            created-data: copy with-this-data
            strip-obj-chars-from created-data  
            insert created-data reduce [node-name " "]
            child: build-tag to-block remove created-data 
            foreach [a b][{=" } "={" {" "} "*}" "*" {"}][replace/all child a b]
            replace DSL with-this-data child
            string-is-data: no
        if block! = type? with-this-data [ 
            get-data with-this-data
        if get-word! = type? with-this-data [
            replace DSL with-this-data to-tag mold to-refinement *name
            replace/all dsl "" [] DOM: copy DSL
            view center-face layout [
            backcolor black space 8
            h3 yellow "Need a Dialect Object Model as type! block"
            text gray "Your DSL type is: " text red bold form :this-type? 
            text gray "Some DOM functions will not work properly"]

format-this: func [node-element with-these-chars][
            foreach [-char +char] with-these-chars [
            replace/all node-element -char +char] 
            do last with-these-chars

as-js-object!: [
            { #} "" 
            {="} {: "} "={" ": {" {""} {"} {" } {", } {", "} {","}
            [if equal? tag! type? node-element [replace node-element " " ": {"] 
            replace/all node-element { "} {: "}
            replace/all node-element "::" ":"
            replace/all node-element " : " ": "
            if equal? tag! type? node-element [append node-element "}"]

clear-node-list: does [foreach [var node] node-list [set to-set-word var none]clear node-list]

.as-js-object: does [format-this node-element as-js-object!]

return-html-dsl: does [
        html: copy form any [find head DOM "<body" head DOM]    
        replace/all replace/all html "<." "<" "' " ", "
        replace/all replace/all html "{" "<" "}" ">" 
        foreach n-name [
                        ".body " ".hr " ".p " ".b " ".i " ".? " 
                        ".tr " ".table " ".td " ".button " ".input "
                        ".div " ".ul " ".li " ".font " ".span "
                        ".img " ".a " ".strong " " ." ".hr " "lua-tbl "
                        ][replace/all html n-name " "
        append replace/all html </body> "" </body>
        html: any [find html "<body" html]

markup-DOM my-dialect

getElementById 'my-p1
querySelecter 'border

document. getnodename {"div"[1]}getattribute "bgcolor"  
document. getnodename{("p")[2]} .style[width] `= "block-build"

setattributevalue('height) "1000"

    getattribute "height"

setnodename {hr[1]} "listview"

document. getnodename{("p")[1]}.style[font-styles] `= "block-build"



data-node: do to-path [DOM .p .b] 

document.(data-node).style[color] `= "bluberry" 

    setattribute('i-style) "silly" 

; Some examples of selecting keys and values set to variables as an array object.
; good to use with anything that's structured with {} , or "". It also can be used with [].
;IE (javascript, json objects/arrays.. lua table/arrays.. associative arrays etc.) 
;even DOM's and rebol data.

;The insert, remove, append, and lookup of a group (a node-element) by way of a Var (variable)
;is done as a data-node and syntactically as an associative array. The associattion of key 
;values is done by index in Rebol therefore there is no need for the overhead of objects or 
;multi.dim arrays. But the cool part is you can do what ever you like!

;You must use use*=*to-set-values before setting the first variable.
;it will use = to set any value to a variable (a set-word) 
;`= this literal equal is used to set values to keys. Feel free to use
;different function symbols for any !op function.  


;variables and there values (node-elements) that are'nt tags are sent and fetched from a
;node-list block for demo purposes. They will be appended to the DOM later.

;The variable name and the first word in it's value must be the same in order for
;the variable to be automatically bound to the node-element and array-obj!() function.

var hello: = {hello 100: "a" 2: "two words" 7="c"}


hello[2] `= "a to z"


;if you use *use-methods: yes, use paths or refinements, /style.bgcolor 
;to get the value.

;use-methods: yes  

app: = document.(getElementByTagName('p)[2]).style[bgcolor]`="green"
  p .innerHTML("Lets change this, shall we.")


;You must call/associate the array-obj! with this variable name
;because the variable name "app" and the node-name/TagName "p"
;are not the same.

;Don't call/associate and just use the set node-name/TagName "p"




;or app: :array-obj!

;the style.obj! is auto created by using the document. function


;is the same as calling, but without the cell(block) this time. 

app "bgcolor"

;Write values however. they are handled by the get-array-obj! as any-type.


app[width] `= "curly quew"

app("bgcolor") `= to-string [purple]

;when you need to create a variable to use with an array-obj!

poppy: {poppy: 100: "a" street : "backside" 7="c"}

var 'poppy ;local or global hoisting.

var join {poppy2: } {200:"a" street : "backside" 7="c"}

poppy[street]`="old rover rd."

poppy["7"] `= "cities"

;You do not need a variable word. If you apply Var to your 
;value, the variable will always be the first word found in 
;the value (node-element) followed by ": =", " =", ": ", or " " 
;you can allso access it with array-obj![]. 

var {
    1: a
    2: b
    3: c


var <new-var: 1: a 2: b 3: c> ;tags are allways node-elements. 


;VAR values can also be set to an arrayed object.

var poppy3: = [poppy3 #100:"a" #3:"c" street: "backside"]

;Even though it's not the best idea to use integers as keys, you can.
;it can encourage mistakes when trying to get by index...  poppy2[3]
;But this is Rebol, so we will roll with this...
;You must always start block cell number keys with the pound sign. "#"
;if it's written as a get-word! ie, 7: "some-value", if not it will error
;It reminds you there's an issue with that key. becarfull

poppy3[street]`= "old rover rd."

poppy3[3]`= "cities"

;First it looks for any 3rd index key/value but then it
;returns any get-word! #issue keys' *value if it exists.



;WHY do this then? you can set your own index numbers, starting 
;at 0 or 1, in or out of order, as lua does with its table structure
;where some can be numbered keys mixed with normal keys/values.

;DOM variables are renamed to start with a dot "." so not to be confused with words.
;this may not change in the future. For now only DOM/parent-nodes can be type! word.
;Only Var type! set-word!'s can not be nested.

;Remember when calling a node-name or a tag! type node-element,
;and using that name as the variable,

var .anObj: = getnodename "anobj"

;you dont have to call/associate the array-obj! with this variable name
;but the variable name must began with a dot. IE "."


;but with 

var anObj: = getnodename "anobj".return-tag-node 

;you do

*![anObj]  ;or anObj: :array-obj!

;quick short parsing example of the node-element sequence.
;it,s not just top down, it's start and stop anywhere, with any
;repeat and backtracking, moving into or out of Vars and prototypes,
;code, and data by reference, linked or not.

*get: func[this][attempt [do this]]

this: [if *value [print .{"I got the value " *value}]]
in-node-element?: [any [all [find node-element key print .{key " In node-element"}]
									  print .{key " not In node-element"}]]

.anobj[] some [
		 "flys" in-node-element? 
		 "100" in-node-element? 
		 "7" in-node-element?
		 "people" in-node-element?

;after calling some variable[key]/array-obj![key], you can replace the key and value.

replace replace node-element *key 'this-key *value {some-value}

;Lets create a Var string node with one element

var {
     width: 50px


;lets use this string node as prototype Object. this code is proof of concept.
new: :copy
;var new try-that[] *![try-this] 

proto-type try-that[] 'try-this 

;lets give it a new key element.

setattribute try-this[key][size]


;give that key a value

try-this[size]`= #200px

;While the string node-element *try-that[] did'nt change


try-this[.innerHTML("change me please") ","]

head try-this[]

;a roadmap for javascripting with the Dialect Object Model (DOM).

;A quick way to change op! functions between rebol and javascript.

js-op!: does [x: :* *: :do console.log: :print var 'use js-do: :js-op!] 
reb-op!: does [*: :x =: :equal? reb-do: :reb-op!]

;This code...

function welcomeSite() {
   siteMessage = "Welcome to the...";
   Message-type: "Welcome"
   var siteMessage;

siteMessage.append("Rebolution") siteMessage

;Is changed to this code...


function: func [fn params this-data][var rejoin [fn " " this-data]]

function 'welcomeSite("") {
     siteMessage: = "Welcome to the... ";
     Message-type: "Welcome"
     do reb-op! alert(siteMessage)
     var 'siteMessage;

;Hey you can load welcomeSite from a DOM or files with variables, functions, key-values or Rebol code:

use welcomeSite([return.]);

;to use the welcomeSite Message-type in your code.

    var say-hi-to: = Message-type
    console.log(["This is a message to" say-hi-to "you."]);
siteMessage.[append("Rebolution.")] siteMessage.[print]

var first-obj: = {first-obj: first-name: "Brigsby" last-name: "Backfort"}

var second-obj: = {second-obj: first-name: "Krystal" last-name: "Frontbunker"}

first-obj[last-name]`="FortBack"  first-obj[]

second-obj[last-name]`="Bunkerfront"  second-obj[]

Var contacts: = {Bestfriend: "[{"first": "Besty", "last": "Bestest", "number": 777-9211}]"}

;Does Var persist if not destroyed? YES.

;and then back to Rebol

reb-do 2 * 2

;Create a DOM from a nested javascript object DSL, search and update.
;A return-js-object-dsl() function will return the new js-object.
;Mold blocks and load strings to do quick formating like remove all ",".
markup-DOM load strip-chars-from {data: [
    fullName: {fullName: "James Zhan"},
    address: {
        city: "Shenzhen",
        state: {
            name: "Guangdone",
            abbr: "CN""
        country: {
                       local-name,Guangdone,abbr,CNN,id,jazzy},   ;CSV example.
    hobbies: ["coding", "reading"],
    projects: [
        { name: "form2json", language: "javascript", popular: true },
        { name: "peony", language: "ruby" }
} ","


var here: dom/.data/.projects/1



format-this node-element as-js-object!

;using paths to get node-elements

var address: dom/.data/.address 

;using nested indexing by keys to get/set node-element values

address[state].[country].[abbr] `="pop"

clear node-list


;And a cool but very simple trick in Rebol. For non-rebolers
;this IS code and data mixed together. First it's ALL string data.

var num: {num: a: 1 b: 2 c: 3}
;Rember, the *num value is a string, not an object.
amount: num[a]`= [amount '+ 15]
;And the new *formed() value is a [string: "1" word: '+ integer: 15]

;The DO() function binds each piece to the interpreter global symbols/funcs, and voila!


;And now Var methods with linked node-element lists, a mixture of object and arrays
;in a simple DSL keeping track of data updates with set limits. Don't try to undestand
;it, it's silly. 

;methods are written as messages sending or recieving. So lets use a form of
;urls and emails.
get-numbers.has-a@variable-a ;or
get-numbers:has-a.variable-a ; cause theres a set-word in there.

;all methods must either have a set-word or "@" appended
;to the tail to be valid  Var methods.

;if the word to start the method is a set-word *get-numbers: 
;the words to continue the method can each have "@" appended to them.


;they will be looked up as Var words or set-words or else there
;is no vectoring/linking. Yes if it's a string word it will be given local context.
;The string word will be matched as a pointer to it's literal word 
;to return the correct Var or local value.

clear node-list

var check-if: = [
                check-if start: 'at-head 
                stop: 'at-tail 
                get-numbers: numbers  ;this is linked to local Var numbers

var numbers: {
        start-at: 1 
        has-a: limit  ;this is linked to local Var limit
               me: [a: "b" c: {d: "go-it"}] ;nest array objects with "{}" or "[]".  


var limit: = {
        variable-a: "yes" 
        info: "I am a returned method" ;using ancester Var to get info:
            variable-b: [function!(js-op!){console.log[(variable-a"info")]reb-op!}]
        } *![limit]

amount: numbers{start-at} `= {amount + 15}

;don't create a vaviable (*amount) to GC.


numbers{start-at} `= {*value + 15}

increased: "start-at"

;Returning a linked var's value with *do instead of (chaining) using .[] or .{}

do check-if 'get-numbers increased ;use ":" , "@" or "/" with key/values as metods.
do check-if [get-numbers](increased)
do check-if ('get-numbers){increased}

question?: :? ?: :if then: :.

check-if 'get-numbers all [ 
?(.[increased]) then {
		`= money: $50.00 
		print .{"....... Yep it" *key "up to" *value} 
		print ."'I *value {, that cash you owed me. the} money"
?: :question?	

;Using .[] or .{} to load the last known variable and retun its node-element

check-if(get-numbers.has-a.variable-a@)do .{
                                    ; this set attribute and value is appended to the last evaluated Var, Limit[].
                                    setattributevalue "last-variable" "value-off"

/*place *fetch, "@" before or after any key. use it in place of the set/get-word #":"

check-if get-numbers.has-a.variable-a@
;And now get-numbers: , has-a, and variable-a becomes Var's once linked to
;only if they have following data. Now we can use them with method calls in the
;*key *value's data.


;Let's send get-numbers:has-a.variable-a data, wich is "yes" to /**/

daniel: "get-numbers@" 
mindsping: "has-a" 
.com: ".variable-a"

send /* check-if*/

;the node-element is now *limit[]

=: :equal?

if (numbers has-a.variable-b@) .{
                print "this worked"
if!: :either then: else: :. ;or just use either

if! 16 = numbers<start-at> .{
    print "yessers"
       } else {  
        print "nossers"

setattributevalue 'reset 'check-if


;This is a quick get by index example
;on strings, using parse and select
;The same string value, ie. node-element
;key can be selected by *key or index now. 




;get nested elements *values by index numbers.

numbers[me].[2].[1] ;same as [me][c][d]

;You can use any ancestor Var, (ie. variable-a) 
;in a Var method (ie. variable-b) to return a *value.

return.(limit 'variable-b) ;or
return.(limit{variable-b}) ;or
return. limit[variable-b] ;or
return. limit"variable-b"


var age: "$user.age" ;single element values are given an index as [#1:].



reb-do 2 * 2

;Ason script DOM example...

probe markup-DOM  [user-database: [

    name: {name1:"John Smith"} ;values with spaces must be wrapped with name space.
    age:  22
    born: 1998-8-15
    usage: #8:22:45
    email: %jsmith--altscript--com
    version: 3.2.14
    passhash: #A94A8FE5CCB19BA6
    colors: [ 255.100.50 50.50.80 ]
    allow: [ login admin upload edit ]
    check: [ if age > 60 [ add-to people.seniors ]]
    ;/*... more users ...*/
var dom/.user-database/.name ;get that name!

name[]  ;use "name.", "name" or array-obj!
name "" 
name 1
name [name1]
name {name1}
name ("name1")
name </name.name1>
name /
array-obj![] ;use ".", array-obj!, name., or "name"
array-obj! /name.name1
array-obj! name:name1
array-obj! name.name1@

;Very quick, easy, short demo, scripting DOM node-elements
;with an easy syntax style.

var {x: 1: 10 2: 20} ;[] can be used in place of {}, "", <>, or these inside of ().

x.{find "10"} 
x.{replace "10" "30"}

var y: = "20" *![y]

var {sum = x[1] '+ y[1]}
*get: func[this][ any [attempt [do reduce skip load this 2] ]] 

*get sum[]

;Control duplicate key injection attacks due to
;different json/map encoding preferences for
;selecting first key but duplicate key is returned
;through decoding and shares an illegal value.


var [x: #1: 10 #1: 50 #2: 20]                                         ; key: #1 is duplicated. wich one do we trust?

if all [
	key1: x.{find [#1: 10]}                                           ;key1 is the right key but wrong value. look again.
	key2: x.{find [#1: 50]}] then { 
	x. #1 `= 30
	print add x #1 pick maximum key1 key2 2


;Or use sequences as array,object, and blocks.

var {x: #1: 10 #1: 50 #2: 20}

of: create_key_*value: :.

if found? all of {
			key1: x.{find/any {#1:*#1*}} 
			key2: x.{find {#1: 50}}
			} create_key_*value   { 
			x.[1]`= 30
			print add *value pick load maximum key1 key2 2

;A method is just putting the name of a Var in another Var as a key's value.
;None of the Vars need to share data structures, but can be linked, or put in a
;Var as *values with your *key variable names. Although it's a linked list all
;data structures are traversed and accessed individually. Thank you Rebol.
;You don't need objects, parsers, classes, or tricked out functions to use your
;DSL's. To start you just look up or set everything by key value pairs.
;methods are just a quicker way to get to local associated data.