Last active
January 17, 2021 06:17
-
-
Save GiuseppeChillemi/93febe44dffd5dfae764b3cd6ad86988 to your computer and use it in GitHub Desktop.
Show how relative paths works on containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Name: "Power Selector" | |
Purpose: "Demostrate the working scenario of relative paths" | |
Notes: { | |
Idea: Giuseppe Chillemi | |
Path operator: Toomas Vooglaid | |
} | |
] | |
;---- Create the new "///" operator | |
path: function [a b][to path! append to block! a to block! b] | |
///: make op! :path | |
;------------ | |
;The list of relative accessors | |
mystruct: [ | |
name: heading/name | |
size: heading/size | |
body: body | |
extra: extra | |
authors: extra/authors | |
] | |
;Now we create 2 contaniers having the same structure | |
; the second one is the previous version of the first one | |
software-list: [ | |
[ | |
heading [name "Red" size 1200] | |
body ["The new merging Full-stack language"] | |
extra [ | |
authors [ | |
"Nenad Rakočević" | |
"Quingtian" | |
"Greg Irvin" | |
"Valdimir Valiliev" | |
"Boleslav Březovský" | |
"Hiiamboris" | |
] | |
] | |
] | |
[ | |
heading [name "Rebol" size 900] | |
body ["The Ancestor of our language"] | |
extra [ | |
authors [ | |
"Carl Sassenrath" | |
] | |
] | |
] | |
[ | |
heading [name "REN-C" size 650] | |
body ["Experimental Rebol derived language" ] | |
extra [ | |
authors [ | |
"Hostile Fork" | |
] | |
] | |
] | |
] | |
software-list-Previous: [ | |
[ | |
heading [name "Red" size 1200] | |
body ["The new merging Full-stack language"] | |
extra [ | |
Authors [ | |
"Nenad Irvin" | |
] | |
] | |
] | |
] | |
; Here we print some elements of the strcuture of the following containers. | |
containers-to-print: [software-list software-list-Previous] | |
;The code loops the containers | |
foreach series containers-to-print [ | |
print ["------- Container name: -------" series] | |
;All the records | |
repeat idx length? get series [ | |
Print [ | |
"Software name:" get series /// idx /// mystruct/name lf | |
"Size is:" get series /// idx /// mystruct/size | |
] | |
;And sub records | |
auth-temp: get series /// idx /// mystruct/authors | |
forall auth-temp [ | |
print [" Author:" first auth-temp] | |
] | |
Print lf | |
] | |
Print lf | |
] | |
;--- Output: ------ | |
comment { | |
------- Container name: ------- software-list | |
Software name: Red | |
Size is: 1200 | |
Author: Nenad Rakočević | |
Author: Quingtian | |
Author: Greg Irvin | |
Author: Valdimir Valiliev | |
Author: Boleslav Březovský | |
Author: Hiiamboris | |
Software name: Rebol | |
Size is: 900 | |
Author: Carl Sassenrath | |
Software name: REN-C | |
Size is: 650 | |
Author: Hostile Fork | |
------- Container name: ------- software-list-Previous | |
Software name: Red | |
Size is: 1200 | |
Author: Nenad Irvin | |
} | |
It's huge, about 21.200 times. Which block is being bound so often to generate such memory consumption?
:)
Oldes' resolve
can be restructured in a somewhat similar way to get-path
:
resolve2: func [block [block!] path [block! path!]][
forall path [
block: either any-block? path/1 [
resolve2 block path/1
][
block/(path/1)
]
]
]
And main procedure reformulated as
Oldes2: does [
foreach series containers-to-print [
repeat idx length? series: get series [
;print [
"Software name:" resolve2 series/:idx mystruct/name
;] print [
"Size is:" resolve2 series/:idx mystruct/size
;]
auth-temp: resolve2 series/:idx mystruct/authors
forall auth-temp [
;print [
" Author:" first auth-temp
;]
]
]
]
]
with similar results:
>> profile/show/count [[Oldes2][Toomas4]] 1000
Count: 1000
Time | Time (Per) | Memory | Code
0:00:00.021 | 0:00:00 | 284 | [Toomas4]
0:00:00.038 | 0:00:00 | 596 | [Oldes2]
Ah, sorry, resolve2 doesn't work this way.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The memory pressure reduction comes from not binding the block to the context every time.