Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
Gregg Irwin
@greggirwin
I can't find one real quick, and my 1 minute hack didn't work. Have to do other things, but will check back later if nobody else jumps in.
Dave Andersen
@dander
@SmackMacDougal maybe not a minimal example, and doesn't display the options, but you could look at the Red Console sources.
Toomas Vooglaid
@toomasv
@SmackMacDougal General idea, but unfinished (sorry, have to go):
blk: [
    ["Blog" http://www.red-lang.org] 
    ["Download" http://www.red-lang.org/downloads] 
    ["Documents" http://www.red-lang.org/documents]
] 
view [
    at 10x33 tl: text-list hidden data [] on-change [
        dd/text: copy pick face/data face/selected 
        face/visible?: no
    ] 
    dd: drop-down focus on-change [
        collect/into [
            foreach b blk [
                case [
                    empty? face/text [clear tl/data tl/visible?: no] 
                    find/match b/1 face/text [keep b/1]
                ]
            ]
        ] clear tl/data 
        tl/visible?: not empty? tl/data
    ] on-key [
        switch event/key [
            down [tl/selected: either tl/selected = -1 [1][max tl/selected + 1 length? tl/data]] 
            up [tl/selected: either tl/selected <= 1 [-1][tl/selected - 1]]
        ]
    ] on-enter [
        if all [tl/selected > 0 tl/visible?] [
            face/text: copy pick tl/data tl/selected 
            clear tl/data 
            tl/visible?: no
        ]
    ]
]
SmackMacDougal
@SmackMacDougal
@toomasv @dander @greggirwin Thank you all, much so.
Toomas that is a start and I shall give it much thought. I've toyed with capturing keys and pushing sub faces, so this should be interesting.
Toomas Vooglaid
@toomasv
It would be nice to have some method to programmatically let drop drop-down's item-list.
(And links are bogus in my example. :flushed: Just typed, didn't check.)
Gregg Irwin
@greggirwin

@toomasv agreed. Having not touched drop-down for a while, this was my quick hack earlier:

choices: [
    "Testing A"
    "Testing B"
    "Profile"
    "Process"
    "Func"
    "Function"
    "Functor"
]

filtered-list: none

view [
    dd: drop-down data choices on-key [
        filtered-list: copy choices
        if not empty? face/text [
            remove-each str filtered-list [not find/match str face/text]
        ]
        face/data: filtered-list
    ]
    button [print mold dd]
]

For a combo box (edit+list), we need to data/text facets for some things.

GiuseppeChillemi
@GiuseppeChillemi
I have a big object full of methods and when I call one of them it seem to work but something is eating words... Any advice on how to find the problem without inspecting piece every methods of the code ?
Gregg Irwin
@greggirwin
What do you mean by "eating words"? Can you post the code for that one function?
GiuseppeChillemi
@GiuseppeChillemi
@greggirwin I have found the cause of the problem: a function name had the same name of an argument of many mathods. It created a fake sense of words being eaten while actually it was dropped as the previous word wasn't a function anymore.
Fran├žois Jouen
@ldci
@melcepstrum I've included in redCV complex numbers operators and FFT routines. You are credited for your job in redCV manual as contributor :)
Nathan Douglas
@nd9600
Is there any way to define an object with a key that's also a word! outside the object? Like
a: 1
o: context [
  a: a
]
I just get lots of a has no value
seems like something that should be really easy to do
nedzadarek
@nedzadarek
@nd9600 like this:
  obj: context [a: 'a]
; make object! [
;     a: 'a
; ]
  obj/a
; a
?
Nathan Douglas
@nd9600
context compose [a: (a)] does it
I remember someone saying something about function specs letting you type return values - is there some way to do that?
I think I heard you can write them, but the compiler/interpreter just ignores it for now
nedzadarek
@nedzadarek
@nd9600 if your a points to something (e.g. a: 'a / a: to-word "a")
Nathan Douglas
@nd9600
like f: function [x [integer!] [integer!]] [x + 1]
thanks
nedzadarek
@nedzadarek

I remember someone saying something about function specs letting you type return values - is there some way to do that?

routines support that. Not sure how compiler treats it.

Nathan Douglas
@nd9600
yep that looks exactly like I want, thanks
nedzadarek
@nedzadarek
:+1:
Vladimir Vasilyev
@9214
@nd9600 return: <datatype or typeset>. It has no bearing on interpreter, but IIRC compiler uses such annotations to make its life easier.
Also:
>> a: 1
== 1
>> set o: object [a: none] a
== 1
>> o
== make object! [
    a: 1
]
Rudolf Meijer
@meijeru
@nd9600 The precise syntax for functions as opposed to routines is return: [<any sequence of datatypes and typesets>] ; see e.g. this spec.
Note (1) there is as yet no check on this and (2) when compiling, the typeset names must be of built-in (pre-defined) typesets -- user-defined typesets are not allowed in that case; see also red/red#3285
Gabriele Santilli
@giesse
@nd9600 another way:
>> a: 1
== 1
>> o: context [a: system/words/a]
== make object! [
    a: 1
]
Gregg Irwin
@greggirwin

@nd9600 your first example is a great "think like Red" experiment:

a: 1
o: context [
  a: a
]

To create a context and bind the words to it, context (or object) has to first find and collect all the set-word! values. Now, while you know that the a you want to evaluate is global, Red doesn't. A slight change should make this clear:

a: 1
o: context [
    a: self/a
]

That's how Red sees it, which lets you express things with locality in mind.

a: 1
o: context [
    a: 2
    b: a
]

Red's design choice is based on the premise that you shouldn't have to say self/a (though you can if you want). This is a huge win overall. Using compose or a path to another context also make it clear when you are reaching outside the spec for values.

rebred
@rebred
abyssconfig.png
I am trying to make the Abyss Web Server work with Red. My red scripts work and I am able to print the date correctly: print ["Date/time is:" now] When I tried to use a CGI form and use print input the server hangs and doesn't print the form content. Is there anyone that has any experience with this server ?
Semseddin Moldibi
@endo64
Not used Abyss Web Server, but you can check this document out, if you didn't already, https://github.com/red/red/wiki/%5BDOC%5D-Using-Red-as-CGI
rebred
@rebred
thank you I am using a post form and following the link page you posted print rejoin ["Post data: " mold input] - the server still hangs
Vladimir Vasilyev
@9214
@rebred it hangs because input is a function that waits for user input from console.
rebred
@rebred
@9214 I see. do you know a way to read the post data
Vladimir Vasilyev
@9214
@rebred have you read the link @endo64 mentioned?

Ah, I see that it mentions

For the POST method, you can get the POST data using input

So I might be wrong.

AndreasWagnerBerlin
@AndreasWagnerBerlin
I have another question regarding parse. I want to parse strings of the following outlook:
(abc OR def)/TI
So there are outer brackets and a /TI at the end. I am not interested what is inside the brackets, as long as there is a /TI.
It becomes tricky with the following strings:
(abc OR (def AND GHI) )/TI
( ( abc AND JKL) OR (def AND GHI))/TI
( ( ((abc AND JKL) OR (def AND GHI) )) )/TI
Is there any easy solution using parse?
Thank you in advance.
Toomas Vooglaid
@toomasv
@AndreasWagnerBerlin Please be more specific:
1) Do you expect just logic return or collected output?
2) What result do you expect in your last case ( ( ((abc AND JKL) OR (def AND GHI) )) )/TI?
3) Can /TI occur inside and outer parens be without ending /TI, e.g. ( ( ((abc AND JKL)/TI OR (def AND GHI) )) )?
AndreasWagnerBerlin
@AndreasWagnerBerlin
@toomasv Sorry for the confusion. I try to be more specific as follows:
re 1) logic return (true or false) would be fine
re 2) I expect a true as return because the case fulfills the pattern ( ... )/TI and the brackets are balanced
re 3) no, the /TIshall not occur inside a larger pattern
Toomas Vooglaid
@toomasv
@AndreasWagnerBerlin Thanks! Does this rule work?
[(pars: 0 yep: no) any [
   #"(" (pars: pars + 1) 
   | ")/TI" end (yep: true) 
   | #")" (pars: pars - 1) 
   | skip
   ] if (all [pars = 1 yep])
]
Vladimir Vasilyev
@9214
source: {
    (abc OR def)/TI
    (abc OR (def AND GHI))/TI
    ((abc AND JKL) OR (def AND GHI))/TI
    ((((abc AND JKL) OR (def AND GHI))))/TI
}

probe parse load source [4 [paren! /TI]]
Toomas Vooglaid
@toomasv
:smile: :+1:
AndreasWagnerBerlin
@AndreasWagnerBerlin
Thank you for both solutions. Both work for me. I did not know those parse features.
Vladimir Vasilyev
@9214
Also:
source: trim/lines {
    (abc OR def)/TI
    (abc OR (def AND GHI))/TI
    ((abc AND JKL) OR (def AND GHI))/TI
    ((((abc AND JKL) OR (def AND GHI))))/TI
}

state: reactor [
    counter: 0
    bump: func [delta][counter: counter + delta]
    balanced?: is [zero? counter]
]

rule: [
    some [
        some [
              #"(" (bump +1) 
            | #")" (bump -1)
            | not "/TI" skip
        ] 
        "/TI" if (balanced?)
    ]
] 

probe parse/case source bind rule state
Gregg Irwin
@greggirwin
@AndreasWagnerBerlin if you could add the pattern and solutions to https://github.com/red/red/wiki/Parse-Cookbook, that would be great. Thanks!
Both solutions are important, because leveraging load is always a win, but sometimes data is not loadable. Matching brackets is also fairly common.