Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 20 22:59
    @dockimbel banned @SmackMacDougal
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
ne1uno
@ne1uno
take at data 2 ;removes 2nd
Rebol2Red
@Rebol2Red
Well i want to remove only "b" from data but not with an index.
So i need something like ... find "b" ...
Boleslav Březovský
@rebolek
remove find data "b"
Rebol2Red
@Rebol2Red
Yep that's it. Thank you very much!
GiuseppeChillemi
@GiuseppeChillemi

IMO it adds too much unnecessary overhead.

I agree. Function wich are executed hundred of thousands of times per seconds could have a slowdown.

But you add readability and flexibility. And the purpose of a language like RED is to be flexyble and readable.
nedzadarek
@nedzadarek

@GiuseppeChillemi

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

is this my-weird-func tux baz qux bar or my-weird-func tux (baz qux bar) (qux is an op!) or 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.

GiuseppeChillemi
@GiuseppeChillemi
add 'db name 
add 'table name 
add 'row [values]
add 'field 'fieldname 'fieldtype

add 'shape 'line start end
add 'song name  interpreter
you can create small dialects using this kind of coding delegating cases to spec and body defined somewhere in a block
change 'block start-point values
change 'samplerate from-value to-value 'recode
To me they seem very simple and coherent
GiuseppeChillemi
@GiuseppeChillemi
You have only to learn the dialect...
Without having to deep learn block parsing.
It a simple way to have dialects and one you manage FUNC and SELECT you are able to use them.
GiuseppeChillemi
@GiuseppeChillemi

However, with the available istructions, the most usable and flexible way to express thing is:

add 'something [parameters]

The last istruction would be

change 'samplerate [from-value to-value 'recode]
Until adoption by the RED team of this GREAT MEGA IPER idea of simple dialecting using variable functions :-)
I'll build from this:
nedzadarek
@nedzadarek

@GiuseppeChillemi

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 add.

GiuseppeChillemi
@GiuseppeChillemi
In fact the idea is for small domains of coding where no parse block complexity is needed
nedzadarek
@nedzadarek
ps. of course you wouldn't use add and change for obvious reason. If it wouldn't destroy the red then it would confuse some people (especially change).
GiuseppeChillemi
@GiuseppeChillemi

You are right, this let me think it would be good having the ability to add variations to a function to select its specs and body in a way like:

add/rows

But we already have refinement...

add :('rows) ?

I am just letting my imagination go

nedzadarek
@nedzadarek
@GiuseppeChillemi refinements, as the name suggest are for this. Nothing stops you from using non-refinement argument (e.g. a in 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".
However, I think separate DSL is better options:
text1: "foo"
color: red

view compose [
  base (color) (text1) 
  base (color)
]
; some code
Boleslav Březovský
@rebolek

@GiuseppeChillemi

you can create small dialects

And that's exactly what you should do. Create dialects.

Here's simple validator for your example, adding actions to it is piece of cake:
>> db-dialect: func [dialect][parse dialect [some ['add ['db word! | 'table word! | 'row block! | 'field word! word!]]]]
== func [dialect][parse dialect [some ['add ['db word! | 'table word! | 'row block! | 'field word! word!]]]]
>> db-dialect [
[    add db table
[    add table name
[    add row [values]
[    add field fieldname fieldtype
[    ]
== true
It's MUCH easier than messing with self-modifying functions.
GiuseppeChillemi
@GiuseppeChillemi
@rebolek I will work on it.
Toomas Vooglaid
@toomasv
@GiuseppeChillemi @rebolek I cooked also something similar - very crude adhoc implementation of your dialect:
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"]
;]
GiuseppeChillemi
@GiuseppeChillemi
@toomasv Fantastic ! I'll spend many nights with this RED girl !
Toomas Vooglaid
@toomasv
:smile:
nedzadarek
@nedzadarek
@toomasv @rebolek Good job!
@GiuseppeChillemi ^^ In my opinion, their codes are much better than separate functions you wanted to make.
GiuseppeChillemi
@GiuseppeChillemi
@nedzadarek I also think so. The idea of having a function with multiple specs remains in my mind for further use but I will continue on parsing DSL.
nedzadarek
@nedzadarek
:+1:
GiuseppeChillemi
@GiuseppeChillemi

@toomasv

First evening with the RED girl: I am dissecting the RED girl to understand how she works.

assign: func [words values][collect [forall words [keep to-set-word words/1 keep values/(index? words)]]]

Lets probe the result of COLLECT

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 assign ?

GiuseppeChillemi
@GiuseppeChillemi
Thinking.... have to dissect the full code to have the answer
nedzadarek
@nedzadarek

@GiuseppeChillemi unless you specify /into refinement, every time you run collect it will create new block by calling make each time:

unless collected [collected: make block! 16]

(^^ from the collect source (?? collect))

GiuseppeChillemi
@GiuseppeChillemi
@nedzadarek So I read the assign: function in a different way: it returns a block of set words (and does not modify itself)
I often misread the console about the blocks returned and the code emitting it when there are one or more []
Toomas Vooglaid
@toomasv
@GiuseppeChillemi assign just 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
nedzadarek
@nedzadarek

@GiuseppeChillemi I sometimes check it by appending something to a block:

f: func [/local arr] [arr: [] ]
bl: f ; == []
append bl 1 ; == [1]
f ; == [1]

It won't cover most cases but I think it's a good start.

Alan
@virtualAlan
I've updated a few things: mycode4fun.co.uk/red-beginners-reference-guide - and also: http://www.mycode4fun.co.uk/red-apps - take a look - Regards, Alan.
ralfwenske
@ralfwenske
I’m having so much fun playing with red again and having seen so much progress.
I am attempting to write a tiny slide show for a shop window display. It is working well so far. However after displaying images for a while it crashes due to memory loss.
I believe garbage collector is not yet complete - is memory loss in following app to be expected?
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
NjinN
@NjinN
@ralfwenske I found that problem too. It seems can't use view/no-wait and waitat the same time. Maybe we should use the rate and on-time in view.
Vladimir Vasilyev
@9214
@ralfwenske bitmap objects allocated for image! values are not freed by GC (yet), so memory leak is expected.
Toomas Vooglaid
@toomasv

@GiuseppeChillemi :point_up: March 3, 2019 9:43 PM
Comment out line until... and its closing bracket and you'll see the culprit.

Or replace until with loop to see how outblock changes.

Toomas Vooglaid
@toomasv
Hint: Check your set-words.
ralfwenske
@ralfwenske
Thank you both. @NjinN I tried rate and on-time already: same result. @9214 that explains it.
GiuseppeChillemi
@GiuseppeChillemi

@toomasv

The problem is: I test VA1 while I use VAL

The font I am using makes "1" and "l" quite identical.

Toomas Vooglaid
@toomasv
Bingo!
ralfwenske
@ralfwenske

@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).

nedzadarek
@nedzadarek
@ralfwenske I'm on the Windows so it may be different.
First, you don't need to copy images (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.
Secondly, view/no-wait [ image img ] might not cache results, so each time forever runs 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.
ps I've run it on: Red 0.6.4 for Windows built 19-Jan-2019/13:54:56+01:00 commit #4880ddb I'll try it on the newest build later.