But you add readability and flexibility. And the purpose of a language like RED is to be flexyble and readable.
I don't think that when function can take different number of arguments then it will add to it's readability.
my-weird-func is a function that could take different number of arguments:
my-weird-func 1 2 my-weird-func 1 2 3 4
are simple enough but what about this:
my-weird-func tux baz qux bar
my-weird-func tux baz qux bar or
my-weird-func tux (baz qux bar) (qux is an
my-weird-func (tux baz) (qux bar).
As you can see it's not readable.
vid managed to make it nice. It's based manly on types and "tags" so when you see, for example, a
pair! you know that's face's size.
change 'block start-point values change 'samplerate from-value to-value 'recode
To me they seem very simple and coherent
Because they are small and isolated examples.
add 'row [values] add 'field f: at field-names 4 f/field-type
Here I would assume that
add takes 2 arguments. In the second example you are just returning (
f/field-type). I wouldn't guessed that it was a 3rd argument to the
func [a /ref b][...]) as something different, depending on existence of a refinement (e.g.
func [a /ref b] [either ref [return a * b] [return append a "!!!!!!!!"]. It might not be "nice".
text1: "foo" color: red view compose [ base (color) (text1) base (color) ] ; some code
>> db-dialect: func [ ]]]] == func [ ][ ]]]] >> db-dialect [ [ add db table [ add table name [ add row [values] [ add field fieldname fieldtype [ ] == true
Red  ;@GiuseppeChillemi [February 26, 2019 11:51 PM](https://gitter.im/red/help?at=5c75b4d7d2d62067b7101b03) assign: func [words values][collect [forall words [keep to-set-word words/1 keep values/(index? words)]]] dbs: clear  selection: clear  dbquery: func [code /local s i j][ parse code [ some [ 'add [s: ;(probe s) 'db (repend dbs [db-name: s/2 db: copy ]) | 'table ( repend db [ tbl-name: s/2 table: copy/deep [spec:  rows: ] ] ) | 'fields (append spec: second table s/2) | 'rows ( append rows: fourth table s/2 new-line/all table/rows on ) ] skip | 'use [s: (spec: none) 'db (db: select dbs s/2) | 'table (table: select db s/2) | 'spec (spec: table/spec) | 'row (row: pick table/rows s/2) ] skip | 'select [s: (selection: clear  fields: extract table/spec 2) 'row integer! (append/only selection row: pick table/rows s/2) | 'rows [ 'where block! ( foreach row table/rows [ if all bind s/3 context assign fields row [ append/only selection row ] ] ) | block! ( parse s/2 [any [i: integer! '- integer! ( repeat j length? table/rows [ if all [j >= i/1 j <= i/3][ append/only selection table/rows/:j ] ] ) | integer! '- 'end ( repeat j length? table/rows [ if j >= i/1 [ append/only selection table/rows/:j ] ] ) | integer! (append/only selection table/rows/(i/1)) ]] ) ] ] ] ] ] code: [ add db redverse add table persons add fields [ alias [email!] fname [string!] lname [string!] ] add rows [ [@GiuseppeChillemi "Giuseppe" "Chillemi"] [@rebolek "Boleslav" "Březovský"] [@nedzadarek "Nedza" "Darek"] [@toomasv "Toomas" "Vooglaid"] ] ] dbquery code dbquery [use table persons] dbquery [select row 1] selection ;== [ ; [@GiuseppeChillemi "Giuseppe" "Chillemi"] ;] dbquery [select rows [2 4]] selection ;== [ ; [@rebolek "Boleslav" "Březovský"] ; [@toomasv "Toomas" "Vooglaid"] ;] dbquery [add rows [[@greggirwin "Gregg" "Irwin"][@gtewalt "Greg" "Tewalt"]]] dbquery [select rows where [find/match fname "G"]] selection ;== [ ; [@GiuseppeChillemi "Giuseppe" "Chillemi"] ; [@greggirwin "Gregg" "Irwin"] ; [@gtewalt "Greg" "Tewalt"] ;]
First evening with the RED girl: I am dissecting the RED girl to understand how she works.
assign: func [ ]]]
Lets probe the result of
words: [first-word second-word] values: [1 2] probe collect [forall words [keep to-set-word words/1 keep values/(index? words)]] >> red-lady.red [first-word: 1 second-word: 2]
assign seems a function whose body is built at runtime. It seems it creates global values but I could be wrong. Also I think what will happen once it is run for the first time, will the body persit or it will be recreated at each run of
assignjust combines provided words and values into new block with words changed into set-words. This block can be further used as object spec or reduced to set values to given words. I made some changes to it so that a single value (e.g.
none) can be initially given for all words. It is currently used only in selection of rows according to provided criteria. Also added some functionality. See examples in gist dbquery
Red [Needs: View] files: [%bg1.png %bg2.png %bg3.png] ; each 1920x1024 imgs:  forall files [ append imgs load files/1 ] forever [ forall imgs [ img: copy imgs/1 ; img: imgs/1 also looses memory view/no-wait [ image img ] wait 1 unview ] ] ; each loop about 8MB are lost --> eventually crashes ; Red 0.6.4 for macOS built 4-Mar-2019/8:37:14+10:00 commit #a3d9204
@GiuseppeChillemi :point_up: March 3, 2019 9:43 PM
Comment out line
until... and its closing bracket and you'll see the culprit.
loop to see how
@NjinN I eliminated all words and compacted the app more. It shows that memory leak happens in
view (as @9214 had pointed out).
Red [Needs: View] files: [[%bg1.png] [%bg2.png] [%bg3.png]] forall files [append files/1 load files/1/1] forever [ forall files [ view/no-wait compose [ image (files/1/2)] wait 1 unview ] ]
(A tiny working slideshow - except for memory leak).
img: copy imgs/1) - you are not editing them. I have done 2 & 10 loops with ~9MB files and I have gotten ~2 MB with
copy. You run it forever and with some images bigger than mine... so it may lose more memory.
view/no-wait [ image img ]might not cache results, so each time
foreverruns it might add some MB. I'm not sure if it's garbage collected. It's my wild guess so take it with a grain of salt.